Add a total line to the tooltip of charts with multiple values (#1280)

* base total

* only visible on certain charts

* remove unwanted changes
This commit is contained in:
Titouan V
2025-11-04 21:44:30 +01:00
committed by GitHub
parent 1e32d13650
commit 23fff31a05
33 changed files with 232 additions and 2 deletions

View File

@@ -29,6 +29,7 @@ export default function AreaChartDefault({
domain,
legend,
itemSorter,
showTotal = false,
}: // logRender = false,
{
chartData: ChartData
@@ -40,6 +41,7 @@ export default function AreaChartDefault({
domain?: [number, number]
legend?: boolean
itemSorter?: (a: any, b: any) => number
showTotal?: boolean
// logRender?: boolean
}) {
const { yAxisWidth, updateYAxisWidth } = useYAxisWidth()
@@ -81,6 +83,7 @@ export default function AreaChartDefault({
<ChartTooltipContent
labelFormatter={(_, data) => formatShortDate(data[0].payload.created)}
contentFormatter={contentFormatter}
showTotal={showTotal}
/>
}
/>
@@ -107,5 +110,5 @@ export default function AreaChartDefault({
</ChartContainer>
</div>
)
}, [chartData.systemStats.at(-1), yAxisWidth, maxToggled])
}, [chartData.systemStats.at(-1), yAxisWidth, maxToggled, showTotal])
}

View File

@@ -136,7 +136,7 @@ export default memo(function ContainerChart({
labelFormatter={(_, data) => formatShortDate(data[0].payload.created)}
// @ts-expect-error
itemSorter={(a, b) => b.value - a.value}
content={<ChartTooltipContent filter={filter} contentFormatter={toolTipFormatter} />}
content={<ChartTooltipContent filter={filter} contentFormatter={toolTipFormatter} showTotal={true} />}
/>
{Object.keys(chartConfig).map((key) => {
const filtered = filteredKeys.has(key)

View File

@@ -61,6 +61,7 @@ export default memo(function MemChart({ chartData, showMax }: { chartData: Chart
const { value: convertedValue, unit } = formatBytes(value * 1024, false, Unit.Bytes, true)
return decimalString(convertedValue, convertedValue >= 100 ? 1 : 2) + " " + unit
}}
showTotal={true}
/>
}
/>