Free cookie consent management tool by TermsFeed Policy Generator

source: branches/OaaS/HeuristicLab.Services.Optimization.Web/Content/jqplot/src/plugins/jqplot.enhancedLegendRenderer.js @ 9166

Last change on this file since 9166 was 9062, checked in by fschoepp, 11 years ago

#1888:
Backend changes:

  • Simplified job state detection (only one hive call will be made to detect all states now, instead of one additional call per job)
  • Reorganized classes (moved model classes into Model folder)

Website changes:

  • Website now heavily uses JavaScript to achieve better user experience
  • JavaScript degrades gracefully, except for plots
  • Tables: Added jquery-datatable-plugin to extend tables (pagination + search functionality)
  • OaaS-Website now uses the design of the HL websites (found in WebApplication branch)
  • Added jqplot to render zoomable line plots for HL-Datatables
  • Styling.js: Plots will be generated by using an ajax call; additional jquery-styling occurs within this file.
  • Added jquery-ui-1.9.2 which is capable of handling/rendering tabs, accordions and resizers.
File size: 8.7 KB
Line 
1/**
2 * jqPlot
3 * Pure JavaScript plotting plugin using jQuery
4 *
5 * Version: @VERSION
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;
107            var idx = 0;
108            // check to see if we need to reverse
109            for (i=series.length-1; i>=0; i--) {
110                if (series[i]._stack || series[i].renderer.constructor == $.jqplot.BezierCurveRenderer){
111                    reverse = true;
112                }
113            }   
114               
115            for (i=0; i<nr; i++) {
116                if (reverse){
117                    tr = $('<tr class="jqplot-table-legend"></tr>').prependTo(this._elem);
118                }
119                else{
120                    tr = $('<tr class="jqplot-table-legend"></tr>').appendTo(this._elem);
121                }
122                for (j=0; j<nc; j++) {
123                    if (idx < series.length && series[idx].show && series[idx].showLabel){
124                        s = series[idx];
125                        lt = this.labels[idx] || s.label.toString();
126                        if (lt) {
127                            var color = s.color;
128                            if (!reverse){
129                                if (i>0){
130                                    pad = true;
131                                }
132                                else{
133                                    pad = false;
134                                }
135                            }
136                            else{
137                                if (i == nr -1){
138                                    pad = false;
139                                }
140                                else{
141                                    pad = true;
142                                }
143                            }
144                            rs = (pad) ? this.rowSpacing : '0';
145                   
146                            td1 = $('<td class="jqplot-table-legend" style="text-align:center;padding-top:'+rs+';">'+
147                                '<div><div class="jqplot-table-legend-swatch" style="background-color:'+color+';border-color:'+color+';"></div>'+
148                                '</div></td>');
149                            td2 = $('<td class="jqplot-table-legend" style="padding-top:'+rs+';"></td>');
150                            if (this.escapeHtml){
151                                td2.text(lt);
152                            }
153                            else {
154                                td2.html(lt);
155                            }
156                            if (reverse) {
157                                if (this.showLabels) {td2.prependTo(tr);}
158                                if (this.showSwatches) {td1.prependTo(tr);}
159                            }
160                            else {
161                                if (this.showSwatches) {td1.appendTo(tr);}
162                                if (this.showLabels) {td2.appendTo(tr);}
163                            }
164                           
165                            if (this.seriesToggle) {
166                                var speed;
167                                if (typeof(this.seriesToggle) == 'string' || typeof(this.seriesToggle) == 'number') {
168                                    if (!$.jqplot.use_excanvas || !this.disableIEFading) {
169                                        speed = this.seriesToggle;
170                                    }
171                                }
172                                if (this.showSwatches) {
173                                    td1.bind('click', {series:s, speed:speed}, s.toggleDisplay);
174                                    td1.addClass('jqplot-seriesToggle');
175                                }
176                                if (this.showLabels)  {
177                                    td2.bind('click', {series:s, speed:speed}, s.toggleDisplay);
178                                    td2.addClass('jqplot-seriesToggle');
179                                }
180                            }
181                           
182                            pad = true;
183                        }
184                    }
185                    idx++;
186                }   
187            }
188        }
189        return this._elem;
190    };
191   
192    // called with scope of plot.
193    var postDraw = function () {
194        if (this.legend.renderer.constructor == $.jqplot.EnhancedLegendRenderer && this.legend.seriesToggle){
195            var e = this.legend._elem.detach();
196            this.eventCanvas._elem.after(e);
197        }
198    };
199})(jQuery);
Note: See TracBrowser for help on using the repository browser.