Skip to content

Commit 3a4ae29

Browse files
committed
0.2.0
1 parent 1040daf commit 3a4ae29

File tree

3 files changed

+49
-76
lines changed

3 files changed

+49
-76
lines changed

dist/vue-highcharts.js

Lines changed: 47 additions & 74 deletions
Original file line numberDiff line numberDiff line change
@@ -1,98 +1,71 @@
11
(function (global, factory) {
2-
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('highcharts')) :
3-
typeof define === 'function' && define.amd ? define(['exports', 'highcharts'], factory) :
4-
(global = global || self, factory(global.VueHighcharts = {}, global.Highcharts));
5-
}(this, function (exports, HighchartsOnly) { 'use strict';
6-
7-
HighchartsOnly = HighchartsOnly && HighchartsOnly.hasOwnProperty('default') ? HighchartsOnly['default'] : HighchartsOnly;
2+
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('vue')) :
3+
typeof define === 'function' && define.amd ? define(['exports', 'vue'], factory) :
4+
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.VueHighcharts = {}, global.Vue));
5+
}(this, (function (exports, vue) { 'use strict';
86

97
var ctors = {
108
Highcharts: 'chart',
119
Highstock: 'stockChart',
1210
Highmaps: 'mapChart',
13-
HighchartsGantt: 'ganttChart',
11+
HighchartsGantt: 'ganttChart'
1412
};
1513

16-
// eslint-disable-next-line consistent-return
17-
function clone(obj) {
18-
var copy;
19-
if (obj === null || typeof obj !== 'object') {
20-
return obj;
21-
}
22-
if (obj instanceof Array) {
23-
copy = [];
24-
for (var i = obj.length - 1; i >= 0; i--) {
25-
copy[i] = clone(obj[i]);
26-
}
27-
return copy;
28-
}
29-
/* istanbul ignore else */
30-
if (obj instanceof Object) {
31-
copy = {};
32-
for (var key in obj) {
33-
copy[key] = clone(obj[key]);
34-
}
35-
return copy;
36-
}
37-
}
38-
39-
function render(createElement) {
40-
return createElement('div');
14+
function render() {
15+
return vue.h('div', {
16+
ref: 'highchartsRef'
17+
});
4118
}
4219

43-
function create(name, Highcharts) {
20+
function createHighcharts(name, Highcharts) {
4421
var ctor = Highcharts[ctors[name]];
22+
4523
if (!ctor) {
46-
return Highcharts.win
47-
? null
48-
// When running in server, Highcharts will not be instanced,
49-
// so there're no constructors in Highcharts,
50-
// to avoid unmated content during SSR, it returns minimum component.
51-
: { render: render };
24+
return Highcharts.win ? null // When running in server, Highcharts will not be instanced,
25+
// so there're no constructors in Highcharts,
26+
// to avoid unmated content during SSR, it returns minimum component.
27+
: {
28+
render: render
29+
};
5230
}
31+
5332
return {
5433
name: name,
55-
props: {
56-
options: { type: Object, required: true }
57-
},
58-
watch: {
59-
options: {
60-
handler: function () {
61-
this.$_h_render();
62-
},
63-
deep: true
64-
}
65-
},
66-
mounted: function () {
67-
this.$_h_render();
68-
},
69-
beforeDestroy: function () {
70-
this.chart.destroy();
71-
},
72-
methods: {
73-
$_h_render: function () {
74-
this.chart = ctor(this.$el, clone(this.options));
75-
}
76-
},
77-
render: render
34+
props: ['options'],
35+
render: render,
36+
setup: function setup(props) {
37+
var highchartsRef = vue.ref(null);
38+
var chart = vue.ref(null);
39+
vue.onMounted(function () {
40+
vue.watchEffect(function () {
41+
chart.value = ctor(highchartsRef.value, props.options);
42+
});
43+
});
44+
vue.onBeforeUnmount(function () {
45+
if (highchartsRef.value) {
46+
chart.value.destroy();
47+
}
48+
});
49+
return {
50+
highchartsRef: highchartsRef,
51+
chart: chart
52+
};
53+
}
7854
};
7955
}
56+
function install(app, options) {
57+
Object.keys(ctors).forEach(function (name) {
58+
var component = createHighcharts(name, options.Highcharts);
8059

81-
function install(Vue, options) {
82-
var Highcharts = (options && options.Highcharts) || HighchartsOnly;
83-
for (var name in ctors) {
84-
var component = create(name, Highcharts);
85-
component && Vue.component(name, component);
86-
}
87-
}
88-
89-
if (typeof window !== 'undefined' && window.Vue && window.Highcharts) {
90-
install(window.Vue, window.Highcharts);
60+
if (component) {
61+
app.component(name, component);
62+
}
63+
});
9164
}
9265

66+
exports.createHighcharts = createHighcharts;
9367
exports.default = install;
94-
exports.genComponent = create;
9568

9669
Object.defineProperty(exports, '__esModule', { value: true });
9770

98-
}));
71+
})));

dist/vue-highcharts.min.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.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "vue-highcharts",
3-
"version": "0.1.0",
3+
"version": "0.2.0",
44
"description": "Highcharts component for Vue",
55
"main": "dist/vue-highcharts.js",
66
"module": "index.js",

0 commit comments

Comments
 (0)