PageSourceSearch

https://ste-b2b.agency/wp-content/plugins/wordpress-stats-manager-…/jqplot.enhancedLegendRenderer.js?ver=1.0.0

js ste-b2b.agency collected 2026-09-24 11:53:56 UTC 14,079 bytes, 306 lines download raw bytes

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

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.