Allow dynamic size value in default area chart

- Fixes system pause / unpause rendering
- Some formatting
This commit is contained in:
henrygd
2025-03-13 22:04:29 -04:00
parent 521be05bc1
commit 3058c24e82
3 changed files with 23 additions and 15 deletions

View File

@@ -35,6 +35,7 @@ export default memo(function AreaChartDefault({
chartData, chartData,
max, max,
tickFormatter, tickFormatter,
contentFormatter,
}: { }: {
maxToggled?: boolean maxToggled?: boolean
unit?: string unit?: string
@@ -42,6 +43,7 @@ export default memo(function AreaChartDefault({
chartData: ChartData chartData: ChartData
max?: number max?: number
tickFormatter?: (value: number) => string tickFormatter?: (value: number) => string
contentFormatter?: (value: number) => string
}) { }) {
const { yAxisWidth, updateYAxisWidth } = useYAxisWidth() const { yAxisWidth, updateYAxisWidth } = useYAxisWidth()
const { i18n } = useLingui() const { i18n } = useLingui()
@@ -115,7 +117,12 @@ export default memo(function AreaChartDefault({
content={ content={
<ChartTooltipContent <ChartTooltipContent
labelFormatter={(_, data) => formatShortDate(data[0].payload.created)} labelFormatter={(_, data) => formatShortDate(data[0].payload.created)}
contentFormatter={(item) => decimalString(item.value) + unit} contentFormatter={({ value }) => {
if (contentFormatter) {
return contentFormatter(value)
}
return decimalString(value) + unit
}}
// indicator="line" // indicator="line"
/> />
} }

View File

@@ -304,7 +304,7 @@ export default function SystemDetail({ name }: { name: string }) {
if (e.target instanceof HTMLInputElement || e.target instanceof HTMLTextAreaElement) { if (e.target instanceof HTMLInputElement || e.target instanceof HTMLTextAreaElement) {
return return
} }
const currentIndex = systems.findIndex(s => s.name === name) const currentIndex = systems.findIndex((s) => s.name === name)
if (currentIndex === -1 || systems.length <= 1) { if (currentIndex === -1 || systems.length <= 1) {
return return
} }
@@ -555,6 +555,10 @@ export default function SystemDetail({ name }: { name: string }) {
<div className="grid xl:grid-cols-2 gap-4"> <div className="grid xl:grid-cols-2 gap-4">
{Object.keys(systemStats.at(-1)?.stats.g ?? {}).map((id) => { {Object.keys(systemStats.at(-1)?.stats.g ?? {}).map((id) => {
const gpu = systemStats.at(-1)?.stats.g?.[id] as GPUData const gpu = systemStats.at(-1)?.stats.g?.[id] as GPUData
const sizeFormatter = (value: number, decimals?: number) => {
const { v, u } = getSizeAndUnit(value, false)
return toFixedFloat(v, decimals || 1) + u
}
return ( return (
<div key={id} className="contents"> <div key={id} className="contents">
<ChartCard <ChartCard
@@ -574,12 +578,9 @@ export default function SystemDetail({ name }: { name: string }) {
<AreaChartDefault <AreaChartDefault
chartData={chartData} chartData={chartData}
chartName={`g.${id}.mu`} chartName={`g.${id}.mu`}
unit=" MB"
max={gpu.mt} max={gpu.mt}
tickFormatter={(value) => { tickFormatter={sizeFormatter}
const { v, u } = getSizeAndUnit(value, false) contentFormatter={(value) => sizeFormatter(value, 2)}
return toFixedFloat(v, 1) + u
}}
/> />
</ChartCard> </ChartCard>
</div> </div>

View File

@@ -554,7 +554,7 @@ const SystemTableRow = memo(
))} ))}
</TableRow> </TableRow>
) )
}, [system, colLength, t]) }, [system, system.status, colLength, t])
} }
) )
@@ -627,9 +627,9 @@ const ActionsButton = memo(({ system }: { system: SystemRecord }) => {
const [editOpen, setEditOpen] = useState(false) const [editOpen, setEditOpen] = useState(false)
let editOpened = useRef(false) let editOpened = useRef(false)
const { t } = useLingui() const { t } = useLingui()
const { id, status, host, name } = system
return useMemo(() => { return useMemo(() => {
const { id, status, host, name } = system
return ( return (
<> <>
<DropdownMenu> <DropdownMenu>
@@ -717,7 +717,7 @@ const ActionsButton = memo(({ system }: { system: SystemRecord }) => {
</AlertDialog> </AlertDialog>
</> </>
) )
}, [system.id, t, deleteOpen, editOpen]) }, [id, status, host, name, t, deleteOpen, editOpen])
}) })
function IndicatorDot({ system, className }: { system: SystemRecord; className?: ClassValue }) { function IndicatorDot({ system, className }: { system: SystemRecord; className?: ClassValue }) {