[ Launch: Tributary inlet ] 8705650 by hanbzu
-
-
Save hanbzu/8705650 to your computer and use it in GitHub Desktop.
bub
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| {"description":"bub","endpoint":"","display":"svg","public":true,"require":[],"fileconfigs":{"inlet.js":{"default":true,"vim":false,"emacs":false,"fontSize":12},"_.md":{"default":true,"vim":false,"emacs":false,"fontSize":12},"config.json":{"default":true,"vim":false,"emacs":false,"fontSize":12}},"fullscreen":false,"play":false,"loop":false,"restart":false,"autoinit":true,"pause":true,"loop_type":"pingpong","bv":false,"nclones":15,"clone_opacity":0.4,"duration":3000,"ease":"linear","dt":0.01,"thumbnail":"http://i.imgur.com/pDAFFq6.png"} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| //Width and height | |
| var w = 500; | |
| var h = 300; | |
| var padding = 30; | |
| //Dynamic, random dataset | |
| var dataset = []; //Initialize empty array | |
| var numDataPoints = 50; //Number of dummy data points to create | |
| var maxRange = Math.random() * 1000; //Max range of new values | |
| for (var i = 0; i < numDataPoints; i++) { //Loop numDataPoints times | |
| var newNumber1 = Math.floor(Math.random() * maxRange); //New random integer | |
| var newNumber2 = Math.floor(Math.random() * maxRange); //New random integer | |
| dataset.push([newNumber1, newNumber2]); //Add new number to array | |
| } | |
| //Create scale functions | |
| var xScale = d3.scale.linear() | |
| .domain([0, d3.max(dataset, function(d) { return d[0]; })]) | |
| .range([padding, w - padding * 2]); | |
| var yScale = d3.scale.linear() | |
| .domain([0, d3.max(dataset, function(d) { return d[1]; })]) | |
| .range([h - padding, padding]); | |
| //Define X axis | |
| var xAxis = d3.svg.axis() | |
| .scale(xScale) | |
| .orient("bottom") | |
| .ticks(5); | |
| //Define Y axis | |
| var yAxis = d3.svg.axis() | |
| .scale(yScale) | |
| .orient("left") | |
| .ticks(5); | |
| //Create SVG element | |
| var svg = d3.select("svg") | |
| .append("svg") | |
| .attr("width", w) | |
| .attr("height", h); | |
| //Create circles | |
| svg.selectAll("circle") | |
| .data(dataset) | |
| .enter() | |
| .append("circle") | |
| .attr("cx", function(d) { | |
| return xScale(d[0]); | |
| }) | |
| .attr("cy", function(d) { | |
| return yScale(d[1]); | |
| }) | |
| .attr("r", 2); | |
| //Create X axis | |
| svg.append("g") | |
| .attr("class", "x axis") | |
| .attr("transform", "translate(0," + (h - padding) + ")") | |
| .call(xAxis); | |
| //Create Y axis | |
| svg.append("g") | |
| .attr("class", "y axis") | |
| .attr("transform", "translate(" + padding + ",0)") | |
| .call(yAxis); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment