-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathdcPlot.js
159 lines (135 loc) · 3.78 KB
/
dcPlot.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
console.log('loading dcPlot.js ...')
confluence={
coreData:[]
}
fetch('dt.json').then(x=>x.json().then(dt=>{
Object.keys(dt).forEach(k=>{
dt
kk=Object.keys(dt[k].tab)
dt[k].tab.study.map((s,i)=>{
let r={} // row as an object
kk.forEach(ki=>{
r[ki]=dt[k].tab[ki][i]
})
r.ageInt=parseInt(r.ageInt)
confluence.coreData.push(r)
})
})
// reduce reset
// DC starts here
let dd = confluence.coreData
valUnique=function(k,v){
var u={}
dd.forEach(d=>{
u[d[k]]=v
})
return u
}
dc.config.defaultColors(d3.schemeCategory10)
let cf=crossfilter(dd)
// Status Pie Chard
C_pieStatus = dc.pieChart("#pieStatus");
let status = cf.dimension(function(d){return d.status});
status_reduce=valUnique('status',0)
count_study=valUnique('study',0)
let G_status = status.group().reduce(
// reduce in
function(p,v){
count_study[v.study]+=1
status_reduce[v.status]+=1
return status_reduce[v.status]
},
//reduce out
function(p,v){
count_study[v.study]-=1
status_reduce[v.status]-=1
return status_reduce[v.status]
},
// ini
function(p){return 0}
)
//let G_status = status.group().reduceCount()
C_pieStatus
.width(350)
.height(200)
.radius(200)
.innerRadius(60)
.dimension(status)
.group(G_status)
.label(function(c){
return `status=${c.key} (${c.value})`
})
//.colors(d3.scaleLinear().domain([-4,3,4]).range(['blue','cyan','gray']))
.colors(d3.scaleOrdinal().domain(['0','1','2','3','4']).range(['#009688','orange','green','red','gray']))
.colorAccessor(function(c,i){
if(count_status[c.key]>0){
return i
}else{
return 4
}
})
// Study braChard
let C_rowStudy = dc.rowChart("#rowStudy");
let study = cf.dimension(function(d){return d.study});
//let G_study = study.group().reduceCount()
study_reduce=valUnique('study',0)
count_status=valUnique('status',0)
let G_study = study.group().reduce(
// reduce in
function(p,v){
count_status[v.status]+=1
study_reduce[v.study]+=1
return study_reduce[v.study]
},
//reduce out
function(p,v){
count_status[v.status]-=1
study_reduce[v.study]-=1
return study_reduce[v.study]
},
// ini
function(p){return 0}
)
//clickStatus = valUnique('status',true)
C_rowStudy
.width(450)
.height(200)
.dimension(study)
.group(G_study)
.elasticX(true)
.colors(d3.scaleLinear().domain([-4,3,4]).range(['blue','cyan','gray']))
.colorAccessor(function(c,i){
//console.log(i)
if(count_study[c.key]>0){
return i
}else{
return 4
}
//debugger
})
.ordering(c=>-dt[c.key].tab.study.length)
.label(function(c){
return `${c.key} (${c.value})`
})
//.yAxisLabel('count')
//
let C_barAge = dc.barChart("#barAge");
let age = cf.dimension(function(d){return d.ageInt});
let G_age = age.group().reduceCount()
C_barAge
.width(500)
.height(500)
.dimension(age)
.group(G_age)
.x(d3.scaleLinear().domain([20,100]))
.elasticY(true)
.xAxisLabel('age')
.yAxisLabel('count')
dc.renderAll();
C_pieStatus.render()
CC={
C_pieStatus:C_pieStatus,
C_rowStudy:C_rowStudy,
C_barAge:C_barAge
}
}))