Sha256: af45f15fe2fe5e1ac29e6dd806f288f5ae9bd67b57fc62fbde1eac18431de3b8

Contents?: true

Size: 1.75 KB

Versions: 1

Compression:

Stored size: 1.75 KB

Contents

<html>
  <head>
    <title>Stacked Area Chart</title>
    <script type="text/javascript" src="../../protovis-d3.3.js"></script>
  </head>
  <body>
    <script type="text/javascript+protovis">

var data = pv.range(4).map(function()
        pv.range(0, 10, .1).map(function(x) {
            return {x: x, y: Math.sin(x) + Math.random() * .5 + 2};
          }));

var i = -1, // mouseover index
    w = 400,
    h = 200,
    x = pv.Scale.linear(0, 9.9).range(0, w),
    y = pv.Scale.linear(0, 14).range(0, h);

var vis = new pv.Panel()
    .width(w)
    .height(h)
    .bottom(20)
    .left(20)
    .right(30)
    .top(5)
    .events("all")
    .event("mousemove", pv.Behavior.point(Infinity).collapse("y"));

var area = vis.add(pv.Layout.Stack)
    .layers(data)
    .x(function(d) x(d.x))
    .y(function(d) y(d.y))
  .layer.add(pv.Area);

/* A transparent overlay to avoid label clipping. */
vis.add(pv.Panel)
    .data(data)
  .add(pv.Area)
    .extend(area)
    .fillStyle(null)
    .event("point", function() (i = this.index, this.parent))
    .event("unpoint", function() (i = -1, this.parent))
  .add(pv.Rule)
    .visible(function() i == this.index)
    .strokeStyle("black")
  .anchor("top").add(pv.Rule)
    .width(6)
    .anchorTarget()
  .anchor("right").add(pv.Label)
    .text(function(d) d.y.toFixed(3));

vis.add(pv.Rule)
    .data(x.ticks())
    .visible(function(d) d)
    .left(x)
    .strokeStyle("rgba(128,128,128,.1)")
  .anchor("bottom").add(pv.Label)
    .text(function(d) d.toFixed());

vis.add(pv.Rule)
    .data(y.ticks())
    .visible(function() !(this.index % 2))
    .bottom(y)
    .strokeStyle(function(d) d ? "rgba(128,128,128,.2)" : "#000")
  .anchor("left").add(pv.Label)
    .text(function(d) d.toFixed());

vis.render();

    </script>
  </body>
</html>

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
rubyvis-0.1.1 vendor/tests/behavior/point-area-stacked.html