Skip to content

Commit 655abfa

Browse files
authored
Merge pull request #12 from ambit-tsai/dev
fix: call `setOption` after rendering
2 parents 48791ba + f77ac01 commit 655abfa

File tree

6 files changed

+40
-45
lines changed

6 files changed

+40
-45
lines changed

docs/main.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/ECharts.js

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -69,10 +69,11 @@ export function createComponent({
6969

7070
watch: {
7171
loading(val) {
72+
const ctx = this;
7273
if (val) {
73-
this.inst.showLoading(this.loadingType, this.loadingOpts);
74+
ctx.inst.showLoading(ctx.loadingType, ctx.loadingOpts);
7475
} else {
75-
this.inst.hideLoading();
76+
ctx.inst.hideLoading();
7677
}
7778
},
7879

@@ -118,13 +119,17 @@ export function createComponent({
118119
}
119120

120121

122+
123+
const style = {
124+
height: '100%',
125+
overflow: 'hidden',
126+
};
127+
128+
121129
function vue2Render(h) {
122130
return h('div', {
123131
attrs: this.$attrs,
124-
style: {
125-
height: '100%',
126-
overflow: 'hidden',
127-
},
132+
style,
128133
});
129134
}
130135

@@ -133,10 +138,7 @@ function getVue3Render(h) {
133138
return function () {
134139
return h('div', {
135140
...this.$attrs,
136-
style: {
137-
height: '100%',
138-
overflow: 'hidden',
139-
},
141+
style,
140142
});
141143
};
142144
}

src/LifecycleHooks.js

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,20 +2,23 @@
22
export function getHooks(echarts) {
33
return {
44
mounted() {
5-
const inst = echarts.init(this.$el, this.initTheme, this.initOpts);
6-
this.$data._private.dynamic.inst = inst;
7-
8-
if (this.loading) {
9-
inst.showLoading(this.loadingType, this.loadingOpts)
5+
const ctx = this;
6+
const inst = echarts.init(ctx.$el, ctx.initTheme, ctx.initOpts);
7+
ctx.$data._private.dynamic.inst = inst;
8+
if (ctx.loading) {
9+
inst.showLoading(ctx.loadingType, ctx.loadingOpts)
1010
}
11-
if (this.option) {
12-
this.setOption(this.option, this.setOptionOpts);
11+
if (ctx.events) {
12+
ctx.events.forEach(args => inst.on.apply(inst, args));
1313
}
14-
if (this.events) {
15-
this.events.forEach(args => inst.on(...args));
14+
if (ctx.autoResize) {
15+
ctx.addResizeListener();
1616
}
17-
if (this.autoResize) {
18-
this.addResizeListener();
17+
if (ctx.option) {
18+
// Wait for rendering
19+
setTimeout(() => {
20+
ctx.setOption(ctx.option, ctx.setOptionOpts);
21+
});
1922
}
2023
},
2124

src/ResizeObserverSham.js

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
11

2-
export default typeof ResizeObserver === 'function'
3-
? ResizeObserver
4-
: class ResizeObserverSham {
5-
constructor() {
6-
console.warn('[ECharts-For-Vue] "autoResize" is invalid, you need a ResizeObserver polyfill');
7-
}
2+
function ResizeObserverSham() {
3+
console.warn('[ECharts-For-Vue] "autoResize" is invalid, you need a ResizeObserver polyfill');
4+
}
85

9-
disconnect() {}
6+
const noop = () => {};
7+
ResizeObserverSham.prototype.disconnect = noop;
8+
ResizeObserverSham.prototype.observe = noop;
109

11-
observe() {}
12-
}
10+
11+
export default typeof ResizeObserver === 'function' ? ResizeObserver : ResizeObserverSham;

test/vue2-echarts3/src/App.vue

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@
44
class="chart"
55
ref="chart"
66
:option="option"
7-
:setOptionOpts="{ notMerge: false }"
7+
:setOptionOpts="{ notMerge: true }"
88
:loading="loading"
9-
:loadingOpts="{ text: 'Wait for 0.8s' }"
9+
:loadingOpts="{ text: 'Wait for 0.5s' }"
1010
:events="[
1111
['dblclick', onDblclick],
1212
]"
@@ -37,15 +37,8 @@ export default {
3737
this.loading = true;
3838
setTimeout(() => {
3939
this.option = this.option === Option1 ? Option2 : Option1;
40-
this.option = {
41-
series: [{
42-
data: Option2.series[0].data.sort(() => Math.random() - .5),
43-
}, {
44-
data: Option2.series[1].data.sort(() => Math.random() - .5),
45-
}],
46-
};
4740
this.loading = false;
48-
}, 100);
41+
}, 500);
4942
},
5043
onDblclick() {
5144
alert('The listener is triggered');

test/vue2-echarts3/src/options.js

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -72,10 +72,8 @@ export const Option1 = Object.freeze({
7272
type: 'line',
7373
stack: '总量',
7474
label: {
75-
normal: {
76-
show: true,
77-
position: 'top'
78-
}
75+
show: true,
76+
position: 'top',
7977
},
8078
areaStyle: {},
8179
data: [820, 932, 901, 934, 1290, 1330, 1320]

0 commit comments

Comments
 (0)