We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 93f7c30 commit 96d2714Copy full SHA for 96d2714
src/chart.tsx
@@ -26,6 +26,7 @@ function ChartComponent<
26
options,
27
plugins = [],
28
fallbackContent,
29
+ updateMode,
30
...props
31
}: ChartProps<TType, TData, TLabel>,
32
ref: ForwardedRef<ChartJS<TType, TData, TLabel>>
@@ -82,9 +83,9 @@ function ChartComponent<
82
83
destroyChart();
84
setTimeout(renderChart);
85
} else {
- chartRef.current.update();
86
+ chartRef.current.update(updateMode);
87
}
- }, [redraw, options, data.labels, data.datasets]);
88
+ }, [redraw, options, data.labels, data.datasets,updateMode]);
89
90
useEffect(() => {
91
renderChart();
src/types.ts
@@ -6,6 +6,7 @@ import type {
6
ChartOptions,
7
DefaultDataPoint,
8
Plugin,
9
+ UpdateMode,
10
} from 'chart.js';
11
12
export type ForwardedRef<T> =
@@ -56,6 +57,11 @@ export interface ChartProps<
56
57
* @todo Replace with `children` prop.
58
*/
59
fallbackContent?: ReactNode;
60
+ /**
61
+ * A mode string to indicate transition configuration should be used.
62
+ * @see https://www.chartjs.org/docs/latest/developers/api.html#update-mode
63
+ */
64
+ updateMode?: UpdateMode;
65
66
67
/**
test/chart.test.tsx
@@ -386,4 +386,34 @@ describe('<Chart />', () => {
386
expect(prevDataset1).toBe(nextDataset1);
387
expect(prevDataset2).toBe(nextDataset2);
388
});
389
+
390
+ it('should pass updateMode prop to update method', () => {
391
+ const newData = {
392
+ labels: ['purple', 'pink'],
393
+ datasets: [{ label: 'new-colors', data: [1, 10] }],
394
+ };
395
396
+ const { rerender } = render(
397
+ <Chart
398
+ data={data}
399
+ options={options}
400
+ type='bar'
401
+ updateMode='active'
402
+ ref={ref}
403
+ />
404
+ );
405
406
+ rerender(
407
408
+ data={newData}
409
410
411
412
413
414
415
416
+ expect(update).toHaveBeenCalledTimes(1);
417
+ expect(update).toBeCalledWith('active');
418
+ });
419
AltStyle によって変換されたページ (->オリジナル) / アドレス: モード: デフォルト 音声ブラウザ ルビ付き 配色反転 文字拡大 モバイル
0 commit comments