-
Notifications
You must be signed in to change notification settings - Fork 26
/
EJSChart.js
20054 lines (16207 loc) · 636 KB
/
EJSChart.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/**********************************************************************
/* Emprise JavaScript Charts 2.3.1 http://www.ejschart.com/
/* Copyright (C) 2006-2013 Emprise Corporation. All Rights Reserved.
/*
/* WARNING: This software program is protected by copyright law
/* and international treaties. Unauthorized reproduction or
/* distribution of this program, or any portion of it, may result
/* in severe civil and criminal penalties, and will be prosecuted
/* to the maximum extent possible under the law.
/*
/* See http://www.ejschart.com/license.html for full license.
/**********************************************************************/
//(function() {
if (window.console == undefined) {
window.console = {
log: function(msg) {}
};
};
// --------------------------------------------------------------------------
// IE Fix: Background Image Cache
// --------------------------------------------------------------------------
// Force IE to cache all background images to reduce/eliminate the "flashing"
// of hover events when a background image is present on the item affected.
// --------------------------------------------------------------------------
try { document.execCommand("BackgroundImageCache", false, true); } catch(e) {};
// --------------------------------------------------------------------------
// Component Information
// --------------------------------------------------------------------------
// Holds all of the information describing this component. This information
// is shown in the "About EJSChart" window.
// --------------------------------------------------------------------------
var __title = 'Emprise JavaScript Charts'; // Title of the chart component
var __short_title = 'EJSChart'; // Short version of the title
var __version = '2.3'; // Version
var __url = 'http://www.ejschart.com/'; // URL to web site
var __urlHelp = 'http://www.ejschart.com/help/'; // URL to documentation
var __curyear = (new Date()).getFullYear(); // Current year (used in copyright)
var __about = '<span style="font-weight:bold;font-size:12px;">' + __title + '</span>' +
'<br/>' +
'Current Version: ' + __version +
'<br/> <br/>' +
'Copyright 2006 - ' + __curyear + ' by' +
'<br/>' +
'<a href="http://www.emprisecorporation.com/" onfocus="this.blur();" target="_blank">Emprise Corporation</a>';
// --------------------------------------------------------------------------
// Global Constants
// --------------------------------------------------------------------------
// These variables store all of the values that are constant between charts
// including storing values in easy-to-remember variable names.
// --------------------------------------------------------------------------
var _x = 0; // Constant used when coverting px-pt or pt-px
var _y = 1; // Constant used when coverting px-pt or pt-px
var __default_canvas_height = 300; // Default height of the CANVAS element
var __default_canvas_width = 400; // Default width of the CANVAS element
var __DefaultColors = [
'rgb(120,90,59)' ,
'rgb(53,115,53)' ,
'rgb(178,87,56)' ,
'rgb(203,143,71)' ,
'rgb(55,106,155)' ,
'rgb(205,197,51)' ,
'rgb(209,130,139)' ,
'rgb(159,153,57)' ,
'rgb(206,173,136)' ,
'rgb(191,132,72)' ,
'rgb(151,135,169)' ,
'rgb(140,48,51)' ,
'rgb(59,144,187)' ,
'rgb(197,190,104)' ,
'rgb(109,136,79)' ,
'rgb(144,100,144)' ,
'rgb(181,94,94)' ,
'rgb(59,144,144)' ,
'rgb(204,136,92)' ,
'rgb(139,167,55)' ,
'rgb(205,171,66)' ,
'rgb(150,184,211)'
];
// Cache math functions and variables
var m_SQRT = Math.sqrt,
m_POW = Math.pow,
m_SIN = Math.sin,
m_COS = Math.cos,
m_TAN = Math.tan,
m_ATAN = Math.atan,
m_ROUND = Math.round,
m_FLOOR = Math.floor,
m_CEIL = Math.ceil,
m_ABS = Math.abs,
m_LOG = Math.log,
m_EXP = Math.exp,
m_PI = Math.PI,
m_PIx2 = m_PI * 2,
m_PId2 = m_PI / 2;
// --------------------------------------------------------------------------
// NAMESPACE: EJSC
// --------------------------------------------------------------------------
// Declare chart namespace to avoid conflicts with any other JavaScript
// packages.
// --------------------------------------------------------------------------
(EJSC = {
/* JGD - 2011-03-02 - Added */
__ready: false,
// V2 - STRINGS object is used to hold all static strings in order to allow for easier localization
STRINGS: {
building_message: "Building Chart...",
max_zoom_message: "Max Zoom Reached",
drawing_message: "Drawing...",
chart_legend_title: "Chart Legend",
y_axis_caption: "Y Axis",
x_axis_caption: "X Axis"
},
// Used to store chart source path
__srcPath: undefined,
// --------------------------------------------------------------------------
// Axis Arrays
// --------------------------------------------------------------------------
// These arrays hold all of the values needed to draw the axis data and
// the grid on the chart. The values decide how to split up the "tick marks"
// and how to round the shown values.
// --------------------------------------------------------------------------
__ticks: new Array( 29030400000, 7257600000, 2419200000, 604800000, 259200000, 86400000, 21600000, 14400000, 3600000, 1000000, 500000, 250000, 100000, 50000, 25000, 10000, 5000, 2500, 1000, 500, 250, 100, 50, 25, 10, 5, 2.5, 1, .5, .25, .1, .05, .025, .01, .005, .0025, .001, .0005, .00025, .0001, .00005, .000025, .00001, .000005, .0000025, .000001, .0000005, .00000025, .0000001, .00000005, .000000025, .00000001, .000000005, .0000000025, .000000001 ),
__subticks: new Array( 7257600000, 2419200000, 604800000, 86400000, 86400000, 21600000, 3600000, 3600000, 600000, 250000, 100000, 50000, 25000, 10000, 5000, 2500, 1000, 500, 250, 100, 50, 25, 10, 5, 2, 1, .5, .25, .1, .05, .025, .01, .005, .0025, .001, .0005, .00025, .0001, .00005, .000025, .00001, .000005, .0000025, .000001, .0000005, .00000025, .0000001, .00000005, .000000025, .00000001, .000000005, .0000000025, .000000001, .0000000005, .00000000025 ),
__tickRound: new Array( undefined, undefined, undefined, undefined, undefined, undefined, undefined, undefined, undefined, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 2, 1, 2, 3, 2, 3, 4, 3, 4, 5, 4, 5, 6, 5, 6, 7, 6, 7, 8, 7, 8, 9, 8, 9, 10, 9, 10, 11 ),
// --------------------------------------------------------------------------
// Formatting Arrays
// --------------------------------------------------------------------------
// These arrays hold all of the values needed to format values that are
// displayed on the axis and in the hints.
// --------------------------------------------------------------------------
__months: new Array( 'January' , 'February' , 'March' , 'April' , 'May' , 'June' , 'July' , 'August' , 'September' , 'October' , 'November' , 'December' ),
__days: new Array( 'Sunday' , 'Monday' , 'Tuesday' , 'Wednesday' , 'Thursday' , 'Friday' , 'Saturday' ),
// --------------------------------------------------------------------------
// Event Array
// --------------------------------------------------------------------------
// This array holds all of the attached events that are added to DOM
// elements in order to be removed on page unload.
// --------------------------------------------------------------------------
__events: [], // Saves all attached events for removal
// Reference to page header for inserting styles and scripts
__headTag: document.getElementsByTagName("head")[0],
// Reference to html tag, used for positioning
__htmlTag: document.getElementsByTagName("html")[0],
// JHM: 2008-09-24 - Save reference to link tag in order to properly free when page is unloaded
// Reference to link tag, used for loading style sheet
__linkTag: null,
__isIE: !window.CanvasRenderingContext2D,
DefaultImagePath: 'images/',
// --------------------------------------------------------------------------
// Default Color Arrays
// --------------------------------------------------------------------------
// This array is used in each chart to specify available series colors. Add
// to this array in order to affect all chart created after modification or
// modify the AvailableColors property of the chart object after it's been
// created to specify colors specific to an instance of a chart
// --------------------------------------------------------------------------
DefaultColors: __DefaultColors.slice(),
DefaultPieColors: __DefaultColors.slice(),
DefaultBarColors: __DefaultColors.slice(),
// --------------------------------------------------------------------------
// Container Arrays
// --------------------------------------------------------------------------
// These arrays hold all of the objects that the ESJC object creates.
// --------------------------------------------------------------------------
__Charts: [], // Holds all charts that have been created
__ResizeTimeouts: [], // Holds all resize timeouts that have been created
__ResizeCharts: [], // Holds all charts to be resized automatically
// JHM: Added storage for resize interval
__ResizeInterval: undefined, // Holds the window resize interval reference
// --------------------------------------------------------------------------
// Unique Series Identifier
// --------------------------------------------------------------------------
// This holds the unique index that is incremented for every series that is
// created, and stored as that series' index.
// --------------------------------------------------------------------------
__CurrentUniqueSeriesIndex: 0, // Unique Series Index
// --------------------------------------------------------------------------
// FUNCTION: __init
// --------------------------------------------------------------------------
// Top level initialization function that is called after the entire EJSC
// object has been defined. Attaches unload event to window to detach all
// events.
// --------------------------------------------------------------------------
// => This function is called when the EJSC namespace has been defined.
// --------------------------------------------------------------------------
__init: function() {
// Register window events for cleanup
// interval in order to monitor the chart container size and resize as necessary
EJSC.utility.__attachEvent(window, "load", EJSC.__doLoad);
EJSC.utility.__attachEvent(window, "unload", EJSC.__doUnload);
// Create base classes
EJSC.Inheritable.__extendTo(EJSC.__Series);
this.Series = EJSC.__Series;
EJSC.Inheritable.__extendTo(EJSC.__Point);
this.Point = EJSC.__Point;
EJSC.Inheritable.__extendTo(EJSC.__DataHandler);
this.DataHandler = EJSC.__DataHandler;
this.Formatter = new EJSC.__Formatter();
EJSC.Inheritable.__extendTo(EJSC.__Axis);
this.Axis = EJSC.__Axis;
// Check for META tag options
var i;
var metaTags = EJSC.__headTag.getElementsByTagName("meta");
EJSC.loadCompatibilityFile = false;
try {
for (i = 0; i < metaTags.length; i++) {
if (metaTags[i].name == "ejsc-src-path") {
EJSC.__srcPath = metaTags[i].content;
} else if (metaTags[i].name == "ejsc-auto-load-support-files") {
if (metaTags[i].content.match(/false/i) != null) {
return;
}
} else if (metaTags[i].name == "ejsc-v1-compatibility") {
if (metaTags[i].content.match(/true/i) != null) {
EJSC.loadCompatibilityFile = true;
}
}
}
} catch (e) {
} finally {
delete metaTags;
metaTags = null;
}
// JHM: 2007-04-15 - Added to insert scripts/styles as necessary in order to reduce the
// coding requirements of end users and ensure styles exist before chart html is added
// to the page
// Extract chart source path from script tag
// This will only function properly if the javascript file is named EJSChart.js
// or EJSChart_*.js where * is some additional string
if (EJSC.__srcPath == undefined) {
var scriptTags = EJSC.__headTag.getElementsByTagName("script");
// JHM: 2007-06-01 - Updated document.getElementsByTagName to __headTag.getElementsByTagName
// JHM: 2008-08-08 - Updated regexp to ignore directories named ejschart_
for (i = 0; i < scriptTags.length; i++) {
if (scriptTags[i].src && scriptTags[i].src.match(/EJSChart(\_[^\/\\]*)?\.js(\?.*)?$/i)) {
// JHM: 2007-09-11 - Updated to use EJSC.__srcPath
EJSC.__srcPath = scriptTags[i].src.replace(/EJSChart(\_[^\/\\]*)?\.js(\?.*)?$/i, "");
break;
}
}
delete scriptTags;
scriptTags = null;
}
// Update default image path
// JHM: 2007-09-11 - Updated to use EJSC.__srcPath
EJSC.DefaultImagePath = EJSC.__srcPath + EJSC.DefaultImagePath;
// Internet Explorer needs special handling of style insert
// and additional scripts and styles
if (EJSC.__isIE) {
var req = EJSC.utility.XMLRequestPool.sendRequest(EJSC.__srcPath + "excanvas.js");
// Update namespace and css to support IE8RC1
req = req.responseText.replace('urn:schemas-microsoft-com:vml");','urn:schemas-microsoft-com:vml","#default#VML");');
req = req.replace('"g_vml_\\:*{behavior:url(#default#VML)}";', '"g_vml_\\:*{behavior:url(#default#VML)} g_vml_\\:shape {display: inline-block;}";');
eval(req);
fixUpExCanvas();
}
// JHM: 2008-09-24 - Save reference to link tag so it can be properly freed on page unload
// Insert style tag into header
EJSC.__linkTag = document.createElement("link");
EJSC.__linkTag.rel = "stylesheet";
EJSC.__linkTag.type = "text/css";
EJSC.__linkTag.href = EJSC.__srcPath + "EJSChart.css";
EJSC.__linkTag.media = "screen,print";
EJSC.__headTag.appendChild(EJSC.__linkTag);
if (EJSC.__isIE) {
// precompute "00" to "FF"
var dec2hex = [];
for (var i = 0; i < 16; i++) {
for (var j = 0; j < 16; j++) {
dec2hex[i * 16 + j] = i.toString(16) + j.toString(16);
}
};
function processLineCap(lineCap) {
switch (lineCap) {
case "butt": return "flat";
case "round": return "round";
case "square":
default:
return "square";
}
};
function processStyle(styleString) {
var str, alpha = 1;
styleString = String(styleString);
if (styleString.substring(0, 3) == "rgb") {
var start = styleString.indexOf("(", 3);
var end = styleString.indexOf(")", start + 1);
var guts = styleString.substring(start + 1, end).split(",");
str = "#";
for (var i = 0; i < 3; i++) {
str += dec2hex[parseInt(guts[i])];
}
if ((guts.length == 4) && (styleString.substr(3, 1) == "a")) {
alpha = guts[3];
}
} else {
str = styleString;
}
return [str, alpha];
};
contextPrototype = window.CanvasRenderingContext2D.prototype;
contextPrototype.stroke = function(aFill) {
// JHM
if (this.updating == undefined || this.updating == false) {
var lineStr = [];
} else {
if (this.lineStr == undefined) { this.lineStr = []; }
var lineStr = this.lineStr;
}
var lineOpen = false;
var a = processStyle(aFill ? this.fillStyle : this.strokeStyle);
var color = a[0];
var opacity = a[1] * this.globalAlpha;
lineStr.push('<g_vml_:shape',
' fillcolor="', color, '"',
' filled="', Boolean(aFill), '"',
' style="position:absolute;width:10px;height:10px;"',
' coordorigin="0 0" coordsize="100 100"',
' stroked="', !aFill, '"',
' strokeweight="', this.lineWidth, '"',
' strokecolor="', color, '"',
' id="' , this.id, '"',
' path="'
);
var newSeq = false;
var min = {x: null, y: null};
var max = {x: null, y: null};
for (var i = 0; i < this.currentPath_.length; i++) {
var p = this.currentPath_[i];
if (p.type == "moveTo") {
lineStr.push(" m ");
var c = this.getCoords_(p.x, p.y);
lineStr.push(m_ROUND(c.x), ",", m_ROUND(c.y));
} else if (p.type == "lineTo") {
lineStr.push(" l ");
var c = this.getCoords_(p.x, p.y);
lineStr.push(m_ROUND(c.x), ",", m_ROUND(c.y));
} else if (p.type == "close") {
lineStr.push(" x ");
} else if (p.type == "bezierCurveTo") {
lineStr.push(" c ");
var c = this.getCoords_(p.x, p.y);
var c1 = this.getCoords_(p.cp1x, p.cp1y);
var c2 = this.getCoords_(p.cp2x, p.cp2y);
lineStr.push(m_ROUND(c1.x), ",", m_ROUND(c1.y), ",",
m_ROUND(c2.x), ",", m_ROUND(c2.y), ",",
m_ROUND(c.x), ",", m_ROUND(c.y));
} else if (p.type == "at" || p.type == "wa") {
lineStr.push(" ", p.type, " ");
var c = this.getCoords_(p.x, p.y);
var cStart = this.getCoords_(p.xStart, p.yStart);
var cEnd = this.getCoords_(p.xEnd, p.yEnd);
lineStr.push(m_ROUND(c.x - this.arcScaleX_ * p.radius), ",",
m_ROUND(c.y - this.arcScaleY_ * p.radius), " ",
m_ROUND(c.x + this.arcScaleX_ * p.radius), ",",
m_ROUND(c.y + this.arcScaleY_ * p.radius), " ",
m_ROUND(cStart.x), ",", m_ROUND(cStart.y), " ",
m_ROUND(cEnd.x), ",", m_ROUND(cEnd.y));
}
// TODO: Following is broken for curves due to
// move to proper paths.
// Figure out dimensions so we can do gradient fills
// properly
if(c) {
if (min.x == null || c.x < min.x) {
min.x = c.x;
}
if (max.x == null || c.x > max.x) {
max.x = c.x;
}
if (min.y == null || c.y < min.y) {
min.y = c.y;
}
if (max.y == null || c.y > max.y) {
max.y = c.y;
}
}
}
lineStr.push(' ">');
if (typeof this.fillStyle == "object") {
var focus = {x: "50%", y: "50%"};
var width = (max.x - min.x);
var height = (max.y - min.y);
var dimension = (width > height) ? width : height;
focus.x = m_ROUND((this.fillStyle.focus_.x / width) * 100 + 50) + "%";
focus.y = m_ROUND((this.fillStyle.focus_.y / height) * 100 + 50) + "%";
var colors = [];
// inside radius (%)
if (this.fillStyle.type_ == "gradientradial") {
var inside = (this.fillStyle.radius1_ / dimension * 100);
// percentage that outside radius exceeds inside radius
var expansion = (this.fillStyle.radius2_ / dimension * 100) - inside;
} else {
var inside = 0;
var expansion = 100;
}
var insidecolor = {offset: null, color: null};
var outsidecolor = {offset: null, color: null};
// We need to sort 'colors' by percentage, from 0 > 100 otherwise ie
// won't interpret it correctly
this.fillStyle.colors_.sort(function (cs1, cs2) {
return cs1.offset - cs2.offset;
});
for (var i = 0; i < this.fillStyle.colors_.length; i++) {
var fs = this.fillStyle.colors_[i];
colors.push( (fs.offset * expansion) + inside, "% ", fs.color, ",");
if (fs.offset > insidecolor.offset || insidecolor.offset == null) {
insidecolor.offset = fs.offset;
insidecolor.color = fs.color;
}
if (fs.offset < outsidecolor.offset || outsidecolor.offset == null) {
outsidecolor.offset = fs.offset;
outsidecolor.color = fs.color;
}
}
colors.pop();
lineStr.push('<g_vml_:fill',
' color="', outsidecolor.color, '"',
' color2="', insidecolor.color, '"',
' type="', this.fillStyle.type_, '"',
' focusposition="', focus.x, ', ', focus.y, '"',
' id="' , this.id, '"',
' colors="', colors.join(""), '"',
' opacity="', opacity, '" />');
} else if (aFill) {
lineStr.push('<g_vml_:fill color="', color, '" opacity="', opacity, '" />');
} else {
lineStr.push('<g_vml_:stroke',
' opacity="', opacity,'"',
' joinstyle="', this.lineJoin, '"',
' miterlimit="', this.miterLimit, '"',
' endcap="', processLineCap(this.lineCap) ,'"',
' weight="', this.lineWidth, 'px"',
' id="' , this.id, '"',
' dashstyle="', this.dashStyle, '"',
' color="', color,'" />'
);
}
lineStr.push("</g_vml_:shape>");
// JHM
if (this.updating == undefined || this.updating == false) {
this.element_.insertAdjacentHTML("beforeEnd", lineStr.join(""));
}
this.lineStr = lineStr;
this.currentPath_ = [];
};
// JHM
contextPrototype.render = function() {
if (EJSC.__ieVersion >= 5.8) {
this.element_.insertAdjacentHTML("beforeEnd", this.lineStr.join(""));
} else {
var frag = document.createDocumentFragment();
var el = document.createElement("DIV");
el.innerHTML = this.lineStr.join("");
frag.appendChild(el);
this.element_.appendChild(frag.cloneNode(true));
}
};
contextPrototype.beginUpdate = function() {
this.updating = true;
};
contextPrototype.endUpdate = function() {
this.updating = false;
this.render();
};
} else {
if (window.CanvasRenderingContext2D) {
window.CanvasRenderingContext2D.prototype.beginUpdate = function() { };
window.CanvasRenderingContext2D.prototype.endUpdate = function() { };
}
}
},
// --------------------------------------------------------------------------
// FUNCTION: __doLoad
// --------------------------------------------------------------------------
// Attaches all document-level events to the document.
// --------------------------------------------------------------------------
// => This function is called when the document is finished loading.
// --------------------------------------------------------------------------
__doLoad: function() {
// JHM: 2007-06-11 - Modified to attach events instead of assigning to global event
var ae = EJSC.utility.__attachEvent;
ae(document, 'mouseup', doAllMouseUp);
ae(document, 'mousemove', doAllMouseMove);
// JHM: 2007-07-29 - Added to force safari to calculate element widths
var safLoadBug = document.body.offsetWidth;
EJSC.__doResize();
},
// --------------------------------------------------------------------------
// FUNCTION: __doUnload
// --------------------------------------------------------------------------
// Detaches all events from page to reduce memory leaks.
// --------------------------------------------------------------------------
// => This function is called when the document is closed or unloaded.
// --------------------------------------------------------------------------
__doUnload: function() {
// JHM: 2007-09-03 - Clear reference to head tag (leak fix)
EJSC.__headTag = undefined;
EJSC.__htmlTag = undefined;
// JHM: Remove resize interval
if (EJSC.__ResizeInterval != undefined) {
window.clearInterval(EJSC.__ResizeInterval);
EJSC.__ResizeInterval = undefined;
}
var e, i, j, r;
// Detach all events
// JHM: 2007-09-11 - Modified references from __events to EJSC.__events
while( EJSC.__events.length > 0 ) {
e = EJSC.__events.pop();
// JHM: 2007-09-03 - Added check to ensure event is valid, event array entry is set to null
// if delete chart method is called
if (e != null) {
EJSC.utility.__detachEvent( e[0] , e[1] , e[2] , e[3] );
}
delete e;
}
// Remove JavaScript <-> DOM references
for ( i = 0 ; i < EJSC.__Charts.length ; i++ ) {
EJSC.__deleteChart(i, true, false);
}
// Remove all XML pending requests
try {
while (EJSC.utility.XMLRequestPool.__requestPool.length > 0) {
r = EJSC.utility.XMLRequestPool.__requestPool.pop();
// JHM: 2008-09-25 - Updated request cleanup to correct memory leak in IE
r.onreadystatechange = function() { };
delete r;
r = null;
}
EJSC.utility.XMLRequestPool.__requestPool = null;
} catch (e) {
}
// Remove all XML active requests
try {
while (EJSC.utility.XMLRequestPool.__activePool.length > 0) {
r = EJSC.utility.XMLRequestPool.__activePool.pop();
// JHM: 2008-09-25 - Updated request cleanup to correct memory leak in IE
r.onreadystatechange = function() { };
delete r;
r = null;
}
EJSC.utility.XMLRequestPool.__activePool = null;
EJSC.utility.XMLRequestPool = null;
} catch (e) {
}
EJSC = null;
// Force IE garbage collection
if (typeof window.CollectGarbage != "undefined") {
window.CollectGarbage();
}
},
// JHM: 2007-09-25 - Added __deleteChart method to cleanup after single chart deletion
__deleteChart: function(index, clearEl, detachEvents) {
if (EJSC.__Charts[index] == null) { return; }
try {
var chart = EJSC.__Charts[index];
EJSC.__Charts[index] = null;
// JHM: 2008-09-24 - Remove chart specific events (fixes memory leak in IE)
EJSC.__removeChartResize(chart);
if (chart.__message_timeout != undefined) {
window.clearTimeout(chart.__message_timeout);
chart.__message_timeout = undefined;
}
chart.__el.__chart = null;
// JHM: 2008-09-24 - Added to correct memory leak when removing charts without a page refresh (all browsers!)
// Remove chart events if necessary
if (detachEvents == undefined || detachEvents == true) {
var e, i;
for (i = 0; i < EJSC.__events.length; i++) {
e = EJSC.__events[i];
if (e != null) {
if (e[4] == chart) {
EJSC.utility.__detachEvent( e[0] , e[1] , e[2] , e[3] );
delete e;
EJSC.__events[i] = null;
}
}
}
}
// Cleanup the axes
chart.axis_left.__free();
chart.axis_bottom.__free();
chart.axis_right.__free();
chart.axis_top.__free();
// Cleanup the series
for (var j = 0; j < chart.__series.length; j++) {
if (chart.__series[j].__free) {
chart.__series[j].__free();
}
}
chart.__series = [];
// Fix excanvas leaks
chart.__el_axes_canvas.getContext = null;
chart.__el_series_canvas.getContext = null;
chart.__el_hint_canvas.getContext = null;
if (chart.__el_axes_canvas.context_) {
chart.__el_axes_canvas.context_.element_ = null;
chart.__el_axes_canvas.context_ = null;
}
chart.__axes_context = null;
chart.__el_axes_canvas = null;
if (chart.__el_series_canvas.context_) {
chart.__el_series_canvas.context_.element_ = null;
chart.__el_series_canvas.context_ = null;
}
chart.__series_context = null;
chart.__el_series_canvas = null;
if (chart.__el_hint_canvas.context_) {
chart.__el_hint_canvas.context_.element_ = null;
chart.__el_hint_canvas.context_ = null;
}
chart.__hint_context = null;
chart.__el_hint_canvas = null;
chart.__el_container = null;
chart.__el_chart_container = null;
chart.__el_axes_canvas_container = null;
chart.__el_series_canvas_container = null;
chart.__el_series_canvas_div = null;
chart.__el_titlebar = null;
chart.__el_mouse_position = null;
chart.__el_titlebar_text = null;
chart.__el_labels = null;
chart.__el_hint_labels = null;
chart.__el_zoombox = null;
chart.__el_message = null;
chart.__el_key_grabber = null;
chart.__el_canvas_cover = null;
chart.__el_legend = null;
chart.__el_legend_title = null;
chart.__el_legend_series.innerHTML = "";
chart.__el_legend_series = null;
chart.__el_legend_owner = null;
chart.__el_legend_owner_title = null;
chart.__el_legend_minimize = null;
chart.__el_legend_maximize = null;
chart.__el_hint = null;
chart.__el_hint_text = null;
chart.__el_hint_pointer = null;
if (clearEl === true) {
chart.__el.innerHTML = "";
}
chart.__el = null;
delete chart;
chart = null;
} catch (e) {
}
},
// --------------------------------------------------------------------------
// FUNCTION: __doResize
// --------------------------------------------------------------------------
// Calls for all charts on the page to resize and redraw themselves.
// --------------------------------------------------------------------------
// => This function is called when the window is resized.
// --------------------------------------------------------------------------
__doResize: function() {
if (EJSC.__ResizeInterval == undefined) { return false; }
var i;
for (i = 0; i < EJSC.__ResizeTimeouts.length; i++) {
try { window.clearTimeout(EJSC.__ResizeTimeouts[i]); } catch (e) {}
}
EJSC.__ResizeTimeouts = [];
for (i = 0; i < EJSC.__ResizeCharts.length; i++) {
// JHM: 2007-09-03 - Added check to ensure chart reference is valid
if (EJSC.__ResizeCharts[i] != null) {
EJSC.__ResizeTimeouts[i] = window.setTimeout("EJSC.__doResizeTimeout(" + i + ")",1);
}
}
},
__doResizeTimeout: function(index) {
/* JGD - 2011-03-02 - Added */
if( EJSC.__ready == false && document.documentMode == 8 ) return;
if (EJSC.__ResizeCharts[index] != null) {
EJSC.__ResizeCharts[index].__resize(true, false, true);
}
},
__addChartResize: function(chart) {
// Make sure its not already in the array
for (var i = 0; i < EJSC.__ResizeCharts.length; i++) {
if (EJSC.__ResizeCharts[i] == chart) { return; }
}
EJSC.__ResizeCharts.push(chart);
// Start up resize timeout if not already running
if (EJSC.__ResizeInterval == undefined) {
// JHM: Added storage of the interval reference so it can be removed
EJSC.__ResizeInterval = window.setInterval(function() { EJSC.__doResize(); }, 500);
}
},
__removeChartResize: function(chart) {
// Find the index of the chart
var i;
for (i = 0; i < EJSC.__ResizeCharts.length; i++) {
if (EJSC.__ResizeCharts[i] == chart) { break; }
}
if (i < EJSC.__ResizeCharts.length) {
EJSC.__ResizeCharts.splice(i, 1);
}
// Stop resize timeout if no more charts to resize
if (EJSC.__ResizeInterval != undefined) {
try { window.clearInterval(EJSC.__ResizeInterval); } catch (e) {}
}
},
// --------------------------------------------------------------------------
// FUNCTION: __getUniqueSeriesIndex
// --------------------------------------------------------------------------
// Finds the next unique series index and returns it to the series calling
// it. Then increments the unique index.
// --------------------------------------------------------------------------
// => This function is called whenever a series is created.
// --------------------------------------------------------------------------
__getUniqueSeriesIndex: function() {
return ++EJSC.__CurrentUniqueSeriesIndex;
},
// --------------------------------------------------------------------------
// OBJECT: utility
// --------------------------------------------------------------------------
utility: {
// JHM: 2007-05-25 - Added __stringIsNumber for validating series data text labels
// --------------------------------------------------------------------------
// FUNCTION: __stringIsNumber
// --------------------------------------------------------------------------
// Checks the input string for existance of only characters which could
// be part of a number, double checks for mismatches with isNaN
// --------------------------------------------------------------------------
__stringIsNumber: function(s) {
var result = true;
try {
if (typeof s == 'string') {
if ((s.match(/^[-.0-9Ee]+$/) != null)) {
if (isNaN(parseFloat(s))) {
result = false;
}
} else {
result = false;
}
}
} catch (e) {
result = true;
}
return result;
},
// JHM: 2007-06-12 - Added __decToHex method
__decToHex: function(n) {
var hex = "0123456789ABCDEF";
if (n < 0) { return "00"; }
else if (n > 255) { return "FF"; }
else { return hex.charAt(m_FLOOR(n / 16)) + hex.charAt(n % 16); }
},
__getColor: function(str, opacity) {
var r, g, b, o, parts;
if (str.indexOf("rgb") != -1) {
parts = str.split("(");
parts = parts[1].split(")");
parts = parts[0].split(",");
r = parts[0];
g = parts[1];
b = parts[2];
if (opacity != undefined) { o = opacity; }
else if (parts.length > 3) { o = parts[3]; }
else { o = 1; }
} else {
str = str.replace("#", "");
// JHM: 2007-01-25 - Updated to fix issues in IE
if (str.match(/\,/) != null) {
parts = str.split(",");
var color = "" + parts[0];
var op = parts[1];
} else {
var color = "" + str;
var op = 1;
}
if (opacity != undefined) { o = opacity; }
else { o = 1; }
if (color.length == 3) {
parts = color.split("");
color = parts[0] + parts[0] + parts[1] + parts[1] + parts[2] + parts[2];
} else {
while (color.length < 6) { color += "0"; }
}
parts = color.split("");
r = parseInt(parts[0] + "" + parts[1], 16);
g = parseInt(parts[2] + "" + parts[3], 16);
b = parseInt(parts[4] + "" + parts[5], 16);
}
return {
hex: "#" + EJSC.utility.__decToHex(r) + EJSC.utility.__decToHex(g) + EJSC.utility.__decToHex(b),
red: r,
green: g,
blue: b,
opacity: o,
rgba: "rgba(" + r + "," + g + "," + b + "," + o + ")",
rgb: "rgb(" + r + "," + g + "," + b + ")"
};
},
__borderSize: function(el, side) {
try {
side = side.replace(/^([lrtb])(.*)/, function(str, p1, p2) { return p1.toUpperCase() + p2; });
return el.style["border" + side + "Width"].replace(/([0-9]+)([^0-9]*)/,
function(str, p1, p2) {
if (p2 == "px") { return parseInt(p1); }
else if (p2 == "em") {
console.log("EJSChart: em border size is not currently supported.");
} else if (p2 == "%") {
console.log("EJSChart: % border size is not currently supported.");
}
return 0;
}
);
} catch (e) {
return 0;
}
},
// JHM: 2007-09-26 - Added __removeChildren method, removes all child nodes from the
// given node with DOM methods
__removeChildren: function(node) {
while (node.firstChild) { node.removeChild(node.firstChild); }
},
// --------------------------------------------------------------------------
// FUNCTION: __realXY
// --------------------------------------------------------------------------
// Determines the true position of the cursor.
// --------------------------------------------------------------------------
__realXY: function(e) {
// Variables
var xValue;
var yValue;
// Find real X value
if (e.pageX) xValue = e.pageX;
else if (e.clientX) xValue = e.clientX + ( document.documentElement.scrollLeft ? document.documentElement.scrollLeft : document.body.scrollLeft );
else xValue = null;
// Find real Y value
if (e.pageY) yValue = e.pageY;
else if (e.clientY) yValue = e.clientY + ( document.documentElement.scrollTop ? document.documentElement.scrollTop : document.body.scrollTop );
else yValue = null;
// Return coordinates
// JHM: 2007-09-03 - Updated to use html tag reference stored in EJSC
xValue += EJSC.utility.__documentOffsetLeft(EJSC.__htmlTag);
yValue += EJSC.utility.__documentOffsetTop(EJSC.__htmlTag);
// JGD: 2007-07-18
// Added checks on mouse movement to pick up on all parentNodes' scrollTop and scrollLeft
var el = ((e.srcElement)?(e.srcElement):(e.target));
while( el.parentNode != undefined ) {
/* JGD - 2011-03-07 - Fixed */
if (el.parentNode == document.body || el.parentNode == EJSC.__htmlTag) { break; }
if (el.parentNode.scrollTop != undefined) {
yValue += el.parentNode.scrollTop;
}
if (el.parentNode.scrollLeft != undefined) {
xValue += el.parentNode.scrollLeft;
}
el = el.parentNode;
}
if( EJSC.__htmlTag.clientTop ) {
xValue -= EJSC.__htmlTag.clientLeft;
yValue -= EJSC.__htmlTag.clientTop;
}
// Return coordinates
return { x: xValue, y: yValue };
},
// --------------------------------------------------------------------------
// FUNCTION: EJSC.utility.__documentOffsetTop
// --------------------------------------------------------------------------
// Determines the distance an [[element]] is from the top of the page, and
// returns that value.
// --------------------------------------------------------------------------
__documentOffsetTop: function(element, includeScroll) {
var offset = element.offsetTop;
// JHM: 2008-10-02 - Added to correct issue with legend movement in a scrollable container
if (includeScroll == true) {
var se = element;
while (se.parentNode != null) {
if (se.parentNode.scrollTop > 0) offset -= se.parentNode.scrollTop;
if (se.parentNode.pageYOffset > 0) offset -= se.parentNode.pageYOffset;
se = se.parentNode;
};
};
while (element.offsetParent != null) {
offset += element.offsetParent.offsetTop;
element = element.offsetParent;
};
// JHM: 2007-09-03 - Updated to use html tag reference stored in EJSC
offset += EJSC.__htmlTag.offsetTop;
return offset;
},