diff --git a/common/changes/@visactor/openinula-vchart/fix-data-prop-with-spec-4657.json b/common/changes/@visactor/openinula-vchart/fix-data-prop-with-spec-4657.json new file mode 100644 index 0000000000..9cb61a6d02 --- /dev/null +++ b/common/changes/@visactor/openinula-vchart/fix-data-prop-with-spec-4657.json @@ -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" +} diff --git a/packages/openinula-vchart/src/VChart.tsx b/packages/openinula-vchart/src/VChart.tsx index 98f24b3493..cee4a88992 100644 --- a/packages/openinula-vchart/src/VChart.tsx +++ b/packages/openinula-vchart/src/VChart.tsx @@ -2,7 +2,7 @@ import { BaseChartProps, createChart } from './charts/BaseChart'; import VChartCore from '@visactor/vchart'; export { VChartCore }; -export type VChartProps = Omit; +export type VChartProps = Omit; export const VChart = createChart('VChart', { vchartConstructor: VChartCore diff --git a/packages/openinula-vchart/src/charts/BaseChart.tsx b/packages/openinula-vchart/src/charts/BaseChart.tsx index 36c57d2fc6..61db08625e 100644 --- a/packages/openinula-vchart/src/charts/BaseChart.tsx +++ b/packages/openinula-vchart/src/charts/BaseChart.tsx @@ -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 { @@ -137,6 +137,13 @@ const BaseChart: React.FC = 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, @@ -209,6 +216,10 @@ const BaseChart: React.FC = React.forwardRef((props, ref) => { enableExitAnimation: false }); handleChartRender(); + } else if (eventsBinded.current.data !== props.data) { + chartContext.current.chart.updateFullDataSync(props.data as any); + handleChartRender(); + eventsBinded.current = props; } return; }