toolkit/exemples/couple/javascript/d3/src/svg/area.js
changeset 47 c0b4a8b5a012
equal deleted inserted replaced
46:efd9c589177a 47:c0b4a8b5a012
       
     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       interpolate,
       
     7       i0,
       
     8       i1,
       
     9       tension = .7;
       
    10 
       
    11   function area(d) {
       
    12     if (d.length < 1) return null;
       
    13     var points0 = d3_svg_linePoints(this, d, x0, y0),
       
    14         points1 = d3_svg_linePoints(this, d, x0 === x1 ? d3_svg_areaX(points0) : x1, y0 === y1 ? d3_svg_areaY(points0) : y1);
       
    15     return "M" + i0(projection(points1), tension)
       
    16          + "L" + i1(projection(points0.reverse()), tension)
       
    17          + "Z";
       
    18   }
       
    19 
       
    20   area.x = function(x) {
       
    21     if (!arguments.length) return x1;
       
    22     x0 = x1 = x;
       
    23     return area;
       
    24   };
       
    25 
       
    26   area.x0 = function(x) {
       
    27     if (!arguments.length) return x0;
       
    28     x0 = x;
       
    29     return area;
       
    30   };
       
    31 
       
    32   area.x1 = function(x) {
       
    33     if (!arguments.length) return x1;
       
    34     x1 = x;
       
    35     return area;
       
    36   };
       
    37 
       
    38   area.y = function(y) {
       
    39     if (!arguments.length) return y1;
       
    40     y0 = y1 = y;
       
    41     return area;
       
    42   };
       
    43 
       
    44   area.y0 = function(y) {
       
    45     if (!arguments.length) return y0;
       
    46     y0 = y;
       
    47     return area;
       
    48   };
       
    49 
       
    50   area.y1 = function(y) {
       
    51     if (!arguments.length) return y1;
       
    52     y1 = y;
       
    53     return area;
       
    54   };
       
    55 
       
    56   area.interpolate = function(x) {
       
    57     if (!arguments.length) return interpolate;
       
    58     i0 = d3_svg_lineInterpolators[interpolate = x];
       
    59     i1 = i0.reverse || i0;
       
    60     return area;
       
    61   };
       
    62 
       
    63   area.tension = function(x) {
       
    64     if (!arguments.length) return tension;
       
    65     tension = x;
       
    66     return area;
       
    67   };
       
    68 
       
    69   return area.interpolate("linear");
       
    70 }
       
    71 
       
    72 d3_svg_lineStepBefore.reverse = d3_svg_lineStepAfter;
       
    73 d3_svg_lineStepAfter.reverse = d3_svg_lineStepBefore;
       
    74 
       
    75 d3.svg.area = function() {
       
    76   return d3_svg_area(Object);
       
    77 };
       
    78 
       
    79 function d3_svg_areaX(points) {
       
    80   return function(d, i) {
       
    81     return points[i][0];
       
    82   };
       
    83 }
       
    84 
       
    85 function d3_svg_areaY(points) {
       
    86   return function(d, i) {
       
    87     return points[i][1];
       
    88   };
       
    89 }