source: node_modules/recharts/es6/cartesian/ReferenceDot.js

Last change on this file was a762898, checked in by istevanoska <ilinastevanoska@…>, 5 months ago

Added visualizations

  • Property mode set to 100644
File size: 6.3 KB
RevLine 
[a762898]1function 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; }
2function _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; }
3function _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; }
4function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == typeof i ? i : i + ""; }
5function _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); }
6function _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); }
7import * as React from 'react';
8import { useEffect } from 'react';
9import { clsx } from 'clsx';
10import { Layer } from '../container/Layer';
11import { Dot } from '../shape/Dot';
12import { CartesianLabelContextProvider, CartesianLabelFromLabelProp } from '../component/Label';
13import { isNumOrStr } from '../util/DataUtils';
14import { addDot, removeDot } from '../state/referenceElementsSlice';
15import { useAppDispatch, useAppSelector } from '../state/hooks';
16import { selectAxisScale } from '../state/selectors/axisSelectors';
17import { useIsPanorama } from '../context/PanoramaContext';
18import { useClipPathId } from '../container/ClipPathProvider';
19import { svgPropertiesAndEvents } from '../util/svgPropertiesAndEvents';
20import { resolveDefaultProps } from '../util/resolveDefaultProps';
21import { ZIndexLayer } from '../zIndex/ZIndexLayer';
22import { DefaultZIndexes } from '../zIndex/DefaultZIndexes';
23import { CartesianScaleHelperImpl } from '../util/scale/CartesianScaleHelper';
24var useCoordinate = (x, y, xAxisId, yAxisId, ifOverflow) => {
25 var isX = isNumOrStr(x);
26 var isY = isNumOrStr(y);
27 var isPanorama = useIsPanorama();
28 var xAxisScale = useAppSelector(state => selectAxisScale(state, 'xAxis', xAxisId, isPanorama));
29 var yAxisScale = useAppSelector(state => selectAxisScale(state, 'yAxis', yAxisId, isPanorama));
30 if (!isX || !isY || xAxisScale == null || yAxisScale == null) {
31 return null;
32 }
33 var scales = new CartesianScaleHelperImpl({
34 x: xAxisScale,
35 y: yAxisScale
36 });
37 var result = scales.map({
38 x,
39 y
40 }, {
41 position: 'middle'
42 });
43 if (ifOverflow === 'discard' && !scales.isInRange(result)) {
44 return null;
45 }
46 return result;
47};
48function ReportReferenceDot(props) {
49 var dispatch = useAppDispatch();
50 useEffect(() => {
51 dispatch(addDot(props));
52 return () => {
53 dispatch(removeDot(props));
54 };
55 });
56 return null;
57}
58var renderDot = (option, props) => {
59 var dot;
60 if (/*#__PURE__*/React.isValidElement(option)) {
61 // @ts-expect-error element cloning is not typed
62 dot = /*#__PURE__*/React.cloneElement(option, props);
63 } else if (typeof option === 'function') {
64 dot = option(props);
65 } else {
66 dot = /*#__PURE__*/React.createElement(Dot, _extends({}, props, {
67 cx: props.cx,
68 cy: props.cy,
69 className: "recharts-reference-dot-dot"
70 }));
71 }
72 return dot;
73};
74function ReferenceDotImpl(props) {
75 var {
76 x,
77 y,
78 r
79 } = props;
80 var clipPathId = useClipPathId();
81 var coordinate = useCoordinate(x, y, props.xAxisId, props.yAxisId, props.ifOverflow);
82 if (!coordinate) {
83 return null;
84 }
85 var {
86 x: cx,
87 y: cy
88 } = coordinate;
89 var {
90 shape,
91 className,
92 ifOverflow
93 } = props;
94 var clipPath = ifOverflow === 'hidden' ? "url(#".concat(clipPathId, ")") : undefined;
95 var dotProps = _objectSpread(_objectSpread({
96 clipPath
97 }, svgPropertiesAndEvents(props)), {}, {
98 cx: cx !== null && cx !== void 0 ? cx : undefined,
99 cy: cy !== null && cy !== void 0 ? cy : undefined
100 });
101 return /*#__PURE__*/React.createElement(ZIndexLayer, {
102 zIndex: props.zIndex
103 }, /*#__PURE__*/React.createElement(Layer, {
104 className: clsx('recharts-reference-dot', className)
105 }, renderDot(shape, dotProps), /*#__PURE__*/React.createElement(CartesianLabelContextProvider, {
106 x: cx - r,
107 y: cy - r,
108 width: 2 * r,
109 height: 2 * r,
110 upperWidth: 2 * r,
111 lowerWidth: 2 * r
112 }, /*#__PURE__*/React.createElement(CartesianLabelFromLabelProp, {
113 label: props.label
114 }), props.children)));
115}
116export var referenceDotDefaultProps = {
117 ifOverflow: 'discard',
118 xAxisId: 0,
119 yAxisId: 0,
120 r: 10,
121 label: false,
122 fill: '#fff',
123 stroke: '#ccc',
124 fillOpacity: 1,
125 strokeWidth: 1,
126 zIndex: DefaultZIndexes.scatter
127};
128/**
129 * Draws a circle on the chart to highlight a specific point.
130 *
131 * This component, unlike {@link Dot} or {@link https://developer.mozilla.org/en-US/docs/Web/SVG/Reference/Element/circle circle}, is aware of the cartesian coordinate system,
132 * so you specify its center by using data coordinates instead of pixels.
133 *
134 * ReferenceDot will calculate the pixels based on the provided data coordinates.
135 *
136 * If you prefer to render dots using pixels rather than data coordinates,
137 * consider using the {@link Dot} component instead.
138 *
139 * @provides CartesianLabelContext
140 * @consumes CartesianChartContext
141 */
142export function ReferenceDot(outsideProps) {
143 var props = resolveDefaultProps(outsideProps, referenceDotDefaultProps);
144 var {
145 x,
146 y,
147 r,
148 ifOverflow,
149 yAxisId,
150 xAxisId
151 } = props;
152 return /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement(ReportReferenceDot, {
153 y: y,
154 x: x,
155 r: r,
156 yAxisId: yAxisId,
157 xAxisId: xAxisId,
158 ifOverflow: ifOverflow
159 }), /*#__PURE__*/React.createElement(ReferenceDotImpl, props));
160}
161ReferenceDot.displayName = 'ReferenceDot';
Note: See TracBrowser for help on using the repository browser.