|
1 | 1 | (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'; |
8 | 6 |
|
9 | 7 | var ctors = { |
10 | 8 | Highcharts: 'chart', |
11 | 9 | Highstock: 'stockChart', |
12 | 10 | Highmaps: 'mapChart', |
13 | | - HighchartsGantt: 'ganttChart', |
| 11 | + HighchartsGantt: 'ganttChart' |
14 | 12 | }; |
15 | 13 |
|
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 | + }); |
41 | 18 | } |
42 | 19 |
|
43 | | - function create(name, Highcharts) { |
| 20 | + function createHighcharts(name, Highcharts) { |
44 | 21 | var ctor = Highcharts[ctors[name]]; |
| 22 | + |
45 | 23 | 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 | + }; |
52 | 30 | } |
| 31 | + |
53 | 32 | return { |
54 | 33 | 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 | + } |
78 | 54 | }; |
79 | 55 | } |
| 56 | + function install(app, options) { |
| 57 | + Object.keys(ctors).forEach(function (name) { |
| 58 | + var component = createHighcharts(name, options.Highcharts); |
80 | 59 |
|
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 | + }); |
91 | 64 | } |
92 | 65 |
|
| 66 | + exports.createHighcharts = createHighcharts; |
93 | 67 | exports.default = install; |
94 | | - exports.genComponent = create; |
95 | 68 |
|
96 | 69 | Object.defineProperty(exports, '__esModule', { value: true }); |
97 | 70 |
|
98 | | -})); |
| 71 | +}))); |
0 commit comments