Skip to content
Open
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
@@ -0,0 +1,10 @@
{
"changes": [
{
"packageName": "@visactor/openinula-vchart",
"comment": "fix: honor the data prop when spec is supplied, including data-only updates",
"type": "patch"
}
],
"packageName": "@visactor/openinula-vchart"
}
2 changes: 1 addition & 1 deletion packages/openinula-vchart/src/VChart.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { BaseChartProps, createChart } from './charts/BaseChart';
import VChartCore from '@visactor/vchart';
export { VChartCore };

export type VChartProps = Omit<BaseChartProps, 'container' | 'data' | 'width' | 'height' | 'type'>;
export type VChartProps = Omit<BaseChartProps, 'container' | 'width' | 'height' | 'type'>;

export const VChart = createChart<VChartProps>('VChart', {
vchartConstructor: VChartCore
Expand Down
13 changes: 12 additions & 1 deletion packages/openinula-vchart/src/charts/BaseChart.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import type { IVChart, IData, IInitOption, ISpec, IVChartConstructor } from '@vi
import React, { useState, useEffect, useRef, useImperativeHandle, ReactNode } from 'openinula';
import withContainer, { ContainerProps } from '../containers/withContainer';
import RootChartContext, { ChartContextType } from '../context/chart';
import { isEqual, isNil, pickWithout } from '@visactor/vutils';
import { isEqual, isNil, isValid, pickWithout } from '@visactor/vutils';
import { toArray } from '../util';
import { REACT_PRIVATE_PROPS } from '../constants';
import {
Expand Down Expand Up @@ -137,6 +137,13 @@ const BaseChart: React.FC<Props> = React.forwardRef((props, ref) => {

if (hasSpec && props.spec) {
spec = props.spec;

if (isValid(props.data)) {
spec = {
...props.spec,
data: props.data
} as ISpec;
}
} else {
spec = {
...prevSpec.current,
Expand Down Expand Up @@ -209,6 +216,10 @@ const BaseChart: React.FC<Props> = React.forwardRef((props, ref) => {
enableExitAnimation: false
});
handleChartRender();
} else if (eventsBinded.current.data !== props.data) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[P2] 移除 data 属性后应恢复 spec.data

parseSpec 在 data 缺省时使用 spec.data,但 data 从有效值变为 undefined 时,这个分支会调用 updateFullDataSync(undefined),实际不会恢复 spec.data。

已复现:同一个 spec 对象内的数据为 [{ id: 'id0', values: [{ x: 'A', y: 1 }] }];首次用 data 属性覆盖为同 id、y:10;随后从 <VChart spec={spec} data={override} /> 更新为 <VChart spec={spec} />,图表仍显示 10,而重新挂载相同 props 会显示 1。

请在撤销可选 data 覆盖时重新解析有效 spec 并更新,使更新与首次渲染保持相同的数据优先级,同时加入撤销覆盖的回归测试。

chartContext.current.chart.updateFullDataSync(props.data as any);
Comment thread
xile611 marked this conversation as resolved.
handleChartRender();
eventsBinded.current = props;
}
return;
}
Expand Down
Loading