From ebd3920ab7315c8535ffe97911b53e7430496e29 Mon Sep 17 00:00:00 2001 From: jacovinus Date: Wed, 23 Mar 2022 21:58:42 +0100 Subject: [PATCH 1/2] fix: date formatting at chart --- src/plugins/charts/index.js | 38 +++++++++++++++++++++++++------------ 1 file changed, 26 insertions(+), 12 deletions(-) diff --git a/src/plugins/charts/index.js b/src/plugins/charts/index.js index 9d21dba8..5e5ae0e4 100644 --- a/src/plugins/charts/index.js +++ b/src/plugins/charts/index.js @@ -31,17 +31,25 @@ function ClokiChart({ matrixData }) { const first = tsArray[0]; const last = tsArray[tsArray.length - 1]; const timeSpan = (last - first) / 1000 / 86400; - return timeSpan > 1 - ? "%m-%d %H:%M" + const formatted = timeSpan > 0.0208? '%H:%M': timeSpan > 1 + ? "%m/%d %H:%M" : timeSpan > 30 - ? "%y-%m-%d %H:%M" + ? "%y/%m/%d %H:%M" : "%H:%M:%S"; + return { + timeformat:formatted, + min: first, + max: last + } } + + const options = { xaxis: { show: true, mode: "time", + timezone:"browser", timeformat: "%Y-%m-%d %H:%M:%S", // set this one on custom settings }, grid: { @@ -252,12 +260,13 @@ function ClokiChart({ matrixData }) { }; try { + const {timeformat,min,max} = formatDateRange(newData) let plot = $q.plot( element, newData, $q.extend(true, {}, chartOptions, { ...chartBarSeries, - xaxis: { timeformat: formatDateRange(newData) }, + xaxis: { timeformat, min, max }, }) ); @@ -308,12 +317,13 @@ function ClokiChart({ matrixData }) { } try { + const {timeformat,min,max} = formatDateRange(newData) let plot = $q.plot( element, newData, $q.extend(true, {}, chartOptions, { ...chartPointsSeries, - xaxis: { timeformat: formatDateRange(newData) }, + xaxis: { timeformat,min,max }, }) ); const colorLabels = plot.getData(); @@ -363,12 +373,13 @@ function ClokiChart({ matrixData }) { }; try { + const {timeformat,min,max} = formatDateRange(newData) let plot = $q.plot( element, newData, $q.extend(true, {}, chartOptions, { ...chartLineSeries, - xaxis: { timeformat: formatDateRange(newData) }, + xaxis: { timeformat,min,max }, }) ); const colorLabels = plot.getData(); @@ -424,7 +435,7 @@ function ClokiChart({ matrixData }) { xaxis: { min: ranges.xaxis.from, max: ranges.xaxis.to, - timeformat: formatDateRange(newData), + timeformat: formatDateRange(newData).timerange, }, }) ); @@ -493,14 +504,14 @@ function ClokiChart({ matrixData }) { }; } }); - + const {timeformat,min,max} = formatDateRange(dataSelected) let plot = $q.plot( element, dataSelected, $q.extend(true, {}, chartOptions, { series: getSeriesFromChartType(chartType), - xaxis: { timeformat: formatDateRange(dataSelected) }, + xaxis: { timeformat,min,max }, }) ); @@ -517,12 +528,13 @@ function ClokiChart({ matrixData }) { points, }; }); + const {timeformat,min,max} = formatDateRange(newData) let plot = $q.plot( element, newData, $q.extend(true, {}, chartOptions, { series: getSeriesFromChartType(chartType), - xaxis: { timeformat: formatDateRange(newData) }, + xaxis: { timeformat,min,max }, }) ); @@ -584,12 +596,13 @@ function ClokiChart({ matrixData }) { } try { + const {timeformat,min,max} = formatDateRange(newData) let plot = $q.plot( element, newData, $q.extend(true, {}, chartOptions, { series: getSeriesFromChartType(chartType), - xaxis: { timeformat: formatDateRange(newData) }, + xaxis: { timeformat,min,max }, }) ); @@ -604,12 +617,13 @@ function ClokiChart({ matrixData }) { function drawChart(data) { if (data?.length) { try { + const {timeformat,min,max} = formatDateRange(data) let plot = $q.plot( chartRef.current, data, $q.extend(true, {}, chartOptions, { series: getSeriesFromChartType(chartType), - xaxis: { timeformat: formatDateRange(data) }, + xaxis: { timeformat,min,max }, }) ); // get generated colors From 6ed0f620ca588f4e33fe4730056ad6789fc82728 Mon Sep 17 00:00:00 2001 From: jacovinus Date: Wed, 23 Mar 2022 22:03:05 +0100 Subject: [PATCH 2/2] fix timerange format --- src/plugins/charts/index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/plugins/charts/index.js b/src/plugins/charts/index.js index 5e5ae0e4..e4b9a98b 100644 --- a/src/plugins/charts/index.js +++ b/src/plugins/charts/index.js @@ -31,7 +31,7 @@ function ClokiChart({ matrixData }) { const first = tsArray[0]; const last = tsArray[tsArray.length - 1]; const timeSpan = (last - first) / 1000 / 86400; - const formatted = timeSpan > 0.0208? '%H:%M': timeSpan > 1 + const formatted = timeSpan > 1 ? "%m/%d %H:%M" : timeSpan > 30 ? "%y/%m/%d %H:%M"