~jstys-z/helioviewer.org/timeline

« back to all changes in this revision

Viewing changes to timeline/Highstock-1.3.10/js/modules/no-data-to-display.src.js

  • Committer: Jeff Stys
  • Date: 2014-04-21 12:46:26 UTC
  • Revision ID: jstys@sesda3.com-20140421124626-2332pb2dyjc33jxi
Proof-of-concept version of Data Coverage Timeline using Highchart/Highstock javascript library.  Changes to getDataCoverage API in order to feed the necessary data to the Timeline

Show diffs side-by-side

added added

removed removed

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