UNPKG

victory-core

Version:
60 lines (59 loc) 2.82 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.getLineFunction = exports.getInterpolationFunction = void 0; var d3Shape = _interopRequireWildcard(require("victory-vendor/d3-shape")); function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); } function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && Object.prototype.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; } const defined = d => { const y = d._y1 !== undefined ? d._y1 : d._y; return y !== null && y !== undefined && d._y0 !== null; }; const getXAccessor = scale => { return d => scale.x(d._x1 !== undefined ? d._x1 : d._x); }; const getYAccessor = scale => { return d => scale.y(d._y1 !== undefined ? d._y1 : d._y); }; const getAngleAccessor = scale => { return d => { const x = scale.x(d._x1 !== undefined ? d._x1 : d._x); return -1 * x + Math.PI / 2; }; }; const toNewName = interpolation => { // d3 shape changed the naming scheme for interpolators from "basis" -> "curveBasis" etc. const capitalize = s => s && s[0].toUpperCase() + s.slice(1); return `curve${capitalize(interpolation)}`; }; const toNewNameClosed = interpolation => { return `${toNewName(interpolation)}Closed`; }; const getInterpolationFunction = props => { const { interpolation } = props; if (typeof interpolation === "function") { return interpolation; } if (typeof interpolation === "string") { const { polar, openCurve = !polar } = props; const interpolationName = !openCurve ? toNewNameClosed(interpolation) : toNewName(interpolation); return d3Shape[interpolationName]; } return d3Shape.curveLinear; }; exports.getInterpolationFunction = getInterpolationFunction; const getLineFunction = props => { const { polar, scale, horizontal } = props; return polar ? d3Shape.lineRadial().defined(defined).curve(getInterpolationFunction(props)).angle(getAngleAccessor(scale)).radius(getYAccessor(scale)) : d3Shape.line().defined(defined).curve(getInterpolationFunction(props)).x(horizontal ? getYAccessor(scale) : getXAccessor(scale)).y(horizontal ? getXAccessor(scale) : getYAccessor(scale)); }; exports.getLineFunction = getLineFunction;