Subversion Repositories Code-Repo

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
141 Kevin 1
/**
2
 * Title: jqPlot Charts
3
 * 
4
 * Pure JavaScript plotting plugin for jQuery.
5
 * 
6
 * About: Version
7
 * 
8
 * 0.9.6 
9
 * 
10
 * About: Copyright & License
11
 * 
12
 * Copyright (c) 2009 Chris Leonello
13
 * jqPlot is currently available for use in all personal or commercial projects 
14
 * under both the MIT and GPL version 2.0 licenses. This means that you can 
15
 * choose the license that best suits your project and use it accordingly.
16
 * 
17
 * See <GPL Version 2> and <MIT License> contained within this distribution for further information. 
18
 *
19
 * The author would appreciate an email letting him know of any substantial
20
 * use of jqPlot.  You can reach the author at: chris dot leonello at gmail 
21
 * dot com or see http://www.jqplot.com/info.php.  This is, of course, not required.
22
 *
23
 * If you are feeling kind and generous, consider supporting the project by
24
 * making a donation at: http://www.jqplot.com/donate.php.
25
 *
26
 * 
27
 * About: Introduction
28
 * 
29
 * jqPlot requires jQuery (tested with 1.3.2 or better). jQuery 1.3.2 is included in the distribution.  
30
 * To use jqPlot include jQuery, the jqPlot jQuery plugin, the jqPlot css file and optionally 
31
 * the excanvas script for IE support in your web page:
32
 * 
33
 * > <!--[if IE]><script language="javascript" type="text/javascript" src="excanvas.js"></script><![endif]-->
34
 * > <script language="javascript" type="text/javascript" src="jquery-1.3.2.min.js"></script>
35
 * > <script language="javascript" type="text/javascript" src="jquery.jqplot.min.js"></script>
36
 * > <link rel="stylesheet" type="text/css" href="jquery.jqplot.css" />
37
 * 
38
 * jqPlot can be customized by overriding the defaults of any of the objects which make
39
 * up the plot. The general usage of jqplot is:
40
 * 
41
 * > chart = $.jqplot('targetElemId', [dataArray,...], {optionsObject});
42
 * 
43
 * The options available to jqplot are detailed in <jqPlot Options> in the jqPlotOptions.txt file.
44
 * 
45
 * An actual call to $.jqplot() may look like the 
46
 * examples below:
47
 * 
48
 * > chart = $.jqplot('chartdiv',  [[[1, 2],[3,5.12],[5,13.1],[7,33.6],[9,85.9],[11,219.9]]]);
49
 * 
50
 * or
51
 * 
52
 * > dataArray = [34,12,43,55,77];
53
 * > chart = $.jqplot('targetElemId', [dataArray, ...], {title:'My Plot', axes:{yaxis:{min:20, max:100}}});
54
 * 
55
 * For more inforrmation, see <jqPlot Usage>.
56
 * 
57
 * About: Usage
58
 * 
59
 * See <jqPlot Usage>
60
 * 
61
 * About: Available Options 
62
 * 
63
 * See <jqPlot Options> for a list of options available thorugh the options object (not complete yet!)
64
 * 
65
 * About: Options Usage
66
 * 
67
 * See <Options Tutorial>
68
 * 
69
 * About: Changes
70
 * 
71
 * See <Change Log>
72
 * 
73
 */
74
 
