-
Notifications
You must be signed in to change notification settings - Fork 0
/
MultipleSclerosisScatter.php
1359 lines (1155 loc) · 61.8 KB
/
MultipleSclerosisScatter.php
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
<html>
<head>
<title>NYP/CUMC - Report for Multiple Sclerosis, generated by the Tatonetti Lab</title>
<link rel="stylesheet" type="text/css" href="dxreport.css">
<link rel="stylesheet" type="text/css" href="print_dxreport.css" media="print">
<script src="http://code.jquery.com/jquery.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.4/js/bootstrap.min.js"></script>
<!--Adding the d3 javaascript-->
<script type="text/javascript" src="d3.min.js"></script>
</head>
<body>
<!--LABELS -->
<div class="tooltip" id="tooltip" class="hidden">
<p><strong></strong></p>
<p><span id="value"></span></p>
</div>
<div id="page">
<div id="logo">
<img src="images/cumc_logo.png"/>
</div>
<div id="header">
<h1>Multiple Sclerosis</h1>
<h3>4,287 total in-patients at NYP/CUMC</h3>
<p>1,155 males, 3,129 females, and 0 unknown</p>
</div>
<div class="section">
<h2>Number of patients broken down by length of observation at CUMC</h2>
<p>
The <i>observation period</i> for a given patient is the length of time where the
patient has data. If a patient visits NYP only once then this value will be 0 (aka ≤ 1 year).
If the patient visits multiple times over the course of five years then this value
will be 5. The plot on the left is the distribution of observation periods, the plot
on the right is the cumulative number of patients with <i>at least</i> a certain
number of years of observations. For example, there are 463 males
and 1,383 females with at least a 5 year observation period.
</p>
<div id="figure1" class=figure>
<!-- I) YEAR OF DIAGNOSIS FOR MULTIPLE SCLEROSIS -->
<script type="text/javascript">
var pL = [
<?php
$periodList = array();
ini_set('auto_detect_line_endings',TRUE);
$handle = fopen('msReportData_ObsYears.txt','r') or die("Unable to open file!");
if($handle){
while ( ($data = fgetcsv($handle, 1000) ) !== FALSE ) {
$x = explode(chr(9), $data[0]);
$ObsYears = $x[0];
$NumPatients = $x[1];
$period = array(
$ObsYears,
$NumPatients
);
array_push($periodList, $period);
}
} else {
echo "Error reading File";
}
fclose($handle);
echo json_encode($periodList);
?>
];
var divWidth = (parseInt($("#figure1").css("width")))
var divBorder = divWidth/20
var graphWidth = divWidth-divBorder
var len = pL[0].length
var buffer = divBorder/2
var barWidth = (graphWidth/len)*0.9
var barBuffer = (graphWidth/len)*0.1
var labelBuffer = graphWidth/400
var verticalTicks = 10
var w = (barWidth+barBuffer)*pL[0].length; // Width to include every entry
var h = 550;
//Get value of div offset
var offsets = $('#figure1').offset();
var topOS1 = offsets.top; //top Offset - labeled so to prevent confusion w/ read-only property of window
var leftOS1 = offsets.left;
//Defining maxHeight - vertical limit of the graph
var maxHeight = d3.max(pL[0], function(d) {
return parseInt(d[1]); // Number of patients
});
var maxYear = d3.max(pL[0], function(d) {
return parseInt(d[0]);
});
var minYear = d3.min(pL[0], function(d) {
return parseInt(d[0]);
});
var svg = d3.select("#figure1")
.append("svg")
.attr({
width: w,
height: h,
});
var yScale = d3.scale.linear()
.domain([0, maxHeight+100])
.range([0, h-buffer]);
var yAxisScale = d3.scale.linear()
.domain([0, maxHeight+100])
.range([h-buffer, 0]);
var xScale = d3.scale.linear()
.domain([minYear-0.5, maxYear+0.5])
.range([divBorder, divWidth-divBorder]);
var xAxisScale = d3.scale.linear()
.domain([minYear-0.5, maxYear+0.5])
.range([divBorder, divWidth-divBorder]);
function make_x_axis() {
return d3.svg.axis()
.scale(xAxisScale)
.orient("bottom")
.ticks(pL[0].length)
}
function make_y_axis() {
return d3.svg.axis()
.scale(yAxisScale)
.orient("left")
.ticks(verticalTicks)
}
svg.append("g")
.attr("class", "grid")
.attr("transform", "translate(0," + (h-buffer) + ")")
.call(make_x_axis()
.tickSize(-h, 0, 0)
.tickFormat("")
)
svg.append("g")
.attr("class", "grid")
.attr("transform", "translate(" + divBorder + ",0)")
.call(make_y_axis()
.tickSize(-w, 0, 0)
.tickFormat("")
)
var convertData = function(x){
var numbers = []
var a
var b
x.forEach(function(d) {
if(!isNaN(parseInt(d[0]))) {
a = parseInt(d[0])
b = parseInt(d[1])
numbers.push([a,b])
//console.log(numbers)
}
})
return numbers
}
var numbers = convertData(pL[0])
var makePoints = function() {
svg.selectAll("circle")
.data(numbers)
.enter()
.append("circle")
.attr({
fill: function(d){
return "blue";
},
r: 5,
cy: function(d){ if(!isNaN(parseInt(d[1]))) {return h-buffer-(yScale(parseInt(d[1])))}},
cx: function(d){
if(!isNaN(parseInt(d[0]))) {
return xScale(parseInt(d[0]))
}
else if(d[0] == "< 1"){
return xScale(0)
}
},
})
//Adding the mouseOver function - Hover to highlight
.on("mouseover", function(d) {
var xPosition = parseFloat(d3.select(this).attr("cx"));
var yPosition = parseFloat(d3.select(this).attr("cy"));
d3.select("#tooltip")
.style("left", (xPosition+leftOS1) + "px")
.style("top", (yPosition+topOS1) + "px")
.select("#value")
.text(d[1]);
d3.select("#tooltip").classed("hidden", false);
})
.on("mouseout", function() {
d3.select("#tooltip").classed("hidden", true);
})
}
makePoints();
var lineGen = d3.svg.line()
.x(function(d) {
return xScale(d[0])
})
.y(function(d) {
return h-buffer-yScale(d[1])
})
.interpolate("linear");
svg.append('svg:path')
.attr('d', lineGen(numbers))
.attr('stroke', 'RGB(130,180,230)')
.attr('stroke-width', 2)
.attr('fill', 'none');
//Interesting Note - this needs to go after making the bars/labels or else the labels will not appear
var yAxis = d3.svg.axis()
.scale(yAxisScale)
.orient("left")
.tickPadding(5)
.ticks(verticalTicks);
var xAxis = d3.svg.axis()
.scale(xAxisScale)
.tickPadding(5)
.tickFormat(d3.format("d")) // removes comma
.ticks(pL[0].length)
.orient("bottom")
svg.append("g")
.attr("class", "axis")
.attr("transform", "translate(" + (divBorder) + ",0)")
.call(yAxis);
svg.append("g")
.attr("class", "axis")
.attr("transform", "translate(" + 0 + ", " + (h-buffer) + ")")
.call(xAxis);
</script>
</div>
</div>
<div class="section">
<h2>Year of First Diagnosis</h2>
<p>
The <i>First Diagnosis</i> is the first record we have of the patient being diagnosed
with Multiple Sclerosis. Note that the patient may have been diagnosed at another clinic
or hospital before coming to NYP/CUMC. This date is the first diagnosis date at NYP/CUMC.
Note, years with 5 or fewer patients have been removed to preserve privacy.
</p>
<div id=figure2 class="figure">
<script type="text/javascript">
var pL = [
<?php
$dXList = array();
ini_set('auto_detect_line_endings',TRUE);
$handle = fopen('msReportData_DXbyYear.txt','r') or die("Unable to open file!");
if($handle){
while ( ($data = fgetcsv($handle, 1000) ) !== FALSE ) {
$x = explode(chr(9), $data[0]);
$Year = $x[0];
$NumDiagnoses = $x[1];
$dXYear = array(
$Year,
$NumDiagnoses
);
array_push($dXList, $dXYear);
}
} else {
echo "Error reading File";
}
fclose($handle);
echo json_encode($dXList);
?>
];
var divWidth = (parseInt($("#figure2").css("width")))
var divBorder = divWidth/20
var graphWidth = divWidth-divBorder
var len = pL[0].length
var buffer = divBorder/2
var barWidth = (graphWidth/len)*0.9
var barBuffer = (graphWidth/len)*0.1
var labelBuffer = graphWidth/400
var w = (barWidth+barBuffer)*pL[0].length; // Width to include every entry
var h = 550;
var verticalTicks = 15
//Get value of div offset
var offsets = $('#figure2').offset();
var topOS2 = offsets.top; //top Offset - labeled so to prevent confusion w/ read-only property of window
var leftOS2 = offsets.left;
//Defining maxHeight - vertical limit of the graph
var maxHeight = d3.max(pL[0], function(d) {
return parseInt(d[1]); // Number of patients
});
var maxYear = d3.max(pL[0], function(d) {
return parseInt(d[0]);
});
var minYear = d3.min(pL[0], function(d) {
return parseInt(d[0]);
});
var yScale = d3.scale.linear()
.domain([0, maxHeight+labelBuffer])
.range([0, h-buffer]);
var yAxisScale = d3.scale.linear()
.domain([0, maxHeight+labelBuffer])
.range([h-buffer, 0]);
var xScale = d3.scale.linear()
.domain([minYear-1, maxYear+0.5]) //+1 to include room for last bar
.range([divBorder, divWidth-divBorder]);
var xAxisScale = d3.scale.linear()
.domain([minYear-1, maxYear+0.5]) //+1 to include room for last bar
.range([divBorder, divWidth-divBorder]);
var svg = d3.select("#figure2")
.append("svg")
.attr({
width: w,
height: h,
});
var convertData = function(x){
var numbers = []
var a
var b
x.forEach(function(d) {
if(!isNaN(parseInt(d[0]))) {
a = parseInt(d[0])
b = parseInt(d[1])
numbers.push([a,b])
//console.log(numbers)
}
})
return numbers
}
var numbers = convertData(pL[0])
var makePoints = function() {
svg.selectAll("circle")
.data(numbers)
.enter()
.append("circle")
.attr({
fill: function(d){
return "blue";
},
r: 5,
cy: function(d){ if(!isNaN(parseInt(d[1]))) {return h-buffer-(yScale(parseInt(d[1])))}},
cx: function(d){
if(!isNaN(parseInt(d[0]))) {
return xScale(parseInt(d[0]))
}
else if(d[0] == "< 1"){
return xScale(0)
}
},
})
}
makePoints();
var lineGen = d3.svg.line()
.x(function(d) {
return xScale(d[0])
})
.y(function(d) {
return h-buffer-yScale(d[1])
})
.interpolate("linear");
svg.append('svg:path')
.attr('d', lineGen(numbers))
.attr('stroke', 'RGB(130,180,230)')
.attr('stroke-width', 2)
.attr('fill', 'none');
//ADDING Grid Lines
var gridScale = d3.scale.linear()
.domain([0, 15])
.range([divBorder, divWidth-divBorder]);
function make_x_axis() {
return d3.svg.axis()
.scale(xAxisScale)
.orient("bottom")
.ticks(pL[0].length)
}
function make_y_axis() {
return d3.svg.axis()
.scale(yAxisScale)
.orient("left")
.ticks(verticalTicks)
}
svg.append("g")
.attr("class", "grid")
.attr("transform", "translate(0," + (h-buffer) + ")")
.call(make_x_axis()
.tickSize(-h, 0, 0)
.tickFormat("")
)
svg.append("g")
.attr("class", "grid")
.attr("transform", "translate(" + divBorder + ",0)")
.call(make_y_axis()
.tickSize(-w, 0, 0)
.tickFormat("")
)
//Interesting Note - this needs to go after making the bars/labels or else the labels will not appear
var yAxis = d3.svg.axis()
.scale(yAxisScale)
.orient("left")
.tickPadding(5)
.ticks(verticalTicks);
var xAxis = d3.svg.axis()
.scale(xAxisScale)
.tickPadding(5)
.tickFormat(d3.format("d")) // removes comma
.ticks(pL[0].length)
.orient("bottom")
svg.append("g")
.attr("class", "axis")
.attr("transform", "translate(" + (divBorder) + ",0)")
.call(yAxis);
svg.append("g")
.attr("class", "axis")
.attr("transform", "translate(" + 0 + ", " + (h-buffer) + ")")
.call(xAxis);
</script>
</div>
</div>
<div class="section">
<h2>Age First Diagnosis</h2>
<p>
The age of the patients at the time they were <i>first diagnosed</i> with Multiple Sclerosis
at NYP/CUMC. Note,
ages with 5 or fewer patients have been removed to preserve privacy.
</p>
<div id="figure3" class="figure">
<script type="text/javascript">
var pL = [
<?php
$patientList = array();
ini_set('auto_detect_line_endings',TRUE);
$handle = fopen('msReportData_DXbyAge.txt','r') or die("Unable to open file!");
if($handle){
while ( ($data = fgetcsv($handle, 1000) ) !== FALSE ) {
$x = explode(chr(9), $data[0]);
$Age = $x[0];
$NumPatients = $x[1];
$patient = array(
$Age,
$NumPatients
);
array_push($patientList, $patient);
}
} else {
echo "Error reading File";
}
fclose($handle);
echo json_encode($patientList);
?>
];
var divWidth = (parseInt($("#figure3").css("width")))
var divBorder = divWidth/20
var graphWidth = divWidth-divBorder
var len = pL[0].length
var buffer = divBorder/2
var barWidth = (graphWidth/len)*0.9
var barBuffer = (graphWidth/len)*0.1
var labelBuffer = graphWidth/400
var w = (barWidth+barBuffer)*pL[0].length;
var h = 550;
var ver
//Get value of div offset
var offsets = $('#figure3').offset();
var topOS3 = offsets.top; //top Offset - labeled so to prevent confusion w/ read-only property of window
var leftOS3 = offsets.left;
//Defining maxHeight - vertical limit of the graph
var maxHeight = d3.max(pL[0], function(d) {return parseInt(d[1]);});
var maxAge = d3.max(pL[0], function(d) {return parseInt(d[0]);});
var minAge = d3.min(pL[0], function(d) {return parseInt(d[0]);});
var yScale = d3.scale.linear()
.domain([0, maxHeight+(maxHeight/10)])
.range([0, h-buffer]);
var yAxisScale = d3.scale.linear()
.domain([0, maxHeight+(maxHeight/10)])
.range([h-buffer, 0]);
var xScale = d3.scale.linear()
.domain([minAge-1, maxAge+1]) // +1 to include room for last bar
.range([divBorder, divWidth-divBorder]);
var xAxisScale = d3.scale.linear()
.domain([minAge-1, maxAge+1]) // +1 to include room for last bar
.range([divBorder, divWidth-divBorder]);
var svg = d3.select("#figure3")
.append("svg")
.attr({
width: w,
height: h,
});
//ADDING Grid Lines
var gridScale = d3.scale.linear()
.domain([0, 15])
.range([divBorder, divWidth-divBorder]);
function make_x_axis() {
return d3.svg.axis()
.scale(xAxisScale)
.orient("bottom")
.ticks(pL[0].length)
}
function make_y_axis() {
return d3.svg.axis()
.scale(yAxisScale)
.orient("left")
.ticks(5)
}
svg.append("g")
.attr("class", "grid")
.attr("transform", "translate(0," + (h-buffer) + ")")
.call(make_x_axis()
.tickSize(-h, 0, 0)
.tickFormat("")
)
svg.append("g")
.attr("class", "grid")
.attr("transform", "translate(" + divBorder + ",0)")
.call(make_y_axis()
.tickSize(-w, 0, 0)
.tickFormat("")
)
var convertData = function(x){
var numbers = []
var a
var b
x.forEach(function(d) {
if(!isNaN(parseInt(d[0]))) {
a = parseInt(d[0])
b = parseInt(d[1])
numbers.push([a,b])
//console.log(numbers)
}
})
return numbers
}
var numbers = convertData(pL[0])
var makePoints = function() {
svg.selectAll("circle")
.data(numbers)
.enter()
.append("circle")
.attr({
fill: function(d){
return "blue";
},
r: 5,
cy: function(d){ if(!isNaN(parseInt(d[1]))) {return h-buffer-(yScale(parseInt(d[1])))}},
cx: function(d){
if(!isNaN(parseInt(d[0]))) {
return xScale(parseInt(d[0]))
}
else if(d[0] == "< 1"){
return xScale(0)
}
},
})
}
makePoints();
var lineGen = d3.svg.line()
.x(function(d) {
return xScale(d[0])
})
.y(function(d) {
return h-buffer-yScale(d[1])
})
.interpolate("linear");
svg.append('svg:path')
.attr('d', lineGen(numbers))
.attr('stroke', 'RGB(130,180,230)')
.attr('stroke-width', 2)
.attr('fill', 'none');
//Function to make Bars
var makeBars = function() {
svg.selectAll("rect")
.data(pL[0])
.enter()
.append("rect")
.attr({
width: barWidth,
height: function(d) {
return (yScale(parseInt(d[1])))
},
fill: function(d){
return "rgb(10, 100, 100)";
},
y: function(d){return h-buffer-(yScale(parseInt(d[1])))},
x: function(d) {return (xScale(parseInt(d[0])))},
})
//Adding the mouseOver function - Hover to highlight
.on("mouseover", function(d) {
var xPosition = parseFloat(d3.select(this).attr("x"));
var yPosition = parseFloat(d3.select(this).attr("y"));
d3.select("#tooltip")
.style("left", (xPosition+leftOS3) + "px")
.style("top", (yPosition+topOS3) + "px")
.select("#value")
.text(d[1]);
d3.select("#tooltip").classed("hidden", false);
})
.on("mouseout", function() {
d3.select("#tooltip").classed("hidden", true);
})
}
//makeBars();
var yAxis = d3.svg.axis()
.scale(yAxisScale)
.orient("left")
.tickPadding(5)
.ticks(15);
var xAxis = d3.svg.axis()
.scale(xAxisScale)
.tickPadding(5)
.tickFormat(d3.format("d")) // removes comma
.ticks(pL[0].length/10)
.orient("bottom")
svg.append("g")
.attr("class", "axis")
.attr("transform", "translate(" + (divBorder) + ",0)")
.call(yAxis);
svg.append("g")
.attr("class", "axis")
.attr("transform", "translate(" + 0 + ", " + (h-buffer) + ")")
.call(xAxis);
</script>
</div>
</div>
<div class="section">
<h2>Top 10 Prescriptions</h2>
<p>
These are the top 10 prescriptions following the diagnosis of Multiple Sclerosis
and within a certain time inteval. At
this time these are not normalized for the frequency of use for the prescriptions so
many of the top ranked drugs are simply the most commonly used medications.
</p>
<div id="figure4" class="figure">
<script type="text/javascript">
var dL = [
<?php
$dXList = array();
ini_set('auto_detect_line_endings',TRUE);
$handle = fopen('msReportData_commonDiseases.txt','r') or die("Unable to open file!");
if($handle){
while ( ($data = fgetcsv($handle, 1000) ) !== FALSE ) {
$x = explode(chr(9), $data[0]);
$code = $x[0];
$drugName = $x[1];
$numOfPatients = $x[2];
$dX = array(
$code,
$drugName,
$numOfPatients
);
array_push($dXList, $dX);
}
} else {
echo "Error reading File";
}
fclose($handle);
echo json_encode($dXList);
?>
];
var divWidth = (parseInt($("#figure4").css("width")))
var divBorder = divWidth/20
var graphWidth = divWidth-divBorder
var len = pL[0].length
var margin = divWidth/100 // 1%
var labelMargin = 20
var textSpace = divWidth/7 // 14%
var barSpace = divWidth/6 // 17% --- Last section expected to be smaller
var sectionSize = margin+textSpace+barSpace
var barHeight = 15
var barMargin = 10
var h = (barHeight+barMargin)*dL[0].length/3
var verticalMargin = h/10
var maxWidth = d3.max(dL[0], function(d) {
if (!isNaN(parseInt(d[2]))){
return parseInt(d[2]); // Number of patients
}
});
//Get value of div offset
var offsets = $('#figure4').offset();
var topOS4 = offsets.top; //top Offset - labeled so to prevent confusion w/ read-only property of window
var leftOS4 = offsets.left;
var yScale = d3.scale.linear()
.domain([0, 12])
.range([labelMargin, h-labelMargin]);
var xScale = d3.scale.linear()
.domain([0, maxWidth])
.range([0, barSpace]);
var svg = d3.select("#figure4")
.append("svg")
.attr({
width: w,
height: h,
});
//Function to make Bars
var makeBars = function() {
svg.selectAll("rect")
.data(dL[0])
.enter()
.append("rect")
.attr({
width: function(d) {
if(!isNaN(parseInt(d[2]))){
return (xScale(parseInt(d[2])));
}
},
height: barHeight,
fill: function(d){
return "rgb(130, 180, 230)";
},
y: function(d, j) {return (yScale(j%12))}, // Adjust input for proper spacing
x: function(d) {
if (dL[0].indexOf(d) < 12){
return margin+textSpace;
}
else if (dL[0].indexOf(d) < 24){
return sectionSize + margin+textSpace;
}
else{return sectionSize*2 + margin+textSpace}
}
})
//Adding the mouseOver function - Hover to highlight
.on("mouseover", function(d) {
var xPosition = parseFloat(d3.select(this).attr("x"));//+parseFloat(d3.select(this).attr("width"));
var yPosition = parseFloat(d3.select(this).attr("y")); // Correcting Value
d3.select("#tooltip")
.style("left", (xPosition+leftOS4) + "px")
.style("top", (yPosition+topOS4) + "px")
.select("#value")
.text(d[2]);
d3.select("#tooltip").classed("hidden", false);
})
.on("mouseout", function() {
d3.select("#tooltip").classed("hidden", true);
})
}
//Function to makeLabels
var makeLabels = function() {
svg.selectAll("text")
.data(dL[0])
.enter()
.append("text")
.text(function(d) {
if (d[1] == ""){
return d[0]
}
else if (d[1] == "disease name"){
return ""
}
else{return d[1]}
})
.attr({
y: function(d, j) {
if (d[1] == ""){
return yScale(0)
}
else{return yScale(j%12+0.75)}
},
x: function(d) {
if (d[1] == ""){
if (dL[0].indexOf(d) == 0 ){
return margin*3;
}
else if (dL[0].indexOf(d) == 12){
return sectionSize + margin;
}
else{ return (sectionSize*2) + margin}
}
else{
if (dL[0].indexOf(d) < 12){
return margin;
}
else if (dL[0].indexOf(d) < 24){
return sectionSize + margin;
}
else{ return sectionSize*2 + margin}
}
},
"font-size": function(d) {
if (d[1] == ""){
return 17;
}
else{
return 10;
}
},
"font-family": "sans-serif",
fill: "black",
})
}
makeLabels();
//MAKING THE GRID LINES
//Creates vertical gridlines
function make_x_axis() {
return d3.svg.axis()
.scale(xScale)
.orient("bottom")
.ticks(pL[0].length/5)
}
//Creates horizontal gridlines
function make_y_axis() {
return d3.svg.axis()
.scale(yScale)
.orient("left")
.ticks(5)
}
//VERTICAL
svg.append("g")
.attr("class", "grid")
.attr("transform", "translate(" + (margin+textSpace) + ", " + (h-verticalMargin/2) + ")")
.call(make_x_axis()
.tickSize(-h+verticalMargin+margin, 0, 0)
.tickFormat("")
)
//VERTICAL
svg.append("g")
.attr("class", "grid")
.attr("transform", "translate(" + (margin+textSpace+sectionSize) + ", " + (h-verticalMargin/2) + ")")
.call(make_x_axis()
.tickSize(-h+verticalMargin+margin, 0, 0)
.tickFormat("")
)
//VERTICAL
svg.append("g")
.attr("class", "grid")
.attr("transform", "translate(" + (margin+textSpace+sectionSize*2) + ", " + (h-verticalMargin/2) + ")")
.call(make_x_axis()
.tickSize(-h+verticalMargin+margin, 0, 0)
.tickFormat("")
)
/*
//HORIZONTAL
svg.append("g")
.attr("class", "grid")
.attr("transform", "translate(" + (margin+textSpace) + ",0)")
.call(make_y_axis()
.tickSize(-sectionSize+margin+textSpace, 0, 0)
.tickFormat("")
)
*/
makeBars();
//Adding Axes
var yAxisScale = d3.scale.linear()
.domain([0, maxHeight])
.range([verticalMargin, h-verticalMargin]);
var xAxisScale = d3.scale.linear()
.domain([0, maxWidth]) // +1 to include room for last bar
.range([0, barSpace]);
var yAxis1 = d3.svg.axis()
.scale(yAxisScale)
.orient("left")
.tickPadding(5)
.ticks(0);
var xAxis1 = d3.svg.axis()
.scale(xAxisScale)
.tickPadding(0)
.tickFormat(d3.format("d")) // removes comma
.ticks(dL[0].length/10)
.orient("bottom")
var yAxis2 = d3.svg.axis()
.scale(yAxisScale)
.orient("left")
.tickPadding(5)
.ticks(0);
var xAxis2 = d3.svg.axis()
.scale(xAxisScale)
.tickPadding(0)
.tickFormat(d3.format("d")) // removes comma
.ticks(dL[0].length/10)
.orient("bottom")
var yAxis3 = d3.svg.axis()
.scale(yAxisScale)
.orient("left")
.tickPadding(5)
.ticks(0);
var xAxis3 = d3.svg.axis()
.scale(xAxisScale)
.tickPadding(0)
.tickFormat(d3.format("d")) // removes comma