Skip to content

The Open Standard for Generative UI

feat: Update BarChartCondensed to support dynamic radius calculation based on theme (#224)

Ankit Dasc6b5332e6cc8
diff --git a/.cursor/worktrees.json b/.cursor/worktrees.json
new file mode 100644
index 000000000..e57556bc0
--- /dev/null
+++ b/.cursor/worktrees.json
@@ -0,0 +1,5 @@
+{
+ "setup-worktree": [
+ "pnpm install"
+ ]
+}
diff --git a/js/packages/react-ui/src/components/Charts/AreaChartCondensed/AreaChartCondensed.tsx b/js/packages/react-ui/src/components/Charts/AreaChartCondensed/AreaChartCondensed.tsx
index 109634f61..b99d6b405 100644
--- a/js/packages/react-ui/src/components/Charts/AreaChartCondensed/AreaChartCondensed.tsx
+++ b/js/packages/react-ui/src/components/Charts/AreaChartCondensed/AreaChartCondensed.tsx
@@ -1,5 +1,5 @@
import clsx from "clsx";
-import React, { useMemo, useRef, useState } from "react";
+import React, { useEffect, useMemo, useRef, useState } from "react";
import { Area, AreaChart as RechartsAreaChart, XAxis, YAxis } from "recharts";
import { useId } from "../../../polyfills";
import { AreaChartData, AreaChartVariant } from "../AreaChart/types";
@@ -18,10 +18,12 @@ import {
CondensedXAxisTick,
CondensedXAxisTickVariant,
CustomTooltipContent,
+ DefaultLegend,
YAxisTick,
} from "../shared";
import { LabelTooltipProvider } from "../shared/LabelTooltip/LabelTooltip";
-import { get2dChartConfig, getDataKeys } from "../utils/dataUtils";
+import { LegendItem } from "../types";
+import { get2dChartConfig, getDataKeys, getLegendItems } from "../utils/dataUtils";
import { PaletteName, useChartPalette } from "../utils/PalletUtils";
export interface AreaChartCondensedProps<T extends AreaChartData> {
@@ -35,12 +37,15 @@ export interface AreaChartCondensedProps<T extends AreaChartData> {
icons?: Partial<Record<keyof T[number], React.ComponentType>>;
isAnimationActive?: boolean;
showYAxis?: boolean;
+ xAxisLabel?: React.ReactNode;
+ yAxisLabel?: React.ReactNode;
+ legend?: boolean;
className?: string;
height?: number;
width?: number;
}
-const CHART_HEIGHT = 200;
+const CHART_HEIGHT = 296;
const CHART_CONTAINER_BOTTOM_MARGIN = 10;
const AreaChartCondensedComponent = <T extends AreaChartData>({
@@ -54,6 +59,9 @@ const AreaChartCondensedComponent = <T extends AreaChartData>({
icons = {},
isAnimationActive = false,
showYAxis = true,
+ xAxisLabel,
+ yAxisLabel,
+ legend = true,
className,
height = CHART_HEIGHT,
width,
@@ -68,9 +76,7 @@ const AreaChartCondensedComponent = <T extends AreaChartData>({
const { angle: calculatedAngle, height: xAxisHeight } = useAutoAngleCalculation(
maxLabelWidth,
- yAxisWidth,
tickVariant === "angled",
- showYAxis,
);
const effectiveHeight = useMemo(() => {
@@ -78,7 +84,7 @@ const AreaChartCondensedComponent = <T extends AreaChartData>({
return xAxisHeight + height;
}
return height;
- }, [height, xAxisHeight]);
+ }, [height, xAxisHeight, tickVariant]);
const transformedKeys = useTransformedKeys(dataKeys);
@@ -107,11 +113,104 @@ const AreaChartCondensedComponent = <T extends AreaChartData>({
);
const containerRef = useRef<HTMLDivElement>(null);
+ const [containerWidth, setContainerWidth] = useState<number>(0);
const [isSideBarTooltipOpen, setIsSideBarTooltipOpen] = useState(false);
const [sideBarTooltipData, setSideBarTooltipData] = useState<SideBarChartData>({
title: "",
values: [],
});
+ const [isLegendExpanded, setIsLegendExpanded] = useState(false);
+
+ // Use provided width or observed width
+ const effectiveWidth = useMemo(() => {
+ return width ?? containerWidth;
+ }, [width, containerWidth]);
+
+ // Observe container width for legend
+ useEffect(() => {
+ // Only set up ResizeObserver if width is not provided
+ if (width || !containerRef.current) {
+ return () => {};
+ }
+
+ const resizeObserver = new ResizeObserver((entries) => {
+ // there is only one entry in the entries array because we are observing the chart container
+ for (const entry of entries) {
+ setContainerWidth(entry.contentRect.width);
+ }
+ });
+
+ resizeObserver.observe(containerRef.current);
+
+ return () => {
+ resizeObserver.disconnect();
+ };
+ }, [width]);
+
+ useEffect(() => {
+ setIsLegendExpanded(false);
+ }, [dataKeys]);
+
+ // Memoize legend items creation
+ const legendItems: LegendItem[] = useMemo(() => {
+ if (!legend) {
+ return [];
+ }
+ return getLegendItems(dataKeys, colors, icons);
+ }, [dataKeys, colors, icons, legend]);
+
+ const yAxis = useMemo(() => {
+ if (!showYAxis) {
+ return null;
+ }
+ return (
+ <div className="crayon-area-chart-condensed-y-axis-container">
+ {/* Y-axis only chart - synchronized with main chart */}
+ <RechartsAreaChart
+ key={`y-axis-area-chart-condensed-${id}`}
+ width={yAxisWidth}
+ height={effectiveHeight}
+ data={data}
+ margin={{
+ top: chartMargin.top,
+ bottom: xAxisHeight + chartMargin.bottom, // this is required to give space for x-axis
+ left: 0,
+ right: 0,
+ }}
+ >
+ <YAxis
+ width={yAxisWidth}
+ tickLine={false}
+ axisLine={false}
+ tick={<YAxisTick setLabelWidth={setLabelWidth} />}
+ />
+ {/* Invisible areas to maintain scale synchronization */}
+ {dataKeys.map((key) => {
+ return (
+ <Area
+ key={`yaxis-area-chart-condensed-${key}`}
+ dataKey={key}
+ fill="transparent"
+ stroke="transparent"
+ stackId="a"
+ isAnimationActive={false}
+ />
+ );
+ })}
+ </RechartsAreaChart>
+ </div>
+ );
+ }, [
+ showYAxis,
+ effectiveHeight,
+ data,
+ dataKeys,
+ id,
+ yAxisWidth,
+ chartMargin,
+ xAxisHeight,
+ setLabelWidth,
+ ]);
return (
<LabelTooltipProvider>
@@ -122,100 +221,110 @@ const AreaChartCondensedComponent = <T extends AreaChartData>({
setData={setSideBarTooltipData}
>
<div
- ref={containerRef}
- className={clsx("crayon-area-chart-condensed", className)}
+ className={clsx("crayon-area-chart-condensed-container", className)}
style={{
- width: width ? `${width}px` : "100%",
- height: `${effectiveHeight}px`,
+ width: width ? `${width}px` : undefined,
}}
>
- <ChartContainer
- config={chartConfig}
- style={{ width: "100%", height: "100%" }}
- rechartsProps={{
- width: "100%",
- height: "100%",
- }}
- >
- <RechartsAreaChart
- accessibilityLayer
- key={`area-chart-condensed-${id}`}
- data={data}
- margin={chartMargin}
- >
- {grid && cartesianGrid()}
-
- <XAxis
- dataKey={categoryKey as string}
- tickLine={false}
- axisLine={false}
- textAnchor={tickVariant === "angled" ? "end" : "middle"}
- interval="preserveStartEnd"
- minTickGap={5}
- height={xAxisHeight}
- tick={<CondensedXAxisTick />}
- angle={calculatedAngle}
- orientation="bottom"
- padding={{
- left: X_AXIS_PADDING,
- right: X_AXIS_PADDING,
+ {yAxisLabel && (
+ <div className="crayon-area-chart-condensed-y-axis-label">{yAxisLabel}</div>
+ )}
+ <div className="crayon-area-chart-condensed-container-inner" ref={containerRef}>
+ {/* Y-axis of the chart */}
+ {yAxis}
+ <div className="crayon-area-chart-condensed">
+ <ChartContainer
+ config={chartConfig}
+ style={{ width: "100%", height: effectiveHeight }}
+ rechartsProps={{
+ width: "100%",
+ height: "100%",
}}
- />
+ >
+ <RechartsAreaChart
+ accessibilityLayer
+ key={`area-chart-condensed-${id}`}
+ data={data}
+ margin={chartMargin}
+ >
+ {grid && cartesianGrid()}
- {showYAxis && (
- <YAxis
- tickLine={false}
- axisLine={false}
- tick={<YAxisTick setLabelWidth={setLabelWidth} />}
- width={yAxisWidth}
- />
- )}
-
- <ChartTooltip
- content={<CustomTooltipContent parentRef={containerRef} />}
- offset={10}
- />
+ <XAxis
+ dataKey={categoryKey as string}
+ tickLine={false}
+ axisLine={false}
+ textAnchor={tickVariant === "angled" ? "end" : "middle"}
+ interval="preserveStartEnd"
+ minTickGap={5}
+ height={xAxisHeight}
+ tick={<CondensedXAxisTick />}
+ angle={calculatedAngle}
+ orientation="bottom"
+ padding={{
+ left: X_AXIS_PADDING,
+ right: X_AXIS_PADDING,
+ }}
+ />
+ {/* Y-axis is rendered in the separate synchronized chart */}
- {dataKeys.map((key) => {
- const transformedKey = transformedKeys[key];
- const color = `var(--color-${transformedKey})`;
- return (
- <defs key={`gradient-${transformedKey}`}>
- <linearGradient
- id={`${gradientID}-${transformedKey}`}
- x1="0"
- y1="0"
- x2="0"
- y2="1"
- >
- <stop offset="5%" stopColor={color} stopOpacity={0.6} />
- <stop offset="95%" stopColor={color} stopOpacity={0} />
- </linearGradient>
- </defs>
- );
- })}
-
- {dataKeys.map((key) => {
- const transformedKey = transformedKeys[key];
- const color = `var(--color-${transformedKey})`;
- return (
- <Area
- key={`area-${key}`}
- dataKey={key}
- type={variant}
- stroke={color}
- fill={`url(#${gradientID}-${transformedKey})`}
- fillOpacity={1}
- stackId="a"
- activeDot={<ActiveDot key={`active-dot-${key}-${id}`} />}
- dot={false}
- isAnimationActive={isAnimationActive}
- // strokeWidth={2}
+ <ChartTooltip
+ content={<CustomTooltipContent parentRef={containerRef} />}
+ offset={10}
/>
- );
- })}
- </RechartsAreaChart>
- </ChartContainer>
+
+ {dataKeys.map((key) => {
+ const transformedKey = transformedKeys[key];
+ const color = `var(--color-${transformedKey})`;
+ return (
+ <defs key={`gradient-${transformedKey}`}>
+ <linearGradient
+ id={`${gradientID}-${transformedKey}`}
+ x1="0"
+ y1="0"
+ x2="0"
+ y2="1"
+ >
+ <stop offset="5%" stopColor={color} stopOpacity={0.6} />
+ <stop offset="95%" stopColor={color} stopOpacity={0} />
+ </linearGradient>
+ </defs>
+ );
+ })}
+
+ {dataKeys.map((key) => {
+ const transformedKey = transformedKeys[key];
+ const color = `var(--color-${transformedKey})`;
+ return (
+ <Area
+ key={`area-${key}`}
+ dataKey={key}
+ type={variant}
+ stroke={color}
+ fill={`url(#${gradientID}-${transformedKey})`}
+ fillOpacity={1}
+ stackId="a"
+ activeDot={<ActiveDot key={`active-dot-${key}-${id}`} />}
+ dot={false}
+ isAnimationActive={isAnimationActive}
+ // strokeWidth={2}
+ />
+ );
+ })}
+ </RechartsAreaChart>
+ </ChartContainer>
+ </div>
+ </div>
+ {xAxisLabel && (
+ <div className="crayon-area-chart-condensed-x-axis-label">{xAxisLabel}</div>
+ )}
+ {legend && (
+ <DefaultLegend
+ items={legendItems}
+ containerWidth={effectiveWidth}
+ isExpanded={isLegendExpanded}
+ setIsExpanded={setIsLegendExpanded}
+ />
+ )}
</div>
</SideBarTooltipProvider>
</LabelTooltipProvider>
diff --git a/js/packages/react-ui/src/components/Charts/AreaChartCondensed/areaChartCondensed.scss b/js/packages/react-ui/src/components/Charts/AreaChartCondensed/areaChartCondensed.scss
index 325231cf3..837e1b7c6 100644
--- a/js/packages/react-ui/src/components/Charts/AreaChartCondensed/areaChartCondensed.scss
+++ b/js/packages/react-ui/src/components/Charts/AreaChartCondensed/areaChartCondensed.scss
@@ -1,7 +1,32 @@
@use "../../../cssUtils" as cssUtils;
-.crayon-area-chart-condensed {
+.crayon-area-chart-condensed-container {
display: flex;
flex-direction: column;
- position: relative;
+}
+
+.crayon-area-chart-condensed-container-inner {
+ display: flex;
+ width: 100%;
+}
+
+.crayon-area-chart-condensed-y-axis-container {
+ flex-shrink: 0;
+}
+
+.crayon-area-chart-condensed {
+ width: 100%;
+ height: 100%;
+
+ &-x-axis-label {
+ @include cssUtils.typography(label, extra-small);
+ color: cssUtils.$secondary-text;
+ text-align: center;
+ }
+
+ &-y-axis-label {
+ @include cssUtils.typography(label, extra-small);
+ color: cssUtils.$secondary-text;
+ padding-bottom: cssUtils.$spacing-s;
+ }
}
diff --git a/js/packages/react-ui/src/components/Charts/AreaChartCondensed/stories/areaChartCondensed.stories.tsx b/js/packages/react-ui/src/components/Charts/AreaChartCondensed/stories/areaChartCondensed.stories.tsx
index 1b7eede05..39f0d690e 100644
--- a/js/packages/react-ui/src/components/Charts/AreaChartCondensed/stories/areaChartCondensed.stories.tsx
+++ b/js/packages/react-ui/src/components/Charts/AreaChartCondensed/stories/areaChartCondensed.stories.tsx
@@ -1289,3 +1289,21 @@ export const TickVariantComparisonDenseData: Story = {
},
},
};
+
+export const SimpleExample: Story = {
+ args: {
+ data: [
+ { label: "A", value: 40 },
+ { label: "B", value: 65 },
+ { label: "C", value: 30 },
+ ],
+ categoryKey: "label",
+ height: 180,
+ theme: "ocean",
+ },
+ render: (args: any) => (
+ <Card style={{ width: "620px", padding: "16px" }}>
+ <AreaChartCondensed {...args} xAxisLabel="Month" yAxisLabel="Sales" />
+ </Card>
+ ),
+};
diff --git a/js/packages/react-ui/src/components/Charts/BarChart/BarChart.tsx b/js/packages/react-ui/src/components/Charts/BarChart/BarChart.tsx
index 3f4c68796..a8ce71796 100644
--- a/js/packages/react-ui/src/components/Charts/BarChart/BarChart.tsx
+++ b/js/packages/react-ui/src/components/Charts/BarChart/BarChart.tsx
@@ -82,7 +82,7 @@ const BarChartComponent = <T extends BarChartData>({
tickVariant = "multiLine",
grid = true,
icons = {},
- radius = BAR_RADIUS,
+ radius,
isAnimationActive = false,
showYAxis = true,
xAxisLabel,
@@ -316,7 +316,7 @@ const BarChartComponent = <T extends BarChartData>({
setHoveredCategory(null);
}, []);
- const { mode } = useTheme();
+ const { mode, theme: userTheme } = useTheme();
const barInternalLineColor = useMemo(() => {
if (mode === "light") {
@@ -325,6 +325,21 @@ const BarChartComponent = <T extends BarChartData>({
return "rgba(0, 0, 0, 0.3)";
}, [mode]);
+ const calculatedRadius = useMemo(() => {
+ let radiusValue: number = BAR_RADIUS;
+
+ if (typeof radius === "number") {
+ radiusValue = radius;
+ } else {
+ const radiusTheme = userTheme.rounded2xs;
+ if (radiusTheme) {
+ radiusValue = typeof radiusTheme === "string" ? parseInt(radiusTheme) : radiusTheme;
+ }
+ }
+
+ return radiusValue;
+ }, [userTheme.rounded2xs, radius]);
+
const onBarsClick = useCallback(
(data: BarClickData) => {
if (data?.activePayload?.length && data.activePayload.length > 10) {
@@ -364,7 +379,7 @@ const BarChartComponent = <T extends BarChartData>({
const customRadius = getRadiusArray(
variant,
- radius,
+ calculatedRadius,
"vertical",
isFirstInStack,
isLastInStack,
@@ -392,7 +407,7 @@ const BarChartComponent = <T extends BarChartData>({
dataKeys,
transformedKeys,
variant,
- radius,
+ calculatedRadius,
isAnimationActive,
barInternalLineColor,
hoveredCategory,
diff --git a/js/packages/react-ui/src/components/Charts/BarChartCondensed/BarChartCondensed.tsx b/js/packages/react-ui/src/components/Charts/BarChartCondensed/BarChartCondensed.tsx
index 44f57db7b..425c74cf9 100644
--- a/js/packages/react-ui/src/components/Charts/BarChartCondensed/BarChartCondensed.tsx
+++ b/js/packages/react-ui/src/components/Charts/BarChartCondensed/BarChartCondensed.tsx
@@ -1,5 +1,5 @@
import clsx from "clsx";
-import React, { useCallback, useMemo, useRef, useState } from "react";
+import React, { useCallback, useEffect, useMemo, useRef, useState } from "react";
import { Bar, BarChart as RechartsBarChart, XAxis, YAxis } from "recharts";
import { useId } from "../../../polyfills";
import { useTheme } from "../../ThemeProvider";
@@ -18,12 +18,14 @@ import {
CondensedXAxisTick,
CondensedXAxisTickVariant,
CustomTooltipContent,
+ DefaultLegend,
LineInBarShape,
YAxisTick,
} from "../shared";
import { LabelTooltipProvider } from "../shared/LabelTooltip/LabelTooltip";
+import { LegendItem } from "../types";
import { getBarStackInfo, getRadiusArray } from "../utils/BarCharts/BarChartsUtils";
-import { get2dChartConfig, getDataKeys } from "../utils/dataUtils";
+import { get2dChartConfig, getDataKeys, getLegendItems } from "../utils/dataUtils";
import { PaletteName, useChartPalette } from "../utils/PalletUtils";
export interface BarChartCondensedProps<T extends BarChartData> {
@@ -38,17 +40,20 @@ export interface BarChartCondensedProps<T extends BarChartData> {
icons?: Partial<Record<keyof T[number], React.ComponentType>>;
isAnimationActive?: boolean;
showYAxis?: boolean;
+ xAxisLabel?: React.ReactNode;
+ yAxisLabel?: React.ReactNode;
+ legend?: boolean;
className?: string;
height?: number;
width?: number;
}
-const BAR_WIDTH = 16;
+const BAR_WIDTH = 12;
const BAR_GAP = 10;
const BAR_CATEGORY_GAP = "20%";
const BAR_INTERNAL_LINE_WIDTH = 1;
const BAR_RADIUS = 4;
-const CHART_HEIGHT = 200;
+const CHART_HEIGHT = 296;
const CHART_CONTAINER_BOTTOM_MARGIN = 10;
const BarChartCondensedComponent = <T extends BarChartData>({
@@ -60,9 +65,12 @@ const BarChartCondensedComponent = <T extends BarChartData>({
tickVariant = "singleLine",
grid = true,
icons = {},
- radius = BAR_RADIUS,
+ radius,
isAnimationActive = false,
showYAxis = true,
+ xAxisLabel,
+ yAxisLabel,
+ legend = true,
className,
height = CHART_HEIGHT,
width,
@@ -77,9 +85,7 @@ const BarChartCondensedComponent = <T extends BarChartData>({
const { angle: calculatedAngle, height: xAxisHeight } = useAutoAngleCalculation(
maxLabelWidth,
- yAxisWidth,
tickVariant === "angled",
- showYAxis,
);
const effectiveHeight = useMemo(() => {
@@ -114,7 +120,22 @@ const BarChartCondensedComponent = <T extends BarChartData>({
[showYAxis],
);
- const { mode } = useTheme();
+ const { mode, theme: userTheme } = useTheme();
+
+ const calculatedRadius = useMemo(() => {
+ let radiusValue: number = BAR_RADIUS;
+
+ if (typeof radius === "number") {
+ radiusValue = radius;
+ } else {
+ const radiusTheme = userTheme.rounded2xs;
+ if (radiusTheme) {
+ radiusValue = typeof radiusTheme === "string" ? parseInt(radiusTheme) : radiusTheme;
+ }
+ }
+
+ return radiusValue;
+ }, [userTheme.rounded2xs, radius]);
const barInternalLineColor = useMemo(() => {
if (mode === "light") {
@@ -124,12 +145,19 @@ const BarChartCondensedComponent = <T extends BarChartData>({
}, [mode]);
const containerRef = useRef<HTMLDivElement>(null);
+ const [containerWidth, setContainerWidth] = useState<number>(0);
const [isSideBarTooltipOpen, setIsSideBarTooltipOpen] = useState(false);
const [sideBarTooltipData, setSideBarTooltipData] = useState<SideBarChartData>({
title: "",
values: [],
});
const [hoveredCategory, setHoveredCategory] = useState<string | number | null>(null);
+ const [isLegendExpanded, setIsLegendExpanded] = useState(false);
+
+ // Use provided width or observed width
+ const effectiveWidth = useMemo(() => {
+ return width ?? containerWidth;
+ }, [width, containerWidth]);
// Handle mouse events for bar hovering
const handleChartMouseMove = useCallback((state: any) => {
@@ -142,6 +170,94 @@ const BarChartCondensedComponent = <T extends BarChartData>({
setHoveredCategory(null);
}, []);
+ // Observe container width for legend
+ useEffect(() => {
+ // Only set up ResizeObserver if width is not provided
+ if (width || !containerRef.current) {
+ return () => {};
+ }
+
+ const resizeObserver = new ResizeObserver((entries) => {
+ // there is only one entry in the entries array because we are observing the chart container
+ for (const entry of entries) {
+ setContainerWidth(entry.contentRect.width);
+ }
+ });
+
+ resizeObserver.observe(containerRef.current);
+
+ return () => {
+ resizeObserver.disconnect();
+ };
+ }, [width]);
+
+ useEffect(() => {
+ setIsLegendExpanded(false);
+ }, [dataKeys]);
+
+ // Memoize legend items creation
+ const legendItems: LegendItem[] = useMemo(() => {
+ if (!legend) {
+ return [];
+ }
+ return getLegendItems(dataKeys, colors, icons);
+ }, [dataKeys, colors, icons, legend]);
+
+ const yAxis = useMemo(() => {
+ if (!showYAxis) {
+ return null;
+ }
+ return (
+ <div className="crayon-bar-chart-condensed-y-axis-container">
+ {/* Y-axis only chart - synchronized with main chart */}
+ <RechartsBarChart
+ key={`y-axis-bar-chart-condensed-${id}`}
+ width={yAxisWidth}
+ height={effectiveHeight}
+ data={data}
+ stackOffset="sign"
+ margin={{
+ top: chartMargin.top,
+ bottom: xAxisHeight + chartMargin.bottom, // this is required to give space for x-axis
+ left: 0,
+ right: 0,
+ }}
+ >
+ <YAxis
+ width={yAxisWidth}
+ tickLine={false}
+ axisLine={false}
+ tick={<YAxisTick setLabelWidth={setLabelWidth} />}
+ />
+ {/* Invisible bars to maintain scale synchronization */}
+ {dataKeys.map((key) => {
+ return (
+ <Bar
+ key={`yaxis-bar-chart-condensed-${key}`}
+ dataKey={key}
+ fill="transparent"
+ stackId={variant === "stacked" ? "a" : undefined}
+ isAnimationActive={false}
+ maxBarSize={0}
+ />
+ );
+ })}
+ </RechartsBarChart>
+ </div>
+ );
+ }, [
+ showYAxis,
+ effectiveHeight,
+ data,
+ dataKeys,
+ variant,
+ id,
+ yAxisWidth,
+ chartMargin,
+ xAxisHeight,
+ setLabelWidth,
+ ]);
+
const barElements = useMemo(() => {
return dataKeys.map((key) => {
const transformedKey = transformedKeys[key];
@@ -164,7 +280,7 @@ const BarChartCondensedComponent = <T extends BarChartData>({
const customRadius = getRadiusArray(
variant,
- radius,
+ calculatedRadius,
"vertical",
isFirstInStack,
isLastInStack,
@@ -192,7 +308,7 @@ const BarChartCondensedComponent = <T extends BarChartData>({
dataKeys,
transformedKeys,
variant,
- radius,
+ calculatedRadius,
isAnimationActive,
barInternalLineColor,
hoveredCategory,
@@ -208,73 +324,84 @@ const BarChartCondensedComponent = <T extends BarChartData>({
setData={setSideBarTooltipData}
>
<div
- ref={containerRef}
- className={clsx("crayon-bar-chart-condensed", className)}
+ className={clsx("crayon-bar-chart-condensed-container", className)}
style={{
- width: width ? `${width}px` : "100%",
- height: `${effectiveHeight}px`,
+ width: width ? `${width}px` : undefined,
}}
>
- <ChartContainer
- config={chartConfig}
- style={{ width: "100%", height: "100%" }}
- rechartsProps={{
- width: "100%",
- height: "100%",
- }}
- >
- <RechartsBarChart
- accessibilityLayer
- key={`bar-chart-condensed-${id}`}
- data={data}
- margin={chartMargin}
- barGap={BAR_GAP}
- barCategoryGap={BAR_CATEGORY_GAP}
- onMouseMove={handleChartMouseMove}
- onMouseLeave={handleChartMouseLeave}
- >
- {grid && cartesianGrid()}
-
- <XAxis
- dataKey={categoryKey as string}
- tickLine={false}
- axisLine={false}
- textAnchor={tickVariant === "angled" ? "end" : "middle"}
- interval="preserveStartEnd"
- minTickGap={5}
- height={xAxisHeight}
- tick={<CondensedXAxisTick />}
- angle={calculatedAngle}
- orientation="bottom"
- padding={{
- left: X_AXIS_PADDING,
- right: X_AXIS_PADDING,
+ {yAxisLabel && (
+ <div className="crayon-bar-chart-condensed-y-axis-label">{yAxisLabel}</div>
+ )}
+ <div className="crayon-bar-chart-condensed-container-inner" ref={containerRef}>
+ {/* Y-axis of the chart */}
+ {yAxis}
+ <div className="crayon-bar-chart-condensed">
+ <ChartContainer
+ config={chartConfig}
+ style={{ width: "100%", height: effectiveHeight }}
+ rechartsProps={{
+ width: "100%",
+ height: "100%",
}}
- />
+ >
+ <RechartsBarChart
+ stackOffset="sign"
+ accessibilityLayer
+ key={`bar-chart-condensed-${id}`}
+ data={data}
+ margin={chartMargin}
+ barGap={BAR_GAP}
+ barCategoryGap={BAR_CATEGORY_GAP}
+ onMouseMove={handleChartMouseMove}
+ onMouseLeave={handleChartMouseLeave}
+ >
+ {grid && cartesianGrid()}
- {showYAxis && (
- <YAxis
- tickLine={false}
- axisLine={false}
- tick={<YAxisTick setLabelWidth={setLabelWidth} />}
- width={yAxisWidth}
- />
- )}
-
- <ChartTooltip
- cursor={{
- fill: "var(--crayon-sunk-fills)",
- stroke: "var(--crayon-stroke-default)",
- opacity: 1,
- strokeWidth: 1,
- }}
- content={<CustomTooltipContent parentRef={containerRef} />}
- offset={10}
- />
+ <XAxis
+ dataKey={categoryKey as string}
+ tickLine={false}
+ axisLine={false}
+ textAnchor={tickVariant === "angled" ? "end" : "middle"}
+ interval="preserveStartEnd"
+ minTickGap={5}
+ height={xAxisHeight}
+ tick={<CondensedXAxisTick />}
+ angle={calculatedAngle}
+ orientation="bottom"
+ padding={{
+ left: X_AXIS_PADDING,
+ right: X_AXIS_PADDING,
+ }}
+ />
+ {/* Y-axis is rendered in the separate synchronized chart */}
+
+ <ChartTooltip
+ cursor={{
+ fill: "var(--crayon-sunk-fills)",
+ stroke: "var(--crayon-stroke-default)",
+ opacity: 1,
+ strokeWidth: 1,
+ }}
+ content={<CustomTooltipContent parentRef={containerRef} />}
+ offset={10}
+ />
- {barElements}
- </RechartsBarChart>
- </ChartContainer>
+ {barElements}
+ </RechartsBarChart>
+ </ChartContainer>
+ </div>
+ </div>
+ {xAxisLabel && (
+ <div className="crayon-bar-chart-condensed-x-axis-label">{xAxisLabel}</div>
+ )}
+ {legend && (
+ <DefaultLegend
+ items={legendItems}
+ containerWidth={effectiveWidth}
+ isExpanded={isLegendExpanded}
+ setIsExpanded={setIsLegendExpanded}
+ />
+ )}
</div>
</SideBarTooltipProvider>
</LabelTooltipProvider>
diff --git a/js/packages/react-ui/src/components/Charts/BarChartCondensed/barChartCondensed.scss b/js/packages/react-ui/src/components/Charts/BarChartCondensed/barChartCondensed.scss
index 4e794e7b8..28e31e355 100644
--- a/js/packages/react-ui/src/components/Charts/BarChartCondensed/barChartCondensed.scss
+++ b/js/packages/react-ui/src/components/Charts/BarChartCondensed/barChartCondensed.scss
@@ -1,8 +1,32 @@
@use "../../../cssUtils" as cssUtils;
+.crayon-bar-chart-condensed-container {
+ display: flex;
+ flex-direction: column;
+}
+
+.crayon-bar-chart-condensed-container-inner {
+ display: flex;
+ width: 100%;
+}
+
+.crayon-bar-chart-condensed-y-axis-container {
+ flex-shrink: 0;
+}
+
.crayon-bar-chart-condensed {
width: 100%;
height: 100%;
- display: flex;
- flex-direction: column;
+
+ &-x-axis-label {
+ @include cssUtils.typography(label, extra-small);
+ color: cssUtils.$secondary-text;
+ text-align: center;
+ }
+
+ &-y-axis-label {
+ @include cssUtils.typography(label, extra-small);
+ color: cssUtils.$secondary-text;
+ padding-bottom: cssUtils.$spacing-s;
+ }
}
diff --git a/js/packages/react-ui/src/components/Charts/BarChartCondensed/stories/barChartCondensed.stories.tsx b/js/packages/react-ui/src/components/Charts/BarChartCondensed/stories/barChartCondensed.stories.tsx
index 69331dc87..e980569ee 100644
--- a/js/packages/react-ui/src/components/Charts/BarChartCondensed/stories/barChartCondensed.stories.tsx
+++ b/js/packages/react-ui/src/components/Charts/BarChartCondensed/stories/barChartCondensed.stories.tsx
@@ -511,7 +511,7 @@ export const DataSize_Small5PointsStacked: Story = {
<div style={{ marginBottom: "8px", fontSize: "12px", color: "#666" }}>
<strong>Test:</strong> Small dataset, 2 series (stacked) | <strong>Data points:</strong> 5
</div>
- <BarChartCondensed {...args} />
+ <BarChartCondensed {...args} xAxisLabel="Month" yAxisLabel="Sales" />
</Card>
),
};
@@ -1381,3 +1381,31 @@ export const TickVariantComparisonDenseData: Story = {
},
},
};
+
+export const SimpleExample: Story = {
+ args: {
+ data: [
+ { label: "A", value: 40 },
+ { label: "B", value: 65 },
+ { label: "C", value: 30 },
+ ],
+ categoryKey: "label",
+ height: 180,
+ theme: "ocean",
+ },
+ render: (args: any) => (
+ <Card style={{ width: "620px", padding: "16px" }}>
+ <div style={{ marginBottom: "8px", fontSize: "14px", color: "#666" }}>
+ Simple BarChartCondensed Example
+ </div>
+ <BarChartCondensed {...args} xAxisLabel="Month" yAxisLabel="Sales" />
+ </Card>
+ ),
+ parameters: {
+ docs: {
+ description: {
+ story: "A simple BarChartCondensed rendering with 3 data points and a single series.",
+ },
+ },
+ },
+};
diff --git a/js/packages/react-ui/src/components/Charts/LineChartCondensed/LineChartCondensed.tsx b/js/packages/react-ui/src/components/Charts/LineChartCondensed/LineChartCondensed.tsx
index d6480a88e..029123828 100644
--- a/js/packages/react-ui/src/components/Charts/LineChartCondensed/LineChartCondensed.tsx
+++ b/js/packages/react-ui/src/components/Charts/LineChartCondensed/LineChartCondensed.tsx
@@ -1,5 +1,5 @@
import clsx from "clsx";
-import React, { useMemo, useRef, useState } from "react";
+import React, { useEffect, useMemo, useRef, useState } from "react";
import { Line, LineChart as RechartsLineChart, XAxis, YAxis } from "recharts";
import { useId } from "../../../polyfills";
import { ChartConfig, ChartContainer, ChartTooltip } from "../Charts";
@@ -18,10 +18,12 @@ import {
CondensedXAxisTick,
CondensedXAxisTickVariant,
CustomTooltipContent,
+ DefaultLegend,
YAxisTick,
} from "../shared";
import { LabelTooltipProvider } from "../shared/LabelTooltip/LabelTooltip";
-import { get2dChartConfig, getDataKeys } from "../utils/dataUtils";
+import { LegendItem } from "../types";
+import { get2dChartConfig, getDataKeys, getLegendItems } from "../utils/dataUtils";
import { PaletteName, useChartPalette } from "../utils/PalletUtils";
export interface LineChartCondensedProps<T extends LineChartData> {
@@ -35,13 +37,16 @@ export interface LineChartCondensedProps<T extends LineChartData> {
icons?: Partial<Record<keyof T[number], React.ComponentType>>;
isAnimationActive?: boolean;
showYAxis?: boolean;
+ xAxisLabel?: React.ReactNode;
+ yAxisLabel?: React.ReactNode;
+ legend?: boolean;
className?: string;
height?: number;
width?: number;
strokeWidth?: number;
}
-const CHART_HEIGHT = 200;
+const CHART_HEIGHT = 296;
const CHART_CONTAINER_BOTTOM_MARGIN = 10;
const LineChartCondensedComponent = <T extends LineChartData>({
@@ -55,6 +60,9 @@ const LineChartCondensedComponent = <T extends LineChartData>({
icons = {},
isAnimationActive = false,
showYAxis = true,
+ xAxisLabel,
+ yAxisLabel,
+ legend = true,
className,
height = CHART_HEIGHT,
width,
@@ -70,9 +78,7 @@ const LineChartCondensedComponent = <T extends LineChartData>({
const { angle: calculatedAngle, height: xAxisHeight } = useAutoAngleCalculation(
maxLabelWidth,
- yAxisWidth,
tickVariant === "angled",
- showYAxis,
);
const effectiveHeight = useMemo(() => {
@@ -80,7 +86,7 @@ const LineChartCondensedComponent = <T extends LineChartData>({
return xAxisHeight + height;
}
return height;
- }, [height, xAxisHeight]);
+ }, [height, xAxisHeight, tickVariant]);
const transformedKeys = useTransformedKeys(dataKeys);
@@ -108,11 +114,104 @@ const LineChartCondensedComponent = <T extends LineChartData>({
);
const containerRef = useRef<HTMLDivElement>(null);
+ const [containerWidth, setContainerWidth] = useState<number>(0);
const [isSideBarTooltipOpen, setIsSideBarTooltipOpen] = useState(false);
const [sideBarTooltipData, setSideBarTooltipData] = useState<SideBarChartData>({
title: "",
values: [],
});
+ const [isLegendExpanded, setIsLegendExpanded] = useState(false);
+
+ // Use provided width or observed width
+ const effectiveWidth = useMemo(() => {
+ return width ?? containerWidth;
+ }, [width, containerWidth]);
+
+ // Observe container width for legend
+ useEffect(() => {
+ // Only set up ResizeObserver if width is not provided
+ if (width || !containerRef.current) {
+ return () => {};
+ }
+
+ const resizeObserver = new ResizeObserver((entries) => {
+ // there is only one entry in the entries array because we are observing the chart container
+ for (const entry of entries) {
+ setContainerWidth(entry.contentRect.width);
+ }
+ });
+
+ resizeObserver.observe(containerRef.current);
+
+ return () => {
+ resizeObserver.disconnect();
+ };
+ }, [width]);
+
+ useEffect(() => {
+ setIsLegendExpanded(false);
+ }, [dataKeys]);
+
+ // Memoize legend items creation
+ const legendItems: LegendItem[] = useMemo(() => {
+ if (!legend) {
+ return [];
+ }
+ return getLegendItems(dataKeys, colors, icons);
+ }, [dataKeys, colors, icons, legend]);
+
+ const yAxis = useMemo(() => {
+ if (!showYAxis) {
+ return null;
+ }
+ return (
+ <div className="crayon-line-chart-condensed-y-axis-container">
+ {/* Y-axis only chart - synchronized with main chart */}
+ <RechartsLineChart
+ key={`y-axis-line-chart-condensed-${id}`}
+ width={yAxisWidth}
+ height={effectiveHeight}
+ data={data}
+ margin={{
+ top: chartMargin.top,
+ bottom: xAxisHeight + chartMargin.bottom, // this is required to give space for x-axis
+ left: 0,
+ right: 0,
+ }}
+ >
+ <YAxis
+ width={yAxisWidth}
+ tickLine={false}
+ axisLine={false}
+ tick={<YAxisTick setLabelWidth={setLabelWidth} />}
+ />
+ {/* Invisible lines to maintain scale synchronization */}
+ {dataKeys.map((key) => {
+ return (
+ <Line
+ key={`yaxis-line-chart-condensed-${key}`}
+ dataKey={key}
+ stroke="transparent"
+ strokeWidth={0}
+ dot={false}
+ isAnimationActive={false}
+ />
+ );
+ })}
+ </RechartsLineChart>
+ </div>
+ );
+ }, [
+ showYAxis,
+ effectiveHeight,
+ data,
+ dataKeys,
+ id,
+ yAxisWidth,
+ chartMargin,
+ xAxisHeight,
+ setLabelWidth,
+ ]);
return (
<LabelTooltipProvider>
@@ -123,78 +222,88 @@ const LineChartCondensedComponent = <T extends LineChartData>({
setData={setSideBarTooltipData}
>
<div
- ref={containerRef}
- className={clsx("crayon-line-chart-condensed", className)}
+ className={clsx("crayon-line-chart-condensed-container", className)}
style={{
- width: width ? `${width}px` : "100%",
- height: `${effectiveHeight}px`,
+ width: width ? `${width}px` : undefined,
}}
>
- <ChartContainer
- config={chartConfig}
- style={{ width: "100%", height: "100%" }}
- rechartsProps={{
- width: "100%",
- height: "100%",
- }}
- >
- <RechartsLineChart
- accessibilityLayer
- key={`line-chart-condensed-${id}`}
- data={data}
- margin={chartMargin}
- >
- {grid && cartesianGrid()}
-
- <XAxis
- dataKey={categoryKey as string}
- tickLine={false}
- axisLine={false}
- textAnchor={tickVariant === "angled" ? "end" : "middle"}
- interval="preserveStartEnd"
- minTickGap={5}
- height={xAxisHeight}
- tick={<CondensedXAxisTick />}
- angle={calculatedAngle}
- orientation="bottom"
- padding={{
- left: X_AXIS_PADDING,
- right: X_AXIS_PADDING,
+ {yAxisLabel && (
+ <div className="crayon-line-chart-condensed-y-axis-label">{yAxisLabel}</div>
+ )}
+ <div className="crayon-line-chart-condensed-container-inner" ref={containerRef}>
+ {/* Y-axis of the chart */}
+ {yAxis}
+ <div className="crayon-line-chart-condensed">
+ <ChartContainer
+ config={chartConfig}
+ style={{ width: "100%", height: effectiveHeight }}
+ rechartsProps={{
+ width: "100%",
+ height: "100%",
}}
- />
+ >
+ <RechartsLineChart
+ accessibilityLayer
+ key={`line-chart-condensed-${id}`}
+ data={data}
+ margin={chartMargin}
+ >
+ {grid && cartesianGrid()}
- {showYAxis && (
- <YAxis
- tickLine={false}
- axisLine={false}
- tick={<YAxisTick setLabelWidth={setLabelWidth} />}
- width={yAxisWidth}
- />
- )}
-
- <ChartTooltip
- content={<CustomTooltipContent parentRef={containerRef} />}
- offset={10}
- />
+ <XAxis
+ dataKey={categoryKey as string}
+ tickLine={false}
+ axisLine={false}
+ textAnchor={tickVariant === "angled" ? "end" : "middle"}
+ interval="preserveStartEnd"
+ minTickGap={5}
+ height={xAxisHeight}
+ tick={<CondensedXAxisTick />}
+ angle={calculatedAngle}
+ orientation="bottom"
+ padding={{
+ left: X_AXIS_PADDING,
+ right: X_AXIS_PADDING,
+ }}
+ />
+ {/* Y-axis is rendered in the separate synchronized chart */}
- {dataKeys.map((key) => {
- const transformedKey = transformedKeys[key];
- const color = `var(--color-${transformedKey})`;
- return (
- <Line
- key={`line-${key}`}
- dataKey={key}
- type={variant}
- stroke={color}
- strokeWidth={strokeWidth}
- dot={false}
- activeDot={<ActiveDot key={`active-dot-${key}-${id}`} />}
- isAnimationActive={isAnimationActive}
+ <ChartTooltip
+ content={<CustomTooltipContent parentRef={containerRef} />}
+ offset={10}
/>
- );
- })}
- </RechartsLineChart>
- </ChartContainer>
+
+ {dataKeys.map((key) => {
+ const transformedKey = transformedKeys[key];
+ const color = `var(--color-${transformedKey})`;
+ return (
+ <Line
+ key={`line-${key}`}
+ dataKey={key}
+ type={variant}
+ stroke={color}
+ strokeWidth={strokeWidth}
+ dot={false}
+ activeDot={<ActiveDot key={`active-dot-${key}-${id}`} />}
+ isAnimationActive={isAnimationActive}
+ />
+ );
+ })}
+ </RechartsLineChart>
+ </ChartContainer>
+ </div>
+ </div>
+ {xAxisLabel && (
+ <div className="crayon-line-chart-condensed-x-axis-label">{xAxisLabel}</div>
+ )}
+ {legend && (
+ <DefaultLegend
+ items={legendItems}
+ containerWidth={effectiveWidth}
+ isExpanded={isLegendExpanded}
+ setIsExpanded={setIsLegendExpanded}
+ />
+ )}
</div>
</SideBarTooltipProvider>
</LabelTooltipProvider>
diff --git a/js/packages/react-ui/src/components/Charts/LineChartCondensed/lineChartCondensed.scss b/js/packages/react-ui/src/components/Charts/LineChartCondensed/lineChartCondensed.scss
index df4381bc1..149316f15 100644
--- a/js/packages/react-ui/src/components/Charts/LineChartCondensed/lineChartCondensed.scss
+++ b/js/packages/react-ui/src/components/Charts/LineChartCondensed/lineChartCondensed.scss
@@ -1,7 +1,32 @@
@use "../../../cssUtils" as cssUtils;
-.crayon-line-chart-condensed {
+.crayon-line-chart-condensed-container {
display: flex;
flex-direction: column;
- position: relative;
+}
+
+.crayon-line-chart-condensed-container-inner {
+ display: flex;
+ width: 100%;
+}
+
+.crayon-line-chart-condensed-y-axis-container {
+ flex-shrink: 0;
+}
+
+.crayon-line-chart-condensed {
+ width: 100%;
+ height: 100%;
+
+ &-x-axis-label {
+ @include cssUtils.typography(label, extra-small);
+ color: cssUtils.$secondary-text;
+ text-align: center;
+ }
+
+ &-y-axis-label {
+ @include cssUtils.typography(label, extra-small);
+ color: cssUtils.$secondary-text;
+ padding-bottom: cssUtils.$spacing-s;
+ }
}
diff --git a/js/packages/react-ui/src/components/Charts/PieChart/PieChart.tsx b/js/packages/react-ui/src/components/Charts/PieChart/PieChart.tsx
index 92523f080..d58aca959 100644
--- a/js/packages/react-ui/src/components/Charts/PieChart/PieChart.tsx
+++ b/js/packages/react-ui/src/components/Charts/PieChart/PieChart.tsx
@@ -1,6 +1,7 @@
import clsx from "clsx";
import { memo, useCallback, useEffect, useMemo, useRef, useState } from "react";
import { Cell, Pie, PieChart as RechartsPieChart } from "recharts";
+import { useTheme } from "../../ThemeProvider/ThemeProvider.js";
import { ChartContainer, ChartTooltip, ChartTooltipContent } from "../Charts.js";
import { useTransformedKeys } from "../hooks/index.js";
import { DefaultLegend } from "../shared/DefaultLegend/DefaultLegend.js";
@@ -13,7 +14,6 @@ import {
calculateTwoLevelChartDimensions,
createAnimationConfig,
createEventHandlers,
- createSectorStyle,
getHoverStyles,
transformDataWithPercentages,
useChartHover,
@@ -47,6 +47,7 @@ export interface PieChartProps<T extends PieChartData> {
const STACKED_LEGEND_BREAKPOINT = 400;
const MIN_CHART_SIZE = 150;
const MAX_CHART_SIZE = 500;
+const CORNER_RADIUS = 0;
const PieChartComponent = <T extends PieChartData>({
data,
@@ -60,7 +61,7 @@ const PieChartComponent = <T extends PieChartData>({
legendVariant = "stacked",
isAnimationActive = true,
appearance = "circular",
- cornerRadius = 0,
+ cornerRadius,
paddingAngle = 0,
onMouseEnter,
onMouseLeave,
@@ -76,6 +77,7 @@ const PieChartComponent = <T extends PieChartData>({
const [hoveredLegendKey, setHoveredLegendKey] = useState<string | null>(null);
const [isLegendExpanded, setIsLegendExpanded] = useState(false);
const { activeIndex, handleMouseEnter, handleMouseLeave } = useChartHover();
+ const { theme: userTheme } = useTheme();
// Determine layout mode based on container width
const isRowLayout =
@@ -154,10 +156,24 @@ const PieChartComponent = <T extends PieChartData>({
[onMouseEnter, onMouseLeave, onClick],
);
- const sectorStyle = useMemo(
- () => createSectorStyle(cornerRadius, variant === "donut" ? 0.5 : paddingAngle),
- [cornerRadius, variant, paddingAngle],
- );
+ const sectorStyle = useMemo(() => {
+ let cornerRadiusValue: number = CORNER_RADIUS;
+
+ if (typeof cornerRadius === "number") {
+ cornerRadiusValue = cornerRadius;
+ } else {
+ const cornerRadiusTheme = userTheme.rounded2xs;
+ if (cornerRadiusTheme) {
+ cornerRadiusValue =
+ typeof cornerRadiusTheme === "string" ? parseInt(cornerRadiusTheme) : cornerRadiusTheme;
+ }
+ }
+
+ return {
+ cornerRadius: cornerRadiusValue,
+ paddingAngle: variant === "donut" ? 0.5 : paddingAngle,
+ };
+ }, [cornerRadius, variant, paddingAngle, userTheme.rounded2xs]);
const colors = useChartPalette({
chartThemeName: theme,
diff --git a/js/packages/react-ui/src/components/Charts/PieChart/utils/PieChartUtils.ts b/js/packages/react-ui/src/components/Charts/PieChart/utils/PieChartUtils.ts
index 71b5a9e48..67d31dfc2 100644
--- a/js/packages/react-ui/src/components/Charts/PieChart/utils/PieChartUtils.ts
+++ b/js/packages/react-ui/src/components/Charts/PieChart/utils/PieChartUtils.ts
@@ -108,7 +108,7 @@ const calculateTwoLevelChartDimensions = (width: number): TwoLevelChartDimension
*/
const getHoverStyles = (index: number, activeIndex: number | null): HoverStyles => {
return {
- opacity: activeIndex === null || activeIndex === index ? 1 : 0.6,
+ opacity: activeIndex === null || activeIndex === index ? 1 : 0.5,
stroke: activeIndex === index ? "#fff" : "none",
strokeWidth: activeIndex === index ? 2 : 0,
};
@@ -205,23 +205,6 @@ const createEventHandlers = (
};
};
-// ==========================================
-// Sector Style Utilities
-// ==========================================
-
-/**
- * Creates sector style configuration
- * @param cornerRadius - Corner radius for sectors
- * @param paddingAngle - Padding angle between sectors
- * @returns Sector style configuration
- */
-const createSectorStyle = (cornerRadius: number = 0, paddingAngle: number = 0) => {
- return {
- cornerRadius,
- paddingAngle,
- };
-};
-
// ==========================================
// Export all utility functions
// ==========================================
@@ -232,7 +215,6 @@ export {
calculateTwoLevelChartDimensions,
createAnimationConfig,
createEventHandlers,
- createSectorStyle,
getHoverStyles,
transformDataWithPercentages,
useChartHover,
diff --git a/js/packages/react-ui/src/components/Charts/constants/CondensedCharts.ts b/js/packages/react-ui/src/components/Charts/constants/CondensedCharts.ts
index 6e4485b47..377fc16c1 100644
--- a/js/packages/react-ui/src/components/Charts/constants/CondensedCharts.ts
+++ b/js/packages/react-ui/src/components/Charts/constants/CondensedCharts.ts
@@ -1,3 +1,3 @@
-export const X_AXIS_PADDING = 10;
-export const MIN_ROTATION_ANGLE = 15;
+export const X_AXIS_PADDING = 20;
+export const MIN_ROTATION_ANGLE = 0;
export const DEFAULT_X_AXIS_HEIGHT = 30;
diff --git a/js/packages/react-ui/src/components/Charts/hooks/useAutoAngleCalculation.ts b/js/packages/react-ui/src/components/Charts/hooks/useAutoAngleCalculation.ts
index 881bd1267..3d1812a46 100644
--- a/js/packages/react-ui/src/components/Charts/hooks/useAutoAngleCalculation.ts
+++ b/js/packages/react-ui/src/components/Charts/hooks/useAutoAngleCalculation.ts
@@ -14,20 +14,17 @@ interface AngleCalculationResult {
*
* Mathematical approach:
* - Hypotenuse = maxLabelWidth (the label length)
- * - Base = X_AXIS_PADDING + yAxisWidth (available horizontal space from left edge to first label)
+ * - Base = X_AXIS_PADDING (available horizontal space from left edge to first label)
* - Height = sqrt(hypotenuse² - base²)
* - Angle = atan(height / base) converted to degrees
*
* @param maxLabelWidth - The maximum width of all labels in pixels
- * @param yAxisWidth - The width of the Y-axis in pixels
* @param enabled - Whether to calculate the angle (typically based on tickVariant)
* @returns Object containing the calculated angle (in degrees) and required height
*/
export const useAutoAngleCalculation = (
maxLabelWidth: number,
- yAxisWidth: number,
enabled: boolean,
- showYAxis: boolean,
): AngleCalculationResult => {
return useMemo(() => {
// If not enabled, return default values for horizontal labels
@@ -41,11 +38,7 @@ export const useAutoAngleCalculation = (
// Calculate the base (horizontal distance from left edge to first label anchor)
let base = 0;
- if (showYAxis) {
- base = X_AXIS_PADDING + yAxisWidth;
- } else {
- base = X_AXIS_PADDING;
- }
+ base = X_AXIS_PADDING;
// The hypotenuse is the maximum label width
const hypotenuse = maxLabelWidth;
@@ -86,5 +79,5 @@ export const useAutoAngleCalculation = (
angle: -finalAngle, // Negative for counter-clockwise rotation
height: Math.max(finalHeight + 16, DEFAULT_X_AXIS_HEIGHT), // Ensure minimum height
};
- }, [maxLabelWidth, yAxisWidth, enabled, showYAxis]);
+ }, [maxLabelWidth, enabled]);
};
diff --git a/js/packages/react-ui/src/components/Charts/shared/CondensedXAxisTick/CondensedXAxisTick.tsx b/js/packages/react-ui/src/components/Charts/shared/CondensedXAxisTick/CondensedXAxisTick.tsx
index 60719de18..4dc93f704 100644
--- a/js/packages/react-ui/src/components/Charts/shared/CondensedXAxisTick/CondensedXAxisTick.tsx
+++ b/js/packages/react-ui/src/components/Charts/shared/CondensedXAxisTick/CondensedXAxisTick.tsx
@@ -9,7 +9,6 @@ interface CondensedXAxisTickProps {
payload?: {
value: any;
};
- fill?: string;
className?: string;
angle?: number;
textAnchor?: string;
@@ -17,7 +16,7 @@ interface CondensedXAxisTickProps {
const CondensedXAxisTick = React.forwardRef<SVGTextElement, CondensedXAxisTickProps>(
(props, ref) => {
- const { x, y, payload, fill, className, angle = 0, textAnchor = "middle" } = props;
+ const { x, y, payload, className, angle = 0, textAnchor = "middle" } = props;
const value = String(payload?.value || "");
@@ -35,7 +34,6 @@ const CondensedXAxisTick = React.forwardRef<SVGTextElement, CondensedXAxisTickPr
x={x}
y={y}
dy={16}
- fill={fill}
textAnchor={textAnchor}
transform={transform}
>
diff --git a/js/packages/react-ui/src/components/Charts/shared/CondensedXAxisTick/condensedXAxisTick.scss b/js/packages/react-ui/src/components/Charts/shared/CondensedXAxisTick/condensedXAxisTick.scss
index d1e626142..be14d455d 100644
--- a/js/packages/react-ui/src/components/Charts/shared/CondensedXAxisTick/condensedXAxisTick.scss
+++ b/js/packages/react-ui/src/components/Charts/shared/CondensedXAxisTick/condensedXAxisTick.scss
@@ -2,10 +2,10 @@
.crayon-chart-condensed-x-axis-tick {
@include cssUtils.typography(label, extra-small);
- color: cssUtils.$secondary-text;
+ fill: cssUtils.$secondary-text;
}
.crayon-chart-condensed-x-axis-tick-angled {
@include cssUtils.typography(label, extra-small);
- color: cssUtils.$secondary-text;
+ fill: cssUtils.$secondary-text;
}
diff --git a/js/packages/react-ui/src/components/Charts/shared/StackedLegend/stackedLegend.scss b/js/packages/react-ui/src/components/Charts/shared/StackedLegend/stackedLegend.scss
index 14636aca0..8ba6df83f 100644
--- a/js/packages/react-ui/src/components/Charts/shared/StackedLegend/stackedLegend.scss
+++ b/js/packages/react-ui/src/components/Charts/shared/StackedLegend/stackedLegend.scss
@@ -155,3 +155,8 @@
.crayon-stacked-legend-separator {
margin: cssUtils.$spacing-2xs 0;
}
+
+.crayon-stacked-legend-header-title {
+ @include cssUtils.typography(label, default);
+ color: cssUtils.$secondary-text;
+}