1 | "use strict";
|
2 | Object.defineProperty(exports, "__esModule", { value: true });
|
3 | var tslib_1 = require("tslib");
|
4 | var util_1 = require("@antv/util");
|
5 | var dependents_1 = require("../../dependents");
|
6 | var coordinate_1 = require("../../util/coordinate");
|
7 | var graphics_1 = require("../../util/graphics");
|
8 | var tooltip_1 = require("../../util/tooltip");
|
9 | var bbox_1 = require("../../util/bbox");
|
10 | var base_1 = require("./base");
|
11 | var event_1 = tslib_1.__importDefault(require("../event"));
|
12 |
|
13 | function uniq(items) {
|
14 | var uniqItems = [];
|
15 | var _loop_1 = function (index) {
|
16 | var item = items[index];
|
17 | var result = (0, util_1.find)(uniqItems, function (subItem) {
|
18 | return (subItem.color === item.color &&
|
19 | subItem.name === item.name &&
|
20 | subItem.value === item.value &&
|
21 | subItem.title === item.title);
|
22 | });
|
23 | if (!result) {
|
24 | uniqItems.push(item);
|
25 | }
|
26 | };
|
27 | for (var index = 0; index < items.length; index++) {
|
28 | _loop_1(index);
|
29 | }
|
30 | return uniqItems;
|
31 | }
|
32 |
|
33 | var Tooltip = (function (_super) {
|
34 | tslib_1.__extends(Tooltip, _super);
|
35 | function Tooltip() {
|
36 | var _this = _super !== null && _super.apply(this, arguments) || this;
|
37 | _this.isLocked = false;
|
38 | return _this;
|
39 | }
|
40 | Object.defineProperty(Tooltip.prototype, "name", {
|
41 | get: function () {
|
42 | return 'tooltip';
|
43 | },
|
44 | enumerable: false,
|
45 | configurable: true
|
46 | });
|
47 | Tooltip.prototype.init = function () { };
|
48 | Tooltip.prototype.isVisible = function () {
|
49 | var option = this.view.getOptions().tooltip;
|
50 | return option !== false;
|
51 | };
|
52 | Tooltip.prototype.render = function () { };
|
53 | |
54 |
|
55 |
|
56 |
|
57 | Tooltip.prototype.showTooltip = function (point) {
|
58 | this.point = point;
|
59 | if (!this.isVisible()) {
|
60 |
|
61 | return;
|
62 | }
|
63 | var view = this.view;
|
64 | var items = this.getTooltipItems(point);
|
65 | if (!items.length) {
|
66 |
|
67 | this.hideTooltip();
|
68 | return;
|
69 | }
|
70 | var title = this.getTitle(items);
|
71 | var dataPoint = {
|
72 | x: items[0].x,
|
73 | y: items[0].y,
|
74 | };
|
75 | view.emit('tooltip:show', event_1.default.fromData(view, 'tooltip:show', tslib_1.__assign({ items: items, title: title }, point)));
|
76 | var cfg = this.getTooltipCfg();
|
77 | var follow = cfg.follow, showMarkers = cfg.showMarkers, showCrosshairs = cfg.showCrosshairs, showContent = cfg.showContent, marker = cfg.marker;
|
78 | var lastItems = this.items;
|
79 | var lastTitle = this.title;
|
80 | if (!(0, util_1.isEqual)(lastTitle, title) || !(0, util_1.isEqual)(lastItems, items)) {
|
81 |
|
82 | view.emit('tooltip:change', event_1.default.fromData(view, 'tooltip:change', tslib_1.__assign({ items: items, title: title }, point)));
|
83 | if ((0, util_1.isFunction)(showContent) ? showContent(items) : showContent) {
|
84 |
|
85 | if (!this.tooltip) {
|
86 |
|
87 | this.renderTooltip();
|
88 | }
|
89 | this.tooltip.update((0, util_1.mix)({}, cfg, {
|
90 | items: this.getItemsAfterProcess(items),
|
91 | title: title,
|
92 | }, follow ? point : {}));
|
93 | this.tooltip.show();
|
94 | }
|
95 | if (showMarkers) {
|
96 |
|
97 | this.renderTooltipMarkers(items, marker);
|
98 | }
|
99 | }
|
100 | else {
|
101 |
|
102 | if (this.tooltip && follow) {
|
103 | this.tooltip.update(point);
|
104 | this.tooltip.show();
|
105 | }
|
106 | if (this.tooltipMarkersGroup) {
|
107 | this.tooltipMarkersGroup.show();
|
108 | }
|
109 | }
|
110 | this.items = items;
|
111 | this.title = title;
|
112 | if (showCrosshairs) {
|
113 |
|
114 | var isCrosshairsFollowCursor = (0, util_1.get)(cfg, ['crosshairs', 'follow'], false);
|
115 | this.renderCrosshairs(isCrosshairsFollowCursor ? point : dataPoint, cfg);
|
116 | }
|
117 | };
|
118 | Tooltip.prototype.hideTooltip = function () {
|
119 | var follow = this.getTooltipCfg().follow;
|
120 | if (!follow) {
|
121 | this.point = null;
|
122 | return;
|
123 | }
|
124 |
|
125 | var tooltipMarkersGroup = this.tooltipMarkersGroup;
|
126 | if (tooltipMarkersGroup) {
|
127 | tooltipMarkersGroup.hide();
|
128 | }
|
129 |
|
130 | var xCrosshair = this.xCrosshair;
|
131 | var yCrosshair = this.yCrosshair;
|
132 | if (xCrosshair) {
|
133 | xCrosshair.hide();
|
134 | }
|
135 | if (yCrosshair) {
|
136 | yCrosshair.hide();
|
137 | }
|
138 | var tooltip = this.tooltip;
|
139 | if (tooltip) {
|
140 | tooltip.hide();
|
141 | }
|
142 | this.view.emit('tooltip:hide', event_1.default.fromData(this.view, 'tooltip:hide', {}));
|
143 | this.point = null;
|
144 | };
|
145 | |
146 |
|
147 |
|
148 | Tooltip.prototype.lockTooltip = function () {
|
149 | this.isLocked = true;
|
150 | if (this.tooltip) {
|
151 |
|
152 | this.tooltip.setCapture(true);
|
153 | }
|
154 | };
|
155 | |
156 |
|
157 |
|
158 | Tooltip.prototype.unlockTooltip = function () {
|
159 | this.isLocked = false;
|
160 | var cfg = this.getTooltipCfg();
|
161 | if (this.tooltip) {
|
162 |
|
163 | this.tooltip.setCapture(cfg.capture);
|
164 | }
|
165 | };
|
166 | |
167 |
|
168 |
|
169 | Tooltip.prototype.isTooltipLocked = function () {
|
170 | return this.isLocked;
|
171 | };
|
172 | Tooltip.prototype.clear = function () {
|
173 | var _a = this, tooltip = _a.tooltip, xCrosshair = _a.xCrosshair, yCrosshair = _a.yCrosshair, tooltipMarkersGroup = _a.tooltipMarkersGroup;
|
174 | if (tooltip) {
|
175 | tooltip.hide();
|
176 | tooltip.clear();
|
177 | }
|
178 | if (xCrosshair) {
|
179 | xCrosshair.clear();
|
180 | }
|
181 | if (yCrosshair) {
|
182 | yCrosshair.clear();
|
183 | }
|
184 | if (tooltipMarkersGroup) {
|
185 | tooltipMarkersGroup.clear();
|
186 | }
|
187 |
|
188 | if (tooltip === null || tooltip === void 0 ? void 0 : tooltip.get('customContent')) {
|
189 | this.tooltip.destroy();
|
190 | this.tooltip = null;
|
191 | }
|
192 |
|
193 |
|
194 | this.title = null;
|
195 | this.items = null;
|
196 | };
|
197 | Tooltip.prototype.destroy = function () {
|
198 | if (this.tooltip) {
|
199 | this.tooltip.destroy();
|
200 | }
|
201 | if (this.xCrosshair) {
|
202 | this.xCrosshair.destroy();
|
203 | }
|
204 | if (this.yCrosshair) {
|
205 | this.yCrosshair.destroy();
|
206 | }
|
207 | if (this.guideGroup) {
|
208 | this.guideGroup.remove(true);
|
209 | }
|
210 | this.reset();
|
211 | };
|
212 | Tooltip.prototype.reset = function () {
|
213 | this.items = null;
|
214 | this.title = null;
|
215 | this.tooltipMarkersGroup = null;
|
216 | this.tooltipCrosshairsGroup = null;
|
217 | this.xCrosshair = null;
|
218 | this.yCrosshair = null;
|
219 | this.tooltip = null;
|
220 | this.guideGroup = null;
|
221 | this.isLocked = false;
|
222 | this.point = null;
|
223 | };
|
224 | Tooltip.prototype.changeVisible = function (visible) {
|
225 | if (this.visible === visible) {
|
226 | return;
|
227 | }
|
228 | var _a = this, tooltip = _a.tooltip, tooltipMarkersGroup = _a.tooltipMarkersGroup, xCrosshair = _a.xCrosshair, yCrosshair = _a.yCrosshair;
|
229 | if (visible) {
|
230 | if (tooltip) {
|
231 | tooltip.show();
|
232 | }
|
233 | if (tooltipMarkersGroup) {
|
234 | tooltipMarkersGroup.show();
|
235 | }
|
236 | if (xCrosshair) {
|
237 | xCrosshair.show();
|
238 | }
|
239 | if (yCrosshair) {
|
240 | yCrosshair.show();
|
241 | }
|
242 | }
|
243 | else {
|
244 | if (tooltip) {
|
245 | tooltip.hide();
|
246 | }
|
247 | if (tooltipMarkersGroup) {
|
248 | tooltipMarkersGroup.hide();
|
249 | }
|
250 | if (xCrosshair) {
|
251 | xCrosshair.hide();
|
252 | }
|
253 | if (yCrosshair) {
|
254 | yCrosshair.hide();
|
255 | }
|
256 | }
|
257 | this.visible = visible;
|
258 | };
|
259 | Tooltip.prototype.getTooltipItems = function (point) {
|
260 | var e_1, _a, e_2, _b, e_3, _c;
|
261 | var items = this.findItemsFromView(this.view, point);
|
262 | if (items.length) {
|
263 |
|
264 | items = (0, util_1.flatten)(items);
|
265 | try {
|
266 | for (var items_1 = tslib_1.__values(items), items_1_1 = items_1.next(); !items_1_1.done; items_1_1 = items_1.next()) {
|
267 | var itemArr = items_1_1.value;
|
268 | try {
|
269 | for (var itemArr_1 = (e_2 = void 0, tslib_1.__values(itemArr)), itemArr_1_1 = itemArr_1.next(); !itemArr_1_1.done; itemArr_1_1 = itemArr_1.next()) {
|
270 | var item = itemArr_1_1.value;
|
271 | var _d = item.mappingData, x = _d.x, y = _d.y;
|
272 | item.x = (0, util_1.isArray)(x) ? x[x.length - 1] : x;
|
273 | item.y = (0, util_1.isArray)(y) ? y[y.length - 1] : y;
|
274 | }
|
275 | }
|
276 | catch (e_2_1) { e_2 = { error: e_2_1 }; }
|
277 | finally {
|
278 | try {
|
279 | if (itemArr_1_1 && !itemArr_1_1.done && (_b = itemArr_1.return)) _b.call(itemArr_1);
|
280 | }
|
281 | finally { if (e_2) throw e_2.error; }
|
282 | }
|
283 | }
|
284 | }
|
285 | catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
286 | finally {
|
287 | try {
|
288 | if (items_1_1 && !items_1_1.done && (_a = items_1.return)) _a.call(items_1);
|
289 | }
|
290 | finally { if (e_1) throw e_1.error; }
|
291 | }
|
292 | var shared = this.getTooltipCfg().shared;
|
293 |
|
294 | if (shared === false && items.length > 1) {
|
295 | var snapItem = items[0];
|
296 | var min = Math.abs(point.y - snapItem[0].y);
|
297 | try {
|
298 | for (var items_2 = tslib_1.__values(items), items_2_1 = items_2.next(); !items_2_1.done; items_2_1 = items_2.next()) {
|
299 | var aItem = items_2_1.value;
|
300 | var yDistance = Math.abs(point.y - aItem[0].y);
|
301 | if (yDistance <= min) {
|
302 | snapItem = aItem;
|
303 | min = yDistance;
|
304 | }
|
305 | }
|
306 | }
|
307 | catch (e_3_1) { e_3 = { error: e_3_1 }; }
|
308 | finally {
|
309 | try {
|
310 | if (items_2_1 && !items_2_1.done && (_c = items_2.return)) _c.call(items_2);
|
311 | }
|
312 | finally { if (e_3) throw e_3.error; }
|
313 | }
|
314 | items = [snapItem];
|
315 | }
|
316 | return uniq((0, util_1.flatten)(items));
|
317 | }
|
318 | return [];
|
319 | };
|
320 | Tooltip.prototype.layout = function () { };
|
321 | Tooltip.prototype.update = function () {
|
322 | if (this.point) {
|
323 | this.showTooltip(this.point);
|
324 | }
|
325 | if (this.tooltip) {
|
326 |
|
327 |
|
328 | var canvas = this.view.getCanvas();
|
329 |
|
330 |
|
331 | this.tooltip.set('region', {
|
332 | start: { x: 0, y: 0 },
|
333 | end: { x: canvas.get('width'), y: canvas.get('height') },
|
334 | });
|
335 | }
|
336 | };
|
337 | |
338 |
|
339 |
|
340 |
|
341 | Tooltip.prototype.isCursorEntered = function (point) {
|
342 |
|
343 | if (this.tooltip) {
|
344 | var el = this.tooltip.getContainer();
|
345 | var capture = this.tooltip.get('capture');
|
346 | if (el && capture) {
|
347 | var _a = el.getBoundingClientRect(), x = _a.x, y = _a.y, width = _a.width, height = _a.height;
|
348 | return new bbox_1.BBox(x, y, width, height).isPointIn(point);
|
349 | }
|
350 | }
|
351 | return false;
|
352 | };
|
353 |
|
354 | Tooltip.prototype.getTooltipCfg = function () {
|
355 | var view = this.view;
|
356 | var option = view.getOptions().tooltip;
|
357 | var processOption = this.processCustomContent(option);
|
358 | var theme = view.getTheme();
|
359 | var defaultCfg = (0, util_1.get)(theme, ['components', 'tooltip'], {});
|
360 | var enterable = (0, util_1.get)(processOption, 'enterable', defaultCfg.enterable);
|
361 | return (0, util_1.deepMix)({}, defaultCfg, processOption, {
|
362 | capture: enterable || this.isLocked ? true : false,
|
363 | });
|
364 | };
|
365 |
|
366 | Tooltip.prototype.processCustomContent = function (option) {
|
367 | if ((0, util_1.isBoolean)(option) || !(0, util_1.get)(option, 'customContent')) {
|
368 | return option;
|
369 | }
|
370 | var currentCustomContent = option.customContent;
|
371 | var customContent = function (title, items) {
|
372 | var content = currentCustomContent(title, items) || '';
|
373 | return (0, util_1.isString)(content) ? '<div class="g2-tooltip">' + content + '</div>' : content;
|
374 | };
|
375 | return tslib_1.__assign(tslib_1.__assign({}, option), { customContent: customContent });
|
376 | };
|
377 | Tooltip.prototype.getTitle = function (items) {
|
378 | var title = items[0].title || items[0].name;
|
379 | this.title = title;
|
380 | return title;
|
381 | };
|
382 | Tooltip.prototype.renderTooltip = function () {
|
383 | var canvas = this.view.getCanvas();
|
384 | var region = {
|
385 | start: { x: 0, y: 0 },
|
386 | end: { x: canvas.get('width'), y: canvas.get('height') },
|
387 | };
|
388 | var cfg = this.getTooltipCfg();
|
389 | var tooltip = new dependents_1.HtmlTooltip(tslib_1.__assign(tslib_1.__assign({ parent: canvas.get('el').parentNode, region: region }, cfg), { visible: false, crosshairs: null }));
|
390 | tooltip.init();
|
391 | this.tooltip = tooltip;
|
392 | };
|
393 | Tooltip.prototype.renderTooltipMarkers = function (items, marker) {
|
394 | var e_4, _a;
|
395 | var tooltipMarkersGroup = this.getTooltipMarkersGroup();
|
396 | var rootView = this.view.getRootView();
|
397 | var limitInPlot = rootView.limitInPlot;
|
398 | try {
|
399 | for (var items_3 = tslib_1.__values(items), items_3_1 = items_3.next(); !items_3_1.done; items_3_1 = items_3.next()) {
|
400 | var item = items_3_1.value;
|
401 | var x = item.x, y = item.y;
|
402 |
|
403 | if (limitInPlot || (tooltipMarkersGroup === null || tooltipMarkersGroup === void 0 ? void 0 : tooltipMarkersGroup.getClip())) {
|
404 | var _b = (0, coordinate_1.getCoordinateClipCfg)(rootView.getCoordinate()), type = _b.type, attrs_1 = _b.attrs;
|
405 | tooltipMarkersGroup === null || tooltipMarkersGroup === void 0 ? void 0 : tooltipMarkersGroup.setClip({
|
406 | type: type,
|
407 | attrs: attrs_1,
|
408 | });
|
409 | }
|
410 | else {
|
411 |
|
412 | tooltipMarkersGroup === null || tooltipMarkersGroup === void 0 ? void 0 : tooltipMarkersGroup.setClip(undefined);
|
413 | }
|
414 | var attrs = tslib_1.__assign(tslib_1.__assign({ fill: item.color, symbol: 'circle', shadowColor: item.color }, marker), { x: x, y: y });
|
415 | tooltipMarkersGroup.addShape('marker', {
|
416 | attrs: attrs,
|
417 | });
|
418 | }
|
419 | }
|
420 | catch (e_4_1) { e_4 = { error: e_4_1 }; }
|
421 | finally {
|
422 | try {
|
423 | if (items_3_1 && !items_3_1.done && (_a = items_3.return)) _a.call(items_3);
|
424 | }
|
425 | finally { if (e_4) throw e_4.error; }
|
426 | }
|
427 | };
|
428 | Tooltip.prototype.renderCrosshairs = function (point, cfg) {
|
429 | var crosshairsType = (0, util_1.get)(cfg, ['crosshairs', 'type'], 'x');
|
430 | if (crosshairsType === 'x') {
|
431 | if (this.yCrosshair) {
|
432 | this.yCrosshair.hide();
|
433 | }
|
434 | this.renderXCrosshairs(point, cfg);
|
435 | }
|
436 | else if (crosshairsType === 'y') {
|
437 | if (this.xCrosshair) {
|
438 | this.xCrosshair.hide();
|
439 | }
|
440 | this.renderYCrosshairs(point, cfg);
|
441 | }
|
442 | else if (crosshairsType === 'xy') {
|
443 | this.renderXCrosshairs(point, cfg);
|
444 | this.renderYCrosshairs(point, cfg);
|
445 | }
|
446 | };
|
447 |
|
448 | Tooltip.prototype.renderXCrosshairs = function (point, tooltipCfg) {
|
449 | var coordinate = this.getViewWithGeometry(this.view).getCoordinate();
|
450 | if (!(0, coordinate_1.isPointInCoordinate)(coordinate, point)) {
|
451 | return;
|
452 | }
|
453 | var start;
|
454 | var end;
|
455 | if (coordinate.isRect) {
|
456 | if (coordinate.isTransposed) {
|
457 | start = {
|
458 | x: coordinate.start.x,
|
459 | y: point.y,
|
460 | };
|
461 | end = {
|
462 | x: coordinate.end.x,
|
463 | y: point.y,
|
464 | };
|
465 | }
|
466 | else {
|
467 | start = {
|
468 | x: point.x,
|
469 | y: coordinate.end.y,
|
470 | };
|
471 | end = {
|
472 | x: point.x,
|
473 | y: coordinate.start.y,
|
474 | };
|
475 | }
|
476 | }
|
477 | else {
|
478 |
|
479 | var angle = (0, coordinate_1.getAngleByPoint)(coordinate, point);
|
480 | var center = coordinate.getCenter();
|
481 | var radius = coordinate.getRadius();
|
482 | end = (0, graphics_1.polarToCartesian)(center.x, center.y, radius, angle);
|
483 | start = center;
|
484 | }
|
485 | var cfg = (0, util_1.deepMix)({
|
486 | start: start,
|
487 | end: end,
|
488 | container: this.getTooltipCrosshairsGroup(),
|
489 | }, (0, util_1.get)(tooltipCfg, 'crosshairs', {}), this.getCrosshairsText('x', point, tooltipCfg));
|
490 | delete cfg.type;
|
491 | var xCrosshair = this.xCrosshair;
|
492 | if (xCrosshair) {
|
493 | xCrosshair.update(cfg);
|
494 | }
|
495 | else {
|
496 | xCrosshair = new dependents_1.Crosshair.Line(cfg);
|
497 | xCrosshair.init();
|
498 | }
|
499 | xCrosshair.render();
|
500 | xCrosshair.show();
|
501 | this.xCrosshair = xCrosshair;
|
502 | };
|
503 |
|
504 | Tooltip.prototype.renderYCrosshairs = function (point, tooltipCfg) {
|
505 | var coordinate = this.getViewWithGeometry(this.view).getCoordinate();
|
506 | if (!(0, coordinate_1.isPointInCoordinate)(coordinate, point)) {
|
507 | return;
|
508 | }
|
509 | var cfg;
|
510 | var type;
|
511 | if (coordinate.isRect) {
|
512 | var start = void 0;
|
513 | var end = void 0;
|
514 | if (coordinate.isTransposed) {
|
515 | start = {
|
516 | x: point.x,
|
517 | y: coordinate.end.y,
|
518 | };
|
519 | end = {
|
520 | x: point.x,
|
521 | y: coordinate.start.y,
|
522 | };
|
523 | }
|
524 | else {
|
525 | start = {
|
526 | x: coordinate.start.x,
|
527 | y: point.y,
|
528 | };
|
529 | end = {
|
530 | x: coordinate.end.x,
|
531 | y: point.y,
|
532 | };
|
533 | }
|
534 | cfg = {
|
535 | start: start,
|
536 | end: end,
|
537 | };
|
538 | type = 'Line';
|
539 | }
|
540 | else {
|
541 |
|
542 | cfg = {
|
543 | center: coordinate.getCenter(),
|
544 |
|
545 | radius: (0, coordinate_1.getDistanceToCenter)(coordinate, point),
|
546 | startAngle: coordinate.startAngle,
|
547 | endAngle: coordinate.endAngle,
|
548 | };
|
549 | type = 'Circle';
|
550 | }
|
551 | cfg = (0, util_1.deepMix)({
|
552 | container: this.getTooltipCrosshairsGroup(),
|
553 | }, cfg, (0, util_1.get)(tooltipCfg, 'crosshairs', {}), this.getCrosshairsText('y', point, tooltipCfg));
|
554 | delete cfg.type;
|
555 | var yCrosshair = this.yCrosshair;
|
556 | if (yCrosshair) {
|
557 |
|
558 | if ((coordinate.isRect && yCrosshair.get('type') === 'circle') ||
|
559 | (!coordinate.isRect && yCrosshair.get('type') === 'line')) {
|
560 | yCrosshair = new dependents_1.Crosshair[type](cfg);
|
561 | yCrosshair.init();
|
562 | }
|
563 | else {
|
564 | yCrosshair.update(cfg);
|
565 | }
|
566 | }
|
567 | else {
|
568 | yCrosshair = new dependents_1.Crosshair[type](cfg);
|
569 | yCrosshair.init();
|
570 | }
|
571 | yCrosshair.render();
|
572 | yCrosshair.show();
|
573 | this.yCrosshair = yCrosshair;
|
574 | };
|
575 | Tooltip.prototype.getCrosshairsText = function (type, point, tooltipCfg) {
|
576 | var textCfg = (0, util_1.get)(tooltipCfg, ['crosshairs', 'text']);
|
577 | var follow = (0, util_1.get)(tooltipCfg, ['crosshairs', 'follow']);
|
578 | var items = this.items;
|
579 | if (textCfg) {
|
580 | var view = this.getViewWithGeometry(this.view);
|
581 |
|
582 | var firstItem = items[0];
|
583 | var xScale = view.getXScale();
|
584 | var yScale = view.getYScales()[0];
|
585 | var xValue = void 0;
|
586 | var yValue = void 0;
|
587 | if (follow) {
|
588 |
|
589 | var invertPoint = this.view.getCoordinate().invert(point);
|
590 | xValue = xScale.invert(invertPoint.x);
|
591 | yValue = yScale.invert(invertPoint.y);
|
592 | }
|
593 | else {
|
594 | xValue = firstItem.data[xScale.field];
|
595 | yValue = firstItem.data[yScale.field];
|
596 | }
|
597 | var content = type === 'x' ? xValue : yValue;
|
598 | if ((0, util_1.isFunction)(textCfg)) {
|
599 | textCfg = textCfg(type, content, items, point);
|
600 | }
|
601 | else {
|
602 | textCfg.content = content;
|
603 | }
|
604 | return {
|
605 | text: textCfg,
|
606 | };
|
607 | }
|
608 | };
|
609 |
|
610 | Tooltip.prototype.getGuideGroup = function () {
|
611 | if (!this.guideGroup) {
|
612 | var foregroundGroup = this.view.foregroundGroup;
|
613 | this.guideGroup = foregroundGroup.addGroup({
|
614 | name: 'tooltipGuide',
|
615 | capture: false,
|
616 | });
|
617 | }
|
618 | return this.guideGroup;
|
619 | };
|
620 |
|
621 | Tooltip.prototype.getTooltipMarkersGroup = function () {
|
622 | var tooltipMarkersGroup = this.tooltipMarkersGroup;
|
623 | if (tooltipMarkersGroup && !tooltipMarkersGroup.destroyed) {
|
624 | tooltipMarkersGroup.clear();
|
625 | tooltipMarkersGroup.show();
|
626 | }
|
627 | else {
|
628 | tooltipMarkersGroup = this.getGuideGroup().addGroup({
|
629 | name: 'tooltipMarkersGroup',
|
630 | });
|
631 | tooltipMarkersGroup.toFront();
|
632 | this.tooltipMarkersGroup = tooltipMarkersGroup;
|
633 | }
|
634 | return tooltipMarkersGroup;
|
635 | };
|
636 |
|
637 | Tooltip.prototype.getTooltipCrosshairsGroup = function () {
|
638 | var tooltipCrosshairsGroup = this.tooltipCrosshairsGroup;
|
639 | if (!tooltipCrosshairsGroup) {
|
640 | tooltipCrosshairsGroup = this.getGuideGroup().addGroup({
|
641 | name: 'tooltipCrosshairsGroup',
|
642 | capture: false,
|
643 | });
|
644 | tooltipCrosshairsGroup.toBack();
|
645 | this.tooltipCrosshairsGroup = tooltipCrosshairsGroup;
|
646 | }
|
647 | return tooltipCrosshairsGroup;
|
648 | };
|
649 | Tooltip.prototype.findItemsFromView = function (view, point) {
|
650 | var e_5, _a;
|
651 | if (view.getOptions().tooltip === false) {
|
652 |
|
653 | return [];
|
654 | }
|
655 | var tooltipCfg = this.getTooltipCfg();
|
656 | var result = (0, tooltip_1.findItemsFromView)(view, point, tooltipCfg);
|
657 | try {
|
658 |
|
659 | for (var _b = tslib_1.__values(view.views), _c = _b.next(); !_c.done; _c = _b.next()) {
|
660 | var childView = _c.value;
|
661 | result = result.concat(this.findItemsFromView(childView, point));
|
662 | }
|
663 | }
|
664 | catch (e_5_1) { e_5 = { error: e_5_1 }; }
|
665 | finally {
|
666 | try {
|
667 | if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
|
668 | }
|
669 | finally { if (e_5) throw e_5.error; }
|
670 | }
|
671 | return result;
|
672 | };
|
673 |
|
674 |
|
675 | Tooltip.prototype.getViewWithGeometry = function (view) {
|
676 | var _this = this;
|
677 | if (view.geometries.length) {
|
678 | return view;
|
679 | }
|
680 | return (0, util_1.find)(view.views, function (childView) { return _this.getViewWithGeometry(childView); });
|
681 | };
|
682 | |
683 |
|
684 |
|
685 |
|
686 | Tooltip.prototype.getItemsAfterProcess = function (originalItems) {
|
687 | var customItems = this.getTooltipCfg().customItems;
|
688 | var fn = customItems ? customItems : function (v) { return v; };
|
689 | return fn(originalItems);
|
690 | };
|
691 | return Tooltip;
|
692 | }(base_1.Controller));
|
693 | exports.default = Tooltip;
|
694 |
|
\ | No newline at end of file |