-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstars_better.html
More file actions
166 lines (129 loc) · 4.88 KB
/
stars_better.html
File metadata and controls
166 lines (129 loc) · 4.88 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
<!DOCTYPE HTML>
<html>
<head>
<meta charset="utf-8">
<style></style>
</head>
<body>
<h1>Two hundred thousand Gaia positioned stars</h1>
<p>See my blog for info about this <a href="http://blog.akademy.co.uk/2016/09/gaia-star-data-with-d3-part-2-prettier-faster/">http://blog.akademy.co.uk/2016/09/gaia-star-data-with-d3-part-2-prettier-faster/</a></p>
<p>See an animated simpler version here: <a href="http://vis.akademy.uk/gaia/stars.html">http://vis.akademy.uk/gaia/stars.html</a></p>
<p>It might take a while to generate this, please be patient: <span id="update" style="color:red">Working...</span></p>
<div></div>
<p style="max-width:1000px;line-height:1.5;">This work has made use of data from the European Space Agency (ESA) mission Gaia (http://www.cosmos.esa.int/gaia), processed by the Gaia Data Processing and Analysis Consortium (DPAC, http://www.cosmos.esa.int/web/gaia/dpac/consortium). Funding for the DPAC has been provided by national institutions, in particular the institutions participating in the Gaia Multilateral Agreement.</p>
<script src="https://d3js.org/d3.v4.min.js"></script>
<script src="js/loadingAnimation.js"></script>
<script>
window.onload = function() {
var svg = d3.select("div").append("svg"),
bufferSvg = 25,
sizeSvg = {"w": (360 * 4 + bufferSvg), "h": (180 * 3 + bufferSvg)};
svg.attr("width", sizeSvg.w)
.attr("height", sizeSvg.h);
svg.append("rect")
.attr("x", bufferSvg)
.attr("y", 0)
.attr("width", sizeSvg.w - bufferSvg)
.attr("height", sizeSvg.h - bufferSvg)
.style("fill", "black");
var config = {
select: "div",
svgD3 : svg,
width: sizeSvg.w,
height: sizeSvg.h,
fill: "red",
stroke: "white"
};
// Chart create
//var waiter = chart.create( null, config );
var xScale = d3.scaleLinear()
.range([bufferSvg, sizeSvg.w])
.domain([0, 360]);
var yScale = d3.scaleLinear()
.range([0, sizeSvg.h - bufferSvg])
.domain([90, -90]);
svg.append("g")
.attr("class", "xaxis bottom")
.attr("transform", "translate(0," + (sizeSvg.h - bufferSvg + 1) + ")")
.call(d3.axisBottom(xScale));
svg.append("g")
.attr("class", "yaxis left")
.attr("transform", "translate(" + (bufferSvg - 2) + ",0)")
.call(d3.axisLeft(yScale));
document.getElementById("update").innerText = "Loading...";
var csvfile = "csvs/stars_skip10_[ra-dec-flux].csv";
//csvfile = "csvs/stars_skip100_[ra-dec-flux].csv";
d3.csv(csvfile, function (d) {
return [d.ra * 1, d.dec * 1, d.flux * 1];
}, function (data) {
var ira = 0, idec = 1, iflux = 2;
var total = data.length;
data.sort(function (d, e) {
return d[iflux] - e[iflux]; // bright ones appear at end of list
});
var extentFlux = [data[0][iflux], data[data.length - 1][iflux]]; //d3.extent(data,function(d) { return d[iflux]; });//[10000,100000000];//
var fluxRadiusScale = d3.scaleLinear()
.range([0.5, 3])
.domain(extentFlux);
var fluxOpacityScale = d3.scaleLog()
.range([0.1,1])
.domain(extentFlux);
document.getElementById("update").innerText = "Creating...";
console.log( total + " stars");
setTimeout( function() {
var g = document.createElementNS("http://www.w3.org/2000/svg", "g");
g.id = "stars";
for (var i = 0; i < data.length; i++) {
g.appendChild(document.createElementNS("http://www.w3.org/2000/svg", "circle"));
}
svg.node().appendChild(g);
console.log("created nodes");
document.getElementById("update").innerText = "Updating...";
setTimeout( function() {
svg.select("g#stars")
.style("pointer-events", "none")
.style("fill", "white")
.style("stroke-width", "0")
.selectAll("circle")
.data(data)
.attr("cx", function (d) {
return xScale(d[ira]);
})
.attr("cy", function (d) {
return yScale(d[idec]);
})
.attr("r", function (d) {
return fluxRadiusScale(d[iflux]);
})
.style("opacity", function (d) {
return fluxOpacityScale(d[iflux]);
})
;
document.getElementById("update").innerText = "Displaying...";
console.log("updated values");
setTimeout( function() {
document.getElementById("update").innerText = "Done"; // maybe...
/*setTimeout( function() {
console.log("Updating flux");
fluxOpacityScale = d3.scaleLog()
.range([0,0.8])
.domain(extentFlux);
svg.select("g#stars")
.selectAll("circle")
.data(data)
.transition()
.duration(5000)
.style("opacity", function (d) {
return fluxOpacityScale(d[iflux]);
})
;
console.log("Done");
}, 3000 );*/
}, 1000 );
}, 50 );
}, 50 );
});
}
</script>
</body>
</html>