Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion src/core/chart-container.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { useResizeObserver } from "@cloudscape-design/component-toolkit/internal

import * as Styles from "../internal/chart-styles";
import { DebouncedCall } from "../internal/utils/utils";
import { ChartAPI } from "./chart-api";

import styles from "./styles.css.js";
import testClasses from "./test-classes/styles.css.js";
Expand All @@ -22,6 +23,7 @@ interface ChartContainerProps {
// The header, footer, vertical axis title, and legend are rendered as is, and we measure the height of these components
// to compute the available height for the chart plot when fitHeight=true. When there is not enough vertical space, the
// container will ensure the overflow behavior.
api: ChartAPI;
chart: (height: undefined | number) => React.ReactNode;
verticalAxisTitle?: React.ReactNode;
verticalAxisTitlePlacement: "top" | "side";
Expand All @@ -40,6 +42,7 @@ interface ChartContainerProps {
}

export function ChartContainer({
api,
chart,
verticalAxisTitle,
verticalAxisTitlePlacement,
Expand All @@ -57,6 +60,8 @@ export function ChartContainer({
chartMinWidth,
}: ChartContainerProps) {
const { refs, measures } = useContainerQueries();
const plotLeft = api.context.chartOrNull?.plotLeft;
const plotWidth = api.context.chartOrNull?.plotWidth;

// The vertical axis title is rendered above the chart, and is technically not a part of the chart plot.
// However, we want to include it to the chart's height computations as it does belong to the chart logically.
Expand Down Expand Up @@ -108,7 +113,13 @@ export function ChartContainer({
{navigator && <div className={testClasses["chart-navigator"]}>{navigator}</div>}
{legend &&
legendPosition === "bottom" &&
(legendBottomMaxHeight ? <div style={{ maxHeight: `${legendBottomMaxHeight}px` }}>{legend}</div> : legend)}
(legendBottomMaxHeight ? (
<div style={{ marginLeft: plotLeft, maxInlineSize: plotWidth, maxHeight: `${legendBottomMaxHeight}px` }}>
{legend}
</div>
) : (
<div style={{ marginLeft: plotLeft, maxInlineSize: plotWidth }}>{legend}</div>
))}
{footer}
</div>
</div>
Expand Down
1 change: 1 addition & 0 deletions src/core/chart-core.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ export function InternalCoreChart({
const rootProps = { ref: mergedRootRef, className: rootClassName, ...getDataAttributes(rest) };
const legendPosition = legendOptions?.position ?? "bottom";
const containerProps = {
api,
fitHeight,
chartHeight,
chartMinHeight,
Expand Down