forked from mivion/ephemeris
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnatalchart.js
1205 lines (1071 loc) · 40.2 KB
/
natalchart.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
var outerWheelRadius = 228;
var chartSignWidth = 20;
var innerCircleRadius = 70;
var middleCircleRadius = innerCircleRadius + 70;
var leadingZero = new Array();
var elementColor = ["red", "green", "yellow", "blue"];
var $planetColor = {
sun: "#feb400",
moon: "#b2b2b2",
mercury: "#abc600",
venus: "#00ccce",
mars: "#be0000",
jupiter: "#0000cb",
saturn: "#a28868",
chiron: "#666666",
uranus: "#bc00ca",
neptune: "#116f43",
pluto: "#6b0000",
ascendant: "#000000",
midheaven: "#000000"
};
$ns.drawNatalChart = function (ctx) {
var y, color;
ctx.save();
// Clear out the chartcanvas for multiple executions
ctx.setTransform(1, 0, 0, 1, 0, 0);
ctx.clearRect(0, 0, 2*chartcanvas.width, 2*chartcanvas.height);
// Move the 0,0 point to the center of the chartcanvas
ctx.translate(chartcanvas.width/2, chartcanvas.height/2);
ctx.strokeStyle = "black";
ctx.fillStyle = "black";
ctx.lineWidth = 1;
ctx.save();
// Start on the Ascendant
ctx.rotate(Math.PI);
// Rotate by the Ascendant to start at 0 degrees Aries
ctx.rotate(hsp.cusp[1]*Math.PI/180);
// Draw outside wheel with colors
for (var i = 0; i < 12; i++) {
ctx.beginPath();
ctx.lineWidth = 2;
ctx.strokeStyle = elementColor[i % 4];
ctx.arc(0, 0, outerWheelRadius, 0, -30*Math.PI/180, true);
ctx.rotate(-Math.PI/6);
ctx.stroke();
}
// Draw outside wheel with black outline
ctx.beginPath();
ctx.lineWidth = 0.5;
ctx.strokeStyle = "black";
ctx.arc(0, 0, outerWheelRadius, 0, 2*Math.PI, true);
ctx.stroke();
ctx.lineWidth = 1.2;
// Draw Decan Marks
for (var i = 0; i < 36; i++) {
ctx.beginPath();
// Outer wheel ticks
ctx.moveTo(outerWheelRadius-6, 0);
ctx.lineTo(outerWheelRadius, 0);
ctx.stroke();
ctx.rotate(-Math.PI/18);
}
// Draw Degree marks
ctx.lineWidth = 0.5;
for (i = 0; i < 360; i++) {
if (i % 30 != 0) {
ctx.beginPath();
// Outer wheel ticks
ctx.moveTo(outerWheelRadius-4, 0);
ctx.lineTo(outerWheelRadius, 0);
ctx.stroke();
}
ctx.rotate(-Math.PI / 180);
}
ctx.restore();
// Draw the House Cusps
var houseCuspBeginX, houseCuspBeginY, houseCuspEndX, houseCuspEndY;
var glpyhCuspBeginX, glpyhCuspBegin7;
var degreeCuspBeginX, degreeCuspBeginY;
var minuteCuspBeginX, minuteCuspBeginY;
var degreeDegreeOffset = Array();
var degreeRadiusOffset = Array();
var minuteDegreeOffset = Array();
var minuteRadiusOffset = Array();
var signDegree, signMinute;
ctx.save();
ctx.font = "10px Arial";
for (var i = 1; i < 13; i++) {
ctx.beginPath();
houseCuspBeginX = (outerWheelRadius-chartSignWidth)*Math.cos((180-(cusp[i]))*DEGTORAD);
houseCuspBeginY = (outerWheelRadius-chartSignWidth)*Math.sin((180-(cusp[i]))*DEGTORAD);
houseCuspEndX = middleCircleRadius*Math.cos((180-(cusp[i]))*DEGTORAD);
houseCuspEndY = middleCircleRadius*Math.sin((180-(cusp[i]))*DEGTORAD);
ctx.moveTo(houseCuspBeginX, houseCuspBeginY);
ctx.lineTo(houseCuspEndX, houseCuspEndY);
ctx.stroke();
// Draw the midheaven arrow
if (i == 10) {
// Draw Midheaven Arrow
var arrowHeadLength = 10; // length of head in pixels
var dx = houseCuspBeginX-houseCuspEndX;
var dy = houseCuspBeginY-houseCuspEndY;
var angle = Math.atan2(dy,dx);
ctx.moveTo(houseCuspBeginX, houseCuspBeginY);
ctx.lineTo(houseCuspBeginX-arrowHeadLength*Math.cos(angle-Math.PI/6),houseCuspBeginY-arrowHeadLength*Math.sin(angle-Math.PI/6));
ctx.moveTo(houseCuspBeginX, houseCuspBeginY);
ctx.lineTo(houseCuspBeginX-arrowHeadLength*Math.cos(angle+Math.PI/6),houseCuspBeginY-arrowHeadLength*Math.sin(angle+Math.PI/6));
ctx.stroke();
}
// Draw Cusp Sign Glpyhs and Degrees
glpyhCuspBeginX = (outerWheelRadius-9)*Math.cos((180-(cusp[i]))*DEGTORAD) - 7;
glpyhCuspBeginY = (outerWheelRadius-9)*Math.sin((180-(cusp[i]))*DEGTORAD) - 7;
ctx.drawImage(signImageArray[Math.floor(hsp.cusp[i]/30)],glpyhCuspBeginX,glpyhCuspBeginY,14,14);
// Add an individual offset to position each degree near the house cusp
// TODO: Refactor this array to be based upon the degree relative to zero Aries. Break into quarters. Use sin & cos
degreeDegreeOffset = [0, -3, -3, -3, -5, -6, -6, 3, 4, 4, 6, 6, 5];
degreeRadiusOffset = [0, -3, -3, -3, -3, -8, -14, -16, -16, -16, -16, -10, -6];
degreeCuspBeginX = (outerWheelRadius+degreeRadiusOffset[i])*Math.cos((180-(cusp[i]+degreeDegreeOffset[i]))*DEGTORAD);
degreeCuspBeginY = (outerWheelRadius+degreeRadiusOffset[i])*Math.sin((180-(cusp[i]+degreeDegreeOffset[i]))*DEGTORAD);
signDegree = Math.floor(hsp.cusp[i] % 30);
ctx.fillText(signDegree+String.fromCharCode(0x00B0), degreeCuspBeginX, degreeCuspBeginY);
// Add an individual offset to position each minute near the house cusp
// TODO: Refactor this array to be based upon the degree relative to zero Aries. Break into quarters. Use sin & cos
minuteDegreeOffset = [0, -5, -4, -4, -3, -2, -3, 5, 4, 4, 4, 2, 3];
minuteRadiusOffset = [0, -2, -2, -2, -2, -8, -14, -16, -16, -16, -16, -13, -7];
minuteCuspBeginX = (outerWheelRadius+minuteRadiusOffset[i]-1)*Math.cos((180-(cusp[i]-minuteDegreeOffset[i]))*DEGTORAD);
minuteCuspBeginY = (outerWheelRadius+minuteRadiusOffset[i])*Math.sin((180-(cusp[i]-minuteDegreeOffset[i]))*DEGTORAD);
signMinute = Math.round(((hsp.cusp[i] % 30)-signDegree)*60);
ctx.fillText(signMinute+'"',minuteCuspBeginX, minuteCuspBeginY);
}
// Draw inside wheel with radius of chartSignWidth less than outside
ctx.save();
ctx.beginPath();
ctx.lineWidth = 1;
ctx.arc(0, 0, outerWheelRadius-chartSignWidth, 0, Math.PI * 2, true);
ctx.stroke();
ctx.restore();
// Draw middle circle with radius of middleCircleRadius
ctx.save();
ctx.beginPath();
ctx.arc(0, 0, middleCircleRadius, 0, Math.PI * 2, true);
ctx.stroke();
ctx.restore();
};
var transitingPlanetSign = Array();
var transitingPlanetHouse = Array();
// Draw the transiting planet locations, tick marks and transit lines
$ns.drawTransitPlanets = function (circleRadius) {
var ctx = document.getElementById('transitcanvas').getContext('2d');
var planetGlyphX, planetGlyphY;
var signGlyphX, signGlyphY;
var planetX, planetY;
var outerX, outerY;
var signDegree, signMinute;
var minuteX, minuteY;
var tickStartX, tickStartY;
var tickStopX, tickStopY;
var innerTickStartX, innerTickStartY;
var innerTickStopX, innerTickStopY;
// Reset transform to the upper right-hand corner
ctx.setTransform(1, 0, 0, 1, 0, 0);
// Draw Planet Glpyhs and Degree lines
// Go from the outside wheel to the inside circle
ctx.font = "10px Arial";
ctx.clearRect(0, 0, transitcanvas.width, transitcanvas.height);
ctx.save();
ctx.translate(transitcanvas.width/2, transitcanvas.height/2);
for (var key in $transitPlanets) {
// Draw the transiting planet degree line on outer circle
ctx.beginPath();
ctx.lineWidth = 0.5;
ctx.strokeStyle = $planetColor[key];
ctx.fillStyle = $planetColor[key];
planetX = Math.cos((180-swe_degnorm($transitPlanets[key]-hsp.cusp[1]))*DEGTORAD);
planetY = Math.sin((180-swe_degnorm($transitPlanets[key]-hsp.cusp[1]))*DEGTORAD);
outerX = outerWheelRadius * planetX;
outerY = outerWheelRadius * planetY;
// Draw planetary position dot the outside of the outer circle
ctx.moveTo(outerX, outerY);
ctx.arc(outerX, outerY, 3, 0, Math.PI * 2, true);
ctx.fill();
// Place glyph of transiting planet
planetGlyphX = 198 * planetX - 8;
planetGlyphY = 198 * planetY - 8;
ctx.drawImage(planetImageArray[key],planetGlyphX,planetGlyphY, 16, 16);
// Place degree of transiting planet
degreeX = 184 * planetX;
degreeY = 184 * planetY;
signDegree = Math.floor($transitPlanets[key] % 30);
ctx.fillText(signDegree+String.fromCharCode(0x00B0), degreeX-5, degreeY+3);
// Place glyph of transiting planet's sign
signGlyphX = 170 * planetX;
signGlyphY = 170 * planetY;
transitingPlanetSign[key] = Math.floor($transitPlanets[key] / 30);
ctx.drawImage(signImageArray[transitingPlanetSign[key]],signGlyphX-6,signGlyphY-6, 12, 12);
// Place miniute of transiting planet's sign
minuteX = 155 * planetX;
minuteY = 155 * planetY;
signMinute = Math.round((($transitPlanets[key] % 30)-signDegree)*60);
ctx.fillText(signMinute+'"', minuteX-5, minuteY+3);
// Draw the transiting planet degree line on middle circle
ctx.lineWidth = 1;
tickStartX = middleCircleRadius * planetX;
tickStartY = middleCircleRadius * planetY;
tickStopX = (middleCircleRadius + 5) * planetX;
tickStopY = (middleCircleRadius + 5) * planetY;
ctx.moveTo(tickStartX, tickStartY);
ctx.lineTo(tickStopX, tickStopY);
ctx.stroke();
// Draw the transiting planet degree line on inner circle
ctx.lineWidth = 1;
transitingPlanetX = Math.cos((180-swe_degnorm($transitPlanets[key]-hsp.cusp[1]))*DEGTORAD);
transitingPlanetY = Math.sin((180-swe_degnorm($transitPlanets[key]-hsp.cusp[1]))*DEGTORAD);
innerTickStartX = circleRadius * transitingPlanetX;
innerTickStartY = circleRadius * transitingPlanetY;
innerTickStopX = (circleRadius - 5) * transitingPlanetX;
innerTickStopY = (circleRadius - 5) * transitingPlanetY;
ctx.moveTo(innerTickStartX, innerTickStartY);
ctx.lineTo(innerTickStopX, innerTickStopY);
ctx.stroke();
}
ctx.restore();
// Calculate which house the transiting planet is in
if (calculateHouses){
transitingPlanetHouse = calculateHouseCusps($transitPlanets);
}
// Label the Outer Wheel Transits
ctx.font = "12px Arial";
ctx.fillText("Outer Wheel / Transits", 335, 14);
ctx.fillText(monthtext[$transitInputDate.month]+" "+$transitInputDate.day+", "+$transitInputDate.year, 385, 28);
$e.calculateLeadingZeros($transitInputDate);
ctx.fillText(leadingZero[0]+$transitInputDate.hours+":"+leadingZero[1]+$transitInputDate.minutes+":"+leadingZero[2]+$transitInputDate.seconds+" GMT", 380, 42);
ctx.fill();
}
// Make the transitIntensity ratings other to other functions
var transitIntensity = {
moon: 1,
sun: 2,
mercury: 4,
venus: 4,
mars: 5,
jupiter: 6,
saturn: 7,
chiron: 8,
uranus: 10,
neptune: 10,
pluto: 10
};
// Calculate and display transits
$ns.drawTransitLines = function (circleRadius) {
var natalTransits = new Array();
var displayTransits = Array();
var transitCount = 0;
var conjunctRadius;
var orb;
if (calculateHouses){
$natalPlanets['ascendant'] = hsp.ac;
$natalPlanets['midheaven'] = hsp.mc;
}
var ctx = document.getElementById('transitcanvas').getContext('2d');
var transitCtx = document.getElementById('transitcanvas').getContext('2d');
ctx.save();
ctx.translate(transitcanvas.width/2, transitcanvas.height/2);
for (var natalKey in $natalPlanets) {
natalTransits[natalKey] = new Array();
for (var transitKey in $transitPlanets) {
natalTransits[natalKey][transitKey] = Math.abs($natalPlanets[natalKey] - $transitPlanets[transitKey]);
if (natalTransits[natalKey][transitKey] > 180) {
natalTransits[natalKey][transitKey] = 360 - natalTransits[natalKey][transitKey];
};
// plot opposition
if (natalTransits[natalKey][transitKey] >= 179) {
displayTransits[transitCount] = {
'strength': 10 * transitIntensity[transitKey],
'transitPlanet': transitKey,
'natalPlanet': natalKey,
'aspect': 'oppose',
'color': 'red',
'difference': Math.abs(180-natalTransits[natalKey][transitKey])
};
$e.drawAspectLine($transitPlanets[transitKey], $natalPlanets[natalKey], displayTransits[transitCount], circleRadius, transitCtx, 1);
transitCount++;
}
// plot conjunction
if (natalTransits[natalKey][transitKey] >= 0 && natalTransits[natalKey][transitKey] <= 1) {
displayTransits[transitCount] = {
'strength': 10 * transitIntensity[transitKey],
'transitPlanet': transitKey,
'natalPlanet': natalKey,
'aspect': 'conjunct',
'color': 'black',
'difference': natalTransits[natalKey][transitKey]
};
// Draw a Black dot on the the transiting planet tick to the natal planet
ctx.save();
ctx.beginPath();
ctx.fillStyle = "black";
// Calculate the radius of the conjunction circle based upon the closeness of the orb of the conjunction
orb = (1.0 - displayTransits[transitCount].difference)*90;
if (orb < 22.5) {
conjunctRadius= 3;
} else if (orb > 22.5 && orb < 45){
conjunctRadius = 4;
} else if (orb > 45 && orb < 67.5){
conjunctRadius = 5;
} else {
conjunctRadius = 6;
}
transitingPlanetX = (circleRadius - 4 - conjunctRadius) * Math.cos((180-swe_degnorm($transitPlanets[transitKey]-hsp.cusp[1]))*DEGTORAD);
transitingPlanetY = (circleRadius - 4 - conjunctRadius) * Math.sin((180-swe_degnorm($transitPlanets[transitKey]-hsp.cusp[1]))*DEGTORAD);
ctx.moveTo(transitingPlanetX, transitingPlanetY);
ctx.arc(transitingPlanetX, transitingPlanetY, conjunctRadius, 0, Math.PI * 2, true);
ctx.fill();
ctx.restore();
transitCount++;
}
// plot square
if (natalTransits[natalKey][transitKey] >= 89 && natalTransits[natalKey][transitKey] <= 91) {
displayTransits[transitCount] = {
'strength': 8 * transitIntensity[transitKey],
'transitPlanet': transitKey,
'natalPlanet': natalKey,
'aspect': 'square',
'color': 'red',
'difference': Math.abs(90-natalTransits[natalKey][transitKey])
};
$e.drawAspectLine($transitPlanets[transitKey], $natalPlanets[natalKey], displayTransits[transitCount], circleRadius, transitCtx, 1);
transitCount++;
}
// plot trine
if (natalTransits[natalKey][transitKey] >= 119 && natalTransits[natalKey][transitKey] <= 121) {
displayTransits[transitCount] = {
'strength': 5 * transitIntensity[transitKey],
'transitPlanet': transitKey,
'natalPlanet': natalKey,
'aspect': 'trine',
'color': 'blue',
'difference': Math.abs(120-natalTransits[natalKey][transitKey])
};
$e.drawAspectLine($transitPlanets[transitKey], $natalPlanets[natalKey], displayTransits[transitCount], circleRadius, transitCtx, 1);
transitCount++;
}
// plot sextile
if (natalTransits[natalKey][transitKey] >= 59 && natalTransits[natalKey][transitKey] <= 61) {
displayTransits[transitCount] = {
'strength': 3 * transitIntensity[transitKey],
'transitPlanet': transitKey,
'natalPlanet': natalKey,
'aspect': 'sextile',
'color': 'blue',
'difference': Math.abs(60-natalTransits[natalKey][transitKey])
};
$e.drawAspectLine($transitPlanets[transitKey], $natalPlanets[natalKey], displayTransits[transitCount], circleRadius, transitCtx, 1);
transitCount++;
}
// plot quincunx
if (natalTransits[natalKey][transitKey] >= 149 && natalTransits[natalKey][transitKey] <= 151) {
displayTransits[transitCount] = {
'strength': 2 * transitIntensity[transitKey],
'transitPlanet': transitKey,
'natalPlanet': natalKey,
'aspect': 'quincunx',
'color': 'green',
'difference': Math.abs(150-natalTransits[natalKey][transitKey])
};
$e.drawAspectLine($transitPlanets[transitKey], $natalPlanets[natalKey], displayTransits[transitCount], circleRadius, transitCtx, 1);
transitCount++;
}
}
}
ctx.restore();
// Sort the displayTransits array in order of the strongest transits first
displayTransits.sort(function compareStrength(a,b) {return b.strength - a.strength});
var ctx = document.getElementById('aspectcanvas').getContext('2d');
var orb;
var x, y;
ctx.clearRect(0, 0, aspectcanvas.width, aspectcanvas.height);
// Display the ordered aspects with an orb indication
for (var i = 0; i < transitCount; i++) {
x = i % 4;
y = Math.floor(i/4);
// draw a grey rectangle around the outer planet transits
if(displayTransits[i].transitPlanet == 'pluto' || displayTransits[i].transitPlanet == 'neptune' || displayTransits[i].transitPlanet == 'uranus') {
ctx.save();
ctx.strokeStyle = "#CDCDCD";
ctx.beginPath();
ctx.moveTo(x*115, y*50);
ctx.strokeRect(x*115, y*50, 100, 40);
ctx.restore();
}
ctx.save();
ctx.beginPath();
// Draw the Transiting Planet, Sign and House
ctx.drawImage(planetImageArray[displayTransits[i].transitPlanet], x*115+0, y*50);
ctx.drawImage(signImageArray[transitingPlanetSign[[displayTransits[i].transitPlanet]]], (x*115)+22, (y*50)+20, 12, 12);
if (calculateHouses){
ctx.fillText(transitingPlanetHouse[[displayTransits[i].transitPlanet]], x*115+25, y*50+19);
}
// Draw the Transiting Aspect
ctx.drawImage(aspectImageArray[displayTransits[i].aspect], x*115+30+12, y*50+5, 16, 16);
// Draw the Natal Planet, Sign and House
ctx.drawImage(planetImageArray[displayTransits[i].natalPlanet], x*115+60, y*50);
ctx.drawImage(signImageArray[planetSign[[displayTransits[i].natalPlanet]]], x*115+60+22, y*50+20, 12, 12);
if (calculateHouses){
ctx.fillText(natalPlanetHouse[[displayTransits[i].natalPlanet]], x*115+60+27, y*50+19);
}
ctx.restore();
ctx.save();
// Calculate the orb strength and plot the bar graph
orb = (1.0 - displayTransits[i].difference)*90;
if (orb < 22.5) {
ctx.lineWidth = 1;
} else if (orb > 22.5 && orb < 45){
ctx.lineWidth = 3;
} else if (orb > 45 && orb < 67.5){
ctx.lineWidth = 5;
} else {
ctx.lineWidth = 7;
}
ctx.strokeStyle = displayTransits[i].color;
ctx.moveTo(x*115, (y*50)+35);
ctx.lineTo((x*115)+orb, (y*50)+35);
ctx.stroke();
// Display the orb of the aspect in minutes
ctx.fillStyle = displayTransits[i].color;
ctx.fillText(Math.round(displayTransits[i].difference*60)+'"', x*115+30+13, y*50+29);
ctx.restore();
}
ctx.setTransform(1, 0, 0, 1, 0, 0);
};
// Draw the aspect line onto the natal chart
$ns.drawAspectLine = function ($transitDegree, $natalDegree, displayTransits, circleRadius, ctx, alpha) {
ctx.save();
ctx.beginPath();
ctx.strokeStyle = displayTransits.color;
// Increase the width of the aspect line depending on the closeness of the orb
var orb = (1.0 - displayTransits.difference)*90;
if (orb < 22.5) {
ctx.lineWidth = 0.5;
} else if (orb > 22.5 && orb < 45){
ctx.lineWidth = 1;
} else if (orb > 45 && orb < 67.5){
ctx.lineWidth = 2;
} else {
ctx.lineWidth = 3;
}
transitingPlanetX = Math.cos((180-swe_degnorm($transitDegree-hsp.cusp[1]))*DEGTORAD);
transitingPlanetY = Math.sin((180-swe_degnorm($transitDegree-hsp.cusp[1]))*DEGTORAD);
aspectLineStartX = (circleRadius) * transitingPlanetX;
aspectLineStartY = (circleRadius) * transitingPlanetY;
natalPlanetX = Math.cos((180-swe_degnorm($natalDegree-hsp.cusp[1]))*DEGTORAD);
natalPlanetY = Math.sin((180-swe_degnorm($natalDegree-hsp.cusp[1]))*DEGTORAD);
aspectLineStopX = circleRadius * natalPlanetX;
aspectLineStopY = circleRadius * natalPlanetY;
ctx.moveTo(aspectLineStartX, aspectLineStartY);
ctx.lineTo(aspectLineStopX, aspectLineStopY);
ctx.globalAlpha = alpha;
ctx.stroke();
// Place the arrow closer to the natal planet for quick visual reference of the transit direction
midpointX = Math.abs(aspectLineStartX-aspectLineStopX)/4;
midpointY = Math.abs(aspectLineStartY-aspectLineStopY)/4;
if (aspectLineStartX-aspectLineStopX > 0) {
// Transit-to-Natal is Right-to-Left
arrowX = aspectLineStopX + midpointX;
} else {
// Transit-to-Natal is Left-to-Right
arrowX = aspectLineStopX - midpointX;
}
if (aspectLineStartY-aspectLineStopY > 0) {
// Transit-to-Natal is Down-to-Up
arrowY = aspectLineStopY + midpointY;
} else {
// Transit-to-Natal is Up-to-Down
arrowY = aspectLineStopY - midpointY;
}
// Draw Arrow
var arrowHeadLength = 10; // length of head in pixels
var dx = aspectLineStopX-aspectLineStartX;
var dy = aspectLineStopY-aspectLineStartY;
var angle = Math.atan2(dy,dx);
ctx.moveTo(arrowX, arrowY);
ctx.lineTo(arrowX-arrowHeadLength*Math.cos(angle-Math.PI/6),arrowY-arrowHeadLength*Math.sin(angle-Math.PI/6));
ctx.moveTo(arrowX, arrowY);
ctx.lineTo(arrowX-arrowHeadLength*Math.cos(angle+Math.PI/6),arrowY-arrowHeadLength*Math.sin(angle+Math.PI/6));
ctx.stroke();
ctx.restore();
};
var planetSign = Array();
var natalPlanetHouse = Array();
// Draw the transiting planet locations, tick marks and transit lines
$ns.drawNatalPlanets = function (ctx, biwheel) {
var planetGlyphX, planetGlyphY;
var signGlyphX, signGlyphY;
var planetX, planetY;
var innerX, innerY;
var middleX, middleY;
var degreeX, degreeY, minuteX, minuteY;
var signDegree, signMinute;
var tickStartX, tickStartY;
var tickStopX, tickStopY;
var planetGlyphRadius;
var degreeRadius, minuteRadius;
var signGlyphRadius;
var circleRadius;
var natalGlyphSize, signGlyphSize;
var maxHouse;
if (calculateHouses){
if (houseSystem !="W"){
delete $natalPlanets['ascendant'];
delete $natalPlanets['midheaven'];
} else {
$natalPlanets['ascendant'] = hsp.ac;
$natalPlanets['midheaven'] = hsp.mc;
}
}
// Move the 0,0 point to the center of the chartcanvas
ctx.translate(natalcanvas.width/2, natalcanvas.height/2);
if (biwheel) {
// For the biwheel, draw the House Cusps marks from middle circle to inner circle & inner circle
var houseCuspBeginX, houseCuspBeginY, houseCuspEndX, houseCuspEndY;
ctx.save();
ctx.lineWidth = 0.75;
for (var i = 1; i < 13; i++) {
ctx.beginPath();
houseCuspBeginX = middleCircleRadius*Math.cos((180-(cusp[i]))*DEGTORAD);
houseCuspBeginY = middleCircleRadius*Math.sin((180-(cusp[i]))*DEGTORAD);
houseCuspEndX = innerCircleRadius*Math.cos((180-(cusp[i]))*DEGTORAD);
houseCuspEndY = innerCircleRadius*Math.sin((180-(cusp[i]))*DEGTORAD);
ctx.moveTo(houseCuspBeginX, houseCuspBeginY);
ctx.lineTo(houseCuspEndX, houseCuspEndY);
ctx.stroke();
}
ctx.restore();
// Draw inside circle with radius of innerCircleRadius
ctx.save();
ctx.beginPath();
ctx.arc(0, 0, innerCircleRadius, 0, Math.PI * 2, true);
ctx.stroke();
ctx.restore();
// For the biwheel, place natal planet info on the inner wheel
planetGlyphRadius = 128;
degreeRadius = 113;
signGlyphRadius = 100;
minuteRadius = 84;
circleRadius = innerCircleRadius;
} else {
// There's no biwheel and so place natal planets on the outer wheel
planetGlyphRadius = 193;
degreeRadius = 178;
signGlyphRadius = 165;
minuteRadius = 150;
circleRadius = middleCircleRadius;
}
ctx.setTransform(1, 0, 0, 1, 0, 0);
ctx.translate(chartcanvas.width/2, chartcanvas.height/2);
for (var key in $natalPlanets) {
ctx.save();
// Draw the natal planet degree line on outer circle
ctx.beginPath();
ctx.strokeStyle = $planetColor[key];
ctx.fillStyle = $planetColor[key];
planetX = Math.cos((180-swe_degnorm($natalPlanets[key]-hsp.cusp[1]))*DEGTORAD);
planetY = Math.sin((180-swe_degnorm($natalPlanets[key]-hsp.cusp[1]))*DEGTORAD);
innerX = (outerWheelRadius - chartSignWidth) * planetX;
innerY = (outerWheelRadius - chartSignWidth) * planetY;
middleX = middleCircleRadius * planetX;
middleY = middleCircleRadius * planetY;
ctx.lineWidth = 0.5;
// Draw planetary position dot on the middle cirlce
if (biwheel) {
ctx.moveTo(middleX, middleY);
ctx.arc(middleX, middleY, 2, 0, Math.PI * 2, true);
ctx.fill();
// Draw planetary position dot on the inside of the outer circle w/ radius of 2
ctx.moveTo(innerX, innerY);
ctx.arc(innerX, innerY, 2, 0, Math.PI * 2, true);
ctx.fill();
natalGlyphSize = 16;
signGlyphSize = 12;
} else {
// Draw planetary position dot on the inside of the outer circle w/ radius of 3
ctx.moveTo(innerX, innerY);
ctx.arc(innerX, innerY, 3, 0, Math.PI * 2, true);
ctx.fill();
natalGlyphSize = 20;
signGlyphSize = 14;
}
// Place glyph of natal planet
planetGlyphX = planetGlyphRadius * planetX - natalGlyphSize/2;
planetGlyphY = planetGlyphRadius * planetY - natalGlyphSize/2;
ctx.drawImage(planetImageArray[key],planetGlyphX,planetGlyphY, natalGlyphSize, natalGlyphSize);
// Place degree of natal planet
degreeX = degreeRadius * planetX;
degreeY = degreeRadius * planetY;
signDegree = Math.floor($natalPlanets[key] % 30);
ctx.fillText(signDegree+String.fromCharCode(0x00B0), degreeX-7, degreeY+5);
// Place glyph of natal planet's sign
signGlyphX = signGlyphRadius * planetX;
signGlyphY = signGlyphRadius * planetY;
planetSign[key] = Math.floor($natalPlanets[key] / 30);
ctx.drawImage(signImageArray[planetSign[key]],signGlyphX-signGlyphSize/2,signGlyphY-signGlyphSize/2, signGlyphSize, signGlyphSize);
// Place minute of natal planet
minuteX = minuteRadius * planetX;
minuteY = minuteRadius * planetY;
signMinute = Math.round((($natalPlanets[key] % 30)-signDegree)*60);
ctx.fillText(signMinute+'"', minuteX-7, minuteY+5);
// Draw the natal planet degree line on inner circle
ctx.lineWidth = 1;
tickStartX = circleRadius * planetX;
tickStartY = circleRadius * planetY;
tickStopX = (circleRadius + 5) * planetX;
tickStopY = (circleRadius + 5) * planetY;
ctx.moveTo(tickStartX, tickStartY);
ctx.lineTo(tickStopX, tickStopY);
ctx.stroke();
ctx.restore();
};
ctx.setTransform(1, 0, 0, 1, 0, 0);
// Label the Inner Wheel Natal Chart
ctx.font = "12px Arial";
if (biwheel) {
ctx.fillText("Inner Wheel / Natal Chart", 0, 14);
} else {
ctx.fillText("Natal Chart", 0, 14);
}
ctx.fillText(monthtext[$natalInputDate.month]+" "+$natalInputDate.day+", "+$natalInputDate.year, 0, 28);
$e.calculateLeadingZeros($natalInputDate);
ctx.fillText(leadingZero[0]+$natalInputDate.hours+":"+leadingZero[1]+$natalInputDate.minutes+":"+leadingZero[2]+$natalInputDate.seconds+" GMT", 0, 42);
ctx.fill();
// Determine which house the natal planet is in
if (calculateHouses){
$natalPlanets['ascendant'] = hsp.ac;
$natalPlanets['midheaven'] = hsp.mc;
natalPlanetHouse = calculateHouseCusps($natalPlanets);
planetSign['ascendant'] = Math.floor($natalPlanets['ascendant'] / 30);
planetSign['midheaven'] = Math.floor($natalPlanets['midheaven'] / 30);
}
};
Array.max = function(array) {
return Math.max.apply(Math, array);
};
// Determine if the hours, seconds and minutes need to have a leading zero
$ns.calculateLeadingZeros = function($inputDate) {
leadingZero[0] = '';
leadingZero[1] = '';
leadingZero[2] = '';
if($inputDate.hours < 10) {
leadingZero[0] = '0';
}
if($inputDate.minutes < 10) {
leadingZero[1] = '0';
}
if($inputDate.seconds < 10) {
leadingZero[2] = '0';
}
}
// Make the transitIntensity ratings other to other functions
var aspectIntensity = {
moon: 10,
sun: 10,
mercury: 8,
venus: 8,
mars: 7,
jupiter: 5,
saturn: 4,
chiron: 2,
uranus: 1,
neptune: 1,
pluto: 1
};
// TODO: Add in the north node = 0, ascendent = 3 and midheaven = 3 once I can calculate those values
var elementalWeight = {
moon: 3,
sun: 3,
mercury: 2,
venus: 2,
mars: 2,
jupiter: 1,
saturn: 1,
chiron: 0,
uranus: 1,
neptune: 1,
pluto: 1,
}
// TODO: Set the orb for the aspects to be a degree larger for the luminaries of the Sun and Moon
// TODO: Calculate whether an aspect is applying or separating, and have special smaller orbs if it's separating.
var aspectOrb = {
conjunct: 9,
oppose: 8,
trine: 7,
square: 6,
sextile: 3.5,
quincunx: 2.5
}
// TODO: Add in the north node, ascendent, and midheaven = 3 once I can calculate those values
var aspectOrderGridCount = {
moon: 0,
sun: 1,
mercury: 2,
venus: 3,
mars: 4,
jupiter: 5,
saturn: 6,
uranus: 7,
neptune: 8,
pluto: 9,
chiron: 10
};
// TODO: Add in the north node, ascendent, and midheaven = 3 once I can calculate those values
var aspectOrder = {
moon: 0,
sun: 1,
mercury: 2,
venus: 3,
mars: 4,
jupiter: 5,
saturn: 6,
uranus: 7,
neptune: 8,
pluto: 9,
chiron: 10,
};
// Draw the aspect lines on the natal chart, draw the aspect grid, and draw element/mode bar graphs
$ns.drawNatalAspects = function (circleRadius) {
var natalAspects = new Array();
var displayAspects = Array();
var aspectCount = 0;
var conjunctRadius;
var orb;
// Add in the Ascendant and Midheaven if calculating House Cusps
if (calculateHouses){
aspectIntensity['ascendant'] = 10;
aspectIntensity['midheaven'] = 10;
elementalWeight['ascendant'] = 3;
elementalWeight['midheaven'] = 3;
aspectOrderGridCount['ascendant'] = 11;
aspectOrderGridCount['midheaven'] = 12;
aspectOrder['ascendant'] = 11;
aspectOrder['midheaven'] = 12;
$natalPlanets['ascendant'] = hsp.ac;
$natalPlanets['midheaven'] = hsp.mc;
planetSign['ascendant'] = Math.floor($natalPlanets['ascendant'] / 30);
planetSign['midheaven'] = Math.floor($natalPlanets['midheaven'] / 30);
} else {
delete aspectIntensity['ascendant'];
delete aspectIntensity['midheaven'];
delete elementalWeight['ascendant'];
delete elementalWeight['midheaven'];
delete aspectOrderGridCount['ascendant'];
delete aspectOrderGridCount['midheaven'];
delete aspectOrder['ascendant'];
delete aspectOrder['midheaven'];
delete $natalPlanets['ascendant'];
delete $natalPlanets['midheaven'];
delete planetSign['ascendant'];
delete planetSign['midheaven'];
}
var ctx = document.getElementById('natalchartcanvas').getContext('2d');
ctx.save();
// Use the width of 460/2 to center the aspect lines
ctx.translate(230,230);
for (var natalKey in aspectOrderGridCount) {
natalAspects[natalKey] = new Array();
delete aspectOrderGridCount[natalKey];
for (var aspectKey in aspectOrderGridCount) {
natalAspects[natalKey][aspectKey] = Math.abs($natalPlanets[natalKey] - $natalPlanets[aspectKey]);
if (natalAspects[natalKey][aspectKey] > 180) {
natalAspects[natalKey][aspectKey] = 360 - natalAspects[natalKey][aspectKey];
};
//TODO: Remove the strength calculations since it's likely not needed for an aspect grid.
// plot conjunction
if (natalAspects[natalKey][aspectKey] >= 0 && natalAspects[natalKey][aspectKey] <= aspectOrb['conjunct']) {
displayAspects[aspectCount] = {
'strength': 10 * aspectIntensity[aspectKey],
'transitPlanet': natalKey,
'natalPlanet': aspectKey,
'aspect': 'conjunct',
'color': 'black',
'difference': natalAspects[natalKey][aspectKey]
};
// Draw a Black dot on the the transiting planet tick to the natal planet
ctx.save();
ctx.beginPath();
ctx.fillStyle = "black";
// Calculate the radius of the conjunction circle based upon the closeness of the orb of the conjunction
orb = (9.0 - displayAspects[aspectCount].difference)*90;
if (orb < 200) {
conjunctRadius= 3;
} else if (orb > 200 && orb < 400){
conjunctRadius = 4;
} else if (orb > 400 && orb < 600){
conjunctRadius = 5;
} else {
conjunctRadius = 6;
}
transitingPlanetX = (circleRadius - 4 - conjunctRadius) * Math.cos((180-swe_degnorm($natalPlanets[aspectKey]-hsp.cusp[1]))*DEGTORAD);
transitingPlanetY = (circleRadius - 4 - conjunctRadius) * Math.sin((180-swe_degnorm($natalPlanets[aspectKey]-hsp.cusp[1]))*DEGTORAD);
ctx.moveTo(transitingPlanetX, transitingPlanetY);
ctx.arc(transitingPlanetX, transitingPlanetY, conjunctRadius, 0, Math.PI * 2, true);
ctx.fill();
ctx.restore();
aspectCount++;
}
// plot opposition
if (natalAspects[natalKey][aspectKey] >= 180-aspectOrb['oppose']) {
displayAspects[aspectCount] = {
'strength': 10 * aspectIntensity[aspectKey],
'transitPlanet': natalKey,
'natalPlanet': aspectKey,
'aspect': 'oppose',
'color': 'red',
'difference': Math.abs(180-natalAspects[natalKey][aspectKey])
};
$e.drawAspectLine($natalPlanets[natalKey], $natalPlanets[aspectKey], displayAspects[aspectCount], circleRadius, ctx);
aspectCount++;
}
// plot trine
if (natalAspects[natalKey][aspectKey] >= 120-aspectOrb['trine'] && natalAspects[natalKey][aspectKey] <= 120+aspectOrb['trine']) {
displayAspects[aspectCount] = {
'strength': 5 * aspectIntensity[aspectKey],
'transitPlanet': natalKey,
'natalPlanet': aspectKey,
'aspect': 'trine',
'color': 'blue',
'difference': Math.abs(120-natalAspects[natalKey][aspectKey])
};
$e.drawAspectLine($natalPlanets[natalKey], $natalPlanets[aspectKey], displayAspects[aspectCount], circleRadius, ctx);
aspectCount++;
}
// plot square
if (natalAspects[natalKey][aspectKey] >= 90-aspectOrb['square'] && natalAspects[natalKey][aspectKey] <= 90+aspectOrb['square']) {
displayAspects[aspectCount] = {
'strength': 8 * aspectIntensity[aspectKey],
'transitPlanet': natalKey,
'natalPlanet': aspectKey,
'aspect': 'square',
'color': 'red',
'difference': Math.abs(90-natalAspects[natalKey][aspectKey])
};
$e.drawAspectLine($natalPlanets[natalKey], $natalPlanets[aspectKey], displayAspects[aspectCount], circleRadius, ctx);
aspectCount++;
}
// plot sextile
if (natalAspects[natalKey][aspectKey] >= 60-aspectOrb['sextile'] && natalAspects[natalKey][aspectKey] <= 60+aspectOrb['sextile']) {
displayAspects[aspectCount] = {
'strength': 3 * aspectIntensity[aspectKey],
'transitPlanet': natalKey,
'natalPlanet': aspectKey,
'aspect': 'sextile',
'color': 'blue',
'difference': Math.abs(60-natalAspects[natalKey][aspectKey])
};
$e.drawAspectLine($natalPlanets[natalKey], $natalPlanets[aspectKey], displayAspects[aspectCount], circleRadius, ctx);
aspectCount++;
}
// plot quincunx
if (natalAspects[natalKey][aspectKey] >= 150-aspectOrb['quincunx'] && natalAspects[natalKey][aspectKey] <= 150+aspectOrb['quincunx']) {
displayAspects[aspectCount] = {
'strength': 2 * aspectIntensity[aspectKey],
'transitPlanet': natalKey,
'natalPlanet': aspectKey,
'aspect': 'quincunx',
'color': 'green',
'difference': Math.abs(150-natalAspects[natalKey][aspectKey])
};
$e.drawAspectLine($natalPlanets[natalKey], $natalPlanets[aspectKey], displayAspects[aspectCount], circleRadius, ctx);
aspectCount++;
}
}
}
ctx.restore();
// Redefine altered aspectOrderGridCount in case there are multiple calculations done on a single pageload.
aspectOrderGridCount = {
moon: 0,
sun: 1,
mercury: 2,
venus: 3,
mars: 4,
jupiter: 5,
saturn: 6,
uranus: 7,
neptune: 8,
pluto: 9,
chiron: 10
};
// Draw Aspect Grid for Natal Chart
var orb;
var x, y;
var aspectBarWidth;
var aspectDegrees;
var aspectMinutes;
// Set the aspect grid width
var gridWidth = 29;
// Add in the Ascendant and Midheaven if calculating House Cusps