|
6 | 6 |
|
7 | 7 | HighchartsOnly = 'default' in HighchartsOnly ? HighchartsOnly['default'] : HighchartsOnly; |
8 | 8 |
|
| 9 | +var ctors = { |
| 10 | + highcharts: 'Chart', |
| 11 | + highstock: 'StockChart', |
| 12 | + highmaps: 'Map', |
| 13 | + 'highcharts-renderer': 'Renderer' |
| 14 | +}; |
| 15 | + |
9 | 16 | function create(tagName, Highcharts) { |
10 | | - var ctors = { |
11 | | - highcharts: 'Chart', |
12 | | - highstock: 'StockChart', |
13 | | - highmaps: 'Map' |
14 | | - }; |
15 | 17 | var Ctor = Highcharts[ctors[tagName]]; |
16 | 18 | if (!Ctor) { |
17 | 19 | return null; |
18 | 20 | } |
| 21 | + var isRenderer = tagName === 'highcharts-renderer'; |
19 | 22 | return { |
20 | 23 | name: tagName, |
21 | 24 | template: '<div></div>', |
22 | | - props: { |
23 | | - options: Object |
24 | | - }, |
| 25 | + props: isRenderer |
| 26 | + ? { |
| 27 | + width: { type: Number, required: true }, |
| 28 | + height: { type: Number, required: true } |
| 29 | + } |
| 30 | + : { options: { type: Object, required: true } }, |
25 | 31 | methods: { |
26 | | - render: function(options) { |
27 | | - var opts = options || {}; |
28 | | - opts.chart = opts.chart || {}; |
29 | | - opts.chart.renderTo = this.$el; |
30 | | - this._chart = new Ctor(opts); |
| 32 | + _renderChart: function() { |
| 33 | + if (isRenderer) { |
| 34 | + this.renderer = new Ctor(this.$el, this.width, this.height); |
| 35 | + } else { |
| 36 | + var opts = JSON.parse(JSON.stringify(this.options)); |
| 37 | + opts.chart = opts.chart || {}; |
| 38 | + opts.chart.renderTo = this.$el; |
| 39 | + this.chart = new Ctor(opts); |
| 40 | + } |
31 | 41 | } |
32 | 42 | }, |
33 | 43 | mounted: function() { |
34 | | - this.render(this.options); |
| 44 | + this._renderChart(); |
35 | 45 | }, |
36 | 46 | beforeDestroy: function() { |
37 | | - this._chart.destroy(); |
| 47 | + !isRenderer && this.chart.destroy(); |
38 | 48 | } |
39 | 49 | }; |
40 | 50 | } |
41 | 51 |
|
42 | 52 | function install(Vue, options) { |
43 | 53 | var Highcharts = (options && options.Highcharts) || HighchartsOnly; |
44 | 54 | Vue.prototype.Highcharts = Highcharts; |
45 | | - ['highcharts', 'highstock', 'highmaps'].forEach(function(tagName) { |
| 55 | + for (var tagName in ctors) { |
46 | 56 | var component = create(tagName, Highcharts); |
47 | 57 | component && Vue.component(tagName, component); |
48 | | - }); |
| 58 | + } |
49 | 59 | } |
50 | 60 |
|
51 | 61 | return install; |
|
0 commit comments