Skip to content

Commit

Permalink
feat: added Option to toggle 24h time format in dashboard timeseries …
Browse files Browse the repository at this point in the history
…panels
  • Loading branch information
SagarRajput-7 committed Jul 10, 2024
1 parent 2c7a512 commit 0bfd711
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions frontend/src/lib/uPlotLib/utils/getAxes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,23 @@ import { getToolTipValue } from 'components/Graph/yAxisConfig';

import getGridColor from './getGridColor';

function format24HourTime(ts, includeDate = false): string {
const date = new Date(ts * 1000);
const hours = date.getHours().toString().padStart(2, '0');
const minutes = date.getMinutes().toString().padStart(2, '0');
const timeStr = `${hours}:${minutes}`;

if (includeDate) {
const day = date.getDate().toString().padStart(2, '0');
const month = (date.getMonth() + 1).toString().padStart(2, '0');
const year = date.getFullYear();
const dateStr = `${month}/${day}/${year}`;
return `${timeStr}\n${dateStr}`;
}

return timeStr;
}

const getAxes = (isDarkMode: boolean, yAxisUnit?: string): any => [
{
stroke: isDarkMode ? 'white' : 'black', // Color of the axis line
Expand All @@ -18,6 +35,8 @@ const getAxes = (isDarkMode: boolean, yAxisUnit?: string): any => [
show: true,
},
gap: 5,
values: (_self, ticks): any =>
ticks.map((ts, i) => format24HourTime(ts, i % 5 === 0)), // Include date every 5th tick
},
{
stroke: isDarkMode ? 'white' : 'black', // Color of the axis line
Expand Down Expand Up @@ -61,4 +80,5 @@ const getAxes = (isDarkMode: boolean, yAxisUnit?: string): any => [
},
},
];

export default getAxes;

0 comments on commit 0bfd711

Please sign in to comment.