UNPKG

rumble-charts

Version:

Truly declarative React charts components

49 lines (46 loc) 2.55 kB
import { __rest } from './external/tslib/tslib.es6.js'; import React, { useMemo } from 'react'; import './helpers/colorFunc.js'; import 'd3-shape'; import 'd3-ease'; import { isUndefined } from './helpers/isUndefined.js'; var counter = 0; /** * Wrapper around standard svg linearGradient and radialGradient. */ function Gradient(_a) { var _b = _a.type, type = _b === void 0 ? 'linear' : _b, _c = _a.idPrefix, idPrefix = _c === void 0 ? 'chartGradient' : _c, _d = _a.gradientUnits, gradientUnits = _d === void 0 ? 'objectBoundingBox' : _d, _e = _a.spreadMethod, spreadMethod = _e === void 0 ? 'pad' : _e, // for linear gradient _f = _a.from, // for linear gradient from = _f === void 0 ? ['0%', '0%'] : _f, _g = _a.to, to = _g === void 0 ? ['100%', '0%'] : _g, // for radial gradient _h = _a.center, // for radial gradient center = _h === void 0 ? ['50%', '50%'] : _h, props = __rest(_a, ["type", "idPrefix", "gradientUnits", "spreadMethod", "from", "to", "center"]); var id = useMemo(function () { if (props.id) { return props.id; } counter++; return idPrefix + counter; }, [props.id, idPrefix]); if (type === 'radial') { var focalPoint = props.focalPoint, radius = props.radius, gradientTransform = props.gradientTransform, cx = props.cx, cy = props.cy, fx = props.fx, fy = props.fy, r = props.r; var _cx = isUndefined(cx) ? (center && center[0]) : cx; var _cy = isUndefined(cy) ? (center && center[1]) : cy; var _fx = isUndefined(fx) ? (focalPoint && focalPoint[0]) : fx; var _fy = isUndefined(fy) ? (focalPoint && focalPoint[1]) : fy; var _r = isUndefined(r) ? radius : r; return React.createElement("radialGradient", { id: id, gradientUnits: gradientUnits, gradientTransform: gradientTransform, spreadMethod: spreadMethod, cx: _cx, cy: _cy, fx: _fx, fy: _fy, r: _r }, props.children); } else { var gradientTransform = props.gradientTransform, x1 = props.x1, y1 = props.y1, x2 = props.x2, y2 = props.y2; var _x1 = isUndefined(x1) ? (from && from[0]) : x1; var _y1 = isUndefined(y1) ? (from && from[1]) : y1; var _x2 = isUndefined(x2) ? (to && to[0]) : x2; var _y2 = isUndefined(y2) ? (to && to[1]) : y2; return React.createElement("linearGradient", { id: id, gradientUnits: gradientUnits, gradientTransform: gradientTransform, spreadMethod: spreadMethod, x1: _x1, y1: _y1, x2: _x2, y2: _y2 }, props.children); } } export { Gradient };