Skip to content

Commit 6cc5441

Browse files
committed
fix: fix vue waring
1 parent c9116e3 commit 6cc5441

File tree

52 files changed

+236
-102
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

52 files changed

+236
-102
lines changed

__tests__/index.spec.ts renamed to __tests__/index.spec.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,6 @@ import * as components from '../src'
33
describe('index.tsx', () => {
44
it('component exported', () => {
55
expect(components).toBeTruthy()
6+
expect(components).toHaveProperty('LineChart')
67
})
78
})

__tests__/plots/area.spec.tsx

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import { mount } from '@vue/test-utils'
2+
import AreaChart from '../../src/plots/area'
3+
4+
describe('AreaChart', () => {
5+
test('should render without crashed', () => {
6+
mount(AreaChart, {
7+
props: {
8+
data: [],
9+
xField: 'a',
10+
yField: 'b',
11+
},
12+
})
13+
})
14+
})

__tests__/plots/line.spec.tsx

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
import { mount } from '@vue/test-utils'
2+
import LineChart from '../../src/plots/line'
3+
4+
describe('LineChart', () => {
5+
test('render without crashed', () => {
6+
mount(LineChart, {
7+
props: {
8+
data: [],
9+
},
10+
})
11+
})
12+
13+
test('test update config and data', async () => {
14+
const handleLineClick1 = () => {
15+
console.log(1)
16+
}
17+
const handleLineClick2 = () => {
18+
console.log(2)
19+
}
20+
const wrapper = mount(LineChart, {
21+
props: {
22+
data: null,
23+
},
24+
})
25+
26+
await wrapper.setProps({
27+
forceFit: true,
28+
data: [],
29+
})
30+
await wrapper.setProps({
31+
forceFit: true,
32+
data: null,
33+
})
34+
35+
await wrapper.setProps({
36+
forceFit: true,
37+
data: [{ x: 1 }],
38+
})
39+
40+
await wrapper.setProps({
41+
forceFit: true,
42+
data: [{ x: 2 }],
43+
})
44+
45+
await wrapper.setProps({
46+
forceFit: true,
47+
})
48+
49+
await wrapper.setProps({
50+
data: [],
51+
forceFit: true,
52+
xAxis: {
53+
visible: true,
54+
},
55+
events: {
56+
onLineClick: handleLineClick1,
57+
},
58+
})
59+
60+
await wrapper.setProps({
61+
data: [],
62+
forceFit: true,
63+
xAxis: {
64+
visible: true,
65+
},
66+
events: {
67+
onLineClick: handleLineClick2,
68+
},
69+
})
70+
71+
await wrapper.setProps({
72+
data: [],
73+
forceFit: true,
74+
xAxis: {
75+
visible: true,
76+
},
77+
events: {
78+
onLineClick: handleLineClick2,
79+
},
80+
})
81+
82+
wrapper.unmount()
83+
})
84+
})

package-lock.json

Lines changed: 6 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
"dev": "vitepress --root ./docs",
2323
"lint": "eslint . --ext=.ts,.tsx",
2424
"lint:fix": "eslint . --ext=.ts,.tsx --fix",
25-
"test": "jest -u",
25+
"test": "jest",
2626
"prebuild": "npm test",
2727
"build": "npm run build:es & npm run build:commonjs & npm run build:types",
2828
"build:es": "babel src -d es --extensions .ts,.tsx --delete-dir-on-start",
@@ -62,6 +62,7 @@
6262
"@typescript-eslint/eslint-plugin": "^3.9.1",
6363
"@typescript-eslint/parser": "^3.9.1",
6464
"@vue/babel-preset-app": "^4.5.4",
65+
"@vue/test-utils": "^2.0.0-beta.3",
6566
"babel-eslint": "^10.1.0",
6667
"canvas": "^2.6.1",
6768
"conventional-changelog-cli": "^2.1.0",

src/components/base.tsx

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,38 +27,44 @@ export interface BaseChartRawBindings<C extends PlotConfig> {
2727
getChartConfig: () => ChartOptions
2828
}
2929

