@cloudscape-design/chart-components 1.0.163 → 1.0.164
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/core/chart-api/chart-extra-pointer.d.ts +3 -2
- package/core/chart-api/chart-extra-pointer.js +15 -6
- package/core/chart-api/chart-extra-pointer.js.map +1 -1
- package/core/chart-api/chart-extra-zoom.d.ts +58 -1
- package/core/chart-api/chart-extra-zoom.js +451 -23
- package/core/chart-api/chart-extra-zoom.js.map +1 -1
- package/core/chart-api/index.d.ts +11 -2
- package/core/chart-api/index.js +25 -9
- package/core/chart-api/index.js.map +1 -1
- package/core/chart-core.js +11 -5
- package/core/chart-core.js.map +1 -1
- package/core/chart-zoom/zoom-state-machine.d.ts +65 -0
- package/core/chart-zoom/zoom-state-machine.js +77 -0
- package/core/chart-zoom/zoom-state-machine.js.map +1 -0
- package/core/chart-zoom/zoom-utils.d.ts +8 -0
- package/core/chart-zoom/zoom-utils.js +47 -0
- package/core/chart-zoom/zoom-utils.js.map +1 -0
- package/core/components/{core-zoom.d.ts → core-zoom-controls.d.ts} +0 -3
- package/core/components/core-zoom-controls.js +30 -0
- package/core/components/core-zoom-controls.js.map +1 -0
- package/core/components/core-zoom-cursor.d.ts +7 -0
- package/core/components/core-zoom-cursor.js +10 -0
- package/core/components/core-zoom-cursor.js.map +1 -0
- package/core/components/core-zoom-live-region.d.ts +4 -0
- package/core/components/core-zoom-live-region.js +11 -0
- package/core/components/core-zoom-live-region.js.map +1 -0
- package/core/i18n-utils.d.ts +8 -0
- package/core/i18n-utils.js +15 -4
- package/core/i18n-utils.js.map +1 -1
- package/core/styles.css.js +24 -22
- package/core/styles.scoped.css +62 -22
- package/core/styles.selectors.js +24 -22
- package/core/test-classes/styles.css.js +38 -33
- package/core/test-classes/styles.scoped.css +38 -33
- package/core/test-classes/styles.selectors.js +38 -33
- package/core/utils.d.ts +1 -0
- package/core/utils.js +6 -0
- package/core/utils.js.map +1 -1
- package/internal/chart-styles.d.ts +12 -0
- package/internal/chart-styles.js +13 -1
- package/internal/chart-styles.js.map +1 -1
- package/internal/environment.js +1 -1
- package/internal/environment.json +1 -1
- package/internal/manifest.json +1 -1
- package/package.json +1 -1
- package/core/components/core-zoom.js +0 -20
- package/core/components/core-zoom.js.map +0 -1
|
@@ -7,6 +7,7 @@ export interface ChartExtraPointerHandlers {
|
|
|
7
7
|
onHoverLost(): void;
|
|
8
8
|
onPointClick(point: Highcharts.Point): void;
|
|
9
9
|
onGroupClick(group: Highcharts.Point[]): void;
|
|
10
|
+
isLocked(): boolean;
|
|
10
11
|
}
|
|
11
12
|
export declare class ChartExtraPointer {
|
|
12
13
|
private context;
|
|
@@ -24,8 +25,8 @@ export declare class ChartExtraPointer {
|
|
|
24
25
|
onMouseLeaveTooltip: () => void;
|
|
25
26
|
private onChartMousemove;
|
|
26
27
|
private onChartMouseout;
|
|
27
|
-
onChartClick: (point: null | Highcharts.Point) =>
|
|
28
|
-
onSeriesPointClick: (point: Highcharts.Point) =>
|
|
28
|
+
onChartClick: (point: null | Highcharts.Point) => boolean;
|
|
29
|
+
onSeriesPointClick: (point: Highcharts.Point) => boolean;
|
|
29
30
|
private onClick;
|
|
30
31
|
private setHoveredPoint;
|
|
31
32
|
private setHoveredGroup;
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
// SPDX-License-Identifier: Apache-2.0
|
|
3
3
|
import { getChartSeries, isPointVisible } from "../../internal/utils/highcharts";
|
|
4
4
|
import { DebouncedCall } from "../../internal/utils/utils";
|
|
5
|
+
import { isInsidePlot } from "../utils";
|
|
5
6
|
const HOVER_LOST_DELAY = 25;
|
|
6
7
|
// Chart helper that implements pointer events (click and hover).
|
|
7
8
|
export class ChartExtraPointer {
|
|
@@ -23,6 +24,9 @@ export class ChartExtraPointer {
|
|
|
23
24
|
// Highcharts because it includes computation of complex shape intersections, such as pie chart segments.
|
|
24
25
|
// When triggered, we set the given point as hovered, and it takes precedence over hovered groups.
|
|
25
26
|
this.onSeriesPointMouseOver = (point) => {
|
|
27
|
+
if (this.handlers.isLocked()) {
|
|
28
|
+
return;
|
|
29
|
+
}
|
|
26
30
|
this.setHoveredPoint(point);
|
|
27
31
|
};
|
|
28
32
|
// When the pointer leaves a point, it does not necessarily mean the hover state needs to be cleared, as another
|
|
@@ -49,6 +53,9 @@ export class ChartExtraPointer {
|
|
|
49
53
|
// of points (those having matching X value in cartesian charts), as this is not directly supported by Highcharts.
|
|
50
54
|
// Points hovering takes precedence over groups hovering.
|
|
51
55
|
this.onChartMousemove = (event) => {
|
|
56
|
+
if (this.handlers.isLocked()) {
|
|
57
|
+
return;
|
|
58
|
+
}
|
|
52
59
|
const chart = this.context.chart();
|
|
53
60
|
// In pie charts there is no support for groups - only a single point can be hovered at a time.
|
|
54
61
|
if (getChartSeries(chart).some((s) => s.type === "pie")) {
|
|
@@ -58,9 +65,8 @@ export class ChartExtraPointer {
|
|
|
58
65
|
const normalized = chart.pointer.normalize(event);
|
|
59
66
|
const plotX = normalized.chartX;
|
|
60
67
|
const plotY = normalized.chartY;
|
|
61
|
-
const { plotLeft, plotTop, plotWidth, plotHeight } = chart;
|
|
62
68
|
// We only check for matched groups if the plotX, plotY are within the plot area, where series are rendered.
|
|
63
|
-
if (
|
|
69
|
+
if (isInsidePlot(chart, plotX, plotY)) {
|
|
64
70
|
// We match groups by comparing the plotX, plotY against each group rect. If the pointer is within one of
|
|
65
71
|
// the rects - the group is considered matched. Otherwise, we take the group which is closest to the pointer.
|
|
66
72
|
// This is done to avoid gaps, when the hover state switches between on and off in a sparsely populated chart,
|
|
@@ -99,11 +105,11 @@ export class ChartExtraPointer {
|
|
|
99
105
|
// This event is triggered by Highcharts when there is a click inside the chart plot. It might or might not include
|
|
100
106
|
// the point, hovered immediately before the click.
|
|
101
107
|
this.onChartClick = (point) => {
|
|
102
|
-
this.onClick(point);
|
|
108
|
+
return this.onClick(point);
|
|
103
109
|
};
|
|
104
110
|
// This event is triggered by Highcharts when a series point is clicked, it always has a point target.
|
|
105
111
|
this.onSeriesPointClick = (point) => {
|
|
106
|
-
this.onClick(point);
|
|
112
|
+
return this.onClick(point);
|
|
107
113
|
};
|
|
108
114
|
// We treat the chart and point clicks the same, but call different handlers depending on the target (null or point).
|
|
109
115
|
// When the point is not present, we assume the click was done on a group, so we take the group that was hovered before
|
|
@@ -112,16 +118,19 @@ export class ChartExtraPointer {
|
|
|
112
118
|
// (visible, and not destroyed by Highcharts).
|
|
113
119
|
this.onClick = (point) => {
|
|
114
120
|
var _a, _b;
|
|
121
|
+
if (this.handlers.isLocked()) {
|
|
122
|
+
return false;
|
|
123
|
+
}
|
|
115
124
|
const targetPoint = point !== null && point !== void 0 ? point : (this.hoveredPoint && isPointVisible(this.hoveredPoint) ? this.hoveredPoint : null);
|
|
116
125
|
if (targetPoint) {
|
|
117
126
|
this.handlers.onPointClick(targetPoint);
|
|
118
|
-
return;
|
|
127
|
+
return true;
|
|
119
128
|
}
|
|
120
129
|
const targetGroup = (_b = (_a = this.hoveredGroup) === null || _a === void 0 ? void 0 : _a.filter(isPointVisible)) !== null && _b !== void 0 ? _b : null;
|
|
121
130
|
if (targetGroup && targetGroup.length > 0) {
|
|
122
131
|
this.handlers.onGroupClick(targetGroup);
|
|
123
|
-
return;
|
|
124
132
|
}
|
|
133
|
+
return true;
|
|
125
134
|
};
|
|
126
135
|
this.setHoveredPoint = (point) => {
|
|
127
136
|
if (isPointVisible(point)) {
|
|
@@ -1 +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,cAAc,EAAa,MAAM,iCAAiC,CAAC;AAC5F,OAAO,EAAE,aAAa,EAAE,MAAM,4BAA4B,CAAC;AAG3D,MAAM,gBAAgB,GAAG,EAAE,CAAC;AAU5B,iEAAiE;AACjE,MAAM,OAAO,iBAAiB;I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inc. or its affiliates. All Rights Reserved.\n// SPDX-License-Identifier: Apache-2.0\n\nimport type Highcharts from \"highcharts\";\n\nimport { getChartSeries, isPointVisible, SafeChart } from \"../../internal/utils/highcharts\";\nimport { DebouncedCall } from \"../../internal/utils/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: SafeChart) => {\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).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 if (container) {\n const value = this.hoveredPoint || this.hoveredGroup ? \"pointer\" : \"default\";\n container.style.cursor = value;\n }\n };\n}\n"]}
|
|
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,cAAc,EAAa,MAAM,iCAAiC,CAAC;AAC5F,OAAO,EAAE,aAAa,EAAE,MAAM,4BAA4B,CAAC;AAC3D,OAAO,EAAE,YAAY,EAAE,MAAM,UAAU,CAAC;AAGxC,MAAM,gBAAgB,GAAG,EAAE,CAAC;AAW5B,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,KAAgB,EAAE,EAAE;YACxC,KAAK,CAAC,SAAS,CAAC,gBAAgB,CAAC,WAAW,EAAE,IAAI,CAAC,gBAAgB,CAAC,CAAC;YACrE,KAAK,CAAC,SAAS,CAAC,gBAAgB,CAAC,UAAU,EAAE,IAAI,CAAC,eAAe,CAAC,CAAC;QACrE,CAAC,CAAC;QAEK,mBAAc,GAAG,GAAG,EAAE;;YAC3B,MAAA,MAAA,IAAI,CAAC,OAAO,CAAC,WAAW,0CAAE,SAAS,0CAAE,mBAAmB,CAAC,WAAW,EAAE,IAAI,C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QACjC,eAAU,GAAG,GAAG,EAAE;YACxB,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,CAAC;oBACrE,IAAI,CAAC,QAAQ,CAAC,WAAW,EAAE,CAAC;oBAC5B,IAAI,CAAC,gBAAgB,EAAE,CAAC;gBAC1B,CAAC;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,IAAI,SAAS,EAAE,CAAC;gBACd,MAAM,KAAK,GAAG,IAAI,CAAC,YAAY,IAAI,IAAI,CAAC,YAAY,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,SAAS,CAAC;gBAC7E,SAAS,CAAC,KAAK,CAAC,MAAM,GAAG,KAAK,CAAC;YACjC,CAAC;QACH,CAAC,CAAC;QA1KA,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC;QACvB,IAAI,CAAC,QAAQ,GAAG,QAAQ,CAAC;IAC3B,CAAC;CAyKF","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, isPointVisible, SafeChart } from \"../../internal/utils/highcharts\";\nimport { DebouncedCall } from \"../../internal/utils/utils\";\nimport { isInsidePlot } 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 isLocked(): boolean;\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: SafeChart) => {\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 if (this.handlers.isLocked()) {\n return;\n }\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 if (this.handlers.isLocked()) {\n return;\n }\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).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 // We only check for matched groups if the plotX, plotY are within the plot area, where series are rendered.\n if (isInsidePlot(chart, plotX, plotY)) {\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): boolean => {\n return 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): boolean => {\n return 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): boolean => {\n if (this.handlers.isLocked()) {\n return false;\n }\n const targetPoint = point ?? (this.hoveredPoint && isPointVisible(this.hoveredPoint) ? this.hoveredPoint : null);\n if (targetPoint) {\n this.handlers.onPointClick(targetPoint);\n return true;\n }\n const targetGroup = this.hoveredGroup?.filter(isPointVisible) ?? null;\n if (targetGroup && targetGroup.length > 0) {\n this.handlers.onGroupClick(targetGroup);\n }\n return true;\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 if (container) {\n const value = this.hoveredPoint || this.hoveredGroup ? \"pointer\" : \"default\";\n container.style.cursor = value;\n }\n };\n}\n"]}
|
|
@@ -1,20 +1,77 @@
|
|
|
1
1
|
import AsyncStore from "../../internal/utils/async-store";
|
|
2
|
+
import { SafeChart } from "../../internal/utils/highcharts";
|
|
3
|
+
import { ZoomCancelReason } from "../chart-zoom/zoom-state-machine";
|
|
2
4
|
import { ChartExtraContext } from "./chart-extra-context";
|
|
3
5
|
export interface ReactiveZoomState {
|
|
4
6
|
zoomed: boolean;
|
|
7
|
+
zooming: boolean;
|
|
8
|
+
canZoom: boolean;
|
|
5
9
|
announcement: string;
|
|
10
|
+
announcementKey: number;
|
|
11
|
+
}
|
|
12
|
+
export interface ChartExtraZoomHandlers {
|
|
13
|
+
onHideTooltip(): void;
|
|
14
|
+
}
|
|
15
|
+
export interface FocusableControl {
|
|
16
|
+
focus(): void;
|
|
6
17
|
}
|
|
7
18
|
export declare class ChartExtraZoom extends AsyncStore<ReactiveZoomState> {
|
|
8
19
|
private context;
|
|
20
|
+
private handlers;
|
|
21
|
+
private interaction;
|
|
22
|
+
private pressIndex;
|
|
23
|
+
private localExtremes;
|
|
24
|
+
private values;
|
|
25
|
+
private pressClickPending;
|
|
26
|
+
private container;
|
|
27
|
+
private cursorElement;
|
|
28
|
+
private controlsElement;
|
|
29
|
+
private zoomButton;
|
|
30
|
+
private resetButton;
|
|
9
31
|
private rangeBand;
|
|
10
32
|
private rangeBorders;
|
|
11
|
-
|
|
33
|
+
private selectionBand;
|
|
34
|
+
private selectionStart;
|
|
35
|
+
constructor(context: ChartExtraContext, handlers: ChartExtraZoomHandlers);
|
|
36
|
+
get pointerLocked(): boolean;
|
|
37
|
+
setCursor: (element: null | HTMLElement) => void;
|
|
38
|
+
setControls: (element: null | HTMLElement) => void;
|
|
39
|
+
setZoomButton: (button: null | FocusableControl) => void;
|
|
40
|
+
setResetButton: (button: null | FocusableControl) => void;
|
|
41
|
+
onChartLoad: (chart: SafeChart) => void;
|
|
12
42
|
onChartRender: () => void;
|
|
13
43
|
onChartDestroy: () => void;
|
|
14
44
|
onZoomPropsChange: () => void;
|
|
45
|
+
enterZoomMode: () => void;
|
|
46
|
+
exitZoomMode: (reason: ZoomCancelReason) => void;
|
|
15
47
|
resetZoom: () => void;
|
|
48
|
+
onCursorKeyDown: (event: React.KeyboardEvent) => void;
|
|
49
|
+
onBlur: (event: React.FocusEvent) => void;
|
|
50
|
+
private updateCanZoom;
|
|
51
|
+
private isFocusWithinZoom;
|
|
52
|
+
private get enabled();
|
|
53
|
+
private get labels();
|
|
54
|
+
private get xAxis();
|
|
55
|
+
private get controlled();
|
|
16
56
|
private getExtremes;
|
|
17
57
|
private reconcile;
|
|
18
58
|
private applyExtremes;
|
|
59
|
+
private updateValues;
|
|
60
|
+
private formatValue;
|
|
61
|
+
private announce;
|
|
62
|
+
private setCommon;
|
|
63
|
+
private dispatch;
|
|
64
|
+
private dispatchInput;
|
|
65
|
+
private moveFocus;
|
|
66
|
+
private runEffect;
|
|
67
|
+
private describeAnnouncement;
|
|
19
68
|
private drawRange;
|
|
69
|
+
private syncOverlay;
|
|
70
|
+
private drawSelection;
|
|
71
|
+
private hideOverlay;
|
|
72
|
+
private onPlotPointerDown;
|
|
73
|
+
private onPlotPointerMove;
|
|
74
|
+
private onContainerClick;
|
|
75
|
+
private onDocumentPointerUp;
|
|
76
|
+
private onDocumentPointerCancel;
|
|
20
77
|
}
|