Skip to content

Instantly share code, notes, and snippets.

@epidemico616
Created December 4, 2013 05:39

Revisions

  1. epidemico616 revised this gist Dec 4, 2013. 1 changed file with 1 addition and 0 deletions.
    1 change: 1 addition & 0 deletions _.md
    Original file line number Diff line number Diff line change
    @@ -0,0 +1 @@
    [ <a href="http://tributary.io/inlet/7782904">Launch: Tributary inlet</a> ] 7782904 by epidemico616<br>
  2. epidemico616 created this gist Dec 4, 2013.
    1 change: 1 addition & 0 deletions config.json
    Original file line number Diff line number Diff line change
    @@ -0,0 +1 @@
    {"description":"Tributary inlet","endpoint":"","display":"svg","public":true,"require":[],"fileconfigs":{"inlet.js":{"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}
    36 changes: 36 additions & 0 deletions inlet.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,36 @@
    optionRadius = 29;
    nodeRadius = 69;
    ringRadius = nodeRadius + optionRadius + 5;
    optionRotation = 2;

    context = [{"name":"first", "action":"test1"},{"name":"second", "action":"test2"},{"name":"third", "action":"test3"},{"name":"fourth", "action":"test4"}];
    n = context.length;

    svg = d3.select("svg");
    node = svg.append("g").attr({transform:"translate(400,400)"})
    inner = node.append("circle").attr({cx:0,cy:0,r:nodeRadius,fill:"#068"})
    ring = node.append("circle").attr({cx:0,cy:0,r:ringRadius,fill:"none",stroke:"black","stroke-width":2})

    option = node.selectAll("option")
    .data(context)
    .enter()
    .append("circle")
    .attr({
    cx:function(d,i){return ringRadius*Math.cos(i/n*(Math.PI*optionRotation))},
    cy:function(d,i){return ringRadius*Math.sin(i/n*(Math.PI*optionRotation))},
    r:optionRadius,
    fill:"grey"
    })
    .on("mouseover", function(d,i){d3.select(this).transition().attr({r:optionRadius+5})})
    .on("mouseout", function(d,i){d3.select(this).transition().attr({r:optionRadius})})
    .on("click", function(d,i){alert(d3.select(this.parentNode).datum(d.name))})
    itemText = node.selectAll("text")
    .data(context)
    .enter()
    .append("text")
    .text(function(d,i){return d.name})
    .attr({
    x:function(d,i){return ringRadius*(Math.cos(i/n*(Math.PI*optionRotation)))},
    y:function(d,i){return ringRadius*(Math.sin(i/n*(Math.PI*optionRotation)))+optionRadius/(optionRadius/6)}
    })
    .style("text-anchor", "middle")