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.
- package/CHANGELOG.md +12 -14
- package/README.md +2 -2
- package/dist/victory-cursor-container.js +1501 -2069
- package/dist/victory-cursor-container.min.js +1 -1
- package/es/cursor-helpers.d.ts +32 -32
- package/es/cursor-helpers.js +78 -110
- package/es/index.d.ts +2 -2
- package/es/victory-cursor-container.d.ts +133 -133
- package/es/victory-cursor-container.js +138 -205
- package/lib/cursor-helpers.d.ts +32 -32
- package/lib/cursor-helpers.js +79 -118
- package/lib/index.d.ts +2 -2
- package/lib/index.js +0 -4
- package/lib/victory-cursor-container.d.ts +133 -133
- package/lib/victory-cursor-container.js +138 -215
- package/package.json +6 -3
- package/src/victory-cursor-container.tsx +165 -186
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
/* eslint-disable complexity */
|
|
2
1
|
import React from "react";
|
|
3
2
|
import {
|
|
3
|
+
VictoryContainer,
|
|
4
4
|
Helpers,
|
|
5
5
|
VictoryContainerProps,
|
|
6
6
|
CoordinatesPropType,
|
|
@@ -8,10 +8,6 @@ import {
|
|
|
8
8
|
ValueOrAccessor,
|
|
9
9
|
VictoryLabel,
|
|
10
10
|
LineSegment,
|
|
11
|
-
VictoryContainer,
|
|
12
|
-
VictoryEventHandler,
|
|
13
|
-
DomainTuple,
|
|
14
|
-
PaddingProps,
|
|
15
11
|
} from "victory-core";
|
|
16
12
|
import { defaults, isObject } from "lodash";
|
|
17
13
|
import { CursorHelpers } from "./cursor-helpers";
|
|
@@ -26,208 +22,191 @@ export interface VictoryCursorContainerProps extends VictoryContainerProps {
|
|
|
26
22
|
cursorLabelOffset?: CursorCoordinatesPropType;
|
|
27
23
|
defaultCursorValue?: CursorCoordinatesPropType;
|
|
28
24
|
disable?: boolean;
|
|
29
|
-
horizontal?: boolean;
|
|
30
|
-
padding?: PaddingProps;
|
|
31
25
|
onCursorChange?: (
|
|
32
26
|
value: CursorCoordinatesPropType,
|
|
33
27
|
props: VictoryCursorContainerProps,
|
|
34
28
|
) => void;
|
|
35
29
|
}
|
|
36
30
|
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
31
|
+
type ComponentClass<TProps> = { new (props: TProps): React.Component<TProps> };
|
|
32
|
+
|
|
33
|
+
export function cursorContainerMixin<
|
|
34
|
+
TBase extends ComponentClass<TProps>,
|
|
35
|
+
TProps extends VictoryCursorContainerProps,
|
|
36
|
+
>(Base: TBase) {
|
|
37
|
+
// @ts-expect-error "TS2545: A mixin class must have a constructor with a single rest parameter of type 'any[]'."
|
|
38
|
+
return class VictoryCursorContainer extends Base {
|
|
39
|
+
static displayName = "VictoryCursorContainer";
|
|
40
|
+
static defaultProps = {
|
|
41
|
+
...VictoryContainer.defaultProps,
|
|
42
|
+
cursorLabelComponent: <VictoryLabel />,
|
|
43
|
+
cursorLabelOffset: {
|
|
44
|
+
x: 5,
|
|
45
|
+
y: -10,
|
|
46
|
+
},
|
|
47
|
+
cursorComponent: <LineSegment />,
|
|
48
|
+
};
|
|
49
|
+
static defaultEvents = (props) => {
|
|
50
|
+
return [
|
|
51
|
+
{
|
|
52
|
+
target: "parent",
|
|
53
|
+
eventHandlers: {
|
|
54
|
+
onMouseLeave: (evt, targetProps) => {
|
|
55
|
+
return props.disable
|
|
56
|
+
? {}
|
|
57
|
+
: CursorHelpers.onMouseLeave(evt, targetProps);
|
|
58
|
+
},
|
|
59
|
+
onTouchCancel: () => {
|
|
60
|
+
return [];
|
|
61
|
+
},
|
|
62
|
+
onMouseMove: (evt, targetProps) => {
|
|
63
|
+
return props.disable
|
|
64
|
+
? {}
|
|
65
|
+
: CursorHelpers.onMouseMove(evt, targetProps);
|
|
66
|
+
},
|
|
67
|
+
onTouchMove: (evt, targetProps) => {
|
|
68
|
+
return props.disable
|
|
69
|
+
? {}
|
|
70
|
+
: CursorHelpers.onMouseMove(evt, targetProps);
|
|
71
|
+
},
|
|
72
|
+
},
|
|
73
|
+
},
|
|
74
|
+
];
|
|
75
|
+
};
|
|
76
|
+
|
|
77
|
+
getCursorPosition(props) {
|
|
78
|
+
const { cursorValue, defaultCursorValue, domain, cursorDimension } =
|
|
79
|
+
props;
|
|
80
|
+
if (cursorValue) {
|
|
81
|
+
return cursorValue;
|
|
82
|
+
}
|
|
60
83
|
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
84
|
+
if (typeof defaultCursorValue === "number") {
|
|
85
|
+
return {
|
|
86
|
+
x: (domain.x[0] + domain.x[1]) / 2,
|
|
87
|
+
y: (domain.y[0] + domain.y[1]) / 2,
|
|
88
|
+
[cursorDimension]: defaultCursorValue,
|
|
89
|
+
};
|
|
90
|
+
}
|
|
66
91
|
|
|
67
|
-
|
|
68
|
-
return {
|
|
69
|
-
x: ((domain.x[0] as number) + (domain.x[1] as number)) / 2,
|
|
70
|
-
y: ((domain.y[0] as number) + (domain.y[1] as number)) / 2,
|
|
71
|
-
...(cursorDimension ? { [cursorDimension]: defaultCursorValue } : {}),
|
|
72
|
-
};
|
|
92
|
+
return defaultCursorValue;
|
|
73
93
|
}
|
|
74
94
|
|
|
75
|
-
|
|
76
|
-
|
|
95
|
+
getCursorLabelOffset(props) {
|
|
96
|
+
const { cursorLabelOffset } = props;
|
|
77
97
|
|
|
78
|
-
|
|
79
|
-
|
|
98
|
+
if (typeof cursorLabelOffset === "number") {
|
|
99
|
+
return {
|
|
100
|
+
x: cursorLabelOffset,
|
|
101
|
+
y: cursorLabelOffset,
|
|
102
|
+
};
|
|
103
|
+
}
|
|
80
104
|
|
|
81
|
-
|
|
82
|
-
return {
|
|
83
|
-
x: cursorLabelOffset,
|
|
84
|
-
y: cursorLabelOffset,
|
|
85
|
-
};
|
|
105
|
+
return cursorLabelOffset;
|
|
86
106
|
}
|
|
87
107
|
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
})
|
|
97
|
-
: props.children;
|
|
98
|
-
return Helpers.getPadding(child?.props);
|
|
108
|
+
getPadding(props) {
|
|
109
|
+
if (props.padding === undefined) {
|
|
110
|
+
const child = props.children.find((c) => {
|
|
111
|
+
return isObject(c.props) && c.props.padding !== undefined;
|
|
112
|
+
});
|
|
113
|
+
return Helpers.getPadding(child.props);
|
|
114
|
+
}
|
|
115
|
+
return Helpers.getPadding(props);
|
|
99
116
|
}
|
|
100
|
-
return Helpers.getPadding(props);
|
|
101
|
-
};
|
|
102
117
|
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
118
|
+
getCursorElements(props) {
|
|
119
|
+
// eslint-disable-line max-statements
|
|
120
|
+
const {
|
|
121
|
+
scale,
|
|
122
|
+
cursorLabelComponent,
|
|
123
|
+
cursorLabel,
|
|
124
|
+
cursorComponent,
|
|
125
|
+
width,
|
|
126
|
+
height,
|
|
127
|
+
name,
|
|
128
|
+
horizontal,
|
|
129
|
+
theme,
|
|
130
|
+
} = props;
|
|
131
|
+
const cursorDimension = CursorHelpers.getDimension(props);
|
|
132
|
+
const cursorValue = this.getCursorPosition(props);
|
|
133
|
+
const cursorLabelOffset = this.getCursorLabelOffset(props);
|
|
134
|
+
|
|
135
|
+
if (!cursorValue) {
|
|
136
|
+
return [];
|
|
137
|
+
}
|
|
123
138
|
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
139
|
+
const newElements: React.ReactElement[] = [];
|
|
140
|
+
const padding = this.getPadding(props);
|
|
141
|
+
const cursorCoordinates = {
|
|
142
|
+
x: horizontal ? scale.y(cursorValue.y) : scale.x(cursorValue.x),
|
|
143
|
+
y: horizontal ? scale.x(cursorValue.x) : scale.y(cursorValue.y),
|
|
144
|
+
};
|
|
145
|
+
if (cursorLabel) {
|
|
146
|
+
let labelProps = defaults(
|
|
147
|
+
{ active: true },
|
|
148
|
+
cursorLabelComponent.props,
|
|
149
|
+
{
|
|
150
|
+
x: cursorCoordinates.x + cursorLabelOffset.x,
|
|
151
|
+
y: cursorCoordinates.y + cursorLabelOffset.y,
|
|
152
|
+
datum: cursorValue,
|
|
153
|
+
active: true,
|
|
154
|
+
key: `${name}-cursor-label`,
|
|
155
|
+
},
|
|
156
|
+
);
|
|
157
|
+
if (Helpers.isTooltip(cursorLabelComponent)) {
|
|
158
|
+
const tooltipTheme = (theme && theme.tooltip) || {};
|
|
159
|
+
labelProps = defaults({}, labelProps, tooltipTheme);
|
|
160
|
+
}
|
|
161
|
+
newElements.push(
|
|
162
|
+
React.cloneElement(
|
|
163
|
+
cursorLabelComponent,
|
|
164
|
+
defaults({}, labelProps, {
|
|
165
|
+
text: Helpers.evaluateProp(cursorLabel, labelProps),
|
|
166
|
+
}),
|
|
167
|
+
),
|
|
168
|
+
);
|
|
151
169
|
}
|
|
152
|
-
newElements.push(
|
|
153
|
-
React.cloneElement(
|
|
154
|
-
cursorLabelComponent,
|
|
155
|
-
defaults({}, labelProps, {
|
|
156
|
-
text: Helpers.evaluateProp(cursorLabel, labelProps),
|
|
157
|
-
}),
|
|
158
|
-
),
|
|
159
|
-
);
|
|
160
|
-
}
|
|
161
170
|
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
);
|
|
166
|
-
if (cursorDimension === "x" || cursorDimension === undefined) {
|
|
167
|
-
newElements.push(
|
|
168
|
-
React.cloneElement(cursorComponent, {
|
|
169
|
-
key: `${name}-x-cursor`,
|
|
170
|
-
x1: cursorCoordinates.x,
|
|
171
|
-
x2: cursorCoordinates.x,
|
|
172
|
-
y1: padding.top,
|
|
173
|
-
y2: (typeof height === "number" ? height : 0) - padding.bottom,
|
|
174
|
-
style: cursorStyle,
|
|
175
|
-
}),
|
|
171
|
+
const cursorStyle = Object.assign(
|
|
172
|
+
{ stroke: "black" },
|
|
173
|
+
cursorComponent.props.style,
|
|
176
174
|
);
|
|
175
|
+
if (cursorDimension === "x" || cursorDimension === undefined) {
|
|
176
|
+
newElements.push(
|
|
177
|
+
React.cloneElement(cursorComponent, {
|
|
178
|
+
key: `${name}-x-cursor`,
|
|
179
|
+
x1: cursorCoordinates.x,
|
|
180
|
+
x2: cursorCoordinates.x,
|
|
181
|
+
y1: padding.top,
|
|
182
|
+
y2: height - padding.bottom,
|
|
183
|
+
style: cursorStyle,
|
|
184
|
+
}),
|
|
185
|
+
);
|
|
186
|
+
}
|
|
187
|
+
if (cursorDimension === "y" || cursorDimension === undefined) {
|
|
188
|
+
newElements.push(
|
|
189
|
+
React.cloneElement(cursorComponent, {
|
|
190
|
+
key: `${name}-y-cursor`,
|
|
191
|
+
x1: padding.left,
|
|
192
|
+
x2: width - padding.right,
|
|
193
|
+
y1: cursorCoordinates.y,
|
|
194
|
+
y2: cursorCoordinates.y,
|
|
195
|
+
style: cursorStyle,
|
|
196
|
+
}),
|
|
197
|
+
);
|
|
198
|
+
}
|
|
199
|
+
return newElements;
|
|
177
200
|
}
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
y2: cursorCoordinates.y,
|
|
186
|
-
style: cursorStyle,
|
|
187
|
-
}),
|
|
188
|
-
);
|
|
201
|
+
|
|
202
|
+
// Overrides method in VictoryContainer
|
|
203
|
+
getChildren(props) {
|
|
204
|
+
return [
|
|
205
|
+
...React.Children.toArray(props.children),
|
|
206
|
+
...this.getCursorElements(props),
|
|
207
|
+
];
|
|
189
208
|
}
|
|
190
|
-
return newElements;
|
|
191
209
|
};
|
|
210
|
+
}
|
|
192
211
|
|
|
193
|
-
|
|
194
|
-
props,
|
|
195
|
-
children: [
|
|
196
|
-
...React.Children.toArray(children),
|
|
197
|
-
...getCursorElements(),
|
|
198
|
-
] as React.ReactElement[],
|
|
199
|
-
};
|
|
200
|
-
};
|
|
201
|
-
|
|
202
|
-
export const VictoryCursorContainer = (
|
|
203
|
-
initialProps: VictoryCursorContainerProps,
|
|
204
|
-
) => {
|
|
205
|
-
const { props, children } = useVictoryCursorContainer(initialProps);
|
|
206
|
-
return <VictoryContainer {...props}>{children}</VictoryContainer>;
|
|
207
|
-
};
|
|
208
|
-
|
|
209
|
-
VictoryCursorContainer.role = "container";
|
|
210
|
-
|
|
211
|
-
VictoryCursorContainer.defaultEvents = (
|
|
212
|
-
initialProps: VictoryCursorContainerProps,
|
|
213
|
-
) => {
|
|
214
|
-
const props = { ...VICTORY_CURSOR_CONTAINER_DEFAULT_PROPS, ...initialProps };
|
|
215
|
-
const createEventHandler =
|
|
216
|
-
(handler: VictoryEventHandler, disabled?: boolean): VictoryEventHandler =>
|
|
217
|
-
// eslint-disable-next-line max-params
|
|
218
|
-
(event, targetProps, eventKey, context) =>
|
|
219
|
-
disabled || props.disable
|
|
220
|
-
? {}
|
|
221
|
-
: handler(event, { ...props, ...targetProps }, eventKey, context);
|
|
222
|
-
|
|
223
|
-
return [
|
|
224
|
-
{
|
|
225
|
-
target: "parent",
|
|
226
|
-
eventHandlers: {
|
|
227
|
-
onMouseLeave: createEventHandler(CursorHelpers.onMouseLeave),
|
|
228
|
-
onMouseMove: createEventHandler(CursorHelpers.onMouseMove),
|
|
229
|
-
onTouchMove: createEventHandler(CursorHelpers.onMouseMove),
|
|
230
|
-
},
|
|
231
|
-
},
|
|
232
|
-
];
|
|
233
|
-
};
|
|
212
|
+
export const VictoryCursorContainer = cursorContainerMixin(VictoryContainer);
|