3
* Pure JavaScript plotting plugin using jQuery
5
* Version: 1.0.0b2_r1012
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.
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 .
17
* If you are feeling kind and generous, consider supporting the project by
18
* making a donation at: http://www.jqplot.com/donate.php .
20
* sprintf functions contained in jqplot.sprintf.js by 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."
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);
37
$.jqplot.EnhancedLegendRenderer.prototype = new $.jqplot.TableLegendRenderer();
38
$.jqplot.EnhancedLegendRenderer.prototype.constructor = $.jqplot.EnhancedLegendRenderer;
40
// called with scope of legend.
41
$.jqplot.EnhancedLegendRenderer.prototype.init = function(options) {
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;
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);
59
if (this.seriesToggle) {
60
$.jqplot.postDrawHooks.push(postDraw);
64
// called with scope of legend
65
$.jqplot.EnhancedLegendRenderer.prototype.draw = function() {
68
var series = this._series;
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');
88
if (this.numberRows) {
90
if (!this.numberColumns){
91
nc = Math.ceil(series.length/nr);
94
nc = this.numberColumns;
97
else if (this.numberColumns) {
98
nc = this.numberColumns;
99
nr = Math.ceil(series.length/this.numberColumns);
106
var i, j, tr, td1, td2, lt, rs, div, div0, div1;
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){
115
for (i=0; i<nr; i++) {
116
tr = $(document.createElement('tr'));
117
tr.addClass('jqplot-table-legend');
119
tr.prependTo(this._elem);
122
tr.appendTo(this._elem);
124
for (j=0; j<nc; j++) {
125
if (idx < series.length && series[idx].show && series[idx].showLabel){
127
lt = this.labels[idx] || s.label.toString();
146
rs = (pad) ? this.rowSpacing : '0';
148
td1 = $(document.createElement('td'));
149
td1.addClass('jqplot-table-legend jqplot-table-legend-swatch');
150
td1.css({textAlign: 'center', paddingTop: rs});
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});
158
td1.append(div0.append(div1));
160
td2 = $(document.createElement('td'));
161
td2.addClass('jqplot-table-legend jqplot-table-legend-label');
162
td2.css('paddingTop', rs);
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>'+
167
// td2 = $('<td class="jqplot-table-legend" style="padding-top:'+rs+';"></td>');
168
if (this.escapeHtml){
175
if (this.showLabels) {td2.prependTo(tr);}
176
if (this.showSwatches) {td1.prependTo(tr);}
179
if (this.showSwatches) {td1.appendTo(tr);}
180
if (this.showLabels) {td2.appendTo(tr);}
183
if (this.seriesToggle) {
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%'});
192
if (typeof(this.seriesToggle) == 'string' || typeof(this.seriesToggle) == 'number') {
193
if (!$.jqplot.use_excanvas || !this.disableIEFading) {
194
speed = this.seriesToggle;
197
if (this.showSwatches) {
198
td1.bind('click', {series:s, speed:speed}, handleToggle);
199
td1.addClass('jqplot-seriesToggle');
201
if (this.showLabels) {
202
td2.bind('click', {series:s, speed:speed}, handleToggle);
203
td2.addClass('jqplot-seriesToggle');
213
td1 = td2 = div0 = div1 = null;
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');
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');
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);
b'\\ No newline at end of file'