From dd5919a6db54f197ec0b24cf3c86654c0f9f0d9f Mon Sep 17 00:00:00 2001 From: i-subham Date: Tue, 1 Jul 2025 19:03:54 +0530 Subject: [PATCH 1/4] Refactor piechart and slider component --- .../components/Charts/PieChart/PieChart.tsx | 11 ++- .../stories/RadialChart.stories.tsx | 4 +- .../shared/StackedLegend/StackedLegend.tsx | 11 ++- .../react-ui/src/components/Slider/Slider.tsx | 84 ++++++++++--------- .../Slider/stories/slider.stories.tsx | 82 +++++++++++++++--- 5 files changed, 131 insertions(+), 61 deletions(-) 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 b7a55b9e2..c7facb730 100644 --- a/js/packages/react-ui/src/components/Charts/PieChart/PieChart.tsx +++ b/js/packages/react-ui/src/components/Charts/PieChart/PieChart.tsx @@ -107,8 +107,13 @@ const PieChartComponent = ({ const chartSize = useMemo(() => { let size; if (isRowLayout) { - const chartContainerWidth = (effectiveWidth - 20) / 2; // Subtract gap - size = Math.min(chartContainerWidth, effectiveHeight); + const chartContainerWidth = (effectiveWidth - 20) / 2; + if (appearance === "semiCircular") { + const chartContainerHeight = (effectiveHeight - 20) / 2; + size = Math.min(chartContainerWidth, chartContainerHeight); + } else { + size = Math.min(chartContainerWidth, effectiveHeight); + } } else { size = Math.min(effectiveWidth, effectiveHeight); } @@ -245,6 +250,7 @@ const PieChartComponent = ({ endAngle, onMouseEnter: handleChartMouseEnter, onMouseLeave: handleChartMouseLeave, + cy: appearance === "semiCircular" ? "100%" : "50%", }), [ transformedData, @@ -257,6 +263,7 @@ const PieChartComponent = ({ endAngle, handleChartMouseEnter, handleChartMouseLeave, + appearance, ], ); diff --git a/js/packages/react-ui/src/components/Charts/RadialChart/stories/RadialChart.stories.tsx b/js/packages/react-ui/src/components/Charts/RadialChart/stories/RadialChart.stories.tsx index c0fc1994b..4dbf258c8 100644 --- a/js/packages/react-ui/src/components/Charts/RadialChart/stories/RadialChart.stories.tsx +++ b/js/packages/react-ui/src/components/Charts/RadialChart/stories/RadialChart.stories.tsx @@ -536,9 +536,7 @@ export const LargeDatasetDemo: Story = { Complete breakdown of 15 compensation categories with carousel navigation

- - - +
{ const ITEM_HEIGHT = 36; // Height of each legend item const ITEM_GAP = 2; // Gap between items const LEGEND_ITEM_LIMIT = 6; +const SHOW_MORE_BREAKPOINT = 450; export const StackedLegend = ({ items, @@ -42,7 +43,9 @@ export const StackedLegend = ({ const [showAll, setShowAll] = useState(false); const [isOverflowing, setIsOverflowing] = useState(false); - const isShowMoreLayout = containerWidth !== undefined && items.length > LEGEND_ITEM_LIMIT; + const isShowMoreLayout = + containerWidth !== undefined && + (containerWidth < SHOW_MORE_BREAKPOINT || items.length > LEGEND_ITEM_LIMIT); const handleMouseEnter = (key: string, index: number) => { onItemHover?.(key); @@ -62,7 +65,7 @@ export const StackedLegend = ({ const overflowing = scrollHeight > clientHeight; setIsOverflowing(overflowing); setShowUpButton(scrollTop > 0); - setShowDownButton(scrollTop < scrollHeight - clientHeight - 1); // -1 for rounding errors + setShowDownButton(scrollTop < scrollHeight - clientHeight - 1); } }; @@ -175,7 +178,7 @@ export const StackedLegend = ({
))} - {isShowMoreLayout && !showAll && ( + {isShowMoreLayout && !showAll && items.length > LEGEND_ITEM_LIMIT && (