recharts
Version:
React charts
56 lines (52 loc) • 1.95 kB
JavaScript
function _extends() { return _extends = Object.assign ? Object.assign.bind() : function (n) { for (var e = 1; e < arguments.length; e++) { var t = arguments[e]; for (var r in t) ({}).hasOwnProperty.call(t, r) && (n[r] = t[r]); } return n; }, _extends.apply(null, arguments); }
import * as React from 'react';
import { clsx } from '../util/clsx';
import { FillObjectPaint, getShapeBounds } from '../fill/fillDefinitions';
import { adaptEventHandlers } from '../util/types';
import { svgPropertiesNoEvents } from '../util/svgPropertiesNoEvents';
import { isNumber } from '../util/DataUtils';
/**
* @public
*/
/**
* The props of the inner renderer, which gets the `fill` as a color or a `url(#…)` reference.
*/
var DotImpl = props => {
var cx = props.cx,
cy = props.cy,
r = props.r,
className = props.className;
var layerClass = clsx('recharts-dot', className);
if (isNumber(cx) && isNumber(cy) && isNumber(r)) {
return /*#__PURE__*/React.createElement("circle", _extends({}, svgPropertiesNoEvents(props), adaptEventHandlers(props), {
className: layerClass,
cx: cx,
cy: cy,
r: r
}));
}
return null;
};
/**
* Renders a dot in the chart.
*
* This component accepts X and Y coordinates in pixels.
* If you need to position the rectangle based on your chart's data,
* consider using the {@link ReferenceDot} component instead.
*
* @param props
* @constructor
* @public
*/
export var Dot = props => {
var fill = props.fill;
// spreading all props first keeps `fill` in its place among the attributes
return fill != null && typeof fill === 'object' ? /*#__PURE__*/React.createElement(FillObjectPaint, {
fill: fill,
bounds: getShapeBounds(2 * Number(props.r), 2 * Number(props.r))
}, paint => /*#__PURE__*/React.createElement(DotImpl, _extends({}, props, {
fill: paint
}))) : /*#__PURE__*/React.createElement(DotImpl, _extends({}, props, {
fill: fill
}));
};