Skip to content

Commit 4867896

Browse files
committed
format yaxis
1 parent c7e85b9 commit 4867896

File tree

1 file changed

+44
-1
lines changed

1 file changed

+44
-1
lines changed

apps/web/src/components/v2Editor/customBlocks/visualizationV2/VisualizationView.tsx

Lines changed: 44 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -331,8 +331,51 @@ function BrieferResult(props: {
331331
},
332332
grid,
333333
xAxis: xAxes.map((axis) => axis.option),
334-
yAxis: props.result.yAxis.map((axis) => ({
334+
yAxis: props.result.yAxis.map((axis, i) => ({
335335
...axis,
336+
axisLabel: {
337+
formatter: (value: string | number): string => {
338+
const format:
339+
| null
340+
| { _tag: 'date'; format: DateFormat }
341+
| { _tag: 'number'; format: NumberFormat } =
342+
props.input.yAxes[i]?.series
343+
.map((s) => {
344+
if (!s.column) {
345+
return null
346+
}
347+
348+
if (NumpyDateTypes.safeParse(s.column.type).success) {
349+
if (s.dateFormat) {
350+
return { _tag: 'date' as const, format: s.dateFormat }
351+
}
352+
}
353+
354+
if (NumpyNumberTypes.safeParse(s.column.type).success) {
355+
if (s.numberFormat) {
356+
return { _tag: 'number' as const, format: s.numberFormat }
357+
}
358+
}
359+
360+
return null
361+
})
362+
.find((f) => f !== null) ?? null
363+
364+
if (!format) {
365+
return value.toString()
366+
}
367+
368+
if (typeof value === 'number' && format._tag === 'number') {
369+
return formatNumber(value, format.format)
370+
}
371+
372+
if (format._tag === 'date') {
373+
return formatDateTime(value, format.format)
374+
}
375+
376+
return value.toString()
377+
},
378+
},
336379
})),
337380
tooltip: {
338381
...props.result.tooltip,

0 commit comments

Comments
 (0)