Skip to content

Commit 8fea316

Browse files
authored
fix: Fixes cursor line position for inverted cartesian chart (#53)
1 parent 362232e commit 8fea316

File tree

3 files changed

+124
-9
lines changed

3 files changed

+124
-9
lines changed

pages/06-visual-tests/column-hover.page.tsx

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,6 @@ import { dateFormatter } from "../common/formatters";
88
import { useChartSettings } from "../common/page-settings";
99
import { Page, PageSection } from "../common/templates";
1010

11-
const domain = [
12-
new Date(1601071200000),
13-
new Date(1601078400000),
14-
new Date(1601085600000),
15-
new Date(1601092800000),
16-
new Date(1601100000000),
17-
];
18-
1911
export default function () {
2012
return (
2113
<Page title="Column series hover visual regression page">
@@ -34,6 +26,14 @@ export default function () {
3426
);
3527
}
3628

29+
const domain = [
30+
new Date(1601071200000),
31+
new Date(1601078400000),
32+
new Date(1601085600000),
33+
new Date(1601092800000),
34+
new Date(1601100000000),
35+
];
36+
3737
function Chart({ type }: { type: "single" | "stacked" | "grouped" }) {
3838
const { chartProps } = useChartSettings();
3939
return (
Lines changed: 115 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,115 @@
1+
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
2+
// SPDX-License-Identifier: Apache-2.0
3+
4+
import ColumnLayout from "@cloudscape-design/components/column-layout";
5+
6+
import CoreChart from "../../lib/components/internal-do-not-use/core-chart";
7+
import { dateFormatter } from "../common/formatters";
8+
import { useChartSettings } from "../common/page-settings";
9+
import { Page, PageSection } from "../common/templates";
10+
11+
export default function () {
12+
return (
13+
<Page title="Line series hover visual regression page">
14+
<ColumnLayout columns={2}>
15+
<PageSection>
16+
<Chart inverted={false} />
17+
</PageSection>
18+
<PageSection>
19+
<Chart inverted={true} />
20+
</PageSection>
21+
</ColumnLayout>
22+
</Page>
23+
);
24+
}
25+
26+
const domain = [
27+
new Date(1600984800000),
28+
new Date(1600985700000),
29+
new Date(1600986600000),
30+
new Date(1600987500000),
31+
new Date(1600988400000),
32+
new Date(1600989300000),
33+
new Date(1600990200000),
34+
new Date(1600991100000),
35+
new Date(1600992000000),
36+
new Date(1600992900000),
37+
new Date(1600993800000),
38+
new Date(1600994700000),
39+
new Date(1600995600000),
40+
new Date(1600996500000),
41+
new Date(1600997400000),
42+
new Date(1600998300000),
43+
new Date(1600999200000),
44+
new Date(1601000100000),
45+
new Date(1601001000000),
46+
new Date(1601001900000),
47+
new Date(1601002800000),
48+
new Date(1601003700000),
49+
new Date(1601004600000),
50+
new Date(1601005500000),
51+
new Date(1601006400000),
52+
new Date(1601007300000),
53+
new Date(1601008200000),
54+
new Date(1601009100000),
55+
new Date(1601010000000),
56+
new Date(1601010900000),
57+
new Date(1601011800000),
58+
new Date(1601012700000),
59+
new Date(1601013600000),
60+
];
61+
const site1Data = [
62+
58020, 102402, 104920, 94031, 125021, 159219, 193082, 162592, 274021, 264286, 289210, 256362, 257306, 186776, 294020,
63+
385975, 486039, 490447, 361845, 339058, 298028, 231902, 224558, 253901, 102839, 234943, 204405, 190391, 183570,
64+
162592, 148910, 229492, 293910,
65+
];
66+
const site2Data = [
67+
151023, 169975, 176980, 168852, 149130, 147299, 169552, 163401, 154091, 199516, 195503, 189953, 181635, 192975,
68+
205951, 218958, 220516, 213557, 165899, 173557, 172331, 186492, 131541, 142262, 194091, 185899, 173401, 171635,
69+
179130, 185951, 144091, 152975, 157299,
70+
];
71+
72+
function Chart({ inverted }: { inverted: boolean }) {
73+
const { chartProps } = useChartSettings();
74+
return (
75+
<CoreChart
76+
highcharts={chartProps.cartesian.highcharts}
77+
ariaLabel="Line chart"
78+
options={{
79+
chart: { inverted },
80+
series: [
81+
{
82+
name: "Site 1",
83+
type: "line",
84+
data: site1Data.map((y, index) => ({ x: domain[index].getTime(), y })),
85+
},
86+
{
87+
name: "Site 2",
88+
type: "line",
89+
data: site2Data.map((y, index) => ({ x: domain[index].getTime(), y })),
90+
},
91+
],
92+
xAxis: [
93+
{
94+
type: "datetime",
95+
title: { text: "Time (UTC)" },
96+
min: domain[0].getTime(),
97+
max: domain[domain.length - 1].getTime(),
98+
valueFormatter: dateFormatter,
99+
},
100+
],
101+
yAxis: [{ title: { text: "Bytes transferred" }, min: 0, max: 500000 }],
102+
}}
103+
legend={{ enabled: false }}
104+
verticalAxisTitlePlacement="top"
105+
callback={(api) => {
106+
setTimeout(() => {
107+
if (api.chart.series) {
108+
const group = api.chart.series.flatMap((s) => s.data.filter((p) => p.x === domain[10].getTime()));
109+
api.highlightChartGroup(group);
110+
}
111+
}, 0);
112+
}}
113+
/>
114+
);
115+
}

src/core/chart-api/chart-extra-tooltip.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ class HighlightCursorCartesian {
157157
const lineAttrs = chart.inverted
158158
? {
159159
x: chart.plotLeft,
160-
y: chart.plotTop + (target.y - 2 * target.height),
160+
y: chart.plotTop + target.y - target.height - 1,
161161
width: chart.plotWidth,
162162
height: 1,
163163
}

0 commit comments

Comments
 (0)