Skip to content

Commit 1094c43

Browse files
Merge pull request #1927 from iamfaran/fix/1836-barchart
[Fix]: #1836 race condition barchart
2 parents aecdd0d + a6c5cf3 commit 1094c43

File tree

3 files changed

+40
-3
lines changed

3 files changed

+40
-3
lines changed

client/packages/lowcoder-comps/src/comps/barChartComp/barChartComp.tsx

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,8 @@ BarChartTmpComp = withViewFn(BarChartTmpComp, (comp) => {
6161
const [chartSize, setChartSize] = useState<ChartSize>();
6262
const firstResize = useRef(true);
6363
const theme = useContext(ThemeContext);
64+
const [chartKey, setChartKey] = useState(0);
65+
const prevRaceMode = useRef<boolean>();
6466
const defaultChartTheme = {
6567
color: chartColorPalette,
6668
backgroundColor: "#fff",
@@ -73,6 +75,16 @@ BarChartTmpComp = withViewFn(BarChartTmpComp, (comp) => {
7375
log.error('theme chart error: ', error);
7476
}
7577

78+
// Detect race mode changes and force chart recreation
79+
const currentRaceMode = comp.children.chartConfig?.children?.comp?.children?.race?.getView();
80+
useEffect(() => {
81+
if (prevRaceMode.current !== undefined && prevRaceMode.current !== currentRaceMode) {
82+
// Force chart recreation when race mode changes
83+
setChartKey(prev => prev + 1);
84+
}
85+
prevRaceMode.current = currentRaceMode;
86+
}, [currentRaceMode]);
87+
7688
const triggerClickEvent = async (dispatch: any, action: CompAction<JSONValue>) => {
7789
await getPromiseAfterDispatch(
7890
dispatch,
@@ -176,10 +188,11 @@ BarChartTmpComp = withViewFn(BarChartTmpComp, (comp) => {
176188
return (
177189
<div ref={containerRef} style={{height: '100%'}}>
178190
<ReactECharts
191+
key={chartKey}
179192
ref={(e) => (echartsCompRef.current = e)}
180193
style={{ height: "100%" }}
181-
notMerge
182-
lazyUpdate
194+
notMerge={!currentRaceMode}
195+
lazyUpdate={!currentRaceMode}
183196
opts={{ locale: getEchartsLocale() }}
184197
option={option}
185198
mode={mode}

client/packages/lowcoder-comps/src/comps/barChartComp/barChartUtils.ts

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,15 @@ export function getEchartsConfig(
201201
animationEasing: 'linear',
202202
animationEasingUpdate: 'linear',
203203
}
204+
} else {
205+
// Ensure proper animation settings when race is disabled
206+
config = {
207+
...config,
208+
animationDuration: 1000,
209+
animationDurationUpdate: 1000,
210+
animationEasing: 'cubicOut',
211+
animationEasingUpdate: 'cubicOut',
212+
}
204213
}
205214
if (props.data.length <= 0) {
206215
// no data
@@ -333,6 +342,21 @@ export function getEchartsConfig(
333342
animationDurationUpdate: 300
334343
},
335344
}
345+
} else {
346+
// Reset axis animations when race is disabled
347+
config = {
348+
...config,
349+
xAxis: {
350+
...config.xAxis,
351+
animationDuration: undefined,
352+
animationDurationUpdate: undefined
353+
},
354+
yAxis: {
355+
...config.yAxis,
356+
animationDuration: undefined,
357+
animationDurationUpdate: undefined
358+
},
359+
}
336360
}
337361
}
338362
// console.log("Echarts transformedData and config", transformedData, config);

client/packages/lowcoder-comps/src/comps/basicChartComp/chartConfigs/barChartConfig.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ export const BarChartConfig = (function () {
5353
type: "bar",
5454
subtype: props.type,
5555
realtimeSort: props.race,
56-
seriesLayoutBy: props.race?'column':undefined,
56+
seriesLayoutBy: props.race?'column':'row',
5757
label: {
5858
show: props.showLabel,
5959
position: "top",

0 commit comments

Comments
 (0)