File tree Expand file tree Collapse file tree 2 files changed +9
-2
lines changed Expand file tree Collapse file tree 2 files changed +9
-2
lines changed Original file line number Diff line number Diff line change 11import { ref } from 'vue'
22import { mount } from '@vue/test-utils'
33import LineChart from '../../src/plots/line'
4+ import { LineOptions , Plot } from '@antv/g2plot'
45
56describe ( 'LineChart' , ( ) => {
67 test ( 'render without crashed' , ( ) => {
78 const chartRef = ref ( null )
8- mount ( < LineChart data = { [ ] } chartRef = { chartRef } /> )
9+ const onReady = ( plot : Plot < LineOptions > ) => {
10+ expect ( plot ) . toBeDefined ( )
11+ }
12+ mount ( < LineChart data = { [ ] } chartRef = { chartRef } onReady = { onReady } /> )
913
1014 expect ( chartRef . value ) . toBeDefined ( )
1115 } )
Original file line number Diff line number Diff line change @@ -21,6 +21,7 @@ export interface BaseChartProps<C extends Options>
2121 chart : any
2222 data : Data
2323 chartRef ?: Ref < BasePlot < C > | null >
24+ onReady ?: ( plot : BasePlot < C > ) => void
2425}
2526
2627interface ComputedOptions < C extends Options > {
@@ -57,14 +58,15 @@ const BaseChart = defineComponent<
5758 // eslint-disable-next-line @typescript-eslint/ban-ts-comment
5859 // @ts -ignore
5960 style,
61+ onReady,
6062 ...config
6163 } = this . attrConfig
6264 return config
6365 } ,
6466 } ,
6567 mounted ( ) {
6668 const chartRef = this . $attrs . chartRef as Ref < BasePlot < any > | null >
67- const { chart : Chart } = this . attrConfig
69+ const { chart : Chart , onReady } = this . attrConfig
6870 const plot = new Chart ( this . $el as HTMLElement , {
6971 data : this . chartData ,
7072 ...this . chartConfig ,
@@ -74,6 +76,7 @@ const BaseChart = defineComponent<
7476 chartRef . value = plot
7577 }
7678 this . plot = plot
79+ onReady ?.( plot )
7780 } ,
7881 beforeUnmount ( ) {
7982 /* istanbul ignore else */
You can’t perform that action at this time.
0 commit comments