-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathjit.js
9049 lines (7224 loc) · 270 KB
/
jit.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
(function () {
/*
File: Core.js
Description:
Provides common utility functions and the Class object used internally by the library.
Also provides the <TreeUtil> object for manipulating JSON tree structures
Some of the Basic utility functions and the Class system are based in the MooTools Framework <http://mootools.net>. Copyright (c) 2006-2009 Valerio Proietti, <http://mad4milk.net/>. MIT license <http://mootools.net/license.txt>.
Author:
Nicolas Garcia Belmonte
Copyright:
Copyright 2008-2009 by Nicolas Garcia Belmonte.
Homepage:
<http://thejit.org>
Version:
1.1.3
License:
BSD License
> Redistribution and use in source and binary forms, with or without
> modification, are permitted provided that the following conditions are met:
> * Redistributions of source code must retain the above copyright
> notice, this list of conditions and the following disclaimer.
> * Redistributions in binary form must reproduce the above copyright
> notice, this list of conditions and the following disclaimer in the
> documentation and/or other materials provided with the distribution.
> * Neither the name of the organization nor the
> names of its contributors may be used to endorse or promote products
> derived from this software without specific prior written permission.
>
> THIS SOFTWARE IS PROVIDED BY Nicolas Garcia Belmonte ``AS IS'' AND ANY
> EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
> WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
> DISCLAIMED. IN NO EVENT SHALL Nicolas Garcia Belmonte BE LIABLE FOR ANY
> DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
> (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
> LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
> ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
> (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
> SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
function $empty() {};
function $extend(original, extended){
for (var key in (extended || {})) original[key] = extended[key];
return original;
};
function $lambda(value){
return (typeof value == 'function') ? value : function(){
return value;
};
};
var $time = Date.now || function(){
return +new Date;
};
function $splat(obj){
var type = $type(obj);
return (type) ? ((type != 'array') ? [obj] : obj) : [];
};
var $type = function(elem) {
return $type.s.call(elem).match(/^\[object\s(.*)\]$/)[1].toLowerCase();
};
$type.s = Object.prototype.toString;
function $each(iterable, fn){
var type = $type(iterable);
if(type == 'object') {
for (var key in iterable) fn(iterable[key], key);
} else {
for(var i=0; i < iterable.length; i++) fn(iterable[i], i);
}
};
function $merge(){
var mix = {};
for (var i = 0, l = arguments.length; i < l; i++){
var object = arguments[i];
if ($type(object) != 'object') continue;
for (var key in object){
var op = object[key], mp = mix[key];
mix[key] = (mp && $type(op) == 'object' && $type(mp) == 'object') ? $merge(mp, op) : $unlink(op);
}
}
return mix;
};
function $unlink(object){
var unlinked;
switch ($type(object)){
case 'object':
unlinked = {};
for (var p in object) unlinked[p] = $unlink(object[p]);
break;
case 'array':
unlinked = [];
for (var i = 0, l = object.length; i < l; i++) unlinked[i] = $unlink(object[i]);
break;
default: return object;
}
return unlinked;
};
function $rgbToHex(srcArray, array){
if (srcArray.length < 3) return null;
if (srcArray.length == 4 && srcArray[3] == 0 && !array) return 'transparent';
var hex = [];
for (var i = 0; i < 3; i++){
var bit = (srcArray[i] - 0).toString(16);
hex.push((bit.length == 1) ? '0' + bit : bit);
}
return (array) ? hex : '#' + hex.join('');
};
function $destroy(elem) {
$clean(elem);
if(elem.parentNode) elem.parentNode.removeChild(elem);
if(elem.clearAttributes) elem.clearAttributes();
};
function $clean(elem) {
for(var ch = elem.childNodes, i=0; i < ch.length; i++) {
$destroy(ch[i]);
}
};
function $addEvent(obj, type, fn) {
if (obj.addEventListener)
obj.addEventListener(type, fn, false);
else
obj.attachEvent('on' + type, fn);
};
function $hasClass(obj, klass) {
return (' ' + obj.className + ' ').indexOf(' ' + klass + ' ') > -1;
};
function $addClass(obj, klass) {
if(!$hasClass(obj, klass)) obj.className = (obj.className + " " + klass);
};
function $removeClass(obj, klass) {
obj.className = obj.className.replace(new RegExp('(^|\\s)' + klass + '(?:\\s|$)'), '$1');
};
function $get(id) {
return document.getElementById(id);
};
var Class = function(properties){
properties = properties || {};
var klass = function(){
// not defining any attributes in Class properties.
// for (var key in this){
// if (typeof this[key] != 'function') this[key] = $unlink(this[key]);
// }
this.constructor = klass;
if (Class.prototyping) return this;
var instance = (this.initialize) ? this.initialize.apply(this, arguments) : this;
return instance;
};
for (var mutator in Class.Mutators){
if (!properties[mutator]) continue;
properties = Class.Mutators[mutator](properties, properties[mutator]);
delete properties[mutator];
}
$extend(klass, this);
klass.constructor = Class;
klass.prototype = properties;
return klass;
};
Class.Mutators = {
Extends: function(self, klass){
Class.prototyping = klass.prototype;
var subclass = new klass;
delete subclass.parent;
subclass = Class.inherit(subclass, self);
delete Class.prototyping;
return subclass;
},
Implements: function(self, klasses){
$each($splat(klasses), function(klass){
Class.prototying = klass;
$extend(self, ($type(klass) == 'function') ? new klass : klass);
delete Class.prototyping;
});
return self;
}
};
$extend(Class, {
inherit: function(object, properties){
var caller = arguments.callee.caller;
for (var key in properties){
var override = properties[key];
var previous = object[key];
var type = $type(override);
if (previous && type == 'function'){
if (override != previous){
if (caller){
override.__parent = previous;
object[key] = override;
} else {
Class.override(object, key, override);
}
}
} else if(type == 'object'){
object[key] = $merge(previous, override);
} else {
object[key] = override;
}
}
if (caller) object.parent = function(){
return arguments.callee.caller.__parent.apply(this, arguments);
};
return object;
},
override: function(object, name, method){
var parent = Class.prototyping;
if (parent && object[name] != parent[name]) parent = null;
var override = function(){
var previous = this.parent;
this.parent = parent ? parent[name] : object[name];
var value = method.apply(this, arguments);
this.parent = previous;
return value;
};
object[name] = override;
}
});
Class.prototype.implement = function(){
var proto = this.prototype;
$each(Array.prototype.slice.call(arguments || []), function(properties){
Class.inherit(proto, properties);
});
return this;
};
/*
Object: TreeUtil
Some common JSON tree manipulation methods.
*/
this.TreeUtil = {
/*
Method: prune
Clears all tree nodes having depth greater than maxLevel.
Parameters:
tree - A JSON tree object. For more information please see <Loader.loadJSON>.
maxLevel - An integer specifying the maximum level allowed for this tree. All nodes having depth greater than max level will be deleted.
*/
prune: function(tree, maxLevel) {
this.each(tree, function(elem, i) {
if(i == maxLevel && elem.children) {
delete elem.children;
elem.children = [];
}
});
},
/*
Method: getParent
Returns the parent node of the node having _id_ as id.
Parameters:
tree - A JSON tree object. See also <Loader.loadJSON>.
id - The _id_ of the child node whose parent will be returned.
Returns:
A tree JSON node if any, or false otherwise.
*/
getParent: function(tree, id) {
if(tree.id == id) return false;
var ch = tree.children;
if(ch && ch.length > 0) {
for(var i=0; i<ch.length; i++) {
if(ch[i].id == id)
return tree;
else {
var ans = this.getParent(ch[i], id);
if(ans) return ans;
}
}
}
return false;
},
/*
Method: getSubtree
Returns the subtree that matches the given id.
Parameters:
tree - A JSON tree object. See also <Loader.loadJSON>.
id - A node *unique* identifier.
Returns:
A subtree having a root node matching the given id. Returns null if no subtree matching the id is found.
*/
getSubtree: function(tree, id) {
if(tree.id == id) return tree;
for(var i=0, ch=tree.children; i<ch.length; i++) {
var t = this.getSubtree(ch[i], id);
if(t != null) return t;
}
return null;
},
/*
Method: getLeaves
Returns the leaves of the tree.
Parameters:
node - A JSON tree node. See also <Loader.loadJSON>.
maxLevel - _optional_ A subtree's max level.
Returns:
An array having objects with two properties.
- The _node_ property contains the leaf node.
- The _level_ property specifies the depth of the node.
*/
getLeaves: function (node, maxLevel) {
var leaves = [], levelsToShow = maxLevel || Number.MAX_VALUE;
this.each(node, function(elem, i) {
if(i < levelsToShow &&
(!elem.children || elem.children.length == 0 )) {
leaves.push({
'node':elem,
'level':levelsToShow - i
});
}
});
return leaves;
},
/*
Method: eachLevel
Iterates on tree nodes with relative depth less or equal than a specified level.
Parameters:
tree - A JSON tree or subtree. See also <Loader.loadJSON>.
initLevel - An integer specifying the initial relative level. Usually zero.
toLevel - An integer specifying a top level. This method will iterate only through nodes with depth less than or equal this number.
action - A function that receives a node and an integer specifying the actual level of the node.
Example:
(start code js)
TreeUtil.eachLevel(tree, 0, 3, function(node, depth) {
alert(node.name + ' ' + depth);
});
(end code)
*/
eachLevel: function(tree, initLevel, toLevel, action) {
if(initLevel <= toLevel) {
action(tree, initLevel);
for(var i=0, ch = tree.children; i<ch.length; i++) {
this.eachLevel(ch[i], initLevel +1, toLevel, action);
}
}
},
/*
Method: each
A tree iterator.
Parameters:
tree - A JSON tree or subtree. See also <Loader.loadJSON>.
action - A function that receives a node.
Example:
(start code js)
TreeUtil.each(tree, function(node) {
alert(node.name);
});
(end code)
*/
each: function(tree, action) {
this.eachLevel(tree, 0, Number.MAX_VALUE, action);
},
/*
Method: loadSubtrees
Appends subtrees to leaves by requesting new subtrees
with the _request_ method.
Parameters:
tree - A JSON tree node. <Loader.loadJSON>.
controller - An object that implements a request method.
Example:
(start code js)
TreeUtil.loadSubtrees(leafNode, {
request: function(nodeId, level, onComplete) {
//Pseudo-code to make an ajax request for a new subtree
// that has as root id _nodeId_ and depth _level_ ...
Ajax.request({
'url': 'http://subtreerequesturl/',
onSuccess: function(json) {
onComplete.onComplete(nodeId, json);
}
});
}
});
(end code)
*/
loadSubtrees: function(tree, controller) {
var maxLevel = controller.request && controller.levelsToShow;
var leaves = this.getLeaves(tree, maxLevel),
len = leaves.length,
selectedNode = {};
if(len == 0) controller.onComplete();
for(var i=0, counter=0; i<len; i++) {
var leaf = leaves[i], id = leaf.node.id;
selectedNode[id] = leaf.node;
controller.request(id, leaf.level, {
onComplete: function(nodeId, tree) {
var ch = tree.children;
selectedNode[nodeId].children = ch;
if(++counter == len) {
controller.onComplete();
}
}
});
}
}
};
/*
* File: Canvas.js
*
* A cross browser Canvas widget.
*
* Used By:
*
* <ST>, <Hypertree>, <RGraph>
*/
/*
Class: Canvas
A multi-purpose Canvas Class. This Class can be used with the ExCanvas library to provide
cross browser Canvas based visualizations.
Parameters:
id - The canvas id. This id will be used as prefix for the canvas widget DOM elements ids.
options - An object containing multiple options such as
- _injectInto_ This property is _required_ and it specifies the id of the DOM element
to which the Canvas widget will be appended
- _width_ The width of the Canvas widget. Default's to 200px
- _height_ The height of the Canvas widget. Default's to 200px
- _backgroundColor_ Used for compatibility with IE. The canvas' background color.
Default's to '#333'
- _styles_ A hash containing canvas specific style properties such as _fillStyle_ and _strokeStyle_ among others.
Example:
Suppose we have this HTML
(start code xml)
<div id="infovis"></div>
(end code)
Now we create a new Canvas instance
(start code js)
//Create a new canvas instance
var canvas = new Canvas('mycanvas', {
//Where to inject the canvas. Any div container will do.
'injectInto':'infovis',
//width and height for canvas. Default's to 200.
'width': 900,
'height':500,
//Canvas styles
'styles': {
'fillStyle': '#ccddee',
'strokeStyle': '#772277'
}
});
(end code)
The generated HTML will look like this
(start code xml)
<div id="infovis">
<div id="mycanvas" style="position:relative;">
<canvas id="mycanvas-canvas" width=900 height=500
style="position:absolute; top:0; left:0; width:900px; height:500px;" />
<div id="mycanvas-label"
style="overflow:visible; position:absolute; top:0; left:0; width:900px; height:0px">
</div>
</div>
</div>
(end code)
As you can see, the generated HTML consists of a canvas DOM element of id _mycanvas-canvas_ and a div label container
of id _mycanvas-label_, wrapped in a main div container of id _mycanvas_.
You can also add a background canvas, for making background drawings.
This is how the <RGraph> background concentric circles are drawn
Example:
(start code js)
//Create a new canvas instance.
var canvas = new Canvas('mycanvas', {
//Where to inject the canvas. Any div container will do.
'injectInto':'infovis',
//width and height for canvas. Default's to 200.
'width': 900,
'height':500,
//Canvas styles
'styles': {
'fillStyle': '#ccddee',
'strokeStyle': '#772277'
},
//Add a background canvas for plotting
//concentric circles.
'backgroundCanvas': {
//Add Canvas styles for the bck canvas.
'styles': {
'fillStyle': '#444',
'strokeStyle': '#444'
},
//Add the initialization and plotting functions.
'impl': {
'init': function() {},
'plot': function(canvas, ctx) {
var times = 6, d = 100;
var pi2 = Math.PI*2;
for(var i=1; i<=times; i++) {
ctx.beginPath();
ctx.arc(0, 0, i * d, 0, pi2, true);
ctx.stroke();
ctx.closePath();
}
}
}
}
});
(end code)
The _backgroundCanvas_ object contains a canvas _styles_ property and
an _impl_ key to be used for implementing background canvas specific code.
The _init_ method is only called once, at the instanciation of the background canvas.
The _plot_ method is called for plotting a Canvas image.
*/
this.Canvas = (function(){
var config = {
'injectInto': 'id',
'width': 200,
'height': 200,
//deprecated
'backgroundColor': '#333333',
'styles': {
'fillStyle': '#000000',
'strokeStyle': '#000000'
},
'backgroundCanvas': false
};
function hasCanvas(){
hasCanvas.t = hasCanvas.t || typeof(HTMLCanvasElement);
return "function" == hasCanvas.t || "object" == hasCanvas.t;
};
function create(tag, prop, styles){
var elem = document.createElement(tag);
(function(obj, prop){
if (prop) {
for (var p in prop) {
obj[p] = prop[p];
}
}
return arguments.callee;
})(elem, prop)(elem.style, styles);
//feature check
if (tag == "canvas" && !hasCanvas() && G_vmlCanvasManager) {
elem = G_vmlCanvasManager.initElement(document.body.appendChild(elem));
}
return elem;
};
function get(id){
return document.getElementById(id);
};
function translateToCenter(canvas, ctx, w, h){
var width = w ? (canvas.width - w) : canvas.width;
var height = h ? (canvas.height - h) : canvas.height;
ctx.translate(width / 2, height / 2);
};
return function(id, opt){
var ctx, bkctx, mainContainer, labelContainer, canvas, bkcanvas;
if (arguments.length < 1)
throw "Arguments missing";
var idLabel = id + "-label", idCanvas = id + "-canvas", idBCanvas = id + "-bkcanvas";
opt = $merge(config, opt || {});
//create elements
var dim = {
'width': opt.width,
'height': opt.height
};
mainContainer = create("div", {
'id': id
}, $merge(dim, {
'position': 'relative'
}));
labelContainer = create("div", {
'id': idLabel
}, {
'overflow': 'visible',
'position': 'absolute',
'top': 0,
'left': 0,
'width': dim.width + 'px',
'height': 0
});
var dimPos = {
'position': 'absolute',
'top': 0,
'left': 0,
'width': dim.width + 'px',
'height': dim.height + 'px'
};
canvas = create("canvas", $merge({
'id': idCanvas
}, dim), dimPos);
var bc = opt.backgroundCanvas;
if (bc) {
bkcanvas = create("canvas", $merge({
'id': idBCanvas
}, dim), dimPos);
//append elements
mainContainer.appendChild(bkcanvas);
}
mainContainer.appendChild(canvas);
mainContainer.appendChild(labelContainer);
get(opt.injectInto).appendChild(mainContainer);
//create contexts
ctx = canvas.getContext('2d');
translateToCenter(canvas, ctx);
var st = opt.styles;
var s;
for (s in st)
ctx[s] = st[s];
if (bc) {
bkctx = bkcanvas.getContext('2d');
st = bc.styles;
for (s in st) {
bkctx[s] = st[s];
}
translateToCenter(bkcanvas, bkctx);
bc.impl.init(bkcanvas, bkctx);
bc.impl.plot(bkcanvas, bkctx);
}
//create methods
return {
'id': id,
/*
Method: getCtx
Returns the main canvas context object
Returns:
Main canvas context
Example:
(start code js)
var ctx = canvas.getCtx();
//Now I can use the native canvas context
//and for example change some canvas styles
ctx.globalAlpha = 1;
(end code)
*/
getCtx: function(){
return ctx;
},
/*
Method: getElement
Returns the main Canvas DOM wrapper
Returns:
DOM canvas wrapper generated, (i.e the div wrapper element with id _mycanvas_)
Example:
(start code js)
var wrapper = canvas.getElement();
//Returns <div id="mycanvas" ... >...</div> as element
(end code)
*/
getElement: function(){
return mainContainer;
},
/*
Method: resize
Resizes the canvas.
Parameters:
width - New canvas width.
height - New canvas height.
This method can be used with the <ST>, <Hypertree> or <RGraph> visualizations to resize
the visualizations
Example:
(start code js)
function resizeViz(width, height) {
canvas.resize(width, height);
rgraph.refresh(); //ht.refresh or st.refresh() also work.
rgraph.onAfterCompute();
}
(end code)
*/
resize: function(width, height){
var pwidth = canvas.width, pheight = canvas.height;
canvas.width = width;
canvas.height = height;
canvas.style.width = width + "px";
canvas.style.height = height + "px";
if (bc) {
bkcanvas.width = width;
bkcanvas.height = height;
bkcanvas.style.width = width + "px";
bkcanvas.style.height = height + "px";
}
//small ExCanvas fix
if(!hasCanvas()) {
translateToCenter(canvas, ctx, pwidth, pheight);
} else {
translateToCenter(canvas, ctx);
}
var st = opt.styles;
var s;
for (s in st) {
ctx[s] = st[s];
}
if (bc) {
st = bc.styles;
for (s in st)
bkctx[s] = st[s];
//same ExCanvas fix here
if(!hasCanvas()) {
translateToCenter(bkcanvas, bkctx, pwidth, pheight);
} else {
translateToCenter(bkcanvas, bkctx);
}
bc.impl.init(bkcanvas, bkctx);
bc.impl.plot(bkcanvas, bkctx);
}
},
/*
Method: getSize
Returns canvas dimensions.
Returns:
An object with _width_ and _height_ properties.
Example:
(start code js)
canvas.getSize(); //returns { width: 900, height: 500 }
(end code)
*/
getSize: function(){
return {
'width': canvas.width,
'height': canvas.height
};
},
path: function(type, action){
ctx.beginPath();
action(ctx);
ctx[type]();
ctx.closePath();
},
/*
Method: clear
Clears the canvas object.
*/
clear: function(){
var size = this.getSize();
ctx.clearRect(-size.width / 2, -size.height / 2, size.width, size.height);
},
/*
Method: clearReactangle
Same as <Canvas.clear> but only clears a section of the canvas.
Parameters:
top - An integer specifying the top of the rectangle.
right - An integer specifying the right of the rectangle.
bottom - An integer specifying the bottom of the rectangle.
left - An integer specifying the left of the rectangle.
*/
clearRectangle: function(top, right, bottom, left){
//if using excanvas
if (!hasCanvas()) {
var f0 = ctx.fillStyle;
ctx.fillStyle = opt.backgroundColor;
ctx.fillRect(left, top, Math.abs(right - left), Math.abs(bottom - top));
ctx.fillStyle = f0;
}
else {
ctx.clearRect(left, top, Math.abs(right - left), Math.abs(bottom - top));
}
}
};
};
})();
/*
* File: Polar.js
*
* Defines the <Polar> class.
*
* Description:
*
* The <Polar> class, just like the <Complex> class, is used by the <Hypertree>, <ST> and <RGraph> as a 2D point representation.
*
* See also:
*
* <http://en.wikipedia.org/wiki/Polar_coordinates>
*
*/
/*
Class: Polar
A multi purpose polar representation.
Description:
The <Polar> class, just like the <Complex> class, is used by the <Hypertree>, <ST> and <RGraph> as a 2D point representation.
See also:
<http://en.wikipedia.org/wiki/Polar_coordinates>
Parameters:
theta - An angle.
rho - The norm.
*/
this.Polar = function(theta, rho) {
this.theta = theta;
this.rho = rho;
};
Polar.prototype = {
/*
Method: getc
Returns a complex number.
Parameters:
simple - _optional_ If *true*, this method will return only an object holding x and y properties and not a <Complex> instance. Default's *false*.
Returns:
A complex number.
*/
getc: function(simple) {
return this.toComplex(simple);
},
/*
Method: getp
Returns a <Polar> representation.
Returns:
A variable in polar coordinates.
*/
getp: function() {
return this;
},
/*
Method: set
Sets a number.
Parameters:
v - A <Complex> or <Polar> instance.
*/
set: function(v) {
v = v.getp();
this.theta = v.theta; this.rho = v.rho;
},
/*
Method: setc
Sets a <Complex> number.
Parameters:
x - A <Complex> number real part.
y - A <Complex> number imaginary part.
*/
setc: function(x, y) {
this.rho = Math.sqrt(x * x + y * y);
this.theta = Math.atan2(y, x);
if(this.theta < 0) this.theta += Math.PI * 2;
},
/*