|
1 | 1 | (function (global, factory) {
|
2 |
| - typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory(require('highcharts')) : |
3 |
| - typeof define === 'function' && define.amd ? define(['highcharts'], factory) : |
4 |
| - (global.VueHighcharts = factory(global.Highcharts)); |
5 |
| -}(this, (function (HighchartsOnly) { 'use strict'; |
| 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 | 6 |
|
7 |
| -HighchartsOnly = HighchartsOnly && HighchartsOnly.hasOwnProperty('default') ? HighchartsOnly['default'] : HighchartsOnly; |
| 7 | + HighchartsOnly = HighchartsOnly && HighchartsOnly.hasOwnProperty('default') ? HighchartsOnly['default'] : HighchartsOnly; |
8 | 8 |
|
9 |
| -var ctors = { |
10 |
| - Highcharts: 'Chart', |
11 |
| - Highstock: 'StockChart', |
12 |
| - Highmaps: 'Map', |
13 |
| - HighchartsRenderer: 'Renderer' |
14 |
| -}; |
| 9 | + var ctors = { |
| 10 | + Highcharts: 'chart', |
| 11 | + Highstock: 'stockChart', |
| 12 | + Highmaps: 'mapChart', |
| 13 | + HighchartsGantt: 'ganttChart', |
| 14 | + }; |
15 | 15 |
|
16 |
| -function clone(obj) { |
17 |
| - var copy; |
18 |
| - if (obj === null || typeof obj !== 'object') { |
19 |
| - return obj; |
20 |
| - } |
21 |
| - if (obj instanceof Array) { |
22 |
| - copy = []; |
23 |
| - for (var i = obj.length - 1; i >= 0; i--) { |
24 |
| - copy[i] = clone(obj[i]); |
| 16 | + // eslint-disable-next-line consistent-return |
| 17 | + function clone(obj) { |
| 18 | + var copy; |
| 19 | + if (obj === null || typeof obj !== 'object') { |
| 20 | + return obj; |
25 | 21 | }
|
26 |
| - return copy; |
27 |
| - } |
28 |
| - /* istanbul ignore else */ |
29 |
| - if (obj instanceof Object) { |
30 |
| - copy = {}; |
31 |
| - for (var key in obj) { |
32 |
| - copy[key] = clone(obj[key]); |
| 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; |
33 | 36 | }
|
34 |
| - return copy; |
35 | 37 | }
|
36 |
| -} |
37 |
| - |
38 |
| -function render(createElement) { |
39 |
| - return createElement('div'); |
40 |
| -} |
41 | 38 |
|
42 |
| -function create(tagName, Highcharts, Vue) { |
43 |
| - var Ctor = Highcharts[ctors[tagName]]; |
44 |
| - if (!Ctor) { |
45 |
| - return Highcharts.win |
46 |
| - ? null |
47 |
| - // When running in server, Highcharts will not be instanced, |
48 |
| - // so there're no constructors in Highcharts, |
49 |
| - // to avoid unmated content during SSR, it returns minimum component. |
50 |
| - : { render: render }; |
| 39 | + function render(createElement) { |
| 40 | + return createElement('div'); |
51 | 41 | }
|
52 |
| - var isRenderer = tagName === 'HighchartsRenderer'; |
53 |
| - var component = { |
54 |
| - name: tagName, |
55 |
| - props: isRenderer |
56 |
| - ? { |
57 |
| - width: { type: Number, required: true }, |
58 |
| - height: { type: Number, required: true } |
59 |
| - } |
60 |
| - : { options: { type: Object, required: true } }, |
61 |
| - methods: { |
62 |
| - _initChart: function() { |
63 |
| - this._renderChart(); |
64 |
| - if (isRenderer) { |
65 |
| - this.$watch('width', this._renderChart); |
66 |
| - this.$watch('height', this._renderChart); |
67 |
| - } else { |
68 |
| - this.$watch('options', this._renderChart, { deep: true }); |
69 |
| - } |
| 42 | + |
| 43 | + function create(name, Highcharts) { |
| 44 | + var ctor = Highcharts[ctors[name]]; |
| 45 | + 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 }; |
| 52 | + } |
| 53 | + return { |
| 54 | + name: name, |
| 55 | + props: { |
| 56 | + options: { type: Object, required: true } |
70 | 57 | },
|
71 |
| - _renderChart: function() { |
72 |
| - if (isRenderer) { |
73 |
| - this.renderer && this.$el.removeChild(this.renderer.box); |
74 |
| - this.renderer = new Ctor(this.$el, this.width, this.height); |
75 |
| - } else { |
76 |
| - this.chart = new Ctor(this.$el, clone(this.options)); |
77 |
| - } |
78 |
| - } |
79 |
| - }, |
80 |
| - beforeDestroy: function() { |
81 |
| - if (isRenderer) { |
82 |
| - this.$el.removeChild(this.renderer.box); |
83 |
| - for (var property in this.renderer) { |
84 |
| - delete this.renderer[property]; |
| 58 | + watch: { |
| 59 | + options: { |
| 60 | + handler: function () { |
| 61 | + this.$_h_render(); |
| 62 | + }, |
| 63 | + deep: true |
85 | 64 | }
|
86 |
| - this.renderer = null; |
87 |
| - } else { |
| 65 | + }, |
| 66 | + mounted: function () { |
| 67 | + this.$_h_render(); |
| 68 | + }, |
| 69 | + beforeDestroy: function () { |
88 | 70 | this.chart.destroy();
|
89 |
| - } |
90 |
| - } |
91 |
| - }; |
92 |
| - var isVue1 = /^1\./.test(Vue.version); |
93 |
| - if (isVue1) { |
94 |
| - component.template = '<div></div>'; |
95 |
| - component.ready = function() { |
96 |
| - this._initChart(); |
97 |
| - }; |
98 |
| - } else { |
99 |
| - component.render = render; |
100 |
| - component.mounted = function() { |
101 |
| - this._initChart(); |
| 71 | + }, |
| 72 | + methods: { |
| 73 | + $_h_render: function () { |
| 74 | + this.chart = ctor(this.$el, clone(this.options)); |
| 75 | + } |
| 76 | + }, |
| 77 | + render: render |
102 | 78 | };
|
103 | 79 | }
|
104 |
| - return component; |
105 |
| -} |
106 | 80 |
|
107 |
| -function install(Vue, options) { |
108 |
| - var Highcharts = (options && options.Highcharts) || HighchartsOnly; |
109 |
| - Vue.prototype.Highcharts = Highcharts; |
110 |
| - for (var tagName in ctors) { |
111 |
| - var component = create(tagName, Highcharts, Vue); |
112 |
| - component && Vue.component(tagName, component); |
| 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); |
113 | 91 | }
|
114 |
| -} |
115 | 92 |
|
116 |
| -return install; |
| 93 | + exports.default = install; |
| 94 | + exports.genComponent = create; |
| 95 | + |
| 96 | + Object.defineProperty(exports, '__esModule', { value: true }); |
117 | 97 |
|
118 |
| -}))); |
| 98 | +})); |
0 commit comments