victory-cursor-container 36.9.2-next.3 → 37.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,134 +1,134 @@
1
- import React from "react";
2
- import { VictoryContainer, VictoryContainerProps, CoordinatesPropType, VictoryLabelProps, ValueOrAccessor } from "victory-core";
3
- export declare type CursorCoordinatesPropType = CoordinatesPropType | number;
4
- export interface VictoryCursorContainerProps extends VictoryContainerProps {
5
- cursorComponent?: React.ReactElement;
6
- cursorDimension?: "x" | "y";
7
- cursorLabel?: ValueOrAccessor<VictoryLabelProps["text"]>;
8
- cursorLabelComponent?: React.ReactElement;
9
- cursorLabelOffset?: CursorCoordinatesPropType;
10
- defaultCursorValue?: CursorCoordinatesPropType;
11
- disable?: boolean;
12
- onCursorChange?: (value: CursorCoordinatesPropType, props: VictoryCursorContainerProps) => void;
13
- }
14
- declare type ComponentClass<TProps> = {
15
- new (props: TProps): React.Component<TProps>;
16
- };
17
- export declare function cursorContainerMixin<TBase extends ComponentClass<TProps>, TProps extends VictoryCursorContainerProps>(Base: TBase): {
18
- new (props: TProps): {
19
- getCursorPosition(props: any): any;
20
- getCursorLabelOffset(props: any): any;
21
- getPadding(props: any): {
22
- top: any;
23
- bottom: any;
24
- left: any;
25
- right: any;
26
- };
27
- getCursorElements(props: any): React.ReactElement<any, string | React.JSXElementConstructor<any>>[];
28
- getChildren(props: any): (string | number | React.ReactElement<any, string | React.JSXElementConstructor<any>> | React.ReactFragment)[];
29
- context: unknown;
30
- setState<K extends never>(state: {} | ((prevState: Readonly<{}>, props: Readonly<TProps>) => {} | Pick<{}, K> | null) | Pick<{}, K> | null, callback?: (() => void) | undefined): void;
31
- forceUpdate(callback?: (() => void) | undefined): void;
32
- render(): React.ReactNode;
33
- readonly props: Readonly<TProps>;
34
- state: Readonly<{}>;
35
- refs: {
36
- [key: string]: React.ReactInstance;
37
- };
38
- componentDidMount?(): void;
39
- shouldComponentUpdate?(nextProps: Readonly<TProps>, nextState: Readonly<{}>, nextContext: any): boolean;
40
- componentWillUnmount?(): void;
41
- componentDidCatch?(error: Error, errorInfo: React.ErrorInfo): void;
42
- getSnapshotBeforeUpdate?(prevProps: Readonly<TProps>, prevState: Readonly<{}>): any;
43
- componentDidUpdate?(prevProps: Readonly<TProps>, prevState: Readonly<{}>, snapshot?: any): void;
44
- componentWillMount?(): void;
45
- UNSAFE_componentWillMount?(): void;
46
- componentWillReceiveProps?(nextProps: Readonly<TProps>, nextContext: any): void;
47
- UNSAFE_componentWillReceiveProps?(nextProps: Readonly<TProps>, nextContext: any): void;
48
- componentWillUpdate?(nextProps: Readonly<TProps>, nextState: Readonly<{}>, nextContext: any): void;
49
- UNSAFE_componentWillUpdate?(nextProps: Readonly<TProps>, nextState: Readonly<{}>, nextContext: any): void;
50
- };
51
- displayName: string;
52
- defaultProps: {
53
- cursorLabelComponent: JSX.Element;
54
- cursorLabelOffset: {
55
- x: number;
56
- y: number;
57
- };
58
- cursorComponent: JSX.Element;
59
- className: string;
60
- portalComponent: JSX.Element;
61
- portalZIndex: number;
62
- responsive: boolean;
63
- role: string;
64
- };
65
- defaultEvents: (props: any) => {
66
- target: string;
67
- eventHandlers: {
68
- onMouseLeave: (evt: any, targetProps: any) => {};
69
- onTouchCancel: () => never[];
70
- onMouseMove: (evt: any, targetProps: any) => {} | undefined;
71
- onTouchMove: (evt: any, targetProps: any) => {} | undefined;
72
- };
73
- }[];
74
- } & TBase;
75
- export declare const VictoryCursorContainer: {
76
- new (props: VictoryCursorContainerProps): {
77
- getCursorPosition(props: any): any;
78
- getCursorLabelOffset(props: any): any;
79
- getPadding(props: any): {
80
- top: any;
81
- bottom: any;
82
- left: any;
83
- right: any;
84
- };
85
- getCursorElements(props: any): React.ReactElement<any, string | React.JSXElementConstructor<any>>[];
86
- getChildren(props: any): (string | number | React.ReactElement<any, string | React.JSXElementConstructor<any>> | React.ReactFragment)[];
87
- context: unknown;
88
- setState<K extends never>(state: {} | ((prevState: Readonly<{}>, props: Readonly<VictoryCursorContainerProps>) => {} | Pick<{}, K> | null) | Pick<{}, K> | null, callback?: (() => void) | undefined): void;
89
- forceUpdate(callback?: (() => void) | undefined): void;
90
- render(): React.ReactNode;
91
- readonly props: Readonly<VictoryCursorContainerProps>;
92
- state: Readonly<{}>;
93
- refs: {
94
- [key: string]: React.ReactInstance;
95
- };
96
- componentDidMount?(): void;
97
- shouldComponentUpdate?(nextProps: Readonly<VictoryCursorContainerProps>, nextState: Readonly<{}>, nextContext: any): boolean;
98
- componentWillUnmount?(): void;
99
- componentDidCatch?(error: Error, errorInfo: React.ErrorInfo): void;
100
- getSnapshotBeforeUpdate?(prevProps: Readonly<VictoryCursorContainerProps>, prevState: Readonly<{}>): any;
101
- componentDidUpdate?(prevProps: Readonly<VictoryCursorContainerProps>, prevState: Readonly<{}>, snapshot?: any): void;
102
- componentWillMount?(): void;
103
- UNSAFE_componentWillMount?(): void;
104
- componentWillReceiveProps?(nextProps: Readonly<VictoryCursorContainerProps>, nextContext: any): void;
105
- UNSAFE_componentWillReceiveProps?(nextProps: Readonly<VictoryCursorContainerProps>, nextContext: any): void;
106
- componentWillUpdate?(nextProps: Readonly<VictoryCursorContainerProps>, nextState: Readonly<{}>, nextContext: any): void;
107
- UNSAFE_componentWillUpdate?(nextProps: Readonly<VictoryCursorContainerProps>, nextState: Readonly<{}>, nextContext: any): void;
108
- };
109
- displayName: string;
110
- defaultProps: {
111
- cursorLabelComponent: JSX.Element;
112
- cursorLabelOffset: {
113
- x: number;
114
- y: number;
115
- };
116
- cursorComponent: JSX.Element;
117
- className: string;
118
- portalComponent: JSX.Element;
119
- portalZIndex: number;
120
- responsive: boolean;
121
- role: string;
122
- };
123
- defaultEvents: (props: any) => {
124
- target: string;
125
- eventHandlers: {
126
- onMouseLeave: (evt: any, targetProps: any) => {};
127
- onTouchCancel: () => never[];
128
- onMouseMove: (evt: any, targetProps: any) => {} | undefined;
129
- onTouchMove: (evt: any, targetProps: any) => {} | undefined;
130
- };
131
- }[];
132
- } & typeof VictoryContainer;
133
- export {};
1
+ import React from "react";
2
+ import { VictoryContainer, VictoryContainerProps, CoordinatesPropType, VictoryLabelProps, ValueOrAccessor } from "victory-core";
3
+ export declare type CursorCoordinatesPropType = CoordinatesPropType | number;
4
+ export interface VictoryCursorContainerProps extends VictoryContainerProps {
5
+ cursorComponent?: React.ReactElement;
6
+ cursorDimension?: "x" | "y";
7
+ cursorLabel?: ValueOrAccessor<VictoryLabelProps["text"]>;
8
+ cursorLabelComponent?: React.ReactElement;
9
+ cursorLabelOffset?: CursorCoordinatesPropType;
10
+ defaultCursorValue?: CursorCoordinatesPropType;
11
+ disable?: boolean;
12
+ onCursorChange?: (value: CursorCoordinatesPropType, props: VictoryCursorContainerProps) => void;
13
+ }
14
+ declare type ComponentClass<TProps> = {
15
+ new (props: TProps): React.Component<TProps>;
16
+ };
17
+ export declare function cursorContainerMixin<TBase extends ComponentClass<TProps>, TProps extends VictoryCursorContainerProps>(Base: TBase): {
18
+ new (props: TProps): {
19
+ getCursorPosition(props: any): any;
20
+ getCursorLabelOffset(props: any): any;
21
+ getPadding(props: any): {
22
+ top: any;
23
+ bottom: any;
24
+ left: any;
25
+ right: any;
26
+ };
27
+ getCursorElements(props: any): React.ReactElement<any, string | React.JSXElementConstructor<any>>[];
28
+ getChildren(props: any): (string | number | React.ReactElement<any, string | React.JSXElementConstructor<any>> | React.ReactFragment)[];
29
+ context: unknown;
30
+ setState<K extends never>(state: {} | ((prevState: Readonly<{}>, props: Readonly<TProps>) => {} | Pick<{}, K> | null) | Pick<{}, K> | null, callback?: (() => void) | undefined): void;
31
+ forceUpdate(callback?: (() => void) | undefined): void;
32
+ render(): React.ReactNode;
33
+ readonly props: Readonly<TProps>;
34
+ state: Readonly<{}>;
35
+ refs: {
36
+ [key: string]: React.ReactInstance;
37
+ };
38
+ componentDidMount?(): void;
39
+ shouldComponentUpdate?(nextProps: Readonly<TProps>, nextState: Readonly<{}>, nextContext: any): boolean;
40
+ componentWillUnmount?(): void;
41
+ componentDidCatch?(error: Error, errorInfo: React.ErrorInfo): void;
42
+ getSnapshotBeforeUpdate?(prevProps: Readonly<TProps>, prevState: Readonly<{}>): any;
43
+ componentDidUpdate?(prevProps: Readonly<TProps>, prevState: Readonly<{}>, snapshot?: any): void;
44
+ componentWillMount?(): void;
45
+ UNSAFE_componentWillMount?(): void;
46
+ componentWillReceiveProps?(nextProps: Readonly<TProps>, nextContext: any): void;
47
+ UNSAFE_componentWillReceiveProps?(nextProps: Readonly<TProps>, nextContext: any): void;
48
+ componentWillUpdate?(nextProps: Readonly<TProps>, nextState: Readonly<{}>, nextContext: any): void;
49
+ UNSAFE_componentWillUpdate?(nextProps: Readonly<TProps>, nextState: Readonly<{}>, nextContext: any): void;
50
+ };
51
+ displayName: string;
52
+ defaultProps: {
53
+ cursorLabelComponent: JSX.Element;
54
+ cursorLabelOffset: {
55
+ x: number;
56
+ y: number;
57
+ };
58
+ cursorComponent: JSX.Element;
59
+ className: string;
60
+ portalComponent: JSX.Element;
61
+ portalZIndex: number;
62
+ responsive: boolean;
63
+ role: string;
64
+ };
65
+ defaultEvents: (props: any) => {
66
+ target: string;
67
+ eventHandlers: {
68
+ onMouseLeave: (evt: any, targetProps: any) => {};
69
+ onTouchCancel: () => never[];
70
+ onMouseMove: (evt: any, targetProps: any) => {} | undefined;
71
+ onTouchMove: (evt: any, targetProps: any) => {} | undefined;
72
+ };
73
+ }[];
74
+ } & TBase;
75
+ export declare const VictoryCursorContainer: {
76
+ new (props: VictoryCursorContainerProps): {
77
+ getCursorPosition(props: any): any;
78
+ getCursorLabelOffset(props: any): any;
79
+ getPadding(props: any): {
80
+ top: any;
81
+ bottom: any;
82
+ left: any;
83
+ right: any;
84
+ };
85
+ getCursorElements(props: any): React.ReactElement<any, string | React.JSXElementConstructor<any>>[];
86
+ getChildren(props: any): (string | number | React.ReactElement<any, string | React.JSXElementConstructor<any>> | React.ReactFragment)[];
87
+ context: unknown;
88
+ setState<K extends never>(state: {} | ((prevState: Readonly<{}>, props: Readonly<VictoryCursorContainerProps>) => {} | Pick<{}, K> | null) | Pick<{}, K> | null, callback?: (() => void) | undefined): void;
89
+ forceUpdate(callback?: (() => void) | undefined): void;
90
+ render(): React.ReactNode;
91
+ readonly props: Readonly<VictoryCursorContainerProps>;
92
+ state: Readonly<{}>;
93
+ refs: {
94
+ [key: string]: React.ReactInstance;
95
+ };
96
+ componentDidMount?(): void;
97
+ shouldComponentUpdate?(nextProps: Readonly<VictoryCursorContainerProps>, nextState: Readonly<{}>, nextContext: any): boolean;
98
+ componentWillUnmount?(): void;
99
+ componentDidCatch?(error: Error, errorInfo: React.ErrorInfo): void;
100
+ getSnapshotBeforeUpdate?(prevProps: Readonly<VictoryCursorContainerProps>, prevState: Readonly<{}>): any;
101
+ componentDidUpdate?(prevProps: Readonly<VictoryCursorContainerProps>, prevState: Readonly<{}>, snapshot?: any): void;
102
+ componentWillMount?(): void;
103
+ UNSAFE_componentWillMount?(): void;
104
+ componentWillReceiveProps?(nextProps: Readonly<VictoryCursorContainerProps>, nextContext: any): void;
105
+ UNSAFE_componentWillReceiveProps?(nextProps: Readonly<VictoryCursorContainerProps>, nextContext: any): void;
106
+ componentWillUpdate?(nextProps: Readonly<VictoryCursorContainerProps>, nextState: Readonly<{}>, nextContext: any): void;
107
+ UNSAFE_componentWillUpdate?(nextProps: Readonly<VictoryCursorContainerProps>, nextState: Readonly<{}>, nextContext: any): void;
108
+ };
109
+ displayName: string;
110
+ defaultProps: {
111
+ cursorLabelComponent: JSX.Element;
112
+ cursorLabelOffset: {
113
+ x: number;
114
+ y: number;
115
+ };
116
+ cursorComponent: JSX.Element;
117
+ className: string;
118
+ portalComponent: JSX.Element;
119
+ portalZIndex: number;
120
+ responsive: boolean;
121
+ role: string;
122
+ };
123
+ defaultEvents: (props: any) => {
124
+ target: string;
125
+ eventHandlers: {
126
+ onMouseLeave: (evt: any, targetProps: any) => {};
127
+ onTouchCancel: () => never[];
128
+ onMouseMove: (evt: any, targetProps: any) => {} | undefined;
129
+ onTouchMove: (evt: any, targetProps: any) => {} | undefined;
130
+ };
131
+ }[];
132
+ } & typeof VictoryContainer;
133
+ export {};
134
134
  //# sourceMappingURL=victory-cursor-container.d.ts.map
@@ -1,220 +1,153 @@
1
1
  import _isObject from "lodash/isObject";
2
2
  import _defaults from "lodash/defaults";
3
-
4
- function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
5
-
6
- function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
7
-
8
- function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
9
-
10
- function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
11
-
12
- function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
13
-
14
- function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); }
15
-
16
- function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }
17
-
18
- function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }
19
-
20
- function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
21
-
22
- function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
23
-
24
- function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
25
-
26
- function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
27
-
28
- function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); Object.defineProperty(subClass, "prototype", { writable: false }); if (superClass) _setPrototypeOf(subClass, superClass); }
29
-
30
- function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
31
-
32
- function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
33
-
34
- function _possibleConstructorReturn(self, call) { if (call && (typeof call === "object" || typeof call === "function")) { return call; } else if (call !== void 0) { throw new TypeError("Derived constructors may only return object or undefined"); } return _assertThisInitialized(self); }
35
-
36
- function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
37
-
38
- function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
39
-
40
- function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
41
-
42
3
  import React from "react";
43
4
  import { VictoryContainer, Helpers, VictoryLabel, LineSegment } from "victory-core";
44
5
  import { CursorHelpers } from "./cursor-helpers";
45
6
  export function cursorContainerMixin(Base) {
46
- var _class;
47
-
48
7
  // @ts-expect-error "TS2545: A mixin class must have a constructor with a single rest parameter of type 'any[]'."
49
- return _class = /*#__PURE__*/function (_Base) {
50
- _inherits(VictoryCursorContainer, _Base);
51
-
52
- var _super = _createSuper(VictoryCursorContainer);
53
-
54
- function VictoryCursorContainer() {
55
- _classCallCheck(this, VictoryCursorContainer);
56
-
57
- return _super.apply(this, arguments);
58
- }
59
-
60
- _createClass(VictoryCursorContainer, [{
61
- key: "getCursorPosition",
62
- value: function getCursorPosition(props) {
63
- var cursorValue = props.cursorValue,
64
- defaultCursorValue = props.defaultCursorValue,
65
- domain = props.domain,
66
- cursorDimension = props.cursorDimension;
67
-
68
- if (cursorValue) {
69
- return cursorValue;
70
- }
71
-
72
- if (typeof defaultCursorValue === "number") {
73
- return _defineProperty({
74
- x: (domain.x[0] + domain.x[1]) / 2,
75
- y: (domain.y[0] + domain.y[1]) / 2
76
- }, cursorDimension, defaultCursorValue);
77
- }
78
-
79
- return defaultCursorValue;
80
- }
81
- }, {
82
- key: "getCursorLabelOffset",
83
- value: function getCursorLabelOffset(props) {
84
- var cursorLabelOffset = props.cursorLabelOffset;
85
-
86
- if (typeof cursorLabelOffset === "number") {
87
- return {
88
- x: cursorLabelOffset,
89
- y: cursorLabelOffset
90
- };
8
+ return class VictoryCursorContainer extends Base {
9
+ static displayName = "VictoryCursorContainer";
10
+ static defaultProps = {
11
+ ...VictoryContainer.defaultProps,
12
+ cursorLabelComponent: /*#__PURE__*/React.createElement(VictoryLabel, null),
13
+ cursorLabelOffset: {
14
+ x: 5,
15
+ y: -10
16
+ },
17
+ cursorComponent: /*#__PURE__*/React.createElement(LineSegment, null)
18
+ };
19
+ static defaultEvents = props => {
20
+ return [{
21
+ target: "parent",
22
+ eventHandlers: {
23
+ onMouseLeave: (evt, targetProps) => {
24
+ return props.disable ? {} : CursorHelpers.onMouseLeave(evt, targetProps);
25
+ },
26
+ onTouchCancel: () => {
27
+ return [];
28
+ },
29
+ onMouseMove: (evt, targetProps) => {
30
+ return props.disable ? {} : CursorHelpers.onMouseMove(evt, targetProps);
31
+ },
32
+ onTouchMove: (evt, targetProps) => {
33
+ return props.disable ? {} : CursorHelpers.onMouseMove(evt, targetProps);
34
+ }
91
35
  }
92
-
93
- return cursorLabelOffset;
36
+ }];
37
+ };
38
+ getCursorPosition(props) {
39
+ const {
40
+ cursorValue,
41
+ defaultCursorValue,
42
+ domain,
43
+ cursorDimension
44
+ } = props;
45
+ if (cursorValue) {
46
+ return cursorValue;
94
47
  }
95
- }, {
96
- key: "getPadding",
97
- value: function getPadding(props) {
98
- if (props.padding === undefined) {
99
- var child = props.children.find(function (c) {
100
- return _isObject(c.props) && c.props.padding !== undefined;
101
- });
102
- return Helpers.getPadding(child.props);
103
- }
104
-
105
- return Helpers.getPadding(props);
48
+ if (typeof defaultCursorValue === "number") {
49
+ return {
50
+ x: (domain.x[0] + domain.x[1]) / 2,
51
+ y: (domain.y[0] + domain.y[1]) / 2,
52
+ [cursorDimension]: defaultCursorValue
53
+ };
106
54
  }
107
- }, {
108
- key: "getCursorElements",
109
- value: function getCursorElements(props) {
110
- // eslint-disable-line max-statements
111
- var scale = props.scale,
112
- cursorLabelComponent = props.cursorLabelComponent,
113
- cursorLabel = props.cursorLabel,
114
- cursorComponent = props.cursorComponent,
115
- width = props.width,
116
- height = props.height,
117
- name = props.name,
118
- horizontal = props.horizontal,
119
- theme = props.theme;
120
- var cursorDimension = CursorHelpers.getDimension(props);
121
- var cursorValue = this.getCursorPosition(props);
122
- var cursorLabelOffset = this.getCursorLabelOffset(props);
123
-
124
- if (!cursorValue) {
125
- return [];
126
- }
127
-
128
- var newElements = [];
129
- var padding = this.getPadding(props);
130
- var cursorCoordinates = {
131
- x: horizontal ? scale.y(cursorValue.y) : scale.x(cursorValue.x),
132
- y: horizontal ? scale.x(cursorValue.x) : scale.y(cursorValue.y)
55
+ return defaultCursorValue;
56
+ }
57
+ getCursorLabelOffset(props) {
58
+ const {
59
+ cursorLabelOffset
60
+ } = props;
61
+ if (typeof cursorLabelOffset === "number") {
62
+ return {
63
+ x: cursorLabelOffset,
64
+ y: cursorLabelOffset
133
65
  };
134
-
135
- if (cursorLabel) {
136
- var labelProps = _defaults({
137
- active: true
138
- }, cursorLabelComponent.props, {
139
- x: cursorCoordinates.x + cursorLabelOffset.x,
140
- y: cursorCoordinates.y + cursorLabelOffset.y,
141
- datum: cursorValue,
142
- active: true,
143
- key: "".concat(name, "-cursor-label")
144
- });
145
-
146
- if (Helpers.isTooltip(cursorLabelComponent)) {
147
- var tooltipTheme = theme && theme.tooltip || {};
148
- labelProps = _defaults({}, labelProps, tooltipTheme);
149
- }
150
-
151
- newElements.push( /*#__PURE__*/React.cloneElement(cursorLabelComponent, _defaults({}, labelProps, {
152
- text: Helpers.evaluateProp(cursorLabel, labelProps)
153
- })));
154
- }
155
-
156
- var cursorStyle = Object.assign({
157
- stroke: "black"
158
- }, cursorComponent.props.style);
159
-
160
- if (cursorDimension === "x" || cursorDimension === undefined) {
161
- newElements.push( /*#__PURE__*/React.cloneElement(cursorComponent, {
162
- key: "".concat(name, "-x-cursor"),
163
- x1: cursorCoordinates.x,
164
- x2: cursorCoordinates.x,
165
- y1: padding.top,
166
- y2: height - padding.bottom,
167
- style: cursorStyle
168
- }));
169
- }
170
-
171
- if (cursorDimension === "y" || cursorDimension === undefined) {
172
- newElements.push( /*#__PURE__*/React.cloneElement(cursorComponent, {
173
- key: "".concat(name, "-y-cursor"),
174
- x1: padding.left,
175
- x2: width - padding.right,
176
- y1: cursorCoordinates.y,
177
- y2: cursorCoordinates.y,
178
- style: cursorStyle
179
- }));
180
- }
181
-
182
- return newElements;
183
- } // Overrides method in VictoryContainer
184
-
185
- }, {
186
- key: "getChildren",
187
- value: function getChildren(props) {
188
- return [].concat(_toConsumableArray(React.Children.toArray(props.children)), _toConsumableArray(this.getCursorElements(props)));
189
66
  }
190
- }]);
191
-
192
- return VictoryCursorContainer;
193
- }(Base), _class.displayName = "VictoryCursorContainer", _class.defaultProps = _objectSpread(_objectSpread({}, VictoryContainer.defaultProps), {}, {
194
- cursorLabelComponent: /*#__PURE__*/React.createElement(VictoryLabel, null),
195
- cursorLabelOffset: {
196
- x: 5,
197
- y: -10
198
- },
199
- cursorComponent: /*#__PURE__*/React.createElement(LineSegment, null)
200
- }), _class.defaultEvents = function (props) {
201
- return [{
202
- target: "parent",
203
- eventHandlers: {
204
- onMouseLeave: function (evt, targetProps) {
205
- return props.disable ? {} : CursorHelpers.onMouseLeave(evt, targetProps);
206
- },
207
- onTouchCancel: function () {
208
- return [];
209
- },
210
- onMouseMove: function (evt, targetProps) {
211
- return props.disable ? {} : CursorHelpers.onMouseMove(evt, targetProps);
212
- },
213
- onTouchMove: function (evt, targetProps) {
214
- return props.disable ? {} : CursorHelpers.onMouseMove(evt, targetProps);
67
+ return cursorLabelOffset;
68
+ }
69
+ getPadding(props) {
70
+ if (props.padding === undefined) {
71
+ const child = props.children.find(c => {
72
+ return _isObject(c.props) && c.props.padding !== undefined;
73
+ });
74
+ return Helpers.getPadding(child.props);
75
+ }
76
+ return Helpers.getPadding(props);
77
+ }
78
+ getCursorElements(props) {
79
+ // eslint-disable-line max-statements
80
+ const {
81
+ scale,
82
+ cursorLabelComponent,
83
+ cursorLabel,
84
+ cursorComponent,
85
+ width,
86
+ height,
87
+ name,
88
+ horizontal,
89
+ theme
90
+ } = props;
91
+ const cursorDimension = CursorHelpers.getDimension(props);
92
+ const cursorValue = this.getCursorPosition(props);
93
+ const cursorLabelOffset = this.getCursorLabelOffset(props);
94
+ if (!cursorValue) {
95
+ return [];
96
+ }
97
+ const newElements = [];
98
+ const padding = this.getPadding(props);
99
+ const cursorCoordinates = {
100
+ x: horizontal ? scale.y(cursorValue.y) : scale.x(cursorValue.x),
101
+ y: horizontal ? scale.x(cursorValue.x) : scale.y(cursorValue.y)
102
+ };
103
+ if (cursorLabel) {
104
+ let labelProps = _defaults({
105
+ active: true
106
+ }, cursorLabelComponent.props, {
107
+ x: cursorCoordinates.x + cursorLabelOffset.x,
108
+ y: cursorCoordinates.y + cursorLabelOffset.y,
109
+ datum: cursorValue,
110
+ active: true,
111
+ key: `${name}-cursor-label`
112
+ });
113
+ if (Helpers.isTooltip(cursorLabelComponent)) {
114
+ const tooltipTheme = theme && theme.tooltip || {};
115
+ labelProps = _defaults({}, labelProps, tooltipTheme);
215
116
  }
117
+ newElements.push( /*#__PURE__*/React.cloneElement(cursorLabelComponent, _defaults({}, labelProps, {
118
+ text: Helpers.evaluateProp(cursorLabel, labelProps)
119
+ })));
120
+ }
121
+ const cursorStyle = Object.assign({
122
+ stroke: "black"
123
+ }, cursorComponent.props.style);
124
+ if (cursorDimension === "x" || cursorDimension === undefined) {
125
+ newElements.push( /*#__PURE__*/React.cloneElement(cursorComponent, {
126
+ key: `${name}-x-cursor`,
127
+ x1: cursorCoordinates.x,
128
+ x2: cursorCoordinates.x,
129
+ y1: padding.top,
130
+ y2: height - padding.bottom,
131
+ style: cursorStyle
132
+ }));
216
133
  }
217
- }];
218
- }, _class;
134
+ if (cursorDimension === "y" || cursorDimension === undefined) {
135
+ newElements.push( /*#__PURE__*/React.cloneElement(cursorComponent, {
136
+ key: `${name}-y-cursor`,
137
+ x1: padding.left,
138
+ x2: width - padding.right,
139
+ y1: cursorCoordinates.y,
140
+ y2: cursorCoordinates.y,
141
+ style: cursorStyle
142
+ }));
143
+ }
144
+ return newElements;
145
+ }
146
+
147
+ // Overrides method in VictoryContainer
148
+ getChildren(props) {
149
+ return [...React.Children.toArray(props.children), ...this.getCursorElements(props)];
150
+ }
151
+ };
219
152
  }
220
- export var VictoryCursorContainer = cursorContainerMixin(VictoryContainer);
153
+ export const VictoryCursorContainer = cursorContainerMixin(VictoryContainer);