Sha256: a5ae45cadc8be9680e14595ba28eb8f0db2f44178f82b368b6ddbdeb27636090

Contents?: true

Size: 1.13 KB

Versions: 25

Compression:

Stored size: 1.13 KB

Contents

var w = 960,
    h = 40;

var chart = d3.chart.horizon()
    .width(w)
    .height(h)
    .bands(5)
    .mode("offset")
    .interpolate("basis");

var svg = d3.select("#chart").append("svg")
    .attr("width", w)
    .attr("height", h);

d3.json("unemployment.json", function(data) {

  // Offset so that positive is above-average and negative is below-average.
  var mean = data.rate.reduce(function(p, v) { return p + v; }, 0) / data.rate.length;

  // Transpose column values to rows.
  data = data.rate.map(function(rate, i) {
    return [Date.UTC(data.year[i], data.month[i] - 1), rate - mean];
  });

  // Render the chart.
  svg.data([data]).call(chart);

  // Enable mode buttons.
  d3.selectAll("#mode button")
      .data(["offset", "mirror"])
      .on("click", function(m) {
        svg.call(chart.duration(0).mode(m));
        d3.selectAll("#mode button")
            .classed("active", function(d) { return d == m; });
      });

  // Enable bands buttons.
  d3.selectAll("#bands button")
      .data([-1, 1])
      .on("click", function bands(db) {
        svg.call(chart.duration(1000).bands(Math.max(1, chart.bands() + db)));
      });
});

Version data entries

25 entries across 25 versions & 1 rubygems

Version Path
picky-statistics-4.5.0 lib/picky-statistics/application/javascripts/d3/examples/horizon/horizon.js
picky-statistics-4.4.2 lib/picky-statistics/application/javascripts/d3/examples/horizon/horizon.js
picky-statistics-4.4.1 lib/picky-statistics/application/javascripts/d3/examples/horizon/horizon.js
picky-statistics-4.4.0 lib/picky-statistics/application/javascripts/d3/examples/horizon/horizon.js
picky-statistics-4.3.2 lib/picky-statistics/application/javascripts/d3/examples/horizon/horizon.js
picky-statistics-4.3.1 lib/picky-statistics/application/javascripts/d3/examples/horizon/horizon.js
picky-statistics-4.3.0 lib/picky-statistics/application/javascripts/d3/examples/horizon/horizon.js
picky-statistics-4.2.4 lib/picky-statistics/application/javascripts/d3/examples/horizon/horizon.js
picky-statistics-4.2.3 lib/picky-statistics/application/javascripts/d3/examples/horizon/horizon.js
picky-statistics-4.2.2 lib/picky-statistics/application/javascripts/d3/examples/horizon/horizon.js
picky-statistics-4.2.1 lib/picky-statistics/application/javascripts/d3/examples/horizon/horizon.js
picky-statistics-4.2.0 lib/picky-statistics/application/javascripts/d3/examples/horizon/horizon.js
picky-statistics-4.1.0 lib/picky-statistics/application/javascripts/d3/examples/horizon/horizon.js
picky-statistics-4.0.9 lib/picky-statistics/application/javascripts/d3/examples/horizon/horizon.js
picky-statistics-4.0.8 lib/picky-statistics/application/javascripts/d3/examples/horizon/horizon.js
picky-statistics-4.0.7 lib/picky-statistics/application/javascripts/d3/examples/horizon/horizon.js
picky-statistics-4.0.6 lib/picky-statistics/application/javascripts/d3/examples/horizon/horizon.js
picky-statistics-4.0.5 lib/picky-statistics/application/javascripts/d3/examples/horizon/horizon.js
picky-statistics-4.0.4 lib/picky-statistics/application/javascripts/d3/examples/horizon/horizon.js
picky-statistics-4.0.3 lib/picky-statistics/application/javascripts/d3/examples/horizon/horizon.js