~bcsaller/juju-gui/update-reductions

« back to all changes in this revision

Viewing changes to lib/d3/src/svg/area.js

  • Committer: kapil.foss at gmail
  • Date: 2012-07-13 18:45:59 UTC
  • Revision ID: kapil.foss@gmail.com-20120713184559-2xl7be17egsrz0c9
reshape

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
function d3_svg_area(projection) {
2
 
  var x0 = d3_svg_lineX,
3
 
      x1 = d3_svg_lineX,
4
 
      y0 = 0,
5
 
      y1 = d3_svg_lineY,
6
 
      defined = d3_true,
7
 
      interpolate = d3_svg_lineInterpolatorDefault,
8
 
      i0 = d3_svg_lineLinear,
9
 
      i1 = d3_svg_lineLinear,
10
 
      L = "L",
11
 
      tension = .7;
12
 
 
13
 
  function area(data) {
14
 
    var segments = [],
15
 
        points0 = [],
16
 
        points1 = [],
17
 
        i = -1,
18
 
        n = data.length,
19
 
        d,
20
 
        fx0 = d3_functor(x0),
21
 
        fy0 = d3_functor(y0),
22
 
        fx1 = x0 === x1 ? function() { return x; } : d3_functor(x1),
23
 
        fy1 = y0 === y1 ? function() { return y; } : d3_functor(y1),
24
 
        x,
25
 
        y;
26
 
 
27
 
    function segment() {
28
 
      segments.push("M", i0(projection(points1), tension),
29
 
          L, i1(projection(points0.reverse()), tension),
30
 
          "Z");
31
 
    }
32
 
 
33
 
    while (++i < n) {
34
 
      if (defined.call(this, d = data[i], i)) {
35
 
        points0.push([x = +fx0.call(this, d, i), y = +fy0.call(this, d, i)]);
36
 
        points1.push([+fx1.call(this, d, i), +fy1.call(this, d, i)]);
37
 
      } else if (points0.length) {
38
 
        segment();
39
 
        points0 = [];
40
 
        points1 = [];
41
 
      }
42
 
    }
43
 
 
44
 
    if (points0.length) segment();
45
 
 
46
 
    return segments.length ? segments.join("") : null;
47
 
  }
48
 
 
49
 
  area.x = function(_) {
50
 
    if (!arguments.length) return x1;
51
 
    x0 = x1 = _;
52
 
    return area;
53
 
  };
54
 
 
55
 
  area.x0 = function(_) {
56
 
    if (!arguments.length) return x0;
57
 
    x0 = _;
58
 
    return area;
59
 
  };
60
 
 
61
 
  area.x1 = function(_) {
62
 
    if (!arguments.length) return x1;
63
 
    x1 = _;
64
 
    return area;
65
 
  };
66
 
 
67
 
  area.y = function(_) {
68
 
    if (!arguments.length) return y1;
69
 
    y0 = y1 = _;
70
 
    return area;
71
 
  };
72
 
 
73
 
  area.y0 = function(_) {
74
 
    if (!arguments.length) return y0;
75
 
    y0 = _;
76
 
    return area;
77
 
  };
78
 
 
79
 
  area.y1 = function(_) {
80
 
    if (!arguments.length) return y1;
81
 
    y1 = _;
82
 
    return area;
83
 
  };
84
 
 
85
 
  area.defined  = function(_) {
86
 
    if (!arguments.length) return defined;
87
 
    defined = _;
88
 
    return area;
89
 
  };
90
 
 
91
 
  area.interpolate = function(_) {
92
 
    if (!arguments.length) return interpolate;
93
 
    if (!d3_svg_lineInterpolators.has(_ += "")) _ = d3_svg_lineInterpolatorDefault;
94
 
    i0 = d3_svg_lineInterpolators.get(interpolate = _);
95
 
    i1 = i0.reverse || i0;
96
 
    L = /-closed$/.test(_) ? "M" : "L";
97
 
    return area;
98
 
  };
99
 
 
100
 
  area.tension = function(_) {
101
 
    if (!arguments.length) return tension;
102
 
    tension = _;
103
 
    return area;
104
 
  };
105
 
 
106
 
  return area;
107
 
}
108
 
 
109
 
d3_svg_lineStepBefore.reverse = d3_svg_lineStepAfter;
110
 
d3_svg_lineStepAfter.reverse = d3_svg_lineStepBefore;
111
 
 
112
 
d3.svg.area = function() {
113
 
  return d3_svg_area(Object);
114
 
};