Created
June 24, 2012 07:51
-
-
Save ptvans/2982339 to your computer and use it in GitHub Desktop.
just another inlet to tributary
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 x_scale = d3.scale.linear().domain([0,100]).range([0,500]); | |
var h=20; | |
//x-origin | |
var o=0; | |
//y-origin | |
var l=30; | |
var color = d3.scale.category20(); | |
var array1 = [16,25,9,12,38]; | |
var touchStart = function(d,i){ | |
d3.selectAll('.bars') | |
.transition() | |
.duration(500) | |
.attr('x',0) | |
.attr('y',function(d,i){ | |
return i * 21; | |
}); | |
} | |
var touchEnd = function(d,i){ | |
var oTemp = 0; | |
d3.selectAll('.bars') | |
.transition() | |
.duration(500) | |
.attr('x',function(d,i){ | |
var cw = x_scale(d); | |
var temp = oTemp; | |
oTemp = oTemp + cw | |
return temp; | |
}) | |
.attr('y',l) | |
} | |
var group = g.append('g').attr('id','barsGroup') | |
var selection = group.selectAll('rect') | |
.data(array1) | |
.enter() | |
.append('rect') | |
.attr('class','bars') | |
.attr('fill',function(d,i){return color(1)}) | |
.attr('height',h) | |
.attr('width',function(d,i){ | |
return x_scale(d); | |
}) | |
.attr('x',function(d,i){ | |
var cw = x_scale(d); | |
var temp = o; | |
o = o + cw | |
return temp; | |
}) | |
.attr('y',l) | |
group.on('touchstart',touchStart) | |
.on('mousedown',touchStart) | |
.on('mouseup',touchEnd) | |
.on('touchend',touchEnd); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment