victory-cursor-container 30.6.1 → 31.2.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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "victory-cursor-container",
3
- "version": "30.6.1",
3
+ "version": "31.2.0",
4
4
  "description": "Interactive Cursor Component for Victory",
5
5
  "keywords": [
6
6
  "data visualization",
@@ -21,7 +21,7 @@
21
21
  "dependencies": {
22
22
  "lodash": "^4.17.5",
23
23
  "prop-types": "^15.5.8",
24
- "victory-core": "^30.6.1"
24
+ "victory-core": "^31.2.0"
25
25
  },
26
26
  "scripts": {
27
27
  "version": "nps build-libs && nps build-dists"
@@ -5,10 +5,12 @@ const CursorHelpers = {
5
5
  withinBounds(point, bounds) {
6
6
  const { x1, x2, y1, y2 } = mapValues(bounds, Number);
7
7
  const { x, y } = mapValues(point, Number);
8
- return x >= Math.min(x1, x2) &&
8
+ return (
9
+ x >= Math.min(x1, x2) &&
9
10
  x <= Math.max(x1, x2) &&
10
11
  y >= Math.min(y1, y2) &&
11
- y <= Math.max(y1, y2);
12
+ y <= Math.max(y1, y2)
13
+ );
12
14
  },
13
15
 
14
16
  onMouseMove(evt, targetProps) {
@@ -42,11 +44,13 @@ const CursorHelpers = {
42
44
  }
43
45
  }
44
46
 
45
- return [{
46
- target: "parent",
47
- eventKey: "parent",
48
- mutation: () => ({ cursorValue, parentSVG })
49
- }];
47
+ return [
48
+ {
49
+ target: "parent",
50
+ eventKey: "parent",
51
+ mutation: () => ({ cursorValue, parentSVG })
52
+ }
53
+ ];
50
54
  },
51
55
 
52
56
  onTouchEnd(evt, targetProps) {
@@ -56,11 +60,13 @@ const CursorHelpers = {
56
60
  onCursorChange(null, targetProps);
57
61
  }
58
62
 
59
- return [{
60
- target: "parent",
61
- eventKey: "parent",
62
- mutation: () => ({ cursorValue: null })
63
- }];
63
+ return [
64
+ {
65
+ target: "parent",
66
+ eventKey: "parent",
67
+ mutation: () => ({ cursorValue: null })
68
+ }
69
+ ];
64
70
  }
65
71
  };
66
72
 
@@ -68,6 +74,7 @@ export default {
68
74
  onMouseMove: throttle(
69
75
  CursorHelpers.onMouseMove.bind(CursorHelpers),
70
76
  32, // eslint-disable-line no-magic-numbers
71
- { leading: true, trailing: false }),
77
+ { leading: true, trailing: false }
78
+ ),
72
79
  onTouchEnd: CursorHelpers.onTouchEnd.bind(CursorHelpers)
73
80
  };
@@ -4,160 +4,176 @@ import { VictoryContainer, VictoryLabel, LineSegment, Helpers } from "victory-co
4
4
  import { defaults, assign, isObject } from "lodash";
5
5
  import CursorHelpers from "./cursor-helpers";
6
6
 
7
- export const cursorContainerMixin = (base) => class VictoryCursorContainer extends base {
8
- static displayName = "VictoryCursorContainer";
9
- static propTypes = {
10
- ...VictoryContainer.propTypes,
11
- cursorDimension: PropTypes.oneOf(["x", "y"]),
12
- cursorLabel: PropTypes.func,
13
- cursorLabelComponent: PropTypes.element,
14
- cursorLabelOffset: PropTypes.oneOfType([
15
- PropTypes.number,
16
- PropTypes.shape({
17
- x: PropTypes.number,
18
- y: PropTypes.number
19
- })
20
- ]),
21
- defaultCursorValue: PropTypes.oneOfType([
22
- PropTypes.number,
23
- PropTypes.shape({
24
- x: PropTypes.number,
25
- y: PropTypes.number
26
- })
27
- ]),
28
- disable: PropTypes.bool,
29
- onCursorChange: PropTypes.func
30
- };
31
- static defaultProps = {
32
- ...VictoryContainer.defaultProps,
33
- cursorLabelComponent: <VictoryLabel/>,
34
- cursorLabelOffset: {
35
- x: 5,
36
- y: -10
37
- },
38
- cursorComponent: <LineSegment/>
39
- };
7
+ export const cursorContainerMixin = (base) =>
8
+ class VictoryCursorContainer extends base {
9
+ static displayName = "VictoryCursorContainer";
10
+ static propTypes = {
11
+ ...VictoryContainer.propTypes,
12
+ cursorDimension: PropTypes.oneOf(["x", "y"]),
13
+ cursorLabel: PropTypes.func,
14
+ cursorLabelComponent: PropTypes.element,
15
+ cursorLabelOffset: PropTypes.oneOfType([
16
+ PropTypes.number,
17
+ PropTypes.shape({
18
+ x: PropTypes.number,
19
+ y: PropTypes.number
20
+ })
21
+ ]),
22
+ defaultCursorValue: PropTypes.oneOfType([
23
+ PropTypes.number,
24
+ PropTypes.shape({
25
+ x: PropTypes.number,
26
+ y: PropTypes.number
27
+ })
28
+ ]),
29
+ disable: PropTypes.bool,
30
+ onCursorChange: PropTypes.func
31
+ };
32
+ static defaultProps = {
33
+ ...VictoryContainer.defaultProps,
34
+ cursorLabelComponent: <VictoryLabel />,
35
+ cursorLabelOffset: {
36
+ x: 5,
37
+ y: -10
38
+ },
39
+ cursorComponent: <LineSegment />
40
+ };
40
41
 
41
- static defaultEvents = (props) => {
42
- return [{
43
- target: "parent",
44
- eventHandlers: {
45
- onMouseLeave: () => {
46
- return [];
47
- },
48
- onTouchCancel: () => {
49
- return [];
50
- },
51
- onMouseMove: (evt, targetProps) => {
52
- return props.disable ? {} : CursorHelpers.onMouseMove(evt, targetProps);
53
- },
54
- onTouchMove: (evt, targetProps) => {
55
- return props.disable ? {} : CursorHelpers.onMouseMove(evt, targetProps);
42
+ static defaultEvents = (props) => {
43
+ return [
44
+ {
45
+ target: "parent",
46
+ eventHandlers: {
47
+ onMouseLeave: () => {
48
+ return [];
49
+ },
50
+ onTouchCancel: () => {
51
+ return [];
52
+ },
53
+ onMouseMove: (evt, targetProps) => {
54
+ return props.disable ? {} : CursorHelpers.onMouseMove(evt, targetProps);
55
+ },
56
+ onTouchMove: (evt, targetProps) => {
57
+ return props.disable ? {} : CursorHelpers.onMouseMove(evt, targetProps);
58
+ }
59
+ }
56
60
  }
61
+ ];
62
+ };
63
+
64
+ getCursorPosition(props) {
65
+ const { cursorValue, defaultCursorValue, cursorDimension, domain } = props;
66
+ if (cursorValue) {
67
+ return cursorValue;
57
68
  }
58
- }];
59
- };
60
69
 
61
- getCursorPosition(props) {
62
- const { cursorValue, defaultCursorValue, cursorDimension, domain } = props;
63
- if (cursorValue) { return cursorValue; }
70
+ if (typeof defaultCursorValue === "number") {
71
+ return {
72
+ x: (domain.x[0] + domain.x[1]) / 2,
73
+ y: (domain.y[0] + domain.y[1]) / 2,
74
+ [cursorDimension]: defaultCursorValue
75
+ };
76
+ }
64
77
 
65
- if (typeof defaultCursorValue === "number") {
66
- return {
67
- x: (domain.x[0] + domain.x[1]) / 2,
68
- y: (domain.y[0] + domain.y[1]) / 2,
69
- [cursorDimension]: defaultCursorValue
70
- };
78
+ return defaultCursorValue;
71
79
  }
72
80
 
73
- return defaultCursorValue;
74
- }
81
+ getCursorLabelOffset(props) {
82
+ const { cursorLabelOffset } = props;
75
83
 
76
- getCursorLabelOffset(props) {
77
- const { cursorLabelOffset } = props;
84
+ if (typeof cursorLabelOffset === "number") {
85
+ return {
86
+ x: cursorLabelOffset,
87
+ y: cursorLabelOffset
88
+ };
89
+ }
78
90
 
79
- if (typeof cursorLabelOffset === "number") {
80
- return {
81
- x: cursorLabelOffset,
82
- y: cursorLabelOffset
83
- };
91
+ return cursorLabelOffset;
84
92
  }
85
93
 
86
- return cursorLabelOffset;
87
- }
88
-
89
- getPadding(props) {
90
- if (props.padding === undefined) {
91
- const child = props.children.find((c) => {
92
- return isObject(c.props) && c.props.padding !== undefined;
93
- });
94
- return Helpers.getPadding(child.props);
95
- } else {
96
- return Helpers.getPadding(props);
94
+ getPadding(props) {
95
+ if (props.padding === undefined) {
96
+ const child = props.children.find((c) => {
97
+ return isObject(c.props) && c.props.padding !== undefined;
98
+ });
99
+ return Helpers.getPadding(child.props);
100
+ } else {
101
+ return Helpers.getPadding(props);
102
+ }
97
103
  }
98
- }
99
104
 
100
- getCursorElements(props) { // eslint-disable-line max-statements
101
- const {
102
- scale, cursorDimension, cursorLabelComponent, cursorLabel,
103
- cursorComponent, width, height, name
104
- } = props;
105
- const cursorValue = this.getCursorPosition(props);
106
- const cursorLabelOffset = this.getCursorLabelOffset(props);
105
+ getCursorElements(props) {
106
+ // eslint-disable-line max-statements
107
+ const {
108
+ scale,
109
+ cursorDimension,
110
+ cursorLabelComponent,
111
+ cursorLabel,
112
+ cursorComponent,
113
+ width,
114
+ height,
115
+ name
116
+ } = props;
117
+ const cursorValue = this.getCursorPosition(props);
118
+ const cursorLabelOffset = this.getCursorLabelOffset(props);
107
119
 
108
- if (!cursorValue) { return []; }
120
+ if (!cursorValue) {
121
+ return [];
122
+ }
109
123
 
110
- const newElements = [];
111
- const padding = this.getPadding(props);
112
- const cursorCoordinates = {
113
- x: scale.x(cursorValue.x),
114
- y: scale.y(cursorValue.y)
115
- };
116
- if (cursorLabel) {
117
- newElements.push(React.cloneElement(
118
- cursorLabelComponent,
119
- defaults(
120
- { active: true },
121
- cursorLabelComponent.props,
122
- {
123
- x: cursorCoordinates.x + cursorLabelOffset.x,
124
- y: cursorCoordinates.y + cursorLabelOffset.y,
125
- text: Helpers.evaluateProp(cursorLabel, cursorValue, true),
126
- active: true,
127
- key: `${name}-cursor-label`
128
- }
129
- )
130
- ));
131
- }
124
+ const newElements = [];
125
+ const padding = this.getPadding(props);
126
+ const cursorCoordinates = {
127
+ x: scale.x(cursorValue.x),
128
+ y: scale.y(cursorValue.y)
129
+ };
130
+ if (cursorLabel) {
131
+ newElements.push(
132
+ React.cloneElement(
133
+ cursorLabelComponent,
134
+ defaults({ active: true }, cursorLabelComponent.props, {
135
+ x: cursorCoordinates.x + cursorLabelOffset.x,
136
+ y: cursorCoordinates.y + cursorLabelOffset.y,
137
+ text: Helpers.evaluateProp(cursorLabel, cursorValue, true),
138
+ active: true,
139
+ key: `${name}-cursor-label`
140
+ })
141
+ )
142
+ );
143
+ }
132
144
 
133
- const cursorStyle = assign({ stroke: "black" }, cursorComponent.props.style);
134
- if (cursorDimension === "x" || cursorDimension === undefined) {
135
- newElements.push(React.cloneElement(cursorComponent, {
136
- key: `${name}-x-cursor`,
137
- x1: cursorCoordinates.x,
138
- x2: cursorCoordinates.x,
139
- y1: padding.top,
140
- y2: (height - padding.bottom),
141
- style: cursorStyle
142
- }));
143
- }
144
- if (cursorDimension === "y" || cursorDimension === undefined) {
145
- newElements.push(React.cloneElement(cursorComponent, {
146
- key: `${name}-y-cursor`,
147
- x1: padding.left,
148
- x2: (width - padding.right),
149
- y1: cursorCoordinates.y,
150
- y2: cursorCoordinates.y,
151
- style: cursorStyle
152
- }));
145
+ const cursorStyle = assign({ stroke: "black" }, cursorComponent.props.style);
146
+ if (cursorDimension === "x" || cursorDimension === undefined) {
147
+ newElements.push(
148
+ React.cloneElement(cursorComponent, {
149
+ key: `${name}-x-cursor`,
150
+ x1: cursorCoordinates.x,
151
+ x2: cursorCoordinates.x,
152
+ y1: padding.top,
153
+ y2: height - padding.bottom,
154
+ style: cursorStyle
155
+ })
156
+ );
157
+ }
158
+ if (cursorDimension === "y" || cursorDimension === undefined) {
159
+ newElements.push(
160
+ React.cloneElement(cursorComponent, {
161
+ key: `${name}-y-cursor`,
162
+ x1: padding.left,
163
+ x2: width - padding.right,
164
+ y1: cursorCoordinates.y,
165
+ y2: cursorCoordinates.y,
166
+ style: cursorStyle
167
+ })
168
+ );
169
+ }
170
+ return newElements;
153
171
  }
154
- return newElements;
155
- }
156
172
 
157
- // Overrides method in VictoryContainer
158
- getChildren(props) {
159
- return [...React.Children.toArray(props.children), ...this.getCursorElements(props)];
160
- }
161
- };
173
+ // Overrides method in VictoryContainer
174
+ getChildren(props) {
175
+ return [...React.Children.toArray(props.children), ...this.getCursorElements(props)];
176
+ }
177
+ };
162
178
 
163
179
  export default cursorContainerMixin(VictoryContainer);