victory-tooltip 36.9.2 → 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 +6 -0
- package/dist/victory-tooltip.js +1580 -1984
- package/dist/victory-tooltip.min.js +1 -1
- package/es/flyout.js +90 -68
- package/es/victory-tooltip.js +471 -576
- package/lib/flyout.js +89 -80
- package/lib/index.js +0 -4
- package/lib/victory-tooltip.js +472 -606
- package/package.json +2 -2
package/es/victory-tooltip.js
CHANGED
|
@@ -2,601 +2,496 @@ import _orderBy from "lodash/orderBy";
|
|
|
2
2
|
import _isPlainObject from "lodash/isPlainObject";
|
|
3
3
|
import _uniqueId from "lodash/uniqueId";
|
|
4
4
|
import _defaults from "lodash/defaults";
|
|
5
|
-
|
|
6
|
-
function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
|
|
7
|
-
|
|
8
|
-
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."); }
|
|
9
|
-
|
|
10
|
-
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); }
|
|
11
|
-
|
|
12
|
-
function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); }
|
|
13
|
-
|
|
14
|
-
function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }
|
|
15
|
-
|
|
16
|
-
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; }
|
|
17
|
-
|
|
18
|
-
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; }
|
|
19
|
-
|
|
20
|
-
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; }
|
|
21
|
-
|
|
22
|
-
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; }
|
|
23
|
-
|
|
24
|
-
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
|
25
|
-
|
|
26
|
-
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); } }
|
|
27
|
-
|
|
28
|
-
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
|
|
29
|
-
|
|
30
|
-
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); }
|
|
31
|
-
|
|
32
|
-
function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
|
|
33
|
-
|
|
34
|
-
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); }; }
|
|
35
|
-
|
|
36
|
-
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); }
|
|
37
|
-
|
|
38
|
-
function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
|
|
39
|
-
|
|
40
|
-
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; } }
|
|
41
|
-
|
|
42
|
-
function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
|
|
43
|
-
|
|
44
5
|
import React from "react";
|
|
45
6
|
import { TextSize, Helpers, LabelHelpers, VictoryLabel, VictoryTheme, VictoryPortal } from "victory-core";
|
|
46
7
|
import { Flyout } from "./flyout";
|
|
47
|
-
|
|
8
|
+
const fallbackProps = {
|
|
48
9
|
cornerRadius: 5,
|
|
49
10
|
pointerLength: 10,
|
|
50
11
|
pointerWidth: 10
|
|
51
12
|
};
|
|
52
|
-
export
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
13
|
+
export class VictoryTooltip extends React.Component {
|
|
14
|
+
static displayName = "VictoryTooltip";
|
|
15
|
+
static role = "tooltip";
|
|
16
|
+
static defaultProps = {
|
|
17
|
+
active: false,
|
|
18
|
+
renderInPortal: true,
|
|
19
|
+
labelComponent: /*#__PURE__*/React.createElement(VictoryLabel, null),
|
|
20
|
+
flyoutComponent: /*#__PURE__*/React.createElement(Flyout, null),
|
|
21
|
+
groupComponent: /*#__PURE__*/React.createElement("g", null)
|
|
22
|
+
};
|
|
23
|
+
static defaultEvents = props => {
|
|
24
|
+
const activate = props.activateData ? [{
|
|
25
|
+
target: "labels",
|
|
26
|
+
mutation: () => ({
|
|
27
|
+
active: true
|
|
28
|
+
})
|
|
29
|
+
}, {
|
|
30
|
+
target: "data",
|
|
31
|
+
mutation: () => ({
|
|
32
|
+
active: true
|
|
33
|
+
})
|
|
34
|
+
}] : [{
|
|
35
|
+
target: "labels",
|
|
36
|
+
mutation: () => ({
|
|
37
|
+
active: true
|
|
38
|
+
})
|
|
39
|
+
}];
|
|
40
|
+
const deactivate = props.activateData ? [{
|
|
41
|
+
target: "labels",
|
|
42
|
+
mutation: () => ({
|
|
43
|
+
active: undefined
|
|
44
|
+
})
|
|
45
|
+
}, {
|
|
46
|
+
target: "data",
|
|
47
|
+
mutation: () => ({
|
|
48
|
+
active: undefined
|
|
49
|
+
})
|
|
50
|
+
}] : [{
|
|
51
|
+
target: "labels",
|
|
52
|
+
mutation: () => ({
|
|
53
|
+
active: undefined
|
|
54
|
+
})
|
|
55
|
+
}];
|
|
56
|
+
return [{
|
|
57
|
+
target: "data",
|
|
58
|
+
eventHandlers: {
|
|
59
|
+
onMouseOver: () => activate,
|
|
60
|
+
onFocus: () => activate,
|
|
61
|
+
onTouchStart: () => activate,
|
|
62
|
+
onMouseOut: () => deactivate,
|
|
63
|
+
onBlur: () => deactivate,
|
|
64
|
+
onTouchEnd: () => deactivate
|
|
79
65
|
}
|
|
80
|
-
|
|
81
|
-
|
|
66
|
+
}];
|
|
67
|
+
};
|
|
68
|
+
constructor(props) {
|
|
69
|
+
super(props);
|
|
70
|
+
this.id = props.id === undefined ? _uniqueId("tooltip-") : props.id;
|
|
71
|
+
}
|
|
72
|
+
getDefaultOrientation(props) {
|
|
73
|
+
const {
|
|
74
|
+
datum,
|
|
75
|
+
horizontal,
|
|
76
|
+
polar
|
|
77
|
+
} = props;
|
|
78
|
+
if (!polar) {
|
|
79
|
+
const positive = horizontal ? "right" : "top";
|
|
80
|
+
const negative = horizontal ? "left" : "bottom";
|
|
81
|
+
return datum && datum.y < 0 ? negative : positive;
|
|
82
82
|
}
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
return degrees < 90 || degrees > 270 ? "right" : "left";
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
return degrees > 180 ? "bottom" : "top";
|
|
83
|
+
return this.getPolarOrientation(props);
|
|
84
|
+
}
|
|
85
|
+
getPolarOrientation(props) {
|
|
86
|
+
const degrees = LabelHelpers.getDegrees(props, props.datum);
|
|
87
|
+
const placement = props.labelPlacement || "vertical";
|
|
88
|
+
if (placement === "vertical") {
|
|
89
|
+
return this.getVerticalOrientations(degrees);
|
|
90
|
+
} else if (placement === "parallel") {
|
|
91
|
+
return degrees < 90 || degrees > 270 ? "right" : "left";
|
|
96
92
|
}
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
93
|
+
return degrees > 180 ? "bottom" : "top";
|
|
94
|
+
}
|
|
95
|
+
getVerticalOrientations(degrees) {
|
|
96
|
+
// eslint-disable-next-line no-magic-numbers
|
|
97
|
+
if (degrees < 45 || degrees > 315) {
|
|
98
|
+
return "right";
|
|
100
99
|
// eslint-disable-next-line no-magic-numbers
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
return "left";
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
return "bottom";
|
|
110
|
-
}
|
|
111
|
-
}, {
|
|
112
|
-
key: "getStyles",
|
|
113
|
-
value: function getStyles(props) {
|
|
114
|
-
var theme = props.theme || VictoryTheme.grayscale;
|
|
115
|
-
var defaultLabelStyles = theme && theme.tooltip && theme.tooltip.style ? theme.tooltip.style : {};
|
|
116
|
-
var baseLabelStyle = Array.isArray(props.style) ? props.style.map(function (s) {
|
|
117
|
-
return _defaults({}, s, defaultLabelStyles);
|
|
118
|
-
}) : _defaults({}, props.style, defaultLabelStyles);
|
|
119
|
-
var defaultFlyoutStyles = theme && theme.tooltip && theme.tooltip.flyoutStyle ? theme.tooltip.flyoutStyle : {};
|
|
120
|
-
var baseFlyoutStyle = props.flyoutStyle ? _defaults({}, props.flyoutStyle, defaultFlyoutStyles) : defaultFlyoutStyles;
|
|
121
|
-
var style = Array.isArray(baseLabelStyle) ? baseLabelStyle.map(function (s) {
|
|
122
|
-
return Helpers.evaluateStyle(s, props);
|
|
123
|
-
}) : Helpers.evaluateStyle(baseLabelStyle, props);
|
|
124
|
-
var flyoutStyle = Helpers.evaluateStyle(baseFlyoutStyle, Object.assign({}, props, {
|
|
125
|
-
style: style
|
|
126
|
-
}));
|
|
127
|
-
return {
|
|
128
|
-
style: style,
|
|
129
|
-
flyoutStyle: flyoutStyle
|
|
130
|
-
};
|
|
100
|
+
} else if (degrees >= 45 && degrees <= 135) {
|
|
101
|
+
return "top";
|
|
102
|
+
// eslint-disable-next-line no-magic-numbers
|
|
103
|
+
} else if (degrees > 135 && degrees < 225) {
|
|
104
|
+
return "left";
|
|
131
105
|
}
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
style: style,
|
|
163
|
-
flyoutStyle: flyoutStyle
|
|
164
|
-
})) || this.getDefaultOrientation(props);
|
|
165
|
-
var padding = Helpers.evaluateProp(props.flyoutPadding, Object.assign({}, props, {
|
|
166
|
-
active: active,
|
|
167
|
-
text: text,
|
|
168
|
-
style: style,
|
|
169
|
-
flyoutStyle: flyoutStyle,
|
|
170
|
-
orientation: orientation
|
|
171
|
-
})) || this.getLabelPadding(style);
|
|
172
|
-
var flyoutPadding = Helpers.getPadding({
|
|
173
|
-
padding: padding
|
|
174
|
-
});
|
|
175
|
-
var pointerWidth = Helpers.evaluateProp(props.pointerWidth, Object.assign({}, props, {
|
|
176
|
-
active: active,
|
|
177
|
-
text: text,
|
|
178
|
-
style: style,
|
|
179
|
-
flyoutStyle: flyoutStyle,
|
|
180
|
-
orientation: orientation
|
|
181
|
-
}));
|
|
182
|
-
var pointerLength = Helpers.evaluateProp(props.pointerLength, Object.assign({}, props, {
|
|
183
|
-
active: active,
|
|
184
|
-
text: text,
|
|
185
|
-
style: style,
|
|
186
|
-
flyoutStyle: flyoutStyle,
|
|
187
|
-
orientation: orientation
|
|
188
|
-
}));
|
|
189
|
-
var labelSize = TextSize.approximateTextSize(text, style);
|
|
190
|
-
|
|
191
|
-
var _this$getDimensions = this.getDimensions(Object.assign({}, props, {
|
|
192
|
-
style: style,
|
|
193
|
-
flyoutStyle: flyoutStyle,
|
|
194
|
-
active: active,
|
|
195
|
-
text: text,
|
|
196
|
-
orientation: orientation,
|
|
197
|
-
flyoutPadding: flyoutPadding,
|
|
198
|
-
pointerWidth: pointerWidth,
|
|
199
|
-
pointerLength: pointerLength
|
|
200
|
-
}), labelSize),
|
|
201
|
-
flyoutHeight = _this$getDimensions.flyoutHeight,
|
|
202
|
-
flyoutWidth = _this$getDimensions.flyoutWidth;
|
|
203
|
-
|
|
204
|
-
var evaluatedProps = Object.assign({}, props, {
|
|
205
|
-
active: active,
|
|
206
|
-
text: text,
|
|
207
|
-
style: style,
|
|
208
|
-
flyoutStyle: flyoutStyle,
|
|
209
|
-
orientation: orientation,
|
|
210
|
-
flyoutHeight: flyoutHeight,
|
|
211
|
-
flyoutWidth: flyoutWidth,
|
|
212
|
-
flyoutPadding: flyoutPadding,
|
|
213
|
-
pointerWidth: pointerWidth,
|
|
214
|
-
pointerLength: pointerLength
|
|
215
|
-
});
|
|
216
|
-
var offsetX = _isPlainObject(centerOffset) && (centerOffset === null || centerOffset === void 0 ? void 0 : centerOffset.x) !== undefined ? Helpers.evaluateProp(centerOffset.x, evaluatedProps) : 0;
|
|
217
|
-
var offsetY = _isPlainObject(centerOffset) && (centerOffset === null || centerOffset === void 0 ? void 0 : centerOffset.y) !== undefined ? Helpers.evaluateProp(centerOffset.y, evaluatedProps) : 0;
|
|
218
|
-
return _objectSpread(_objectSpread({}, evaluatedProps), {}, {
|
|
219
|
-
centerOffset: {
|
|
220
|
-
x: offsetX,
|
|
221
|
-
y: offsetY
|
|
222
|
-
},
|
|
223
|
-
dx: dx !== undefined ? Helpers.evaluateProp(dx, evaluatedProps) : 0,
|
|
224
|
-
dy: dy !== undefined ? Helpers.evaluateProp(dy, evaluatedProps) : 0,
|
|
225
|
-
cornerRadius: Helpers.evaluateProp(cornerRadius, evaluatedProps)
|
|
226
|
-
});
|
|
106
|
+
return "bottom";
|
|
107
|
+
}
|
|
108
|
+
getStyles(props) {
|
|
109
|
+
const theme = props.theme || VictoryTheme.grayscale;
|
|
110
|
+
const defaultLabelStyles = theme && theme.tooltip && theme.tooltip.style ? theme.tooltip.style : {};
|
|
111
|
+
const baseLabelStyle = Array.isArray(props.style) ? props.style.map(s => _defaults({}, s, defaultLabelStyles)) : _defaults({}, props.style, defaultLabelStyles);
|
|
112
|
+
const defaultFlyoutStyles = theme && theme.tooltip && theme.tooltip.flyoutStyle ? theme.tooltip.flyoutStyle : {};
|
|
113
|
+
const baseFlyoutStyle = props.flyoutStyle ? _defaults({}, props.flyoutStyle, defaultFlyoutStyles) : defaultFlyoutStyles;
|
|
114
|
+
const style = Array.isArray(baseLabelStyle) ? baseLabelStyle.map(s => Helpers.evaluateStyle(s, props)) : Helpers.evaluateStyle(baseLabelStyle, props);
|
|
115
|
+
const flyoutStyle = Helpers.evaluateStyle(baseFlyoutStyle, Object.assign({}, props, {
|
|
116
|
+
style
|
|
117
|
+
}));
|
|
118
|
+
return {
|
|
119
|
+
style,
|
|
120
|
+
flyoutStyle
|
|
121
|
+
};
|
|
122
|
+
}
|
|
123
|
+
getEvaluatedProps(props) {
|
|
124
|
+
const {
|
|
125
|
+
cornerRadius,
|
|
126
|
+
centerOffset,
|
|
127
|
+
dx,
|
|
128
|
+
dy
|
|
129
|
+
} = props;
|
|
130
|
+
const active = Helpers.evaluateProp(props.active, props);
|
|
131
|
+
let text = Helpers.evaluateProp(props.text, Object.assign({}, props, {
|
|
132
|
+
active
|
|
133
|
+
}));
|
|
134
|
+
if (text === undefined || text === null) {
|
|
135
|
+
text = "";
|
|
227
136
|
}
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
value: function getCalculatedValues(props) {
|
|
231
|
-
var style = props.style,
|
|
232
|
-
text = props.text,
|
|
233
|
-
flyoutStyle = props.flyoutStyle,
|
|
234
|
-
flyoutHeight = props.flyoutHeight,
|
|
235
|
-
flyoutWidth = props.flyoutWidth;
|
|
236
|
-
var labelSize = TextSize.approximateTextSize(text, style);
|
|
237
|
-
var flyoutDimensions = {
|
|
238
|
-
height: flyoutHeight,
|
|
239
|
-
width: flyoutWidth
|
|
240
|
-
};
|
|
241
|
-
var flyoutCenter = this.getFlyoutCenter(props, flyoutDimensions);
|
|
242
|
-
var transform = this.getTransform(props);
|
|
243
|
-
return {
|
|
244
|
-
style: style,
|
|
245
|
-
flyoutStyle: flyoutStyle,
|
|
246
|
-
labelSize: labelSize,
|
|
247
|
-
flyoutDimensions: flyoutDimensions,
|
|
248
|
-
flyoutCenter: flyoutCenter,
|
|
249
|
-
transform: transform
|
|
250
|
-
};
|
|
137
|
+
if (typeof text === "number") {
|
|
138
|
+
text = text.toString();
|
|
251
139
|
}
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
140
|
+
const {
|
|
141
|
+
style,
|
|
142
|
+
flyoutStyle
|
|
143
|
+
} = this.getStyles(Object.assign({}, props, {
|
|
144
|
+
active,
|
|
145
|
+
text
|
|
146
|
+
}));
|
|
147
|
+
const orientation = Helpers.evaluateProp(props.orientation, Object.assign({}, props, {
|
|
148
|
+
active,
|
|
149
|
+
text,
|
|
150
|
+
style,
|
|
151
|
+
flyoutStyle
|
|
152
|
+
})) || this.getDefaultOrientation(props);
|
|
153
|
+
const padding = Helpers.evaluateProp(props.flyoutPadding, Object.assign({}, props, {
|
|
154
|
+
active,
|
|
155
|
+
text,
|
|
156
|
+
style,
|
|
157
|
+
flyoutStyle,
|
|
158
|
+
orientation
|
|
159
|
+
})) || this.getLabelPadding(style);
|
|
160
|
+
const flyoutPadding = Helpers.getPadding({
|
|
161
|
+
padding
|
|
162
|
+
});
|
|
163
|
+
const pointerWidth = Helpers.evaluateProp(props.pointerWidth, Object.assign({}, props, {
|
|
164
|
+
active,
|
|
165
|
+
text,
|
|
166
|
+
style,
|
|
167
|
+
flyoutStyle,
|
|
168
|
+
orientation
|
|
169
|
+
}));
|
|
170
|
+
const pointerLength = Helpers.evaluateProp(props.pointerLength, Object.assign({}, props, {
|
|
171
|
+
active,
|
|
172
|
+
text,
|
|
173
|
+
style,
|
|
174
|
+
flyoutStyle,
|
|
175
|
+
orientation
|
|
176
|
+
}));
|
|
177
|
+
const labelSize = TextSize.approximateTextSize(text, style);
|
|
178
|
+
const {
|
|
179
|
+
flyoutHeight,
|
|
180
|
+
flyoutWidth
|
|
181
|
+
} = this.getDimensions(Object.assign({}, props, {
|
|
182
|
+
style,
|
|
183
|
+
flyoutStyle,
|
|
184
|
+
active,
|
|
185
|
+
text,
|
|
186
|
+
orientation,
|
|
187
|
+
flyoutPadding,
|
|
188
|
+
pointerWidth,
|
|
189
|
+
pointerLength
|
|
190
|
+
}), labelSize);
|
|
191
|
+
const evaluatedProps = Object.assign({}, props, {
|
|
192
|
+
active,
|
|
193
|
+
text,
|
|
194
|
+
style,
|
|
195
|
+
flyoutStyle,
|
|
196
|
+
orientation,
|
|
197
|
+
flyoutHeight,
|
|
198
|
+
flyoutWidth,
|
|
199
|
+
flyoutPadding,
|
|
200
|
+
pointerWidth,
|
|
201
|
+
pointerLength
|
|
202
|
+
});
|
|
203
|
+
const offsetX = _isPlainObject(centerOffset) && centerOffset?.x !== undefined ? Helpers.evaluateProp(centerOffset.x, evaluatedProps) : 0;
|
|
204
|
+
const offsetY = _isPlainObject(centerOffset) && centerOffset?.y !== undefined ? Helpers.evaluateProp(centerOffset.y, evaluatedProps) : 0;
|
|
205
|
+
return {
|
|
206
|
+
...evaluatedProps,
|
|
207
|
+
centerOffset: {
|
|
208
|
+
x: offsetX,
|
|
209
|
+
y: offsetY
|
|
210
|
+
},
|
|
211
|
+
dx: dx !== undefined ? Helpers.evaluateProp(dx, evaluatedProps) : 0,
|
|
212
|
+
dy: dy !== undefined ? Helpers.evaluateProp(dy, evaluatedProps) : 0,
|
|
213
|
+
cornerRadius: Helpers.evaluateProp(cornerRadius, evaluatedProps)
|
|
214
|
+
};
|
|
215
|
+
}
|
|
216
|
+
getCalculatedValues(props) {
|
|
217
|
+
const {
|
|
218
|
+
style,
|
|
219
|
+
text,
|
|
220
|
+
flyoutStyle,
|
|
221
|
+
flyoutHeight,
|
|
222
|
+
flyoutWidth
|
|
223
|
+
} = props;
|
|
224
|
+
const labelSize = TextSize.approximateTextSize(text, style);
|
|
225
|
+
const flyoutDimensions = {
|
|
226
|
+
height: flyoutHeight,
|
|
227
|
+
width: flyoutWidth
|
|
228
|
+
};
|
|
229
|
+
const flyoutCenter = this.getFlyoutCenter(props, flyoutDimensions);
|
|
230
|
+
const transform = this.getTransform(props);
|
|
231
|
+
return {
|
|
232
|
+
style,
|
|
233
|
+
flyoutStyle,
|
|
234
|
+
labelSize,
|
|
235
|
+
flyoutDimensions,
|
|
236
|
+
flyoutCenter,
|
|
237
|
+
transform
|
|
238
|
+
};
|
|
239
|
+
}
|
|
240
|
+
getTransform(props) {
|
|
241
|
+
const {
|
|
242
|
+
x,
|
|
243
|
+
y,
|
|
244
|
+
style
|
|
245
|
+
} = props;
|
|
246
|
+
const labelStyle = style || {};
|
|
247
|
+
const angle = labelStyle.angle || props.angle || this.getDefaultAngle(props);
|
|
248
|
+
return angle ? `rotate(${angle} ${x} ${y})` : undefined;
|
|
249
|
+
}
|
|
250
|
+
getDefaultAngle(props) {
|
|
251
|
+
const {
|
|
252
|
+
polar,
|
|
253
|
+
labelPlacement,
|
|
254
|
+
orientation,
|
|
255
|
+
datum
|
|
256
|
+
} = props;
|
|
257
|
+
if (!polar || !labelPlacement || labelPlacement === "vertical") {
|
|
258
|
+
return 0;
|
|
261
259
|
}
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
}
|
|
273
|
-
|
|
274
|
-
var degrees = LabelHelpers.getDegrees(props, datum);
|
|
275
|
-
var sign = degrees > 90 && degrees < 180 || degrees > 270 ? 1 : -1;
|
|
276
|
-
var labelRotation = labelPlacement === "perpendicular" ? 0 : 90;
|
|
277
|
-
var angle = 0;
|
|
278
|
-
|
|
279
|
-
if (degrees === 0 || degrees === 180) {
|
|
280
|
-
angle = orientation === "top" && degrees === 180 ? 270 : 90;
|
|
281
|
-
} else if (degrees > 0 && degrees < 180) {
|
|
282
|
-
angle = 90 - degrees;
|
|
283
|
-
} else if (degrees > 180 && degrees < 360) {
|
|
284
|
-
angle = 270 - degrees;
|
|
285
|
-
}
|
|
286
|
-
|
|
287
|
-
return angle + sign * labelRotation;
|
|
260
|
+
const degrees = LabelHelpers.getDegrees(props, datum);
|
|
261
|
+
const sign = degrees > 90 && degrees < 180 || degrees > 270 ? 1 : -1;
|
|
262
|
+
const labelRotation = labelPlacement === "perpendicular" ? 0 : 90;
|
|
263
|
+
let angle = 0;
|
|
264
|
+
if (degrees === 0 || degrees === 180) {
|
|
265
|
+
angle = orientation === "top" && degrees === 180 ? 270 : 90;
|
|
266
|
+
} else if (degrees > 0 && degrees < 180) {
|
|
267
|
+
angle = 90 - degrees;
|
|
268
|
+
} else if (degrees > 180 && degrees < 360) {
|
|
269
|
+
angle = 270 - degrees;
|
|
288
270
|
}
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
271
|
+
return angle + sign * labelRotation;
|
|
272
|
+
}
|
|
273
|
+
constrainTooltip(center, props, dimensions) {
|
|
274
|
+
const {
|
|
275
|
+
x,
|
|
276
|
+
y
|
|
277
|
+
} = center;
|
|
278
|
+
const {
|
|
279
|
+
width,
|
|
280
|
+
height
|
|
281
|
+
} = dimensions;
|
|
282
|
+
const extent = {
|
|
283
|
+
x: [0, props.width],
|
|
284
|
+
y: [0, props.height]
|
|
285
|
+
};
|
|
286
|
+
const flyoutExtent = {
|
|
287
|
+
x: [x - width / 2, x + width / 2],
|
|
288
|
+
y: [y - height / 2, y + height / 2]
|
|
289
|
+
};
|
|
290
|
+
const adjustments = {
|
|
291
|
+
x: [flyoutExtent.x[0] < extent.x[0] ? extent.x[0] - flyoutExtent.x[0] : 0, flyoutExtent.x[1] > extent.x[1] ? flyoutExtent.x[1] - extent.x[1] : 0],
|
|
292
|
+
y: [flyoutExtent.y[0] < extent.y[0] ? extent.y[0] - flyoutExtent.y[0] : 0, flyoutExtent.y[1] > extent.y[1] ? flyoutExtent.y[1] - extent.y[1] : 0]
|
|
293
|
+
};
|
|
294
|
+
return {
|
|
295
|
+
x: Math.round(x + adjustments.x[0] - adjustments.x[1]),
|
|
296
|
+
y: Math.round(y + adjustments.y[0] - adjustments.y[1])
|
|
297
|
+
};
|
|
298
|
+
}
|
|
313
299
|
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
300
|
+
// eslint-disable-next-line complexity
|
|
301
|
+
getFlyoutCenter(props, dimensions) {
|
|
302
|
+
const {
|
|
303
|
+
x,
|
|
304
|
+
y,
|
|
305
|
+
dx,
|
|
306
|
+
dy,
|
|
307
|
+
pointerLength,
|
|
308
|
+
orientation,
|
|
309
|
+
constrainToVisibleArea,
|
|
310
|
+
centerOffset
|
|
311
|
+
} = props;
|
|
312
|
+
const {
|
|
313
|
+
height,
|
|
314
|
+
width
|
|
315
|
+
} = dimensions;
|
|
316
|
+
const xSign = orientation === "left" ? -1 : 1;
|
|
317
|
+
const ySign = orientation === "bottom" ? -1 : 1;
|
|
318
|
+
const flyoutCenter = {
|
|
319
|
+
x: orientation === "left" || orientation === "right" ? x + xSign * (pointerLength + width / 2 + xSign * dx) : x + dx,
|
|
320
|
+
y: orientation === "top" || orientation === "bottom" ? y - ySign * (pointerLength + height / 2 - ySign * dy) : y + dy
|
|
321
|
+
};
|
|
322
|
+
const center = {
|
|
323
|
+
x: _isPlainObject(props.center) && props.center.x !== undefined ? props.center.x : flyoutCenter.x,
|
|
324
|
+
y: _isPlainObject(props.center) && props.center.y !== undefined ? props.center.y : flyoutCenter.y
|
|
325
|
+
};
|
|
326
|
+
const centerWithOffset = {
|
|
327
|
+
x: center.x + centerOffset.x,
|
|
328
|
+
y: center.y + centerOffset.y
|
|
329
|
+
};
|
|
330
|
+
return constrainToVisibleArea ? this.constrainTooltip(centerWithOffset, props, dimensions) : centerWithOffset;
|
|
331
|
+
}
|
|
332
|
+
getLabelPadding(style) {
|
|
333
|
+
if (!style) {
|
|
334
|
+
return 0;
|
|
342
335
|
}
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
336
|
+
const paddings = Array.isArray(style) ? style.map(s => s.padding) : [style.padding];
|
|
337
|
+
return Math.max(...paddings, 0);
|
|
338
|
+
}
|
|
339
|
+
getDimensions(props, labelSize) {
|
|
340
|
+
const {
|
|
341
|
+
orientation,
|
|
342
|
+
pointerLength,
|
|
343
|
+
pointerWidth,
|
|
344
|
+
flyoutHeight,
|
|
345
|
+
flyoutWidth,
|
|
346
|
+
flyoutPadding
|
|
347
|
+
} = props;
|
|
348
|
+
const cornerRadius = Helpers.evaluateProp(props.cornerRadius, props);
|
|
349
|
+
const getHeight = () => {
|
|
350
|
+
const calculatedHeight = labelSize.height + flyoutPadding.top + flyoutPadding.bottom;
|
|
351
|
+
const minHeight = orientation === "top" || orientation === "bottom" ? 2 * cornerRadius : 2 * cornerRadius + pointerWidth;
|
|
352
|
+
return Math.max(minHeight, calculatedHeight);
|
|
353
|
+
};
|
|
354
|
+
const getWidth = () => {
|
|
355
|
+
const calculatedWidth = labelSize.width + flyoutPadding.left + flyoutPadding.right;
|
|
356
|
+
const minWidth = orientation === "left" || orientation === "right" ? 2 * cornerRadius + pointerLength : 2 * cornerRadius;
|
|
357
|
+
return Math.max(minWidth, calculatedWidth);
|
|
358
|
+
};
|
|
359
|
+
return {
|
|
360
|
+
flyoutHeight: flyoutHeight ? Helpers.evaluateProp(flyoutHeight, props) : getHeight(),
|
|
361
|
+
flyoutWidth: flyoutWidth ? Helpers.evaluateProp(flyoutWidth, props) : getWidth()
|
|
362
|
+
};
|
|
363
|
+
}
|
|
364
|
+
getLabelProps(props, calculatedValues) {
|
|
365
|
+
const {
|
|
366
|
+
flyoutCenter,
|
|
367
|
+
style,
|
|
368
|
+
labelSize,
|
|
369
|
+
dy = 0,
|
|
370
|
+
dx = 0
|
|
371
|
+
} = calculatedValues;
|
|
372
|
+
const {
|
|
373
|
+
text,
|
|
374
|
+
datum,
|
|
375
|
+
activePoints,
|
|
376
|
+
labelComponent,
|
|
377
|
+
index,
|
|
378
|
+
flyoutPadding
|
|
379
|
+
} = props;
|
|
380
|
+
const textAnchor = (Array.isArray(style) && style.length ? style[0].textAnchor : style.textAnchor) || "middle";
|
|
381
|
+
const getLabelX = () => {
|
|
382
|
+
if (!textAnchor || textAnchor === "middle") {
|
|
383
|
+
return flyoutCenter.x;
|
|
348
384
|
}
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
});
|
|
424
|
-
}
|
|
425
|
-
}, {
|
|
426
|
-
key: "getPointerOrientation",
|
|
427
|
-
value: function getPointerOrientation(point, center, flyoutDimensions) {
|
|
428
|
-
var edges = {
|
|
429
|
-
bottom: center.y + flyoutDimensions.height / 2,
|
|
430
|
-
top: center.y - flyoutDimensions.height / 2,
|
|
431
|
-
left: center.x - flyoutDimensions.width / 2,
|
|
432
|
-
right: center.x + flyoutDimensions.width / 2
|
|
433
|
-
};
|
|
434
|
-
var gaps = [{
|
|
435
|
-
side: "top",
|
|
436
|
-
val: edges.top > point.y ? edges.top - point.y : -1
|
|
437
|
-
}, {
|
|
438
|
-
side: "bottom",
|
|
439
|
-
val: edges.bottom < point.y ? point.y - edges.bottom : -1
|
|
440
|
-
}, {
|
|
441
|
-
side: "right",
|
|
442
|
-
val: edges.right < point.x ? point.x - edges.right : -1
|
|
443
|
-
}, {
|
|
444
|
-
side: "left",
|
|
445
|
-
val: edges.left > point.x ? edges.left - point.x : -1
|
|
446
|
-
}];
|
|
447
|
-
return _orderBy(gaps, "val", "desc")[0].side;
|
|
448
|
-
}
|
|
449
|
-
}, {
|
|
450
|
-
key: "getFlyoutProps",
|
|
451
|
-
value: function getFlyoutProps(props, calculatedValues) {
|
|
452
|
-
var flyoutDimensions = calculatedValues.flyoutDimensions,
|
|
453
|
-
flyoutStyle = calculatedValues.flyoutStyle,
|
|
454
|
-
flyoutCenter = calculatedValues.flyoutCenter;
|
|
455
|
-
var x = props.x,
|
|
456
|
-
y = props.y,
|
|
457
|
-
dx = props.dx,
|
|
458
|
-
dy = props.dy,
|
|
459
|
-
datum = props.datum,
|
|
460
|
-
activePoints = props.activePoints,
|
|
461
|
-
index = props.index,
|
|
462
|
-
pointerLength = props.pointerLength,
|
|
463
|
-
pointerWidth = props.pointerWidth,
|
|
464
|
-
cornerRadius = props.cornerRadius,
|
|
465
|
-
events = props.events,
|
|
466
|
-
flyoutComponent = props.flyoutComponent;
|
|
467
|
-
var pointerOrientation = Helpers.evaluateProp(props.pointerOrientation, props);
|
|
468
|
-
return _defaults({}, flyoutComponent.props, {
|
|
385
|
+
const sign = textAnchor === "end" ? -1 : 1;
|
|
386
|
+
return flyoutCenter.x - sign * (labelSize.width / 2);
|
|
387
|
+
};
|
|
388
|
+
return _defaults({}, labelComponent.props, {
|
|
389
|
+
key: `${this.id}-label-${index}`,
|
|
390
|
+
text,
|
|
391
|
+
datum,
|
|
392
|
+
activePoints,
|
|
393
|
+
textAnchor,
|
|
394
|
+
dy,
|
|
395
|
+
dx,
|
|
396
|
+
style,
|
|
397
|
+
x: getLabelX() + (flyoutPadding.left - flyoutPadding.right) / 2,
|
|
398
|
+
y: flyoutCenter.y + (flyoutPadding.top - flyoutPadding.bottom) / 2,
|
|
399
|
+
verticalAnchor: "middle",
|
|
400
|
+
angle: style.angle
|
|
401
|
+
});
|
|
402
|
+
}
|
|
403
|
+
getPointerOrientation(point, center, flyoutDimensions) {
|
|
404
|
+
const edges = {
|
|
405
|
+
bottom: center.y + flyoutDimensions.height / 2,
|
|
406
|
+
top: center.y - flyoutDimensions.height / 2,
|
|
407
|
+
left: center.x - flyoutDimensions.width / 2,
|
|
408
|
+
right: center.x + flyoutDimensions.width / 2
|
|
409
|
+
};
|
|
410
|
+
const gaps = [{
|
|
411
|
+
side: "top",
|
|
412
|
+
val: edges.top > point.y ? edges.top - point.y : -1
|
|
413
|
+
}, {
|
|
414
|
+
side: "bottom",
|
|
415
|
+
val: edges.bottom < point.y ? point.y - edges.bottom : -1
|
|
416
|
+
}, {
|
|
417
|
+
side: "right",
|
|
418
|
+
val: edges.right < point.x ? point.x - edges.right : -1
|
|
419
|
+
}, {
|
|
420
|
+
side: "left",
|
|
421
|
+
val: edges.left > point.x ? edges.left - point.x : -1
|
|
422
|
+
}];
|
|
423
|
+
return _orderBy(gaps, "val", "desc")[0].side;
|
|
424
|
+
}
|
|
425
|
+
getFlyoutProps(props, calculatedValues) {
|
|
426
|
+
const {
|
|
427
|
+
flyoutDimensions,
|
|
428
|
+
flyoutStyle,
|
|
429
|
+
flyoutCenter
|
|
430
|
+
} = calculatedValues;
|
|
431
|
+
const {
|
|
432
|
+
x,
|
|
433
|
+
y,
|
|
434
|
+
dx,
|
|
435
|
+
dy,
|
|
436
|
+
datum,
|
|
437
|
+
activePoints,
|
|
438
|
+
index,
|
|
439
|
+
pointerLength,
|
|
440
|
+
pointerWidth,
|
|
441
|
+
cornerRadius,
|
|
442
|
+
events,
|
|
443
|
+
flyoutComponent
|
|
444
|
+
} = props;
|
|
445
|
+
const pointerOrientation = Helpers.evaluateProp(props.pointerOrientation, props);
|
|
446
|
+
return _defaults({}, flyoutComponent.props, {
|
|
447
|
+
x,
|
|
448
|
+
y,
|
|
449
|
+
dx,
|
|
450
|
+
dy,
|
|
451
|
+
datum,
|
|
452
|
+
activePoints,
|
|
453
|
+
index,
|
|
454
|
+
pointerLength,
|
|
455
|
+
pointerWidth,
|
|
456
|
+
cornerRadius,
|
|
457
|
+
events,
|
|
458
|
+
orientation: pointerOrientation || this.getPointerOrientation({
|
|
469
459
|
x: x,
|
|
470
|
-
y: y
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
events: events,
|
|
480
|
-
orientation: pointerOrientation || this.getPointerOrientation({
|
|
481
|
-
x: x,
|
|
482
|
-
y: y
|
|
483
|
-
}, flyoutCenter, flyoutDimensions),
|
|
484
|
-
key: "".concat(this.id, "-tooltip-").concat(index),
|
|
485
|
-
width: flyoutDimensions.width,
|
|
486
|
-
height: flyoutDimensions.height,
|
|
487
|
-
style: flyoutStyle,
|
|
488
|
-
center: flyoutCenter
|
|
489
|
-
});
|
|
490
|
-
} // Overridden in victory-core-native
|
|
491
|
-
|
|
492
|
-
}, {
|
|
493
|
-
key: "renderTooltip",
|
|
494
|
-
value: function renderTooltip(props) {
|
|
495
|
-
var active = Helpers.evaluateProp(props.active, props);
|
|
496
|
-
var renderInPortal = props.renderInPortal;
|
|
497
|
-
|
|
498
|
-
if (!active) {
|
|
499
|
-
return renderInPortal ? /*#__PURE__*/React.createElement(VictoryPortal, null) : null;
|
|
500
|
-
}
|
|
501
|
-
|
|
502
|
-
var evaluatedProps = this.getEvaluatedProps(props);
|
|
503
|
-
var flyoutComponent = evaluatedProps.flyoutComponent,
|
|
504
|
-
labelComponent = evaluatedProps.labelComponent,
|
|
505
|
-
groupComponent = evaluatedProps.groupComponent;
|
|
506
|
-
var calculatedValues = this.getCalculatedValues(evaluatedProps);
|
|
507
|
-
var children = [/*#__PURE__*/React.cloneElement(flyoutComponent, this.getFlyoutProps(evaluatedProps, calculatedValues)), /*#__PURE__*/React.cloneElement(labelComponent, this.getLabelProps(evaluatedProps, calculatedValues))];
|
|
508
|
-
var tooltip = /*#__PURE__*/React.cloneElement(groupComponent, {
|
|
509
|
-
role: "presentation",
|
|
510
|
-
transform: calculatedValues.transform
|
|
511
|
-
}, children);
|
|
512
|
-
return renderInPortal ? /*#__PURE__*/React.createElement(VictoryPortal, null, tooltip) : tooltip;
|
|
513
|
-
}
|
|
514
|
-
}, {
|
|
515
|
-
key: "render",
|
|
516
|
-
value: function render() {
|
|
517
|
-
var props = Helpers.modifyProps(this.props, fallbackProps, "tooltip");
|
|
518
|
-
return this.renderTooltip(props);
|
|
519
|
-
}
|
|
520
|
-
}]);
|
|
521
|
-
|
|
522
|
-
return VictoryTooltip;
|
|
523
|
-
}(React.Component);
|
|
524
|
-
VictoryTooltip.displayName = "VictoryTooltip";
|
|
525
|
-
VictoryTooltip.role = "tooltip";
|
|
526
|
-
VictoryTooltip.defaultProps = {
|
|
527
|
-
active: false,
|
|
528
|
-
renderInPortal: true,
|
|
529
|
-
labelComponent: /*#__PURE__*/React.createElement(VictoryLabel, null),
|
|
530
|
-
flyoutComponent: /*#__PURE__*/React.createElement(Flyout, null),
|
|
531
|
-
groupComponent: /*#__PURE__*/React.createElement("g", null)
|
|
532
|
-
};
|
|
460
|
+
y: y
|
|
461
|
+
}, flyoutCenter, flyoutDimensions),
|
|
462
|
+
key: `${this.id}-tooltip-${index}`,
|
|
463
|
+
width: flyoutDimensions.width,
|
|
464
|
+
height: flyoutDimensions.height,
|
|
465
|
+
style: flyoutStyle,
|
|
466
|
+
center: flyoutCenter
|
|
467
|
+
});
|
|
468
|
+
}
|
|
533
469
|
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
}, {
|
|
543
|
-
target: "data",
|
|
544
|
-
mutation: function () {
|
|
545
|
-
return {
|
|
546
|
-
active: true
|
|
547
|
-
};
|
|
548
|
-
}
|
|
549
|
-
}] : [{
|
|
550
|
-
target: "labels",
|
|
551
|
-
mutation: function () {
|
|
552
|
-
return {
|
|
553
|
-
active: true
|
|
554
|
-
};
|
|
555
|
-
}
|
|
556
|
-
}];
|
|
557
|
-
var deactivate = props.activateData ? [{
|
|
558
|
-
target: "labels",
|
|
559
|
-
mutation: function () {
|
|
560
|
-
return {
|
|
561
|
-
active: undefined
|
|
562
|
-
};
|
|
470
|
+
// Overridden in victory-core-native
|
|
471
|
+
renderTooltip(props) {
|
|
472
|
+
const active = Helpers.evaluateProp(props.active, props);
|
|
473
|
+
const {
|
|
474
|
+
renderInPortal
|
|
475
|
+
} = props;
|
|
476
|
+
if (!active) {
|
|
477
|
+
return renderInPortal ? /*#__PURE__*/React.createElement(VictoryPortal, null) : null;
|
|
563
478
|
}
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
return activate;
|
|
584
|
-
},
|
|
585
|
-
onFocus: function () {
|
|
586
|
-
return activate;
|
|
587
|
-
},
|
|
588
|
-
onTouchStart: function () {
|
|
589
|
-
return activate;
|
|
590
|
-
},
|
|
591
|
-
onMouseOut: function () {
|
|
592
|
-
return deactivate;
|
|
593
|
-
},
|
|
594
|
-
onBlur: function () {
|
|
595
|
-
return deactivate;
|
|
596
|
-
},
|
|
597
|
-
onTouchEnd: function () {
|
|
598
|
-
return deactivate;
|
|
599
|
-
}
|
|
600
|
-
}
|
|
601
|
-
}];
|
|
602
|
-
};
|
|
479
|
+
const evaluatedProps = this.getEvaluatedProps(props);
|
|
480
|
+
const {
|
|
481
|
+
flyoutComponent,
|
|
482
|
+
labelComponent,
|
|
483
|
+
groupComponent
|
|
484
|
+
} = evaluatedProps;
|
|
485
|
+
const calculatedValues = this.getCalculatedValues(evaluatedProps);
|
|
486
|
+
const children = [/*#__PURE__*/React.cloneElement(flyoutComponent, this.getFlyoutProps(evaluatedProps, calculatedValues)), /*#__PURE__*/React.cloneElement(labelComponent, this.getLabelProps(evaluatedProps, calculatedValues))];
|
|
487
|
+
const tooltip = /*#__PURE__*/React.cloneElement(groupComponent, {
|
|
488
|
+
role: "presentation",
|
|
489
|
+
transform: calculatedValues.transform
|
|
490
|
+
}, children);
|
|
491
|
+
return renderInPortal ? /*#__PURE__*/React.createElement(VictoryPortal, null, tooltip) : tooltip;
|
|
492
|
+
}
|
|
493
|
+
render() {
|
|
494
|
+
const props = Helpers.modifyProps(this.props, fallbackProps, "tooltip");
|
|
495
|
+
return this.renderTooltip(props);
|
|
496
|
+
}
|
|
497
|
+
}
|