[ Launch: show narco ] 5934712 by gelicia
-
-
Save gelicia/5934712 to your computer and use it in GitHub Desktop.
show narco
This file contains 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":"show narco","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":"period","bv":false,"nclones":15,"clone_opacity":0.4,"duration":3000,"ease":"linear","dt":0.01} |
This file contains 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 data = [ | |
{name: 'pear', value : 32}, | |
{name: 'apple', value : 20}, | |
{name: 'orange', value : 27}, | |
{name: 'banana', value : 36} | |
] | |
var svg = d3.select("svg"); | |
var maxHeight = d3.max(data, function(d){return d.value}); | |
var height = 90; | |
var margin = 50; | |
var heightScale = d3.scale.linear().domain([0, maxHeight]) | |
.range([0, height]); | |
var colorScale = d3.scale.linear().domain([0, maxHeight]) | |
.range(['blue', 'green']); | |
svg.selectAll("rect") | |
.data(data).enter() | |
.append('rect') | |
.attr({ | |
x: function(d,i){return margin + (50 * i);}, | |
y: function(d){return margin + height - heightScale(d.value);}, | |
height : 0, | |
width: 0, | |
fill : function(d){return colorScale(d.value);} | |
}) | |
//.transition() | |
// .duration(1000) | |
//.ease("bounce") | |
.attr({ | |
x: function(d,i){return margin + (50 * i);}, | |
y: function(d){return margin + height - heightScale(d.value);}, | |
height : function(d){return heightScale(d.value);}, | |
width: 50, | |
fill : function(d){return colorScale(d.value);} | |
}) | |
svg.selectAll("text") | |
.data(data).enter() | |
.append('text') | |
.attr({ | |
x: function(d,i){return margin + (50 * i);}, | |
y: function(d){return margin + height - heightScale(d.value);}, | |
height : 0, | |
width: 0, | |
fill : function(d){return colorScale(d.value);} | |
}) | |
.text(function(d){return d.value}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment