-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathHHOW-Visualizer.js
201 lines (185 loc) · 7.7 KB
/
HHOW-Visualizer.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
String.prototype.trunc =
function(n){
return this.substr(0,n-1)+(this.length>n?'…':'');
};
function remove_empty_bins(source_group) {
return {
all: function () {
return source_group.all().filter(function (d) {
return d.value != 0;
});
}
};
}
var displayDateFormat = d3.time.format("%m/%d/%Y");
var filename = "SpecimenStats.csv";
d3.csv(filename, function (error, data) {
if (error) {
var msg = "Could not read " + filename;
console.log(msg);
alert(msg);
return;
}
data.forEach(function (d) {
var number = d.SpecimenCount.match(/\d+$/);
d.SpecimenCount = parseInt(number, 10);
});
var ndx = crossfilter(data);
var all = ndx.groupAll();
var protocolCategoryDimension = ndx.dimension(function (d) { return d.ProtocolCategory; });
var protocolCategoryGroup = protocolCategoryDimension.group().reduceSum(function (d) { return d.SpecimenCount; });
var protocolCategoryChart = dc.pieChart('#protocol-category')
.dimension(protocolCategoryDimension)
.group(protocolCategoryGroup)
.width(600) // (optional) define chart width, :default = 200
.height(350) // (optional) define chart height, :default = 200
.radius(150)
.innerRadius(100)
.legend(dc.legend().x(0).y(0))//.gap(5))
.cx(400)
//.label(null)
.minAngleForLabel(100);
var protocolStatusDimension = ndx.dimension(function (d) { return d.CollectionProtocolStatus; });
var protocolStatusGroup = protocolStatusDimension.group().reduceSum(function (d) { return d.SpecimenCount; });
var protocolStatusChart = dc.pieChart('#protocol-status')
.dimension(protocolStatusDimension)
.group(protocolStatusGroup)
.width(300) // (optional) define chart width, :default = 200
.height(200) // (optional) define chart height, :default = 200
.radius(50)
.cx(200)
.cy(50)
.legend(dc.legend().x(0).y(0))//.gap(5))
//.innerRadius(50)
.minAngleForLabel(100);
var protocolDimension = ndx.dimension(function (d) { return d.CtepStudyID; });
var protocolGroup = protocolDimension.group().reduceSum(function (d) { return d.SpecimenCount; });
/*
var protocolChart = dc.bubbleCloud('#protocols')
.dimension(protocolDimension)
.group(protocolGroup)
.width(300)
.height(300) // (optional) define chart height, :default = 200
//.x(d3.scale.ordinal().domain([0,150000]))
.x(d3.scale.ordinal())
.r(d3.scale.linear().domain([0, 150000]))
.maxBubbleRelativeSize(0.1)
.radiusValueAccessor(function (d) {
return d.value; // 1; // d.value; // 0.5; //d.SpecimenCount;
});
*/
var protocolGroup2 = remove_empty_bins(protocolGroup);
/*
var protocolChart2 = dc.rowChart('#protocols2')
.dimension(protocolDimension)
.group(protocolGroup2)
.width(700)
.height(700)
.elasticX(true);
*/
var protocolChart3 = dc.barChart('#protocols3')
.dimension(protocolDimension)
.group(protocolGroup2)
.width(1100)
.height(400)
.elasticY(true)
.elasticX(true)
.x(d3.scale.ordinal())
.xUnits(dc.units.ordinal)
.brushOn(false)
.margins({top:0, bottom:70, left:60, right:0})
.yAxisLabel("# Specimens")
.barPadding(0.1)
.outerPadding(0.05)
.renderlet(function (chart) {
chart.selectAll("g.x text")
.attr('dx', '-30')
.attr('dy', '-7')
.attr('transform', "rotate(-90)");
});
var specimenBiophysicalType = ndx.dimension(function (d) { return d.specimenBiophysicalType; });
var specimenBiophysicalTypeGroup = specimenBiophysicalType.group().reduceSum(function (d) { return d.SpecimenCount; });
var specimenBiophysicalTypeChart = dc.pieChart('#specimen-biophysical-type')
.dimension(specimenBiophysicalType)
.group(specimenBiophysicalTypeGroup)
/*
.width(300) // (optional) define chart width, :default = 200
.height(300) // (optional) define chart height, :default = 200
.radius(150)
.innerRadius(20);
*/
.width(300) // (optional) define chart width, :default = 200
.height(200) // (optional) define chart height, :default = 200
.radius(50)
.cx(200)
.cy(50)
.legend(dc.legend().x(0).y(0))//.gap(5))
//.innerRadius(50)
.minAngleForLabel(100);
var diseaseStatus = ndx.dimension(function (d) { return d.diseaseStatus; });
var diseaseStatuseGroup = diseaseStatus.group().reduceSum(function (d) { return d.SpecimenCount; });
var diseaseStatusChart = dc.pieChart('#disease-status')
.dimension(diseaseStatus)
.group(diseaseStatuseGroup)
.width(300) // (optional) define chart width, :default = 200
.height(200) // (optional) define chart height, :default = 200
.radius(50)
.cx(200)
.cy(50)
.legend(dc.legend().x(0).y(0))//.gap(5))
//.innerRadius(50)
.minAngleForLabel(100);
dc.dataCount('.dc-data-count')
.dimension(ndx)
.group(all);
var specimenCountGroup = ndx.groupAll().reduceSum(function (p) { return p.SpecimenCount; });
var specimenCountND = dc.numberDisplay(".candidate-specimens-counter")
.formatNumber(d3.format(".g"))
.valueAccessor(function (p) { return p; })
.group(specimenCountGroup)
.transitionDuration(0);
var totalSpecimenCount = specimenCountGroup.value();
var specimenCountND = dc.numberDisplay(".total-specimens-counter")
.formatNumber(d3.format(".g"))
.valueAccessor(function (p) { return totalSpecimenCount; })
.group(specimenCountGroup)
.transitionDuration(0);
/*
http://getbootstrap.com/examples/theme/#
http://www.codeproject.com/Articles/693841/Making-Dashboards-with-Dc-js-Part-1-Using-Crossfil
file:///C:/TDE/GitHub/hhow-datavis-prototype/HHOW-Visualizer.html
https://becomingadatascientist.wordpress.com/tag/dc-js/
http://paletton.com/#uid=72G0u0kfDpf6bEGaJuhkgkIphfP
http://stackoverflow.com/questions/27789872/display-the-number-of-distinct-items-with-data-count-widget
*/
var specimenStatsGrid = dc.dataTable('#specimen-stats-grid')
.width(960)
.height(800)
.dimension(protocolDimension)
.group(function (d) { return "(Candidate Subset)" })
.size(20) // (optional) max number of records to be shown, :default = 25
.columns([
function (d) { return d.CtepStudyID; },
function (d) { return d.CollectionProtocolStatus; },
function (d) { return d.ProtocolCategory; },
function (d) { return d.specimenBiophysicalType; },
function (d) { return d.preservationType; },
function (d) { return d.fmaAnatomicSourceLocation; },
function (d) { return d.pathologicalStatus; },
function (d) { return d.diseaseStatus; },
function (d) { return d.SpecimenCount; }
])
.sortBy(function (d) { return d.CtepStudyID; });
$(document).ready(function () {
// Render all charts
dc.filterAll();
dc.renderAll();
});
});
function print_filter(filter) {
var f = eval(filter);
if (typeof (f.length) != "undefined") { } else { }
if (typeof (f.top) != "undefined") { f = f.top(Infinity); } else { }
if (typeof (f.dimension) != "undefined") { f = f.dimension(function (d) { return ""; }).top(Infinity); } else { }
console.log(filter + "(" + f.length + ") = " + JSON.stringify(f).replace("[", "[\n\t").replace(/}\,/g, "},\n\t").replace("]", "\n]"));
}