-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathparallel.html
473 lines (388 loc) · 14.4 KB
/
parallel.html
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
<html>
<style>
.plotbutton{
background-color: #4CAF50
}
</style>
<body>
<h2>Comparing 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>
<table>
<tr><td>
<button onclick = "update(csv_wfd)">Proposal Id=1 WFD</button>
<button onclick="update(csv_GP_wfd)">Galactic Plane</button>
<button onclick="update(csv_LMC_wfd)">LMC</button>
<button onclick="update(csv_SMC_wfd)">SMC</button>
</tr></td>
<tr><td>
<button onclick = "update(csv_all)">ALL(exclude DDFs)</button>
<button onclick="update(csv_GP_all)">Galactic Plane</button>
<button onclick="update(csv_LMC_all)">LMC</button>
<button onclick="update(csv_SMC_all)">SMC</button>
</tr></td>
</table>
<p>Enter link to a csv file (make sure same format as <a href= "https://github.com/fedhere/LSSTunknowns/blob/master/tdAnom/data_v1_5/df_radar_wfd.csv"> this example</a>) then click Plot:</p>
<p></p>
<textarea id="csvlink" cols="100" ></textarea>
<button class="plotbutton" onclick="update2()" > Plot </button>
<button class="plotbutton", onclick = "update_cum()">culmulative</button>
<table>
<tr>
<th> <div id="rank"></div> </th>
<th> <div id="legend"></div> </th>
</tr>
</table>
</body>
</html>
<!-- load d3.js-->
<script type="text/javascript", src="./js/d3/d3.js"></script>
<script type="text/javascript">
var margin = {top:50, right:50, bottom:50, left:50}
var width = 800 - margin.left - margin.right
var height = 500 - margin.top - margin.bottom
//var csvfile = "./data/iris.csv"
//var csvfile = "./data/df_rank.csv"
//var csvfile = "./data/df_radar_wfd.csv"
var csv_wfd = "https://raw.githubusercontent.com/fedhere/LSSTunknowns/master/tdAnom/data_v1_5/df_radar_wfd.csv"
var csv_GP_wfd = "https://raw.githubusercontent.com/fedhere/LSSTunknowns/master/tdAnom/data_v1_5/df_radar_GP_inwfd.csv"
var csv_LMC_wfd = "https://raw.githubusercontent.com/fedhere/LSSTunknowns/master/tdAnom/data_v1_5/df_radar_LMC_inwfd.csv"
var csv_SMC_wfd = "https://raw.githubusercontent.com/fedhere/LSSTunknowns/master/tdAnom/data_v1_5/df_radar_SMC_inwfd.csv"
var csv_all = "https://raw.githubusercontent.com/fedhere/LSSTunknowns/master/tdAnom/data_v1_5/df_radar_all.csv"
var csv_GP_all = "https://raw.githubusercontent.com/fedhere/LSSTunknowns/master/tdAnom/data_v1_5/df_radar_GP_allsky.csv"
var csv_LMC_all = "https://raw.githubusercontent.com/fedhere/LSSTunknowns/master/tdAnom/data_v1_5/df_radar_LMC_allsky.csv"
var csv_SMC_all = "https://raw.githubusercontent.com/fedhere/LSSTunknowns/master/tdAnom/data_v1_5/df_radar_SMC_allsky.csv"
//var csv_all_cum = "https://raw.githubusercontent.com/fedhere/LSSTunknowns/master/tdAnom/data_v1_5/df_radar_SMC_allsky.csv"
// color
families = ['agnddf', 'alt', 'baseline', 'bulges', 'daily', 'dcr', 'descddf',
'filterdist', 'footprint', 'goodseeing', 'greedy', 'roll',
'rolling', 'short', 'spiders', 'third', 'twilight', 'u60', 'var',
'wfd']
var color = d3.scaleOrdinal()
.domain( families )
.range([ '#a6cee3', '#1f78b4', '#b2df8a', '#33a02c', '#fb9a99', '#e31a1c', '#fdbf6f', '#ff7f00', '#cab2d6', '#6a3d9a', '#ffff99', '#b15928', '#004301', '#5e0022', '#ed00d7', '#00008f', '#626d60', '#9978ff', '#5b3600', '#00a799'])
// Here I set the list of dimension manually to control the order of axis:
//dimensions = ["Petal_Length", "Petal_Width", "Sepal_Length", "Sepal_Width"]
//dimensions = ["tgaps_wfd", "tgaps_all", "nfields_wfd", "nfields_all", "nstars_wfd", "nstars_all"]
//dimensions = ["brightness","color", "depth", "footprint", "star density"]
dimensions = ["flux change","color", "depth", "footprint", "star count"]
// append svg to body
var svg = d3.select("#rank")
.append("svg")
.attr("width", width + margin.left + margin.right)
.attr("height", height + margin.top + margin.bottom)
.style("background-color", "#f7f7f7f7")
.append("g")
.attr("transform", "translate(" + margin.left +", "+ margin.top +")")
// colormap
//var cmap = d3.scaleLinear()
// .range(["white", "#69b3a2"])
// .domain([0, 100])
//var cmap = d3.scaleSequential(d3.interpolateSpectral).domain([100, 0])
// x scale
var x = d3.scalePoint()
.range([0, width])
.domain(dimensions)
var ymax = 1
var y = {}
for (i in dimensions){
name = dimensions[i]
y[name] = d3.scaleLinear()
//.domain([0, 86]) // same range for each group
.domain([0, 1])
.range([height, 0])
}
// Draw the axis:
svg.selectAll("myAxis")
// For each dimension of the dataset I add a 'g' element:
.data(dimensions).enter()
.append("g")
.attr("class", "axis")
// I translate this element to its right position on the x axis
.attr("transform", function(d) { return "translate(" + x(d) + ")"; })
// And I build the axis with the call function
.each(function(d) { d3.select(this).call(d3.axisLeft().ticks(5).scale(y[d])); })
// Add axis title
.append("text")
.style("text-anchor", "middle")
.attr("y", -9)
.text(function(d) { return d; })
.style("fill", "black")
function update(csvfile){
// update when button is clicked
// remove before plot new lines
d3.selectAll(".axis").remove()
d3.selectAll(".opsimlines").remove()
//d3.selectAll("#csvlink").text(csvfile)
document.getElementById('csvlink').value = csvfile;
var ymax = 1
//var y = {}
for (i in dimensions){
name = dimensions[i]
y[name] = d3.scaleLinear()
//.domain([0, 86]) // same range for each group
.domain([0, ymax])
.range([height, 0])
}
// Draw the axis:
svg.selectAll("myAxis")
// For each dimension of the dataset I add a 'g' element:
.data(dimensions).enter()
.append("g")
.attr("class", "axis")
// I translate this element to its right position on the x axis
.attr("transform", function(d) { return "translate(" + x(d) + ")"; })
// And I build the axis with the call function
.each(function(d) { d3.select(this).call(d3.axisLeft().ticks(5).scale(y[d])); })
// Add axis title
.append("text")
.style("text-anchor", "middle")
.attr("y", -9)
.text(function(d) { return d; })
.style("fill", "black")
var data = d3.csv(csvfile).then(
function(data){
//dimensions = d3.keys(data[0]).filter(function(d) { return d != "db" })
// Draw lines
svg.selectAll("myPath")
.data(data)
.enter()
.append("g")
.attr("class", "opsimlines")
.append("path")
.attr("class", function (d) { return "line " + d.family } )
//.attr("id", function (d) { return "line" + d.id } )
.attr("d", path)
.style("fill", "none" )
.style("stroke", function(d){ return( color(d.family))} )
//.style( "stroke-dasharray", "10,10")
.style("opacity", 0.1)
.style("stroke-width", 1)
.on("mouseover", linemouseover)
.on("mouseleave", linemouseleave)
.on("click", highlight)
.on("dblclick", doNotHighlight )
}
)
}
// function path
// The path function take a row of the csv as input, and return x and y coordinates of the line to draw for this raw.
function path(d) {
//return d3.line()( dimensions.map( function(p) { return [x(p), y[p] (d[p])]; })); // y[p]
return d3.line()( dimensions.map( p => [x(p), y[p] (d[p] ) ]) ) ; // y[p] y-axis for current dimension
}
// The path function take a row of the csv as input, and return x and y coordinates of the line to draw for this raw.
function path_cum(d,y) {
//return d3.line()( dimensions.map( function(p) { return [x(p), y[p] (d[p])]; })); // y[p]
return d3.line()( cum(d,y)
) ; // y[p] y-axis for current dimension
}
// calculate the culumative positions
function cum(d, y){
var arr = []
for (i in dimensions){
p = dimensions[i]
y_cum = 0
for (j=0; j<=i; j++){
//console.log( d[ dimensions[j] ] )
y_cum += d[ dimensions[j] ]*1
}
arr.push( [x(p), y[p] ( y_cum) ] )
}
return arr
}
function update_c(csvfile){
// update when button is clicked
// remove before plot new lines
d3.selectAll(".axis").remove()
d3.selectAll(".opsimlines").remove()
d3.selectAll("#csvlink").text(csvfile)
var ymax = 5
var y = {}
for (i in dimensions){
name = dimensions[i]
y[name] = d3.scaleLinear()
//.domain([0, 86]) // same range for each group
.domain([0, ymax])
.range([height, 0])
}
// Draw the axis:
svg.selectAll("myAxis")
// For each dimension of the dataset I add a 'g' element:
.data(dimensions).enter()
.append("g")
.attr("class", "axis")
// I translate this element to its right position on the x axis
.attr("transform", function(d) { return "translate(" + x(d) + ")"; })
// And I build the axis with the call function
.each(function(d) { d3.select(this).call(d3.axisLeft().ticks(5).scale(y[d])); })
// Add axis title
.append("text")
.style("text-anchor", "middle")
.attr("y", -9)
.text(function(d) { return d; })
.style("fill", "black")
var data = d3.csv(csvfile).then(
function(data){
// Draw lines
svg.selectAll("myPath")
.data(data)
.enter()
.append("g")
.attr("class", "opsimlines")
.append("path")
.attr("class", function (d) { return "line " + d.family } )
//.attr("id", function (d) { return "line" + d.id } )
.attr("d", d=>path_cum(d, y))
.style("fill", "none" )
.style("stroke", function(d){ return( color(d.family))} )
//.style( "stroke-dasharray", "10,10")
.style("opacity", 0.1)
.style("stroke-width", 1)
.on("mouseover", linemouseover)
.on("mouseleave", linemouseleave)
.on("click", highlight)
.on("dblclick", doNotHighlight )
}
)
}
// mouse event function
// Highlight the specie that is hovered
var highlight = function(d){
// first every group turns grey
//d3.selectAll(".line")
// .transition().duration(200)
// .style("stroke", "lightgrey")
// .style("opacity", "0.2")
// Second the hovered specie takes its color
d3.select(this )
.transition().duration(100)
.style("stroke", color( d.family ))
.style("stroke-width", "2")
.style("opacity", "1")
}
// Unhighlight
var doNotHighlight = function(d){
d3.select(this )
.transition().duration(200)
.style("stroke", color( d.family ))
.style("stroke-width", "1")
.style("opacity", "0.1")
}
// showtooltip
var linemouseover = function(d){
d3.select(this )
.transition().duration(100)
.style("stroke-width", "8")
tooltip.style("visibility", "visible")
.text( d.db )
.style("top", (d3.event.pageY-10)+"px")
.style("left",(d3.event.pageX+10)+"px")
.style("opacity", 1)
}
var linemouseleave = function(){
d3.select(this )
.transition().duration(50)
.style("stroke-width", "2")
tooltip.style("visibility", "hidden")
}
//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)
var margin2 = {top:50, right:50, bottom:50, left:50}
// add legend in second svg
var svg2 = d3.select("#legend")
.append("svg")
.attr("width", 50 + margin2.left + margin2.right)
.attr("height", height + margin2.top + margin2.bottom)
.style("background-color", "#f0f0f0f0")
.append("g")
.attr("transform", "translate(" + margin.left +", "+ margin.top +")")
// Add one dot in the legend for each name.
svg2.selectAll("mydots")
.data(families)
.enter()
.append("circle")
.attr("cx", 0)
.attr("cy", function(d,i){ return i*20})
.attr("r", 5)
.attr("id", function(d){return "dots"+d} )
.style("fill", function(d){ return color(d)})
.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){
console.log(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
d3.selectAll("." + d)
.transition().duration(200)
.style("stroke", color(d))
.style("opacity", "1")
.style("stroke-width", "2")
} )
.on("dblclick", function(d){
d3.select(this).style("stroke-opacity", "0")
d3.selectAll("."+d)
.transition().duration(200)
.style("stroke", color(d))
.style("opacity", "0.2")
}
)
//var highlight2 = function(d){
// first every group turns grey
// console.log("hello")
// d3.select(this).style("opacity", 0.1).attr("r", 15)
// }
svg2.selectAll("mylabels")
.data(families)
.enter()
.append("text")
.attr("x", 10)
.attr("y", function(d,i){ return i*20}) // 100 is where the first dot appears. 25 is the distance between dots
.style("fill", function(d){ return color(d)})
.text(function(d){ return d})
.attr("text-anchor", "left")
.style("alignment-baseline", "middle")
.on("mouseover", function(d){ // first every group turns grey
console.log(d)
d3.select(this).style("opacity", 1).style("stroke", "black").style("stroke-opacity", 1)
// Second the hovered specie takes its color
d3.selectAll("." + d)
.transition().duration(200)
.style("stroke", color(d))
.style("opacity", "1")
.style("stroke-width", "2")
})
.on("mouseleave", function(d){
d3.select(this).style("opacity", 1).style("stroke", "black").style("stroke-opacity", 0)
// Second the hovered specie takes its color
d3.selectAll("." + d)
.transition().duration(200)
.style("stroke", color(d))
.style("opacity", "0.2")
.style("stroke-width", "1")
// also make the dots stroke invisiable
d3.select("#dots"+d).style("stroke-opacity", 0)
} )
// run update when page first loaded
update(csv_wfd)
function update_cum(){
//var csv_cum = d3.select("#csvlink").text()
var csv_cum = document.getElementById("csvlink").value
console.log(csv_cum)
update_c(csv_cum)
}
function update2(){
var csv_cum = document.getElementById("csvlink").value
console.log(csv_cum)
update(csv_cum)
}
</script>