File tree 2 files changed +9
-2
lines changed
2 files changed +9
-2
lines changed Original file line number Diff line number Diff line change 1
1
import { ref } from 'vue'
2
2
import { mount } from '@vue/test-utils'
3
3
import LineChart from '../../src/plots/line'
4
+ import { LineOptions , Plot } from '@antv/g2plot'
4
5
5
6
describe ( 'LineChart' , ( ) => {
6
7
test ( 'render without crashed' , ( ) => {
7
8
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 } /> )
9
13
10
14
expect ( chartRef . value ) . toBeDefined ( )
11
15
} )
Original file line number Diff line number Diff line change @@ -21,6 +21,7 @@ export interface BaseChartProps<C extends Options>
21
21
chart : any
22
22
data : Data
23
23
chartRef ?: Ref < BasePlot < C > | null >
24
+ onReady ?: ( plot : BasePlot < C > ) => void
24
25
}
25
26
26
27
interface ComputedOptions < C extends Options > {
@@ -57,14 +58,15 @@ const BaseChart = defineComponent<
57
58
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
58
59
// @ts -ignore
59
60
style,
61
+ onReady,
60
62
...config
61
63
} = this . attrConfig
62
64
return config
63
65
} ,
64
66
} ,
65
67
mounted ( ) {
66
68
const chartRef = this . $attrs . chartRef as Ref < BasePlot < any > | null >
67
- const { chart : Chart } = this . attrConfig
69
+ const { chart : Chart , onReady } = this . attrConfig
68
70
const plot = new Chart ( this . $el as HTMLElement , {
69
71
data : this . chartData ,
70
72
...this . chartConfig ,
@@ -74,6 +76,7 @@ const BaseChart = defineComponent<
74
76
chartRef . value = plot
75
77
}
76
78
this . plot = plot
79
+ onReady ?.( plot )
77
80
} ,
78
81
beforeUnmount ( ) {
79
82
/* istanbul ignore else */
You can’t perform that action at this time.
0 commit comments