Skip to content

Instantly share code, notes, and snippets.

@ariaz
Created December 9, 2013 02:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ariaz/7866640 to your computer and use it in GitHub Desktop.
Save ariaz/7866640 to your computer and use it in GitHub Desktop.
tangle-d3
{"description":"tangle-d3","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/VatMsPv.png"}
var drag = d3.behavior.drag()
.origin(Object)
.on("drag", dragmove);
var data = [{val:1, step: 1, min:0, max:100, format:"2d" },
{val:2, step: 0.25, min:0, max:20, format:".2f"},
{val:0, step: 0.05, min:0, max:1, format:"%"}
];
var texts = d3.select("svg").selectAll("text").data(data).enter();
texts.append("text")
.attr("x", function(d, i){ return tributary.sw/3})
.attr("y", function(d, i){ return tributary.sh/3 + 100*i})
.attr("font-size", 100)
.style("font-family", "impact")
.attr("fill", "blue")
.text(function(d){return d3.format(d.format)(d.val)})
.call(drag);
var color = d3.interpolate("blue","red");
function dragmove(d){
d.val = (d3.event.dx < 0) ? d.val - d.step : d.val + +d.step;
if (d.val > d.max) d.val = d.max;
if (d.val < d.min) d.val = d.min;
d3.select(this)
.text(d3.format(d.format)(d.val))
.attr("fill",color(d.val/d.max));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment