source: node_modules/recharts/es6/component/Cursor.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: 5.9 KB
RevLine 
[a762898]1function _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); }
2function 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; }
3function _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; }
4function _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; }
5function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == typeof i ? i : i + ""; }
6function _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); }
7import * as React from 'react';
8import { cloneElement, createElement, isValidElement } from 'react';
9import { clsx } from 'clsx';
10import { isPolarCoordinate } from '../util/types';
11import { Curve } from '../shape/Curve';
12import { Cross } from '../shape/Cross';
13import { getCursorRectangle } from '../util/cursor/getCursorRectangle';
14import { Rectangle } from '../shape/Rectangle';
15import { getRadialCursorPoints } from '../util/cursor/getRadialCursorPoints';
16import { Sector } from '../shape/Sector';
17import { getCursorPoints } from '../util/cursor/getCursorPoints';
18import { useChartLayout, useOffsetInternal } from '../context/chartLayoutContext';
19import { useTooltipAxisBandSize } from '../context/useTooltipAxis';
20import { useChartName } from '../state/selectors/selectors';
21import { svgPropertiesNoEventsFromUnknown } from '../util/svgPropertiesNoEvents';
22import { ZIndexLayer } from '../zIndex/ZIndexLayer';
23import { DefaultZIndexes } from '../zIndex/DefaultZIndexes';
24
25/**
26 * If set false, no cursor will be drawn when tooltip is active.
27 * If set an object, the option is the configuration of cursor.
28 * If set a React element, the option is the custom react element of drawing cursor
29 */
30
31function RenderCursor(_ref) {
32 var {
33 cursor,
34 cursorComp,
35 cursorProps
36 } = _ref;
37 if (/*#__PURE__*/isValidElement(cursor)) {
38 return /*#__PURE__*/cloneElement(cursor, cursorProps);
39 }
40 return /*#__PURE__*/createElement(cursorComp, cursorProps);
41}
42export function CursorInternal(props) {
43 var _props$zIndex;
44 var {
45 coordinate,
46 payload,
47 index,
48 offset,
49 tooltipAxisBandSize,
50 layout,
51 cursor,
52 tooltipEventType,
53 chartName
54 } = props;
55
56 // The cursor is a part of the Tooltip, and it should be shown (by default) when the Tooltip is active.
57 var activeCoordinate = coordinate;
58 var activePayload = payload;
59 var activeTooltipIndex = index;
60 if (!cursor || !activeCoordinate || chartName !== 'ScatterChart' && tooltipEventType !== 'axis') {
61 return null;
62 }
63 var restProps, cursorComp, preferredZIndex;
64 if (chartName === 'ScatterChart') {
65 restProps = activeCoordinate;
66 cursorComp = Cross;
67 preferredZIndex = DefaultZIndexes.cursorLine;
68 } else if (chartName === 'BarChart') {
69 restProps = getCursorRectangle(layout, activeCoordinate, offset, tooltipAxisBandSize);
70 cursorComp = Rectangle;
71 preferredZIndex = DefaultZIndexes.cursorRectangle;
72 } else if (layout === 'radial' && isPolarCoordinate(activeCoordinate)) {
73 var {
74 cx,
75 cy,
76 radius,
77 startAngle,
78 endAngle
79 } = getRadialCursorPoints(activeCoordinate);
80 restProps = {
81 cx,
82 cy,
83 startAngle,
84 endAngle,
85 innerRadius: radius,
86 outerRadius: radius
87 };
88 cursorComp = Sector;
89 preferredZIndex = DefaultZIndexes.cursorLine;
90 } else {
91 restProps = {
92 points: getCursorPoints(layout, activeCoordinate, offset)
93 };
94 cursorComp = Curve;
95 preferredZIndex = DefaultZIndexes.cursorLine;
96 }
97 var extraClassName = typeof cursor === 'object' && 'className' in cursor ? cursor.className : undefined;
98 var cursorProps = _objectSpread(_objectSpread(_objectSpread(_objectSpread({
99 stroke: '#ccc',
100 pointerEvents: 'none'
101 }, offset), restProps), svgPropertiesNoEventsFromUnknown(cursor)), {}, {
102 payload: activePayload,
103 payloadIndex: activeTooltipIndex,
104 className: clsx('recharts-tooltip-cursor', extraClassName)
105 });
106 return /*#__PURE__*/React.createElement(ZIndexLayer, {
107 zIndex: (_props$zIndex = props.zIndex) !== null && _props$zIndex !== void 0 ? _props$zIndex : preferredZIndex
108 }, /*#__PURE__*/React.createElement(RenderCursor, {
109 cursor: cursor,
110 cursorComp: cursorComp,
111 cursorProps: cursorProps
112 }));
113}
114
115/*
116 * Cursor is the background, or a highlight,
117 * that shows when user mouses over or activates
118 * an area.
119 *
120 * It usually shows together with a tooltip
121 * to emphasise which part of the chart does the tooltip refer to.
122 */
123export function Cursor(props) {
124 var tooltipAxisBandSize = useTooltipAxisBandSize();
125 var offset = useOffsetInternal();
126 var layout = useChartLayout();
127 var chartName = useChartName();
128 if (tooltipAxisBandSize == null || offset == null || layout == null || chartName == null) {
129 return null;
130 }
131 return /*#__PURE__*/React.createElement(CursorInternal, _extends({}, props, {
132 offset: offset,
133 layout: layout,
134 tooltipAxisBandSize: tooltipAxisBandSize,
135 chartName: chartName
136 }));
137}
Note: See TracBrowser for help on using the repository browser.