[ Launch: draggableBars ] 7864776 by ariaz
-
-
Save ariaz/7864776 to your computer and use it in GitHub Desktop.
draggableBars
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":"draggableBars","endpoint":"","display":"svg","public":true,"require":[],"fileconfigs":{"inlet.js":{"default":true,"vim":false,"emacs":false,"fontSize":12},"style.css":{"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/bOZ2aXq.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
| var margin = {top: 10, right: 30, bottom: 30, left: 18}, | |
| width = tributary.sw - margin.left - margin.right, | |
| height = tributary.sh - margin.top - margin.bottom; | |
| var data = _.map(d3.range(10), function(d){return {x:d, y:100*Math.random()}}); | |
| var x = d3.scale.linear().domain([0,10]).range([0,width]); | |
| var y = d3.scale.linear() | |
| .domain([0, d3.max(data, function(d) { return d.y; })]) | |
| .range([height, 0]); | |
| var xAxis = d3.svg.axis() | |
| .scale(x) | |
| .orient("bottom"); | |
| var drag = d3.behavior.drag() | |
| .origin(Object) | |
| .on("drag", dragmove) | |
| .on("dragstart", dragstart) | |
| .on("dragend", dragstop); | |
| var svg = d3.select("svg") | |
| .append("g") | |
| .attr("transform", "translate(" + margin.left + "," + margin.top + ")");; | |
| var bar = svg.selectAll("rect.bar") | |
| .data(data).enter() | |
| var rects = bar | |
| .append("rect") | |
| .attr("class", "bar") | |
| rects | |
| .attr("x", function(d){return x(d.x)}) | |
| .attr("y", function(d){return y(d.y)}) | |
| .attr("width", 40) | |
| .attr("height", function(d) { return height - y(d.y); }) | |
| .call(drag); | |
| svg.append("g") | |
| .attr("class", "x axis") | |
| .attr("transform", "translate(0," + height + ")") | |
| .call(xAxis); | |
| function dragmove(d) { | |
| d.y = Math.max(3, d3.event.y); | |
| d3.select(this) | |
| .style("fill", "#9467BD") | |
| .attr("y", function(d) { return y(d.y); }) | |
| .attr("height", function(d) { return height - y(d.y); }) | |
| } | |
| function dragstop(d) { | |
| d3.select(this) | |
| .style("fill", "steelblue") | |
| } | |
| function dragstart(d) { | |
| d3.select(this) | |
| .style("fill", "#9467BD") | |
| } | |
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
| rect.bar { | |
| fill: steelblue; | |
| shape-rendering: crispEdges; | |
| font: 10px sans-serif; | |
| } | |
| .bar text { | |
| fill: #fff; | |
| font: 10px sans-serif; | |
| } | |
| .axis text { | |
| font: 10px sans-serif; | |
| } | |
| .axis path, .axis line { | |
| fill: none; | |
| stroke: #000; | |
| shape-rendering: crispEdges; | |
| font: 10px sans-serif; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment