| 1 | "use strict";
|
|---|
| 2 |
|
|---|
| 3 | Object.defineProperty(exports, "__esModule", {
|
|---|
| 4 | value: true
|
|---|
| 5 | });
|
|---|
| 6 | exports.default = _default;
|
|---|
| 7 | var _index = require("../../../lib-vendor/d3-path/src/index.js");
|
|---|
| 8 | var _array = _interopRequireDefault(require("./array.js"));
|
|---|
| 9 | var _constant = _interopRequireDefault(require("./constant.js"));
|
|---|
| 10 | var _linear = _interopRequireDefault(require("./curve/linear.js"));
|
|---|
| 11 | var _line = _interopRequireDefault(require("./line.js"));
|
|---|
| 12 | var _point = require("./point.js");
|
|---|
| 13 | function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|---|
| 14 | function _default(x0, y0, y1) {
|
|---|
| 15 | var x1 = null,
|
|---|
| 16 | defined = (0, _constant.default)(true),
|
|---|
| 17 | context = null,
|
|---|
| 18 | curve = _linear.default,
|
|---|
| 19 | output = null;
|
|---|
| 20 | x0 = typeof x0 === "function" ? x0 : x0 === undefined ? _point.x : (0, _constant.default)(+x0);
|
|---|
| 21 | y0 = typeof y0 === "function" ? y0 : y0 === undefined ? (0, _constant.default)(0) : (0, _constant.default)(+y0);
|
|---|
| 22 | y1 = typeof y1 === "function" ? y1 : y1 === undefined ? _point.y : (0, _constant.default)(+y1);
|
|---|
| 23 | function area(data) {
|
|---|
| 24 | var i,
|
|---|
| 25 | j,
|
|---|
| 26 | k,
|
|---|
| 27 | n = (data = (0, _array.default)(data)).length,
|
|---|
| 28 | d,
|
|---|
| 29 | defined0 = false,
|
|---|
| 30 | buffer,
|
|---|
| 31 | x0z = new Array(n),
|
|---|
| 32 | y0z = new Array(n);
|
|---|
| 33 | if (context == null) output = curve(buffer = (0, _index.path)());
|
|---|
| 34 | for (i = 0; i <= n; ++i) {
|
|---|
| 35 | if (!(i < n && defined(d = data[i], i, data)) === defined0) {
|
|---|
| 36 | if (defined0 = !defined0) {
|
|---|
| 37 | j = i;
|
|---|
| 38 | output.areaStart();
|
|---|
| 39 | output.lineStart();
|
|---|
| 40 | } else {
|
|---|
| 41 | output.lineEnd();
|
|---|
| 42 | output.lineStart();
|
|---|
| 43 | for (k = i - 1; k >= j; --k) {
|
|---|
| 44 | output.point(x0z[k], y0z[k]);
|
|---|
| 45 | }
|
|---|
| 46 | output.lineEnd();
|
|---|
| 47 | output.areaEnd();
|
|---|
| 48 | }
|
|---|
| 49 | }
|
|---|
| 50 | if (defined0) {
|
|---|
| 51 | x0z[i] = +x0(d, i, data), y0z[i] = +y0(d, i, data);
|
|---|
| 52 | output.point(x1 ? +x1(d, i, data) : x0z[i], y1 ? +y1(d, i, data) : y0z[i]);
|
|---|
| 53 | }
|
|---|
| 54 | }
|
|---|
| 55 | if (buffer) return output = null, buffer + "" || null;
|
|---|
| 56 | }
|
|---|
| 57 | function arealine() {
|
|---|
| 58 | return (0, _line.default)().defined(defined).curve(curve).context(context);
|
|---|
| 59 | }
|
|---|
| 60 | area.x = function (_) {
|
|---|
| 61 | return arguments.length ? (x0 = typeof _ === "function" ? _ : (0, _constant.default)(+_), x1 = null, area) : x0;
|
|---|
| 62 | };
|
|---|
| 63 | area.x0 = function (_) {
|
|---|
| 64 | return arguments.length ? (x0 = typeof _ === "function" ? _ : (0, _constant.default)(+_), area) : x0;
|
|---|
| 65 | };
|
|---|
| 66 | area.x1 = function (_) {
|
|---|
| 67 | return arguments.length ? (x1 = _ == null ? null : typeof _ === "function" ? _ : (0, _constant.default)(+_), area) : x1;
|
|---|
| 68 | };
|
|---|
| 69 | area.y = function (_) {
|
|---|
| 70 | return arguments.length ? (y0 = typeof _ === "function" ? _ : (0, _constant.default)(+_), y1 = null, area) : y0;
|
|---|
| 71 | };
|
|---|
| 72 | area.y0 = function (_) {
|
|---|
| 73 | return arguments.length ? (y0 = typeof _ === "function" ? _ : (0, _constant.default)(+_), area) : y0;
|
|---|
| 74 | };
|
|---|
| 75 | area.y1 = function (_) {
|
|---|
| 76 | return arguments.length ? (y1 = _ == null ? null : typeof _ === "function" ? _ : (0, _constant.default)(+_), area) : y1;
|
|---|
| 77 | };
|
|---|
| 78 | area.lineX0 = area.lineY0 = function () {
|
|---|
| 79 | return arealine().x(x0).y(y0);
|
|---|
| 80 | };
|
|---|
| 81 | area.lineY1 = function () {
|
|---|
| 82 | return arealine().x(x0).y(y1);
|
|---|
| 83 | };
|
|---|
| 84 | area.lineX1 = function () {
|
|---|
| 85 | return arealine().x(x1).y(y0);
|
|---|
| 86 | };
|
|---|
| 87 | area.defined = function (_) {
|
|---|
| 88 | return arguments.length ? (defined = typeof _ === "function" ? _ : (0, _constant.default)(!!_), area) : defined;
|
|---|
| 89 | };
|
|---|
| 90 | area.curve = function (_) {
|
|---|
| 91 | return arguments.length ? (curve = _, context != null && (output = curve(context)), area) : curve;
|
|---|
| 92 | };
|
|---|
| 93 | area.context = function (_) {
|
|---|
| 94 | return arguments.length ? (_ == null ? context = output = null : output = curve(context = _), area) : context;
|
|---|
| 95 | };
|
|---|
| 96 | return area;
|
|---|
| 97 | } |
|---|