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