generated from amazon-archives/__template_Apache-2.0
-
Notifications
You must be signed in to change notification settings - Fork 12
fix: Adjusting chart tooltip position on resize #117
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,128 @@ | ||
| // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
| // SPDX-License-Identifier: Apache-2.0 | ||
|
|
||
| import { useState } from "react"; | ||
|
|
||
| import Button from "@cloudscape-design/components/button"; | ||
| import ColumnLayout from "@cloudscape-design/components/column-layout"; | ||
| import Container from "@cloudscape-design/components/container"; | ||
| import Link from "@cloudscape-design/components/link"; | ||
| import SplitPanel from "@cloudscape-design/components/split-panel"; | ||
|
|
||
| import { PieChart } from "../../lib/components"; | ||
| import CoreChart from "../../lib/components/internal-do-not-use/core-chart"; | ||
| import { moneyFormatter } from "../common/formatters"; | ||
| import { PageSettings, useChartSettings } from "../common/page-settings"; | ||
| import { Page } from "../common/templates"; | ||
|
|
||
| interface ThisPageSettings extends PageSettings { | ||
| visibleItems: string; | ||
| } | ||
|
|
||
| const categories = ["Jun 2019", "Jul 2019", "Aug 2019", "Sep 2019", "Oct 2019", "Nov 2019", "Dec 2019"]; | ||
|
|
||
| export default function () { | ||
| const [splitPanelContent, setSplitPanelContent] = useState(""); | ||
| const chartSplitPanelProps = { | ||
| onToggle: (content: string) => setSplitPanelContent((prev) => (prev === content ? "" : content)), | ||
| }; | ||
| return ( | ||
| <Page | ||
| title="Chart with split panel demo" | ||
| subtitle="This page demonstrates opening a split panel from inside chart's tooltip." | ||
| splitPanel={<SplitPanel header="Details">{splitPanelContent}</SplitPanel>} | ||
| splitPanelOpen={splitPanelContent !== ""} | ||
| splitPanelPreferences={{ position: "side" }} | ||
| onSplitPanelToggle={() => setSplitPanelContent((prev) => (prev ? "" : "generic content"))} | ||
| > | ||
| <Container> | ||
| <ColumnLayout columns={2}> | ||
| <LineChartDemo splitPanel={chartSplitPanelProps} /> | ||
| <PieChartDemo splitPanel={chartSplitPanelProps} /> | ||
| </ColumnLayout> | ||
| </Container> | ||
| </Page> | ||
| ); | ||
| } | ||
|
|
||
| function LineChartDemo({ splitPanel }: { splitPanel: { onToggle: (content: string) => void } }) { | ||
| const { chartProps } = useChartSettings<ThisPageSettings>(); | ||
| return ( | ||
| <CoreChart | ||
| {...chartProps.cartesian} | ||
| chartHeight={200} | ||
| ariaLabel="Line chart" | ||
| legend={{ enabled: false }} | ||
| options={{ | ||
| series: [ | ||
| { | ||
| id: "Costs", | ||
| name: "Costs", | ||
| type: "line", | ||
| data: [6562, 8768, 9742, 10464, 16777, 9956, 5876], | ||
| }, | ||
| ], | ||
| xAxis: [{ title: { text: "" }, type: "category", categories }], | ||
| yAxis: [{ title: { text: "" } }], | ||
| }} | ||
| getTooltipContent={() => ({ | ||
| point: ({ item }) => { | ||
| return { | ||
| key: item.point.series.name, | ||
| value: ( | ||
| <Link | ||
| external={true} | ||
| href="#" | ||
| ariaLabel={`See details for ${item.point.series.name} (opens in a new tab)`} | ||
| > | ||
| {item.point.y !== null ? moneyFormatter(item.point.y!) : null} | ||
| </Link> | ||
| ), | ||
| }; | ||
| }, | ||
| footer: (detail) => ( | ||
| <Button onClick={() => splitPanel.onToggle(`Line chart point, x=${detail.x}`)}>Toggle details</Button> | ||
| ), | ||
| })} | ||
| callback={(api) => { | ||
| setTimeout(() => { | ||
| if (api.chart.series) { | ||
| const seriesIndex = Math.min(api.chart.series.length - 1, 1); | ||
| const point = api.chart.series[seriesIndex].data.find((p) => p.x === 2)!; | ||
| api.highlightChartPoint(point); | ||
| splitPanel.onToggle(`Line chart point, x=${point.x}`); | ||
| } | ||
| }, 0); | ||
| }} | ||
| /> | ||
| ); | ||
| } | ||
|
|
||
| function PieChartDemo({ splitPanel }: { splitPanel: { onToggle: (content: string) => void } }) { | ||
| const { chartProps } = useChartSettings<ThisPageSettings>(); | ||
| return ( | ||
| <PieChart | ||
| {...chartProps.pie} | ||
| chartHeight={200} | ||
| ariaLabel="Pie chart" | ||
| legend={{ enabled: false }} | ||
| segmentTitle={() => ""} | ||
| tooltip={{ | ||
| footer: (detail) => ( | ||
| <Button onClick={() => splitPanel.onToggle(`Pie chart point, segment=${detail.segmentName}`)}> | ||
| Toggle details | ||
| </Button> | ||
| ), | ||
| }} | ||
| series={{ | ||
| name: "Resource count", | ||
| type: "pie", | ||
| data: [ | ||
| { name: "Running", y: 60 }, | ||
| { name: "Failed", y: 30 }, | ||
| { name: "In-progress", y: 10 }, | ||
| ], | ||
| }} | ||
| /> | ||
| ); | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If fixes were necessary on this package's side, shouldn't we have some coverage for this too?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Makes sense!
I updated the test page so that it opens the split panel on the given point on the page load, so that the screenshot test captures the desired outcome.