1 | /**
|
2 | * @license Highcharts JS v5.0.0 (2016-09-29)
|
3 | * Plugin for displaying a message when there is no data visible in chart.
|
4 | *
|
5 | * (c) 2010-2016 Highsoft AS
|
6 | * Author: Oystein Moseng
|
7 | *
|
8 | * License: www.highcharts.com/license
|
9 | */
|
10 | (function(factory) {
|
11 | if (typeof module === 'object' && module.exports) {
|
12 | module.exports = factory;
|
13 | } else {
|
14 | factory(Highcharts);
|
15 | }
|
16 | }(function(Highcharts) {
|
17 | (function(H) {
|
18 | /**
|
19 | * Plugin for displaying a message when there is no data visible in chart.
|
20 | *
|
21 | * (c) 2010-2016 Highsoft AS
|
22 | * Author: Oystein Moseng
|
23 | *
|
24 | * License: www.highcharts.com/license
|
25 | */
|
26 | ;
|
27 |
|
28 | var seriesTypes = H.seriesTypes,
|
29 | chartPrototype = H.Chart.prototype,
|
30 | defaultOptions = H.getOptions(),
|
31 | extend = H.extend,
|
32 | each = H.each;
|
33 |
|
34 | // Add language option
|
35 | extend(defaultOptions.lang, {
|
36 | noData: 'No data to display'
|
37 | });
|
38 |
|
39 | // Add default display options for message
|
40 | defaultOptions.noData = {
|
41 | position: {
|
42 | x: 0,
|
43 | y: 0,
|
44 | align: 'center',
|
45 | verticalAlign: 'middle'
|
46 | }
|
47 | // useHTML: false
|
48 | };
|
49 |
|
50 |
|
51 |
|
52 | /**
|
53 | * Define hasData functions for series. These return true if there are data points on this series within the plot area
|
54 | */
|
55 | function hasDataPie() {
|
56 | return !!this.points.length; /* != 0 */
|
57 | }
|
58 |
|
59 | each(['pie', 'gauge', 'waterfall', 'bubble', 'treemap'], function(type) {
|
60 | if (seriesTypes[type]) {
|
61 | seriesTypes[type].prototype.hasData = hasDataPie;
|
62 | }
|
63 | });
|
64 |
|
65 | H.Series.prototype.hasData = function() {
|
66 | return this.visible && this.dataMax !== undefined && this.dataMin !== undefined; // #3703
|
67 | };
|
68 |
|
69 | /**
|
70 | * Display a no-data message.
|
71 | *
|
72 | * @param {String} str An optional message to show in place of the default one
|
73 | */
|
74 | chartPrototype.showNoData = function(str) {
|
75 | var chart = this,
|
76 | options = chart.options,
|
77 | text = str || options.lang.noData,
|
78 | noDataOptions = options.noData;
|
79 |
|
80 | if (!chart.noDataLabel) {
|
81 | chart.noDataLabel = chart.renderer
|
82 | .label(
|
83 | text,
|
84 | 0,
|
85 | 0,
|
86 | null,
|
87 | null,
|
88 | null,
|
89 | noDataOptions.useHTML,
|
90 | null,
|
91 | 'no-data'
|
92 | );
|
93 |
|
94 |
|
95 |
|
96 | chart.noDataLabel.add();
|
97 |
|
98 | chart.noDataLabel.align(extend(chart.noDataLabel.getBBox(), noDataOptions.position), false, 'plotBox');
|
99 | }
|
100 | };
|
101 |
|
102 | /**
|
103 | * Hide no-data message
|
104 | */
|
105 | chartPrototype.hideNoData = function() {
|
106 | var chart = this;
|
107 | if (chart.noDataLabel) {
|
108 | chart.noDataLabel = chart.noDataLabel.destroy();
|
109 | }
|
110 | };
|
111 |
|
112 | /**
|
113 | * Returns true if there are data points within the plot area now
|
114 | */
|
115 | chartPrototype.hasData = function() {
|
116 | var chart = this,
|
117 | series = chart.series,
|
118 | i = series.length;
|
119 |
|
120 | while (i--) {
|
121 | if (series[i].hasData() && !series[i].options.isInternal) {
|
122 | return true;
|
123 | }
|
124 | }
|
125 |
|
126 | return false;
|
127 | };
|
128 |
|
129 | /**
|
130 | * Show no-data message if there is no data in sight. Otherwise, hide it.
|
131 | */
|
132 | function handleNoData() {
|
133 | var chart = this;
|
134 | if (chart.hasData()) {
|
135 | chart.hideNoData();
|
136 | } else {
|
137 | chart.showNoData();
|
138 | }
|
139 | }
|
140 |
|
141 | /**
|
142 | * Add event listener to handle automatic display of no-data message
|
143 | */
|
144 | chartPrototype.callbacks.push(function(chart) {
|
145 | H.addEvent(chart, 'load', handleNoData);
|
146 | H.addEvent(chart, 'redraw', handleNoData);
|
147 | });
|
148 |
|
149 | }(Highcharts));
|
150 | }));
|