Subversion-Projekte lars-tiefland.ci

Revision

Details | Letzte Änderung | Log anzeigen | RSS feed

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