75
(function($) {
76
    // make sure undefined is undefined
77
    var undefined;
78
 
79
    /**
80
     * Class: $.jqplot
81
     * jQuery function called by the user to create a plot.
82
     *  
83
     * Parameters:
84
     * target - ID of target element to render the plot into.
85
     * data - an array of data series.
86
     * options - user defined options object.  See the individual classes for available options.
87
     * 
88
     * Properties:
89
     * config - object to hold configuration information for jqPlot plot object.
90
     * 
91
     * attributes:
92
     * enablePlugins - False to disable plugins by default.  Plugins must then be explicitly 
93
     *   enabled in the individual plot options.  Default: true.
94
     *   This property sets the "show" property of certain plugins to true or false.
95
     *   Only plugins that can be immediately active upon loading are affected.  This includes
96
     *   non-renderer plugins like cursor, dragable, highlighter, and trendline.
97
     * defaultHeight - Default height for plots where no css height specification exists.  This
98
     *   is a jqplot wide default.
99
     * defaultWidth - Default height for plots where no css height specification exists.  This
100
     *   is a jqplot wide default.
101
     */
102
 
103
    $.jqplot = function(target, data, options) {
104
        var _data, _options;
105
 
106
        // check to see if only 2 arguments were specified, what is what.
107
        if (data == null) {
108
            throw "No data specified";
109
        }
110
        if (data.constructor == Array && data.length == 0 || data[0].constructor != Array) {
111
            throw "Improper Data Array";
112
        }
113
        if (options == null) {
114
            if (data instanceof Array) {
115
                _data = data;
116
                _options = null;   
117
            }
118
 
119
            else if (data.constructor == Object) {
120
                _data = null;
121
                _options = data;
122
            }
123
        }
124
        else {
125
            _data = data;
126
            _options = options;
127
        }
128
        var plot = new jqPlot();
129
        plot.init(target, _data, _options);
130
        plot.draw();
131
        return plot;
132
    };
133
 
134
    $.jqplot.debug = 1;
135
    $.jqplot.config = {
136
        debug:1,
137
        enablePlugins:true,
138
        defaultHeight:300,
139
        defaultWidth:400
140
    };
141
 
142
    $.jqplot.enablePlugins = $.jqplot.config.enablePlugins;
143
 
144
    /**
145
     * 
146
     * Hooks: jqPlot Pugin Hooks
147
     * 
148
     * $.jqplot.preInitHooks - called before initialization.
149
     * $.jqplot.postInitHooks - called after initialization.
150
     * $.jqplot.preParseOptionsHooks - called before user options are parsed.
151
     * $.jqplot.postParseOptionsHooks - called after user options are parsed.
152
     * $.jqplot.preDrawHooks - called before plot draw.
153
     * $.jqplot.postDrawHooks - called after plot draw.
154
     * $.jqplot.preDrawSeriesHooks - called before each series is drawn.
155
     * $.jqplot.postDrawSeriesHooks - called after each series is drawn.
156
     * $.jqplot.preDrawLegendHooks - called before the legend is drawn.
157
     * $.jqplot.addLegendRowHooks - called at the end of legend draw, so plugins
158
     *     can add rows to the legend table.
159
     * $.jqplot.preSeriesInitHooks - called before series is initialized.
160
     * $.jqplot.postSeriesInitHooks - called after series is initialized.
161
     * $.jqplot.preParseSeriesOptionsHooks - called before series related options
162
     *     are parsed.
163
     * $.jqplot.postParseSeriesOptionsHooks - called after series related options
164
     *     are parsed.
165
     * $.jqplot.eventListenerHooks - called at the end of plot drawing, binds
166
     *     listeners to the event canvas which lays on top of the grid area.
167
     * $.jqplot.preDrawSeriesShadowHooks - called before series shadows are drawn.
168
     * $.jqplot.postDrawSeriesShadowHooks - called after series shadows are drawn.
169
     * 
170
     */
171
 
172
    $.jqplot.preInitHooks = [];
173
    $.jqplot.postInitHooks = [];
174
    $.jqplot.preParseOptionsHooks = [];
175
    $.jqplot.postParseOptionsHooks = [];
176
    $.jqplot.preDrawHooks = [];
177
    $.jqplot.postDrawHooks = [];
178
    $.jqplot.preDrawSeriesHooks = [];
179
    $.jqplot.postDrawSeriesHooks = [];
180
    $.jqplot.preDrawLegendHooks = [];
181
    $.jqplot.addLegendRowHooks = [];
182
    $.jqplot.preSeriesInitHooks = [];
183
    $.jqplot.postSeriesInitHooks = [];
184
    $.jqplot.preParseSeriesOptionsHooks = [];
185
    $.jqplot.postParseSeriesOptionsHooks = [];
186
    $.jqplot.eventListenerHooks = [];
187
    $.jqplot.preDrawSeriesShadowHooks = [];
188
    $.jqplot.postDrawSeriesShadowHooks = [];
189
 
190
    // A superclass holding some common properties and methods.
191
    $.jqplot.ElemContainer = function() {
192
        this._elem;
193
        this._plotWidth;
194
        this._plotHeight;
195
        this._plotDimensions = {height:null, width:null};
196
    };
197
 
198
    $.jqplot.ElemContainer.prototype.getWidth = function() {
199
        if (this._elem) {
200
            return this._elem.outerWidth(true);
201
        }
202
        else {
203
            return null;
204
        }
205
    };
206
 
207
    $.jqplot.ElemContainer.prototype.getHeight = function() {
208
        if (this._elem) {
209
            return this._elem.outerHeight(true);
210
        }
211
        else {
212
            return null;
213
        }
214
    };
215
 
216
    $.jqplot.ElemContainer.prototype.getPosition = function() {
217
        if (this._elem) {
218
            return this._elem.position();
219
        }
220
        else {
221
            return {top:null, left:null, bottom:null, right:null};
222
        }
223
    };
224
 
225
    $.jqplot.ElemContainer.prototype.getTop = function() {
226
        return this.getPosition().top;
227
    };
228
 
229
    $.jqplot.ElemContainer.prototype.getLeft = function() {
230
        return this.getPosition().left;
231
    };
232
 
233
    $.jqplot.ElemContainer.prototype.getBottom = function() {
234
        return this._elem.css('bottom');
235
    };
236
 
237
    $.jqplot.ElemContainer.prototype.getRight = function() {
238
        return this._elem.css('right');
239
    };
240
 
241
 
242
    /**
243
     * Class: Axis
244
     * An individual axis object.  Cannot be instantiated directly, but created
245
     * by the Plot oject.  Axis properties can be set or overriden by the 
246
     * options passed in from the user.
247
     * 
248
     */
249
    function Axis(name) {
250
        $.jqplot.ElemContainer.call(this);
251
        // Group: Properties
252
        //
253
        // Axes options are specified within an axes object at the top level of the 
254
        // plot options like so:
255
        // > {
256
        // >    axes: {
257
        // >        xaxis: {min: 5},
258
        // >        yaxis: {min: 2, max: 8, numberTicks:4},
259
        // >        x2axis: {pad: 1.5},
260
        // >        y2axis: {ticks:[22, 44, 66, 88]}
261
        // >        }
262
        // > }
263
        // There are 4 axes, 'xaxis', 'yaxis', 'x2axis', 'y2axis'.  Any or all of 
264
        // which may be specified.
265
        this.name = name;
266
        this._series = [];
267
        // prop: show
268
        // Wether to display the axis on the graph.
269
        this.show = false;
270
        // prop: tickRenderer
271
        // A class of a rendering engine for creating the ticks labels displayed on the plot, 
272
        // See <$.jqplot.AxisTickRenderer>.
273
        this.tickRenderer = $.jqplot.AxisTickRenderer;
274
        // prop: tickOptions
275
        // Options that will be passed to the tickRenderer, see <$.jqplot.AxisTickRenderer> options.
276
        this.tickOptions = {};
277
        // prop: labelRenderer
278
        // A class of a rendering engine for creating an axis label.
279
        this.labelRenderer = $.jqplot.AxisLabelRenderer;
280
        // prop: labelOptions
281
        // Options passed to the label renderer.
282
        this.labelOptions = {};
283
        // prop: label
284
        // Label for the axis
285
        this.label = null;
286
        // prop: showLabel
287
        // true to show the axis label.
288
        this.showLabel = true;
289
        // prop: min
290
        // minimum value of the axis (in data units, not pixels).
291
        this.min=null;
292
        // prop: max
293
        // maximum value of the axis (in data units, not pixels).
294
        this.max=null;
295
        // prop: autoscale
296
        // Autoscale the axis min and max values to provide sensible tick spacing.
297
        // If axis min or max are set, autoscale will be turned off.
298
        // The numberTicks, tickInterval and pad options do work with 
299
        // autoscale, although tickInterval has not been tested yet.
300
        // padMin and padMax do nothing when autoscale is on.
301
        this.autoscale = false;
302
        // prop: pad
303
        // Padding to extend the range above and below the data bounds.
304
        // The data range is multiplied by this factor to determine minimum and maximum axis bounds.
305
        // A value of 0 will be interpreted to mean no padding, and pad will be set to 1.0.
306
        this.pad = 1.2;
307
        // prop: padMax
308
        // Padding to extend the range above data bounds.
309
        // The top of the data range is multiplied by this factor to determine maximum axis bounds.
310
        // A value of 0 will be interpreted to mean no padding, and padMax will be set to 1.0.
311
        this.padMax = null;
312
        // prop: padMin
313
        // Padding to extend the range below data bounds.
314
        // The bottom of the data range is multiplied by this factor to determine minimum axis bounds.
315
        // A value of 0 will be interpreted to mean no padding, and padMin will be set to 1.0.
316
        this.padMin = null;
317
        // prop: ticks
318
        // 1D [val, val, ...] or 2D [[val, label], [val, label], ...] array of ticks for the axis.
319
        // If no label is specified, the value is formatted into an appropriate label.
320
        this.ticks = [];
321
        // prop: numberTicks
322
        // Desired number of ticks.  Default is to compute automatically.
323
        this.numberTicks;
324
        // prop: tickInterval
325
        // number of units between ticks.  Mutually exclusive with numberTicks.
326
        this.tickInterval;
327
        // prop: renderer
328
        // A class of a rendering engine that handles tick generation, 
329
        // scaling input data to pixel grid units and drawing the axis element.
330
        this.renderer = $.jqplot.LinearAxisRenderer;
331
        // prop: rendererOptions
332
        // renderer specific options.  See <$.jqplot.LinearAxisRenderer> for options.
333
        this.rendererOptions = {};
334
        // prop: showTicks
335
        // wether to show the ticks (both marks and labels) or not.
336
        this.showTicks = true;
337
        // prop: showTickMarks
338
        // wether to show the tick marks (line crossing grid) or not.
339
        this.showTickMarks = true;
340
        // prop: showMinorTicks
341
        // Wether or not to show minor ticks.  This is renderer dependent.
342
        // The default <$.jqplot.LinearAxisRenderer> does not have minor ticks.
343
        this.showMinorTicks = true;
344
        // prop: useSeriesColor
345
        // Use the color of the first series associated with this axis for the
346
        // tick marks and line bordering this axis.
347
        this.useSeriesColor = false;
348
        // prop: borderWidth
349
        // width of line stroked at the border of the axis.  Defaults
350
        // to the width of the grid boarder.
351
        this.borderWidth = null;
352
        // prop: borderColor
353
        // color of the border adjacent to the axis.  Defaults to grid border color.
354
        this.borderColor = null;
355
        // minimum and maximum values on the axis.
356
        this._dataBounds = {min:null, max:null};
357
        // pixel position from the top left of the min value and max value on the axis.
358
        this._offsets = {min:null, max:null};
359
        this._ticks=[];
360
        this._label = null;
361
        // prop: syncTicks
362
        // true to try and synchronize tick spacing across multiple axes so that ticks and
363
        // grid lines line up.  This has an impact on autoscaling algorithm, however.
364
        // In general, autoscaling an individual axis will work better if it does not
365
        // have to sync ticks.
366
        this.syncTicks = null;
367
        // prop: tickSpacing
368
        // Approximate pixel spacing between ticks on graph.  Used during autoscaling.
369
        // This number will be an upper bound, actual spacing will be less.
370
        this.tickSpacing = 75;
371
        // Properties to hold the original values for min, max, ticks, tickInterval and numberTicks
372
        // so they can be restored if altered by plugins.
373
        this._min = null;
374
        this._max = null;
375
        this._tickInterval = null;
376
        this._numberTicks = null;
377
        this.__ticks = null;
378
    }
379
 
380
    Axis.prototype = new $.jqplot.ElemContainer();
381
    Axis.prototype.constructor = Axis;
382
 
383
    Axis.prototype.init = function() {
384
        this.renderer = new this.renderer();
385
        // set the axis name
386
        this.tickOptions.axis = this.name;
387
        if (this.label == null || this.label == '') {
388
            this.showLabel = false;
389
        }
390
        else {
391
            this.labelOptions.label = this.label;
392
        }
393
        if (this.showLabel == false) {
394
            this.labelOptions.show = false;
395
        }
396
        // set the default padMax, padMin if not specified
397
        // special check, if no padding desired, padding
398
        // should be set to 1.0
399
        if (this.pad == 0) {
400
            this.pad = 1.0;
401
        }
402
        if (this.padMax == 0) {
403
            this.padMax = 1.0;
404
        }
405
        if (this.padMin == 0) {
406
            this.padMin = 1.0;
407
        }
408
        if (this.padMax == null) {
409
            this.padMax = (this.pad-1)/2 + 1;
410
        }
411
        if (this.padMin == null) {
412
            this.padMin = (this.pad-1)/2 + 1;
413
        }
414
        // now that padMin and padMax are correctly set, reset pad in case user has supplied 
415
        // padMin and/or padMax
416
        this.pad = this.padMax + this.padMin - 1;
417
        if (this.min != null || this.max != null) {
418
            this.autoscale = false;
419
        }
420
        // if not set, sync ticks for y axes but not x by default.
421
        if (this.syncTicks == null && this.name.indexOf('y') > -1) {
422
            this.syncTicks = true;
423
        }
424
        else if (this.syncTicks == null){
425
            this.syncTicks = false;
426
        }
427
        this.renderer.init.call(this, this.rendererOptions);
428
 
429
    };
430
 
431
    Axis.prototype.draw = function(ctx) {
432
        return this.renderer.draw.call(this, ctx);
433
 
434
    };
435
 
436
    Axis.prototype.set = function() {
437
        this.renderer.set.call(this);
438
    };
439
 
440
    Axis.prototype.pack = function(pos, offsets) {
441
        if (this.show) {
442
            this.renderer.pack.call(this, pos, offsets);
443
        }
444
        // these properties should all be available now.
445
        if (this._min == null) {
446
            this._min = this.min;
447
            this._max = this.max;
448
            this._tickInterval = this.tickInterval;
449
            this._numberTicks = this.numberTicks;
450
            this.__ticks = this._ticks;
451
        }
452
    };
453
 
454
    // reset the axis back to original values if it has been scaled, zoomed, etc.
455
    Axis.prototype.reset = function() {
456
        this.renderer.reset.call(this);
457
    };
458
 
459
    Axis.prototype.resetScale = function() {
460
        this.min = null;
461
        this.max = null;
462
        this.numberTicks = null;
463
        this.tickInterval = null;
464
    };
465
 
466
    /**
467
     * Class: Legend
468
     * Legend object.  Cannot be instantiated directly, but created
469
     * by the Plot oject.  Legend properties can be set or overriden by the 
470
     * options passed in from the user.
471
     */
472
    function Legend(options) {
473
        $.jqplot.ElemContainer.call(this);
474
        // Group: Properties
475
 
476
        // prop: show
477
        // Wether to display the legend on the graph.
478
        this.show = false;
479
        // prop: location
480
        // Placement of the legend.  one of the compass directions: nw, n, ne, e, se, s, sw, w
481
        this.location = 'ne';
482
        // prop: xoffset
483
        // offset from the inside edge of the plot in the x direction in pixels.
484
        this.xoffset = 12;
485
        // prop: yoffset
486
        // offset from the inside edge of the plot in the y direction in pixels.
487
        this.yoffset = 12;
488
        // prop: border
489
        // css spec for the border around the legend box.
490
        this.border;
491
        // prop: background
492
        // css spec for the background of the legend box.
493
        this.background;
494
        // prop: textColor
495
        // css color spec for the legend text.
496
        this.textColor;
497
        // prop: fontFamily
498
        // css font-family spec for the legend text.
499
        this.fontFamily; 
500
        // prop: fontSize
501
        // css font-size spec for the legend text.
502
        this.fontSize ;
503
        // prop: rowSpacing
504
        // css padding-top spec for the rows in the legend.
505
        this.rowSpacing = '0.5em';
506
        // renderer
507
        // A class that will create a DOM object for the legend,
508
        // see <$.jqplot.TableLegendRenderer>.
509
        this.renderer = $.jqplot.TableLegendRenderer;
510
        // prop: rendererOptions
511
        // renderer specific options passed to the renderer.
512
        this.rendererOptions = {};
513
        // prop: predraw
514
        // Wether to draw the legend before the series or not.
515
        this.preDraw = false;
516
        this.escapeHtml = false;
517
        this._series = [];
518
 
519
        $.extend(true, this, options);
520
    }
521
 
522
    Legend.prototype = new $.jqplot.ElemContainer();
523
    Legend.prototype.constructor = Legend;
524
 
525
    Legend.prototype.init = function() {
526
        this.renderer = new this.renderer();
527
        this.renderer.init.call(this, this.rendererOptions);
528
    };
529
 
530
    Legend.prototype.draw = function(offsets) {
531
        for (var i=0; i<$.jqplot.preDrawLegendHooks.length; i++){
532
            $.jqplot.preDrawLegendHooks[i].call(this, offsets);
533
        }
534
        return this.renderer.draw.call(this, offsets);
535
    };
536
 
537
    Legend.prototype.pack = function(offsets) {
538
        this.renderer.pack.call(this, offsets);
539
    };
540
 
541
    /**
542
     * Class: Title
543
     * Plot Title object.  Cannot be instantiated directly, but created
544
     * by the Plot oject.  Title properties can be set or overriden by the 
545
     * options passed in from the user.
546
     * 
547
     * Parameters:
548
     * text - text of the title.
549
     */
550
    function Title(text) {
551
        $.jqplot.ElemContainer.call(this);
552
        // Group: Properties
553
 
554
        // prop: text
555
        // text of the title;
556
        this.text = text;
557
        // prop: show
558
        // wether or not to show the title
559
        this.show = true;
560
        // prop: fontFamily
561
        // css font-family spec for the text.
562
        this.fontFamily;
563
        // prop: fontSize
564
        // css font-size spec for the text.
565
        this.fontSize ;
566
        // prop: textAlign
567
        // css text-align spec for the text.
568
        this.textAlign;
569
        // prop: textColor
570
        // css color spec for the text.
571
        this.textColor;
572
        // prop: renderer
573
        // A class for creating a DOM element for the title,
574
        // see <$.jqplot.DivTitleRenderer>.
575
        this.renderer = $.jqplot.DivTitleRenderer;
576
        // prop: rendererOptions
577
        // renderer specific options passed to the renderer.
578
        this.rendererOptions = {};   
579
    }
580
 
581
    Title.prototype = new $.jqplot.ElemContainer();
582
    Title.prototype.constructor = Title;
583
 
584
    Title.prototype.init = function() {
585
        this.renderer = new this.renderer();
586
        this.renderer.init.call(this, this.rendererOptions);
587
    };
588
 
589
    Title.prototype.draw = function(width) {
590
        return this.renderer.draw.call(this, width);
591
    };
592
 
593
    Title.prototype.pack = function() {
594
        this.renderer.pack.call(this);
595
    };
596
 
597
 
598
    /**
599
     * Class: Series
600
     * An individual data series object.  Cannot be instantiated directly, but created
601
     * by the Plot oject.  Series properties can be set or overriden by the 
602
     * options passed in from the user.
603
     */
604
    function Series() {
605
        $.jqplot.ElemContainer.call(this);
606
        // Group: Properties
607
        // Properties will be assigned from a series array at the top level of the
608
        // options.  If you had two series and wanted to change the color and line
609
        // width of the first and set the second to use the secondary y axis with
610
        // no shadow and supply custom labels for each:
611
        // > {
612
        // >    series:[
613
        // >        {color: '#ff4466', lineWidth: 5, label:'good line'},
614
        // >        {yaxis: 'y2axis', shadow: false, label:'bad line'}
615
        // >    ]
616
        // > }
617
 
618
        // prop: show
619
        // wether or not to draw the series.
620
        this.show = true;
621
        // prop: xaxis
622
        // which x axis to use with this series, either 'xaxis' or 'x2axis'.
623
        this.xaxis = 'xaxis';
624
        this._xaxis;
625
        // prop: yaxis
626
        // which y axis to use with this series, either 'yaxis' or 'y2axis'.
627
        this.yaxis = 'yaxis';
628
        this._yaxis;
629
        this.gridBorderWidth = 2.0;
630
        // prop: renderer
631
        // A class of a renderer which will draw the series, 
632
        // see <$.jqplot.LineRenderer>.
633
        this.renderer = $.jqplot.LineRenderer;
634
        // prop: rendererOptions
635
        // Options to pass on to the renderer.
636
        this.rendererOptions = {};
637
        this.data = [];
638
        this.gridData = [];
639
        // prop: label
640
        // Line label to use in the legend.
641
        this.label = '';
642
        // prop: showLabel
643
        // true to show label for this series in the legend.
644
        this.showLabel = true;
645
        // prop: color
646
        // css color spec for the series
647
        this.color;
648
        // prop: lineWidth
649
        // width of the line in pixels.  May have different meanings depending on renderer.
650
        this.lineWidth = 2.5;
651
        // prop: shadow
652
        // wether or not to draw a shadow on the line
653
        this.shadow = true;
654
        // prop: shadowAngle
655
        // Shadow angle in degrees
656
        this.shadowAngle = 45;
657
        // prop: shadowOffset
658
        // Shadow offset from line in pixels
659
        this.shadowOffset = 1.25;
660
        // prop: shadowDepth
661
        // Number of times shadow is stroked, each stroke offset shadowOffset from the last.
662
        this.shadowDepth = 3;
663
        // prop: shadowAlpha
664
        // Alpha channel transparency of shadow.  0 = transparent.
665
        this.shadowAlpha = '0.1';
666
        // prop: breakOnNull
667
        // Not implemented. wether line segments should be be broken at null value.
668
        // False will join point on either side of line.
669
        this.breakOnNull = false;
670
        // prop: markerRenderer
671
        // A class of a renderer which will draw marker (e.g. circle, square, ...) at the data points,
672
        // see <$.jqplot.MarkerRenderer>.
673
        this.markerRenderer = $.jqplot.MarkerRenderer;
674
        // prop: markerOptions
675
        // renderer specific options to pass to the markerRenderer,
676
        // see <$.jqplot.MarkerRenderer>.
677
        this.markerOptions = {};
678
        // prop: showLine
679
        // wether to actually draw the line or not.  Series will still be renderered, even if no line is drawn.
680
        this.showLine = true;
681
        // prop: showMarker
682
        // wether or not to show the markers at the data points.
683
        this.showMarker = true;
684
        // prop: index
685
        // 0 based index of this series in the plot series array.
686
        this.index;
687
        // prop: fill
688
        // true or false, wether to fill under lines or in bars.
689
        // May not be implemented in all renderers.
690
        this.fill = false;
691
        // prop: fillColor
692
        // CSS color spec to use for fill under line.  Defaults to line color.
693
        this.fillColor;
694
        // prop: fillAlpha
695
        // Alpha transparency to apply to the fill under the line.
696
        // Use this to adjust alpha separate from fill color.
697
        this.fillAlpha;
698
        // prop: fillAndStroke
699
        // If true will stroke the line (with color this.color) as well as fill under it.
700
        // Applies only when fill is true.
701
        this.fillAndStroke = false;
702
        // prop: disableStack
703
        // true to not stack this series with other series in the plot.
704
        // To render properly, non-stacked series must come after any stacked series
705
        // in the plot's data series array.  So, the plot's data series array would look like:
706
        // > [stackedSeries1, stackedSeries2, ..., nonStackedSeries1, nonStackedSeries2, ...]
707
        // disableStack will put a gap in the stacking order of series, and subsequent
708
        // stacked series will not fill down through the non-stacked series and will
709
        // most likely not stack properly on top of the non-stacked series.
710
        this.disableStack = false;
711
        // _stack is set by the Plot if the plot is a stacked chart.
712
        // will stack lines or bars on top of one another to build a "mountain" style chart.
713
        // May not be implemented in all renderers.
714
        this._stack = false;
715
        // prop: neighborThreshold
716
        // how close or far (in pixels) the cursor must be from a point marker to detect the point.
717
        this.neighborThreshold = 4;
718
        // prop: fillToZero
719
        // true will force bar and filled series to fill toward zero on the fill Axis.
720
        this.fillToZero = false;
721
        // prop: fillAxis
722
        // Either 'x' or 'y'.  Which axis to fill the line toward if fillToZero is true.
723
        // 'y' means fill up/down to 0 on the y axis for this series.
724
        this.fillAxis = 'y';
725
        this._stackData = [];
726
        // _plotData accounts for stacking.  If plots not stacked, _plotData and data are same.  If
727
        // stacked, _plotData is accumulation of stacking data.
728
        this._plotData = [];
729
        // _plotValues hold the individual x and y values that will be plotted for this series.
730
        this._plotValues = {x:[], y:[]};
731
        // statistics about the intervals between data points.  Used for auto scaling.
732
        this._intervals = {x:{}, y:{}};
733
        // data from the previous series, for stacked charts.
734
        this._prevPlotData = [];
735
        this._prevGridData = [];
736
        this._stackAxis = 'y';
737
        this._primaryAxis = '_xaxis';
738
        this.plugins = {};
739
    }
740
 
741
    Series.prototype = new $.jqplot.ElemContainer();
742
    Series.prototype.constructor = Series;
743
 
744
    Series.prototype.init = function(index, gridbw) {
745
        // weed out any null values in the data.
746
        this.index = index;
747
        this.gridBorderWidth = gridbw;
748
        var d = this.data;
749
        for (var i=0; i<d.length; i++) {
750
            if (! this.breakOnNull) {
751
                if (d[i] == null || d[i][0] == null || d[i][1] == null) {
752
                    d.splice(i,1);
753
                    continue;
754
                }
755
            }
756
            else {
757
                if (d[i] == null || d[i][0] == null || d[i][1] == null) {
758
                    // TODO: figure out what to do with null values
759
                    var undefined;
760
                }
761
            }
762
        }
763
        if (!this.fillColor) {
764
            this.fillColor = this.color;
765
        }
766
        if (this.fillAlpha) {
767
            var comp = $.jqplot.normalize2rgb(this.fillColor);
768
            var comp = $.jqplot.getColorComponents(comp);
769
            this.fillColor = 'rgba('+comp[0]+','+comp[1]+','+comp[2]+','+this.fillAlpha+')';
770
        }
771
        this.renderer = new this.renderer();
772
        this.renderer.init.call(this, this.rendererOptions);
773
        this.markerRenderer = new this.markerRenderer();
774
        if (!this.markerOptions.color) {
775
            this.markerOptions.color = this.color;
776
        }
777
        if (this.markerOptions.show == null) {
778
            this.markerOptions.show = this.showMarker;
779
        }
780
        // the markerRenderer is called within it's own scaope, don't want to overwrite series options!!
781
        this.markerRenderer.init(this.markerOptions);
782
    };
783
 
784
    // data - optional data point array to draw using this series renderer
785
    // gridData - optional grid data point array to draw using this series renderer
786
    // stackData - array of cumulative data for stacked plots.
787
    Series.prototype.draw = function(sctx, opts) {
788
        var options = (opts == undefined) ? {} : opts;
789
        // hooks get called even if series not shown
790
        // we don't clear canvas here, it would wipe out all other series as well.
791
        for (var j=0; j<$.jqplot.preDrawSeriesHooks.length; j++) {
792
            $.jqplot.preDrawSeriesHooks[j].call(this, sctx, options);
793
        }
794
        if (this.show) {
795
            this.renderer.setGridData.call(this);
796
            if (!options.preventJqPlotSeriesDrawTrigger) {
797
                $(sctx.canvas).trigger('jqplotSeriesDraw', [this.data, this.gridData]);
798
            }
799
            var data = [];
800
            if (options.data) {
801
                data = options.data;
802
            }
803
            else if (!this._stack) {
804
                data = this.data;
805
            }
806
            else {
807
                data = this._plotData;
808
            }
809
            var gridData = options.gridData || this.renderer.makeGridData.call(this, data);
810
 
811
            this.renderer.draw.call(this, sctx, gridData, options);
812
        }
813
 
814
        for (var j=0; j<$.jqplot.postDrawSeriesHooks.length; j++) {
815
            $.jqplot.postDrawSeriesHooks[j].call(this, sctx, options);
816
        }
817
    };
818
 
819
    Series.prototype.drawShadow = function(sctx, opts) {
820
        var options = (opts == undefined) ? {} : opts;
821
        // hooks get called even if series not shown
822
        // we don't clear canvas here, it would wipe out all other series as well.
823
        for (var j=0; j<$.jqplot.preDrawSeriesShadowHooks.length; j++) {
824
            $.jqplot.preDrawSeriesShadowHooks[j].call(this, sctx, options);
825
        }
826
        if (this.shadow) {
827
            this.renderer.setGridData.call(this);
828
 
829
            var data = [];
830
            if (options.data) {
831
                data = options.data;
832
            }
833
            else if (!this._stack) {
834
                data = this.data;
835
            }
836
            else {
837
                data = this._plotData;
838
            }
839
            var gridData = options.gridData || this.renderer.makeGridData.call(this, data);
840
 
841
            this.renderer.drawShadow.call(this, sctx, gridData, options);
842
        }
843
 
844
        for (var j=0; j<$.jqplot.postDrawSeriesShadowHooks.length; j++) {
845
            $.jqplot.postDrawSeriesShadowHooks[j].call(this, sctx, options);
846
        }
847
 
848
    };
849
 
850
 
851
 
852
    /**
853
     * Class: Grid
854
     * 
855
     * Object representing the grid on which the plot is drawn.  The grid in this
856
     * context is the area bounded by the axes, the area which will contain the series.
857
     * Note, the series are drawn on their own canvas.
858
     * The Grid object cannot be instantiated directly, but is created by the Plot oject.  
859
     * Grid properties can be set or overriden by the options passed in from the user.
860
     */
861
    function Grid() {
862
        $.jqplot.ElemContainer.call(this);
863
        // Group: Properties
864
 
865
        // prop: drawGridlines
866
        // wether to draw the gridlines on the plot.
867
        this.drawGridlines = true;
868
        // prop: gridLineColor
869
        // color of the grid lines.
870
        this.gridLineColor = '#cccccc';
871
        // prop: gridLineWidth
872
        // width of the grid lines.
873
        this.gridLineWidth = 1.0;
874
        // prop: background
875
        // css spec for the background color.
876
        this.background = '#fffdf6';
877
        // prop: borderColor
878
        // css spec for the color of the grid border.
879
        this.borderColor = '#999999';
880
        // prop: borderWidth
881
        // width of the border in pixels.
882
        this.borderWidth = 2.0;
883
        // prop: shadow
884
        // wether to show a shadow behind the grid.
885
        this.shadow = true;
886
        // prop: shadowAngle
887
        // shadow angle in degrees
888
        this.shadowAngle = 45;
889
        // prop: shadowOffset
890
        // Offset of each shadow stroke from the border in pixels
891
        this.shadowOffset = 1.5;
892
        // prop: shadowWidth
893
        // width of the stoke for the shadow
894
        this.shadowWidth = 3;
895
        // prop: shadowDepth
896
        // Number of times shadow is stroked, each stroke offset shadowOffset from the last.
897
        this.shadowDepth = 3;
898
        // prop: shadowAlpha
899
        // Alpha channel transparency of shadow.  0 = transparent.
900
        this.shadowAlpha = '0.07';
901
        this._left;
902
        this._top;
903
        this._right;
904
        this._bottom;
905
        this._width;
906
        this._height;
907
        this._axes = [];
908
        // prop: renderer
909
        // Instance of a renderer which will actually render the grid,
910
        // see <$.jqplot.CanvasGridRenderer>.
911
        this.renderer = $.jqplot.CanvasGridRenderer;
912
        // prop: rendererOptions
913
        // Options to pass on to the renderer,
914
        // see <$.jqplot.CanvasGridRenderer>.
915
        this.rendererOptions = {};
916
        this._offsets = {top:null, bottom:null, left:null, right:null};
917
    }
918
 
919
    Grid.prototype = new $.jqplot.ElemContainer();
920
    Grid.prototype.constructor = Grid;
921
 
922
    Grid.prototype.init = function() {
923
        this.renderer = new this.renderer();
924
        this.renderer.init.call(this, this.rendererOptions);
925
    };
926
 
927
    Grid.prototype.createElement = function(offsets) {
928
        this._offsets = offsets;
929
        return this.renderer.createElement.call(this);
930
    };
931
 
932
    Grid.prototype.draw = function() {
933
        this.renderer.draw.call(this);
934
    };
935
 
936
    $.jqplot.GenericCanvas = function() {
937
        $.jqplot.ElemContainer.call(this);
938
        this._ctx;  
939
    };
940
 
941
    $.jqplot.GenericCanvas.prototype = new $.jqplot.ElemContainer();
942
    $.jqplot.GenericCanvas.prototype.constructor = $.jqplot.GenericCanvas;
943
 
944
    $.jqplot.GenericCanvas.prototype.createElement = function(offsets, clss, plotDimensions) {
945
        this._offsets = offsets;
946
        var klass = 'jqplot';
947
        if (clss != undefined) {
948
            klass = clss;
949
        }
950
        var elem = document.createElement('canvas');
951
        // if new plotDimensions supplied, use them.
952
        if (plotDimensions != undefined) {
953
            this._plotDimensions = plotDimensions;
954
        }
955
        elem.width = this._plotDimensions.width - this._offsets.left - this._offsets.right;
956
        elem.height = this._plotDimensions.height - this._offsets.top - this._offsets.bottom;
957
        this._elem = $(elem);
958
        this._elem.addClass(klass);
959
        this._elem.css({ position: 'absolute', left: this._offsets.left, top: this._offsets.top });
960
        // borrowed from flot by Ole Laursen
961
        if ($.browser.msie) {
962
            window.G_vmlCanvasManager.init_(document);
963
        }
964
        if ($.browser.msie) {
965
            elem = window.G_vmlCanvasManager.initElement(elem);
966
        }
967
        return this._elem;
968
    };
969
 
970
    $.jqplot.GenericCanvas.prototype.setContext = function() {
971
        this._ctx = this._elem.get(0).getContext("2d");
972
        return this._ctx;
973
    };
974
 
975
    /**
976
     * Class: jqPlot
977
     * Plot object returned by call to $.jqplot.  Handles parsing user options,
978
     * creating sub objects (Axes, legend, title, series) and rendering the plot.
979
     */
980
    function jqPlot() {
981
        // Group: Properties
982
        // These properties are specified at the top of the options object
983
        // like so:
984
        // > {
985
        // >     axesDefaults:{min:0},
986
        // >     series:[{color:'#6633dd'}],
987
        // >     title: 'A Plot'
988
        // > }
989
        //
990
        // prop: data
991
        // user's data.  Data should *NOT* be specified in the options object,
992
        // but be passed in as the second argument to the $.jqplot() function.
993
        // The data property is described here soley for reference. 
994
        // The data should be in the form of an array of 2D or 1D arrays like
995
        // > [ [[x1, y1], [x2, y2],...], [y1, y2, ...] ].
996
        this.data = [];
997
        // The id of the dom element to render the plot into
998
        this.targetId = null;
999
        // the jquery object for the dom target.
1000
        this.target = null; 
1001
        this.defaults = {
1002
            // prop: axesDefaults
1003
            // default options that will be applied to all axes.
1004
            // see <Axis> for axes options.
1005
            axesDefaults: {},
1006
            axes: {xaxis:{}, yaxis:{}, x2axis:{}, y2axis:{}, y3axis:{}, y4axis:{}, y5axis:{}, y6axis:{}, y7axis:{}, y8axis:{}, y9axis:{}},
1007
            // prop: seriesDefaults
1008
            // default options that will be applied to all series.
1009
            // see <Series> for series options.
1010
            seriesDefaults: {},
1011
            gridPadding: {top:10, right:10, bottom:23, left:10},
1012
            series:[]
1013
        };
1014
        // prop: series
1015
        // Array of series object options.
1016
        // see <Series> for series specific options.
1017
        this.series = [];
1018
        // prop: axes
1019
        // up to 4 axes are supported, each with it's own options, 
1020
        // See <Axis> for axis specific options.
1021
        this.axes = {xaxis: new Axis('xaxis'), yaxis: new Axis('yaxis'), x2axis: new Axis('x2axis'), y2axis: new Axis('y2axis'), y3axis: new Axis('y3axis'), y4axis: new Axis('y4axis'), y5axis: new Axis('y5axis'), y6axis: new Axis('y6axis'), y7axis: new Axis('y7axis'), y8axis: new Axis('y8axis'), y9axis: new Axis('y9axis')};
1022
        // prop: grid
1023
        // See <Grid> for grid specific options.
1024
        this.grid = new Grid();
1025
        // prop: legend
1026
        // see <$.jqplot.TableLegendRenderer>
1027
        this.legend = new Legend();
1028
        this.baseCanvas = new $.jqplot.GenericCanvas();
1029
        this.seriesCanvas = new $.jqplot.GenericCanvas();
1030
        this.eventCanvas = new $.jqplot.GenericCanvas();
1031
        this._width = null;
1032
        this._height = null; 
1033
        this._plotDimensions = {height:null, width:null};
1034
        this._gridPadding = {top:10, right:10, bottom:10, left:10};
1035
        // a shortcut for axis syncTicks options.  Not implemented yet.
1036
        this.syncXTicks = true;
1037
        // a shortcut for axis syncTicks options.  Not implemented yet.
1038
        this.syncYTicks = true;
1039
        // prop: seriesColors
1040
        // Ann array of CSS color specifications that will be applied, in order,
1041
        // to the series in the plot.  Colors will wrap around so, if their
1042
        // are more series than colors, colors will be reused starting at the
1043
        // beginning.  For pie charts, this specifies the colors of the slices.
1044
        this.seriesColors = [ "#4bb2c5", "#EAA228", "#c5b47f", "#579575", "#839557", "#958c12", "#953579", "#4b5de4", "#d8b83f", "#ff5800", "#0085cc"];
1045
        // this.negativeSeriesColors = [ "#9653C4", "#1CE540", "#7BC28F", "#525A94", "#529386", "#00914A", "#967C33", "#E650A8", "#37D46A", "#1BF800", "#AD25CC"];
1046
        this.negativeSeriesColors = [ "#498991", "#C08840", "#9F9274", "#546D61", "#646C4A", "#6F6621", "#6E3F5F", "#4F64B0", "#A89050", "#C45923", "#187399"];
1047
        // prop: sortData
1048
        // false to not sort the data passed in by the user.
1049
        // Many bar, stakced and other graphs as well as many plugins depend on
1050
        // having sorted data.
1051
        this.sortData = true;
1052
        var seriesColorsIndex = 0;
1053
        // prop textColor
1054
        // css spec for the css color attribute.  Default for the entire plot.
1055
        this.textColor;
1056
        // prop; fontFamily
1057
        // css spec for the font-family attribute.  Default for the entire plot.
1058
        this.fontFamily;
1059
        // prop: fontSize
1060
        // css spec for the font-size attribute.  Default for the entire plot.
1061
        this.fontSize;
1062
        // prop: title
1063
        // Title object.  See <Title> for specific options.  As a shortcut, you
1064
        // can specify the title option as just a string like: title: 'My Plot'
1065
        // and this will create a new title object with the specified text.
1066
        this.title = new Title();
1067
        // container to hold all of the merged options.  Convienence for plugins.
1068
        this.options = {};
1069
        // prop: stackSeries
1070
        // true or false, creates a stack or "mountain" plot.
1071
        // Not all series renderers may implement this option.
1072
        this.stackSeries = false;
1073
        // array to hold the cumulative stacked series data.
1074
        // used to ajust the individual series data, which won't have access to other
1075
        // series data.
1076
        this._stackData = [];
1077
        // array that holds the data to be plotted. This will be the series data
1078
        // merged with the the appropriate data from _stackData according to the stackAxis.
1079
        this._plotData = [];
1080
        // Namespece to hold plugins.  Generally non-renderer plugins add themselves to here.
1081
        this.plugins = {};
1082
        // Count how many times the draw method has been called while the plot is visible.
1083
        // Mostly used to test if plot has never been dran (=0), has been successfully drawn
1084
        // into a visible container once (=1) or draw more than once into a visible container.
1085
        // Can use this in tests to see if plot has been visibly drawn at least one time.
1086
        // After plot has been visibly drawn once, it generally doesn't need redrawn if its
1087
        // container is hidden and shown.
1088
        this._drawCount = 0;
1089
        // prop: drawIfHidden
1090
        // True to execute the draw method even if the plot target is hidden.
1091
        // Generally, this should be false.  Most plot elements will not be sized/
1092
        // positioned correclty if renderered into a hidden container.  To render into
1093
        // a hidden container, call the replot method when the container is shown.
1094
        this.drawIfHidden = false;
1095
 
1096
        this.colorGenerator = $.jqplot.ColorGenerator;
1097
 
1098
        // Group: methods
1099
        //
1100
        // method: init
1101
        // sets the plot target, checks data and applies user
1102
        // options to plot.
1103
        this.init = function(target, data, options) {
1104
            for (var i=0; i<$.jqplot.preInitHooks.length; i++) {
1105
                $.jqplot.preInitHooks[i].call(this, target, data, options);
1106
            }
1107
            this.targetId = '#'+target;
1108
            this.target = $('#'+target);
1109
            if (!this.target.get(0)) {
1110
                throw "No plot target specified";
1111
            }
1112
 
1113
            // make sure the target is positioned by some means and set css
1114
            if (this.target.css('position') == 'static') {
1115
                this.target.css('position', 'relative');
1116
            }
1117
            if (!this.target.hasClass('jqplot-target')) {
1118
                this.target.addClass('jqplot-target');
1119
            }
1120
 
1121
            // if no height or width specified, use a default.
1122
            if (!this.target.height()) {
1123
                var h;
1124
                if (options && options.height) {
1125
                    h = parseInt(options.height, 10);
1126
                }
1127
                else if (this.target.attr('data-height')) {
1128
                    h = parseInt(this.target.attr('data-height'), 10);
1129
                }
1130
                else {
1131
                    h = parseInt($.jqplot.config.defaultHeight, 10);
1132
                }
1133
                this._height = h;
1134
                this.target.css('height', h+'px');
1135
            }
1136
            else {
1137
                this._height = this.target.height();
1138
            }
1139
            if (!this.target.width()) {
1140
                var w;
1141
                if (options && options.width) {
1142
                    w = parseInt(options.width, 10);
1143
                }
1144
                else if (this.target.attr('data-width')) {
1145
                    w = parseInt(this.target.attr('data-width'), 10);
1146
                }
1147
                else {
1148
                    w = parseInt($.jqplot.config.defaultWidth, 10);
1149
                }
1150
                this._width = w;
1151
                this.target.css('width', w+'px');
1152
            }
1153
            else {
1154
                this._width = this.target.width();
1155
            }
1156
 
1157
            this._plotDimensions.height = this._height;
1158
            this._plotDimensions.width = this._width;
1159
            this.grid._plotDimensions = this._plotDimensions;
1160
            this.title._plotDimensions = this._plotDimensions;
1161
            this.baseCanvas._plotDimensions = this._plotDimensions;
1162
            this.seriesCanvas._plotDimensions = this._plotDimensions;
1163
            this.eventCanvas._plotDimensions = this._plotDimensions;
1164
            this.legend._plotDimensions = this._plotDimensions;
1165
            if (this._height <=0 || this._width <=0 || !this._height || !this._width) {
1166
                throw "Canvas dimension not set";
1167
            }
1168
 
1169
            this.data = data;
1170
 
1171
            this.parseOptions(options);
1172
 
1173
            if (this.textColor) {
1174
                this.target.css('color', this.textColor);
1175
            }
1176
            if (this.fontFamily) {
1177
                this.target.css('font-family', this.fontFamily);
1178
            }
1179
            if (this.fontSize) {
1180
                this.target.css('font-size', this.fontSize);
1181
            }
1182
 
1183
            this.title.init();
1184
            this.legend.init();
1185
            for (var i=0; i<this.series.length; i++) {
1186
                for (var j=0; j<$.jqplot.preSeriesInitHooks.length; j++) {
1187
                    $.jqplot.preSeriesInitHooks[j].call(this.series[i], target, data, this.options.seriesDefaults, this.options.series[i]);
1188
                }
1189
                this.populatePlotData(this.series[i], i);
1190
                this.series[i]._plotDimensions = this._plotDimensions;
1191
                this.series[i].init(i, this.grid.borderWidth);
1192
                for (var j=0; j<$.jqplot.postSeriesInitHooks.length; j++) {
1193
                    $.jqplot.postSeriesInitHooks[j].call(this.series[i], target, data, this.options.seriesDefaults, this.options.series[i]);
1194
                }
1195
            }
1196
 
1197
            for (var name in this.axes) {
1198
                this.axes[name]._plotDimensions = this._plotDimensions;
1199
                this.axes[name].init();
1200
            }
1201
 
1202
            if (this.sortData) {
1203
                sortData(this.series);
1204
            }
1205
            this.grid.init();
1206
            this.grid._axes = this.axes;
1207
 
1208
            this.legend._series = this.series;
1209
 
1210
            for (var i=0; i<$.jqplot.postInitHooks.length; i++) {
1211
                $.jqplot.postInitHooks[i].call(this, target, data, options);
1212
            }
1213
        };  
1214
 
1215
        // method: resetAxesScale
1216
        // Reset the specified axes min, max, numberTicks and tickInterval properties to null
1217
        // or reset these properties on all axes if no list of axes is provided.
1218
        //
1219
        // Parameters:
1220
        // axes - Boolean to reset or not reset all axes or an array or object of axis names to reset.
1221
        this.resetAxesScale = function(axes) {
1222
            var ax = (axes != undefined) ? axes : this.axes;
1223
            if (ax === true) {
1224
                ax = this.axes;
1225
            }
1226
            if (ax.constructor === Array) {
1227
                for (var i = 0; i < ax.length; i++) {
1228
                    this.axes[ax[i]].resetScale();
1229
                }
1230
            }
1231
            else if (ax.constructor === Object) {
1232
                for (var name in ax) {
1233
                    this.axes[name].resetScale();
1234
                }
1235
            }
1236
        };
1237
        // method: reInitialize
1238
        // reinitialize plot for replotting.
1239
        // not called directly.
1240
        this.reInitialize = function () {
1241
            // Plot should be visible and have a height and width.
1242
            // If plot doesn't have height and width for some
1243
            // reason, set it by other means.  Plot must not have
1244
            // a display:none attribute, however.
1245
            if (!this.target.height()) {
1246
                var h;
1247
                if (options && options.height) {
1248
                    h = parseInt(options.height, 10);
1249
                }
1250
                else if (this.target.attr('data-height')) {
1251
                    h = parseInt(this.target.attr('data-height'), 10);
1252
                }
1253
                else {
1254
                    h = parseInt($.jqplot.config.defaultHeight, 10);
1255
                }
1256
                this._height = h;
1257
                this.target.css('height', h+'px');
1258
            }
1259
            else {
1260
                this._height = this.target.height();
1261
            }
1262
            if (!this.target.width()) {
1263
                var w;
1264
                if (options && options.width) {
1265
                    w = parseInt(options.width, 10);
1266
                }
1267
                else if (this.target.attr('data-width')) {
1268
                    w = parseInt(this.target.attr('data-width'), 10);
1269
                }
1270
                else {
1271
                    w = parseInt($.jqplot.config.defaultWidth, 10);
1272
                }
1273
                this._width = w;
1274
                this.target.css('width', w+'px');
1275
            }
1276
            else {
1277
                this._width = this.target.width();
1278
            }
1279
 
1280
            if (this._height <=0 || this._width <=0 || !this._height || !this._width) {
1281
                throw "Target dimension not set";
1282
            }
1283
 
1284
            this._plotDimensions.height = this._height;
1285
            this._plotDimensions.width = this._width;
1286
            this.grid._plotDimensions = this._plotDimensions;
1287
            this.title._plotDimensions = this._plotDimensions;
1288
            this.baseCanvas._plotDimensions = this._plotDimensions;
1289
            this.seriesCanvas._plotDimensions = this._plotDimensions;
1290
            this.eventCanvas._plotDimensions = this._plotDimensions;
1291
            this.legend._plotDimensions = this._plotDimensions;
1292
 
1293
            for (var n in this.axes) {
1294
                var axis = this.axes[n];
1295
                axis._plotWidth = this._width;
1296
                axis._plotHeight = this._height;
1297
            }
1298
 
1299
            this.title._plotWidth = this._width;
1300
 
1301
            if (this.textColor) {
1302
                this.target.css('color', this.textColor);
1303
            }
1304
            if (this.fontFamily) {
1305
                this.target.css('font-family', this.fontFamily);
1306
            }
1307
            if (this.fontSize) {
1308
                this.target.css('font-size', this.fontSize);
1309
            }
1310
 
1311
            for (var i=0; i<this.series.length; i++) {
1312
                this.populatePlotData(this.series[i], i);
1313
                this.series[i]._plotDimensions = this._plotDimensions;
1314
                //this.series[i].init(i, this.grid.borderWidth);
1315
            }
1316
 
1317
            for (var name in this.axes) {
1318
                this.axes[name]._plotDimensions = this._plotDimensions;
1319
                this.axes[name]._ticks = [];
1320
                this.axes[name].renderer.init.call(this.axes[name], {});
1321
            }
1322
 
1323
            if (this.sortData) {
1324
                sortData(this.series);
1325
            }
1326
 
1327
            this.grid._axes = this.axes;
1328
 
1329
            this.legend._series = this.series;
1330
        };
1331
 
1332
        // sort the series data in increasing order.
1333
        function sortData(series) {
1334
            var d, ret;
1335
            for (var i=0; i<series.length; i++) {
1336
                d = series[i].data;
1337
                var check = true;
1338
                if (series[i]._stackAxis == 'x') {
1339
                    for (var j = 0; j < d.length; j++) {
1340
                        if (typeof(d[j][1]) != "number") {
1341
                            check = false;
1342
                            break;
1343
                        }
1344
                    }
1345
                    if (check) {
1346
                        d.sort(function(a,b) { return a[1] - b[1]; });
1347
                    }
1348
                }
1349
                else {
1350
                    for (var j = 0; j < d.length; j++) {
1351
                        if (typeof(d[j][0]) != "number") {
1352
                            check = false;
1353
                            break;
1354
                        }
1355
                    }
1356
                    if (check) {
1357
                        d.sort(function(a,b) { return a[0] - b[0]; });
1358
                    }
1359
                }
1360
            }
1361
        }
1362
 
1363
        // populate the _stackData and _plotData arrays for the plot and the series.
1364
        this.populatePlotData = function(series, index) {
1365
            // if a stacked chart, compute the stacked data
1366
            this._plotData = [];
1367
            this._stackData = [];
1368
            series._stackData = [];
1369
            series._plotData = [];
1370
            var plotValues = {x:[], y:[]};
1371
            if (this.stackSeries && !series.disableStack) {
1372
                series._stack = true;
1373
                var sidx = series._stackAxis == 'x' ? 0 : 1;
1374
                var idx = sidx ? 0 : 1;
1375
                // push the current data into stackData
1376
                //this._stackData.push(this.series[i].data);
1377
                var temp = $.extend(true, [], series.data);
1378
                // create the data that will be plotted for this series
1379
                var plotdata = $.extend(true, [], series.data);
1380
                // for first series, nothing to add to stackData.
1381
                for (var j=0; j<index; j++) {
1382
                    var cd = this.series[j].data;
1383
                    for (var k=0; k<cd.length; k++) {
1384
                        temp[k][0] += cd[k][0];
1385
                        temp[k][1] += cd[k][1];
1386
                        // only need to sum up the stack axis column of data
1387
                        plotdata[k][sidx] += cd[k][sidx];
1388
                    }
1389
                }
1390
                for (var i=0; i<plotdata.length; i++) {
1391
                    plotValues.x.push(plotdata[i][0]);
1392
                    plotValues.y.push(plotdata[i][1]);
1393
                }
1394
                this._plotData.push(plotdata);
1395
                this._stackData.push(temp);
1396
                series._stackData = temp;
1397
                series._plotData = plotdata;
1398
                series._plotValues = plotValues;
1399
            }
1400
            else {
1401
                for (var i=0; i<series.data.length; i++) {
1402
                    plotValues.x.push(series.data[i][0]);
1403
                    plotValues.y.push(series.data[i][1]);
1404
                }
1405
                this._stackData.push(series.data);
1406
                this.series[index]._stackData = series.data;
1407
                this._plotData.push(series.data);
1408
                series._plotData = series.data;
1409
                series._plotValues = plotValues;
1410
            }
1411
            if (index>0) {
1412
                series._prevPlotData = this.series[index-1]._plotData;
1413
            }
1414
        };
1415
 
1416
        // function to safely return colors from the color array and wrap around at the end.
1417
        this.getNextSeriesColor = (function(t) {
1418
            var idx = 0;
1419
            var sc = t.seriesColors;
1420
 
1421
            return function () { 
1422
                if (idx < sc.length) {
1423
                    return sc[idx++];
1424
                }
1425
                else {
1426
                    idx = 0;
1427
                    return sc[idx++];
1428
                }
1429
            };
1430
        })(this);
1431
 
1432
        this.parseOptions = function(options){
1433
            for (var i=0; i<$.jqplot.preParseOptionsHooks.length; i++) {
1434
                $.jqplot.preParseOptionsHooks[i].call(this, options);
1435
            }
1436
            this.options = $.extend(true, {}, this.defaults, options);
1437
            this.stackSeries = this.options.stackSeries;
1438
            if (this.options.seriesColors) {
1439
                this.seriesColors = this.options.seriesColors;
1440
            }
1441
            var cg = new this.colorGenerator(this.seriesColors);
1442
            // this._gridPadding = this.options.gridPadding;
1443
            $.extend(true, this._gridPadding, this.options.gridPadding);
1444
            this.sortData = (this.options.sortData != null) ? this.options.sortData : this.sortData;
1445
            for (var n in this.axes) {
1446
                var axis = this.axes[n];
1447
                $.extend(true, axis, this.options.axesDefaults, this.options.axes[n]);
1448
                axis._plotWidth = this._width;
1449
                axis._plotHeight = this._height;
1450
            }
1451
            if (this.data.length == 0) {
1452
                this.data = [];
1453
                for (var i=0; i<this.options.series.length; i++) {
1454
                    this.data.push(this.options.series.data);
1455
                }    
1456
            }
1457
 
1458
            var normalizeData = function(data) {
1459
                // return data as an array of point arrays,
1460
                // in form [[x1,y1...], [x2,y2...], ...]
1461
                var temp = [];
1462
                var i;
1463
                if (!(data[0] instanceof Array)) {
1464
                    // we have a series of scalars.  One line with just y values.
1465
                    // turn the scalar list of data into a data array of form:
1466
                    // [[1, data[0]], [2, data[1]], ...]
1467
                    for (var i=0; i<data.length; i++) {
1468
                        temp.push([i+1, data[i]]);
1469
                    }
1470
                }
1471
 
1472
                else {
1473
                    // we have a properly formatted data series, copy it.
1474
                    $.extend(true, temp, data);
1475
                }
1476
                return temp;
1477
            };
1478
 
1479
            for (var i=0; i<this.data.length; i++) { 
1480
                var temp = new Series();
1481
                for (var j=0; j<$.jqplot.preParseSeriesOptionsHooks.length; j++) {
1482
                    $.jqplot.preParseSeriesOptionsHooks[j].call(temp, this.options.seriesDefaults, this.options.series[i]);
1483
                }
1484
                $.extend(true, temp, {seriesColors:this.seriesColors, negativeSeriesColors:this.negativeSeriesColors}, this.options.seriesDefaults, this.options.series[i]);
1485
                temp.data = normalizeData(this.data[i]);
1486
                switch (temp.xaxis) {
1487
                    case 'xaxis':
1488
                        temp._xaxis = this.axes.xaxis;
1489
                        break;
1490
                    case 'x2axis':
1491
                        temp._xaxis = this.axes.x2axis;
1492
                        break;
1493
                    default:
1494
                        break;
1495
                }
1496
                temp._yaxis = this.axes[temp.yaxis];
1497
                temp._xaxis._series.push(temp);
1498
                temp._yaxis._series.push(temp);
1499
                if (temp.show) {
1500
                    temp._xaxis.show = true;
1501
                    temp._yaxis.show = true;
1502
                }
1503
 
1504
                // parse the renderer options and apply default colors if not provided
1505
                if (!temp.color && temp.show != false) {
1506
                    temp.color = cg.next();
1507
                }
1508
                if (!temp.label) {
1509
                    temp.label = 'Series '+ (i+1).toString();
1510
                }
1511
                // temp.rendererOptions.show = temp.show;
1512
                // $.extend(true, temp.renderer, {color:this.seriesColors[i]}, this.rendererOptions);
1513
                this.series.push(temp);  
1514
                for (var j=0; j<$.jqplot.postParseSeriesOptionsHooks.length; j++) {
1515
                    $.jqplot.postParseSeriesOptionsHooks[j].call(this.series[i], this.options.seriesDefaults, this.options.series[i]);
1516
                }
1517
            }
1518
 
1519
            // copy the grid and title options into this object.
1520
            $.extend(true, this.grid, this.options.grid);
1521
            // if axis border properties aren't set, set default.
1522
            for (var n in this.axes) {
1523
                var axis = this.axes[n];
1524
                if (axis.borderWidth == null) {
1525
                    axis.borderWidth =this.grid.borderWidth;
1526
                }
1527
                if (axis.borderColor == null) {
1528
                    if (n != 'xaxis' && n != 'x2axis' && axis.useSeriesColor === true && axis.show) {
1529
                        axis.borderColor = axis._series[0].color;
1530
                    }
1531
                    else {
1532
                        axis.borderColor = this.grid.borderColor;
1533
                    }
1534
                }
1535
            }
1536
 
1537
            if (typeof this.options.title == 'string') {
1538
                this.title.text = this.options.title;
1539
            }
1540
            else if (typeof this.options.title == 'object') {
1541
                $.extend(true, this.title, this.options.title);
1542
            }
1543
            this.title._plotWidth = this._width;
1544
            $.extend(true, this.legend, this.options.legend);
1545
 
1546
            for (var i=0; i<$.jqplot.postParseOptionsHooks.length; i++) {
1547
                $.jqplot.postParseOptionsHooks[i].call(this, options);
1548
            }
1549
        };
1550
 
1551
        // method: replot
1552
        // Does a reinitialization of the plot followed by
1553
        // a redraw.  Method could be used to interactively
1554
        // change plot characteristics and then replot.
1555
        //
1556
        // Parameters:
1557
        // options - Options used for replotting.
1558
        //
1559
        // Properties:
1560
        // clear - false to not clear (empty) the plot container before replotting (default: true).
1561
        // resetAxes - true to reset all axes min, max, numberTicks and tickInterval setting so axes will rescale themselves.
1562
        //             optionally pass in list of axes to reset (e.g. ['xaxis', 'y2axis']) (default: false).
1563
        this.replot = function(options) {
1564
            var opts = (options != undefined) ? options : {};
1565
            var clear = (opts.clear != undefined) ? opts.clear : true;
1566
            var resetAxes = (opts.resetAxes != undefined) ? opts.resetAxes : false;
1567
            this.target.trigger('jqplotPreReplot');
1568
            if (clear) {
1569
                this.target.empty();
1570
            }
1571
            if (resetAxes) {
1572
                this.resetAxesScale(resetAxes);
1573
            }
1574
            this.reInitialize();
1575
            this.draw();
1576
            this.target.trigger('jqplotPostReplot');
1577
        };
1578
 
1579
        // method: redraw
1580
        // Empties the plot target div and redraws the plot.
1581
        // This enables plot data and properties to be changed
1582
        // and then to comletely clear the plot and redraw.
1583
        // redraw *will not* reinitialize any plot elements.
1584
        // That is, axes will not be autoscaled and defaults
1585
        // will not be reapplied to any plot elements.  redraw
1586
        // is used primarily with zooming. 
1587
        //
1588
        // Parameters:
1589
        // clear - false to not clear (empty) the plot container before redrawing (default: true).
1590
        this.redraw = function(clear) {
1591
            clear = (clear != null) ? clear : true;
1592
            this.target.trigger('jqplotPreRedraw');
1593
            if (clear) {
1594
                this.target.empty();
1595
            }
1596
             for (var ax in this.axes) {
1597
                this.axes[ax]._ticks = [];
1598
    	    }
1599
            for (var i=0; i<this.series.length; i++) {
1600
                this.populatePlotData(this.series[i], i);
1601
            }
1602
            this.draw();
1603
            this.target.trigger('jqplotPostRedraw');
1604
        };
1605
 
1606
        // method: draw
1607
        // Draws all elements of the plot into the container.
1608
        // Does not clear the container before drawing.
1609
        this.draw = function(){
1610
            if (this.drawIfHidden || this.target.is(':visible')) {
1611
                this.target.trigger('jqplotPreDraw');
1612
                for (var i=0; i<$.jqplot.preDrawHooks.length; i++) {
1613
                    $.jqplot.preDrawHooks[i].call(this);
1614
                }
1615
                // create an underlying canvas to be used for special features.
1616
                this.target.append(this.baseCanvas.createElement({left:0, right:0, top:0, bottom:0}, 'jqplot-base-canvas'));
1617
                var bctx = this.baseCanvas.setContext();
1618
                this.target.append(this.title.draw());
1619
                this.title.pack({top:0, left:0});
1620
                for (var name in this.axes) {
1621
                    this.target.append(this.axes[name].draw(bctx));
1622
                    this.axes[name].set();
1623
                }
1624
                if (this.axes.yaxis.show) {
1625
                    this._gridPadding.left = this.axes.yaxis.getWidth();
1626
                }
1627
                var ra = ['y2axis', 'y3axis', 'y4axis', 'y5axis', 'y6axis', 'y7axis', 'y8axis', 'y9axis'];
1628
                var rapad = [0, 0, 0, 0];
1629
                var gpr = 0;
1630
                for (var n=8; n>0; n--) {
1631
                    var ax = this.axes[ra[n-1]];
1632
                    if (ax.show) {
1633
                        rapad[n-1] = gpr;
1634
                        gpr += ax.getWidth();
1635
                    }
1636
                }
1637
                if (gpr > this._gridPadding.right) {
1638
                    this._gridPadding.right = gpr;
1639
                }
1640
                if (this.title.show && this.axes.x2axis.show) {
1641
                    this._gridPadding.top = this.title.getHeight() + this.axes.x2axis.getHeight();
1642
                }
1643
                else if (this.title.show) {
1644
                    this._gridPadding.top = this.title.getHeight();
1645
                }
1646
                else if (this.axes.x2axis.show) {
1647
                    this._gridPadding.top = this.axes.x2axis.getHeight();
1648
                }
1649
                if (this.axes.xaxis.show) {
1650
                    this._gridPadding.bottom = this.axes.xaxis.getHeight();
1651
                }
1652
 
1653
                this.axes.xaxis.pack({position:'absolute', bottom:0, left:0, width:this._width}, {min:this._gridPadding.left, max:this._width - this._gridPadding.right});
1654
                this.axes.yaxis.pack({position:'absolute', top:0, left:0, height:this._height}, {min:this._height - this._gridPadding.bottom, max: this._gridPadding.top});
1655
                this.axes.x2axis.pack({position:'absolute', top:this.title.getHeight(), left:0, width:this._width}, {min:this._gridPadding.left, max:this._width - this._gridPadding.right});
1656
                for (var i=8; i>0; i--) {
1657
                    this.axes[ra[i-1]].pack({position:'absolute', top:0, right:rapad[i-1]}, {min:this._height - this._gridPadding.bottom, max: this._gridPadding.top});
1658
                }
1659
                // this.axes.y2axis.pack({position:'absolute', top:0, right:0}, {min:this._height - this._gridPadding.bottom, max: this._gridPadding.top});
1660
 
1661
                this.target.append(this.grid.createElement(this._gridPadding));
1662
                this.grid.draw();
1663
                this.target.append(this.seriesCanvas.createElement(this._gridPadding, 'jqplot-series-canvas'));
1664
                var sctx = this.seriesCanvas.setContext();
1665
                this.target.append(this.eventCanvas.createElement(this._gridPadding, 'jqplot-event-canvas'));
1666
                var ectx = this.eventCanvas.setContext();
1667
                ectx.fillStyle = 'rgba(0,0,0,0)';
1668
                ectx.fillRect(0,0,ectx.canvas.width, ectx.canvas.height);
1669
 
1670
                // bind custom event handlers to regular events.
1671
                this.bindCustomEvents();
1672
 
1673
                // draw legend before series if the series needs to know the legend dimensions.
1674
                if (this.legend.preDraw) {  
1675
                    this.target.append(this.legend.draw());
1676
                    this.legend.pack(this._gridPadding);
1677
                    if (this.legend._elem) {
1678
                        this.drawSeries(sctx, {legendInfo:{location:this.legend.location, width:this.legend.getWidth(), height:this.legend.getHeight(), xoffset:this.legend.xoffset, yoffset:this.legend.yoffset}});
1679
                    }
1680
                    else {
1681
                        this.drawSeries(sctx);
1682
                    }
1683
                }
1684
                else {  // draw series before legend
1685
                    this.drawSeries(sctx);
1686
                    $(this.seriesCanvas._elem).after(this.legend.draw());
1687
                    // this.target.append(this.legend.draw());
1688
                    this.legend.pack(this._gridPadding);                
1689
                }
1690
 
1691
                // register event listeners on the overlay canvas
1692
                for (var i=0; i<$.jqplot.eventListenerHooks.length; i++) {
1693
                    var h = $.jqplot.eventListenerHooks[i];
1694
                    // in the handler, this will refer to the eventCanvas dom element.
1695
                    // make sure there are references back into plot objects.
1696
                    this.eventCanvas._elem.bind(h[0], {plot:this}, h[1]);
1697
                }
1698
 
1699
                for (var i=0; i<$.jqplot.postDrawHooks.length; i++) {
1700
                    $.jqplot.postDrawHooks[i].call(this);
1701
                }
1702
 
1703
                if (this.target.is(':visible')) {
1704
                    this._drawCount += 1;
1705
                }
1706
 
1707
                this.target.trigger('jqplotPostDraw', [this]);
1708
            }
1709
        };
1710
 
1711
        this.bindCustomEvents = function() {
1712
            this.eventCanvas._elem.bind('click', {plot:this}, this.onClick);
1713
            this.eventCanvas._elem.bind('dblclick', {plot:this}, this.onDblClick);
1714
            this.eventCanvas._elem.bind('mousedown', {plot:this}, this.onMouseDown);
1715
            this.eventCanvas._elem.bind('mouseup', {plot:this}, this.onMouseUp);
1716
            this.eventCanvas._elem.bind('mousemove', {plot:this}, this.onMouseMove);
1717
            this.eventCanvas._elem.bind('mouseenter', {plot:this}, this.onMouseEnter);
1718
            this.eventCanvas._elem.bind('mouseleave', {plot:this}, this.onMouseLeave);
1719
        };
1720
 
1721
        function getEventPosition(ev) {
1722
    	    var plot = ev.data.plot;
1723
            // var xaxis = plot.axes.xaxis;
1724
            // var x2axis = plot.axes.x2axis;
1725
            // var yaxis = plot.axes.yaxis;
1726
            // var y2axis = plot.axes.y2axis;
1727
    	    var offsets = plot.eventCanvas._elem.offset();
1728
    	    var gridPos = {x:ev.pageX - offsets.left, y:ev.pageY - offsets.top};
1729
            // var dataPos = {x1y1:{x:null, y:null}, x1y2:{x:null, y:null}, x2y1:{x:null, y:null}, x2y2:{x:null, y:null}};
1730
    	    var dataPos = {xaxis:null, yaxis:null, x2axis:null, y2axis:null, y3axis:null, y4axis:null, y5axis:null, y6axis:null, y7axis:null, y8axis:null, y9axis:null};
1731
 
1732
    	    var an = ['xaxis', 'yaxis', 'x2axis', 'y2axis', 'y3axis', 'y4axis', 'y5axis', 'y6axis', 'y7axis', 'y8axis', 'y9axis'];
1733
    	    var ax = plot.axes;
1734
    	    for (var n=11; n>0; n--) {
1735
    	        var axis = an[n-1];
1736
    	        if (ax[axis].show) {
1737
    	            dataPos[axis] = ax[axis].series_p2u(gridPos[axis.charAt(0)]);
1738
    	        }
1739
    	    }
1740
 
1741
            return ({offsets:offsets, gridPos:gridPos, dataPos:dataPos});
1742
        }
1743
 
1744
        function getNeighborPoint(plot, x, y) {
1745
            var ret = null;
1746
            var s, i, d0, d, j, r;
1747
            var threshold;
1748
            for (var i=0; i<plot.series.length; i++) {
1749
                s = plot.series[i];
1750
                r = s.renderer;
1751
                if (s.show) {
1752
                    threshold = Math.abs(s.markerRenderer.size/2+s.neighborThreshold);
1753
                    for (var j=0; j<s.gridData.length; j++) {
1754
                        p = s.gridData[j];
1755
                        // neighbor looks different to OHLC chart.
1756
                        if (r.constructor == $.jqplot.OHLCRenderer) {
1757
                            if (r.candleStick) {
1758
                                var yp = s._yaxis.series_u2p;
1759
                                if (x >= p[0]-r._bodyWidth/2 && x <= p[0]+r._bodyWidth/2 && y >= yp(s.data[j][2]) && y <= yp(s.data[j][3])) {
1760
                                    ret = {seriesIndex: i, pointIndex:j, gridData:p, data:s.data[j]};
1761
                                }
1762
                            }
1763
                            // if an open hi low close chart
1764
                            else if (!r.hlc){
1765
                                var yp = s._yaxis.series_u2p;
1766
                                if (x >= p[0]-r._tickLength && x <= p[0]+r._tickLength && y >= yp(s.data[j][2]) && y <= yp(s.data[j][3])) {
1767
                                    ret = {seriesIndex: i, pointIndex:j, gridData:p, data:s.data[j]};
1768
                                }
1769
                            }
1770
                            // a hi low close chart
1771
                            else {
1772
                                var yp = s._yaxis.series_u2p;
1773
                                if (x >= p[0]-r._tickLength && x <= p[0]+r._tickLength && y >= yp(s.data[j][1]) && y <= yp(s.data[j][2])) {
1774
                                    ret = {seriesIndex: i, pointIndex:j, gridData:p, data:s.data[j]};
1775
                                }
1776
                            }
1777
 
1778
                        }
1779
                        else {
1780
                            d = Math.sqrt( (x-p[0]) * (x-p[0]) + (y-p[1]) * (y-p[1]) );
1781
                            if (d <= threshold && (d <= d0 || d0 == null)) {
1782
                               d0 = d;
1783
                               ret = {seriesIndex: i, pointIndex:j, gridData:p, data:s.data[j]};
1784
                            }
1785
                        }
1786
                    } 
1787
                }
1788
            }
1789
            return ret;
1790
        }
1791
 
1792
        this.onClick = function(ev) {
1793
            // Event passed in is unnormalized and will have data attribute.
1794
            // Event passed out in normalized and won't have data attribute.
1795
            var positions = getEventPosition(ev);
1796
            var p = ev.data.plot;
1797
            var neighbor = getNeighborPoint(p, positions.gridPos.x, positions.gridPos.y);
1798
    	    ev.data.plot.eventCanvas._elem.trigger('jqplotClick', [positions.gridPos, positions.dataPos, neighbor, p]);
1799
        };
1800
 
1801
        this.onDblClick = function(ev) {
1802
            // Event passed in is unnormalized and will have data attribute.
1803
            // Event passed out in normalized and won't have data attribute.
1804
            var positions = getEventPosition(ev);
1805
            var p = ev.data.plot;
1806
            var neighbor = getNeighborPoint(p, positions.gridPos.x, positions.gridPos.y);
1807
    	    ev.data.plot.eventCanvas._elem.trigger('jqplotDblClick', [positions.gridPos, positions.dataPos, neighbor, p]);
1808
        };
1809
 
1810
        this.onMouseDown = function(ev) {
1811
            var positions = getEventPosition(ev);
1812
            var p = ev.data.plot;
1813
            var neighbor = getNeighborPoint(p, positions.gridPos.x, positions.gridPos.y);
1814
    	    ev.data.plot.eventCanvas._elem.trigger('jqplotMouseDown', [positions.gridPos, positions.dataPos, neighbor, p]);
1815
        };
1816
 
1817
        this.onMouseUp = function(ev) {
1818
            var positions = getEventPosition(ev);
1819
    	    ev.data.plot.eventCanvas._elem.trigger('jqplotMouseUp', [positions.gridPos, positions.dataPos, null, ev.data.plot]);
1820
        };
1821
 
1822
        this.onMouseMove = function(ev) {
1823
            var positions = getEventPosition(ev);
1824
            var p = ev.data.plot;
1825
            var neighbor = getNeighborPoint(p, positions.gridPos.x, positions.gridPos.y);
1826
    	    ev.data.plot.eventCanvas._elem.trigger('jqplotMouseMove', [positions.gridPos, positions.dataPos, neighbor, p]);
1827
        };
1828
 
1829
        this.onMouseEnter = function(ev) {
1830
            var positions = getEventPosition(ev);
1831
            var p = ev.data.plot;
1832
    	    ev.data.plot.eventCanvas._elem.trigger('jqplotMouseEnter', [positions.gridPos, positions.dataPos, null, p]);
1833
        };
1834
 
1835
        this.onMouseLeave = function(ev) {
1836
            var positions = getEventPosition(ev);
1837
            var p = ev.data.plot;
1838
    	    ev.data.plot.eventCanvas._elem.trigger('jqplotMouseLeave', [positions.gridPos, positions.dataPos, null, p]);
1839
        };
1840
 
1841
        this.drawSeries = function(sctx, options){
1842
            // first clear the canvas, since we are redrawing all series.
1843
            sctx.clearRect(0,0,sctx.canvas.width, sctx.canvas.height);
1844
            // if call series drawShadow method first, in case all series shadows
1845
            // should be drawn before any series.  This will ensure, like for 
1846
            // stacked bar plots, that shadows don't overlap series.
1847
            for (var i=0; i<this.series.length; i++) {
1848
                this.series[i].drawShadow(sctx, options);
1849
            }
1850
            for (var i=0; i<this.series.length; i++) {
1851
                this.series[i].draw(sctx, options);
1852
            }
1853
        };
1854
    }
1855
 
1856
 
1857
   $.jqplot.ColorGenerator = function(colors) {
1858
        var idx = 0;
1859
 
1860
        this.next = function () { 
1861
            if (idx < colors.length) {
1862
                return colors[idx++];
1863
            }
1864
            else {
1865
                idx = 0;
1866
                return colors[idx++];
1867
            }
1868
        };
1869
 
1870
        this.previous = function () { 
1871
            if (idx > 0) {
1872
                return colors[idx--];
1873
            }
1874
            else {
1875
                idx = colors.length-1;
1876
                return colors[idx];
1877
            }
1878
        };
1879
 
1880
        // get a color by index without advancing pointer.
1881
        this.get = function(i) {
1882
            return colors[i];
1883
        };
1884
 
1885
        this.setColors = function(c) {
1886
            colors = c;
1887
        };
1888
 
1889
        this.reset = function() {
1890
            idx = 0;
1891
        };
1892
    };
1893
 
1894
    // convert a hex color string to rgb string.
1895
    // h - 3 or 6 character hex string, with or without leading #
1896
    // a - optional alpha
1897
    $.jqplot.hex2rgb = function(h, a) {
1898
        h = h.replace('#', '');
1899
        if (h.length == 3) {
1900
            h = h[0]+h[0]+h[1]+h[1]+h[2]+h[2];
1901
        }
1902
        var rgb;
1903
        rgb = 'rgba('+parseInt(h.slice(0,2), 16)+', '+parseInt(h.slice(2,4), 16)+', '+parseInt(h.slice(4,6), 16);
1904
        if (a) {
1905
            rgb += ', '+a;
1906
        }
1907
        rgb += ')';
1908
        return rgb;
1909
    };
1910
 
1911
    // convert an rgb color spec to a hex spec.  ignore any alpha specification.
1912
    $.jqplot.rgb2hex = function(s) {
1913
        var pat = /rgba?\( *([0-9]{1,3}\.?[0-9]*%?) *, *([0-9]{1,3}\.?[0-9]*%?) *, *([0-9]{1,3}\.?[0-9]*%?) *(?:, *[0-9.]*)?\)/;
1914
        var m = s.match(pat);
1915
        var h = '#';
1916
        for (i=1; i<4; i++) {
1917
            var temp;
1918
            if (m[i].search(/%/) != -1) {
1919
                temp = parseInt(255*m[i]/100, 10).toString(16);
1920
                if (temp.length == 1) {
1921
                    temp = '0'+temp;
1922
                }
1923
            }
1924
            else {
1925
                temp = parseInt(m[i], 10).toString(16);
1926
                if (temp.length == 1) {
1927
                    temp = '0'+temp;
1928
                }
1929
            }
1930
            h += temp;
1931
        }
1932
        return h;
1933
    };
1934
 
1935
    // given a css color spec, return an rgb css color spec
1936
    $.jqplot.normalize2rgb = function(s, a) {
1937
        if (s.search(/^ *rgba?\(/) != -1) {
1938
            return s; 
1939
        }
1940
        else if (s.search(/^ *#?[0-9a-fA-F]?[0-9a-fA-F]/) != -1) {
1941
            return $.jqplot.hex2rgb(s, a);
1942
        }
1943
        else {
1944
            throw 'invalid color spec';
1945
        }
1946
    };
1947
 
1948
    // extract the r, g, b, a color components out of a css color spec.
1949
    $.jqplot.getColorComponents = function(s) {
1950
        var rgb = $.jqplot.normalize2rgb(s);
1951
        var pat = /rgba?\( *([0-9]{1,3}\.?[0-9]*%?) *, *([0-9]{1,3}\.?[0-9]*%?) *, *([0-9]{1,3}\.?[0-9]*%?) *,? *([0-9.]* *)?\)/;
1952
        var m = rgb.match(pat);
1953
        var ret = [];
1954
        for (i=1; i<4; i++) {
1955
            if (m[i].search(/%/) != -1) {
1956
                ret[i-1] = parseInt(255*m[i]/100, 10);
1957
            }
1958
            else {
1959
                ret[i-1] = parseInt(m[i], 10);
1960
            }
1961
        }
1962
        ret[3] = parseFloat(m[4]) ? parseFloat(m[4]) : 1.0;
1963
        return ret;
1964
    };
1965
 
1966
	// Convienence function that won't hang IE.
1967
	$.jqplot.log = function() {
1968
	    if (window.console && $.jqplot.debug) {
1969
	       if (arguments.length == 1) {
1970
	           console.log (arguments[0]);
1971
	        }
1972
	       else {
1973
	           console.log(arguments);
1974
	        }
1975
	    }
1976
	};
1977
	var log = $.jqplot.log;
1978
 
1979
 
1980
    // class: $.jqplot.AxisLabelRenderer
1981
    // Renderer to place labels on the axes.
1982
    $.jqplot.AxisLabelRenderer = function(options) {
1983
        // Group: Properties
1984
        $.jqplot.ElemContainer.call(this);
1985
        // name of the axis associated with this tick
1986
        this.axis;
1987
        // prop: show
1988
        // wether or not to show the tick (mark and label).
1989
        this.show = true;
1990
        // prop: label
1991
        // The text or html for the label.
1992
        this.label = '';
1993
        this._elem;
1994
        // prop: escapeHTML
1995
        // true to escape HTML entities in the label.
1996
        this.escapeHTML = false;
1997
 
1998
        $.extend(true, this, options);
1999
    };
2000
 
2001
    $.jqplot.AxisLabelRenderer.prototype = new $.jqplot.ElemContainer();
2002
    $.jqplot.AxisLabelRenderer.prototype.constructor = $.jqplot.AxisLabelRenderer;
2003
 
2004
    $.jqplot.AxisLabelRenderer.prototype.init = function(options) {
2005
        $.extend(true, this, options);
2006
    };
2007
 
2008
    $.jqplot.AxisLabelRenderer.prototype.draw = function() {
2009
        this._elem = $('<div style="position:absolute;" class="jqplot-'+this.axis+'-label"></div>');
2010
 
2011
        if (Number(this.label)) {
2012
            this._elem.css('white-space', 'nowrap');
2013
        }
2014
 
2015
        if (!this.escapeHTML) {
2016
            this._elem.html(this.label);
2017
        }
2018
        else {
2019
            this._elem.text(this.label);
2020
        }
2021
 
2022
        return this._elem;
2023
    };
2024
 
2025
    $.jqplot.AxisLabelRenderer.prototype.pack = function() {
2026
    };
2027
 
2028
    // class: $.jqplot.AxisTickRenderer
2029
    // A "tick" object showing the value of a tick/gridline on the plot.
2030
    $.jqplot.AxisTickRenderer = function(options) {
2031
        // Group: Properties
2032
        $.jqplot.ElemContainer.call(this);
2033
        // prop: mark
2034
        // tick mark on the axis.  One of 'inside', 'outside', 'cross', '' or null.
2035
        this.mark = 'outside';
2036
        // name of the axis associated with this tick
2037
        this.axis;
2038
        // prop: showMark
2039
        // wether or not to show the mark on the axis.
2040
        this.showMark = true;
2041
        // prop: showGridline
2042
        // wether or not to draw the gridline on the grid at this tick.
2043
        this.showGridline = true;
2044
        // prop: isMinorTick
2045
        // if this is a minor tick.
2046
        this.isMinorTick = false;
2047
        // prop: size
2048
        // Length of the tick beyond the grid in pixels.
2049
        // DEPRECATED: This has been superceeded by markSize
2050
        this.size = 4;
2051
        // prop:  markSize
2052
        // Length of the tick marks in pixels.  For 'cross' style, length
2053
        // will be stoked above and below axis, so total length will be twice this.
2054
        this.markSize = 6;
2055
        // prop: show
2056
        // wether or not to show the tick (mark and label).
2057
        // Setting this to false requires more testing.  It is recommended
2058
        // to set showLabel and showMark to false instead.
2059
        this.show = true;
2060
        // prop: showLabel
2061
        // wether or not to show the label.
2062
        this.showLabel = true;
2063
        this.label = '';
2064
        this.value = null;
2065
        this._styles = {};
2066
        // prop: formatter
2067
        // A class of a formatter for the tick text.  sprintf by default.
2068
        this.formatter = $.jqplot.DefaultTickFormatter;
2069
        // prop: formatString
2070
        // string passed to the formatter.
2071
        this.formatString = '';
2072
        // prop: fontFamily
2073
        // css spec for the font-family css attribute.
2074
        this.fontFamily;
2075
        // prop: fontSize
2076
        // css spec for the font-size css attribute.
2077
        this.fontSize;
2078
        // prop: textColor
2079
        // css spec for the color attribute.
2080
        this.textColor;
2081
        this._elem;
2082
 
2083
        $.extend(true, this, options);
2084
    };
2085
 
2086
    $.jqplot.AxisTickRenderer.prototype.init = function(options) {
2087
        $.extend(true, this, options);
2088
    };
2089
 
2090
    $.jqplot.AxisTickRenderer.prototype = new $.jqplot.ElemContainer();
2091
    $.jqplot.AxisTickRenderer.prototype.constructor = $.jqplot.AxisTickRenderer;
2092
 
2093
    $.jqplot.AxisTickRenderer.prototype.setTick = function(value, axisName, isMinor) {
2094
        this.value = value;
2095
        this.axis = axisName;
2096
        if (isMinor) {
2097
            this.isMinorTick = true;
2098
        }
2099
        return this;
2100
    };
2101
 
2102
    $.jqplot.AxisTickRenderer.prototype.draw = function() {
2103
        if (!this.label) {
2104
            this.label = this.formatter(this.formatString, this.value);
2105
        }
2106
        style ='style="position:absolute;';
2107
        if (Number(this.label)) {
2108
            style +='white-space:nowrap;';
2109
        }
2110
        style += '"';
2111
        this._elem = $('<div '+style+' class="jqplot-'+this.axis+'-tick">'+this.label+'</div>');
2112
        for (var s in this._styles) {
2113
            this._elem.css(s, this._styles[s]);
2114
        }
2115
        if (this.fontFamily) {
2116
            this._elem.css('font-family', this.fontFamily);
2117
        }
2118
        if (this.fontSize) {
2119
            this._elem.css('font-size', this.fontSize);
2120
        }
2121
        if (this.textColor) {
2122
            this._elem.css('color', this.textColor);
2123
        }
2124
        return this._elem;
2125
    };
2126
 
2127
    $.jqplot.DefaultTickFormatter = function (format, val) {
2128
        if (typeof val == 'number') {
2129
            if (!format) {
2130
                format = '%.1f';
2131
            }
2132
            return $.jqplot.sprintf(format, val);
2133
        }
2134
        else {
2135
            return String(val);
2136
        }
2137
    };
2138
 
2139
    $.jqplot.AxisTickRenderer.prototype.pack = function() {
2140
    };
2141
 
2142
    // Class: $.jqplot.CanvasGridRenderer
2143
    // The default jqPlot grid renderer, creating a grid on a canvas element.
2144
    // The renderer has no additional options beyond the <Grid> class.
2145
    $.jqplot.CanvasGridRenderer = function(){
2146
        this.shadowRenderer = new $.jqplot.ShadowRenderer();
2147
    };
2148
 
2149
    // called with context of Grid object
2150
    $.jqplot.CanvasGridRenderer.prototype.init = function(options) {
2151
        this._ctx;
2152
        $.extend(true, this, options);
2153
        // set the shadow renderer options
2154
        var sopts = {lineJoin:'miter', lineCap:'round', fill:false, isarc:false, angle:this.shadowAngle, offset:this.shadowOffset, alpha:this.shadowAlpha, depth:this.shadowDepth, lineWidth:this.shadowWidth, closePath:false};
2155
        this.renderer.shadowRenderer.init(sopts);
2156
    };
2157
 
2158
    // called with context of Grid.
2159
    $.jqplot.CanvasGridRenderer.prototype.createElement = function() {
2160
        var elem = document.createElement('canvas');
2161
        var w = this._plotDimensions.width;
2162
        var h = this._plotDimensions.height;
2163
        elem.width = w;
2164
        elem.height = h;
2165
        this._elem = $(elem);
2166
        this._elem.addClass('jqplot-grid-canvas');
2167
        this._elem.css({ position: 'absolute', left: 0, top: 0 });
2168
        if ($.browser.msie) {
2169
            window.G_vmlCanvasManager.init_(document);
2170
        }
2171
        if ($.browser.msie) {
2172
            elem = window.G_vmlCanvasManager.initElement(elem);
2173
        }
2174
        this._top = this._offsets.top;
2175
        this._bottom = h - this._offsets.bottom;
2176
        this._left = this._offsets.left;
2177
        this._right = w - this._offsets.right;
2178
        this._width = this._right - this._left;
2179
        this._height = this._bottom - this._top;
2180
        return this._elem;
2181
    };
2182
 
2183
    $.jqplot.CanvasGridRenderer.prototype.draw = function() {
2184
        this._ctx = this._elem.get(0).getContext("2d");
2185
        var ctx = this._ctx;
2186
        var axes = this._axes;
2187
        // Add the grid onto the grid canvas.  This is the bottom most layer.
2188
        ctx.save();
2189
        ctx.fillStyle = this.background;
2190
        ctx.fillRect(this._left, this._top, this._width, this._height);
2191
 
2192
        if (this.drawGridlines) {
2193
            ctx.save();
2194
            ctx.lineJoin = 'miter';
2195
            ctx.lineCap = 'butt';
2196
            ctx.lineWidth = this.gridLineWidth;
2197
            ctx.strokeStyle = this.gridLineColor;
2198
            var b, e;
2199
            var ax = ['xaxis', 'yaxis', 'x2axis', 'y2axis'];
2200
            for (var i=4; i>0; i--) {
2201
                var name = ax[i-1];
2202
                var axis = axes[name];
2203
                var ticks = axis._ticks;
2204
                if (axis.show) {
2205
                    for (var j=ticks.length; j>0; j--) {
2206
                        var t = ticks[j-1];
2207
                        if (t.show) {
2208
                            var pos = Math.round(axis.u2p(t.value)) + 0.5;
2209
                            switch (name) {
2210
                                case 'xaxis':
2211
                                    // draw the grid line
2212
                                    if (t.showGridline) {
2213
                                        drawLine(pos, this._top, pos, this._bottom);
2214
                                    }
2215
 
2216
                                    // draw the mark
2217
                                    if (t.showMark && t.mark) {
2218
                                        s = t.markSize;
2219
                                        m = t.mark;
2220
                                        var pos = Math.round(axis.u2p(t.value)) + 0.5;
2221
                                        switch (m) {
2222
                                            case 'outside':
2223
                                                b = this._bottom;
2224
                                                e = this._bottom+s;
2225
                                                break;
2226
                                            case 'inside':
2227
                                                b = this._bottom-s;
2228
                                                e = this._bottom;
2229
                                                break;
2230
                                            case 'cross':
2231
                                                b = this._bottom-s;
2232
                                                e = this._bottom+s;
2233
                                                break;
2234
                                            default:
2235
                                                b = this._bottom;
2236
                                                e = this._bottom+s;
2237
                                                break;
2238
                                        }
2239
                                        // draw the shadow
2240
                                        if (this.shadow) {
2241
                                            this.renderer.shadowRenderer.draw(ctx, [[pos,b],[pos,e]], {lineCap:'butt', lineWidth:this.gridLineWidth, offset:this.gridLineWidth*0.75, depth:2, fill:false, closePath:false});
2242
                                        }
2243
                                        // draw the line
2244
                                        drawLine(pos, b, pos, e);
2245
                                    }
2246
                                    break;
2247
                                case 'yaxis':
2248
                                    // draw the grid line
2249
                                    if (t.showGridline) {
2250
                                        drawLine(this._right, pos, this._left, pos);
2251
                                    }
2252
                                    // draw the mark
2253
                                    if (t.showMark && t.mark) {
2254
                                        s = t.markSize;
2255
                                        m = t.mark;
2256
                                        var pos = Math.round(axis.u2p(t.value)) + 0.5;
2257
                                        switch (m) {
2258
                                            case 'outside':
2259
                                                b = this._left-s;
2260
                                                e = this._left;
2261
                                                break;
2262
                                            case 'inside':
2263
                                                b = this._left;
2264
                                                e = this._left+s;
2265
                                                break;
2266
                                            case 'cross':
2267
                                                b = this._left-s;
2268
                                                e = this._left+s;
2269
                                                break;
2270
                                            default:
2271
                                                b = this._left-s;
2272
                                                e = this._left;
2273
                                                break;
2274
                                                }
2275
                                        // draw the shadow
2276
                                        if (this.shadow) {
2277
                                            this.renderer.shadowRenderer.draw(ctx, [[b, pos], [e, pos]], {lineCap:'butt', lineWidth:this.gridLineWidth*1.5, offset:this.gridLineWidth*0.75, fill:false, closePath:false});
2278
                                        }
2279
                                        drawLine(b, pos, e, pos, {strokeStyle:axis.borderColor});
2280
                                    }
2281
                                    break;
2282
                                case 'x2axis':
2283
                                    // draw the grid line
2284
                                    if (t.showGridline) {
2285
                                        drawLine(pos, this._bottom, pos, this._top);
2286
                                    }
2287
                                    // draw the mark
2288
                                    if (t.showMark && t.mark) {
2289
                                        s = t.markSize;
2290
                                        m = t.mark;
2291
                                        var pos = Math.round(axis.u2p(t.value)) + 0.5;
2292
                                        switch (m) {
2293
                                            case 'outside':
2294
                                                b = this._top-s;
2295
                                                e = this._top;
2296
                                                break;
2297
                                            case 'inside':
2298
                                                b = this._top;
2299
                                                e = this._top+s;
2300
                                                break;
2301
                                            case 'cross':
2302
                                                b = this._top-s;
2303
                                                e = this._top+s;
2304
                                                break;
2305
                                            default:
2306
                                                b = this._top-s;
2307
                                                e = this._top;
2308
                                                break;
2309
                                                }
2310
                                        // draw the shadow
2311
                                        if (this.shadow) {
2312
                                            this.renderer.shadowRenderer.draw(ctx, [[pos,b],[pos,e]], {lineCap:'butt', lineWidth:this.gridLineWidth, offset:this.gridLineWidth*0.75, depth:2, fill:false, closePath:false});
2313
                                        }
2314
                                        drawLine(pos, b, pos, e);
2315
                                    }
2316
                                    break;
2317
                                case 'y2axis':
2318
                                    // draw the grid line
2319
                                    if (t.showGridline) {
2320
                                        drawLine(this._left, pos, this._right, pos);
2321
                                    }
2322
                                    // draw the mark
2323
                                    if (t.showMark && t.mark) {
2324
                                        s = t.markSize;
2325
                                        m = t.mark;
2326
                                        var pos = Math.round(axis.u2p(t.value)) + 0.5;
2327
                                        switch (m) {
2328
                                            case 'outside':
2329
                                                b = this._right;
2330
                                                e = this._right+s;
2331
                                                break;
2332
                                            case 'inside':
2333
                                                b = this._right-s;
2334
                                                e = this._right;
2335
                                                break;
2336
                                            case 'cross':
2337
                                                b = this._right-s;
2338
                                                e = this._right+s;
2339
                                                break;
2340
                                            default:
2341
                                                b = this._right;
2342
                                                e = this._right+s;
2343
                                                break;
2344
                                                }
2345
                                        // draw the shadow
2346
                                        if (this.shadow) {
2347
                                            this.renderer.shadowRenderer.draw(ctx, [[b, pos], [e, pos]], {lineCap:'butt', lineWidth:this.gridLineWidth*1.5, offset:this.gridLineWidth*0.75, fill:false, closePath:false});
2348
                                        }
2349
                                        drawLine(b, pos, e, pos, {strokeStyle:axis.borderColor});
2350
                                    }
2351
                                    break;
2352
                                default:
2353
                                    break;
2354
                            }
2355
                        }
2356
                    }
2357
                }
2358
            }
2359
            // Now draw grid lines for additional y axes
2360
            ax = ['y3axis', 'y4axis', 'y5axis', 'y6axis', 'y7axis', 'y8axis', 'y9axis'];
2361
            for (var i=7; i>0; i--) {
2362
                var axis = axes[ax[i-1]];
2363
                var ticks = axis._ticks;
2364
                if (axis.show) {
2365
                    var tn = ticks[axis.numberTicks-1];
2366
                    var t0 = ticks[0];
2367
                    var left = axis.getLeft();
2368
                    var points = [[left, tn.getTop() + tn.getHeight()/2], [left, t0.getTop() + t0.getHeight()/2 + 1.0]];
2369
                    // draw the shadow
2370
                    if (this.shadow) {
2371
                        this.renderer.shadowRenderer.draw(ctx, points, {lineCap:'butt', fill:false, closePath:false});
2372
                    }
2373
                    // draw the line
2374
                    drawLine(points[0][0], points[0][1], points[1][0], points[1][1], {lineCap:'butt', strokeStyle:axis.borderColor, lineWidth:axis.borderWidth});
2375
                    // draw the tick marks
2376
                    for (var j=ticks.length; j>0; j--) {
2377
                        var t = ticks[j-1];
2378
                        s = t.markSize;
2379
                        m = t.mark;
2380
                        var pos = Math.round(axis.u2p(t.value)) + 0.5;
2381
                        if (t.showMark && t.mark) {
2382
                            switch (m) {
2383
                                case 'outside':
2384
                                    b = left;
2385
                                    e = left+s;
2386
                                    break;
2387
                                case 'inside':
2388
                                    b = left-s;
2389
                                    e = left;
2390
                                    break;
2391
                                case 'cross':
2392
                                    b = left-s;
2393
                                    e = left+s;
2394
                                    break;
2395
                                default:
2396
                                    b = left;
2397
                                    e = left+s;
2398
                                    break;
2399
                            }
2400
                            points = [[b,pos], [e,pos]];
2401
                            // draw the shadow
2402
                            if (this.shadow) {
2403
                                this.renderer.shadowRenderer.draw(ctx, points, {lineCap:'butt', lineWidth:this.gridLineWidth*1.5, offset:this.gridLineWidth*0.75, fill:false, closePath:false});
2404
                            }
2405
                            // draw the line
2406
                            drawLine(b, pos, e, pos, {strokeStyle:axis.borderColor});
2407
                        }
2408
                    }
2409
                }
2410
            }
2411
 
2412
            ctx.restore();
2413
        }
2414
 
2415
        function drawLine(bx, by, ex, ey, opts) {
2416
            ctx.save();
2417
            opts = opts || {};
2418
            $.extend(true, ctx, opts);
2419
            ctx.beginPath();
2420
            ctx.moveTo(bx, by);
2421
            ctx.lineTo(ex, ey);
2422
            ctx.stroke();
2423
            ctx.restore();
2424
        }
2425
 
2426
        if (this.shadow) {
2427
            var points = [[this._left, this._bottom], [this._right, this._bottom], [this._right, this._top]];
2428
            this.renderer.shadowRenderer.draw(ctx, points);
2429
        }
2430
        // Now draw border around grid.  Use axis border definitions. start at
2431
        // upper left and go clockwise.
2432
        drawLine (this._left, this._top, this._right, this._top, {lineCap:'round', strokeStyle:axes.x2axis.borderColor, lineWidth:axes.x2axis.borderWidth});
2433
        drawLine (this._right, this._top, this._right, this._bottom, {lineCap:'round', strokeStyle:axes.y2axis.borderColor, lineWidth:axes.y2axis.borderWidth});
2434
        drawLine (this._right, this._bottom, this._left, this._bottom, {lineCap:'round', strokeStyle:axes.xaxis.borderColor, lineWidth:axes.xaxis.borderWidth});
2435
        drawLine (this._left, this._bottom, this._left, this._top, {lineCap:'round', strokeStyle:axes.yaxis.borderColor, lineWidth:axes.yaxis.borderWidth});
2436
        // ctx.lineWidth = this.borderWidth;
2437
        // ctx.strokeStyle = this.borderColor;
2438
        // ctx.strokeRect(this._left, this._top, this._width, this._height);
2439
 
2440
 
2441
        ctx.restore();
2442
    };
2443
 
2444
    // Class: $.jqplot.DivTitleRenderer
2445
    // The default title renderer for jqPlot.  This class has no options beyond the <Title> class. 
2446
    $.jqplot.DivTitleRenderer = function() {
2447
    };
2448
 
2449
    $.jqplot.DivTitleRenderer.prototype.init = function(options) {
2450
        $.extend(true, this, options);
2451
    };
2452
 
2453
    $.jqplot.DivTitleRenderer.prototype.draw = function() {
2454
        var r = this.renderer;
2455
        if (!this.text) {
2456
            this.show = false;
2457
            this._elem = $('<div style="height:0px;width:0px;"></div>');
2458
        }
2459
        else if (this.text) {
2460
            // don't trust that a stylesheet is present, set the position.
2461
            var styletext = 'position:absolute;top:0px;left:0px;';
2462
            styletext += (this._plotWidth) ? 'width:'+this._plotWidth+'px;' : '';
2463
            styletext += (this.fontFamily) ? 'font-family:'+this.fontFamily+';' : '';
2464
            styletext += (this.fontSize) ? 'font-size:'+this.fontSize+';' : '';
2465
            styletext += (this.textAlign) ? 'text-align:'+this.textAlign+';' : 'text-align:center;';
2466
            styletext += (this.textColor) ? 'color:'+this.textColor+';' : '';
2467
            this._elem = $('<div class="jqplot-title" style="'+styletext+'">'+this.text+'</div>');
2468
        }
2469
 
2470
        return this._elem;
2471
    };
2472
 
2473
    $.jqplot.DivTitleRenderer.prototype.pack = function() {
2474
        // nothing to do here
2475
    };
2476
 
2477
    // Class: $.jqplot.LineRenderer
2478
    // The default line renderer for jqPlot, this class has no options beyond the <Series> class.
2479
    // Draws series as a line.
2480
    $.jqplot.LineRenderer = function(){
2481
        this.shapeRenderer = new $.jqplot.ShapeRenderer();
2482
        this.shadowRenderer = new $.jqplot.ShadowRenderer();
2483
    };
2484
 
2485
    // called with scope of series.
2486
    $.jqplot.LineRenderer.prototype.init = function(options) {
2487
        $.extend(true, this.renderer, options);
2488
        // set the shape renderer options
2489
        var opts = {lineJoin:'round', lineCap:'round', fill:this.fill, isarc:false, strokeStyle:this.color, fillStyle:this.fillColor, lineWidth:this.lineWidth, closePath:this.fill};
2490
        this.renderer.shapeRenderer.init(opts);
2491
        // set the shadow renderer options
2492
        // scale the shadowOffset to the width of the line.
2493
        if (this.lineWidth > 2.5) {
2494
            var shadow_offset = this.shadowOffset* (1 + (Math.atan((this.lineWidth/2.5))/0.785398163 - 1)*0.6);
2495
            // var shadow_offset = this.shadowOffset;
2496
        }
2497
        // for skinny lines, don't make such a big shadow.
2498
        else {
2499
            var shadow_offset = this.shadowOffset*Math.atan((this.lineWidth/2.5))/0.785398163;
2500
        }
2501
        var sopts = {lineJoin:'round', lineCap:'round', fill:this.fill, isarc:false, angle:this.shadowAngle, offset:shadow_offset, alpha:this.shadowAlpha, depth:this.shadowDepth, lineWidth:this.lineWidth, closePath:this.fill};
2502
        this.renderer.shadowRenderer.init(sopts);
2503
    };
2504
 
2505
    // Method: setGridData
2506
    // converts the user data values to grid coordinates and stores them
2507
    // in the gridData array.
2508
    // Called with scope of a series.
2509
    $.jqplot.LineRenderer.prototype.setGridData = function() {
2510
        // recalculate the grid data
2511
        var xp = this._xaxis.series_u2p;
2512
        var yp = this._yaxis.series_u2p;
2513
        var data = this._plotData;
2514
        var pdata = this._prevPlotData;
2515
        this.gridData = [];
2516
        this._prevGridData = [];
2517
        for (var i=0; i<this.data.length; i++) {
2518
            if (data[i] != null) {
2519
                this.gridData.push([xp.call(this._xaxis, data[i][0]), yp.call(this._yaxis, data[i][1])]);
2520
            }
2521
            if (pdata[i] != null) {
2522
                this._prevGridData.push([xp.call(this._xaxis, pdata[i][0]), yp.call(this._yaxis, pdata[i][1])]);
2523
            }
2524
        }
2525
    };
2526
 
2527
    // Method: makeGridData
2528
    // converts any arbitrary data values to grid coordinates and
2529
    // returns them.  This method exists so that plugins can use a series'
2530
    // linerenderer to generate grid data points without overwriting the
2531
    // grid data associated with that series.
2532
    // Called with scope of a series.
2533
    $.jqplot.LineRenderer.prototype.makeGridData = function(data) {
2534
        // recalculate the grid data
2535
        var xp = this._xaxis.series_u2p;
2536
        var yp = this._yaxis.series_u2p;
2537
        var gd = [];
2538
        var pgd = [];
2539
        for (var i=0; i<data.length; i++) {
2540
            if (data[i] != null) {
2541
                gd.push([xp.call(this._xaxis, data[i][0]), yp.call(this._yaxis, data[i][1])]);
2542
            }
2543
        }
2544
        return gd;
2545
    };
2546
 
2547
 
2548
    // called within scope of series.
2549
    $.jqplot.LineRenderer.prototype.draw = function(ctx, gd, options) {
2550
        var i;
2551
        var opts = (options != undefined) ? options : {};
2552
        var shadow = (opts.shadow != undefined) ? opts.shadow : this.shadow;
2553
        var showLine = (opts.showLine != undefined) ? opts.showLine : this.showLine;
2554
        var fill = (opts.fill != undefined) ? opts.fill : this.fill;
2555
        var fillAndStroke = (opts.fillAndStroke != undefined) ? opts.fillAndStroke : this.fillAndStroke;
2556
        ctx.save();
2557
        if (gd.length) {
2558
            if (showLine) {
2559
                // if we fill, we'll have to add points to close the curve.
2560
                if (fill) {
2561
                    if (this.fillToZero) {
2562
                        // have to break line up into shapes at axis crossings
2563
                        var negativeColors = new $.jqplot.ColorGenerator(this.negativeSeriesColors);
2564
                        var negativeColor = negativeColors.get(this.index);
2565
                        var isnegative = false;
2566
                        var posfs = opts.fillStyle;
2567
 
2568
                        // if stoking line as well as filling, get a copy of line data.
2569
                        if (fillAndStroke) {
2570
                            var fasgd = gd.slice(0);
2571
                        }
2572
                        // if not stacked, fill down to axis
2573
                        if (this.index == 0 || !this._stack) {
2574
 
2575
                            var tempgd = [];
2576
                            var pyzero = this._yaxis.series_u2p(0);
2577
                            var pxzero = this._xaxis.series_u2p(0);
2578
 
2579
                            if (this.fillAxis == 'y') {
2580
                                tempgd.push([gd[0][0], pyzero]);
2581
 
2582
                                for (var i=0; i<gd.length-1; i++) {
2583
                                    tempgd.push(gd[i]);
2584
                                    // do we have an axis crossing?
2585
                                    if (this._plotData[i][1] * this._plotData[i+1][1] < 0) {
2586
                                        if (this._plotData[i][1] < 0) {
2587
                                            isnegative = true;
2588
                                            opts.fillStyle = negativeColor;
2589
                                        }
2590
                                        else {
2591
                                            isnegative = false;
2592
                                            opts.fillStyle = posfs;
2593
                                        }
2594
 
2595
                                        var xintercept = gd[i][0] + (gd[i+1][0] - gd[i][0]) * (pyzero-gd[i][1])/(gd[i+1][1] - gd[i][1]);
2596
                                        tempgd.push([xintercept, pyzero]);
2597
                                        // now draw this shape and shadow.
2598
                                        if (shadow) {
2599
                                            this.renderer.shadowRenderer.draw(ctx, tempgd, opts);
2600
                                        }
2601
                                        this.renderer.shapeRenderer.draw(ctx, tempgd, opts);
2602
                                        // now empty temp array and continue
2603
                                        tempgd = [[xintercept, pyzero]];
2604
                                    }   
2605
                                }
2606
                                if (this._plotData[gd.length-1][1] < 0) {
2607
                                    isnegative = true;
2608
                                    opts.fillStyle = negativeColor;
2609
                                }
2610
                                else {
2611
                                    isnegative = false;
2612
                                    opts.fillStyle = posfs;
2613
                                }
2614
                                tempgd.push(gd[gd.length-1]);
2615
                                tempgd.push([gd[gd.length-1][0], pyzero]); 
2616
                            }
2617
                            // now draw this shape and shadow.
2618
                            if (shadow) {
2619
                                this.renderer.shadowRenderer.draw(ctx, tempgd, opts);
2620
                            }
2621
                            this.renderer.shapeRenderer.draw(ctx, tempgd, opts);
2622
 
2623
 
2624
                            // var gridymin = this._yaxis.series_u2p(0);
2625
                            // // IE doesn't return new length on unshift
2626
                            // gd.unshift([gd[0][0], gridymin]);
2627
                            // len = gd.length;
2628
                            // gd.push([gd[len - 1][0], gridymin]);                   
2629
                        }
2630
                        // if stacked, fill to line below 
2631
                        else {
2632
                            var prev = this._prevGridData;
2633
                            for (var i=prev.length; i>0; i--) {
2634
                                gd.push(prev[i-1]);
2635
                            }
2636
                            if (shadow) {
2637
                                this.renderer.shadowRenderer.draw(ctx, gd, opts);
2638
                            }
2639
 
2640
                            this.renderer.shapeRenderer.draw(ctx, gd, opts);
2641
                        }
2642
                    }
2643
                    else {                    
2644
                        // if stoking line as well as filling, get a copy of line data.
2645
                        if (fillAndStroke) {
2646
                            var fasgd = gd.slice(0);
2647
                        }
2648
                        // if not stacked, fill down to axis
2649
                        if (this.index == 0 || !this._stack) {
2650
                            // var gridymin = this._yaxis.series_u2p(this._yaxis.min) - this.gridBorderWidth / 2;
2651
                            var gridymin = ctx.canvas.height;
2652
                            // IE doesn't return new length on unshift
2653
                            gd.unshift([gd[0][0], gridymin]);
2654
                            len = gd.length;
2655
                            gd.push([gd[len - 1][0], gridymin]);                   
2656
                        }
2657
                        // if stacked, fill to line below 
2658
                        else {
2659
                            var prev = this._prevGridData;
2660
                            for (var i=prev.length; i>0; i--) {
2661
                                gd.push(prev[i-1]);
2662
                            }
2663
                        }
2664
                        if (shadow) {
2665
                            this.renderer.shadowRenderer.draw(ctx, gd, opts);
2666
                        }
2667
 
2668
                        this.renderer.shapeRenderer.draw(ctx, gd, opts);                        
2669
                    }
2670
                    if (fillAndStroke) {
2671
                        var fasopts = $.extend(true, {}, opts, {fill:false, closePath:false});
2672
                        this.renderer.shapeRenderer.draw(ctx, fasgd, fasopts);
2673
                        //////////
2674
                        // TODO: figure out some way to do shadows nicely
2675
                        // if (shadow) {
2676
                        //     this.renderer.shadowRenderer.draw(ctx, fasgd, fasopts);
2677
                        // }
2678
                        // now draw the markers
2679
                        if (this.markerRenderer.show) {
2680
                            for (i=0; i<fasgd.length; i++) {
2681
                                this.markerRenderer.draw(fasgd[i][0], fasgd[i][1], ctx, opts.markerOptions);
2682
                            }
2683
                        }
2684
                    }
2685
                }
2686
                else {
2687
                    if (shadow) {
2688
                        this.renderer.shadowRenderer.draw(ctx, gd, opts);
2689
                    }
2690
 
2691
                    this.renderer.shapeRenderer.draw(ctx, gd, opts);
2692
                }
2693
            }
2694
 
2695
            // now draw the markers
2696
            if (this.markerRenderer.show && !fill) {
2697
                for (i=0; i<gd.length; i++) {
2698
                    this.markerRenderer.draw(gd[i][0], gd[i][1], ctx, opts.markerOptions);
2699
                }
2700
            }
2701
        }
2702
 
2703
        ctx.restore();
2704
    };  
2705
 
2706
    $.jqplot.LineRenderer.prototype.drawShadow = function(ctx, gd, options) {
2707
        // This is a no-op, shadows drawn with lines.
2708
    };
2709
 
2710
 
2711
    // class: $.jqplot.LinearAxisRenderer
2712
    // The default jqPlot axis renderer, creating a numeric axis.
2713
    // The renderer has no additional options beyond the <Axis> object.
2714
    $.jqplot.LinearAxisRenderer = function() {
2715
    };
2716
 
2717
    // called with scope of axis object.
2718
    $.jqplot.LinearAxisRenderer.prototype.init = function(options){
2719
        $.extend(true, this, options);
2720
        var db = this._dataBounds;
2721
        // Go through all the series attached to this axis and find
2722
        // the min/max bounds for this axis.
2723
        for (var i=0; i<this._series.length; i++) {
2724
            var s = this._series[i];
2725
            var d = s._plotData;
2726
 
2727
            for (var j=0; j<d.length; j++) { 
2728
                if (this.name == 'xaxis' || this.name == 'x2axis') {
2729
                    if (d[j][0] < db.min || db.min == null) {
2730
                    	db.min = d[j][0];
2731
                    }
2732
                    if (d[j][0] > db.max || db.max == null) {
2733
                    	db.max = d[j][0];
2734
                    }
2735
                }              
2736
                else {
2737
                    if (d[j][1] < db.min || db.min == null) {
2738
                    	db.min = d[j][1];
2739
                    }
2740
                    if (d[j][1] > db.max || db.max == null) {
2741
                    	db.max = d[j][1];
2742
                    }
2743
                }              
2744
            }
2745
        }
2746
    };
2747
 
2748
    // called with scope of axis
2749
    $.jqplot.LinearAxisRenderer.prototype.draw = function(ctx) {
2750
        if (this.show) {
2751
            // populate the axis label and value properties.
2752
            // createTicks is a method on the renderer, but
2753
            // call it within the scope of the axis.
2754
            this.renderer.createTicks.call(this);
2755
            // fill a div with axes labels in the right direction.
2756
            // Need to pregenerate each axis to get it's bounds and
2757
            // position it and the labels correctly on the plot.
2758
            var dim=0;
2759
            var temp;
2760
 
2761
            this._elem = $('<div class="jqplot-axis jqplot-'+this.name+'" style="position:absolute;"></div>');
2762
 
2763
            if (this.name == 'xaxis' || this.name == 'x2axis') {
2764
            	this._elem.width(this._plotDimensions.width);
2765
            }
2766
            else {
2767
                this._elem.height(this._plotDimensions.height);
2768
            }
2769
 
2770
            // create a _label object.
2771
            this.labelOptions.axis = this.name;
2772
            this._label = new this.labelRenderer(this.labelOptions);
2773
            if (this._label.show) {
2774
                var elem = this._label.draw(ctx);
2775
                elem.appendTo(this._elem);
2776
            }
2777
 
2778
            if (this.showTicks) {
2779
                var t = this._ticks;
2780
                for (var i=0; i<t.length; i++) {
2781
                    var tick = t[i];
2782
                    if (tick.showLabel && (!tick.isMinorTick || this.showMinorTicks)) {
2783
                        var elem = tick.draw(ctx);
2784
                        elem.appendTo(this._elem);
2785
                    }
2786
                }
2787
            }
2788
        }
2789
        return this._elem;
2790
    };
2791
 
2792
    // called with scope of an axis
2793
    $.jqplot.LinearAxisRenderer.prototype.reset = function() {
2794
        this.min = this._min;
2795
        this.max = this._max;
2796
        this.tickInterval = this._tickInterval;
2797
        this.numberTicks = this._numberTicks;
2798
        // this._ticks = this.__ticks;
2799
    };
2800
 
2801
    // called with scope of axis
2802
    $.jqplot.LinearAxisRenderer.prototype.set = function() { 
2803
        var dim = 0;
2804
        var temp;
2805
        var w = 0;
2806
        var h = 0;
2807
        var lshow = (this._label == null) ? false : this._label.show;
2808
        if (this.show && this.showTicks) {
2809
            var t = this._ticks;
2810
            for (var i=0; i<t.length; i++) {
2811
                var tick = t[i];
2812
                if (tick.showLabel && (!tick.isMinorTick || this.showMinorTicks)) {
2813
                    if (this.name == 'xaxis' || this.name == 'x2axis') {
2814
                        temp = tick._elem.outerHeight(true);
2815
                    }
2816
                    else {
2817
                        temp = tick._elem.outerWidth(true);
2818
                    }
2819
                    if (temp > dim) {
2820
                    	dim = temp;
2821
                    }
2822
                }
2823
            }
2824
 
2825
            if (lshow) {
2826
                w = this._label._elem.outerWidth(true);
2827
                h = this._label._elem.outerHeight(true); 
2828
            }
2829
            if (this.name == 'xaxis') {
2830
                dim = dim + h;
2831
            	this._elem.css({'height':dim+'px', left:'0px', bottom:'0px'});
2832
            }
2833
            else if (this.name == 'x2axis') {
2834
                dim = dim + h;
2835
            	this._elem.css({'height':dim+'px', left:'0px', top:'0px'});
2836
            }
2837
            else if (this.name == 'yaxis') {
2838
                dim = dim + w;
2839
            	this._elem.css({'width':dim+'px', left:'0px', top:'0px'});
2840
            	if (lshow && this._label.constructor == $.jqplot.AxisLabelRenderer) {
2841
                    this._label._elem.css('width', w+'px');
2842
                }
2843
            }
2844
            else {
2845
                dim = dim + w;
2846
            	this._elem.css({'width':dim+'px', right:'0px', top:'0px'});
2847
            	if (lshow && this._label.constructor == $.jqplot.AxisLabelRenderer) {
2848
                    this._label._elem.css('width', w+'px');
2849
                }
2850
            }
2851
        }  
2852
    };    
2853
 
2854
    // called with scope of axis
2855
    $.jqplot.LinearAxisRenderer.prototype.createTicks = function() {
2856
        // we're are operating on an axis here
2857
        var ticks = this._ticks;
2858
        var userTicks = this.ticks;
2859
        var name = this.name;
2860
        // databounds were set on axis initialization.
2861
        var db = this._dataBounds;
2862
        var dim, interval;
2863
        var min, max;
2864
        var pos1, pos2;
2865
        var tt, i;
2866
 
2867
        // if we already have ticks, use them.
2868
        // ticks must be in order of increasing value.
2869
 
2870
        if (userTicks.length) {
2871
            // ticks could be 1D or 2D array of [val, val, ,,,] or [[val, label], [val, label], ...] or mixed
2872
            for (i=0; i<userTicks.length; i++){
2873
                var ut = userTicks[i];
2874
                var t = new this.tickRenderer(this.tickOptions);
2875
                if (ut.constructor == Array) {
2876
                    t.value = ut[0];
2877
                    t.label = ut[1];
2878
                    if (!this.showTicks) {
2879
                        t.showLabel = false;
2880
                        t.showMark = false;
2881
                    }
2882
                    else if (!this.showTickMarks) {
2883
                    	t.showMark = false;
2884
                    }
2885
                    t.setTick(ut[0], this.name);
2886
                    this._ticks.push(t);
2887
                }
2888
 
2889
                else {
2890
                    t.value = ut;
2891
                    if (!this.showTicks) {
2892
                        t.showLabel = false;
2893
                        t.showMark = false;
2894
                    }
2895
                    else if (!this.showTickMarks) {
2896
                    	t.showMark = false;
2897
                    }
2898
                    t.setTick(ut, this.name);
2899
                    this._ticks.push(t);
2900
                }
2901
            }
2902
            this.numberTicks = userTicks.length;
2903
            this.min = this._ticks[0].value;
2904
            this.max = this._ticks[this.numberTicks-1].value;
2905
            this.tickInterval = (this.max - this.min) / (this.numberTicks - 1);
2906
        }
2907
 
2908
        // we don't have any ticks yet, let's make some!
2909
        else {
2910
            if (name == 'xaxis' || name == 'x2axis') {
2911
                dim = this._plotDimensions.width;
2912
            }
2913
            else {
2914
                dim = this._plotDimensions.height;
2915
            }
2916
 
2917
            // if min, max and number of ticks specified, user can't specify interval.
2918
            if (!this.autoscale && this.min != null && this.max != null && this.numberTicks != null) {
2919
                this.tickInterval = null;
2920
            }
2921
 
2922
            // if max, min, and interval specified and interval won't fit, ignore interval.
2923
            // if (this.min != null && this.max != null && this.tickInterval != null) {
2924
            //     if (parseInt((this.max-this.min)/this.tickInterval, 10) != (this.max-this.min)/this.tickInterval) {
2925
            //         this.tickInterval = null;
2926
            //     }
2927
            // }
2928
 
2929
            min = ((this.min != null) ? this.min : db.min);
2930
            max = ((this.max != null) ? this.max : db.max);
2931
 
2932
            // if min and max are same, space them out a bit
2933
            if (min == max) {
2934
                var adj = 0.05;
2935
                if (min > 0) {
2936
                    adj = Math.max(Math.log(min)/Math.LN10, 0.05);
2937
                }
2938
                min -= adj;
2939
                max += adj;
2940
            }
2941
 
2942
            var range = max - min;
2943
            var rmin, rmax;
2944
            var temp;
2945
 
2946
            // autoscale.  Can't autoscale if min or max is supplied.
2947
            // Will use numberTicks and tickInterval if supplied.  Ticks
2948
            // across multiple axes may not line up depending on how
2949
            // bars are to be plotted.
2950
            if (this.autoscale && this.min == null && this.max == null) {
2951
                var rrange, ti, margin;
2952
                var forceMinZero = false;
2953
                var forceZeroLine = false;
2954
                var intervals = {min:null, max:null, average:null, stddev:null};
2955
                // if any series are bars, or if any are fill to zero, and if this
2956
                // is the axis to fill toward, check to see if we can start axis at zero.
2957
                for (var i=0; i<this._series.length; i++) {
2958
                    var s = this._series[i];
2959
                    var faname = (s.fillAxis == 'x') ? s._xaxis.name : s._yaxis.name;
2960
                    // check to see if this is the fill axis
2961
                    if (this.name == faname) {
2962
                        var vals = s._plotValues[s.fillAxis];
2963
                        var vmin = vals[0];
2964
                        var vmax = vals[0];
2965
                        for (var j=1; j<vals.length; j++) {
2966
                            if (vals[j] < vmin) {
2967
                                vmin = vals[j];
2968
                            }
2969
                            else if (vals[j] > vmax) {
2970
                                vmax = vals[j];
2971
                            }
2972
                        }
2973
                        var dp = (vmax - vmin) / vmax;
2974
                        // is this sries a bar?
2975
                        if (s.renderer.constructor == $.jqplot.BarRenderer) {
2976
                            // if no negative values and could also check range.
2977
                            if (vmin >= 0 && (s.fillToZero || dp > 0.1)) {
2978
                                forceMinZero = true;
2979
                            }
2980
                            else {
2981
                                forceMinZero = false;
2982
                                if (s.fill && s.fillToZero && vmin < 0 && vmax > 0) {
2983
                                    forceZeroLine = true;
2984
                                }
2985
                                else {
2986
                                    forceZeroLine = false;
2987
                                }
2988
                            }
2989
                        }
2990
 
2991
                        // if not a bar and filling, use appropriate method.
2992
                        else if (s.fill) {
2993
                            if (vmin >= 0 && (s.fillToZero || dp > 0.1)) {
2994
                                forceMinZero = true;
2995
                            }
2996
                            else if (vmin < 0 && vmax > 0 && s.fillToZero) {
2997
                                forceMinZero = false;
2998
                                forceZeroLine = true;
2999
                            }
3000
                            else {
3001
                                forceMinZero = false;
3002
                                forceZeroLine = false;
3003
                            }
3004
                        }
3005
 
3006
                        // if not a bar and not filling, only change existing state
3007
                        // if it doesn't make sense
3008
                        else if (vmin < 0) {
3009
                            forceMinZero = false;
3010
                        }
3011
                    }
3012
                }
3013
 
3014
                // check if we need make axis min at 0.
3015
                if (forceMinZero) {
3016
                    // compute number of ticks
3017
                    this.numberTicks = 2 + Math.ceil((dim-(this.tickSpacing-1))/this.tickSpacing);
3018
                    this.min = 0;
3019
                    // what order is this range?
3020
                    // what tick interval does that give us?
3021
                    ti = max/(this.numberTicks-1);
3022
                    temp = Math.pow(10, Math.abs(Math.floor(Math.log(ti)/Math.LN10)));
3023
                    if (ti/temp == parseInt(ti/temp, 10)) {
3024
                        ti += temp;
3025
                    }
3026
                    this.tickInterval = Math.ceil(ti/temp) * temp;
3027
                    this.max = this.tickInterval * (this.numberTicks - 1);
3028
                }
3029
 
3030
                // check if we need to make sure there is a tick at 0.
3031
                else if (forceZeroLine) {
3032
                    // compute number of ticks
3033
                    this.numberTicks = 2 + Math.ceil((dim-(this.tickSpacing-1))/this.tickSpacing);
3034
                    var ntmin = Math.ceil(Math.abs(min)/range*(this.numberTicks-1));
3035
                    var ntmax = this.numberTicks - 1  - ntmin;
3036
                    ti = Math.max(Math.abs(min/ntmin), Math.abs(max/ntmax));
3037
                    temp = Math.pow(10, Math.abs(Math.floor(Math.log(ti)/Math.LN10)));
3038
                    this.tickInterval = Math.ceil(ti/temp) * temp;
3039
                    this.max = this.tickInterval * ntmax;
3040
                    this.min = -this.tickInterval * ntmin;                  
3041
                }
3042
 
3043
                // if nothing else, do autoscaling which will try to line up ticks across axes.
3044
                else {  
3045
                    if (this.numberTicks == null){
3046
                        if (this.tickInterval) {
3047
                            this.numberTicks = 3 + Math.ceil(range / this.tickInterval);
3048
                        }
3049
                        else {
3050
                            this.numberTicks = 2 + Math.ceil((dim-(this.tickSpacing-1))/this.tickSpacing);
3051
                        }
3052
                    }
3053
 
3054
                    if (this.tickInterval == null) {
3055
                        // get a tick interval
3056
                        ti = range/(this.numberTicks - 1);
3057
 
3058
                        if (ti < 1) {
3059
                            temp = Math.pow(10, Math.abs(Math.floor(Math.log(ti)/Math.LN10)));
3060
                        }
3061
                        else {
3062
                            temp = 1;
3063
                        }
3064
                        this.tickInterval = Math.ceil(ti*temp*this.pad)/temp;
3065
                    }
3066
                    else {
3067
                        temp = 1 / this.tickInterval;
3068
                    }
3069
 
3070
                    // try to compute a nicer, more even tick interval
3071
                    // temp = Math.pow(10, Math.floor(Math.log(ti)/Math.LN10));
3072
                    // this.tickInterval = Math.ceil(ti/temp) * temp;
3073
                    rrange = this.tickInterval * (this.numberTicks - 1);
3074
                    margin = (rrange - range)/2;
3075
 
3076
                    if (this.min == null) {
3077
                        this.min = Math.floor(temp*(min-margin))/temp;
3078
                    }
3079
                    if (this.max == null) {
3080
                        this.max = this.min + rrange;
3081
                    }
3082
                }
3083
            }
3084
 
3085
            else {
3086
                rmin = (this.min != null) ? this.min : min - range*(this.padMin - 1);
3087
                rmax = (this.max != null) ? this.max : max + range*(this.padMax - 1);
3088
                this.min = rmin;
3089
                this.max = rmax;
3090
                range = this.max - this.min;
3091
 
3092
                if (this.numberTicks == null){
3093
                    // if tickInterval is specified by user, we will ignore computed maximum.
3094
                    // max will be equal or greater to fit even # of ticks.
3095
                    if (this.tickInterval != null) {
3096
                        this.numberTicks = Math.ceil((this.max - this.min)/this.tickInterval)+1;
3097
                        this.max = this.min + this.tickInterval*(this.numberTicks-1);
3098
                    }
3099
                    else if (dim > 100) {
3100
                        this.numberTicks = parseInt(3+(dim-100)/75, 10);
3101
                    }
3102
                    else {
3103
                        this.numberTicks = 2;
3104
                    }
3105
                }
3106
 
3107
                if (this.tickInterval == null) {
3108
                	this.tickInterval = range / (this.numberTicks-1);
3109
                }
3110
            }
3111
 
3112
            for (var i=0; i<this.numberTicks; i++){
3113
                tt = this.min + i * this.tickInterval;
3114
                var t = new this.tickRenderer(this.tickOptions);
3115
                // var t = new $.jqplot.AxisTickRenderer(this.tickOptions);
3116
                if (!this.showTicks) {
3117
                    t.showLabel = false;
3118
                    t.showMark = false;
3119
                }
3120
                else if (!this.showTickMarks) {
3121
                	t.showMark = false;
3122
                }
3123
                t.setTick(tt, this.name);
3124
                this._ticks.push(t);
3125
            }
3126
        }
3127
    };
3128
 
3129
    // called with scope of axis
3130
    $.jqplot.LinearAxisRenderer.prototype.pack = function(pos, offsets) {
3131
        var ticks = this._ticks;
3132
        var max = this.max;
3133
        var min = this.min;
3134
        var offmax = offsets.max;
3135
        var offmin = offsets.min;
3136
        var lshow = (this._label == null) ? false : this._label.show;
3137
 
3138
        for (var p in pos) {
3139
            this._elem.css(p, pos[p]);
3140
        }
3141
 
3142
        this._offsets = offsets;
3143
        // pixellength will be + for x axes and - for y axes becasue pixels always measured from top left.
3144
        var pixellength = offmax - offmin;
3145
        var unitlength = max - min;
3146
 
3147
        // point to unit and unit to point conversions references to Plot DOM element top left corner.
3148
        this.p2u = function(p){
3149
            return (p - offmin) * unitlength / pixellength + min;
3150
        };
3151
 
3152
        this.u2p = function(u){
3153
            return (u - min) * pixellength / unitlength + offmin;
3154
        };
3155
 
3156
        if (this.name == 'xaxis' || this.name == 'x2axis'){
3157
            this.series_u2p = function(u){
3158
                return (u - min) * pixellength / unitlength;
3159
            };
3160
            this.series_p2u = function(p){
3161
                return p * unitlength / pixellength + min;
3162
            };
3163
        }
3164
 
3165
        else {
3166
            this.series_u2p = function(u){
3167
                return (u - max) * pixellength / unitlength;
3168
            };
3169
            this.series_p2u = function(p){
3170
                return p * unitlength / pixellength + max;
3171
            };
3172
        }
3173
 
3174
        if (this.show) {
3175
            if (this.name == 'xaxis' || this.name == 'x2axis') {
3176
                for (i=0; i<ticks.length; i++) {
3177
                    var t = ticks[i];
3178
                    if (t.show && t.showLabel) {
3179
                        var shim;
3180
 
3181
                        if (t.constructor == $.jqplot.CanvasAxisTickRenderer && t.angle) {
3182
                            // will need to adjust auto positioning based on which axis this is.
3183
                            var temp = (this.name == 'xaxis') ? 1 : -1;
3184
                            switch (t.labelPosition) {
3185
                                case 'auto':
3186
                                    // position at end
3187
                                    if (temp * t.angle < 0) {
3188
                                        shim = -t.getWidth() + t._textRenderer.height * Math.sin(-t._textRenderer.angle) / 2;
3189
                                    }
3190
                                    // position at start
3191
                                    else {
3192
                                        shim = -t._textRenderer.height * Math.sin(t._textRenderer.angle) / 2;
3193
                                    }
3194
                                    break;
3195
                                case 'end':
3196
                                    shim = -t.getWidth() + t._textRenderer.height * Math.sin(-t._textRenderer.angle) / 2;
3197
                                    break;
3198
                                case 'start':
3199
                                    shim = -t._textRenderer.height * Math.sin(t._textRenderer.angle) / 2;
3200
                                    break;
3201
                                case 'middle':
3202
                                    shim = -t.getWidth()/2 + t._textRenderer.height * Math.sin(-t._textRenderer.angle) / 2;
3203
                                    break;
3204
                                default:
3205
                                    shim = -t.getWidth()/2 + t._textRenderer.height * Math.sin(-t._textRenderer.angle) / 2;
3206
                                    break;
3207
                            }
3208
                        }
3209
                        else {
3210
                            shim = -t.getWidth()/2;
3211
                        }
3212
                        var val = this.u2p(t.value) + shim + 'px';
3213
                        t._elem.css('left', val);
3214
                        t.pack();
3215
                    }
3216
                }
3217
                if (lshow) {
3218
                    var w = this._label._elem.outerWidth(true);
3219
                    this._label._elem.css('left', offmin + pixellength/2 - w/2 + 'px');
3220
                    if (this.name == 'xaxis') {
3221
                        this._label._elem.css('bottom', '0px');
3222
                    }
3223
                    else {
3224
                        this._label._elem.css('top', '0px');
3225
                    }
3226
                    this._label.pack();
3227
                }
3228
            }
3229
            else {
3230
                for (i=0; i<ticks.length; i++) {
3231
                    var t = ticks[i];
3232
                    if (t.show && t.showLabel) {                        
3233
                        var shim;
3234
                        if (t.constructor == $.jqplot.CanvasAxisTickRenderer && t.angle) {
3235
                            // will need to adjust auto positioning based on which axis this is.
3236
                            var temp = (this.name == 'yaxis') ? 1 : -1;
3237
                            switch (t.labelPosition) {
3238
                                case 'auto':
3239
                                    // position at end
3240
                                case 'end':
3241
                                    if (temp * t.angle < 0) {
3242
                                        shim = -t._textRenderer.height * Math.cos(-t._textRenderer.angle) / 2;
3243
                                    }
3244
                                    else {
3245
                                        shim = -t.getHeight() + t._textRenderer.height * Math.cos(t._textRenderer.angle) / 2;
3246
                                    }
3247
                                    break;
3248
                                case 'start':
3249
                                    if (t.angle > 0) {
3250
                                        shim = -t._textRenderer.height * Math.cos(-t._textRenderer.angle) / 2;
3251
                                    }
3252
                                    else {
3253
                                        shim = -t.getHeight() + t._textRenderer.height * Math.cos(t._textRenderer.angle) / 2;
3254
                                    }
3255
                                    break;
3256
                                case 'middle':
3257
                                    // if (t.angle > 0) {
3258
                                    //     shim = -t.getHeight()/2 + t._textRenderer.height * Math.sin(-t._textRenderer.angle) / 2;
3259
                                    // }
3260
                                    // else {
3261
                                    //     shim = -t.getHeight()/2 - t._textRenderer.height * Math.sin(t._textRenderer.angle) / 2;
3262
                                    // }
3263
                                    shim = -t.getHeight()/2;
3264
                                    break;
3265
                                default:
3266
                                    shim = -t.getHeight()/2;
3267
                                    break;
3268
                            }
3269
                        }
3270
                        else {
3271
                            shim = -t.getHeight()/2;
3272
                        }
3273
 
3274
                        var val = this.u2p(t.value) + shim + 'px';
3275
                        t._elem.css('top', val);
3276
                        t.pack();
3277
                    }
3278
                }
3279
                if (lshow) {
3280
                    var h = this._label._elem.outerHeight(true);
3281
                    this._label._elem.css('top', offmax - pixellength/2 - h/2 + 'px');
3282
                    if (this.name == 'yaxis') {
3283
                        this._label._elem.css('left', '0px');
3284
                    }
3285
                    else {
3286
                        this._label._elem.css('right', '0px');
3287
                    }   
3288
                    this._label.pack();
3289
                }
3290
            }
3291
        }
3292
    };
3293
 
3294
 
3295
	// class: $.jqplot.MarkerRenderer
3296
	// The default jqPlot marker renderer, rendering the points on the line.
3297
    $.jqplot.MarkerRenderer = function(options){
3298
        // Group: Properties
3299
 
3300
        // prop: show
3301
        // wether or not to show the marker.
3302
        this.show = true;
3303
        // prop: style
3304
        // One of diamond, circle, square, x, plus, dash, filledDiamond, filledCircle, filledSquare
3305
        this.style = 'filledCircle';
3306
        // prop: lineWidth
3307
        // size of the line for non-filled markers.
3308
        this.lineWidth = 2;
3309
        // prop: size
3310
        // Size of the marker (diameter or circle, length of edge of square, etc.)
3311
        this.size = 9.0;
3312
        // prop: color
3313
        // color of marker.  Will be set to color of series by default on init.
3314
        this.color = '#666666';
3315
        // prop: shadow
3316
        // wether or not to draw a shadow on the line
3317
        this.shadow = true;
3318
        // prop: shadowAngle
3319
        // Shadow angle in degrees
3320
        this.shadowAngle = 45;
3321
        // prop: shadowOffset
3322
        // Shadow offset from line in pixels
3323
        this.shadowOffset = 1;
3324
        // prop: shadowDepth
3325
        // Number of times shadow is stroked, each stroke offset shadowOffset from the last.
3326
        this.shadowDepth = 3;
3327
        // prop: shadowAlpha
3328
        // Alpha channel transparency of shadow.  0 = transparent.
3329
        this.shadowAlpha = '0.07';
3330
        // prop: shadowRenderer
3331
        // Renderer that will draws the shadows on the marker.
3332
        this.shadowRenderer = new $.jqplot.ShadowRenderer();
3333
        // prop: shapeRenderer
3334
        // Renderer that will draw the marker.
3335
        this.shapeRenderer = new $.jqplot.ShapeRenderer();
3336
 
3337
        $.extend(true, this, options);
3338
    };
3339
 
3340
    $.jqplot.MarkerRenderer.prototype.init = function(options) {
3341
        $.extend(true, this, options);
3342
        var sdopt = {angle:this.shadowAngle, offset:this.shadowOffset, alpha:this.shadowAlpha, lineWidth:this.lineWidth, depth:this.shadowDepth, closePath:true};
3343
        if (this.style.indexOf('filled') != -1) {
3344
            sdopt.fill = true;
3345
        }
3346
        if (this.style.indexOf('ircle') != -1) {
3347
            sdopt.isarc = true;
3348
            sdopt.closePath = false;
3349
        }
3350
        this.shadowRenderer.init(sdopt);
3351
 
3352
        var shopt = {fill:false, isarc:false, strokeStyle:this.color, fillStyle:this.color, lineWidth:this.lineWidth, closePath:true};
3353
        if (this.style.indexOf('filled') != -1) {
3354
            shopt.fill = true;
3355
        }
3356
        if (this.style.indexOf('ircle') != -1) {
3357
            shopt.isarc = true;
3358
            shopt.closePath = false;
3359
        }
3360
        this.shapeRenderer.init(shopt);
3361
    };
3362
 
3363
    $.jqplot.MarkerRenderer.prototype.drawDiamond = function(x, y, ctx, fill, options) {
3364
        var stretch = 1.2;
3365
        var dx = this.size/2/stretch;
3366
        var dy = this.size/2*stretch;
3367
        var points = [[x-dx, y], [x, y+dy], [x+dx, y], [x, y-dy]];
3368
        if (this.shadow) {
3369
            this.shadowRenderer.draw(ctx, points);
3370
        }
3371
        this.shapeRenderer.draw(ctx, points, options);
3372
 
3373
        ctx.restore();
3374
    };
3375
 
3376
    $.jqplot.MarkerRenderer.prototype.drawPlus = function(x, y, ctx, fill, options) {
3377
        var stretch = 1.0;
3378
        var dx = this.size/2*stretch;
3379
        var dy = this.size/2*stretch;
3380
        var points1 = [[x, y-dy], [x, y+dy]];
3381
        var points2 = [[x+dx, y], [x-dx, y]];
3382
        var opts = $.extend(true, {}, this.options, {closePath:false});
3383
        if (this.shadow) {
3384
            this.shadowRenderer.draw(ctx, points1, {closePath:false});
3385
            this.shadowRenderer.draw(ctx, points2, {closePath:false});
3386
        }
3387
        this.shapeRenderer.draw(ctx, points1, opts);
3388
        this.shapeRenderer.draw(ctx, points2, opts);
3389
 
3390
        ctx.restore();
3391
    };
3392
 
3393
    $.jqplot.MarkerRenderer.prototype.drawX = function(x, y, ctx, fill, options) {
3394
        var stretch = 1.0;
3395
        var dx = this.size/2*stretch;
3396
        var dy = this.size/2*stretch;
3397
        var opts = $.extend(true, {}, this.options, {closePath:false});
3398
        var points1 = [[x-dx, y-dy], [x+dx, y+dy]];
3399
        var points2 = [[x-dx, y+dy], [x+dx, y-dy]];
3400
        if (this.shadow) {
3401
            this.shadowRenderer.draw(ctx, points1, {closePath:false});
3402
            this.shadowRenderer.draw(ctx, points2, {closePath:false});
3403
        }
3404
        this.shapeRenderer.draw(ctx, points1, opts);
3405
        this.shapeRenderer.draw(ctx, points2, opts);
3406
 
3407
        ctx.restore();
3408
    };
3409
 
3410
    $.jqplot.MarkerRenderer.prototype.drawDash = function(x, y, ctx, fill, options) {
3411
        var stretch = 1.0;
3412
        var dx = this.size/2*stretch;
3413
        var dy = this.size/2*stretch;
3414
        var points = [[x-dx, y], [x+dx, y]];
3415
        if (this.shadow) {
3416
            this.shadowRenderer.draw(ctx, points);
3417
        }
3418
        this.shapeRenderer.draw(ctx, points, options);
3419
 
3420
        ctx.restore();
3421
    };
3422
 
3423
    $.jqplot.MarkerRenderer.prototype.drawSquare = function(x, y, ctx, fill, options) {
3424
        var stretch = 1.0;
3425
        var dx = this.size/2/stretch;
3426
        var dy = this.size/2*stretch;
3427
        var points = [[x-dx, y-dy], [x-dx, y+dy], [x+dx, y+dy], [x+dx, y-dy]];
3428
        if (this.shadow) {
3429
            this.shadowRenderer.draw(ctx, points);
3430
        }
3431
        this.shapeRenderer.draw(ctx, points, options);
3432
 
3433
        ctx.restore();
3434
    };
3435
 
3436
    $.jqplot.MarkerRenderer.prototype.drawCircle = function(x, y, ctx, fill, options) {
3437
        var radius = this.size/2;
3438
        var end = 2*Math.PI;
3439
        var points = [x, y, radius, 0, end, true];
3440
        if (this.shadow) {
3441
            this.shadowRenderer.draw(ctx, points);
3442
        }
3443
        this.shapeRenderer.draw(ctx, points, options);
3444
 
3445
        ctx.restore();
3446
    };
3447
 
3448
    $.jqplot.MarkerRenderer.prototype.draw = function(x, y, ctx, options) {
3449
        options = options || {};
3450
        switch (this.style) {
3451
            case 'diamond':
3452
                this.drawDiamond(x,y,ctx, false, options);
3453
                break;
3454
            case 'filledDiamond':
3455
                this.drawDiamond(x,y,ctx, true, options);
3456
                break;
3457
            case 'circle':
3458
                this.drawCircle(x,y,ctx, false, options);
3459
                break;
3460
            case 'filledCircle':
3461
                this.drawCircle(x,y,ctx, true, options);
3462
                break;
3463
            case 'square':
3464
                this.drawSquare(x,y,ctx, false, options);
3465
                break;
3466
            case 'filledSquare':
3467
                this.drawSquare(x,y,ctx, true, options);
3468
                break;
3469
            case 'x':
3470
                this.drawX(x,y,ctx, true, options);
3471
                break;
3472
            case 'plus':
3473
                this.drawPlus(x,y,ctx, true, options);
3474
                break;
3475
            case 'dash':
3476
                this.drawDash(x,y,ctx, true, options);
3477
                break;
3478
            default:
3479
                this.drawDiamond(x,y,ctx, false, options);
3480
                break;
3481
        }
3482
    };
3483
 
3484
	// class: $.jqplot.shadowRenderer
3485
	// The default jqPlot shadow renderer, rendering shadows behind shapes.
3486
    $.jqplot.ShadowRenderer = function(options){ 
3487
        // Group: Properties
3488
 
3489
        // prop: angle
3490
        // Angle of the shadow in degrees.  Measured counter-clockwise from the x axis.
3491
        this.angle = 45;
3492
        // prop: offset
3493
        // Pixel offset at the given shadow angle of each shadow stroke from the last stroke.
3494
        this.offset = 1;
3495
        // prop: alpha
3496
        // alpha transparency of shadow stroke.
3497
        this.alpha = 0.07;
3498
        // prop: lineWidth
3499
        // width of the shadow line stroke.
3500
        this.lineWidth = 1.5;
3501
        // prop: lineJoin
3502
        // How line segments of the shadow are joined.
3503
        this.lineJoin = 'miter';
3504
        // prop: lineCap
3505
        // how ends of the shadow line are rendered.
3506
        this.lineCap = 'round';
3507
        // prop; closePath
3508
        // whether line path segment is closed upon itself.
3509
        this.closePath = false;
3510
        // prop: fill
3511
        // whether to fill the shape.
3512
        this.fill = false;
3513
        // prop: depth
3514
        // how many times the shadow is stroked.  Each stroke will be offset by offset at angle degrees.
3515
        this.depth = 3;
3516
        // prop: isarc
3517
        // wether the shadow is an arc or not.
3518
        this.isarc = false;
3519
 
3520
        $.extend(true, this, options);
3521
    };
3522
 
3523
    $.jqplot.ShadowRenderer.prototype.init = function(options) {
3524
        $.extend(true, this, options);
3525
    };
3526
 
3527
    // function: draw
3528
    // draws an transparent black (i.e. gray) shadow.
3529
    //
3530
    // ctx - canvas drawing context
3531
    // points - array of points or [x, y, radius, start angle (rad), end angle (rad)]
3532
    $.jqplot.ShadowRenderer.prototype.draw = function(ctx, points, options) {
3533
        ctx.save();
3534
        var opts = (options != null) ? options : {};
3535
        var fill = (opts.fill != null) ? opts.fill : this.fill;
3536
        var closePath = (opts.closePath != null) ? opts.closePath : this.closePath;
3537
        var offset = (opts.offset != null) ? opts.offset : this.offset;
3538
        var alpha = (opts.alpha != null) ? opts.alpha : this.alpha;
3539
        var depth = (opts.depth != null) ? opts.depth : this.depth;
3540
        ctx.lineWidth = (opts.lineWidth != null) ? opts.lineWidth : this.lineWidth;
3541
        ctx.lineJoin = (opts.lineJoin != null) ? opts.lineJoin : this.lineJoin;
3542
        ctx.lineCap = (opts.lineCap != null) ? opts.lineCap : this.lineCap;
3543
        ctx.strokeStyle = 'rgba(0,0,0,'+alpha+')';
3544
        ctx.fillStyle = 'rgba(0,0,0,'+alpha+')';
3545
        for (var j=0; j<depth; j++) {
3546
            ctx.translate(Math.cos(this.angle*Math.PI/180)*offset, Math.sin(this.angle*Math.PI/180)*offset);
3547
            ctx.beginPath();
3548
            if (this.isarc) {
3549
                ctx.arc(points[0], points[1], points[2], points[3], points[4], true);                
3550
            }
3551
            else {
3552
                ctx.moveTo(points[0][0], points[0][1]);
3553
                for (var i=1; i<points.length; i++) {
3554
                    ctx.lineTo(points[i][0], points[i][1]);
3555
                }
3556
 
3557
            }
3558
            if (closePath) {
3559
            	ctx.closePath();
3560
            }
3561
            if (fill) {
3562
            	ctx.fill();
3563
            }
3564
            else {
3565
                ctx.stroke();
3566
            }
3567
        }
3568
        ctx.restore();
3569
    };
3570
 
3571
	// class: $.jqplot.shapeRenderer
3572
	// The default jqPlot shape renderer.  Given a set of points will
3573
	// plot them and either stroke a line (fill = false) or fill them (fill = true).
3574
	// If a filled shape is desired, closePath = true must also be set to close
3575
	// the shape.
3576
    $.jqplot.ShapeRenderer = function(options){
3577
 
3578
        this.lineWidth = 1.5;
3579
        // prop: lineJoin
3580
        // How line segments of the shadow are joined.
3581
        this.lineJoin = 'miter';
3582
        // prop: lineCap
3583
        // how ends of the shadow line are rendered.
3584
        this.lineCap = 'round';
3585
        // prop; closePath
3586
        // whether line path segment is closed upon itself.
3587
        this.closePath = false;
3588
        // prop: fill
3589
        // whether to fill the shape.
3590
        this.fill = false;
3591
        // prop: isarc
3592
        // wether the shadow is an arc or not.
3593
        this.isarc = false;
3594
        // prop: fillRect
3595
        // true to draw shape as a filled rectangle.
3596
        this.fillRect = false;
3597
        // prop: strokeRect
3598
        // true to draw shape as a stroked rectangle.
3599
        this.strokeRect = false;
3600
        // prop: clearRect
3601
        // true to cear a rectangle.
3602
        this.clearRect = false;
3603
        // prop: strokeStyle
3604
        // css color spec for the stoke style
3605
        this.strokeStyle = '#999999';
3606
        // prop: fillStyle
3607
        // css color spec for the fill style.
3608
        this.fillStyle = '#999999'; 
3609
 
3610
        $.extend(true, this, options);
3611
    };
3612
 
3613
    $.jqplot.ShapeRenderer.prototype.init = function(options) {
3614
        $.extend(true, this, options);
3615
    };
3616
 
3617
    // function: draw
3618
    // draws the shape.
3619
    //
3620
    // ctx - canvas drawing context
3621
    // points - array of points for shapes or 
3622
    // [x, y, width, height] for rectangles or
3623
    // [x, y, radius, start angle (rad), end angle (rad)] for circles and arcs.
3624
    $.jqplot.ShapeRenderer.prototype.draw = function(ctx, points, options) {
3625
        ctx.save();
3626
        var opts = (options != null) ? options : {};
3627
        var fill = (opts.fill != null) ? opts.fill : this.fill;
3628
        var closePath = (opts.closePath != null) ? opts.closePath : this.closePath;
3629
        var fillRect = (opts.fillRect != null) ? opts.fillRect : this.fillRect;
3630
        var strokeRect = (opts.strokeRect != null) ? opts.strokeRect : this.strokeRect;
3631
        var clearRect = (opts.clearRect != null) ? opts.clearRect : this.clearRect;
3632
        var isarc = (opts.isarc != null) ? opts.isarc : this.isarc;
3633
        ctx.lineWidth = opts.lineWidth || this.lineWidth;
3634
        ctx.lineJoin = opts.lineJoing || this.lineJoin;
3635
        ctx.lineCap = opts.lineCap || this.lineCap;
3636
        ctx.strokeStyle = (opts.strokeStyle || opts.color) || this.strokeStyle;
3637
        ctx.fillStyle = opts.fillStyle || this.fillStyle;
3638
        ctx.beginPath();
3639
        if (isarc) {
3640
            ctx.arc(points[0], points[1], points[2], points[3], points[4], true);   
3641
            if (closePath) {
3642
                ctx.closePath();
3643
            }
3644
            if (fill) {
3645
            	ctx.fill();
3646
            }
3647
            else {
3648
                ctx.stroke();
3649
            }             
3650
        }
3651
        else if (fillRect) {
3652
            ctx.fillRect(points[0], points[1], points[2], points[3]);
3653
        }
3654
        else if (strokeRect) {
3655
            ctx.strokeRect(points[0], points[1], points[2], points[3]);
3656
        }
3657
        else if (clearRect) {
3658
            ctx.clearRect(points[0], points[1], points[2], points[3]);
3659
        }
3660
        else {
3661
            ctx.moveTo(points[0][0], points[0][1]);
3662
            for (var i=1; i<points.length; i++) {
3663
                ctx.lineTo(points[i][0], points[i][1]);
3664
            }
3665
            if (closePath) {
3666
                ctx.closePath();
3667
            }
3668
            if (fill) {
3669
            	ctx.fill();
3670
            }
3671
            else {
3672
                ctx.stroke();
3673
            }
3674
        }
3675
        ctx.restore();
3676
    };
3677
 
3678
    // class $.jqplot.TableLegendRenderer
3679
    // The default legend renderer for jqPlot, this class has no options beyond the <Legend> class.
3680
    $.jqplot.TableLegendRenderer = function(){
3681
        //
3682
    };
3683
 
3684
    $.jqplot.TableLegendRenderer.prototype.init = function(options) {
3685
        $.extend(true, this, options);
3686
    };
3687
 
3688
    $.jqplot.TableLegendRenderer.prototype.addrow = function (label, color, pad) {
3689
        var rs = (pad) ? this.rowSpacing : '0';
3690
        var tr = $('<tr class="jqplot-table-legend"></tr>').appendTo(this._elem);
3691
        $('<td class="jqplot-table-legend" style="text-align:center;padding-top:'+rs+';">'+
3692
            '<div><div class="jqplot-table-legend-swatch" style="border-color:'+color+';"></div>'+
3693
            '</div></td>').appendTo(tr);
3694
        var elem = $('<td class="jqplot-table-legend" style="padding-top:'+rs+';"></td>');
3695
        elem.appendTo(tr);
3696
        if (this.escapeHtml) {
3697
            elem.text(label);
3698
        }
3699
        else {
3700
            elem.html(label);
3701
        }
3702
    };
3703
 
3704
    // called with scope of legend
3705
    $.jqplot.TableLegendRenderer.prototype.draw = function() {
3706
        var legend = this;
3707
        if (this.show) {
3708
            var series = this._series;
3709
            // make a table.  one line label per row.
3710
            var ss = 'position:absolute;';
3711
            ss += (this.background) ? 'background:'+this.background+';' : '';
3712
            ss += (this.border) ? 'border:'+this.border+';' : '';
3713
            ss += (this.fontSize) ? 'font-size:'+this.fontSize+';' : '';
3714
            ss += (this.fontFamily) ? 'font-family:'+this.fontFamily+';' : '';
3715
            ss += (this.textColor) ? 'color:'+this.textColor+';' : '';
3716
            this._elem = $('<table class="jqplot-table-legend" style="'+ss+'"></table>');
3717
 
3718
            var pad = false;
3719
            for (var i = 0; i< series.length; i++) {
3720
                s = series[i];
3721
                if (s.show && s.showLabel) {
3722
                    var lt = s.label.toString();
3723
                    if (lt) {
3724
                        var color = s.color;
3725
                        if (s._stack && !s.fill) {
3726
                            color = '';
3727
                        }
3728
                        this.renderer.addrow.call(this, lt, color, pad);
3729
                        pad = true;
3730
                    }
3731
                    // let plugins add more rows to legend.  Used by trend line plugin.
3732
                    for (var j=0; j<$.jqplot.addLegendRowHooks.length; j++) {
3733
                        var item = $.jqplot.addLegendRowHooks[j].call(this, s);
3734
                        if (item) {
3735
                            this.renderer.addrow.call(this, item.label, item.color, pad);
3736
                            pad = true;
3737
                        } 
3738
                    }
3739
                }
3740
            }
3741
        }
3742
        return this._elem;
3743
    };
3744
 
3745
    $.jqplot.TableLegendRenderer.prototype.pack = function(offsets) {
3746
        if (this.show) {
3747
            // fake a grid for positioning
3748
            var grid = {_top:offsets.top, _left:offsets.left, _right:offsets.right, _bottom:this._plotDimensions.height - offsets.bottom};      
3749
            switch (this.location) {
3750
                case 'nw':
3751
                    var a = grid._left + this.xoffset;
3752
                    var b = grid._top + this.yoffset;
3753
                    this._elem.css('left', a);
3754
                    this._elem.css('top', b);
3755
                    break;
3756
                case 'n':
3757
                    var a = (offsets.left + (this._plotDimensions.width - offsets.right))/2 - this.getWidth()/2;
3758
                    var b = grid._top + this.yoffset;
3759
                    this._elem.css('left', a);
3760
                    this._elem.css('top', b);
3761
                    break;
3762
                case 'ne':
3763
                    var a = offsets.right + this.xoffset;
3764
                    var b = grid._top + this.yoffset;
3765
                    this._elem.css({right:a, top:b});
3766
                    break;
3767
                case 'e':
3768
                    var a = offsets.right + this.xoffset;
3769
                    var b = (offsets.top + (this._plotDimensions.height - offsets.bottom))/2 - this.getHeight()/2;
3770
                    this._elem.css({right:a, top:b});
3771
                    break;
3772
                case 'se':
3773
                    var a = offsets.right + this.xoffset;
3774
                    var b = offsets.bottom + this.yoffset;
3775
                    this._elem.css({right:a, bottom:b});
3776
                    break;
3777
                case 's':
3778
                    var a = (offsets.left + (this._plotDimensions.width - offsets.right))/2 - this.getWidth()/2;
3779
                    var b = offsets.bottom + this.yoffset;
3780
                    this._elem.css({left:a, bottom:b});
3781
                    break;
3782
                case 'sw':
3783
                    var a = grid._left + this.xoffset;
3784
                    var b = offsets.bottom + this.yoffset;
3785
                    this._elem.css({left:a, bottom:b});
3786
                    break;
3787
                case 'w':
3788
                    var a = grid._left + this.xoffset;
3789
                    var b = (offsets.top + (this._plotDimensions.height - offsets.bottom))/2 - this.getHeight()/2;
3790
                    this._elem.css({left:a, top:b});
3791
                    break;
3792
                default:  // same as 'se'
3793
                    var a = grid._right - this.xoffset;
3794
                    var b = grid._bottom + this.yoffset;
3795
                    this._elem.css({right:a, bottom:b});
3796
                    break;
3797
            }
3798
        } 
3799
    };
3800
 
3801
    /**
3802
     * JavaScript printf/sprintf functions.
3803
     *
3804
     * This code is unrestricted: you are free to use it however you like.
3805
     * 
3806
     * The functions should work as expected, performing left or right alignment,
3807
     * truncating strings, outputting numbers with a required precision etc.
3808
     *
3809
     * For complex cases, these functions follow the Perl implementations of
3810
     * (s)printf, allowing arguments to be passed out-of-order, and to set the
3811
     * precision or length of the output based on arguments instead of fixed
3812
     * numbers.
3813
     *
3814
     * See http://perldoc.perl.org/functions/sprintf.html for more information.
3815
     *
3816
     * Implemented:
3817
     * - zero and space-padding
3818
     * - right and left-alignment,
3819
     * - base X prefix (binary, octal and hex)
3820
     * - positive number prefix
3821
     * - (minimum) width
3822
     * - precision / truncation / maximum width
3823
     * - out of order arguments
3824
     *
3825
     * Not implemented (yet):
3826
     * - vector flag
3827
     * - size (bytes, words, long-words etc.)
3828
     * 
3829
     * Will not implement:
3830
     * - %n or %p (no pass-by-reference in JavaScript)
3831
     *
3832
     * @version 2007.04.27
3833
     * @author Ash Searle
3834
     */
3835
 
3836
     /**
3837
      * @Modifications 2009.05.26
3838
      * @author Chris Leonello
3839
      * 
3840
      * Added %p %P specifier
3841
      * Acts like %g or %G but will not add more significant digits to the output than present in the input.
3842
      * Example:
3843
      * Format: '%.3p', Input: 0.012, Output: 0.012
3844
      * Format: '%.3g', Input: 0.012, Output: 0.0120
3845
      * Format: '%.4p', Input: 12.0, Output: 12.0
3846
      * Format: '%.4g', Input: 12.0, Output: 12.00
3847
      * Format: '%.4p', Input: 4.321e-5, Output: 4.321e-5
3848
      * Format: '%.4g', Input: 4.321e-5, Output: 4.3210e-5
3849
      */
3850
    $.jqplot.sprintf = function() {
3851
        function pad(str, len, chr, leftJustify) {
3852
    	    var padding = (str.length >= len) ? '' : Array(1 + len - str.length >>> 0).join(chr);
3853
        	return leftJustify ? str + padding : padding + str;
3854
 
3855
        }
3856
 
3857
        function justify(value, prefix, leftJustify, minWidth, zeroPad, htmlSpace) {
3858
    	    var diff = minWidth - value.length;
3859
        	if (diff > 0) {
3860
        	    var spchar = ' ';
3861
        	    if (htmlSpace) { spchar = '&nbsp;'; }
3862
        	    if (leftJustify || !zeroPad) {
3863
        		    value = pad(value, minWidth, spchar, leftJustify);
3864
        	    } else {
3865
        		    value = value.slice(0, prefix.length) + pad('', diff, '0', true) + value.slice(prefix.length);
3866
        	    }
3867
        	}
3868
        	return value;
3869
        }
3870
 
3871
        function formatBaseX(value, base, prefix, leftJustify, minWidth, precision, zeroPad, htmlSpace) {
3872
        	// Note: casts negative numbers to positive ones
3873
        	var number = value >>> 0;
3874
        	prefix = prefix && number && {'2': '0b', '8': '0', '16': '0x'}[base] || '';
3875
        	value = prefix + pad(number.toString(base), precision || 0, '0', false);
3876
        	return justify(value, prefix, leftJustify, minWidth, zeroPad, htmlSpace);
3877
        }
3878
 
3879
        function formatString(value, leftJustify, minWidth, precision, zeroPad, htmlSpace) {
3880
        	if (precision != null) {
3881
        	    value = value.slice(0, precision);
3882
        	}
3883
        	return justify(value, '', leftJustify, minWidth, zeroPad, htmlSpace);
3884
        }
3885
 
3886
        var a = arguments, i = 0, format = a[i++];
3887
 
3888
        return format.replace($.jqplot.sprintf.regex, function(substring, valueIndex, flags, minWidth, _, precision, type) {
3889
    	    if (substring == '%%') { return '%'; }
3890
 
3891
    	    // parse flags
3892
    	    var leftJustify = false, positivePrefix = '', zeroPad = false, prefixBaseX = false, htmlSpace = false;
3893
        	    for (var j = 0; flags && j < flags.length; j++) switch (flags.charAt(j)) {
3894
        		case ' ': positivePrefix = ' '; break;
3895
        		case '+': positivePrefix = '+'; break;
3896
        		case '-': leftJustify = true; break;
3897
        		case '0': zeroPad = true; break;
3898
        		case '#': prefixBaseX = true; break;
3899
        		case '&': htmlSpace = true; break;
3900
    	    }
3901
 
3902
    	    // parameters may be null, undefined, empty-string or real valued
3903
    	    // we want to ignore null, undefined and empty-string values
3904
 
3905
    	    if (!minWidth) {
3906
    		    minWidth = 0;
3907
    	    } 
3908
    	    else if (minWidth == '*') {
3909
    		    minWidth = +a[i++];
3910
    	    } 
3911
    	    else if (minWidth.charAt(0) == '*') {
3912
    		    minWidth = +a[minWidth.slice(1, -1)];
3913
    	    } 
3914
    	    else {
3915
    		    minWidth = +minWidth;
3916
    	    }
3917
 
3918
    	    // Note: undocumented perl feature:
3919
    	    if (minWidth < 0) {
3920
        		minWidth = -minWidth;
3921
        		leftJustify = true;
3922
    	    }
3923
 
3924
    	    if (!isFinite(minWidth)) {
3925
    		    throw new Error('$.jqplot.sprintf: (minimum-)width must be finite');
3926
    	    }
3927
 
3928
    	    if (!precision) {
3929
    		    precision = 'fFeE'.indexOf(type) > -1 ? 6 : (type == 'd') ? 0 : void(0);
3930
    	    } 
3931
    	    else if (precision == '*') {
3932
    		    precision = +a[i++];
3933
    	    } 
3934
    	    else if (precision.charAt(0) == '*') {
3935
    		    precision = +a[precision.slice(1, -1)];
3936
    	    } 
3937
    	    else {
3938
    		    precision = +precision;
3939
    	    }
3940
 
3941
    	    // grab value using valueIndex if required?
3942
    	    var value = valueIndex ? a[valueIndex.slice(0, -1)] : a[i++];
3943
 
3944
    	    switch (type) {
3945
    		case 's': {
3946
    		    if (value == null) {
3947
    		        return '';
3948
    		    }
3949
    		    return formatString(String(value), leftJustify, minWidth, precision, zeroPad, htmlSpace);
3950
		    }
3951
    		case 'c': return formatString(String.fromCharCode(+value), leftJustify, minWidth, precision, zeroPad, htmlSpace);
3952
    		case 'b': return formatBaseX(value, 2, prefixBaseX, leftJustify, minWidth, precision, zeroPad,htmlSpace);
3953
    		case 'o': return formatBaseX(value, 8, prefixBaseX, leftJustify, minWidth, precision, zeroPad, htmlSpace);
3954
    		case 'x': return formatBaseX(value, 16, prefixBaseX, leftJustify, minWidth, precision, zeroPad, htmlSpace);
3955
    		case 'X': return formatBaseX(value, 16, prefixBaseX, leftJustify, minWidth, precision, zeroPad, htmlSpace).toUpperCase();
3956
    		case 'u': return formatBaseX(value, 10, prefixBaseX, leftJustify, minWidth, precision, zeroPad, htmlSpace);
3957
    		case 'i':
3958
    		case 'd': {
3959
              var number = parseInt(+value, 10);
3960
              if (isNaN(number)) {
3961
                return '';
3962
              }
3963
              var prefix = number < 0 ? '-' : positivePrefix;
3964
              value = prefix + pad(String(Math.abs(number)), precision, '0', false);
3965
              return justify(value, prefix, leftJustify, minWidth, zeroPad, htmlSpace);
3966
    			  }
3967
    		case 'e':
3968
    		case 'E':
3969
    		case 'f':
3970
    		case 'F':
3971
    		case 'g':
3972
    		case 'G':
3973
    		          {
3974
    			      var number = +value;
3975
                      if (isNaN(number)) {
3976
                          return '';
3977
                      }
3978
    			      var prefix = number < 0 ? '-' : positivePrefix;
3979
    			      var method = ['toExponential', 'toFixed', 'toPrecision']['efg'.indexOf(type.toLowerCase())];
3980
    			      var textTransform = ['toString', 'toUpperCase']['eEfFgG'.indexOf(type) % 2];
3981
    			      value = prefix + Math.abs(number)[method](precision);
3982
    			      return justify(value, prefix, leftJustify, minWidth, zeroPad, htmlSpace)[textTransform]();
3983
    			  }
3984
    		case 'p':
3985
    		case 'P':
3986
    		{
3987
    		    // make sure number is a number
3988
                var number = +value;
3989
                if (isNaN(number)) {
3990
                    return '';
3991
                }
3992
                var prefix = number < 0 ? '-' : positivePrefix;
3993
 
3994
                var parts = String(Number(Math.abs(number)).toExponential()).split(/e|E/);
3995
                var sd = (parts[0].indexOf('.') != -1) ? parts[0].length - 1 : parts[0].length;
3996
                var zeros = (parts[1] < 0) ? -parts[1] - 1 : 0;
3997
 
3998
                if (Math.abs(number) < 1) {
3999
                    if (sd + zeros  <= precision) {
4000
                        value = prefix + Math.abs(number).toPrecision(sd);
4001
                    }
4002
                    else {
4003
                        if (sd  <= precision - 1) {
4004
                            value = prefix + Math.abs(number).toExponential(sd-1);
4005
                        }
4006
                        else {
4007
                            value = prefix + Math.abs(number).toExponential(precision-1);
4008
                        }
4009
                    }
4010
                }
4011
                else {
4012
                    var prec = (sd <= precision) ? sd : precision;
4013
                    value = prefix + Math.abs(number).toPrecision(prec);
4014
                }
4015
                var textTransform = ['toString', 'toUpperCase']['pP'.indexOf(type) % 2];
4016
                return justify(value, prefix, leftJustify, minWidth, zeroPad, htmlSpace)[textTransform]();
4017
            }
4018
            case 'n': return '';
4019
    		default: return substring;
4020
    	    }
4021
    	});
4022
    };
4023
 
4024
    $.jqplot.sprintf.regex = /%%|%(\d+\$)?([-+#0& ]*)(\*\d+\$|\*|\d+)?(\.(\*\d+\$|\*|\d+))?([nAscboxXuidfegpEGP])/g;
4025
 
4026
})(jQuerySysStatWidget || jQuery);