Skip to content

Commit 3ffcfdf

Browse files
authored
[ez][HUD] Format time function, loading page height, onEvents for TimeSeriesPanel (#6271)
* Add a function for formatting time, generally used in tooltips in charts and use it whenever possible * Add an option for setting the height of a `LoadingPage` component * Add an option for onEvents for TimeSeriesPanel so you can listen to clicks etc on the chart
1 parent e8c908c commit 3ffcfdf

File tree

6 files changed

+28
-15
lines changed

6 files changed

+28
-15
lines changed

torchci/components/LoadingPage.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,11 @@ const LoadingItem = styled("div")(({}) => ({
1212
margin: "10px",
1313
}));
1414

15-
function LoadingPage() {
15+
function LoadingPage({ height }: { height?: number }) {
16+
const style = height !== undefined ? { height: height } : {};
1617
return (
1718
<>
18-
<LoadingContainer>
19+
<LoadingContainer style={style}>
1920
<div>
2021
<em> Loading...</em>
2122
</div>

torchci/components/TimeUtils.tsx

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,3 +67,12 @@ export function durationDisplay(seconds: number): string {
6767
const days = hours / 24.0;
6868
return days.toFixed(1) + "d";
6969
}
70+
71+
export const TIME_DISPLAY_FORMAT = "M/D h:mm:ss A";
72+
73+
export function formatTimeForCharts(
74+
time: string,
75+
format = TIME_DISPLAY_FORMAT
76+
) {
77+
return dayjs.utc(time).local().format(format);
78+
}

torchci/components/metrics/panels/TimeSeriesPanel.tsx

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
*/
44

55
import { Paper, Skeleton } from "@mui/material";
6+
import { formatTimeForCharts, TIME_DISPLAY_FORMAT } from "components/TimeUtils";
67
import dayjs from "dayjs";
78
import utc from "dayjs/plugin/utc";
89
import { EChartsOption } from "echarts";
@@ -155,7 +156,7 @@ export function TimeSeriesPanelWithData({
155156
// as its own line.
156157
groupByFieldName,
157158
// Display format for the time field (ex "M/D h:mm:ss A")
158-
timeFieldDisplayFormat = "M/D h:mm:ss A",
159+
timeFieldDisplayFormat = TIME_DISPLAY_FORMAT,
159160
// Callback to render the y axis value in some nice way.
160161
yAxisRenderer,
161162
// What label to put on the y axis.
@@ -164,6 +165,7 @@ export function TimeSeriesPanelWithData({
164165
additionalOptions,
165166
// To avoid overlapping long legends and the chart
166167
legendPadding = 200,
168+
onEvents,
167169
}: {
168170
data: any;
169171
series: any;
@@ -174,6 +176,7 @@ export function TimeSeriesPanelWithData({
174176
yAxisLabel?: string;
175177
additionalOptions?: EChartsOption;
176178
legendPadding?: number;
179+
onEvents?: { [key: string]: any };
177180
}) {
178181
// Add extra padding when the legend is active
179182
const legend_padding = groupByFieldName !== undefined ? legendPadding : 48;
@@ -226,10 +229,10 @@ export function TimeSeriesPanelWithData({
226229
trigger: "item",
227230
formatter: (params: any) =>
228231
`${params.seriesName}` +
229-
`<br/>${dayjs
230-
.utc(params.value[0])
231-
.local()
232-
.format(timeFieldDisplayFormat)}<br/>` +
232+
`<br/>${formatTimeForCharts(
233+
params.value[0],
234+
timeFieldDisplayFormat
235+
)}<br/>` +
233236
`${getTooltipMarker(params.color)}` +
234237
`<b>${yAxisRenderer(params.value[1])}</b>` +
235238
// add total value to tooltip,
@@ -250,6 +253,7 @@ export function TimeSeriesPanelWithData({
250253
style={{ height: "100%", width: "100%" }}
251254
option={options}
252255
notMerge={true}
256+
onEvents={onEvents}
253257
/>
254258
</Paper>
255259
);
@@ -270,7 +274,7 @@ export default function TimeSeriesPanel({
270274
// What field name to treat as the time value.
271275
timeFieldName,
272276
// Display format for the time field (ex "M/D h:mm:ss A")
273-
timeFieldDisplayFormat = "M/D h:mm:ss A",
277+
timeFieldDisplayFormat = TIME_DISPLAY_FORMAT,
274278
// What field name to put on the y axis.
275279
yAxisFieldName,
276280
// Callback to render the y axis value in some nice way.

torchci/pages/query_execution_metrics.tsx

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import {
1212
Granularity,
1313
TimeSeriesPanelWithData,
1414
} from "components/metrics/panels/TimeSeriesPanel";
15+
import { formatTimeForCharts } from "components/TimeUtils";
1516
import dayjs from "dayjs";
1617
import utc from "dayjs/plugin/utc";
1718
import { useEffect, useState } from "react";
@@ -129,10 +130,7 @@ export default function Page() {
129130
: `${field.headerName}: ${data[field.field]}`
130131
)
131132
.join("<br>");
132-
return `${dayjs
133-
.utc(data.time)
134-
.local()
135-
.format("M/D h:mm:ss A")}<br>${fieldInfo}`;
133+
return `${formatTimeForCharts(data.time)}<br>${fieldInfo}`;
136134
},
137135
},
138136
yAxis: [

torchci/pages/reliability/[repoOwner]/[repoName]/[[...page]].tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import {
88
Granularity,
99
seriesWithInterpolatedTimes,
1010
} from "components/metrics/panels/TimeSeriesPanel";
11+
import { formatTimeForCharts } from "components/TimeUtils";
1112
import dayjs from "dayjs";
1213
import { EChartsOption } from "echarts";
1314
import ReactECharts from "echarts-for-react";
@@ -172,7 +173,7 @@ function GraphPanel({
172173
trigger: "item",
173174
formatter: (params: any) =>
174175
`${params.seriesName}` +
175-
`<br/>${dayjs(params.value[0]).local().format("M/D h:mm:ss A")}<br/>` +
176+
`<br/>${formatTimeForCharts(params.value[0])}<br/>` +
176177
`${getTooltipMarker(params.color)}` +
177178
`<b>${params.value[1]}</b>`,
178179
},

torchci/pages/tts/[repoOwner]/[repoName]/[branch]/[[...page]].tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import {
66
Granularity,
77
seriesWithInterpolatedTimes,
88
} from "components/metrics/panels/TimeSeriesPanel";
9-
import { durationDisplay } from "components/TimeUtils";
9+
import { durationDisplay, formatTimeForCharts } from "components/TimeUtils";
1010
import dayjs from "dayjs";
1111
import { EChartsOption } from "echarts";
1212
import ReactECharts from "echarts-for-react";
@@ -59,7 +59,7 @@ function Panel({
5959
trigger: "item",
6060
formatter: (params: any) =>
6161
`${params.seriesName}` +
62-
`<br/>${dayjs(params.value[0]).local().format("M/D h:mm:ss A")}<br/>` +
62+
`<br/>${formatTimeForCharts(params.value[0])}<br/>` +
6363
`${getTooltipMarker(params.color)}` +
6464
`<b>${durationDisplay(params.value[1])}</b>`,
6565
},

0 commit comments

Comments
 (0)