victory-core
Version:
81 lines (80 loc) • 3.21 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.Point = void 0;
var _react = _interopRequireDefault(require("react"));
var _defaults = _interopRequireDefault(require("lodash/defaults"));
var Helpers = _interopRequireWildcard(require("../victory-util/helpers"));
var pathHelpers = _interopRequireWildcard(require("../victory-util/point-path-helpers"));
var UserProps = _interopRequireWildcard(require("../victory-util/user-props"));
var _path = require("./path");
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; }
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
const getPath = props => {
const {
x,
y,
size,
symbol
} = props;
if (props.getPath) {
return props.getPath(x, y, size);
}
const pathFunctions = pathHelpers;
const symbolFunction = typeof pathFunctions[symbol] === "function" ? pathFunctions[symbol] : pathFunctions.circle;
return symbolFunction(x, y, size);
};
const evaluateProps = props => {
/**
* Potential evaluated props are:
* `ariaLabel`
* `desc`
* `id`
* `size`
* `style`
* `symbol`
* `tabIndex`
*/
const ariaLabel = Helpers.evaluateProp(props.ariaLabel, props);
const desc = Helpers.evaluateProp(props.desc, props);
const id = Helpers.evaluateProp(props.id, props);
const size = Helpers.evaluateProp(props.size, props);
const style = Helpers.evaluateStyle(props.style, props);
const symbol = Helpers.evaluateProp(props.symbol, props);
const tabIndex = Helpers.evaluateProp(props.tabIndex, props);
return Object.assign({}, props, {
ariaLabel,
desc,
id,
size,
style,
symbol,
tabIndex
});
};
const defaultProps = {
pathComponent: /*#__PURE__*/_react.default.createElement(_path.Path, null),
role: "presentation",
shapeRendering: "auto"
};
const Point = initialProps => {
const props = evaluateProps((0, _defaults.default)({}, initialProps, defaultProps));
const userProps = UserProps.getSafeUserProps(props);
return /*#__PURE__*/_react.default.cloneElement(props.pathComponent, {
...props.events,
"aria-label": props.ariaLabel,
d: getPath(props),
style: props.style,
desc: props.desc,
tabIndex: props.tabIndex,
role: props.role,
shapeRendering: props.shapeRendering,
className: props.className,
transform: props.transform,
clipPath: props.clipPath,
...userProps
});
};
exports.Point = Point;