Skip to content

Commit c7c8caa

Browse files
authored
val symbol (#2263)
1 parent 4e0d863 commit c7c8caa

File tree

2 files changed

+15
-8
lines changed

2 files changed

+15
-8
lines changed

src/containers/LlamaAI/types.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,16 @@ export interface ChartConfiguration {
1111
x: {
1212
field: string
1313
label: string
14-
type: 'time' | 'category'
14+
type: 'time' | 'category' | 'value'
15+
valueSymbol?: string
1516
}
1617
yAxes: Array<{
1718
id: string
1819
fields: string[]
1920
label: string
2021
position: 'left' | 'right'
2122
scale?: 'linear' | 'log'
23+
valueSymbol?: string
2224
}>
2325
}
2426

src/containers/LlamaAI/utils/chartAdapter.ts

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -231,6 +231,16 @@ function adaptScatterChartData(config: ChartConfiguration, rawData: any[]): Adap
231231
const xAxisLabel = config.axes.x.label || xField
232232
const yAxisLabel = config.axes.yAxes[0]?.label || yField
233233

234+
const xAxisSymbol = config.axes.x.valueSymbol ?? config.valueSymbol ?? ''
235+
const yAxisSymbol = config.axes.yAxes[0]?.valueSymbol ?? config.valueSymbol ?? ''
236+
237+
const formatValue = (val: number, symbol: string) => {
238+
if (symbol === '$') return formattedNum(val, true)
239+
if (symbol === '%') return val.toFixed(2) + '%'
240+
if (symbol === '') return formattedNum(val)
241+
return `${formattedNum(val)} ${symbol}`
242+
}
243+
234244
const scatterProps = {
235245
chartData: scatterData,
236246
title: config.title,
@@ -243,12 +253,7 @@ function adaptScatterChartData(config: ChartConfiguration, rawData: any[]): Adap
243253
const xValue = params.value[0]
244254
const yValue = params.value[1]
245255
const entityName = params.value[2] || 'Unknown'
246-
const formatValue = (val: number) => {
247-
if (config.valueSymbol === '$') return formattedNum(val, true)
248-
if (config.valueSymbol === '%') return val.toFixed(2) + '%'
249-
return formattedNum(val)
250-
}
251-
return `<strong>${entityName}</strong><br/>${xAxisLabel}: ${formatValue(xValue)}<br/>${yAxisLabel}: ${formatValue(yValue)}`
256+
return `<strong>${entityName}</strong><br/>${xAxisLabel}: ${formatValue(xValue, xAxisSymbol)}<br/>${yAxisLabel}: ${formatValue(yValue, yAxisSymbol)}`
252257
}
253258
return ''
254259
}
@@ -474,7 +479,7 @@ export function adaptMultiSeriesData(config: ChartConfiguration, rawData: any[])
474479
hideDataZoom: true,
475480
hideDownloadButton: false,
476481
valueSymbol: config.valueSymbol ?? '',
477-
xAxisType: config.axes.x.type,
482+
xAxisType: config.axes.x.type === 'value' ? 'category' : config.axes.x.type,
478483

479484
...(config.hallmarks?.length && {
480485
hallmarks: normalizeHallmarks(config.hallmarks)

0 commit comments

Comments
 (0)