~ubuntu-branches/ubuntu/raring/ntop/raring-proposed

« back to all changes in this revision

Viewing changes to html/jqplot/plugins/jqplot.enhancedLegendRenderer.js

  • Committer: Package Import Robot
  • Author(s): Ludovico Cavedon
  • Date: 2012-06-27 00:24:42 UTC
  • mfrom: (1.1.7)
  • Revision ID: package-import@ubuntu.com-20120627002442-9ljq6fhjqzx9qsu6
Tags: 3:4.99.3+ndpi5517+dfsg1-1
* Imported Upstream version 4.99.3 and nDPI r5517.
* get-orig-source.sh: incude nDPI in the orig tarball.
* No longer suggest ntop-graphs and update NEWS about that.
* Update copyright for the new jqPlot library.
* Refresh patches.
* Enable hardening flags.
* Add install-jqplot.patch to install jqPlot.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/**
 
2
 * jqPlot
 
3
 * Pure JavaScript plotting plugin using jQuery
 
4
 *
 
5
 * Version: 1.0.0b2_r1012
 
6
 *
 
7
 * Copyright (c) 2009-2011 Chris Leonello
 
8
 * jqPlot is currently available for use in all personal or commercial projects 
 
9
 * under both the MIT (http://www.opensource.org/licenses/mit-license.php) and GPL 
 
10
 * version 2.0 (http://www.gnu.org/licenses/gpl-2.0.html) licenses. This means that you can 
 
11
 * choose the license that best suits your project and use it accordingly. 
 
12
 *
 
13
 * Although not required, the author would appreciate an email letting him 
 
14
 * know of any substantial use of jqPlot.  You can reach the author at: 
 
15
 * chris at jqplot dot com or see http://www.jqplot.com/info.php .
 
16
 *
 
17
 * If you are feeling kind and generous, consider supporting the project by
 
18
 * making a donation at: http://www.jqplot.com/donate.php .
 
19
 *
 
20
 * sprintf functions contained in jqplot.sprintf.js by Ash Searle:
 
21
 *
 
22
 *     version 2007.04.27
 
23
 *     author Ash Searle
 
24
 *     http://hexmen.com/blog/2007/03/printf-sprintf/
 
25
 *     http://hexmen.com/js/sprintf.js
 
26
 *     The author (Ash Searle) has placed this code in the public domain:
 
27
 *     "This code is unrestricted: you are free to use it however you like."
 
28
 * 
 
29
 */
 
