@cloudscape-design/chart-components 1.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/LICENSE +175 -0
- package/NOTICE +1 -0
- package/README.md +25 -0
- package/cartesian-chart/chart-cartesian-internal.d.ts +10 -0
- package/cartesian-chart/chart-cartesian-internal.js +99 -0
- package/cartesian-chart/chart-cartesian-internal.js.map +1 -0
- package/cartesian-chart/chart-series-cartesian.d.ts +7 -0
- package/cartesian-chart/chart-series-cartesian.js +95 -0
- package/cartesian-chart/chart-series-cartesian.js.map +1 -0
- package/cartesian-chart/index.d.ts +5 -0
- package/cartesian-chart/index.js +133 -0
- package/cartesian-chart/index.js.map +1 -0
- package/cartesian-chart/interfaces.d.ts +166 -0
- package/cartesian-chart/interfaces.js +4 -0
- package/cartesian-chart/interfaces.js.map +1 -0
- package/cartesian-chart/test-classes/styles.css.js +6 -0
- package/cartesian-chart/test-classes/styles.scoped.css +7 -0
- package/cartesian-chart/test-classes/styles.selectors.js +7 -0
- package/core/chart-api/chart-extra-axis-titles.d.ts +10 -0
- package/core/chart-api/chart-extra-axis-titles.js +42 -0
- package/core/chart-api/chart-extra-axis-titles.js.map +1 -0
- package/core/chart-api/chart-extra-context.d.ts +41 -0
- package/core/chart-api/chart-extra-context.js +93 -0
- package/core/chart-api/chart-extra-context.js.map +1 -0
- package/core/chart-api/chart-extra-highlight.d.ts +20 -0
- package/core/chart-api/chart-extra-highlight.js +205 -0
- package/core/chart-api/chart-extra-highlight.js.map +1 -0
- package/core/chart-api/chart-extra-legend.d.ts +27 -0
- package/core/chart-api/chart-extra-legend.js +118 -0
- package/core/chart-api/chart-extra-legend.js.map +1 -0
- package/core/chart-api/chart-extra-navigation.d.ts +84 -0
- package/core/chart-api/chart-extra-navigation.js +470 -0
- package/core/chart-api/chart-extra-navigation.js.map +1 -0
- package/core/chart-api/chart-extra-nodata.d.ts +15 -0
- package/core/chart-api/chart-extra-nodata.js +45 -0
- package/core/chart-api/chart-extra-nodata.js.map +1 -0
- package/core/chart-api/chart-extra-pointer.d.ts +33 -0
- package/core/chart-api/chart-extra-pointer.js +173 -0
- package/core/chart-api/chart-extra-pointer.js.map +1 -0
- package/core/chart-api/chart-extra-tooltip.d.ts +33 -0
- package/core/chart-api/chart-extra-tooltip.js +209 -0
- package/core/chart-api/chart-extra-tooltip.js.map +1 -0
- package/core/chart-api/index.d.ts +75 -0
- package/core/chart-api/index.js +383 -0
- package/core/chart-api/index.js.map +1 -0
- package/core/chart-container.d.ts +20 -0
- package/core/chart-container.js +55 -0
- package/core/chart-container.js.map +1 -0
- package/core/chart-core.d.ts +7 -0
- package/core/chart-core.js +287 -0
- package/core/chart-core.js.map +1 -0
- package/core/components/core-application.d.ts +6 -0
- package/core/components/core-application.js +16 -0
- package/core/components/core-application.js.map +1 -0
- package/core/components/core-filters.d.ts +9 -0
- package/core/components/core-filters.js +22 -0
- package/core/components/core-filters.js.map +1 -0
- package/core/components/core-legend.d.ts +13 -0
- package/core/components/core-legend.js +27 -0
- package/core/components/core-legend.js.map +1 -0
- package/core/components/core-no-data.d.ts +6 -0
- package/core/components/core-no-data.js +48 -0
- package/core/components/core-no-data.js.map +1 -0
- package/core/components/core-slots.d.ts +7 -0
- package/core/components/core-slots.js +11 -0
- package/core/components/core-slots.js.map +1 -0
- package/core/components/core-tooltip.d.ts +7 -0
- package/core/components/core-tooltip.js +183 -0
- package/core/components/core-tooltip.js.map +1 -0
- package/core/components/core-vertical-axis-title.d.ts +5 -0
- package/core/components/core-vertical-axis-title.js +15 -0
- package/core/components/core-vertical-axis-title.js.map +1 -0
- package/core/formatters.d.ts +2 -0
- package/core/formatters.js +113 -0
- package/core/formatters.js.map +1 -0
- package/core/i18n-utils.d.ts +21 -0
- package/core/i18n-utils.js +18 -0
- package/core/i18n-utils.js.map +1 -0
- package/core/interfaces.d.ts +436 -0
- package/core/interfaces.js +4 -0
- package/core/interfaces.js.map +1 -0
- package/core/styles.css.js +25 -0
- package/core/styles.scoped.css +115 -0
- package/core/styles.selectors.js +26 -0
- package/core/test-classes/styles.css.js +33 -0
- package/core/test-classes/styles.scoped.css +34 -0
- package/core/test-classes/styles.selectors.js +34 -0
- package/core/utils.d.ts +45 -0
- package/core/utils.js +262 -0
- package/core/utils.js.map +1 -0
- package/index.d.ts +4 -0
- package/index.js +5 -0
- package/index.js.map +1 -0
- package/internal/api-docs/components/cartesian-chart.js +571 -0
- package/internal/api-docs/components/index.d.ts +3 -0
- package/internal/api-docs/components/index.js +4 -0
- package/internal/api-docs/components/interfaces.d.ts +81 -0
- package/internal/api-docs/components/pie-chart.js +430 -0
- package/internal/api-docs/test-utils-doc/dom.js +4 -0
- package/internal/api-docs/test-utils-doc/selectors.js +4 -0
- package/internal/base-component/get-data-attributes.d.ts +1 -0
- package/internal/base-component/get-data-attributes.js +12 -0
- package/internal/base-component/get-data-attributes.js.map +1 -0
- package/internal/base-component/use-base-component.d.ts +13 -0
- package/internal/base-component/use-base-component.js +18 -0
- package/internal/base-component/use-base-component.js.map +1 -0
- package/internal/base-component/use-telemetry.d.ts +2 -0
- package/internal/base-component/use-telemetry.js +8 -0
- package/internal/base-component/use-telemetry.js.map +1 -0
- package/internal/chart-styles.d.ts +88 -0
- package/internal/chart-styles.js +145 -0
- package/internal/chart-styles.js.map +1 -0
- package/internal/components/chart-legend/index.d.ts +14 -0
- package/internal/components/chart-legend/index.js +245 -0
- package/internal/components/chart-legend/index.js.map +1 -0
- package/internal/components/chart-legend/styles.css.js +22 -0
- package/internal/components/chart-legend/styles.scoped.css +233 -0
- package/internal/components/chart-legend/styles.selectors.js +23 -0
- package/internal/components/chart-legend/test-classes/styles.css.js +11 -0
- package/internal/components/chart-legend/test-classes/styles.scoped.css +12 -0
- package/internal/components/chart-legend/test-classes/styles.selectors.js +12 -0
- package/internal/components/chart-series-filter/index.d.ts +17 -0
- package/internal/components/chart-series-filter/index.js +14 -0
- package/internal/components/chart-series-filter/index.js.map +1 -0
- package/internal/components/interfaces.d.ts +17 -0
- package/internal/components/interfaces.js +4 -0
- package/internal/components/interfaces.js.map +1 -0
- package/internal/components/series-details/index.d.ts +23 -0
- package/internal/components/series-details/index.js +45 -0
- package/internal/components/series-details/index.js.map +1 -0
- package/internal/components/series-details/styles.css.js +22 -0
- package/internal/components/series-details/styles.scoped.css +150 -0
- package/internal/components/series-details/styles.selectors.js +23 -0
- package/internal/components/series-details/test-classes/styles.css.js +10 -0
- package/internal/components/series-details/test-classes/styles.scoped.css +11 -0
- package/internal/components/series-details/test-classes/styles.selectors.js +11 -0
- package/internal/components/series-marker/index.d.ts +8 -0
- package/internal/components/series-marker/index.js +45 -0
- package/internal/components/series-marker/index.js.map +1 -0
- package/internal/components/series-marker/interfaces.d.ts +1 -0
- package/internal/components/series-marker/interfaces.js +4 -0
- package/internal/components/series-marker/interfaces.js.map +1 -0
- package/internal/components/series-marker/render-marker.d.ts +3 -0
- package/internal/components/series-marker/render-marker.js +74 -0
- package/internal/components/series-marker/render-marker.js.map +1 -0
- package/internal/components/series-marker/styles.css.js +7 -0
- package/internal/components/series-marker/styles.scoped.css +55 -0
- package/internal/components/series-marker/styles.selectors.js +8 -0
- package/internal/environment.d.ts +4 -0
- package/internal/environment.js +5 -0
- package/internal/environment.json +7 -0
- package/internal/events/index.d.ts +23 -0
- package/internal/events/index.js +41 -0
- package/internal/events/index.js.map +1 -0
- package/internal/generated/styles/tokens.d.ts +756 -0
- package/internal/generated/styles/tokens.js +756 -0
- package/internal/generated/theming/index.cjs +12584 -0
- package/internal/generated/theming/index.cjs.d.ts +2399 -0
- package/internal/generated/theming/index.d.ts +2399 -0
- package/internal/generated/theming/index.js +12584 -0
- package/internal/manifest.json +3 -0
- package/internal/styles.css.js +6 -0
- package/internal/styles.scoped.css +13 -0
- package/internal/styles.selectors.js +7 -0
- package/internal/utils/apply-display-name.d.ts +1 -0
- package/internal/utils/apply-display-name.js +6 -0
- package/internal/utils/apply-display-name.js.map +1 -0
- package/internal/utils/async-store.d.ts +19 -0
- package/internal/utils/async-store.js +58 -0
- package/internal/utils/async-store.js.map +1 -0
- package/internal/utils/chart-series.d.ts +8 -0
- package/internal/utils/chart-series.js +11 -0
- package/internal/utils/chart-series.js.map +1 -0
- package/internal/utils/renderer-utils.d.ts +17 -0
- package/internal/utils/renderer-utils.js +95 -0
- package/internal/utils/renderer-utils.js.map +1 -0
- package/internal/utils/series-data.d.ts +2 -0
- package/internal/utils/series-data.js +8 -0
- package/internal/utils/series-data.js.map +1 -0
- package/internal/utils/test-i18n-provider.d.ts +8 -0
- package/internal/utils/test-i18n-provider.js +8 -0
- package/internal/utils/test-i18n-provider.js.map +1 -0
- package/internal/utils/use-previous.d.ts +4 -0
- package/internal/utils/use-previous.js +14 -0
- package/internal/utils/use-previous.js.map +1 -0
- package/internal/utils/utils.d.ts +16 -0
- package/internal/utils/utils.js +49 -0
- package/internal/utils/utils.js.map +1 -0
- package/internal-do-not-use/core-chart/index.d.ts +4 -0
- package/internal-do-not-use/core-chart/index.js +13 -0
- package/internal-do-not-use/core-chart/index.js.map +1 -0
- package/internal-do-not-use/core-legend/index.d.ts +2 -0
- package/internal-do-not-use/core-legend/index.js +11 -0
- package/internal-do-not-use/core-legend/index.js.map +1 -0
- package/package.json +106 -0
- package/pie-chart/chart-inner-area.d.ts +10 -0
- package/pie-chart/chart-inner-area.js +63 -0
- package/pie-chart/chart-inner-area.js.map +1 -0
- package/pie-chart/chart-pie-internal.d.ts +11 -0
- package/pie-chart/chart-pie-internal.js +103 -0
- package/pie-chart/chart-pie-internal.js.map +1 -0
- package/pie-chart/index.d.ts +5 -0
- package/pie-chart/index.js +48 -0
- package/pie-chart/index.js.map +1 -0
- package/pie-chart/interfaces.d.ts +101 -0
- package/pie-chart/interfaces.js +4 -0
- package/pie-chart/interfaces.js.map +1 -0
- package/pie-chart/test-classes/styles.css.js +8 -0
- package/pie-chart/test-classes/styles.scoped.css +9 -0
- package/pie-chart/test-classes/styles.selectors.js +9 -0
- package/test-utils/dom/cartesian-chart/index.d.ts +14 -0
- package/test-utils/dom/cartesian-chart/index.js +24 -0
- package/test-utils/dom/cartesian-chart/index.js.map +1 -0
- package/test-utils/dom/cartesian-chart/tooltip.d.ts +28 -0
- package/test-utils/dom/cartesian-chart/tooltip.js +48 -0
- package/test-utils/dom/cartesian-chart/tooltip.js.map +1 -0
- package/test-utils/dom/index.d.ts +46 -0
- package/test-utils/dom/index.js +35 -0
- package/test-utils/dom/index.js.map +1 -0
- package/test-utils/dom/internal/base.d.ts +93 -0
- package/test-utils/dom/internal/base.js +146 -0
- package/test-utils/dom/internal/base.js.map +1 -0
- package/test-utils/dom/internal/core.d.ts +14 -0
- package/test-utils/dom/internal/core.js +37 -0
- package/test-utils/dom/internal/core.js.map +1 -0
- package/test-utils/dom/pie-chart/index.d.ts +17 -0
- package/test-utils/dom/pie-chart/index.js +29 -0
- package/test-utils/dom/pie-chart/index.js.map +1 -0
- package/test-utils/selectors/cartesian-chart/index.d.ts +14 -0
- package/test-utils/selectors/cartesian-chart/index.js +24 -0
- package/test-utils/selectors/cartesian-chart/index.js.map +1 -0
- package/test-utils/selectors/cartesian-chart/tooltip.d.ts +28 -0
- package/test-utils/selectors/cartesian-chart/tooltip.js +48 -0
- package/test-utils/selectors/cartesian-chart/tooltip.js.map +1 -0
- package/test-utils/selectors/index.d.ts +46 -0
- package/test-utils/selectors/index.js +32 -0
- package/test-utils/selectors/index.js.map +1 -0
- package/test-utils/selectors/internal/base.d.ts +93 -0
- package/test-utils/selectors/internal/base.js +146 -0
- package/test-utils/selectors/internal/base.js.map +1 -0
- package/test-utils/selectors/internal/core.d.ts +14 -0
- package/test-utils/selectors/internal/core.js +37 -0
- package/test-utils/selectors/internal/core.js.map +1 -0
- package/test-utils/selectors/pie-chart/index.d.ts +17 -0
- package/test-utils/selectors/pie-chart/index.js +29 -0
- package/test-utils/selectors/pie-chart/index.js.map +1 -0
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import type Highcharts from "highcharts";
|
|
2
|
+
import { ChartExtraContext } from "./chart-extra-context";
|
|
3
|
+
export interface ChartExtraPointerHandlers {
|
|
4
|
+
onPointHover(point: Highcharts.Point): void;
|
|
5
|
+
onGroupHover(group: Highcharts.Point[]): void;
|
|
6
|
+
onHoverLost(): void;
|
|
7
|
+
onPointClick(point: Highcharts.Point): void;
|
|
8
|
+
onGroupClick(group: Highcharts.Point[]): void;
|
|
9
|
+
}
|
|
10
|
+
export declare class ChartExtraPointer {
|
|
11
|
+
private context;
|
|
12
|
+
private handlers;
|
|
13
|
+
private hoveredPoint;
|
|
14
|
+
private hoveredGroup;
|
|
15
|
+
private tooltipHovered;
|
|
16
|
+
private hoverLostCall;
|
|
17
|
+
constructor(context: ChartExtraContext, handlers: ChartExtraPointerHandlers);
|
|
18
|
+
onChartLoad: (chart: Highcharts.Chart) => void;
|
|
19
|
+
onChartDestroy: () => void;
|
|
20
|
+
onSeriesPointMouseOver: (point: Highcharts.Point) => void;
|
|
21
|
+
onSeriesPointMouseOut: () => void;
|
|
22
|
+
onMouseEnterTooltip: () => void;
|
|
23
|
+
onMouseLeaveTooltip: () => void;
|
|
24
|
+
private onChartMousemove;
|
|
25
|
+
private onChartMouseout;
|
|
26
|
+
onChartClick: (point: null | Highcharts.Point) => void;
|
|
27
|
+
onSeriesPointClick: (point: Highcharts.Point) => void;
|
|
28
|
+
private onClick;
|
|
29
|
+
private setHoveredPoint;
|
|
30
|
+
private setHoveredGroup;
|
|
31
|
+
private clearHover;
|
|
32
|
+
private applyCursorStyle;
|
|
33
|
+
}
|
|
@@ -0,0 +1,173 @@
|
|
|
1
|
+
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
2
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
import { getChartSeries } from "../../internal/utils/chart-series";
|
|
4
|
+
import { DebouncedCall } from "../../internal/utils/utils";
|
|
5
|
+
import { isPointVisible } from "../utils";
|
|
6
|
+
const HOVER_LOST_DELAY = 25;
|
|
7
|
+
// Chart helper that implements pointer events (click and hover).
|
|
8
|
+
export class ChartExtraPointer {
|
|
9
|
+
constructor(context, handlers) {
|
|
10
|
+
this.hoveredPoint = null;
|
|
11
|
+
this.hoveredGroup = null;
|
|
12
|
+
this.tooltipHovered = false;
|
|
13
|
+
this.hoverLostCall = new DebouncedCall();
|
|
14
|
+
this.onChartLoad = (chart) => {
|
|
15
|
+
chart.container.addEventListener("mousemove", this.onChartMousemove);
|
|
16
|
+
chart.container.addEventListener("mouseout", this.onChartMouseout);
|
|
17
|
+
};
|
|
18
|
+
this.onChartDestroy = () => {
|
|
19
|
+
var _a, _b, _c, _d;
|
|
20
|
+
(_b = (_a = this.context.chartOrNull) === null || _a === void 0 ? void 0 : _a.container) === null || _b === void 0 ? void 0 : _b.removeEventListener("mousemove", this.onChartMousemove);
|
|
21
|
+
(_d = (_c = this.context.chartOrNull) === null || _c === void 0 ? void 0 : _c.container) === null || _d === void 0 ? void 0 : _d.removeEventListener("mouseout", this.onChartMouseout);
|
|
22
|
+
};
|
|
23
|
+
// This event is triggered by Highcharts when the cursor is over a Highcharts point. We leave this to
|
|
24
|
+
// Highcharts because it includes computation of complex shape intersections, such as pie chart segments.
|
|
25
|
+
// When triggered, we set the given point as hovered, and it takes precedence over hovered groups.
|
|
26
|
+
this.onSeriesPointMouseOver = (point) => {
|
|
27
|
+
this.setHoveredPoint(point);
|
|
28
|
+
};
|
|
29
|
+
// When the pointer leaves a point, it does not necessarily mean the hover state needs to be cleared, as another
|
|
30
|
+
// point or group can be hovered next. If it does not happen, the on-hover-lost handler is called after a short delay.
|
|
31
|
+
this.onSeriesPointMouseOut = () => {
|
|
32
|
+
this.hoveredPoint = null;
|
|
33
|
+
this.clearHover();
|
|
34
|
+
};
|
|
35
|
+
// We clear hover state when the pointer is moved outside the chart, unless it is moved inside the tooltip.
|
|
36
|
+
// Wo do, hover, clear the point and group hover state so that if the pointer leaves chart from the tooltip,
|
|
37
|
+
// the on-hover-lost handler is still called.
|
|
38
|
+
this.onMouseEnterTooltip = () => {
|
|
39
|
+
this.tooltipHovered = true;
|
|
40
|
+
this.hoveredPoint = null;
|
|
41
|
+
this.hoveredGroup = null;
|
|
42
|
+
};
|
|
43
|
+
// When the pointer leaves the tooltip it can hover another point or group. If that does not happen,
|
|
44
|
+
// the on-hover-lost handler is called after a short delay.
|
|
45
|
+
this.onMouseLeaveTooltip = () => {
|
|
46
|
+
this.tooltipHovered = false;
|
|
47
|
+
this.clearHover();
|
|
48
|
+
};
|
|
49
|
+
// The mouse-move handler takes all move events inside the chart, and its purpose is to capture hover for groups
|
|
50
|
+
// of points (those having matching X value in cartesian charts), as this is not directly supported by Highcharts.
|
|
51
|
+
// Points hovering takes precedence over groups hovering.
|
|
52
|
+
this.onChartMousemove = (event) => {
|
|
53
|
+
const chart = this.context.chart();
|
|
54
|
+
// In pie charts there is no support for groups - only a single point can be hovered at a time.
|
|
55
|
+
if (getChartSeries(chart.series).some((s) => s.type === "pie")) {
|
|
56
|
+
return;
|
|
57
|
+
}
|
|
58
|
+
// The plotX and plotY are pointer coordinates, normalized against the chart plot.
|
|
59
|
+
const normalized = chart.pointer.normalize(event);
|
|
60
|
+
const plotX = normalized.chartX;
|
|
61
|
+
const plotY = normalized.chartY;
|
|
62
|
+
const { plotLeft, plotTop, plotWidth, plotHeight } = chart;
|
|
63
|
+
// We only check for matched groups if the plotX, plotY are within the plot area, where series are rendered.
|
|
64
|
+
if (plotX >= plotLeft && plotX <= plotLeft + plotWidth && plotY >= plotTop && plotY <= plotTop + plotHeight) {
|
|
65
|
+
// We match groups by comparing the plotX, plotY against each group rect. If the pointer is within one of
|
|
66
|
+
// the rects - the group is considered matched. Otherwise, we take the group which is closest to the pointer.
|
|
67
|
+
// This is done to avoid gaps, when the hover state switches between on and off in a sparsely populated chart,
|
|
68
|
+
// causing the tooltip to show and hide as the pointer moves.
|
|
69
|
+
let matchedGroup = [];
|
|
70
|
+
let minDistance = Number.POSITIVE_INFINITY;
|
|
71
|
+
for (const { group, rect } of this.context.derived.groupRects) {
|
|
72
|
+
const [target, start, end] = chart.inverted
|
|
73
|
+
? [plotY, rect.y, rect.y + rect.height]
|
|
74
|
+
: [plotX, rect.x, rect.x + rect.width];
|
|
75
|
+
const minTargetDistance = Math.min(Math.abs(start - target), Math.abs(end - target));
|
|
76
|
+
if (start <= target && target < end) {
|
|
77
|
+
matchedGroup = group;
|
|
78
|
+
break;
|
|
79
|
+
}
|
|
80
|
+
else if (minTargetDistance < minDistance) {
|
|
81
|
+
minDistance = minTargetDistance;
|
|
82
|
+
matchedGroup = group;
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
this.setHoveredGroup(matchedGroup);
|
|
86
|
+
}
|
|
87
|
+
// If the plotX, plotY are outside of the series area (e.g. if the pointer is above axis titles or ticks),
|
|
88
|
+
// we clear the group hover state and trigger the on-hover-lost after a short delay.
|
|
89
|
+
else {
|
|
90
|
+
this.hoveredGroup = null;
|
|
91
|
+
this.clearHover();
|
|
92
|
+
}
|
|
93
|
+
};
|
|
94
|
+
// This event is triggered when the pointer leaves the chart area. Here, it is technically not necessary to add
|
|
95
|
+
// a delay before calling the on-hover-lost handler, but it is done for consistency in the UX.
|
|
96
|
+
this.onChartMouseout = () => {
|
|
97
|
+
this.hoveredGroup = null;
|
|
98
|
+
this.clearHover();
|
|
99
|
+
};
|
|
100
|
+
// This event is triggered by Highcharts when there is a click inside the chart plot. It might or might not include
|
|
101
|
+
// the point, hovered immediately before the click.
|
|
102
|
+
this.onChartClick = (point) => {
|
|
103
|
+
this.onClick(point);
|
|
104
|
+
};
|
|
105
|
+
// This event is triggered by Highcharts when a series point is clicked, it always has a point target.
|
|
106
|
+
this.onSeriesPointClick = (point) => {
|
|
107
|
+
this.onClick(point);
|
|
108
|
+
};
|
|
109
|
+
// We treat the chart and point clicks the same, but call different handlers depending on the target (null or point).
|
|
110
|
+
// When the point is not present, we assume the click was done on a group, so we take the group that was hovered before
|
|
111
|
+
// the click event triggered.
|
|
112
|
+
// Before calling the on-point-click or on-group-click handlers, we verify if the target point or group are still valid
|
|
113
|
+
// (visible, and not destroyed by Highcharts).
|
|
114
|
+
this.onClick = (point) => {
|
|
115
|
+
var _a, _b;
|
|
116
|
+
const targetPoint = point !== null && point !== void 0 ? point : (this.hoveredPoint && isPointVisible(this.hoveredPoint) ? this.hoveredPoint : null);
|
|
117
|
+
if (targetPoint) {
|
|
118
|
+
this.handlers.onPointClick(targetPoint);
|
|
119
|
+
return;
|
|
120
|
+
}
|
|
121
|
+
const targetGroup = (_b = (_a = this.hoveredGroup) === null || _a === void 0 ? void 0 : _a.filter(isPointVisible)) !== null && _b !== void 0 ? _b : null;
|
|
122
|
+
if (targetGroup && targetGroup.length > 0) {
|
|
123
|
+
this.handlers.onGroupClick(targetGroup);
|
|
124
|
+
return;
|
|
125
|
+
}
|
|
126
|
+
};
|
|
127
|
+
this.setHoveredPoint = (point) => {
|
|
128
|
+
if (isPointVisible(point)) {
|
|
129
|
+
this.hoveredPoint = point;
|
|
130
|
+
this.hoveredGroup = null;
|
|
131
|
+
this.handlers.onPointHover(point);
|
|
132
|
+
this.applyCursorStyle();
|
|
133
|
+
}
|
|
134
|
+
};
|
|
135
|
+
this.setHoveredGroup = (group) => {
|
|
136
|
+
if (!this.hoveredPoint || !isPointVisible(this.hoveredPoint)) {
|
|
137
|
+
const availablePoints = group.filter(isPointVisible);
|
|
138
|
+
this.hoveredPoint = null;
|
|
139
|
+
this.hoveredGroup = availablePoints;
|
|
140
|
+
this.handlers.onGroupHover(availablePoints);
|
|
141
|
+
this.applyCursorStyle();
|
|
142
|
+
}
|
|
143
|
+
};
|
|
144
|
+
// The function calls the on-hover-lost handler in a short delay to give time for the hover to
|
|
145
|
+
// transition from one target to another. Before calling the handler we check if no target
|
|
146
|
+
// (point, group, or tooltip) is hovered.
|
|
147
|
+
this.clearHover = () => {
|
|
148
|
+
this.hoverLostCall.call(() => {
|
|
149
|
+
if (!this.hoveredPoint && !this.hoveredGroup && !this.tooltipHovered) {
|
|
150
|
+
this.handlers.onHoverLost();
|
|
151
|
+
this.applyCursorStyle();
|
|
152
|
+
}
|
|
153
|
+
}, HOVER_LOST_DELAY);
|
|
154
|
+
};
|
|
155
|
+
this.applyCursorStyle = () => {
|
|
156
|
+
const container = this.context.chart().container;
|
|
157
|
+
const setCursor = (value) => {
|
|
158
|
+
if (container && container.style.cursor !== value) {
|
|
159
|
+
container.style.cursor = value;
|
|
160
|
+
}
|
|
161
|
+
};
|
|
162
|
+
if (this.hoveredPoint || this.hoveredGroup) {
|
|
163
|
+
setCursor("pointer");
|
|
164
|
+
}
|
|
165
|
+
else {
|
|
166
|
+
setCursor("default");
|
|
167
|
+
}
|
|
168
|
+
};
|
|
169
|
+
this.context = context;
|
|
170
|
+
this.handlers = handlers;
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
//# sourceMappingURL=chart-extra-pointer.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"chart-extra-pointer.js","sourceRoot":"","sources":["../../../../src/core/chart-api/chart-extra-pointer.tsx"],"names":[],"mappings":"AAAA,qEAAqE;AACrE,sCAAsC;AAItC,OAAO,EAAE,cAAc,EAAE,MAAM,mCAAmC,CAAC;AACnE,OAAO,EAAE,aAAa,EAAE,MAAM,4BAA4B,CAAC;AAC3D,OAAO,EAAE,cAAc,EAAE,MAAM,UAAU,CAAC;AAG1C,MAAM,gBAAgB,GAAG,EAAE,CAAC;AAU5B,iEAAiE;AACjE,MAAM,OAAO,iBAAiB;IAQ5B,YAAY,OAA0B,EAAE,QAAmC;QALnE,iBAAY,GAA4B,IAAI,CAAC;QAC7C,iBAAY,GAA8B,IAAI,CAAC;QAC/C,mBAAc,GAAG,KAAK,CAAC;QACvB,kBAAa,GAAG,IAAI,aAAa,EAAE,CAAC;QAOrC,gBAAW,GAAG,CAAC,KAAuB,EAAE,EAAE;YAC/C,KAAK,CAAC,SAAS,CAAC,gBAAgB,CAAC,WAAW,EAAE,IAAI,CAAC,gBAAgB,CAAC,CAAC;YACrE,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IAAI,CAAC,aAAa,CAAC,IAAI,CAAC,GAAG,EAAE;gBAC3B,IAAI,CAAC,IAAI,CAAC,YAAY,IAAI,CAAC,IAAI,CAAC,YAAY,IAAI,CAAC,IAAI,CAAC,cAAc,EAAE;oBACpE,IAAI,CAAC,QAAQ,CAAC,WAAW,EAAE,CAAC;oBAC5B,IAAI,CAAC,gBAAgB,EAAE,CAAC;iBACzB;YACH,CAAC,EAAE,gBAAgB,CAAC,CAAC;QACvB,CAAC,CAAC;QAEM,qBAAgB,GAAG,GAAG,EAAE;YAC9B,MAAM,SAAS,GAAG,IAAI,CAAC,OAAO,CAAC,KAAK,EAAE,CAAC,SAAS,CAAC;YACjD,MAAM,SAAS,GAAG,CAAC,KAA4B,EAAE,EAAE;gBACjD,IAAI,SAAS,IAAI,SAAS,CAAC,KAAK,CAAC,MAAM,KAAK,KAAK,EAAE;oBACjD,SAAS,CAAC,KAAK,CAAC,MAAM,GAAG,KAAK,CAAC;iBAChC;YACH,CAAC,CAAC;YACF,IAAI,IAAI,CAAC,YAAY,IAAI,IAAI,CAAC,YAAY,EAAE;gBAC1C,SAAS,CAAC,SAAS,CAAC,CAAC;aACtB;iBAAM;gBACL,SAAS,CAAC,SAAS,CAAC,CAAC;aACtB;QACH,CAAC,CAAC;QAxKA,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC;QACvB,IAAI,CAAC,QAAQ,GAAG,QAAQ,CAAC;IAC3B,CAAC;CAuKF","sourcesContent":["// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n// SPDX-License-Identifier: Apache-2.0\n\nimport type Highcharts from \"highcharts\";\n\nimport { getChartSeries } from \"../../internal/utils/chart-series\";\nimport { DebouncedCall } from \"../../internal/utils/utils\";\nimport { isPointVisible } from \"../utils\";\nimport { ChartExtraContext } from \"./chart-extra-context\";\n\nconst HOVER_LOST_DELAY = 25;\n\nexport interface ChartExtraPointerHandlers {\n onPointHover(point: Highcharts.Point): void;\n onGroupHover(group: Highcharts.Point[]): void;\n onHoverLost(): void;\n onPointClick(point: Highcharts.Point): void;\n onGroupClick(group: Highcharts.Point[]): void;\n}\n\n// Chart helper that implements pointer events (click and hover).\nexport class ChartExtraPointer {\n private context: ChartExtraContext;\n private handlers: ChartExtraPointerHandlers;\n private hoveredPoint: null | Highcharts.Point = null;\n private hoveredGroup: null | Highcharts.Point[] = null;\n private tooltipHovered = false;\n private hoverLostCall = new DebouncedCall();\n\n constructor(context: ChartExtraContext, handlers: ChartExtraPointerHandlers) {\n this.context = context;\n this.handlers = handlers;\n }\n\n public onChartLoad = (chart: Highcharts.Chart) => {\n chart.container.addEventListener(\"mousemove\", this.onChartMousemove);\n chart.container.addEventListener(\"mouseout\", this.onChartMouseout);\n };\n\n public onChartDestroy = () => {\n this.context.chartOrNull?.container?.removeEventListener(\"mousemove\", this.onChartMousemove);\n this.context.chartOrNull?.container?.removeEventListener(\"mouseout\", this.onChartMouseout);\n };\n\n // This event is triggered by Highcharts when the cursor is over a Highcharts point. We leave this to\n // Highcharts because it includes computation of complex shape intersections, such as pie chart segments.\n // When triggered, we set the given point as hovered, and it takes precedence over hovered groups.\n public onSeriesPointMouseOver = (point: Highcharts.Point) => {\n this.setHoveredPoint(point);\n };\n\n // When the pointer leaves a point, it does not necessarily mean the hover state needs to be cleared, as another\n // point or group can be hovered next. If it does not happen, the on-hover-lost handler is called after a short delay.\n public onSeriesPointMouseOut = () => {\n this.hoveredPoint = null;\n this.clearHover();\n };\n\n // We clear hover state when the pointer is moved outside the chart, unless it is moved inside the tooltip.\n // Wo do, hover, clear the point and group hover state so that if the pointer leaves chart from the tooltip,\n // the on-hover-lost handler is still called.\n public onMouseEnterTooltip = () => {\n this.tooltipHovered = true;\n this.hoveredPoint = null;\n this.hoveredGroup = null;\n };\n\n // When the pointer leaves the tooltip it can hover another point or group. If that does not happen,\n // the on-hover-lost handler is called after a short delay.\n public onMouseLeaveTooltip = () => {\n this.tooltipHovered = false;\n this.clearHover();\n };\n\n // The mouse-move handler takes all move events inside the chart, and its purpose is to capture hover for groups\n // of points (those having matching X value in cartesian charts), as this is not directly supported by Highcharts.\n // Points hovering takes precedence over groups hovering.\n private onChartMousemove = (event: MouseEvent) => {\n const chart = this.context.chart();\n // In pie charts there is no support for groups - only a single point can be hovered at a time.\n if (getChartSeries(chart.series).some((s) => s.type === \"pie\")) {\n return;\n }\n // The plotX and plotY are pointer coordinates, normalized against the chart plot.\n const normalized = chart.pointer.normalize(event);\n const plotX = normalized.chartX;\n const plotY = normalized.chartY;\n const { plotLeft, plotTop, plotWidth, plotHeight } = chart;\n // We only check for matched groups if the plotX, plotY are within the plot area, where series are rendered.\n if (plotX >= plotLeft && plotX <= plotLeft + plotWidth && plotY >= plotTop && plotY <= plotTop + plotHeight) {\n // We match groups by comparing the plotX, plotY against each group rect. If the pointer is within one of\n // the rects - the group is considered matched. Otherwise, we take the group which is closest to the pointer.\n // This is done to avoid gaps, when the hover state switches between on and off in a sparsely populated chart,\n // causing the tooltip to show and hide as the pointer moves.\n let matchedGroup: Highcharts.Point[] = [];\n let minDistance = Number.POSITIVE_INFINITY;\n for (const { group, rect } of this.context.derived.groupRects) {\n const [target, start, end] = chart.inverted\n ? [plotY, rect.y, rect.y + rect.height]\n : [plotX, rect.x, rect.x + rect.width];\n const minTargetDistance = Math.min(Math.abs(start - target), Math.abs(end - target));\n if (start <= target && target < end) {\n matchedGroup = group;\n break;\n } else if (minTargetDistance < minDistance) {\n minDistance = minTargetDistance;\n matchedGroup = group;\n }\n }\n this.setHoveredGroup(matchedGroup);\n }\n // If the plotX, plotY are outside of the series area (e.g. if the pointer is above axis titles or ticks),\n // we clear the group hover state and trigger the on-hover-lost after a short delay.\n else {\n this.hoveredGroup = null;\n this.clearHover();\n }\n };\n\n // This event is triggered when the pointer leaves the chart area. Here, it is technically not necessary to add\n // a delay before calling the on-hover-lost handler, but it is done for consistency in the UX.\n private onChartMouseout = () => {\n this.hoveredGroup = null;\n this.clearHover();\n };\n\n // This event is triggered by Highcharts when there is a click inside the chart plot. It might or might not include\n // the point, hovered immediately before the click.\n public onChartClick = (point: null | Highcharts.Point) => {\n this.onClick(point);\n };\n\n // This event is triggered by Highcharts when a series point is clicked, it always has a point target.\n public onSeriesPointClick = (point: Highcharts.Point) => {\n this.onClick(point);\n };\n\n // We treat the chart and point clicks the same, but call different handlers depending on the target (null or point).\n // When the point is not present, we assume the click was done on a group, so we take the group that was hovered before\n // the click event triggered.\n // Before calling the on-point-click or on-group-click handlers, we verify if the target point or group are still valid\n // (visible, and not destroyed by Highcharts).\n private onClick = (point: null | Highcharts.Point) => {\n const targetPoint = point ?? (this.hoveredPoint && isPointVisible(this.hoveredPoint) ? this.hoveredPoint : null);\n if (targetPoint) {\n this.handlers.onPointClick(targetPoint);\n return;\n }\n const targetGroup = this.hoveredGroup?.filter(isPointVisible) ?? null;\n if (targetGroup && targetGroup.length > 0) {\n this.handlers.onGroupClick(targetGroup);\n return;\n }\n };\n\n private setHoveredPoint = (point: Highcharts.Point) => {\n if (isPointVisible(point)) {\n this.hoveredPoint = point;\n this.hoveredGroup = null;\n this.handlers.onPointHover(point);\n this.applyCursorStyle();\n }\n };\n\n private setHoveredGroup = (group: Highcharts.Point[]) => {\n if (!this.hoveredPoint || !isPointVisible(this.hoveredPoint)) {\n const availablePoints = group.filter(isPointVisible);\n this.hoveredPoint = null;\n this.hoveredGroup = availablePoints;\n this.handlers.onGroupHover(availablePoints);\n this.applyCursorStyle();\n }\n };\n\n // The function calls the on-hover-lost handler in a short delay to give time for the hover to\n // transition from one target to another. Before calling the handler we check if no target\n // (point, group, or tooltip) is hovered.\n private clearHover = () => {\n this.hoverLostCall.call(() => {\n if (!this.hoveredPoint && !this.hoveredGroup && !this.tooltipHovered) {\n this.handlers.onHoverLost();\n this.applyCursorStyle();\n }\n }, HOVER_LOST_DELAY);\n };\n\n private applyCursorStyle = () => {\n const container = this.context.chart().container;\n const setCursor = (value: \"pointer\" | \"default\") => {\n if (container && container.style.cursor !== value) {\n container.style.cursor = value;\n }\n };\n if (this.hoveredPoint || this.hoveredGroup) {\n setCursor(\"pointer\");\n } else {\n setCursor(\"default\");\n }\n };\n}\n"]}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import type Highcharts from "highcharts";
|
|
2
|
+
import AsyncStore from "../../internal/utils/async-store";
|
|
3
|
+
import { ChartExtraContext } from "./chart-extra-context";
|
|
4
|
+
export interface ReactiveTooltipState {
|
|
5
|
+
visible: boolean;
|
|
6
|
+
pinned: boolean;
|
|
7
|
+
point: null | Highcharts.Point;
|
|
8
|
+
group: readonly Highcharts.Point[];
|
|
9
|
+
}
|
|
10
|
+
export declare class ChartExtraTooltip extends AsyncStore<ReactiveTooltipState> {
|
|
11
|
+
private context;
|
|
12
|
+
tooltipLock: boolean;
|
|
13
|
+
private tooltipLockCall;
|
|
14
|
+
private setTooltipLock;
|
|
15
|
+
private cursor;
|
|
16
|
+
private targetTrack;
|
|
17
|
+
private groupTrack;
|
|
18
|
+
constructor(context: ChartExtraContext);
|
|
19
|
+
getTargetTrack: () => SVGElement | null;
|
|
20
|
+
getGroupTrack: () => SVGElement | null;
|
|
21
|
+
onChartDestroy(): void;
|
|
22
|
+
showTooltipOnPoint(point: Highcharts.Point, matchingGroup: readonly Highcharts.Point[], ignoreLock?: boolean): void;
|
|
23
|
+
showTooltipOnGroup(group: readonly Highcharts.Point[], ignoreLock?: boolean): void;
|
|
24
|
+
hideTooltip(): void;
|
|
25
|
+
pinTooltip(): void;
|
|
26
|
+
private setGroupIfDifferent;
|
|
27
|
+
private onRenderTooltip;
|
|
28
|
+
private onRenderTooltipCartesian;
|
|
29
|
+
private onRenderTooltipPie;
|
|
30
|
+
private onRenderTooltipSolidGauge;
|
|
31
|
+
private get commonTrackAttrs();
|
|
32
|
+
private get direction();
|
|
33
|
+
}
|
|
@@ -0,0 +1,209 @@
|
|
|
1
|
+
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
2
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
import clsx from "clsx";
|
|
4
|
+
import { getIsRtl } from "@cloudscape-design/component-toolkit/internal";
|
|
5
|
+
import * as Styles from "../../internal/chart-styles";
|
|
6
|
+
import { renderMarker } from "../../internal/components/series-marker/render-marker";
|
|
7
|
+
import AsyncStore from "../../internal/utils/async-store";
|
|
8
|
+
import { SVGRendererPool, SVGRendererSingle } from "../../internal/utils/renderer-utils";
|
|
9
|
+
import { DebouncedCall, isEqualArrays } from "../../internal/utils/utils";
|
|
10
|
+
import { getGroupRect, getPointRect, getSeriesId, isXThreshold } from "../utils";
|
|
11
|
+
import testClasses from "../test-classes/styles.css.js";
|
|
12
|
+
const TOOLTIP_LAST_DISMISS_DELAY = 250;
|
|
13
|
+
// Chart helper that implements tooltip placement logic and cursors.
|
|
14
|
+
export class ChartExtraTooltip extends AsyncStore {
|
|
15
|
+
constructor(context) {
|
|
16
|
+
super({ visible: false, pinned: false, point: null, group: [] });
|
|
17
|
+
// The tooltip lock is used to prevent tooltip position changes shortly after it was dismissed, to
|
|
18
|
+
// deny its immediate re-appearance in the spot under where the dismiss button was.
|
|
19
|
+
this.tooltipLock = false;
|
|
20
|
+
this.tooltipLockCall = new DebouncedCall();
|
|
21
|
+
this.setTooltipLock = () => {
|
|
22
|
+
if (this.get().pinned) {
|
|
23
|
+
this.tooltipLock = true;
|
|
24
|
+
this.tooltipLockCall.call(() => (this.tooltipLock = false), TOOLTIP_LAST_DISMISS_DELAY);
|
|
25
|
+
}
|
|
26
|
+
};
|
|
27
|
+
// The cursor is a vertical or horizontal (in inverted charts) line and hollow or filled markers,
|
|
28
|
+
// shown in cartesian charts on top of the matched group or point.
|
|
29
|
+
this.cursor = new HighlightCursorCartesian();
|
|
30
|
+
// The track elements are invisible rectangles, compted for the given target point or group.
|
|
31
|
+
// The target track is used for the "target" tooltip placement. The group track is used for
|
|
32
|
+
// the "middle" and "outside" tooltip placement.
|
|
33
|
+
this.targetTrack = new SVGRendererSingle();
|
|
34
|
+
this.groupTrack = new SVGRendererSingle();
|
|
35
|
+
// The targetElement.element can get invalidated by Highcharts, so we cannot use
|
|
36
|
+
// trackRef.current = targetElement.element as it might get invalidated unexpectedly.
|
|
37
|
+
// The getTrack function ensures the latest element reference is given on each request.
|
|
38
|
+
this.getTargetTrack = () => { var _a, _b; return ((_b = (_a = this.targetTrack.element) === null || _a === void 0 ? void 0 : _a.element) !== null && _b !== void 0 ? _b : null); };
|
|
39
|
+
this.getGroupTrack = () => { var _a, _b; return ((_b = (_a = this.groupTrack.element) === null || _a === void 0 ? void 0 : _a.element) !== null && _b !== void 0 ? _b : null); };
|
|
40
|
+
this.onRenderTooltip = (props) => {
|
|
41
|
+
var _a, _b;
|
|
42
|
+
const chartType = (_b = (_a = this.context.chart().series.find((s) => s.type === "pie" || s.type === "solidgauge")) === null || _a === void 0 ? void 0 : _a.type) !== null && _b !== void 0 ? _b : "cartesian";
|
|
43
|
+
if (chartType === "pie") {
|
|
44
|
+
return this.onRenderTooltipPie(props.group[0]);
|
|
45
|
+
}
|
|
46
|
+
else if (chartType === "solidgauge") {
|
|
47
|
+
return this.onRenderTooltipSolidGauge(props.group[0]);
|
|
48
|
+
}
|
|
49
|
+
else {
|
|
50
|
+
return this.onRenderTooltipCartesian(props);
|
|
51
|
+
}
|
|
52
|
+
};
|
|
53
|
+
this.onRenderTooltipCartesian = ({ point, group, }) => {
|
|
54
|
+
const pointRect = point ? getPointRect(point) : getGroupRect(group.slice(0, 1));
|
|
55
|
+
const groupRect = getGroupRect(group);
|
|
56
|
+
// The cursor is not shown when column series are present (a UX decision).
|
|
57
|
+
const hasColumnSeries = this.context.chart().series.some((s) => s.type === "column");
|
|
58
|
+
this.cursor.create(groupRect, point, group, !hasColumnSeries);
|
|
59
|
+
this.targetTrack.rect(this.context.chart().renderer, { ...pointRect, ...this.commonTrackAttrs });
|
|
60
|
+
this.groupTrack.rect(this.context.chart().renderer, { ...groupRect, ...this.commonTrackAttrs });
|
|
61
|
+
};
|
|
62
|
+
this.onRenderTooltipPie = (point) => {
|
|
63
|
+
// We only create target track for pie chart as pie chart does not support groups.
|
|
64
|
+
// It is also expected that only "target" tooltip position is used for pie charts.
|
|
65
|
+
const pointRect = getPieChartTargetPlacement(point);
|
|
66
|
+
this.targetTrack.rect(this.context.chart().renderer, { ...pointRect, ...this.commonTrackAttrs });
|
|
67
|
+
};
|
|
68
|
+
this.onRenderTooltipSolidGauge = (point) => {
|
|
69
|
+
// Solid gauge charts are similar to pie charts in that they have a circular shape
|
|
70
|
+
// and don't support grouping. We use a similar approach to pie charts.
|
|
71
|
+
const pointRect = getSolidGaugeTargetPlacement(point);
|
|
72
|
+
this.targetTrack.rect(this.context.chart().renderer, { ...pointRect, ...this.commonTrackAttrs });
|
|
73
|
+
};
|
|
74
|
+
this.context = context;
|
|
75
|
+
}
|
|
76
|
+
onChartDestroy() {
|
|
77
|
+
this.cursor.destroy();
|
|
78
|
+
this.targetTrack.destroy();
|
|
79
|
+
this.groupTrack.destroy();
|
|
80
|
+
}
|
|
81
|
+
showTooltipOnPoint(point, matchingGroup, ignoreLock = false) {
|
|
82
|
+
if (!this.tooltipLock || ignoreLock) {
|
|
83
|
+
this.set(() => ({ visible: true, pinned: false, point, group: matchingGroup }));
|
|
84
|
+
this.onRenderTooltip({ point, group: matchingGroup });
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
showTooltipOnGroup(group, ignoreLock = false) {
|
|
88
|
+
if (!this.tooltipLock || ignoreLock) {
|
|
89
|
+
this.setGroupIfDifferent(group);
|
|
90
|
+
this.onRenderTooltip({ point: null, group });
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
hideTooltip() {
|
|
94
|
+
this.cursor.hide();
|
|
95
|
+
this.targetTrack.hide();
|
|
96
|
+
this.groupTrack.hide();
|
|
97
|
+
this.setTooltipLock();
|
|
98
|
+
this.set((prev) => ({ ...prev, visible: false, pinned: false }));
|
|
99
|
+
}
|
|
100
|
+
pinTooltip() {
|
|
101
|
+
if (this.context.settings.tooltipEnabled) {
|
|
102
|
+
this.set((prev) => ({ ...prev, visible: true, pinned: true }));
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
// Avoid re-rendering the tooltip on every cursor position change when hovering over the graph.
|
|
106
|
+
// Just re-render when the groups are different.
|
|
107
|
+
setGroupIfDifferent(group) {
|
|
108
|
+
function isGroupEqual(a, b) {
|
|
109
|
+
return (a === null || a === void 0 ? void 0 : a.x) === (b === null || b === void 0 ? void 0 : b.x) && (a === null || a === void 0 ? void 0 : a.y) === (b === null || b === void 0 ? void 0 : b.y) && getSeriesId(a === null || a === void 0 ? void 0 : a.series) === getSeriesId(b === null || b === void 0 ? void 0 : b.series);
|
|
110
|
+
}
|
|
111
|
+
this.set((prev) => {
|
|
112
|
+
return isEqualArrays(prev.group, group, isGroupEqual)
|
|
113
|
+
? prev
|
|
114
|
+
: { visible: true, pinned: false, point: null, group };
|
|
115
|
+
});
|
|
116
|
+
}
|
|
117
|
+
get commonTrackAttrs() {
|
|
118
|
+
return { fill: "transparent", zIndex: -1, style: "pointer-events:none", direction: this.direction };
|
|
119
|
+
}
|
|
120
|
+
// We compute the direction from the chart container and then explicitly set it to the track
|
|
121
|
+
// elements, as otherwise the direction check done for track elements always results to "ltr".
|
|
122
|
+
get direction() {
|
|
123
|
+
const isRtl = getIsRtl(this.context.chart().container.parentElement);
|
|
124
|
+
return isRtl ? "rtl" : "ltr";
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
// A helper class to draw the cursor elements (include cursor line and matched points markers).
|
|
128
|
+
class HighlightCursorCartesian {
|
|
129
|
+
constructor() {
|
|
130
|
+
this.lineElement = new SVGRendererSingle();
|
|
131
|
+
this.markerElementsPool = new SVGRendererPool();
|
|
132
|
+
this.isPointEligibleForMarker = (point) => {
|
|
133
|
+
return !isXThreshold(point.series) && point.series.type !== "column" && point.series.type !== "errorbar";
|
|
134
|
+
};
|
|
135
|
+
}
|
|
136
|
+
create(target, point, group, showLine) {
|
|
137
|
+
var _a;
|
|
138
|
+
this.hide();
|
|
139
|
+
const chart = (_a = group[0]) === null || _a === void 0 ? void 0 : _a.series.chart;
|
|
140
|
+
if (!chart) {
|
|
141
|
+
return;
|
|
142
|
+
}
|
|
143
|
+
if (showLine) {
|
|
144
|
+
// The cursor line is rendered orthogonally to the x axis (when the chart is inverted, the line is rendered horizontally).
|
|
145
|
+
// The line is 1px thick, and is rendered through the center of the target's rect.
|
|
146
|
+
const lineAttrs = chart.inverted
|
|
147
|
+
? {
|
|
148
|
+
x: chart.plotLeft,
|
|
149
|
+
y: chart.plotTop + target.y - target.height - 1,
|
|
150
|
+
width: chart.plotWidth,
|
|
151
|
+
height: 1,
|
|
152
|
+
}
|
|
153
|
+
: {
|
|
154
|
+
x: target.x + target.width / 2,
|
|
155
|
+
y: chart.plotTop,
|
|
156
|
+
width: 1,
|
|
157
|
+
height: chart.plotHeight,
|
|
158
|
+
};
|
|
159
|
+
this.lineElement.rect(chart.renderer, { ...Styles.cursorLine, ...lineAttrs });
|
|
160
|
+
}
|
|
161
|
+
for (const p of group.filter(this.isPointEligibleForMarker)) {
|
|
162
|
+
if (p.plotX !== undefined && p.plotY !== undefined) {
|
|
163
|
+
const selected = p === point;
|
|
164
|
+
const className = clsx(testClasses["highlight-marker"], selected && testClasses["highlight-marker-selected"]);
|
|
165
|
+
renderMarker(chart, this.markerElementsPool, p, selected, className);
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
hide() {
|
|
170
|
+
this.lineElement.hide();
|
|
171
|
+
this.markerElementsPool.hideAll();
|
|
172
|
+
}
|
|
173
|
+
destroy() {
|
|
174
|
+
this.lineElement.destroy();
|
|
175
|
+
this.markerElementsPool.destroyAll();
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
function getPieChartTargetPlacement(point) {
|
|
179
|
+
// The pie series segments do not provide plotX, plotY to compute the tooltip placement.
|
|
180
|
+
// Instead, there is a `tooltipPos` tuple, which is not covered by TS.
|
|
181
|
+
// See: https://github.com/highcharts/highcharts/issues/23118.
|
|
182
|
+
if ("tooltipPos" in point && Array.isArray(point.tooltipPos)) {
|
|
183
|
+
// We use very small but non-zero track size as otherwise it is placed incorrectly in Firefox.
|
|
184
|
+
return { x: point.tooltipPos[0], y: point.tooltipPos[1], width: 0.1, height: 0.1 };
|
|
185
|
+
}
|
|
186
|
+
// We use the alternative, middle, tooltip placement as a fallback, in case the undocumented "tooltipPos"
|
|
187
|
+
// is no longer available in the point.
|
|
188
|
+
return getPieMiddlePlacement(point);
|
|
189
|
+
}
|
|
190
|
+
function getPieMiddlePlacement(point) {
|
|
191
|
+
const chart = point.series.chart;
|
|
192
|
+
const [relativeX, relativeY, relativeDiameter] = point.series.center;
|
|
193
|
+
const plotLeft = chart.plotLeft;
|
|
194
|
+
const plotTop = chart.plotTop;
|
|
195
|
+
const centerX = plotLeft + (typeof relativeX === "number" ? relativeX : (relativeX / 100) * chart.plotWidth);
|
|
196
|
+
const centerY = plotTop + (typeof relativeY === "number" ? relativeY : (relativeY / 100) * chart.plotHeight);
|
|
197
|
+
const radius = (typeof relativeDiameter === "number" ? relativeDiameter : (relativeDiameter / 100) * chart.plotWidth) / 2;
|
|
198
|
+
return { x: centerX, y: centerY - radius, width: 1, height: 2 * radius };
|
|
199
|
+
}
|
|
200
|
+
function getSolidGaugeTargetPlacement(point) {
|
|
201
|
+
const chart = point.series.chart;
|
|
202
|
+
return {
|
|
203
|
+
x: chart.plotLeft + chart.plotWidth / 2,
|
|
204
|
+
y: chart.plotTop + chart.plotHeight / 2,
|
|
205
|
+
width: 0.1,
|
|
206
|
+
height: 0.1,
|
|
207
|
+
};
|
|
208
|
+
}
|
|
209
|
+
//# sourceMappingURL=chart-extra-tooltip.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"chart-extra-tooltip.js","sourceRoot":"","sources":["../../../../src/core/chart-api/chart-extra-tooltip.tsx"],"names":[],"mappings":"AAAA,qEAAqE;AACrE,sCAAsC;AAEtC,OAAO,I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,EAAE,KAAK,EAAE,CAAC,EAAE,MAAM,EAAE,CAAC,GAAG,MAAM,EAAE,CAAC;AAC3E,CAAC;AAED,SAAS,4BAA4B,CAAC,KAAuB;IAC3D,MAAM,KAAK,GAAG,KAAK,CAAC,MAAM,CAAC,KAAK,CAAC;IACjC,OAAO;QACL,CAAC,EAAE,KAAK,CAAC,QAAQ,GAAG,KAAK,CAAC,SAAS,GAAG,CAAC;QACvC,CAAC,EAAE,KAAK,CAAC,OAAO,GAAG,KAAK,CAAC,UAAU,GAAG,CAAC;QACvC,KAAK,EAAE,GAAG;QACV,MAAM,EAAE,GAAG;KACZ,CAAC;AACJ,CAAC","sourcesContent":["// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n// SPDX-License-Identifier: Apache-2.0\n\nimport clsx from \"clsx\";\nimport type Highcharts from \"highcharts\";\n\nimport { getIsRtl } from \"@cloudscape-design/component-toolkit/internal\";\n\nimport * as Styles from \"../../internal/chart-styles\";\nimport { renderMarker } from \"../../internal/components/series-marker/render-marker\";\nimport AsyncStore from \"../../internal/utils/async-store\";\nimport { SVGRendererPool, SVGRendererSingle } from \"../../internal/utils/renderer-utils\";\nimport { DebouncedCall, isEqualArrays } from \"../../internal/utils/utils\";\nimport { Rect } from \"../interfaces\";\nimport { getGroupRect, getPointRect, getSeriesId, isXThreshold } from \"../utils\";\nimport { ChartExtraContext } from \"./chart-extra-context\";\n\nimport testClasses from \"../test-classes/styles.css.js\";\n\nconst TOOLTIP_LAST_DISMISS_DELAY = 250;\n\n// The reactive state is used to propagate updates to the chart tooltip React component. The tooltip\n// content is to be derived from the target point and group.\nexport interface ReactiveTooltipState {\n visible: boolean;\n pinned: boolean;\n point: null | Highcharts.Point;\n group: readonly Highcharts.Point[];\n}\n\n// Chart helper that implements tooltip placement logic and cursors.\nexport class ChartExtraTooltip extends AsyncStore<ReactiveTooltipState> {\n private context: ChartExtraContext;\n\n // The tooltip lock is used to prevent tooltip position changes shortly after it was dismissed, to\n // deny its immediate re-appearance in the spot under where the dismiss button was.\n public tooltipLock = false;\n private tooltipLockCall = new DebouncedCall();\n private setTooltipLock = () => {\n if (this.get().pinned) {\n this.tooltipLock = true;\n this.tooltipLockCall.call(() => (this.tooltipLock = false), TOOLTIP_LAST_DISMISS_DELAY);\n }\n };\n\n // The cursor is a vertical or horizontal (in inverted charts) line and hollow or filled markers,\n // shown in cartesian charts on top of the matched group or point.\n private cursor = new HighlightCursorCartesian();\n // The track elements are invisible rectangles, compted for the given target point or group.\n // The target track is used for the \"target\" tooltip placement. The group track is used for\n // the \"middle\" and \"outside\" tooltip placement.\n private targetTrack = new SVGRendererSingle();\n private groupTrack = new SVGRendererSingle();\n\n constructor(context: ChartExtraContext) {\n super({ visible: false, pinned: false, point: null, group: [] });\n this.context = context;\n }\n\n // The targetElement.element can get invalidated by Highcharts, so we cannot use\n // trackRef.current = targetElement.element as it might get invalidated unexpectedly.\n // The getTrack function ensures the latest element reference is given on each request.\n public getTargetTrack = () => (this.targetTrack.element?.element ?? null) as null | SVGElement;\n public getGroupTrack = () => (this.groupTrack.element?.element ?? null) as null | SVGElement;\n\n public onChartDestroy() {\n this.cursor.destroy();\n this.targetTrack.destroy();\n this.groupTrack.destroy();\n }\n\n public showTooltipOnPoint(point: Highcharts.Point, matchingGroup: readonly Highcharts.Point[], ignoreLock = false) {\n if (!this.tooltipLock || ignoreLock) {\n this.set(() => ({ visible: true, pinned: false, point, group: matchingGroup }));\n this.onRenderTooltip({ point, group: matchingGroup });\n }\n }\n\n public showTooltipOnGroup(group: readonly Highcharts.Point[], ignoreLock = false) {\n if (!this.tooltipLock || ignoreLock) {\n this.setGroupIfDifferent(group);\n this.onRenderTooltip({ point: null, group });\n }\n }\n\n public hideTooltip() {\n this.cursor.hide();\n this.targetTrack.hide();\n this.groupTrack.hide();\n this.setTooltipLock();\n this.set((prev) => ({ ...prev, visible: false, pinned: false }));\n }\n\n public pinTooltip() {\n if (this.context.settings.tooltipEnabled) {\n this.set((prev) => ({ ...prev, visible: true, pinned: true }));\n }\n }\n\n // Avoid re-rendering the tooltip on every cursor position change when hovering over the graph.\n // Just re-render when the groups are different.\n private setGroupIfDifferent(group: readonly Highcharts.Point[]) {\n function isGroupEqual(a: Highcharts.Point, b: Highcharts.Point) {\n return a?.x === b?.x && a?.y === b?.y && getSeriesId(a?.series) === getSeriesId(b?.series);\n }\n\n this.set((prev) => {\n return isEqualArrays(prev.group, group, isGroupEqual)\n ? prev\n : { visible: true, pinned: false, point: null, group };\n });\n }\n\n private onRenderTooltip = (props: { point: null | Highcharts.Point; group: readonly Highcharts.Point[] }) => {\n const chartType =\n this.context.chart().series.find((s) => s.type === \"pie\" || s.type === \"solidgauge\")?.type ?? \"cartesian\";\n if (chartType === \"pie\") {\n return this.onRenderTooltipPie(props.group[0]);\n } else if (chartType === \"solidgauge\") {\n return this.onRenderTooltipSolidGauge(props.group[0]);\n } else {\n return this.onRenderTooltipCartesian(props);\n }\n };\n\n private onRenderTooltipCartesian = ({\n point,\n group,\n }: {\n point: null | Highcharts.Point;\n group: readonly Highcharts.Point[];\n }) => {\n const pointRect = point ? getPointRect(point) : getGroupRect(group.slice(0, 1));\n const groupRect = getGroupRect(group);\n // The cursor is not shown when column series are present (a UX decision).\n const hasColumnSeries = this.context.chart().series.some((s) => s.type === \"column\");\n this.cursor.create(groupRect, point, group, !hasColumnSeries);\n this.targetTrack.rect(this.context.chart().renderer, { ...pointRect, ...this.commonTrackAttrs });\n this.groupTrack.rect(this.context.chart().renderer, { ...groupRect, ...this.commonTrackAttrs });\n };\n\n private onRenderTooltipPie = (point: Highcharts.Point) => {\n // We only create target track for pie chart as pie chart does not support groups.\n // It is also expected that only \"target\" tooltip position is used for pie charts.\n const pointRect = getPieChartTargetPlacement(point);\n this.targetTrack.rect(this.context.chart().renderer, { ...pointRect, ...this.commonTrackAttrs });\n };\n\n private onRenderTooltipSolidGauge = (point: Highcharts.Point) => {\n // Solid gauge charts are similar to pie charts in that they have a circular shape\n // and don't support grouping. We use a similar approach to pie charts.\n const pointRect = getSolidGaugeTargetPlacement(point);\n this.targetTrack.rect(this.context.chart().renderer, { ...pointRect, ...this.commonTrackAttrs });\n };\n\n private get commonTrackAttrs() {\n return { fill: \"transparent\", zIndex: -1, style: \"pointer-events:none\", direction: this.direction };\n }\n\n // We compute the direction from the chart container and then explicitly set it to the track\n // elements, as otherwise the direction check done for track elements always results to \"ltr\".\n private get direction() {\n const isRtl = getIsRtl(this.context.chart().container.parentElement);\n return isRtl ? \"rtl\" : \"ltr\";\n }\n}\n\n// A helper class to draw the cursor elements (include cursor line and matched points markers).\nclass HighlightCursorCartesian {\n private lineElement = new SVGRendererSingle();\n private markerElementsPool = new SVGRendererPool();\n\n public create(target: Rect, point: null | Highcharts.Point, group: readonly Highcharts.Point[], showLine: boolean) {\n this.hide();\n const chart = group[0]?.series.chart;\n if (!chart) {\n return;\n }\n if (showLine) {\n // The cursor line is rendered orthogonally to the x axis (when the chart is inverted, the line is rendered horizontally).\n // The line is 1px thick, and is rendered through the center of the target's rect.\n const lineAttrs = chart.inverted\n ? {\n x: chart.plotLeft,\n y: chart.plotTop + target.y - target.height - 1,\n width: chart.plotWidth,\n height: 1,\n }\n : {\n x: target.x + target.width / 2,\n y: chart.plotTop,\n width: 1,\n height: chart.plotHeight,\n };\n this.lineElement.rect(chart.renderer, { ...Styles.cursorLine, ...lineAttrs });\n }\n for (const p of group.filter(this.isPointEligibleForMarker)) {\n if (p.plotX !== undefined && p.plotY !== undefined) {\n const selected = p === point;\n const className = clsx(testClasses[\"highlight-marker\"], selected && testClasses[\"highlight-marker-selected\"]);\n renderMarker(chart, this.markerElementsPool, p, selected, className);\n }\n }\n }\n\n public hide() {\n this.lineElement.hide();\n this.markerElementsPool.hideAll();\n }\n\n public destroy() {\n this.lineElement.destroy();\n this.markerElementsPool.destroyAll();\n }\n\n private isPointEligibleForMarker = (point: Highcharts.Point) => {\n return !isXThreshold(point.series) && point.series.type !== \"column\" && point.series.type !== \"errorbar\";\n };\n}\n\nfunction getPieChartTargetPlacement(point: Highcharts.Point): Rect {\n // The pie series segments do not provide plotX, plotY to compute the tooltip placement.\n // Instead, there is a `tooltipPos` tuple, which is not covered by TS.\n // See: https://github.com/highcharts/highcharts/issues/23118.\n if (\"tooltipPos\" in point && Array.isArray(point.tooltipPos)) {\n // We use very small but non-zero track size as otherwise it is placed incorrectly in Firefox.\n return { x: point.tooltipPos[0], y: point.tooltipPos[1], width: 0.1, height: 0.1 };\n }\n // We use the alternative, middle, tooltip placement as a fallback, in case the undocumented \"tooltipPos\"\n // is no longer available in the point.\n return getPieMiddlePlacement(point);\n}\n\nfunction getPieMiddlePlacement(point: Highcharts.Point): Rect {\n const chart = point.series.chart;\n const [relativeX, relativeY, relativeDiameter] = point.series.center;\n const plotLeft = chart.plotLeft;\n const plotTop = chart.plotTop;\n const centerX = plotLeft + (typeof relativeX === \"number\" ? relativeX : (relativeX / 100) * chart.plotWidth);\n const centerY = plotTop + (typeof relativeY === \"number\" ? relativeY : (relativeY / 100) * chart.plotHeight);\n const radius =\n (typeof relativeDiameter === \"number\" ? relativeDiameter : (relativeDiameter / 100) * chart.plotWidth) / 2;\n return { x: centerX, y: centerY - radius, width: 1, height: 2 * radius };\n}\n\nfunction getSolidGaugeTargetPlacement(point: Highcharts.Point): Rect {\n const chart = point.series.chart;\n return {\n x: chart.plotLeft + chart.plotWidth / 2,\n y: chart.plotTop + chart.plotHeight / 2,\n width: 0.1,\n height: 0.1,\n };\n}\n"]}
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
/// <reference types="react" />
|
|
2
|
+
import type Highcharts from "highcharts";
|
|
3
|
+
import { ReadonlyAsyncStore } from "../../internal/utils/async-store";
|
|
4
|
+
import { ReactiveAxisTitlesState } from "./chart-extra-axis-titles";
|
|
5
|
+
import { ChartExtraContext } from "./chart-extra-context";
|
|
6
|
+
import { ReactiveLegendState } from "./chart-extra-legend";
|
|
7
|
+
import { ReactiveNodataState } from "./chart-extra-nodata";
|
|
8
|
+
import { ReactiveTooltipState } from "./chart-extra-tooltip";
|
|
9
|
+
export declare function useChartAPI(settings: ChartExtraContext.Settings, handlers: ChartExtraContext.Handlers, state: ChartExtraContext.State): ChartAPI;
|
|
10
|
+
export declare class ChartAPI {
|
|
11
|
+
context: ChartExtraContext;
|
|
12
|
+
private chartExtraHighlight;
|
|
13
|
+
private chartExtraTooltip;
|
|
14
|
+
private chartExtraNavigation;
|
|
15
|
+
private chartExtraPointer;
|
|
16
|
+
private chartExtraLegend;
|
|
17
|
+
private chartExtraNodata;
|
|
18
|
+
private chartExtraAxisTitles;
|
|
19
|
+
constructor(settings: ChartExtraContext.Settings, handlers: ChartExtraContext.Handlers, state: ChartExtraContext.State);
|
|
20
|
+
get ready(): boolean;
|
|
21
|
+
getOptions(): {
|
|
22
|
+
onChartLoad: Highcharts.ChartLoadCallbackFunction;
|
|
23
|
+
onChartRender: Highcharts.ChartRenderCallbackFunction;
|
|
24
|
+
onChartClick: Highcharts.ChartClickCallbackFunction;
|
|
25
|
+
onSeriesPointMouseOver: Highcharts.PointMouseOverCallbackFunction;
|
|
26
|
+
onSeriesPointMouseOut: Highcharts.PointMouseOutCallbackFunction;
|
|
27
|
+
onSeriesPointClick: Highcharts.PointClickCallbackFunction;
|
|
28
|
+
};
|
|
29
|
+
onChartDestroy: () => void;
|
|
30
|
+
get tooltipStore(): ReadonlyAsyncStore<ReactiveTooltipState>;
|
|
31
|
+
get legendStore(): ReadonlyAsyncStore<ReactiveLegendState>;
|
|
32
|
+
get nodataStore(): ReadonlyAsyncStore<ReactiveNodataState>;
|
|
33
|
+
get axisTitlesStore(): ReadonlyAsyncStore<ReactiveAxisTitlesState>;
|
|
34
|
+
getTargetTrack: () => SVGElement | null;
|
|
35
|
+
getGroupTrack: () => SVGElement | null;
|
|
36
|
+
renderMarker: (type: import("../../internal/components/series-marker").ChartSeriesMarkerType, color: string, visible?: boolean) => import("react").ReactNode;
|
|
37
|
+
onMouseEnterTooltip: () => void;
|
|
38
|
+
onMouseLeaveTooltip: () => void;
|
|
39
|
+
onDismissTooltip: (outsideClick?: boolean) => void;
|
|
40
|
+
setApplication: (element: HTMLElement | null) => void;
|
|
41
|
+
updateItemsVisibility: () => void;
|
|
42
|
+
onItemVisibilityChange: (items: readonly string[]) => void;
|
|
43
|
+
onHighlightChartItems: (itemIds: readonly string[]) => void;
|
|
44
|
+
onClearChartItemsHighlight: () => void;
|
|
45
|
+
highlightChartItems: (itemIds: readonly string[]) => void;
|
|
46
|
+
setItemsVisible: (visibleItemsIds: readonly string[], { isApiCall }: {
|
|
47
|
+
isApiCall: boolean;
|
|
48
|
+
}) => void;
|
|
49
|
+
highlightChartPoint: (point: Highcharts.Point, { isApiCall }: {
|
|
50
|
+
isApiCall: boolean;
|
|
51
|
+
}) => void;
|
|
52
|
+
highlightChartGroup: (group: readonly Highcharts.Point[], { isApiCall }: {
|
|
53
|
+
isApiCall: boolean;
|
|
54
|
+
}) => void;
|
|
55
|
+
clearChartHighlight: ({ isApiCall }: {
|
|
56
|
+
isApiCall: boolean;
|
|
57
|
+
}) => void;
|
|
58
|
+
get publicApi(): {
|
|
59
|
+
highlightItems: (itemIds: readonly string[]) => void;
|
|
60
|
+
setItemsVisible: (visibleItemIds: readonly string[]) => void;
|
|
61
|
+
highlightChartPoint: (point: Highcharts.Point) => void;
|
|
62
|
+
highlightChartGroup: (group: readonly Highcharts.Point[]) => void;
|
|
63
|
+
clearChartHighlight: () => void;
|
|
64
|
+
};
|
|
65
|
+
private get navigationHandlers();
|
|
66
|
+
private get pointerHandlers();
|
|
67
|
+
private showMarkersForIsolatedPoints;
|
|
68
|
+
private handleDestroyedPoints;
|
|
69
|
+
private resetColorCounter;
|
|
70
|
+
private pinTooltipOnPoint;
|
|
71
|
+
private pinTooltipOnGroup;
|
|
72
|
+
private highlightActions;
|
|
73
|
+
private clearHighlightActions;
|
|
74
|
+
private get isTooltipPinned();
|
|
75
|
+
}
|