Built with blockbuilder.org
forked from anonymous's block: satellite_scatterplot
forked from hydrosquall's block: satellite_scatterplot
| license: mit |
Built with blockbuilder.org
forked from anonymous's block: satellite_scatterplot
forked from hydrosquall's block: satellite_scatterplot
| <!DOCTYPE html> | |
| <head> | |
| <meta charset="utf-8"> | |
| <style> | |
| body { margin:0;position:fixed;top:0;right:0;bottom:0;left:0; } | |
| </style> | |
| </head> | |
| <body> | |
| <svg></svg> | |
| <script src="https://d3js.org/d3.v4.min.js"></script> | |
| <script src="index.js"></script> | |
| </body> |
| // items | |
| var svg = d3.select("body").append("svg"); | |
| // var color_mapper = function(d) { | |
| // const nation = d.country; | |
| // let val = "" | |
| // if (nation == "USA") { | |
| // val = "#F2CE6D"; | |
| // } else if (nation === "China") { | |
| // val = "#E27465"; | |
| // } else if (nation === "Russia") { | |
| // val = "#8695BF"; | |
| // } else { | |
| // val = "#999999"; | |
| // } | |
| // return val; | |
| // } | |
| // ; | |
| const data_url = "https://gist.githubusercontent.com/hydrosquall/2529709f951320cc8acc8ff7938a02db/raw/2d99657a1ebbafdeb58285dfaae31c3e3fe0c9df/satellites_listing.csv"; | |
| var get_data = function(url) { | |
| return d3.csv(url, function(d) { | |
| return { | |
| x: d3.isoParse(d.date_of_launch), | |
| y: +d.launch_mass_kg, | |
| country: d.country_of_operator_owner, | |
| raw: d | |
| } | |
| }) | |
| }; | |
| var raw_data = get_data(data_url); | |
| var data = raw_data.filter(x => x.x ); | |
| var margin = ({top: 100, right: 50, bottom: 30, left: 50}); | |
| var x = d3.scaleTime() | |
| .domain(d3.extent(data, d => d.x)).nice() | |
| .range([margin.left, width - margin.right]); | |
| var y = d3.scaleLinear() | |
| .domain(d3.extent(data, d => d.y)).nice() | |
| .range([height - margin.bottom, margin.top]); | |
| // axes | |
| // var xAxis = g => g | |
| // .attr("transform", `translate(0,${height - margin.bottom})`) | |
| // .call(d3.axisBottom(x)) | |
| // .call(g => g.select(".domain").remove()) | |
| // .call(g => g.append("text") | |
| // .attr("x", width - margin.right) | |
| // .attr("y", -4) | |
| // .attr("fill", "#000") | |
| // .attr("font-weight", "bold") | |
| // .attr("text-anchor", "end") | |
| // .text(data.x) | |
| // ); | |
| // var yAxis = g => g | |
| // .attr("transform", `translate(${margin.left},0)`) | |
| // .call(d3.axisLeft(y)) | |
| // .call(g => g.select(".domain").remove()) | |
| // .call(g => g.append("text") | |
| // .attr("fill", "#000") | |
| // .attr("x", 50) | |
| // .attr("y", margin.top) | |
| // .attr("dy", "0.32em") | |
| // .attr("text-anchor", "start") | |
| // .attr("font-weight", "bold") | |
| // .text(data.y)); | |
| // Build the viz | |
| // svg.append("g") | |
| // .call(xAxis); | |
| // svg.append("g") | |
| // .call(yAxis); | |
| var data = [ | |
| [3, 4], | |
| [5, 6] | |
| ] | |
| // Create scatter-circles | |
| svg.append("g") | |
| .attr("stroke-width", 2) | |
| .selectAll("circle") | |
| .data(data) | |
| .enter().append("circle") | |
| .attr("stroke", "#000") | |
| .attr("fill", "#000") | |
| .attr("cx", d => d[0]) | |
| .attr("cy", d => d[1]) | |
| .attr("r", 2); |