30
(function($) {
 
31
    // class $.jqplot.EnhancedLegendRenderer
 
32
    // Legend renderer which can specify the number of rows and/or columns in the legend.
 
33
    $.jqplot.EnhancedLegendRenderer = function(){
 
34
        $.jqplot.TableLegendRenderer.call(this);
 
35
    };
 
36
    
 
37
    $.jqplot.EnhancedLegendRenderer.prototype = new $.jqplot.TableLegendRenderer();
 
38
    $.jqplot.EnhancedLegendRenderer.prototype.constructor = $.jqplot.EnhancedLegendRenderer;
 
39
    
 
40
    // called with scope of legend.
 
41
    $.jqplot.EnhancedLegendRenderer.prototype.init = function(options) {
 
42
        // prop: numberRows
 
43
        // Maximum number of rows in the legend.  0 or null for unlimited.
 
44
        this.numberRows = null;
 
45
        // prop: numberColumns
 
46
        // Maximum number of columns in the legend.  0 or null for unlimited.
 
47
        this.numberColumns = null;
 
48
        // prop: seriesToggle
 
49
        // false to not enable series on/off toggling on the legend.
 
50
        // true or a fadein/fadeout speed (number of milliseconds or 'fast', 'normal', 'slow') 
 
51
        // to enable show/hide of series on click of legend item.
 
52
        this.seriesToggle = 'normal';
 
53
        // prop: disableIEFading
 
54
        // true to toggle series with a show/hide method only and not allow fading in/out.  
 
55
        // This is to overcome poor performance of fade in some versions of IE.
 
56
        this.disableIEFading = true;
 
57
        $.extend(true, this, options);
 
58
        
 
59
        if (this.seriesToggle) {
 
60
            $.jqplot.postDrawHooks.push(postDraw);
 
61
        }
 
62
    };
 
63
    
 
64
    // called with scope of legend
 
65
    $.jqplot.EnhancedLegendRenderer.prototype.draw = function() {
 
66
        var legend = this;
 
67
        if (this.show) {
 
68
            var series = this._series;
 
69
                        var s;
 
70
            var ss = 'position:absolute;';
 
71
            ss += (this.background) ? 'background:'+this.background+';' : '';
 
72
            ss += (this.border) ? 'border:'+this.border+';' : '';
 
73
            ss += (this.fontSize) ? 'font-size:'+this.fontSize+';' : '';
 
74
            ss += (this.fontFamily) ? 'font-family:'+this.fontFamily+';' : '';
 
75
            ss += (this.textColor) ? 'color:'+this.textColor+';' : '';
 
76
            ss += (this.marginTop != null) ? 'margin-top:'+this.marginTop+';' : '';
 
77
            ss += (this.marginBottom != null) ? 'margin-bottom:'+this.marginBottom+';' : '';
 
78
            ss += (this.marginLeft != null) ? 'margin-left:'+this.marginLeft+';' : '';
 
79
            ss += (this.marginRight != null) ? 'margin-right:'+this.marginRight+';' : '';
 
80
            this._elem = $('<table class="jqplot-table-legend" style="'+ss+'"></table>');
 
81
            if (this.seriesToggle) {
 
82
                this._elem.css('z-index', '3');
 
83
            }
 
84
        
 
85
            var pad = false, 
 
86
                reverse = false,
 
87
                nr, nc;
 
88
            if (this.numberRows) {
 
89
                nr = this.numberRows;
 
90
                if (!this.numberColumns){
 
91
                    nc = Math.ceil(series.length/nr);
 
92
                }
 
93
                else{
 
94
                    nc = this.numberColumns;
 
95
                }
 
96
            }
 
97
            else if (this.numberColumns) {
 
98
                nc = this.numberColumns;
 
99
                nr = Math.ceil(series.length/this.numberColumns);
 
100
            }
 
101
            else {
 
102
                nr = series.length;
 
103
                nc = 1;
 
104
            }
 
105
                
 
106
            var i, j, tr, td1, td2, lt, rs, div, div0, div1;
 
107
            var idx = 0;
 
108
            // check to see if we need to reverse
 
109
            for (i=series.length-1; i>=0; i--) {
 
110
                if (nc == 1 && series[i]._stack || series[i].renderer.constructor == $.jqplot.BezierCurveRenderer){
 
111
                    reverse = true;
 
112
                }
 
113
            }    
 
114
                
 
115
            for (i=0; i<nr; i++) {
 
116
                tr = $(document.createElement('tr'));
 
117
                tr.addClass('jqplot-table-legend');
 
118
                if (reverse){
 
119
                    tr.prependTo(this._elem);
 
120
                }
 
121
                else{
 
122
                    tr.appendTo(this._elem);
 
123
                }
 
124
                for (j=0; j<nc; j++) {
 
125
                    if (idx < series.length && series[idx].show && series[idx].showLabel){
 
126
                        s = series[idx];
 
127
                        lt = this.labels[idx] || s.label.toString();
 
128
                        if (lt) {
 
129
                            var color = s.color;
 
130
                            if (!reverse){
 
131
                                if (i>0){
 
132
                                    pad = true;
 
133
                                }
 
134
                                else{
 
135
                                    pad = false;
 
136
                                }
 
137
                            }
 
138
                            else{
 
139
                                if (i == nr -1){
 
140
                                    pad = false;
 
141
                                }
 
142
                                else{
 
143
                                    pad = true;
 
144
                                }
 
145
                            }
 
146
                            rs = (pad) ? this.rowSpacing : '0';
 
147
 
 
148
                            td1 = $(document.createElement('td'));
 
149
                            td1.addClass('jqplot-table-legend jqplot-table-legend-swatch');
 
150
                            td1.css({textAlign: 'center', paddingTop: rs});
 
151
 
 
152
                            div0 = $(document.createElement('div'));
 
153
                            div0.addClass('jqplot-table-legend-swatch-outline');
 
154
                            div1 = $(document.createElement('div'));
 
155
                            div1.addClass('jqplot-table-legend-swatch');
 
156
                            div1.css({backgroundColor: color, borderColor: color});
 
157
 
 
158
                            td1.append(div0.append(div1));
 
159
 
 
160
                            td2 = $(document.createElement('td'));
 
161
                            td2.addClass('jqplot-table-legend jqplot-table-legend-label');
 
162
                            td2.css('paddingTop', rs);
 
163
                    
 
164
                            // td1 = $('<td class="jqplot-table-legend" style="text-align:center;padding-top:'+rs+';">'+
 
165
                            //     '<div><div class="jqplot-table-legend-swatch" style="background-color:'+color+';border-color:'+color+';"></div>'+
 
166
                            //     '</div></td>');
 
167
                            // td2 = $('<td class="jqplot-table-legend" style="padding-top:'+rs+';"></td>');
 
168
                            if (this.escapeHtml){
 
169
                                td2.text(lt);
 
170
                            }
 
171
                            else {
 
172
                                td2.html(lt);
 
173
                            }
 
174
                            if (reverse) {
 
175
                                if (this.showLabels) {td2.prependTo(tr);}
 
176
                                if (this.showSwatches) {td1.prependTo(tr);}
 
177
                            }
 
178
                            else {
 
179
                                if (this.showSwatches) {td1.appendTo(tr);}
 
180
                                if (this.showLabels) {td2.appendTo(tr);}
 
181
                            }
 
182
                            
 
183
                            if (this.seriesToggle) {
 
184
 
 
185
                                // add an overlay for clicking series on/off
 
186
                                // div0 = $(document.createElement('div'));
 
187
                                // div0.addClass('jqplot-table-legend-overlay');
 
188
                                // div0.css({position:'relative', left:0, top:0, height:'100%', width:'100%'});
 
189
                                // tr.append(div0);
 
190
 
 
191
                                var speed;
 
192
                                if (typeof(this.seriesToggle) == 'string' || typeof(this.seriesToggle) == 'number') {
 
193
                                    if (!$.jqplot.use_excanvas || !this.disableIEFading) {
 
194
                                        speed = this.seriesToggle;
 
195
                                    }
 
196
                                } 
 
197
                                if (this.showSwatches) {
 
198
                                    td1.bind('click', {series:s, speed:speed}, handleToggle);
 
199
                                    td1.addClass('jqplot-seriesToggle');
 
200
                                }
 
201
                                if (this.showLabels)  {
 
202
                                    td2.bind('click', {series:s, speed:speed}, handleToggle);
 
203
                                    td2.addClass('jqplot-seriesToggle');
 
204
                                }
 
205
                            }
 
206
                            
 
207
                            pad = true;
 
208
                        }
 
209
                    }
 
210
                    idx++;
 
211
                }
 
212
                
 
213
                td1 = td2 = div0 = div1 = null;   
 
214
            }
 
215
        }
 
216
        return this._elem;
 
217
    };
 
218
 
 
219
    var handleToggle = function (ev) {
 
220
        ev.data.series.toggleDisplay(ev);
 
221
        if (ev.data.series.canvas._elem.hasClass('jqplot-series-hidden')) {
 
222
            $(this).addClass('jqplot-series-hidden');
 
223
            $(this).next('.jqplot-table-legend-label').addClass('jqplot-series-hidden');
 
224
            $(this).prev('.jqplot-table-legend-swatch').addClass('jqplot-series-hidden');
 
225
 
 
226
        }
 
227
        else {
 
228
            $(this).removeClass('jqplot-series-hidden');
 
229
            $(this).next('.jqplot-table-legend-label').removeClass('jqplot-series-hidden');
 
230
            $(this).prev('.jqplot-table-legend-swatch').removeClass('jqplot-series-hidden');
 
231
        }
 
232
    };
 
233
    
 
234
    // called with scope of plot.
 
235
    var postDraw = function () {
 
236
        if (this.legend.renderer.constructor == $.jqplot.EnhancedLegendRenderer && this.legend.seriesToggle){
 
237
            var e = this.legend._elem.detach();
 
238
            this.eventCanvas._elem.after(e);
 
239
        }
 
240
    };
 
241
})(jQuery);
 
 
b'\\ No newline at end of file'