Skip to content

[Fix]: #1836 race condition barchart #1927

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 4, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@ BarChartTmpComp = withViewFn(BarChartTmpComp, (comp) => {
const [chartSize, setChartSize] = useState<ChartSize>();
const firstResize = useRef(true);
const theme = useContext(ThemeContext);
const [chartKey, setChartKey] = useState(0);
const prevRaceMode = useRef<boolean>();
const defaultChartTheme = {
color: chartColorPalette,
backgroundColor: "#fff",
Expand All @@ -73,6 +75,16 @@ BarChartTmpComp = withViewFn(BarChartTmpComp, (comp) => {
log.error('theme chart error: ', error);
}

// Detect race mode changes and force chart recreation
const currentRaceMode = comp.children.chartConfig?.children?.comp?.children?.race?.getView();
useEffect(() => {
if (prevRaceMode.current !== undefined && prevRaceMode.current !== currentRaceMode) {
// Force chart recreation when race mode changes
setChartKey(prev => prev + 1);
}
prevRaceMode.current = currentRaceMode;
}, [currentRaceMode]);

const triggerClickEvent = async (dispatch: any, action: CompAction<JSONValue>) => {
await getPromiseAfterDispatch(
dispatch,
Expand Down Expand Up @@ -176,10 +188,11 @@ BarChartTmpComp = withViewFn(BarChartTmpComp, (comp) => {
return (
<div ref={containerRef} style={{height: '100%'}}>
<ReactECharts
key={chartKey}
ref={(e) => (echartsCompRef.current = e)}
style={{ height: "100%" }}
notMerge
lazyUpdate
notMerge={!currentRaceMode}
lazyUpdate={!currentRaceMode}
opts={{ locale: getEchartsLocale() }}
option={option}
mode={mode}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,15 @@ export function getEchartsConfig(
animationEasing: 'linear',
animationEasingUpdate: 'linear',
}
} else {
// Ensure proper animation settings when race is disabled
config = {
...config,
animationDuration: 1000,
animationDurationUpdate: 1000,
animationEasing: 'cubicOut',
animationEasingUpdate: 'cubicOut',
}
}
if (props.data.length <= 0) {
// no data
Expand Down Expand Up @@ -333,6 +342,21 @@ export function getEchartsConfig(
animationDurationUpdate: 300
},
}
} else {
// Reset axis animations when race is disabled
config = {
...config,
xAxis: {
...config.xAxis,
animationDuration: undefined,
animationDurationUpdate: undefined
},
yAxis: {
...config.yAxis,
animationDuration: undefined,
animationDurationUpdate: undefined
},
}
}
}
// console.log("Echarts transformedData and config", transformedData, config);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ export const BarChartConfig = (function () {
type: "bar",
subtype: props.type,
realtimeSort: props.race,
seriesLayoutBy: props.race?'column':undefined,
seriesLayoutBy: props.race?'column':'row',
label: {
show: props.showLabel,
position: "top",
Expand Down
Loading