Sha256: 6ba5805dfa41e59f35f09653942059a2a2f024420cd40e60ff40d58e85a997c8

Contents?: true

Size: 1.87 KB

Versions: 4

Compression:

Stored size: 1.87 KB

Contents

var assert = require("../assert"),
    _ = require("../../");

module.exports = {
  topic: function(d3) {
    var callback = this.callback,
        dd = [],
        ii = [],
        tt = [],
        vv = [];

    var s = d3.select("body").html("").append("div").selectAll("div")
        .data(["red", "green"])
      .enter().append("div")
        .attr("color", function(d, i) { return i ? "#008000" : "#ff0000"; });

    var t = s.transition()
        .attrTween("color", tween);

    function tween(d, i, v) {
      dd.push(d);
      ii.push(i);
      vv.push(v);
      if (tt.push(this) >= 2) callback(null, {
        selection: s,
        transition: t,
        data: dd,
        index: ii,
        value: vv,
        context: tt
      });
      return i && _.interpolateHsl(v, "blue");
    }
  },

  "defines the corresponding attr tween": function(result) {
    assert.typeOf(result.transition.tween("attr.color"), "function");
  },
  "invokes the tween function": function(result) {
    assert.deepEqual(result.data, ["red", "green"], "expected data, got {actual}");
    assert.deepEqual(result.index, [0, 1], "expected data, got {actual}");
    assert.deepEqual(result.value, ["#ff0000", "#008000"], "expected value, got {actual}");
    assert.domEqual(result.context[0], result.selection[0][0], "expected this, got {actual}");
    assert.domEqual(result.context[1], result.selection[0][1], "expected this, got {actual}");
  },

  "end": {
    topic: function(result) {
      var callback = this.callback;
      result.transition.each("end", function(d, i) { if (i >= 1) callback(null, result); });
    },
    "uses the returned interpolator": function(result) {
      assert.equal(result.selection[0][1].getAttribute("color"), "#0000ff");
    },
    "does nothing if the interpolator is falsey": function(result) {
      assert.equal(result.selection[0][0].getAttribute("color"), "#ff0000");
    }
  }
};

Version data entries

4 entries across 4 versions & 2 rubygems

Version Path
stripchart-0.0.3 lib/stripchart/public/components/d3/test/transition/transition-test-attrTween.js
stripmem-0.0.3 lib/stripmem/public/components/d3/test/transition/transition-test-attrTween.js
stripmem-0.0.2 lib/stripmem/public/components/d3/test/transition/transition-test-attrTween.js
stripmem-0.0.1 lib/stripmem/public/components/d3/test/transition/transition-test-attrTween.js