topical media & game development

talk show tell print

mobile-data-circle-01.htm / htm



  <script src="http://d3js.org/d3.v3.min.js"></script>
  <link rel="stylesheet" type="text/css" href="mobile-data-circle-style-d3.css">
  <script type="text/javascript">
  

data


    var data = [32, 57, 112],
        dataEnter = data.concat(293),
        dataExit = data.slice(0, 2),
        w = 360,
        h = 180,
        x = d3.scale.ordinal().domain([57, 32, 112]).rangePoints([0, w], 1),
        y = d3.scale.ordinal().domain(data).rangePoints([0, h], 2);
  
</script> <!-- <p>Once upon a time, there were three little circles. This tutorial shows you how to manipulate them using selections.</p> --> <h2 id="selecting_elements">selecting elements</h2> <p>The <a href="https://github.com/mbostock/d3/wiki/Selections#selectAll">selectAll</a> operator takes a <a href="http://www.w3.org/TR/CSS2/selector.html">selector</a> string, such as circle, and returns a selection:</p> <div class="chart" id="chart-2"> <pre class="code">var circle = svg.selectAll("circle"); </pre> <button>run</button> <!-- <svg width="360" height="180"><circle class="little" cx="180" cy="45" r="12"></circle><circle class="little" cx="60" cy="90" r="12"></circle><circle class="little" cx="300" cy="135" r="12"></circle></svg></div> --> <script type="text/javascript">

script


  (function() {
    var svg = d3.select("#chart-2").append("svg")
        .attr("width", w)
        .attr("height", h);
  
    svg.selectAll(".little")
        .data(data)
      .enter().append("circle")
        .attr("class", "little")
        .attr("cx", x)
        .attr("cy", y)
        .attr("r", 12);

attribute


  
    d3.select("#chart-2 button").on("click", function() {
      svg.selectAll(".select").remove();
  
      svg.selectAll(".select")
          .data(data)
        .enter().append("circle")
          .attr("class", "select")
          .attr("cx", x)
          .attr("cy", y)
          .attr("r", 60)
          .style("fill", "none")
          .style("stroke", "red")
          .style("stroke-opacity", 1e-6)
          .style("stroke-width", 3)

transition


        .transition()
          .duration(750)
          .attr("r", 12)
          .style("stroke-opacity", 1);
    });
  })();
</script>


(C) Æliens 04/09/2009

You may not copy or print any of this material without explicit permission of the author or the publisher. In case of other copyright issues, contact the author.
<script src="http://www.google-analytics.com/urchin.js" type="text/javascript"> </script> <script type="text/javascript"> _uacct = "UA-2780434-1"; urchinTracker(); </script>