phpmyadmin/resources/js/modules/functions/createProfilingChart.ts
Liviu-Mihail Concioiu cf80ac28bb Improve createProfilingChart function and remove duplicate code
Signed-off-by: Liviu-Mihail Concioiu <liviu.concioiu@gmail.com>
2025-09-04 00:32:17 +02:00

33 lines
959 B
TypeScript

import { CommonParams } from '../common.ts';
/**
* Creates a Profiling Chart. Used in sql.ts
* and in server/status/monitor.ts
*
* @param {string} target
* @param {any[]} chartData
* @param {string} legendPosition
*
* @return {object}
*/
export default function createProfilingChart (target, chartData, legendPosition) {
const lang = CommonParams.get('lang');
const numberFormat = new Intl.NumberFormat(lang.replace('_', '-'), {
style: 'unit',
unit: 'second',
unitDisplay: 'long',
notation: 'engineering',
});
return new window.Chart(target, {
type: 'pie',
data: { labels: chartData.labels, datasets: [{ data: chartData.data }] },
options: {
plugins: {
legend: { position: legendPosition },
tooltip: { callbacks: { label: context => context.parsed ? numberFormat.format(context.parsed) : '' } },
},
},
});
}