victory-cursor-container 36.9.2-next.1 → 36.9.2
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 +6 -12
- package/LICENSE.txt +30 -0
- package/README.md +2 -2
- package/dist/victory-cursor-container.js +1045 -31023
- package/dist/victory-cursor-container.min.js +1 -2
- package/es/cursor-helpers.d.ts +32 -32
- package/es/index.d.ts +2 -2
- package/es/victory-cursor-container.d.ts +133 -84
- package/es/victory-cursor-container.js +188 -161
- package/lib/cursor-helpers.d.ts +32 -32
- package/lib/index.d.ts +2 -2
- package/lib/victory-cursor-container.d.ts +133 -84
- package/lib/victory-cursor-container.js +189 -166
- package/package.json +6 -3
- package/src/victory-cursor-container.tsx +164 -174
- package/dist/victory-cursor-container.min.js.LICENSE.txt +0 -19
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import React from "react";
|
|
2
2
|
import {
|
|
3
|
+
VictoryContainer,
|
|
3
4
|
Helpers,
|
|
4
5
|
VictoryContainerProps,
|
|
5
6
|
CoordinatesPropType,
|
|
@@ -7,10 +8,6 @@ import {
|
|
|
7
8
|
ValueOrAccessor,
|
|
8
9
|
VictoryLabel,
|
|
9
10
|
LineSegment,
|
|
10
|
-
VictoryContainer,
|
|
11
|
-
VictoryEventHandler,
|
|
12
|
-
DomainTuple,
|
|
13
|
-
PaddingProps,
|
|
14
11
|
} from "victory-core";
|
|
15
12
|
import { defaults, isObject } from "lodash";
|
|
16
13
|
import { CursorHelpers } from "./cursor-helpers";
|
|
@@ -25,198 +22,191 @@ export interface VictoryCursorContainerProps extends VictoryContainerProps {
|
|
|
25
22
|
cursorLabelOffset?: CursorCoordinatesPropType;
|
|
26
23
|
defaultCursorValue?: CursorCoordinatesPropType;
|
|
27
24
|
disable?: boolean;
|
|
28
|
-
horizontal?: boolean;
|
|
29
|
-
padding?: PaddingProps;
|
|
30
25
|
onCursorChange?: (
|
|
31
26
|
value: CursorCoordinatesPropType,
|
|
32
27
|
props: VictoryCursorContainerProps,
|
|
33
28
|
) => void;
|
|
34
29
|
}
|
|
35
30
|
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
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
|
+
};
|
|
41
76
|
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
cursorComponent: <LineSegment />,
|
|
49
|
-
};
|
|
50
|
-
|
|
51
|
-
export const useVictoryCursorContainer = (
|
|
52
|
-
initialProps: VictoryCursorContainerProps,
|
|
53
|
-
) => {
|
|
54
|
-
const props = {
|
|
55
|
-
...VICTORY_CURSOR_CONTAINER_DEFAULT_PROPS,
|
|
56
|
-
...(initialProps as VictoryCursorContainerMutatedProps),
|
|
57
|
-
};
|
|
58
|
-
const { children } = props;
|
|
77
|
+
getCursorPosition(props) {
|
|
78
|
+
const { cursorValue, defaultCursorValue, domain, cursorDimension } =
|
|
79
|
+
props;
|
|
80
|
+
if (cursorValue) {
|
|
81
|
+
return cursorValue;
|
|
82
|
+
}
|
|
59
83
|
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
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
|
+
}
|
|
65
91
|
|
|
66
|
-
|
|
67
|
-
return {
|
|
68
|
-
x: ((domain.x[0] as number) + (domain.x[1] as number)) / 2,
|
|
69
|
-
y: ((domain.y[0] as number) + (domain.y[1] as number)) / 2,
|
|
70
|
-
...(cursorDimension ? { [cursorDimension]: defaultCursorValue } : {}),
|
|
71
|
-
};
|
|
92
|
+
return defaultCursorValue;
|
|
72
93
|
}
|
|
73
94
|
|
|
74
|
-
|
|
75
|
-
|
|
95
|
+
getCursorLabelOffset(props) {
|
|
96
|
+
const { cursorLabelOffset } = props;
|
|
76
97
|
|
|
77
|
-
|
|
78
|
-
|
|
98
|
+
if (typeof cursorLabelOffset === "number") {
|
|
99
|
+
return {
|
|
100
|
+
x: cursorLabelOffset,
|
|
101
|
+
y: cursorLabelOffset,
|
|
102
|
+
};
|
|
103
|
+
}
|
|
79
104
|
|
|
80
|
-
|
|
81
|
-
return {
|
|
82
|
-
x: cursorLabelOffset,
|
|
83
|
-
y: cursorLabelOffset,
|
|
84
|
-
};
|
|
105
|
+
return cursorLabelOffset;
|
|
85
106
|
}
|
|
86
107
|
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
})
|
|
96
|
-
: props.children;
|
|
97
|
-
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);
|
|
98
116
|
}
|
|
99
|
-
return Helpers.getPadding(props);
|
|
100
|
-
};
|
|
101
117
|
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
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
|
+
}
|
|
122
138
|
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
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
|
+
);
|
|
140
169
|
}
|
|
141
|
-
newElements.push(
|
|
142
|
-
React.cloneElement(
|
|
143
|
-
cursorLabelComponent,
|
|
144
|
-
defaults({}, labelProps, {
|
|
145
|
-
text: Helpers.evaluateProp(cursorLabel, labelProps),
|
|
146
|
-
}),
|
|
147
|
-
),
|
|
148
|
-
);
|
|
149
|
-
}
|
|
150
170
|
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
);
|
|
155
|
-
if (cursorDimension === "x" || cursorDimension === undefined) {
|
|
156
|
-
newElements.push(
|
|
157
|
-
React.cloneElement(cursorComponent, {
|
|
158
|
-
key: `${name}-x-cursor`,
|
|
159
|
-
x1: cursorCoordinates.x,
|
|
160
|
-
x2: cursorCoordinates.x,
|
|
161
|
-
y1: padding.top,
|
|
162
|
-
y2: height || 0 - padding.bottom,
|
|
163
|
-
style: cursorStyle,
|
|
164
|
-
}),
|
|
171
|
+
const cursorStyle = Object.assign(
|
|
172
|
+
{ stroke: "black" },
|
|
173
|
+
cursorComponent.props.style,
|
|
165
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;
|
|
166
200
|
}
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
y2: cursorCoordinates.y,
|
|
175
|
-
style: cursorStyle,
|
|
176
|
-
}),
|
|
177
|
-
);
|
|
201
|
+
|
|
202
|
+
// Overrides method in VictoryContainer
|
|
203
|
+
getChildren(props) {
|
|
204
|
+
return [
|
|
205
|
+
...React.Children.toArray(props.children),
|
|
206
|
+
...this.getCursorElements(props),
|
|
207
|
+
];
|
|
178
208
|
}
|
|
179
|
-
return newElements;
|
|
180
209
|
};
|
|
210
|
+
}
|
|
181
211
|
|
|
182
|
-
|
|
183
|
-
props,
|
|
184
|
-
children: [
|
|
185
|
-
...React.Children.toArray(children),
|
|
186
|
-
...getCursorElements(),
|
|
187
|
-
] as React.ReactElement[],
|
|
188
|
-
};
|
|
189
|
-
};
|
|
190
|
-
|
|
191
|
-
export const VictoryCursorContainer = (
|
|
192
|
-
initialProps: VictoryCursorContainerProps,
|
|
193
|
-
) => {
|
|
194
|
-
const { props, children } = useVictoryCursorContainer(initialProps);
|
|
195
|
-
return <VictoryContainer {...props}>{children}</VictoryContainer>;
|
|
196
|
-
};
|
|
197
|
-
|
|
198
|
-
VictoryCursorContainer.role = "container";
|
|
199
|
-
|
|
200
|
-
VictoryCursorContainer.defaultEvents = (
|
|
201
|
-
initialProps: VictoryCursorContainerProps,
|
|
202
|
-
) => {
|
|
203
|
-
const props = { ...VICTORY_CURSOR_CONTAINER_DEFAULT_PROPS, ...initialProps };
|
|
204
|
-
const createEventHandler =
|
|
205
|
-
(handler: VictoryEventHandler, disabled?: boolean): VictoryEventHandler =>
|
|
206
|
-
// eslint-disable-next-line max-params
|
|
207
|
-
(event, targetProps, eventKey, context) =>
|
|
208
|
-
disabled || props.disable
|
|
209
|
-
? {}
|
|
210
|
-
: handler(event, { ...props, ...targetProps }, eventKey, context);
|
|
211
|
-
|
|
212
|
-
return [
|
|
213
|
-
{
|
|
214
|
-
target: "parent",
|
|
215
|
-
eventHandlers: {
|
|
216
|
-
onMouseLeave: createEventHandler(CursorHelpers.onMouseLeave),
|
|
217
|
-
onMouseMove: createEventHandler(CursorHelpers.onMouseMove),
|
|
218
|
-
onTouchMove: createEventHandler(CursorHelpers.onMouseMove),
|
|
219
|
-
},
|
|
220
|
-
},
|
|
221
|
-
];
|
|
222
|
-
};
|
|
212
|
+
export const VictoryCursorContainer = cursorContainerMixin(VictoryContainer);
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @license React
|
|
3
|
-
* react-dom.production.min.js
|
|
4
|
-
*
|
|
5
|
-
* Copyright (c) Facebook, Inc. and its affiliates.
|
|
6
|
-
*
|
|
7
|
-
* This source code is licensed under the MIT license found in the
|
|
8
|
-
* LICENSE file in the root directory of this source tree.
|
|
9
|
-
*/
|
|
10
|
-
|
|
11
|
-
/**
|
|
12
|
-
* @license React
|
|
13
|
-
* scheduler.production.min.js
|
|
14
|
-
*
|
|
15
|
-
* Copyright (c) Facebook, Inc. and its affiliates.
|
|
16
|
-
*
|
|
17
|
-
* This source code is licensed under the MIT license found in the
|
|
18
|
-
* LICENSE file in the root directory of this source tree.
|
|
19
|
-
*/
|