30-
export default defineComponent<BaseChartProps<any>, BaseChartRawBindings<any>>({
30+
const BaseChart = defineComponent<
31+
BaseChartProps<any>,
32+
BaseChartRawBindings<any>
33+
>({
34+
inheritAttrs: false,
3135
name: 'BaseChart',
3236
mounted() {
3337
const { chart: Chart } = this.$attrs as Record<string, any>
3438
const { data, config } = this.getChartConfig()
3539
this.config = cloneDeep(config)
3640
const normalizedData = data || []
3741
this.data = normalizedData
38-
const chart = new Chart(this.$el, {
42+
this.plot = new Chart(this.$el, {
3943
data: normalizedData,
4044
...config,
4145
})
42-
this.plot = chart
4346
this.plot.render()
4447
},
4548
beforeUpdate() {
4649
const { data, config } = this.getChartConfig()
4750
const normalizedData = data || []
51+
/* istanbul ignore else */
4852
if (this.plot) {
4953
if (!isEqual(config, this.config) || !this.data.length) {
5054
this.config = cloneDeep(config)
5155
this.plot.updateConfig({
52-
data,
56+
data: normalizedData,
5357
...config,
5458
})
5559
this.plot.render()
5660
} else {
5761
this.plot.changeData(normalizedData)
5862
}
63+
this.data = normalizedData
5964
}
6065
},
6166
beforeUnmount() {
67+
/* istanbul ignore else */
6268
if (this.plot) {
6369
this.plot.destroy()
6470
}
@@ -80,3 +86,5 @@ export default defineComponent<BaseChartProps<any>, BaseChartRawBindings<any>>({
8086
return <div />
8187
},
8288
})
89+
90+
export default BaseChart

src/plots/area/index.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ import BaseChart, { BaseChartProps } from '../../components/base'
55
export type AreaChartProps = Omit<BaseChartProps<AreaConfig>, 'chart'> &
66
AreaConfig
77

8-
const AreaChart = defineComponent<AreaChartProps>((_, ctx) => {
9-
return <BaseChart chart={Area} {...ctx.attrs} />
8+
const AreaChart = defineComponent<AreaChartProps>((props, ctx) => {
9+
return () => <BaseChart chart={Area} {...ctx.attrs} {...props} />
1010
})
1111

1212
export default AreaChart

src/plots/bar/index.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ import BaseChart, { BaseChartProps } from '../../components/base'
44

55
export type BarChartProps = Omit<BaseChartProps<BarConfig>, 'chart'> & BarConfig
66

7-
const BarChart = defineComponent<BarChartProps>((_, ctx) => {
8-
return <BaseChart chart={Bar} {...ctx.attrs} />
7+
const BarChart = defineComponent<BarChartProps>((props, ctx) => {
8+
return () => <BaseChart chart={Bar} {...ctx.attrs} {...props} />
99
})
1010

1111
export default BarChart

src/plots/bubble/index.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ import BaseChart, { BaseChartProps } from '../../components/base'
55
export type BubbleChartProps = Omit<BaseChartProps<BubbleConfig>, 'chart'> &
66
BubbleConfig
77

8-
const BubbleChart = defineComponent<BubbleChartProps>((_, ctx) => {
9-
return <BaseChart chart={Bubble} {...ctx.attrs} />
8+
const BubbleChart = defineComponent<BubbleChartProps>((props, ctx) => {
9+
return () => <BaseChart chart={Bubble} {...ctx.attrs} {...props} />
1010
})
1111

1212
export default BubbleChart

src/plots/bullet/index.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ import BaseChart, { BaseChartProps } from '../../components/base'
55
export type BulletChartProps = Omit<BaseChartProps<BulletConfig>, 'chart'> &
66
BulletConfig
77

8-
const BulletChart = defineComponent<BulletChartProps>((_, ctx) => {
9-
return <BaseChart chart={Bullet} {...ctx.attrs} />
8+
const BulletChart = defineComponent<BulletChartProps>((props, ctx) => {
9+
return () => <BaseChart chart={Bullet} {...ctx.attrs} {...props} />
1010
})
1111

1212
export default BulletChart

0 commit comments

Comments
 (0)