-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathhist.html
More file actions
379 lines (315 loc) · 16.7 KB
/
hist.html
File metadata and controls
379 lines (315 loc) · 16.7 KB
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
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<script src="https://d3js.org/d3-array.v2.min.js"></script>
<script type="text/javascript", src="./js/d3/d3.js"></script>
<style>
.plotbutton{
background-color: #4CAF50
}
</style>
</head>
<body>
<h2>Histogram chart for LSST OpSims</h2>
<p>Click line to highlight, double click to cancel. Click the legend dots to select families. Mouseover legend text to preview. Mouseleave legend text to clear selections.</p>
<div class="slider item">
<div id="selected_nbins">number of bins </div>
<div><span class="low">10</span>
<input type="range" id='nbins_slider' name="scale" min="10" max="100" step='1' value="50">
<span>100</span></div>
</div>
<button class="button" onclick = "update()">Update</button>
<table>
<tr>
<th> <div id="hist"></div> </th>
<th> <div id="rank"></div> </th>
</tr>
<tr>
<th> <div id="skymap"></div></th>
</tr>>
</table>
<script type="text/javascript">
var width = 900
var height = 800
var margin = {top: 70, right: 70, bottom: 70, left: 70},
w = width - margin.left - margin.right,
h = height - margin.top - margin.bottom;
var centerXPos = w / 2 + margin.left;
var centerYPos = h / 2 + margin.top;
var svg = d3.select("#hist").append("svg")
.attr("width", w + margin.left + margin.right)
.attr("height", h + margin.top + margin.bottom)
.style("background-color", "#f7f7f7f7")
.append("g")
.attr("transform", "translate(" + margin.left +", "+ margin.top +")")
// add axis label
svg.append("text").attr("text-anchor", "end")
.attr("x", width/2)
.attr("y", height-margin.bottom-20)
.text("recovery rate")
svg.append("text").attr("text-anchor", "center")
.attr("transform", "rotate(-90)")
.attr("y", -margin.left + 20)
.attr("x", margin.top - height/2 + 20)
.text("N (healpix nside=16)")
svg.append("text").attr("text-anchor", "end")
.attr("transform", "rotate(-90)")
.attr("y", -margin.left + width - 20) // actual x because of rotation
.attr("x", margin.top - height/2 + 50)
.text("N cumulative")
var svg2 = d3.select("#rank").append("svg")
.attr("width", 400 + margin.left + margin.right)
.attr("height", h + margin.top + margin.bottom)
.style("background-color", "#f7f7f7f7")
.append("g")
.attr("transform", "translate(" + margin.left +", "+ margin.top +")")
//var color = d3.scale.category10(); // use in d3.v3
//var color = d3.scaleOrdinal(d3.schemeCategory10) // in > d3.v4
//families = [ '#a6cee3', '#1f78b4', '#b2df8a', '#33a02c', '#fb9a99', '#e31a1c', '#fdbf6f', '#ff7f00', '#cab2d6', '#6a3d9a', '#ffff99', '#b15928', '#004301', '#5e0022', '#ed00d7', '#00008f', '#626d60', '#9978ff', '#5b3600', '#00a799']
//families = ['#a6cee3','#1f78b4','#1f78b4','#b2df8a','#b2df8a','#b2df8a','#33a02c','#33a02c','#33a02c','#33a02c','#33a02c','#33a02c','#fb9a99','#e31a1c','#e31a1c','#e31a1c','#e31a1c','#e31a1c','#e31a1c','#fdbf6f','#ff7f00','#ff7f00','#ff7f00','#ff7f00','#ff7f00','#ff7f00','#ff7f00','#ff7f00','#cab2d6','#cab2d6','#cab2d6','#cab2d6','#cab2d6','#cab2d6','#cab2d6','#cab2d6','#cab2d6','#cab2d6','#cab2d6','#cab2d6','#6a3d9a','#6a3d9a','#6a3d9a','#6a3d9a','#6a3d9a','#ffff99','#b15928','#004301','#004301','#004301','#004301','#004301','#004301','#5e0022','#5e0022','#5e0022','#5e0022','#ed00d7','#00008f','#00008f','#00008f','#00008f','#00008f','#00008f','#626d60','#626d60','#626d60','#626d60','#9978ff','#5b3600','#00a799','#00a799','#00a799','#00a799','#00a799','#00a799','#00a799','#00a799','#00a799','#00a799','#00a799','#00a799','#00a799','#00a799','#00a799','#00a799']
families = ['#a6cee3','#1f78b4','#1f78b4','#b2df8a','#b2df8a','#b2df8a','#33a02c','#33a02c','#33a02c','#33a02c','#33a02c','#33a02c','#fb9a99','#e31a1c','#e31a1c','#e31a1c','#e31a1c','#e31a1c','#e31a1c','#fdbf6f','#ff7f00','#ff7f00','#ff7f00','#ff7f00','#ff7f00','#ff7f00','#ff7f00','#ff7f00','#cab2d6','#cab2d6','#cab2d6','#cab2d6','#cab2d6','#cab2d6','#cab2d6','#cab2d6','#cab2d6','#cab2d6','#cab2d6','#cab2d6','#6a3d9a','#6a3d9a','#6a3d9a','#6a3d9a','#6a3d9a','#ffff99','#004301','#004301','#004301','#004301','#004301','#004301','#5e0022','#5e0022','#5e0022','#5e0022','#ed00d7','#00008f','#00008f','#00008f','#00008f','#00008f','#00008f','#626d60','#626d60','#626d60','#626d60','#9978ff','#5b3600','#00a799','#00a799','#00a799','#00a799','#00a799','#00a799','#00a799','#00a799','#00a799','#00a799','#00a799','#00a799','#00a799','#00a799','#00a799','#00a799','#b2df8a','#b2df8a','#1F87A7','#1F87A7','#1F87A7','#1F87A7','#1F87A7','#1F87A7','#2A0319','#2A0319','#2A0319','#2A0319','#2A0319','#2A0319','#2A0319','#2A0319','#46982C','#46982C','#46982C','#46982C','#46982C','#cab2d6','#cab2d6','#cab2d6','#cab2d6','#cab2d6','#cab2d6','#cab2d6','#cab2d6','#cab2d6','#933379','#933379','#933379','#933379','#933379','#004301','#004301','#004301','#004301','#004301','#004301','#004301','#004301','#004301','#004301','#004301','#004301','#004301','#004301','#004301','#004301','#004301','#004301','#004301','#004301','#004301','#004301','#004301','#004301','#626d60','#626d60','#626d60','#626d60','#626d60','#626d60','#626d60','#626d60','#626d60','#626d60','#626d60','#9978ff','#9978ff','#9978ff','#9978ff']
//var variables = ["variable 1", "variable 2"]
var variables = ['agnddf_v1_5_10yrs', 'alt_dust_v1_5_10yrs', 'alt_roll_mod2_dust_sdf_0_20_v1_5_10yrs', 'baseline_2snaps_v1_5_10yrs',
'baseline_samefilt_v1_5_10yrs', 'baseline_v1_5_10yrs', 'bulges_bs_v1_5_10yrs', 'bulges_bulge_wfd_v1_5_10yrs',
'bulges_cadence_bs_v1_5_10yrs', 'bulges_cadence_bulge_wfd_v1_5_10yrs', 'bulges_cadence_i_heavy_v1_5_10yrs',
'bulges_i_heavy_v1_5_10yrs', 'daily_ddf_v1_5_10yrs', 'dcr_nham1_ug_v1_5_10yrs', 'dcr_nham1_ugr_v1_5_10yrs',
'dcr_nham1_ugri_v1_5_10yrs',
'dcr_nham2_ug_v1_5_10yrs',
'dcr_nham2_ugr_v1_5_10yrs',
'dcr_nham2_ugri_v1_5_10yrs',
'descddf_v1_5_10yrs',
'filterdist_indx1_v1_5_10yrs',
'filterdist_indx2_v1_5_10yrs',
'filterdist_indx3_v1_5_10yrs',
'filterdist_indx4_v1_5_10yrs',
'filterdist_indx5_v1_5_10yrs',
'filterdist_indx6_v1_5_10yrs',
'filterdist_indx7_v1_5_10yrs',
'filterdist_indx8_v1_5_10yrs',
'footprint_add_mag_cloudsv1_5_10yrs',
'footprint_big_sky_dustv1_5_10yrs',
'footprint_big_sky_nouiyv1_5_10yrs',
'footprint_big_skyv1_5_10yrs',
'footprint_big_wfdv1_5_10yrs',
'footprint_bluer_footprintv1_5_10yrs',
'footprint_gp_smoothv1_5_10yrs',
'footprint_newAv1_5_10yrs',
'footprint_newBv1_5_10yrs',
'footprint_no_gp_northv1_5_10yrs',
'footprint_standard_goalsv1_5_10yrs',
'footprint_stuck_rollingv1_5_10yrs',
'goodseeing_gi_v1_5_10yrs',
'goodseeing_gri_v1_5_10yrs',
'goodseeing_griz_v1_5_10yrs',
'goodseeing_gz_v1_5_10yrs',
'goodseeing_i_v1_5_10yrs',
'greedy_footprint_v1_5_10yrs',
'rolling_mod2_sdf_0_10_v1_5_10yrs',
'rolling_mod2_sdf_0_20_v1_5_10yrs',
'rolling_mod3_sdf_0_10_v1_5_10yrs',
'rolling_mod3_sdf_0_20_v1_5_10yrs',
'rolling_mod6_sdf_0_10_v1_5_10yrs',
'rolling_mod6_sdf_0_20_v1_5_10yrs',
'short_exp_2ns_1expt_v1_5_10yrs',
'short_exp_2ns_5expt_v1_5_10yrs',
'short_exp_5ns_1expt_v1_5_10yrs',
'short_exp_5ns_5expt_v1_5_10yrs',
'spiders_v1_5_10yrs',
'third_obs_pt120v1_5_10yrs',
'third_obs_pt15v1_5_10yrs',
'third_obs_pt30v1_5_10yrs',
'third_obs_pt45v1_5_10yrs',
'third_obs_pt60v1_5_10yrs',
'third_obs_pt90v1_5_10yrs',
'twilight_neo_mod1_v1_5_10yrs',
'twilight_neo_mod2_v1_5_10yrs',
'twilight_neo_mod3_v1_5_10yrs',
'twilight_neo_mod4_v1_5_10yrs',
'u60_v1_5_10yrs',
'var_expt_v1_5_10yrs',
'wfd_depth_scale0_65_noddf_v1_5_10yrs',
'wfd_depth_scale0_65_v1_5_10yrs',
'wfd_depth_scale0_70_noddf_v1_5_10yrs',
'wfd_depth_scale0_70_v1_5_10yrs',
'wfd_depth_scale0_75_noddf_v1_5_10yrs',
'wfd_depth_scale0_75_v1_5_10yrs',
'wfd_depth_scale0_80_noddf_v1_5_10yrs',
'wfd_depth_scale0_80_v1_5_10yrs',
'wfd_depth_scale0_85_noddf_v1_5_10yrs',
'wfd_depth_scale0_85_v1_5_10yrs',
'wfd_depth_scale0_90_noddf_v1_5_10yrs',
'wfd_depth_scale0_90_v1_5_10yrs',
'wfd_depth_scale0_95_noddf_v1_5_10yrs',
'wfd_depth_scale0_95_v1_5_10yrs',
'wfd_depth_scale0_99_noddf_v1_5_10yrs',
'wfd_depth_scale0_99_v1_5_10yrs']
var color = d3.scaleOrdinal(families).domain(variables)
//csvfile = './data/data_doubleHist.csv'
//csvfile = 'https://raw.githubusercontent.com/fedhere/LSSTunknowns/master/pmAnom/TPM.csv'
csvfile = './data/TPM.csv'
function update(){
var nbins = document.querySelector("#nbins_slider").value
console.log(nbins)
d3.select("#selected_nbins").text('number of bins '+ nbins)
d3.csv(csvfile).then( function(data){
// X axis: scale and draw:
var x = d3.scaleLinear()
.domain([0, 0.5]) // can use this instead of 1000 to have the max of data: d3.max(data, function(d) { return +d.price })
.range([0, w]);
svg.append("g")
.attr("transform", "translate(0," + h + ")")
.call(d3.axisBottom(x));
// Y axis: scale and draw:
var y = d3.scaleLinear()
.range([h, 0])
// Y axis: right
var y2 = d3.scaleLinear()
.range([h, 0])
.domain([0, 1850])
svg.append("g").attr("transform", "translate("+w+", 0)")
.call(d3.axisRight(y2))
// set the parameters for the histogram
var histogram = d3.histogram()
.value(function(d) { return +d.values; }) // I need to give the vector of value
.domain(x.domain()) // then the domain of the graphic
.thresholds(x.ticks(nbins)); // then the numbers of bins
for (var v=0;v<variables.length;v++){
// And apply twice this function to data to get the bins.
var bins1 = histogram(data.filter( function(d){return d.variable === variables[v]} ));
y.domain([0, d3.max(bins1, function(d) { return d.length*1.2; })]); // d3.hist has to be called before the Y axis obviously
// update axis and path
d3.select("#axisy").remove()
d3.selectAll("."+variables[v]).remove()
d3.selectAll(".cumpath"+variables[v]).remove()
d3.selectAll("#dots"+variables[v]).remove()
d3.selectAll(".legendtext"+variables[v]).remove()
svg.append("g")
.attr("id", "axisy")
.call(d3.axisLeft(y));
//console.log(bins1)
// append the bars for series 1
var length_cum = 0;
svg.selectAll("rect"+v)
.data(bins1)
.enter()
.append("g")
.append("rect")
.attr('class', variables[v])
.attr("x", 1)
.attr("transform", function(d) { return "translate(" + x(d.x0) + "," + y(d.length) + ")"; })
.attr("width", function(d) { return x(d.x1) - x(d.x0); })
.attr("height", function(d, i) {
//length_cum += d.length
return h - y(d.length);
})
.style("fill", families[v])
.style("opacity", 0.004)
// add line
var linedata = [ {"linex":0, "liney":0 + v },
{"linex":0.1, "liney":10 + v },
{"linex":0.2, "liney":50 + v },]
var h_cum = 0;
var line = d3.line().x(function(d){return x(d.x0)})
.y(function(d, i){
h_cum += d.length
//console.log([v, h_cum])
return y2(h_cum)})
svg.append("path")
.datum(bins1)
.attr("class", "cumpath"+variables[v])
.attr("d",line)
.style("stroke", color(variables[v])).style("stroke-width", 1)
.style("fill", "none")
.style("stroke-opacity", 0.2)
.on("mouseover", function(d){
d3.select(this).style("stroke-width", 5).style("stroke-opacity", 1)
//d3.select("#"+d).style("stroke-opacity", 1)
tooltip.style("visibility", "visible")
.text( d3.select(this).attr("class").replace("cumpath", "") )
.style("top", (d3.event.pageY-10)+"px")
.style("left",(d3.event.pageX+10)+"px")
.style("opacity", 1)
})
.on("mouseleave", function(d){
d3.select(this).style("stroke-width", 1).style("stroke-opacity", 0.2)
//d3.select("#"+d).style("stroke-opacity", 0.1)
tooltip.style("visibility", "hidden")
})
// Handmade legend
svg2.append("circle")
.attr("cx", function(d,i){if (v>variables.length/2){return 240-10} else {return 0} })
.attr("cy", function(d,i){ if (v<=variables.length/2){return v*12} else {return (v-variables.length/2)*12} })
.attr("r", 5)
.attr("id", "dots"+variables[v] )
.style("fill", families[v] )
.on("mouseover", function(d){
d3.select("#dots"+d).attr("r", 8)
})
.on("mouseleave", function(d){
d3.select("#dots"+d).attr("r", 5)
})
.on("click", function(d){
d3.select(this).style("opacity", 1).style("stroke-width", 4)
.style("stroke", "black").style("stroke-opacity", 1)
// Second the hovered specie takes its color
tex = this.id.replace("dots","")
console.log( tex )
d3.selectAll("." + tex)
.style("opacity", 0.5)//.style("stroke-width", "2")
//.style("fill", "#f7f7f7f7")
//.style("stroke", color(tex)).style("stroke-opacity", 1)
d3.selectAll('.cumpath'+tex)
.style("stroke-width", "3")
//.style("fill", "#f7f7f7f7")
.style("stroke-opacity", 1)
//.transition().duration(200)
//.style("stroke", color(d))
} )
svg2.append("text")
.attr("class", "legendtext"+variables[v])
.attr("x", function(){
if (v<= variables.length/2) {return 10} else {return 240}
})
.attr("y", function(){
if (v<= variables.length/2) {return v*12} else {return (v-variables.length/2)*12}
})
.text(variables[v]).style("font-size", "12px")
.attr("alignment-baseline","middle")
.on("mouseover", function(){
var tex = d3.select(this).text()
console.log(tex)
d3.selectAll('.'+tex)
.style("opacity", 0.5).style("stroke-width", "0")
//.style("fill", "#f7f7f7f7")
.style("stroke", color(tex)).style("stroke-opacity", 1)
d3.selectAll('.cumpath'+tex)
.style("stroke-width", "3")
//.style("fill", "#f7f7f7f7")
.style("stroke-opacity", 1)
})
.on("mouseleave", function(){
var tex = d3.select(this).text()
console.log(tex)
d3.selectAll('.'+tex)
.style("opacity", 0.004).style("stroke-opacity", 0)
d3.selectAll('.cumpath'+tex)
.style("stroke-width", "1")
//.style("fill", "#f7f7f7f7")
.style("stroke-opacity", 0.2)
d3.select("#dots"+tex).attr("r", 5).style("stroke-opacity", 0)
})
}
})
}
//add a tooltip
var tooltip = d3.select("body").append("div")
.style("position", "absolute")
.style("z-index", "10")
.style("visibility", "hidden")
.style("background", "white" )
.style("opacity", 0.6)
update()
</script>
</body>
</html>