| 1 | var _excluded = ["id"],
|
|---|
| 2 | _excluded2 = ["onMouseEnter", "onClick", "onMouseLeave"],
|
|---|
| 3 | _excluded3 = ["animationBegin", "animationDuration", "animationEasing", "hide", "isAnimationActive", "legendType", "lineJointType", "lineType", "shape", "xAxisId", "yAxisId", "zAxisId"];
|
|---|
| 4 | function _objectWithoutProperties(e, t) { if (null == e) return {}; var o, r, i = _objectWithoutPropertiesLoose(e, t); if (Object.getOwnPropertySymbols) { var n = Object.getOwnPropertySymbols(e); for (r = 0; r < n.length; r++) o = n[r], -1 === t.indexOf(o) && {}.propertyIsEnumerable.call(e, o) && (i[o] = e[o]); } return i; }
|
|---|
| 5 | function _objectWithoutPropertiesLoose(r, e) { if (null == r) return {}; var t = {}; for (var n in r) if ({}.hasOwnProperty.call(r, n)) { if (-1 !== e.indexOf(n)) continue; t[n] = r[n]; } return t; }
|
|---|
| 6 | 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); }
|
|---|
| 7 | function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|---|
| 8 | function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|---|
| 9 | function _defineProperty(e, r, t) { return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: !0, configurable: !0, writable: !0 }) : e[r] = t, e; }
|
|---|
| 10 | function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == typeof i ? i : i + ""; }
|
|---|
| 11 | function _toPrimitive(t, r) { if ("object" != typeof t || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != typeof i) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
|
|---|
| 12 | import * as React from 'react';
|
|---|
| 13 | import { useCallback, useMemo, useRef, useState } from 'react';
|
|---|
| 14 | import { clsx } from 'clsx';
|
|---|
| 15 | import { Layer } from '../container/Layer';
|
|---|
| 16 | import { CartesianLabelListContextProvider, LabelListFromLabelProp } from '../component/LabelList';
|
|---|
| 17 | import { findAllByType } from '../util/ReactUtils';
|
|---|
| 18 | import { Curve } from '../shape/Curve';
|
|---|
| 19 | import { Cell } from '../component/Cell';
|
|---|
| 20 | import { getLinearRegression, interpolate, isNullish } from '../util/DataUtils';
|
|---|
| 21 | import { getCateCoordinateOfLine, getTooltipNameProp, getValueByDataKey } from '../util/ChartUtils';
|
|---|
| 22 | import { adaptEventsOfChild, isNonEmptyArray } from '../util/types';
|
|---|
| 23 | import { ScatterSymbol } from '../util/ScatterUtils';
|
|---|
| 24 | import { useMouseClickItemDispatch, useMouseEnterItemDispatch, useMouseLeaveItemDispatch } from '../context/tooltipContext';
|
|---|
| 25 | import { SetTooltipEntrySettings } from '../state/SetTooltipEntrySettings';
|
|---|
| 26 | import { SetErrorBarContext } from '../context/ErrorBarContext';
|
|---|
| 27 | import { GraphicalItemClipPath, useNeedsClip } from './GraphicalItemClipPath';
|
|---|
| 28 | import { selectScatterPoints } from '../state/selectors/scatterSelectors';
|
|---|
| 29 | import { useAppSelector } from '../state/hooks';
|
|---|
| 30 | import { implicitZAxis } from '../state/selectors/axisSelectors';
|
|---|
| 31 | import { useIsPanorama } from '../context/PanoramaContext';
|
|---|
| 32 | import { selectActiveTooltipIndex } from '../state/selectors/tooltipSelectors';
|
|---|
| 33 | import { SetLegendPayload } from '../state/SetLegendPayload';
|
|---|
| 34 | import { DATA_ITEM_GRAPHICAL_ITEM_ID_ATTRIBUTE_NAME } from '../util/Constants';
|
|---|
| 35 | import { useAnimationId } from '../util/useAnimationId';
|
|---|
| 36 | import { resolveDefaultProps } from '../util/resolveDefaultProps';
|
|---|
| 37 | import { RegisterGraphicalItemId } from '../context/RegisterGraphicalItemId';
|
|---|
| 38 | import { SetCartesianGraphicalItem } from '../state/SetGraphicalItem';
|
|---|
| 39 | import { svgPropertiesNoEvents, svgPropertiesNoEventsFromUnknown } from '../util/svgPropertiesNoEvents';
|
|---|
| 40 | import { JavascriptAnimate } from '../animation/JavascriptAnimate';
|
|---|
| 41 | import { useViewBox } from '../context/chartLayoutContext';
|
|---|
| 42 | import { ZIndexLayer } from '../zIndex/ZIndexLayer';
|
|---|
| 43 | import { DefaultZIndexes } from '../zIndex/DefaultZIndexes';
|
|---|
| 44 | import { propsAreEqual } from '../util/propsAreEqual';
|
|---|
| 45 |
|
|---|
| 46 | /**
|
|---|
| 47 | * Scatter coordinates are nullable because sometimes the point value is out of the domain,
|
|---|
| 48 | * and we can't compute a valid coordinate for it.
|
|---|
| 49 | *
|
|---|
| 50 | * Scatter -> Symbol ignores points with null cx or cy so those won't render if using the default shapes.
|
|---|
| 51 | * However: the points are exposed via various props and can be used in custom shapes so we keep them around.
|
|---|
| 52 | */
|
|---|
| 53 |
|
|---|
| 54 | /**
|
|---|
| 55 | * Internal props, combination of external props + defaultProps + private Recharts state
|
|---|
| 56 | */
|
|---|
| 57 |
|
|---|
| 58 | /**
|
|---|
| 59 | * External props, intended for end users to fill in
|
|---|
| 60 | */
|
|---|
| 61 |
|
|---|
| 62 | /**
|
|---|
| 63 | * Because of naming conflict, we are forced to ignore certain (valid) SVG attributes.
|
|---|
| 64 | */
|
|---|
| 65 |
|
|---|
| 66 | var computeLegendPayloadFromScatterProps = props => {
|
|---|
| 67 | var {
|
|---|
| 68 | dataKey,
|
|---|
| 69 | name,
|
|---|
| 70 | fill,
|
|---|
| 71 | legendType,
|
|---|
| 72 | hide
|
|---|
| 73 | } = props;
|
|---|
| 74 | return [{
|
|---|
| 75 | inactive: hide,
|
|---|
| 76 | dataKey,
|
|---|
| 77 | type: legendType,
|
|---|
| 78 | color: fill,
|
|---|
| 79 | value: getTooltipNameProp(name, dataKey),
|
|---|
| 80 | payload: props
|
|---|
| 81 | }];
|
|---|
| 82 | };
|
|---|
| 83 | var SetScatterTooltipEntrySettings = /*#__PURE__*/React.memo(_ref => {
|
|---|
| 84 | var {
|
|---|
| 85 | dataKey,
|
|---|
| 86 | points,
|
|---|
| 87 | stroke,
|
|---|
| 88 | strokeWidth,
|
|---|
| 89 | fill,
|
|---|
| 90 | name,
|
|---|
| 91 | hide,
|
|---|
| 92 | tooltipType,
|
|---|
| 93 | id
|
|---|
| 94 | } = _ref;
|
|---|
| 95 | var tooltipEntrySettings = {
|
|---|
| 96 | dataDefinedOnItem: points === null || points === void 0 ? void 0 : points.map(p => p.tooltipPayload),
|
|---|
| 97 | getPosition: index => {
|
|---|
| 98 | var _points$Number;
|
|---|
| 99 | return points === null || points === void 0 || (_points$Number = points[Number(index)]) === null || _points$Number === void 0 ? void 0 : _points$Number.tooltipPosition;
|
|---|
| 100 | },
|
|---|
| 101 | settings: {
|
|---|
| 102 | stroke,
|
|---|
| 103 | strokeWidth,
|
|---|
| 104 | fill,
|
|---|
| 105 | nameKey: undefined,
|
|---|
| 106 | dataKey,
|
|---|
| 107 | name: getTooltipNameProp(name, dataKey),
|
|---|
| 108 | hide,
|
|---|
| 109 | type: tooltipType,
|
|---|
| 110 | color: fill,
|
|---|
| 111 | unit: '',
|
|---|
| 112 | // why doesn't Scatter support unit?
|
|---|
| 113 | graphicalItemId: id
|
|---|
| 114 | }
|
|---|
| 115 | };
|
|---|
| 116 | return /*#__PURE__*/React.createElement(SetTooltipEntrySettings, {
|
|---|
| 117 | tooltipEntrySettings: tooltipEntrySettings
|
|---|
| 118 | });
|
|---|
| 119 | });
|
|---|
| 120 | function ScatterLine(_ref2) {
|
|---|
| 121 | var {
|
|---|
| 122 | points,
|
|---|
| 123 | props
|
|---|
| 124 | } = _ref2;
|
|---|
| 125 | var {
|
|---|
| 126 | line,
|
|---|
| 127 | lineType,
|
|---|
| 128 | lineJointType
|
|---|
| 129 | } = props;
|
|---|
| 130 | if (!line) {
|
|---|
| 131 | return null;
|
|---|
| 132 | }
|
|---|
| 133 | var scatterProps = svgPropertiesNoEvents(props);
|
|---|
| 134 | var customLineProps = svgPropertiesNoEventsFromUnknown(line);
|
|---|
| 135 | var linePoints, lineItem;
|
|---|
| 136 | if (lineType === 'joint') {
|
|---|
| 137 | linePoints = points.map(entry => {
|
|---|
| 138 | var _entry$cx, _entry$cy;
|
|---|
| 139 | return {
|
|---|
| 140 | x: (_entry$cx = entry.cx) !== null && _entry$cx !== void 0 ? _entry$cx : null,
|
|---|
| 141 | y: (_entry$cy = entry.cy) !== null && _entry$cy !== void 0 ? _entry$cy : null
|
|---|
| 142 | };
|
|---|
| 143 | });
|
|---|
| 144 | } else if (lineType === 'fitting') {
|
|---|
| 145 | var {
|
|---|
| 146 | xmin,
|
|---|
| 147 | xmax,
|
|---|
| 148 | a,
|
|---|
| 149 | b
|
|---|
| 150 | } = getLinearRegression(points);
|
|---|
| 151 | var linearExp = x => a * x + b;
|
|---|
| 152 | linePoints = [{
|
|---|
| 153 | x: xmin,
|
|---|
| 154 | y: linearExp(xmin)
|
|---|
| 155 | }, {
|
|---|
| 156 | x: xmax,
|
|---|
| 157 | y: linearExp(xmax)
|
|---|
| 158 | }];
|
|---|
| 159 | }
|
|---|
| 160 | var lineProps = _objectSpread(_objectSpread(_objectSpread({}, scatterProps), {}, {
|
|---|
| 161 | // @ts-expect-error customLineProps is contributing unknown props
|
|---|
| 162 | fill: 'none',
|
|---|
| 163 | // @ts-expect-error customLineProps is contributing unknown props
|
|---|
| 164 | stroke: scatterProps && scatterProps.fill
|
|---|
| 165 | }, customLineProps), {}, {
|
|---|
| 166 | // @ts-expect-error linePoints is used before it is assigned (???)
|
|---|
| 167 | points: linePoints
|
|---|
| 168 | });
|
|---|
| 169 | if (/*#__PURE__*/React.isValidElement(line)) {
|
|---|
| 170 | lineItem = /*#__PURE__*/React.cloneElement(line, lineProps);
|
|---|
| 171 | } else if (typeof line === 'function') {
|
|---|
| 172 | lineItem = line(lineProps);
|
|---|
| 173 | } else {
|
|---|
| 174 | lineItem = /*#__PURE__*/React.createElement(Curve, _extends({}, lineProps, {
|
|---|
| 175 | type: lineJointType
|
|---|
| 176 | }));
|
|---|
| 177 | }
|
|---|
| 178 | return /*#__PURE__*/React.createElement(Layer, {
|
|---|
| 179 | className: "recharts-scatter-line",
|
|---|
| 180 | key: "recharts-scatter-line"
|
|---|
| 181 | }, lineItem);
|
|---|
| 182 | }
|
|---|
| 183 | function ScatterLabelListProvider(_ref3) {
|
|---|
| 184 | var {
|
|---|
| 185 | showLabels,
|
|---|
| 186 | points,
|
|---|
| 187 | children
|
|---|
| 188 | } = _ref3;
|
|---|
| 189 | var chartViewBox = useViewBox();
|
|---|
| 190 | var labelListEntries = useMemo(() => {
|
|---|
| 191 | return points === null || points === void 0 ? void 0 : points.map(point => {
|
|---|
| 192 | var _point$x, _point$y;
|
|---|
| 193 | var viewBox = {
|
|---|
| 194 | /*
|
|---|
| 195 | * Scatter label uses x and y as the reference point for the label,
|
|---|
| 196 | * not cx and cy.
|
|---|
| 197 | */
|
|---|
| 198 | x: (_point$x = point.x) !== null && _point$x !== void 0 ? _point$x : 0,
|
|---|
| 199 | /*
|
|---|
| 200 | * Scatter label uses x and y as the reference point for the label,
|
|---|
| 201 | * not cx and cy.
|
|---|
| 202 | */
|
|---|
| 203 | y: (_point$y = point.y) !== null && _point$y !== void 0 ? _point$y : 0,
|
|---|
| 204 | width: point.width,
|
|---|
| 205 | height: point.height,
|
|---|
| 206 | lowerWidth: point.width,
|
|---|
| 207 | upperWidth: point.width
|
|---|
| 208 | };
|
|---|
| 209 | return _objectSpread(_objectSpread({}, viewBox), {}, {
|
|---|
| 210 | /*
|
|---|
| 211 | * Here we put undefined because Scatter shows two values usually, one for X and one for Y.
|
|---|
| 212 | * LabelList will see this undefined and will use its own `dataKey` prop to determine which value to show,
|
|---|
| 213 | * using the payload below.
|
|---|
| 214 | */
|
|---|
| 215 | value: undefined,
|
|---|
| 216 | payload: point.payload,
|
|---|
| 217 | viewBox,
|
|---|
| 218 | parentViewBox: chartViewBox,
|
|---|
| 219 | fill: undefined
|
|---|
| 220 | });
|
|---|
| 221 | });
|
|---|
| 222 | }, [chartViewBox, points]);
|
|---|
| 223 | return /*#__PURE__*/React.createElement(CartesianLabelListContextProvider, {
|
|---|
| 224 | value: showLabels ? labelListEntries : undefined
|
|---|
| 225 | }, children);
|
|---|
| 226 | }
|
|---|
| 227 | function ScatterSymbols(props) {
|
|---|
| 228 | var {
|
|---|
| 229 | points,
|
|---|
| 230 | allOtherScatterProps
|
|---|
| 231 | } = props;
|
|---|
| 232 | var {
|
|---|
| 233 | shape,
|
|---|
| 234 | activeShape,
|
|---|
| 235 | dataKey
|
|---|
| 236 | } = allOtherScatterProps;
|
|---|
| 237 | var {
|
|---|
| 238 | id
|
|---|
| 239 | } = allOtherScatterProps,
|
|---|
| 240 | allOtherPropsWithoutId = _objectWithoutProperties(allOtherScatterProps, _excluded);
|
|---|
| 241 | var activeIndex = useAppSelector(selectActiveTooltipIndex);
|
|---|
| 242 | var {
|
|---|
| 243 | onMouseEnter: onMouseEnterFromProps,
|
|---|
| 244 | onClick: onItemClickFromProps,
|
|---|
| 245 | onMouseLeave: onMouseLeaveFromProps
|
|---|
| 246 | } = allOtherScatterProps,
|
|---|
| 247 | restOfAllOtherProps = _objectWithoutProperties(allOtherScatterProps, _excluded2);
|
|---|
| 248 | var onMouseEnterFromContext = useMouseEnterItemDispatch(onMouseEnterFromProps, dataKey, id);
|
|---|
| 249 | var onMouseLeaveFromContext = useMouseLeaveItemDispatch(onMouseLeaveFromProps);
|
|---|
| 250 | var onClickFromContext = useMouseClickItemDispatch(onItemClickFromProps, dataKey, id);
|
|---|
| 251 | if (!isNonEmptyArray(points)) {
|
|---|
| 252 | return null;
|
|---|
| 253 | }
|
|---|
| 254 | var baseProps = svgPropertiesNoEvents(allOtherPropsWithoutId);
|
|---|
| 255 | return /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement(ScatterLine, {
|
|---|
| 256 | points: points,
|
|---|
| 257 | props: allOtherPropsWithoutId
|
|---|
| 258 | }), points.map((entry, i) => {
|
|---|
| 259 | var hasActiveShape = activeShape != null && activeShape !== false;
|
|---|
| 260 | var isActive = hasActiveShape && activeIndex === String(i);
|
|---|
| 261 | var option = hasActiveShape && isActive ? activeShape : shape;
|
|---|
| 262 | var symbolProps = _objectSpread(_objectSpread(_objectSpread({}, baseProps), entry), {}, {
|
|---|
| 263 | index: i,
|
|---|
| 264 | [DATA_ITEM_GRAPHICAL_ITEM_ID_ATTRIBUTE_NAME]: String(id)
|
|---|
| 265 | });
|
|---|
| 266 | return /*#__PURE__*/React.createElement(ZIndexLayer, {
|
|---|
| 267 | key: "symbol-".concat(entry === null || entry === void 0 ? void 0 : entry.cx, "-").concat(entry === null || entry === void 0 ? void 0 : entry.cy, "-").concat(entry === null || entry === void 0 ? void 0 : entry.size, "-").concat(i)
|
|---|
| 268 | /*
|
|---|
| 269 | * inactive Scatters use the parent zIndex, which is represented by undefined here.
|
|---|
| 270 | * ZIndexLayer will render undefined zIndex as-is, as regular children, without portals.
|
|---|
| 271 | * Active Scatters use the activeDot zIndex so they render above other elements.
|
|---|
| 272 | */,
|
|---|
| 273 | zIndex: isActive ? DefaultZIndexes.activeDot : undefined
|
|---|
| 274 | }, /*#__PURE__*/React.createElement(Layer, _extends({
|
|---|
| 275 | className: "recharts-scatter-symbol"
|
|---|
| 276 | }, adaptEventsOfChild(restOfAllOtherProps, entry, i), {
|
|---|
| 277 | // @ts-expect-error the types need a bit of attention
|
|---|
| 278 | onMouseEnter: onMouseEnterFromContext(entry, i)
|
|---|
| 279 | // @ts-expect-error the types need a bit of attention
|
|---|
| 280 | ,
|
|---|
| 281 | onMouseLeave: onMouseLeaveFromContext(entry, i)
|
|---|
| 282 | // @ts-expect-error the types need a bit of attention
|
|---|
| 283 | ,
|
|---|
| 284 | onClick: onClickFromContext(entry, i)
|
|---|
| 285 | }), /*#__PURE__*/React.createElement(ScatterSymbol, _extends({
|
|---|
| 286 | option: option,
|
|---|
| 287 | isActive: isActive
|
|---|
| 288 | }, symbolProps))));
|
|---|
| 289 | }));
|
|---|
| 290 | }
|
|---|
| 291 | function SymbolsWithAnimation(_ref4) {
|
|---|
| 292 | var {
|
|---|
| 293 | previousPointsRef,
|
|---|
| 294 | props
|
|---|
| 295 | } = _ref4;
|
|---|
| 296 | var {
|
|---|
| 297 | points,
|
|---|
| 298 | isAnimationActive,
|
|---|
| 299 | animationBegin,
|
|---|
| 300 | animationDuration,
|
|---|
| 301 | animationEasing
|
|---|
| 302 | } = props;
|
|---|
| 303 | var prevPoints = previousPointsRef.current;
|
|---|
| 304 | var animationId = useAnimationId(props, 'recharts-scatter-');
|
|---|
| 305 | var [isAnimating, setIsAnimating] = useState(false);
|
|---|
| 306 | var handleAnimationEnd = useCallback(() => {
|
|---|
| 307 | // Scatter doesn't have onAnimationEnd prop, and if we want to add it we do it here
|
|---|
| 308 | // if (typeof onAnimationEnd === 'function') {
|
|---|
| 309 | // onAnimationEnd();
|
|---|
| 310 | // }
|
|---|
| 311 | setIsAnimating(false);
|
|---|
| 312 | }, []);
|
|---|
| 313 | var handleAnimationStart = useCallback(() => {
|
|---|
| 314 | // Scatter doesn't have onAnimationStart prop, and if we want to add it we do it here
|
|---|
| 315 | // if (typeof onAnimationStart === 'function') {
|
|---|
| 316 | // onAnimationStart();
|
|---|
| 317 | // }
|
|---|
| 318 | setIsAnimating(true);
|
|---|
| 319 | }, []);
|
|---|
| 320 | var showLabels = !isAnimating;
|
|---|
| 321 | return /*#__PURE__*/React.createElement(ScatterLabelListProvider, {
|
|---|
| 322 | showLabels: showLabels,
|
|---|
| 323 | points: points
|
|---|
| 324 | }, props.children, /*#__PURE__*/React.createElement(JavascriptAnimate, {
|
|---|
| 325 | animationId: animationId,
|
|---|
| 326 | begin: animationBegin,
|
|---|
| 327 | duration: animationDuration,
|
|---|
| 328 | isActive: isAnimationActive,
|
|---|
| 329 | easing: animationEasing,
|
|---|
| 330 | onAnimationEnd: handleAnimationEnd,
|
|---|
| 331 | onAnimationStart: handleAnimationStart,
|
|---|
| 332 | key: animationId
|
|---|
| 333 | }, t => {
|
|---|
| 334 | var stepData = t === 1 ? points : points === null || points === void 0 ? void 0 : points.map((entry, index) => {
|
|---|
| 335 | var prev = prevPoints && prevPoints[index];
|
|---|
| 336 | if (prev) {
|
|---|
| 337 | return _objectSpread(_objectSpread({}, entry), {}, {
|
|---|
| 338 | cx: entry.cx == null ? undefined : interpolate(prev.cx, entry.cx, t),
|
|---|
| 339 | cy: entry.cy == null ? undefined : interpolate(prev.cy, entry.cy, t),
|
|---|
| 340 | size: interpolate(prev.size, entry.size, t)
|
|---|
| 341 | });
|
|---|
| 342 | }
|
|---|
| 343 | return _objectSpread(_objectSpread({}, entry), {}, {
|
|---|
| 344 | size: interpolate(0, entry.size, t)
|
|---|
| 345 | });
|
|---|
| 346 | });
|
|---|
| 347 | if (t > 0) {
|
|---|
| 348 | // eslint-disable-next-line no-param-reassign
|
|---|
| 349 | previousPointsRef.current = stepData;
|
|---|
| 350 | }
|
|---|
| 351 | return /*#__PURE__*/React.createElement(Layer, null, /*#__PURE__*/React.createElement(ScatterSymbols, {
|
|---|
| 352 | points: stepData,
|
|---|
| 353 | allOtherScatterProps: props,
|
|---|
| 354 | showLabels: showLabels
|
|---|
| 355 | }));
|
|---|
| 356 | }), /*#__PURE__*/React.createElement(LabelListFromLabelProp, {
|
|---|
| 357 | label: props.label
|
|---|
| 358 | }));
|
|---|
| 359 | }
|
|---|
| 360 | export function computeScatterPoints(_ref5) {
|
|---|
| 361 | var {
|
|---|
| 362 | displayedData,
|
|---|
| 363 | xAxis,
|
|---|
| 364 | yAxis,
|
|---|
| 365 | zAxis,
|
|---|
| 366 | scatterSettings,
|
|---|
| 367 | xAxisTicks,
|
|---|
| 368 | yAxisTicks,
|
|---|
| 369 | cells
|
|---|
| 370 | } = _ref5;
|
|---|
| 371 | var xAxisDataKey = isNullish(xAxis.dataKey) ? scatterSettings.dataKey : xAxis.dataKey;
|
|---|
| 372 | var yAxisDataKey = isNullish(yAxis.dataKey) ? scatterSettings.dataKey : yAxis.dataKey;
|
|---|
| 373 | var zAxisDataKey = zAxis && zAxis.dataKey;
|
|---|
| 374 | var defaultRangeZ = zAxis ? zAxis.range : implicitZAxis.range;
|
|---|
| 375 | var defaultZ = defaultRangeZ && defaultRangeZ[0];
|
|---|
| 376 | var xBandSize = xAxis.scale.bandwidth ? xAxis.scale.bandwidth() : 0;
|
|---|
| 377 | var yBandSize = yAxis.scale.bandwidth ? yAxis.scale.bandwidth() : 0;
|
|---|
| 378 | return displayedData.map((entry, index) => {
|
|---|
| 379 | var x = getValueByDataKey(entry, xAxisDataKey);
|
|---|
| 380 | var y = getValueByDataKey(entry, yAxisDataKey);
|
|---|
| 381 | var z = !isNullish(zAxisDataKey) && getValueByDataKey(entry, zAxisDataKey) || '-';
|
|---|
| 382 | var tooltipPayload = [{
|
|---|
| 383 | name: isNullish(xAxis.dataKey) ? scatterSettings.name : xAxis.name || String(xAxis.dataKey),
|
|---|
| 384 | unit: xAxis.unit || '',
|
|---|
| 385 | // @ts-expect-error getValueByDataKey does not validate the output type
|
|---|
| 386 | value: x,
|
|---|
| 387 | payload: entry,
|
|---|
| 388 | dataKey: xAxisDataKey,
|
|---|
| 389 | type: scatterSettings.tooltipType
|
|---|
| 390 | }, {
|
|---|
| 391 | name: isNullish(yAxis.dataKey) ? scatterSettings.name : yAxis.name || String(yAxis.dataKey),
|
|---|
| 392 | unit: yAxis.unit || '',
|
|---|
| 393 | // @ts-expect-error getValueByDataKey does not validate the output type
|
|---|
| 394 | value: y,
|
|---|
| 395 | payload: entry,
|
|---|
| 396 | dataKey: yAxisDataKey,
|
|---|
| 397 | type: scatterSettings.tooltipType
|
|---|
| 398 | }];
|
|---|
| 399 | if (z !== '-' && zAxis != null) {
|
|---|
| 400 | tooltipPayload.push({
|
|---|
| 401 | // @ts-expect-error name prop should not have dataKey in it
|
|---|
| 402 | name: zAxis.name || zAxis.dataKey,
|
|---|
| 403 | unit: zAxis.unit || '',
|
|---|
| 404 | // @ts-expect-error getValueByDataKey does not validate the output type
|
|---|
| 405 | value: z,
|
|---|
| 406 | payload: entry,
|
|---|
| 407 | dataKey: zAxisDataKey,
|
|---|
| 408 | type: scatterSettings.tooltipType
|
|---|
| 409 | });
|
|---|
| 410 | }
|
|---|
| 411 | var cx = getCateCoordinateOfLine({
|
|---|
| 412 | axis: xAxis,
|
|---|
| 413 | ticks: xAxisTicks,
|
|---|
| 414 | bandSize: xBandSize,
|
|---|
| 415 | entry,
|
|---|
| 416 | index,
|
|---|
| 417 | dataKey: xAxisDataKey
|
|---|
| 418 | });
|
|---|
| 419 | var cy = getCateCoordinateOfLine({
|
|---|
| 420 | axis: yAxis,
|
|---|
| 421 | ticks: yAxisTicks,
|
|---|
| 422 | bandSize: yBandSize,
|
|---|
| 423 | entry,
|
|---|
| 424 | index,
|
|---|
| 425 | dataKey: yAxisDataKey
|
|---|
| 426 | });
|
|---|
| 427 | var size = z !== '-' && zAxis != null ? zAxis.scale.map(z) : defaultZ;
|
|---|
| 428 | var radius = size == null ? 0 : Math.sqrt(Math.max(size, 0) / Math.PI);
|
|---|
| 429 | return _objectSpread(_objectSpread({}, entry), {}, {
|
|---|
| 430 | cx,
|
|---|
| 431 | cy,
|
|---|
| 432 | x: cx == null ? undefined : cx - radius,
|
|---|
| 433 | y: cy == null ? undefined : cy - radius,
|
|---|
| 434 | width: 2 * radius,
|
|---|
| 435 | height: 2 * radius,
|
|---|
| 436 | size,
|
|---|
| 437 | node: {
|
|---|
| 438 | x,
|
|---|
| 439 | y,
|
|---|
| 440 | z
|
|---|
| 441 | },
|
|---|
| 442 | tooltipPayload,
|
|---|
| 443 | tooltipPosition: {
|
|---|
| 444 | x: cx,
|
|---|
| 445 | y: cy
|
|---|
| 446 | },
|
|---|
| 447 | payload: entry
|
|---|
| 448 | }, cells && cells[index] && cells[index].props);
|
|---|
| 449 | });
|
|---|
| 450 | }
|
|---|
| 451 | var errorBarDataPointFormatter = (dataPoint, dataKey, direction) => {
|
|---|
| 452 | return {
|
|---|
| 453 | x: dataPoint.cx,
|
|---|
| 454 | y: dataPoint.cy,
|
|---|
| 455 | value: direction === 'x' ? Number(dataPoint.node.x) : Number(dataPoint.node.y),
|
|---|
| 456 | // @ts-expect-error getValueByDataKey does not validate the output type
|
|---|
| 457 | errorVal: getValueByDataKey(dataPoint, dataKey)
|
|---|
| 458 | };
|
|---|
| 459 | };
|
|---|
| 460 | function ScatterWithId(props) {
|
|---|
| 461 | var {
|
|---|
| 462 | hide,
|
|---|
| 463 | points,
|
|---|
| 464 | className,
|
|---|
| 465 | needClip,
|
|---|
| 466 | xAxisId,
|
|---|
| 467 | yAxisId,
|
|---|
| 468 | id
|
|---|
| 469 | } = props;
|
|---|
| 470 | var previousPointsRef = useRef(null);
|
|---|
| 471 | if (hide) {
|
|---|
| 472 | return null;
|
|---|
| 473 | }
|
|---|
| 474 | var layerClass = clsx('recharts-scatter', className);
|
|---|
| 475 | var clipPathId = id;
|
|---|
| 476 | return /*#__PURE__*/React.createElement(ZIndexLayer, {
|
|---|
| 477 | zIndex: props.zIndex
|
|---|
| 478 | }, /*#__PURE__*/React.createElement(Layer, {
|
|---|
| 479 | className: layerClass,
|
|---|
| 480 | clipPath: needClip ? "url(#clipPath-".concat(clipPathId, ")") : undefined,
|
|---|
| 481 | id: id
|
|---|
| 482 | }, needClip && /*#__PURE__*/React.createElement("defs", null, /*#__PURE__*/React.createElement(GraphicalItemClipPath, {
|
|---|
| 483 | clipPathId: clipPathId,
|
|---|
| 484 | xAxisId: xAxisId,
|
|---|
| 485 | yAxisId: yAxisId
|
|---|
| 486 | })), /*#__PURE__*/React.createElement(SetErrorBarContext, {
|
|---|
| 487 | xAxisId: xAxisId,
|
|---|
| 488 | yAxisId: yAxisId,
|
|---|
| 489 | data: points,
|
|---|
| 490 | dataPointFormatter: errorBarDataPointFormatter,
|
|---|
| 491 | errorBarOffset: 0
|
|---|
| 492 | }, /*#__PURE__*/React.createElement(Layer, {
|
|---|
| 493 | key: "recharts-scatter-symbols"
|
|---|
| 494 | }, /*#__PURE__*/React.createElement(SymbolsWithAnimation, {
|
|---|
| 495 | props: props,
|
|---|
| 496 | previousPointsRef: previousPointsRef
|
|---|
| 497 | })))));
|
|---|
| 498 | }
|
|---|
| 499 | export var defaultScatterProps = {
|
|---|
| 500 | xAxisId: 0,
|
|---|
| 501 | yAxisId: 0,
|
|---|
| 502 | zAxisId: 0,
|
|---|
| 503 | label: false,
|
|---|
| 504 | line: false,
|
|---|
| 505 | legendType: 'circle',
|
|---|
| 506 | lineType: 'joint',
|
|---|
| 507 | lineJointType: 'linear',
|
|---|
| 508 | shape: 'circle',
|
|---|
| 509 | hide: false,
|
|---|
| 510 | isAnimationActive: 'auto',
|
|---|
| 511 | animationBegin: 0,
|
|---|
| 512 | animationDuration: 400,
|
|---|
| 513 | animationEasing: 'linear',
|
|---|
| 514 | zIndex: DefaultZIndexes.scatter
|
|---|
| 515 | };
|
|---|
| 516 | function ScatterImpl(props) {
|
|---|
| 517 | var _resolveDefaultProps = resolveDefaultProps(props, defaultScatterProps),
|
|---|
| 518 | {
|
|---|
| 519 | animationBegin,
|
|---|
| 520 | animationDuration,
|
|---|
| 521 | animationEasing,
|
|---|
| 522 | hide,
|
|---|
| 523 | isAnimationActive,
|
|---|
| 524 | legendType,
|
|---|
| 525 | lineJointType,
|
|---|
| 526 | lineType,
|
|---|
| 527 | shape,
|
|---|
| 528 | xAxisId,
|
|---|
| 529 | yAxisId,
|
|---|
| 530 | zAxisId
|
|---|
| 531 | } = _resolveDefaultProps,
|
|---|
| 532 | everythingElse = _objectWithoutProperties(_resolveDefaultProps, _excluded3);
|
|---|
| 533 | var {
|
|---|
| 534 | needClip
|
|---|
| 535 | } = useNeedsClip(xAxisId, yAxisId);
|
|---|
| 536 | var cells = useMemo(() => findAllByType(props.children, Cell), [props.children]);
|
|---|
| 537 | var isPanorama = useIsPanorama();
|
|---|
| 538 | var points = useAppSelector(state => {
|
|---|
| 539 | return selectScatterPoints(state, xAxisId, yAxisId, zAxisId, props.id, cells, isPanorama);
|
|---|
| 540 | });
|
|---|
| 541 | if (needClip == null) {
|
|---|
| 542 | return null;
|
|---|
| 543 | }
|
|---|
| 544 | if (points == null) {
|
|---|
| 545 | return null;
|
|---|
| 546 | }
|
|---|
| 547 | return /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement(SetScatterTooltipEntrySettings, {
|
|---|
| 548 | dataKey: props.dataKey,
|
|---|
| 549 | points: points,
|
|---|
| 550 | stroke: props.stroke,
|
|---|
| 551 | strokeWidth: props.strokeWidth,
|
|---|
| 552 | fill: props.fill,
|
|---|
| 553 | name: props.name,
|
|---|
| 554 | hide: props.hide,
|
|---|
| 555 | tooltipType: props.tooltipType,
|
|---|
| 556 | id: props.id
|
|---|
| 557 | }), /*#__PURE__*/React.createElement(ScatterWithId, _extends({}, everythingElse, {
|
|---|
| 558 | xAxisId: xAxisId,
|
|---|
| 559 | yAxisId: yAxisId,
|
|---|
| 560 | zAxisId: zAxisId,
|
|---|
| 561 | lineType: lineType,
|
|---|
| 562 | lineJointType: lineJointType,
|
|---|
| 563 | legendType: legendType,
|
|---|
| 564 | shape: shape,
|
|---|
| 565 | hide: hide,
|
|---|
| 566 | isAnimationActive: isAnimationActive,
|
|---|
| 567 | animationBegin: animationBegin,
|
|---|
| 568 | animationDuration: animationDuration,
|
|---|
| 569 | animationEasing: animationEasing,
|
|---|
| 570 | points: points,
|
|---|
| 571 | needClip: needClip
|
|---|
| 572 | })));
|
|---|
| 573 | }
|
|---|
| 574 | function ScatterFn(outsideProps) {
|
|---|
| 575 | var props = resolveDefaultProps(outsideProps, defaultScatterProps);
|
|---|
| 576 | var isPanorama = useIsPanorama();
|
|---|
| 577 | return /*#__PURE__*/React.createElement(RegisterGraphicalItemId, {
|
|---|
| 578 | id: props.id,
|
|---|
| 579 | type: "scatter"
|
|---|
| 580 | }, id => /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement(SetLegendPayload, {
|
|---|
| 581 | legendPayload: computeLegendPayloadFromScatterProps(props)
|
|---|
| 582 | }), /*#__PURE__*/React.createElement(SetCartesianGraphicalItem, {
|
|---|
| 583 | type: "scatter",
|
|---|
| 584 | id: id,
|
|---|
| 585 | data: props.data,
|
|---|
| 586 | xAxisId: props.xAxisId,
|
|---|
| 587 | yAxisId: props.yAxisId,
|
|---|
| 588 | zAxisId: props.zAxisId,
|
|---|
| 589 | dataKey: props.dataKey,
|
|---|
| 590 | hide: props.hide,
|
|---|
| 591 | name: props.name,
|
|---|
| 592 | tooltipType: props.tooltipType,
|
|---|
| 593 | isPanorama: isPanorama
|
|---|
| 594 | }), /*#__PURE__*/React.createElement(ScatterImpl, _extends({}, props, {
|
|---|
| 595 | id: id
|
|---|
| 596 | }))));
|
|---|
| 597 | }
|
|---|
| 598 |
|
|---|
| 599 | /**
|
|---|
| 600 | * @provides LabelListContext
|
|---|
| 601 | * @provides ErrorBarContext
|
|---|
| 602 | * @provides CellReader
|
|---|
| 603 | * @consumes CartesianChartContext
|
|---|
| 604 | */
|
|---|
| 605 | export var Scatter = /*#__PURE__*/React.memo(ScatterFn, propsAreEqual);
|
|---|
| 606 | Scatter.displayName = 'Scatter'; |
|---|