fix: chart flicker

This commit is contained in:
jialin
2026-04-29 09:29:04 +08:00
committed by jialin
parent 26880b4612
commit 3144328874
3 changed files with 17 additions and 3 deletions
@@ -180,10 +180,14 @@ const BarChart: React.FC<BarChartProps> = (props) => {
} }
}, },
legend: { legend: {
type: 'scroll',
itemWidth: 8, itemWidth: 8,
itemHeight: 8, itemHeight: 8,
itemGap: 12, itemGap: 12,
textStyle: { color: token.colorTextTertiary }, textStyle: { color: token.colorTextTertiary },
pageTextStyle: { color: token.colorTextTertiary },
pageIconColor: token.colorTextTertiary,
pageIconInactiveColor: token.colorTextDisabled,
bottom: 0, bottom: 0,
data: legendData, data: legendData,
show: !!legendData?.length show: !!legendData?.length
+5 -1
View File
@@ -86,6 +86,10 @@ const DailyUsage: React.FC<DailyUsageProps> = (props) => {
return dayjs(v).format('MM-DD'); return dayjs(v).format('MM-DD');
}; };
// Recompute only when data (or locale) changes, NOT when metric/groupBy/granularity change.
// Filter changes already trigger a refetch; deriving on stale data with new filters
// produces an inconsistent intermediate frame (e.g. grouped data flattened to total),
// which is the visible flicker.
const { seriesData, xAxisData, legendData } = useMemo(() => { const { seriesData, xAxisData, legendData } = useMemo(() => {
const items = timeSeriesData?.items || []; const items = timeSeriesData?.items || [];
if (items.length === 0) { if (items.length === 0) {
@@ -233,7 +237,7 @@ const DailyUsage: React.FC<DailyUsageProps> = (props) => {
xAxisData: xAxis, xAxisData: xAxis,
legendData: dedupedLegend legendData: dedupedLegend
}; };
}, [timeSeriesData, metric, groupBy, granularity, startDate, endDate, intl]); }, [timeSeriesData, intl]);
const handleOnGroupByChange = (value: string) => { const handleOnGroupByChange = (value: string) => {
onGroupByChange(value || null); onGroupByChange(value || null);
+8 -2
View File
@@ -182,7 +182,11 @@ const ExportData: React.FC<{
} }
}, },
{ {
title: intl.formatMessage({ id: 'usage.filter.totalTokens' }), title: (
<AutoTooltip ghost>
{intl.formatMessage({ id: 'usage.filter.totalTokens' })}
</AutoTooltip>
),
dataIndex: 'total_tokens', dataIndex: 'total_tokens',
render: (text: string, record: any) => { render: (text: string, record: any) => {
return <AutoTooltip ghost>{text}</AutoTooltip>; return <AutoTooltip ghost>{text}</AutoTooltip>;
@@ -322,7 +326,9 @@ const ExportData: React.FC<{
style={{ style={{
position: 'sticky', position: 'sticky',
top: 0, top: 0,
zIndex: 1 zIndex: 1,
backgroundColor: 'var(--ant-color-bg-elevated)',
paddingBottom: 8
}} }}
> >
<FilterBar <FilterBar