-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathjquery.jqplot.js
6983 lines (6533 loc) · 290 KB
/
jquery.jqplot.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/**
* Title: jqPlot Charts
*
* Pure JavaScript plotting plugin for jQuery.
*
* About: Version
*
* 0.9.7r635
*
* About: Copyright & License
*
* Copyright (c) 2009 - 2010 Chris Leonello
* jqPlot is currently available for use in all personal or commercial projects
* under both the MIT and GPL version 2.0 licenses. This means that you can
* choose the license that best suits your project and use it accordingly.
*
* See <GPL Version 2> and <MIT License> contained within this distribution for further information.
*
* The author would appreciate an email letting him know of any substantial
* use of jqPlot. You can reach the author at: chris at jqplot dot com
* or see http://www.jqplot.com/info.php. This is, of course, not required.
*
* If you are feeling kind and generous, consider supporting the project by
* making a donation at: http://www.jqplot.com/donate.php.
*
* jqPlot includes `date instance methods and printf/sprintf functions by other authors:
*
* Date instance methods:
*
* author Ken Snyder (ken d snyder at gmail dot com)
* date 2008-09-10
* version 2.0.2 (http://kendsnyder.com/sandbox/date/)
* license Creative Commons Attribution License 3.0 (http://creativecommons.org/licenses/by/3.0/)
*
* JavaScript printf/sprintf functions:
*
* version 2007.04.27
* author Ash Searle
* http://hexmen.com/blog/2007/03/printf-sprintf/
* http://hexmen.com/js/sprintf.js
* The author (Ash Searle) has placed this code in the public domain:
* "This code is unrestricted: you are free to use it however you like."
*
*
* About: Introduction
*
* jqPlot requires jQuery (1.4+ required for certain features). jQuery 1.4.1 is included in the distribution.
* To use jqPlot include jQuery, the jqPlot jQuery plugin, the jqPlot css file and optionally
* the excanvas script for IE support in your web page:
*
* > <!--[if IE]><script language="javascript" type="text/javascript" src="excanvas.js"></script><![endif]-->
* > <script language="javascript" type="text/javascript" src="jquery-1.4.2.min.js"></script>
* > <script language="javascript" type="text/javascript" src="jquery.jqplot.min.js"></script>
* > <link rel="stylesheet" type="text/css" href="jquery.jqplot.css" />
*
* jqPlot can be customized by overriding the defaults of any of the objects which make
* up the plot. The general usage of jqplot is:
*
* > chart = $.jqplot('targetElemId', [dataArray,...], {optionsObject});
*
* The options available to jqplot are detailed in <jqPlot Options> in the jqPlotOptions.txt file.
*
* An actual call to $.jqplot() may look like the
* examples below:
*
* > chart = $.jqplot('chartdiv', [[[1, 2],[3,5.12],[5,13.1],[7,33.6],[9,85.9],[11,219.9]]]);
*
* or
*
* > dataArray = [34,12,43,55,77];
* > chart = $.jqplot('targetElemId', [dataArray, ...], {title:'My Plot', axes:{yaxis:{min:20, max:100}}});
*
* For more inforrmation, see <jqPlot Usage>.
*
* About: Usage
*
* See <jqPlot Usage>
*
* About: Available Options
*
* See <jqPlot Options> for a list of options available thorugh the options object (not complete yet!)
*
* About: Options Usage
*
* See <Options Tutorial>
*
* About: Changes
*
* See <Change Log>
*
*/
(function($) {
// make sure undefined is undefined
var undefined;
/**
* Class: $.jqplot
* jQuery function called by the user to create a plot.
*
* Parameters:
* target - ID of target element to render the plot into.
* data - an array of data series.
* options - user defined options object. See the individual classes for available options.
*
* Properties:
* config - object to hold configuration information for jqPlot plot object.
*
* attributes:
* enablePlugins - False to disable plugins by default. Plugins must then be explicitly
* enabled in the individual plot options. Default: false.
* This property sets the "show" property of certain plugins to true or false.
* Only plugins that can be immediately active upon loading are affected. This includes
* non-renderer plugins like cursor, dragable, highlighter, and trendline.
* defaultHeight - Default height for plots where no css height specification exists. This
* is a jqplot wide default.
* defaultWidth - Default height for plots where no css height specification exists. This
* is a jqplot wide default.
*/
$.jqplot = function(target, data, options) {
var _data, _options;
if (options == null) {
if (data instanceof Array) {
_data = data;
_options = null;
}
else if (data.constructor == Object) {
_data = null;
_options = data;
}
}
else {
_data = data;
_options = options;
}
var plot = new jqPlot();
// remove any error class that may be stuck on target.
$('#'+target).removeClass('jqplot-error');
if ($.jqplot.config.catchErrors) {
try {
plot.init(target, _data, _options);
plot.draw();
plot.themeEngine.init.call(plot);
return plot;
}
catch(e) {
var msg = $.jqplot.config.errorMessage || e.message;
$('#'+target).append('<div class="jqplot-error-message">'+msg+'</div>');
$('#'+target).addClass('jqplot-error');
document.getElementById(target).style.background = $.jqplot.config.errorBackground;
document.getElementById(target).style.border = $.jqplot.config.errorBorder;
document.getElementById(target).style.fontFamily = $.jqplot.config.errorFontFamily;
document.getElementById(target).style.fontSize = $.jqplot.config.errorFontSize;
document.getElementById(target).style.fontStyle = $.jqplot.config.errorFontStyle;
document.getElementById(target).style.fontWeight = $.jqplot.config.errorFontWeight;
}
}
else {
plot.init(target, _data, _options);
plot.draw();
plot.themeEngine.init.call(plot);
return plot;
}
};
$.jqplot.debug = 1;
$.jqplot.config = {
debug:1,
enablePlugins:false,
defaultHeight:300,
defaultWidth:400,
UTCAdjust:false,
timezoneOffset: new Date(new Date().getTimezoneOffset() * 60000),
errorMessage: '',
errorBackground: '',
errorBorder: '',
errorFontFamily: '',
errorFontSize: '',
errorFontStyle: '',
errorFontWeight: '',
catchErrors: false,
defaultTickFormatString: "%.1f"
};
$.jqplot.enablePlugins = $.jqplot.config.enablePlugins;
// canvas related tests taken from modernizer:
// Copyright © 2009–2010 Faruk Ates.
// http://www.modernizr.com
$.jqplot.support_canvas = function() {
return !!document.createElement('canvas').getContext;
};
$.jqplot.support_canvas_text = function() {
return !!(document.createElement('canvas').getContext && typeof document.createElement('canvas').getContext('2d').fillText == 'function');
};
$.jqplot.use_excanvas = ($.browser.msie && !$.jqplot.support_canvas()) ? true : false;
/**
*
* Hooks: jqPlot Pugin Hooks
*
* $.jqplot.preInitHooks - called before initialization.
* $.jqplot.postInitHooks - called after initialization.
* $.jqplot.preParseOptionsHooks - called before user options are parsed.
* $.jqplot.postParseOptionsHooks - called after user options are parsed.
* $.jqplot.preDrawHooks - called before plot draw.
* $.jqplot.postDrawHooks - called after plot draw.
* $.jqplot.preDrawSeriesHooks - called before each series is drawn.
* $.jqplot.postDrawSeriesHooks - called after each series is drawn.
* $.jqplot.preDrawLegendHooks - called before the legend is drawn.
* $.jqplot.addLegendRowHooks - called at the end of legend draw, so plugins
* can add rows to the legend table.
* $.jqplot.preSeriesInitHooks - called before series is initialized.
* $.jqplot.postSeriesInitHooks - called after series is initialized.
* $.jqplot.preParseSeriesOptionsHooks - called before series related options
* are parsed.
* $.jqplot.postParseSeriesOptionsHooks - called after series related options
* are parsed.
* $.jqplot.eventListenerHooks - called at the end of plot drawing, binds
* listeners to the event canvas which lays on top of the grid area.
* $.jqplot.preDrawSeriesShadowHooks - called before series shadows are drawn.
* $.jqplot.postDrawSeriesShadowHooks - called after series shadows are drawn.
*
*/
$.jqplot.preInitHooks = [];
$.jqplot.postInitHooks = [];
$.jqplot.preParseOptionsHooks = [];
$.jqplot.postParseOptionsHooks = [];
$.jqplot.preDrawHooks = [];
$.jqplot.postDrawHooks = [];
$.jqplot.preDrawSeriesHooks = [];
$.jqplot.postDrawSeriesHooks = [];
$.jqplot.preDrawLegendHooks = [];
$.jqplot.addLegendRowHooks = [];
$.jqplot.preSeriesInitHooks = [];
$.jqplot.postSeriesInitHooks = [];
$.jqplot.preParseSeriesOptionsHooks = [];
$.jqplot.postParseSeriesOptionsHooks = [];
$.jqplot.eventListenerHooks = [];
$.jqplot.preDrawSeriesShadowHooks = [];
$.jqplot.postDrawSeriesShadowHooks = [];
// A superclass holding some common properties and methods.
$.jqplot.ElemContainer = function() {
this._elem;
this._plotWidth;
this._plotHeight;
this._plotDimensions = {height:null, width:null};
};
$.jqplot.ElemContainer.prototype.createElement = function(el, offsets, clss, cssopts, attrib) {
this._offsets = offsets;
var klass = clss || 'jqplot';
var elem = document.createElement(el);
this._elem = $(elem);
this._elem.addClass(klass);
this._elem.css(cssopts);
this._elem.attr(attrib);
return this._elem;
};
$.jqplot.ElemContainer.prototype.getWidth = function() {
if (this._elem) {
return this._elem.outerWidth(true);
}
else {
return null;
}
};
$.jqplot.ElemContainer.prototype.getHeight = function() {
if (this._elem) {
return this._elem.outerHeight(true);
}
else {
return null;
}
};
$.jqplot.ElemContainer.prototype.getPosition = function() {
if (this._elem) {
return this._elem.position();
}
else {
return {top:null, left:null, bottom:null, right:null};
}
};
$.jqplot.ElemContainer.prototype.getTop = function() {
return this.getPosition().top;
};
$.jqplot.ElemContainer.prototype.getLeft = function() {
return this.getPosition().left;
};
$.jqplot.ElemContainer.prototype.getBottom = function() {
return this._elem.css('bottom');
};
$.jqplot.ElemContainer.prototype.getRight = function() {
return this._elem.css('right');
};
/**
* Class: Axis
* An individual axis object. Cannot be instantiated directly, but created
* by the Plot oject. Axis properties can be set or overriden by the
* options passed in from the user.
*
*/
function Axis(name) {
$.jqplot.ElemContainer.call(this);
// Group: Properties
//
// Axes options are specified within an axes object at the top level of the
// plot options like so:
// > {
// > axes: {
// > xaxis: {min: 5},
// > yaxis: {min: 2, max: 8, numberTicks:4},
// > x2axis: {pad: 1.5},
// > y2axis: {ticks:[22, 44, 66, 88]}
// > }
// > }
// There are 4 axes, 'xaxis', 'yaxis', 'x2axis', 'y2axis'. Any or all of
// which may be specified.
this.name = name;
this._series = [];
// prop: show
// Wether to display the axis on the graph.
this.show = false;
// prop: tickRenderer
// A class of a rendering engine for creating the ticks labels displayed on the plot,
// See <$.jqplot.AxisTickRenderer>.
this.tickRenderer = $.jqplot.AxisTickRenderer;
// prop: tickOptions
// Options that will be passed to the tickRenderer, see <$.jqplot.AxisTickRenderer> options.
this.tickOptions = {};
// prop: labelRenderer
// A class of a rendering engine for creating an axis label.
this.labelRenderer = $.jqplot.AxisLabelRenderer;
// prop: labelOptions
// Options passed to the label renderer.
this.labelOptions = {};
// prop: label
// Label for the axis
this.label = null;
// prop: showLabel
// true to show the axis label.
this.showLabel = true;
// prop: min
// minimum value of the axis (in data units, not pixels).
this.min=null;
// prop: max
// maximum value of the axis (in data units, not pixels).
this.max=null;
// prop: autoscale
// Autoscale the axis min and max values to provide sensible tick spacing.
// If axis min or max are set, autoscale will be turned off.
// The numberTicks, tickInterval and pad options do work with
// autoscale, although tickInterval has not been tested yet.
// padMin and padMax do nothing when autoscale is on.
this.autoscale = false;
// prop: pad
// Padding to extend the range above and below the data bounds.
// The data range is multiplied by this factor to determine minimum and maximum axis bounds.
// A value of 0 will be interpreted to mean no padding, and pad will be set to 1.0.
this.pad = 1.2;
// prop: padMax
// Padding to extend the range above data bounds.
// The top of the data range is multiplied by this factor to determine maximum axis bounds.
// A value of 0 will be interpreted to mean no padding, and padMax will be set to 1.0.
this.padMax = null;
// prop: padMin
// Padding to extend the range below data bounds.
// The bottom of the data range is multiplied by this factor to determine minimum axis bounds.
// A value of 0 will be interpreted to mean no padding, and padMin will be set to 1.0.
this.padMin = null;
// prop: ticks
// 1D [val, val, ...] or 2D [[val, label], [val, label], ...] array of ticks for the axis.
// If no label is specified, the value is formatted into an appropriate label.
this.ticks = [];
// prop: numberTicks
// Desired number of ticks. Default is to compute automatically.
this.numberTicks;
// prop: tickInterval
// number of units between ticks. Mutually exclusive with numberTicks.
this.tickInterval;
// prop: renderer
// A class of a rendering engine that handles tick generation,
// scaling input data to pixel grid units and drawing the axis element.
this.renderer = $.jqplot.LinearAxisRenderer;
// prop: rendererOptions
// renderer specific options. See <$.jqplot.LinearAxisRenderer> for options.
this.rendererOptions = {};
// prop: showTicks
// Wether to show the ticks (both marks and labels) or not.
// Will not override showMark and showLabel options if specified on the ticks themselves.
this.showTicks = true;
// prop: showTickMarks
// Wether to show the tick marks (line crossing grid) or not.
// Overridden by showTicks and showMark option of tick itself.
this.showTickMarks = true;
// prop: showMinorTicks
// Wether or not to show minor ticks. This is renderer dependent.
// The default <$.jqplot.LinearAxisRenderer> does not have minor ticks.
this.showMinorTicks = true;
// prop: useSeriesColor
// Use the color of the first series associated with this axis for the
// tick marks and line bordering this axis.
this.useSeriesColor = false;
// prop: borderWidth
// width of line stroked at the border of the axis. Defaults
// to the width of the grid boarder.
this.borderWidth = null;
// prop: borderColor
// color of the border adjacent to the axis. Defaults to grid border color.
this.borderColor = null;
// minimum and maximum values on the axis.
this._dataBounds = {min:null, max:null};
// pixel position from the top left of the min value and max value on the axis.
this._offsets = {min:null, max:null};
this._ticks=[];
this._label = null;
// prop: syncTicks
// true to try and synchronize tick spacing across multiple axes so that ticks and
// grid lines line up. This has an impact on autoscaling algorithm, however.
// In general, autoscaling an individual axis will work better if it does not
// have to sync ticks.
this.syncTicks = null;
// prop: tickSpacing
// Approximate pixel spacing between ticks on graph. Used during autoscaling.
// This number will be an upper bound, actual spacing will be less.
this.tickSpacing = 75;
// Properties to hold the original values for min, max, ticks, tickInterval and numberTicks
// so they can be restored if altered by plugins.
this._min = null;
this._max = null;
this._tickInterval = null;
this._numberTicks = null;
this.__ticks = null;
}
Axis.prototype = new $.jqplot.ElemContainer();
Axis.prototype.constructor = Axis;
Axis.prototype.init = function() {
this.renderer = new this.renderer();
// set the axis name
this.tickOptions.axis = this.name;
// if showMark or showLabel tick options not specified, use value of axis option.
// showTicks overrides showTickMarks.
if (this.tickOptions.showMark == null) {
this.tickOptions.showMark = this.showTicks;
}
if (this.tickOptions.showMark == null) {
this.tickOptions.showMark = this.showTickMarks;
}
if (this.tickOptions.showLabel == null) {
this.tickOptions.showLabel = this.showTicks;
}
if (this.label == null || this.label == '') {
this.showLabel = false;
}
else {
this.labelOptions.label = this.label;
}
if (this.showLabel == false) {
this.labelOptions.show = false;
}
// set the default padMax, padMin if not specified
// special check, if no padding desired, padding
// should be set to 1.0
if (this.pad == 0) {
this.pad = 1.0;
}
if (this.padMax == 0) {
this.padMax = 1.0;
}
if (this.padMin == 0) {
this.padMin = 1.0;
}
if (this.padMax == null) {
this.padMax = (this.pad-1)/2 + 1;
}
if (this.padMin == null) {
this.padMin = (this.pad-1)/2 + 1;
}
// now that padMin and padMax are correctly set, reset pad in case user has supplied
// padMin and/or padMax
this.pad = this.padMax + this.padMin - 1;
if (this.min != null || this.max != null) {
this.autoscale = false;
}
// if not set, sync ticks for y axes but not x by default.
if (this.syncTicks == null && this.name.indexOf('y') > -1) {
this.syncTicks = true;
}
else if (this.syncTicks == null){
this.syncTicks = false;
}
this.renderer.init.call(this, this.rendererOptions);
};
Axis.prototype.draw = function(ctx) {
return this.renderer.draw.call(this, ctx);
};
Axis.prototype.set = function() {
this.renderer.set.call(this);
};
Axis.prototype.pack = function(pos, offsets) {
if (this.show) {
this.renderer.pack.call(this, pos, offsets);
}
// these properties should all be available now.
if (this._min == null) {
this._min = this.min;
this._max = this.max;
this._tickInterval = this.tickInterval;
this._numberTicks = this.numberTicks;
this.__ticks = this._ticks;
}
};
// reset the axis back to original values if it has been scaled, zoomed, etc.
Axis.prototype.reset = function() {
this.renderer.reset.call(this);
};
Axis.prototype.resetScale = function() {
this.min = null;
this.max = null;
this.numberTicks = null;
this.tickInterval = null;
};
/**
* Class: Legend
* Legend object. Cannot be instantiated directly, but created
* by the Plot oject. Legend properties can be set or overriden by the
* options passed in from the user.
*/
function Legend(options) {
$.jqplot.ElemContainer.call(this);
// Group: Properties
// prop: show
// Wether to display the legend on the graph.
this.show = false;
// prop: location
// Placement of the legend. one of the compass directions: nw, n, ne, e, se, s, sw, w
this.location = 'ne';
// prop: labels
// Array of labels to use. By default the renderer will look for labels on the series.
// Labels specified in this array will override labels specified on the series.
this.labels = [];
// prop: showLabels
// true to show the label text on the legend.
this.showLabels = true;
// prop: showSwatch
// true to show the color swatches on the legend.
this.showSwatches = true;
// prop: placement
// "insideGrid" places legend inside the grid area of the plot.
// "outsideGrid" places the legend outside the grid but inside the plot container,
// shrinking the grid to accomodate the legend.
// "inside" synonym for "insideGrid",
// "outside" places the legend ouside the grid area, but does not shrink the grid which
// can cause the legend to overflow the plot container.
this.placement = "insideGrid";
// prop: xoffset
// DEPRECATED. Set the margins on the legend using the marginTop, marginLeft, etc.
// properties or via CSS margin styling of the .jqplot-table-legend class.
this.xoffset = 0;
// prop: yoffset
// DEPRECATED. Set the margins on the legend using the marginTop, marginLeft, etc.
// properties or via CSS margin styling of the .jqplot-table-legend class.
this.yoffset = 0;
// prop: border
// css spec for the border around the legend box.
this.border;
// prop: background
// css spec for the background of the legend box.
this.background;
// prop: textColor
// css color spec for the legend text.
this.textColor;
// prop: fontFamily
// css font-family spec for the legend text.
this.fontFamily;
// prop: fontSize
// css font-size spec for the legend text.
this.fontSize ;
// prop: rowSpacing
// css padding-top spec for the rows in the legend.
this.rowSpacing = '0.5em';
// renderer
// A class that will create a DOM object for the legend,
// see <$.jqplot.TableLegendRenderer>.
this.renderer = $.jqplot.TableLegendRenderer;
// prop: rendererOptions
// renderer specific options passed to the renderer.
this.rendererOptions = {};
// prop: predraw
// Wether to draw the legend before the series or not.
// Used with series specific legend renderers for pie, donut, mekko charts, etc.
this.preDraw = false;
// prop: marginTop
// CSS margin for the legend DOM element. This will set an element
// CSS style for the margin which will override any style sheet setting.
// The default will be taken from the stylesheet.
this.marginTop = null;
// prop: marginRight
// CSS margin for the legend DOM element. This will set an element
// CSS style for the margin which will override any style sheet setting.
// The default will be taken from the stylesheet.
this.marginRight = null;
// prop: marginBottom
// CSS margin for the legend DOM element. This will set an element
// CSS style for the margin which will override any style sheet setting.
// The default will be taken from the stylesheet.
this.marginBottom = null;
// prop: marginLeft
// CSS margin for the legend DOM element. This will set an element
// CSS style for the margin which will override any style sheet setting.
// The default will be taken from the stylesheet.
this.marginLeft = null;
this.escapeHtml = false;
this._series = [];
$.extend(true, this, options);
}
Legend.prototype = new $.jqplot.ElemContainer();
Legend.prototype.constructor = Legend;
Legend.prototype.setOptions = function(options) {
$.extend(true, this, options);
// Try to emulate deprecated behaviour
// if user has specified xoffset or yoffset, copy these to
// the margin properties.
if (this.placement == 'inside') this.placement = 'insideGrid';
if (this.xoffset >0) {
if (this.placement == 'insideGrid') {
switch (this.location) {
case 'nw':
case 'w':
case 'sw':
if (this.marginLeft == null) {
this.marginLeft = this.xoffset + 'px';
}
this.marginRight = '0px';
break;
case 'ne':
case 'e':
case 'se':
default:
if (this.marginRight == null) {
this.marginRight = this.xoffset + 'px';
}
this.marginLeft = '0px';
break;
}
}
else if (this.placement == 'outside') {
switch (this.location) {
case 'nw':
case 'w':
case 'sw':
if (this.marginRight == null) {
this.marginRight = this.xoffset + 'px';
}
this.marginLeft = '0px';
break;
case 'ne':
case 'e':
case 'se':
default:
if (this.marginLeft == null) {
this.marginLeft = this.xoffset + 'px';
}
this.marginRight = '0px';
break;
}
}
this.xoffset = 0;
}
if (this.yoffset >0) {
if (this.placement == 'outside') {
switch (this.location) {
case 'sw':
case 's':
case 'se':
if (this.marginTop == null) {
this.marginTop = this.yoffset + 'px';
}
this.marginBottom = '0px';
break;
case 'ne':
case 'n':
case 'nw':
default:
if (this.marginBottom == null) {
this.marginBottom = this.yoffset + 'px';
}
this.marginTop = '0px';
break;
}
}
else if (this.placement == 'insideGrid') {
switch (this.location) {
case 'sw':
case 's':
case 'se':
if (this.marginBottom == null) {
this.marginBottom = this.yoffset + 'px';
}
this.marginTop = '0px';
break;
case 'ne':
case 'n':
case 'nw':
default:
if (this.marginTop == null) {
this.marginTop = this.yoffset + 'px';
}
this.marginBottom = '0px';
break;
}
}
this.yoffset = 0;
}
// TO-DO:
// Handle case where offsets are < 0.
//
};
Legend.prototype.init = function() {
this.renderer = new this.renderer();
this.renderer.init.call(this, this.rendererOptions);
};
Legend.prototype.draw = function(offsets) {
for (var i=0; i<$.jqplot.preDrawLegendHooks.length; i++){
$.jqplot.preDrawLegendHooks[i].call(this, offsets);
}
return this.renderer.draw.call(this, offsets);
};
Legend.prototype.pack = function(offsets) {
this.renderer.pack.call(this, offsets);
};
/**
* Class: Title
* Plot Title object. Cannot be instantiated directly, but created
* by the Plot oject. Title properties can be set or overriden by the
* options passed in from the user.
*
* Parameters:
* text - text of the title.
*/
function Title(text) {
$.jqplot.ElemContainer.call(this);
// Group: Properties
// prop: text
// text of the title;
this.text = text;
// prop: show
// wether or not to show the title
this.show = true;
// prop: fontFamily
// css font-family spec for the text.
this.fontFamily;
// prop: fontSize
// css font-size spec for the text.
this.fontSize ;
// prop: textAlign
// css text-align spec for the text.
this.textAlign;
// prop: textColor
// css color spec for the text.
this.textColor;
// prop: renderer
// A class for creating a DOM element for the title,
// see <$.jqplot.DivTitleRenderer>.
this.renderer = $.jqplot.DivTitleRenderer;
// prop: rendererOptions
// renderer specific options passed to the renderer.
this.rendererOptions = {};
}
Title.prototype = new $.jqplot.ElemContainer();
Title.prototype.constructor = Title;
Title.prototype.init = function() {
this.renderer = new this.renderer();
this.renderer.init.call(this, this.rendererOptions);
};
Title.prototype.draw = function(width) {
return this.renderer.draw.call(this, width);
};
Title.prototype.pack = function() {
this.renderer.pack.call(this);
};
/**
* Class: Series
* An individual data series object. Cannot be instantiated directly, but created
* by the Plot oject. Series properties can be set or overriden by the
* options passed in from the user.
*/
function Series() {
$.jqplot.ElemContainer.call(this);
// Group: Properties
// Properties will be assigned from a series array at the top level of the
// options. If you had two series and wanted to change the color and line
// width of the first and set the second to use the secondary y axis with
// no shadow and supply custom labels for each:
// > {
// > series:[
// > {color: '#ff4466', lineWidth: 5, label:'good line'},
// > {yaxis: 'y2axis', shadow: false, label:'bad line'}
// > ]
// > }
// prop: show
// wether or not to draw the series.
this.show = true;
// prop: xaxis
// which x axis to use with this series, either 'xaxis' or 'x2axis'.
this.xaxis = 'xaxis';
this._xaxis;
// prop: yaxis
// which y axis to use with this series, either 'yaxis' or 'y2axis'.
this.yaxis = 'yaxis';
this._yaxis;
this.gridBorderWidth = 2.0;
// prop: renderer
// A class of a renderer which will draw the series,
// see <$.jqplot.LineRenderer>.
this.renderer = $.jqplot.LineRenderer;
// prop: rendererOptions
// Options to pass on to the renderer.
this.rendererOptions = {};
this.data = [];
this.gridData = [];
// prop: label
// Line label to use in the legend.
this.label = '';
// prop: showLabel
// true to show label for this series in the legend.
this.showLabel = true;
// prop: color
// css color spec for the series
this.color;
// prop: lineWidth
// width of the line in pixels. May have different meanings depending on renderer.
this.lineWidth = 2.5;
// prop: shadow
// wether or not to draw a shadow on the line
this.shadow = true;
// prop: shadowAngle
// Shadow angle in degrees
this.shadowAngle = 45;
// prop: shadowOffset
// Shadow offset from line in pixels
this.shadowOffset = 1.25;
// prop: shadowDepth
// Number of times shadow is stroked, each stroke offset shadowOffset from the last.
this.shadowDepth = 3;
// prop: shadowAlpha
// Alpha channel transparency of shadow. 0 = transparent.
this.shadowAlpha = '0.1';
// prop: breakOnNull
// Not implemented. wether line segments should be be broken at null value.
// False will join point on either side of line.
this.breakOnNull = false;
// prop: markerRenderer
// A class of a renderer which will draw marker (e.g. circle, square, ...) at the data points,
// see <$.jqplot.MarkerRenderer>.
this.markerRenderer = $.jqplot.MarkerRenderer;
// prop: markerOptions
// renderer specific options to pass to the markerRenderer,
// see <$.jqplot.MarkerRenderer>.
this.markerOptions = {};
// prop: showLine
// wether to actually draw the line or not. Series will still be renderered, even if no line is drawn.
this.showLine = true;
// prop: showMarker
// wether or not to show the markers at the data points.
this.showMarker = true;
// prop: index
// 0 based index of this series in the plot series array.
this.index;
// prop: fill
// true or false, wether to fill under lines or in bars.
// May not be implemented in all renderers.
this.fill = false;
// prop: fillColor
// CSS color spec to use for fill under line. Defaults to line color.
this.fillColor;
// prop: fillAlpha
// Alpha transparency to apply to the fill under the line.
// Use this to adjust alpha separate from fill color.
this.fillAlpha;
// prop: fillAndStroke
// If true will stroke the line (with color this.color) as well as fill under it.
// Applies only when fill is true.
this.fillAndStroke = false;
// prop: disableStack
// true to not stack this series with other series in the plot.
// To render properly, non-stacked series must come after any stacked series
// in the plot's data series array. So, the plot's data series array would look like:
// > [stackedSeries1, stackedSeries2, ..., nonStackedSeries1, nonStackedSeries2, ...]
// disableStack will put a gap in the stacking order of series, and subsequent
// stacked series will not fill down through the non-stacked series and will
// most likely not stack properly on top of the non-stacked series.
this.disableStack = false;
// _stack is set by the Plot if the plot is a stacked chart.
// will stack lines or bars on top of one another to build a "mountain" style chart.
// May not be implemented in all renderers.
this._stack = false;
// prop: neighborThreshold
// how close or far (in pixels) the cursor must be from a point marker to detect the point.
this.neighborThreshold = 4;
// prop: fillToZero
// true will force bar and filled series to fill toward zero on the fill Axis.
this.fillToZero = false;
// prop: fillToValue
// fill a filled series to this value on the fill axis.
// Works in conjunction with fillToZero, so that must be true.
this.fillToValue = 0;
// prop: fillAxis
// Either 'x' or 'y'. Which axis to fill the line toward if fillToZero is true.
// 'y' means fill up/down to 0 on the y axis for this series.
this.fillAxis = 'y';
// prop: useNegativeColors
// true to color negative values differently in filled and bar charts.
this.useNegativeColors = true;
this._stackData = [];
// _plotData accounts for stacking. If plots not stacked, _plotData and data are same. If
// stacked, _plotData is accumulation of stacking data.
this._plotData = [];
// _plotValues hold the individual x and y values that will be plotted for this series.
this._plotValues = {x:[], y:[]};
// statistics about the intervals between data points. Used for auto scaling.
this._intervals = {x:{}, y:{}};
// data from the previous series, for stacked charts.
this._prevPlotData = [];
this._prevGridData = [];
this._stackAxis = 'y';
this._primaryAxis = '_xaxis';
// give each series a canvas to draw on. This should allow for redrawing speedups.
this.canvas = new $.jqplot.GenericCanvas();
this.shadowCanvas = new $.jqplot.GenericCanvas();
this.plugins = {};
// sum of y values in this series.
this._sumy = 0;
this._sumx = 0;
}
Series.prototype = new $.jqplot.ElemContainer();
Series.prototype.constructor = Series;
Series.prototype.init = function(index, gridbw, plot) {
// weed out any null values in the data.
this.index = index;
this.gridBorderWidth = gridbw;
var d = this.data;
var temp = [], i;
for (i=0; i<d.length; i++) {
if (! this.breakOnNull) {
if (d[i] == null || d[i][0] == null || d[i][1] == null) {
continue;