Skip to content

Commit c9617ee

Browse files
author
Nils Bars
committed
Localize scoreboard chart dates and hide unstarted assignment markers
Tooltip and x-axis labels in the points-over-time and challenge plots now use Intl.DateTimeFormat with the user's locale. The points-over-time chart only renders assignment boundary markers for assignments whose start date has already passed. Also fix pre-existing typecheck errors in the ECharts series/markLine options and resolve a type-identity conflict between the 'echarts' and 'echarts/core' module declarations.
1 parent a82da89 commit c9617ee

4 files changed

Lines changed: 42 additions & 17 deletions

File tree

spa-frontend/src/components/scoreboard/ChallengePlot.vue

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -97,18 +97,18 @@ function buildSeries() {
9797
},
9898
markLine: index === 0 && baseline !== null
9999
? {
100-
symbol: ['none', 'none'],
100+
symbol: ['none', 'none'] as ['none', 'none'],
101101
animation: false,
102102
label: {
103103
show: true,
104-
position: 'insideMiddleTop',
104+
position: 'insideMiddleTop' as const,
105105
distance: 4,
106106
formatter: 'baseline',
107107
color: mark.label,
108108
},
109109
lineStyle: {
110110
color: mark.line,
111-
type: 'dashed',
111+
type: 'dashed' as const,
112112
width: 1,
113113
},
114114
data: [{ yAxis: baseline }],

spa-frontend/src/components/scoreboard/PointsOverTimeChart.vue

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,9 @@ function buildSeries() {
3333
showSymbol: true,
3434
symbol: getTeamSymbol(team),
3535
symbolSize: 10,
36-
data: scores.map(({ time, score }) => ({ value: [time, score] })),
36+
data: scores.map(({ time, score }) => ({
37+
value: [time, score] as [number, number],
38+
})),
3739
lineStyle: {
3840
width: 2,
3941
color: getTeamColor(team),
@@ -46,21 +48,21 @@ function buildSeries() {
4648
},
4749
markLine: index === 0 && props.assignmentBoundaries.length > 0
4850
? {
49-
symbol: ['none', 'none'],
51+
symbol: ['none', 'none'] as ['none', 'none'],
5052
animation: false,
5153
label: {
5254
show: true,
53-
position: 'middle',
55+
position: 'middle' as const,
5456
rotate: 90,
55-
align: 'center',
56-
verticalAlign: 'middle',
57+
align: 'center' as const,
58+
verticalAlign: 'middle' as const,
5759
color: mark.label,
5860
formatter: ({ dataIndex }: { dataIndex: number }) =>
5961
`Assignment ${dataIndex + 1}`,
6062
},
6163
lineStyle: {
6264
color: mark.line,
63-
type: 'dashed',
65+
type: 'dashed' as const,
6466
width: 1,
6567
},
6668
data: props.assignmentBoundaries.map((time) => ({

spa-frontend/src/components/scoreboard/chartSetup.ts

Lines changed: 27 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,9 @@ import {
88
TooltipComponent,
99
} from 'echarts/components';
1010
import { CanvasRenderer } from 'echarts/renderers';
11-
import type { EChartsOption, EChartsType } from 'echarts';
11+
import type { EChartsOption } from 'echarts';
12+
13+
type EChartsInstance = ReturnType<typeof echarts.init>;
1214

1315
echarts.use([
1416
LineChart,
@@ -121,14 +123,28 @@ export function onThemeChange(listener: () => void): () => void {
121123
}
122124

123125
const tooltipDateFormatter = new Intl.DateTimeFormat(undefined, {
124-
day: '2-digit',
125-
month: '2-digit',
126-
hour: '2-digit',
127-
minute: '2-digit',
126+
dateStyle: 'short',
127+
timeStyle: 'short',
128+
});
129+
130+
const axisDateFormatter = new Intl.DateTimeFormat(undefined, {
131+
dateStyle: 'short',
128132
});
129133

134+
const axisTimeFormatter = new Intl.DateTimeFormat(undefined, {
135+
timeStyle: 'short',
136+
});
137+
138+
export function formatAxisDate(value: number): string {
139+
return axisDateFormatter.format(new Date(value));
140+
}
141+
142+
export function formatAxisTime(value: number): string {
143+
return axisTimeFormatter.format(new Date(value));
144+
}
145+
130146
export type ManagedChart = {
131-
chart: EChartsType;
147+
chart: EChartsInstance;
132148
resizeObserver: ResizeObserver;
133149
};
134150

@@ -212,7 +228,11 @@ export function buildCommonOptions(xMin: number, xMax?: number): EChartsOption {
212228
type: 'time',
213229
min: xMin || undefined,
214230
max: xMax || undefined,
215-
axisLabel: { color: t.axisLabel },
231+
axisLabel: {
232+
color: t.axisLabel,
233+
hideOverlap: true,
234+
formatter: (value: number) => formatAxisDate(value),
235+
},
216236
axisLine: { lineStyle: { color: t.axisLine } },
217237
splitLine: { lineStyle: { color: t.splitLine } },
218238
},

spa-frontend/src/pages/Scoreboard.vue

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,10 @@ const scoresOverTime = computed(() => {
125125
});
126126
const assignmentBoundaries = computed(() => {
127127
if (!config.value) return [];
128-
return computeAssignmentStartTimes(assignments.value);
128+
const now = Date.now();
129+
return computeAssignmentStartTimes(assignments.value).filter(
130+
(d) => d.getTime() <= now,
131+
);
129132
});
130133
131134
const activeChallenges = computed(() => {

0 commit comments

Comments
 (0)