Skip to content

Commit ec4161b

Browse files
Merge pull request #19844 from liviuconcioiu/profiling
Improve createProfilingChart function and remove duplicate code
2 parents 2373dde + cf80ac2 commit ec4161b

3 files changed

Lines changed: 10 additions & 28 deletions

File tree

resources/js/modules/functions/createProfilingChart.ts

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,16 @@
11
import { CommonParams } from '../common.ts';
22

33
/**
4-
* Creates a Profiling Chart. Used in sql.js
5-
* and in server/status/monitor.js
4+
* Creates a Profiling Chart. Used in sql.ts
5+
* and in server/status/monitor.ts
66
*
77
* @param {string} target
8-
* @param {any[]} data
8+
* @param {any[]} chartData
9+
* @param {string} legendPosition
910
*
1011
* @return {object}
1112
*/
12-
export default function createProfilingChart (target, data) {
13+
export default function createProfilingChart (target, chartData, legendPosition) {
1314
const lang = CommonParams.get('lang');
1415
const numberFormat = new Intl.NumberFormat(lang.replace('_', '-'), {
1516
style: 'unit',
@@ -20,10 +21,10 @@ export default function createProfilingChart (target, data) {
2021

2122
return new window.Chart(target, {
2223
type: 'pie',
23-
data: { labels: data.map(row => row[0]), datasets: [{ data: data.map(row => row[1]) }] },
24+
data: { labels: chartData.labels, datasets: [{ data: chartData.data }] },
2425
options: {
2526
plugins: {
26-
legend: { position: 'right' },
27+
legend: { position: legendPosition },
2728
tooltip: { callbacks: { label: context => context.parsed ? numberFormat.format(context.parsed) : '' } },
2829
},
2930
},

resources/js/server/status/monitor.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2211,7 +2211,7 @@ AJAX.registerOnload('server/status/monitor.js', function () {
22112211
return false;
22122212
});
22132213

2214-
profilingChart = createProfilingChart('queryProfilingCanvas', chartData);
2214+
profilingChart = createProfilingChart('queryProfilingCanvas', chartData, 'right');
22152215
}
22162216
});
22172217

resources/js/sql.ts

Lines changed: 2 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { AJAX } from './modules/ajax.ts';
44
import { checkFormElementInRange, checkSqlQuery, prepareForAjaxRequest } from './modules/functions.ts';
55
import { Navigation } from './modules/navigation.ts';
66
import { CommonParams } from './modules/common.ts';
7+
import createProfilingChart from './modules/functions/createProfilingChart.ts';
78
import highlightSql from './modules/sql-highlight.ts';
89
import { ajaxRemoveMessage, ajaxShowMessage } from './modules/ajax-message.ts';
910
import { escapeBacktick, escapeHtml } from './modules/functions/escape.ts';
@@ -1369,27 +1370,7 @@ function buildProfilingChart () {
13691370
return;
13701371
}
13711372

1372-
const lang = CommonParams.get('lang');
1373-
const numberFormat = new Intl.NumberFormat(lang.replace('_', '-'), {
1374-
style: 'unit',
1375-
unit: 'second',
1376-
unitDisplay: 'long',
1377-
notation: 'engineering',
1378-
});
1379-
1380-
new window.Chart(profilingChartCanvas, {
1381-
type: 'pie',
1382-
data: {
1383-
labels: chartData.labels,
1384-
datasets: [{ data: chartData.data }],
1385-
},
1386-
options: {
1387-
plugins: {
1388-
legend: { position: 'bottom' },
1389-
tooltip: { callbacks: { label: context => context.parsed ? numberFormat.format(context.parsed) : '' } },
1390-
},
1391-
},
1392-
});
1373+
createProfilingChart('profilingChartCanvas', chartData, 'bottom');
13931374
}
13941375

13951376
/**

0 commit comments

Comments
 (0)