Skip to content

Commit

Permalink
fix: 结构调整
Browse files Browse the repository at this point in the history
  • Loading branch information
yxh01132861 committed Aug 1, 2023
1 parent 3634a61 commit 6dd2258
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,8 @@ const IntervalLine = ({
legend: showLegend,
};

const themeCfg = getChartTheme(theme) as Record<string, any>;

if (!plotRef.current) {
const chart = new Chart({
container: containerRef.current!,
Expand All @@ -84,7 +86,6 @@ const IntervalLine = ({
paddingBottom: 30,
});

const themeCfg = getChartTheme(theme) as Record<string, any>;
chart.theme(themeCfg);

chart.options({
Expand All @@ -109,17 +110,9 @@ const IntervalLine = ({
type: 'view',
children: [{ ...commConfig }],
});
plotRef.current?.theme(themeCfg);
plotRef.current?.render();
}, [data, xField, yField, showLegend, type, isCount]);

useEffect(() => {
if (theme && plotRef.current) {
const themeCfg = getChartTheme(theme) as Record<string, any>;
plotRef.current.theme(themeCfg);

plotRef.current.render();
}
}, [theme]);
}, [data, xField, yField, showLegend, type, isCount, theme]);

useEffect(() => {
if (height && width && plotRef.current) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ const Pie = ({ className, theme, height, width, data = [], angleField, colorFiel
],
};

const themeCfg = getChartTheme(theme) as Record<string, any>;

if (!plotRef.current) {
const chart = new Chart({
container: containerRef.current!,
Expand All @@ -54,7 +56,6 @@ const Pie = ({ className, theme, height, width, data = [], angleField, colorFiel
padding: 30,
});

const themeCfg = getChartTheme(theme) as Record<string, any>;
chart.theme(themeCfg);

chart.options({
Expand All @@ -79,24 +80,17 @@ const Pie = ({ className, theme, height, width, data = [], angleField, colorFiel
type: 'view',
children: [{ ...commConfig }],
});

plotRef.current?.theme(themeCfg);
plotRef.current?.render();
}, [data, angleField, colorField, showLegend, isCount]);
}, [data, angleField, colorField, showLegend, isCount, theme]);

useEffect(() => {
if (height && width && plotRef.current) {
plotRef.current.forceFit();
}
}, [height, width]);

useEffect(() => {
if (theme && plotRef.current) {
const themeCfg = getChartTheme(theme) as Record<string, any>;
plotRef.current.theme(themeCfg);

plotRef.current.render();
}
}, [theme]);

useEffect(() => {
// 组件销毁时销毁图表
return () => {
Expand Down

0 comments on commit 6dd2258

Please sign in to comment.