-
-
Save tonysherbondy/4190494 to your computer and use it in GitHub Desktop.
Another Inlet
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":"Another Inlet","endpoint":"","display":"svg","public":true,"require":[],"tab":"edit","display_percent":0.473220747889023,"play":false,"loop":false,"restart":false,"autoinit":true,"pause":true,"loop_type":"period","bv":false,"nclones":15,"clone_opacity":0.4,"duration":3000,"ease":"linear","dt":0.01} |
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
var svg = d3.select("svg"); | |
//Width and height | |
var w = 500; | |
var h = 300; | |
var padding = 27; | |
var dataset = [ | |
[2, 20], [480, 90], [250, 50], [100, 33], [330, 95], | |
[410, 12], [475, 44], [25, 67], [85, 21], [220, 88], | |
[643, 98] | |
]; | |
//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]); | |
var rScale = d3.scale.linear() | |
.domain([0, d3.max(dataset, function(d) { return d[1]; })]) | |
.range([2, 10]); | |
//Define X axis | |
var xAxis = d3.svg.axis() | |
.scale(xScale) | |
.orient("bottom"); | |
//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", function(d) { | |
return rScale(d[1]); | |
}); | |
//Create labels | |
svg.selectAll("text") | |
.data(dataset) | |
.enter() | |
.append("text") | |
.text(function(d) { | |
return d[0] + "," + d[1]; | |
}) | |
.attr("x", function(d) { | |
return xScale(d[0]); | |
}) | |
.attr("y", function(d) { | |
return yScale(d[1]); | |
}) | |
.attr("font-family", "sans-serif") | |
.attr("font-size", "11px") | |
.attr("fill", "red"); | |
//Create X axis | |
svg.append("g") | |
.call(xAxis); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment