Skip to content

The Open Standard for Generative UI

Enhance PieChart and RadialChart components (#182)

subham827ecd41971b
diff --git a/js/packages/react-ui/package.json b/js/packages/react-ui/package.json
index a59a3cdf5..d667fdba4 100644
--- a/js/packages/react-ui/package.json
+++ b/js/packages/react-ui/package.json
@@ -2,7 +2,7 @@
"type": "module",
"name": "@crayonai/react-ui",
"license": "MIT",
- "version": "0.8.23",
+ "version": "0.8.24",
"description": "Component library for Generative UI SDK",
"main": "dist/index.js",
"types": "dist/index.d.ts",
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 659679e66..eb474c3af 100644
--- a/js/packages/react-ui/src/components/Charts/PieChart/PieChart.tsx
+++ b/js/packages/react-ui/src/components/Charts/PieChart/PieChart.tsx
@@ -37,6 +37,8 @@ export interface PieChartProps<T extends PieChartData> {
onMouseLeave?: () => void;
onClick?: (data: any, index: number) => void;
className?: string;
+ maxChartSize?: number;
+ minChartSize?: number;
}
const STACKED_LEGEND_BREAKPOINT = 400;
@@ -61,6 +63,8 @@ const PieChartComponent = <T extends PieChartData>({
onMouseLeave,
onClick,
className,
+ maxChartSize = MAX_CHART_SIZE,
+ minChartSize = MIN_CHART_SIZE,
}: PieChartProps<T>) => {
const wrapperRef = useRef<HTMLDivElement>(null);
const [wrapperRect, setWrapperRect] = useState({ width: 0, height: 0 });
@@ -105,12 +109,12 @@ const PieChartComponent = <T extends PieChartData>({
} else {
size = Math.min(effectiveWidth, effectiveHeight);
}
- size = Math.min(size, MAX_CHART_SIZE);
- return Math.max(MIN_CHART_SIZE, size);
+ size = Math.min(size, maxChartSize);
+ return Math.max(minChartSize, size);
}, [effectiveWidth, effectiveHeight, isRowLayout]);
const chartSizeStyle = useMemo(() => ({ width: chartSize, height: chartSize }), [chartSize]);
- const rechartsProps = useMemo(() => ({ width: chartSize, height: chartSize }), [chartSize]);
+ const rechartsProps = useMemo(() => ({ width: "100%", height: "100%" }), []);
// Memoize expensive data transformations and configurations
const transformedData = useMemo(
diff --git a/js/packages/react-ui/src/components/Charts/RadialChart/RadialChart.tsx b/js/packages/react-ui/src/components/Charts/RadialChart/RadialChart.tsx
index e94afd937..02bb8fead 100644
--- a/js/packages/react-ui/src/components/Charts/RadialChart/RadialChart.tsx
+++ b/js/packages/react-ui/src/components/Charts/RadialChart/RadialChart.tsx
@@ -35,6 +35,8 @@ export interface RadialChartProps<T extends RadialChartData> {
onMouseLeave?: () => void;
onClick?: (data: any, index: number) => void;
className?: string;
+ maxChartSize?: number;
+ minChartSize?: number;
}
const STACKED_LEGEND_BREAKPOINT = 400;
@@ -58,6 +60,8 @@ export const RadialChart = <T extends RadialChartData>({
onMouseLeave,
onClick,
className,
+ maxChartSize = MAX_CHART_SIZE,
+ minChartSize = MIN_CHART_SIZE,
}: RadialChartProps<T>) => {
const wrapperRef = useRef<HTMLDivElement>(null);
const [wrapperRect, setWrapperRect] = useState({ width: 0, height: 0 });
@@ -106,8 +110,8 @@ export const RadialChart = <T extends RadialChartData>({
// In a column layout, the chart's size is constrained by the smaller of the total container's width or height.
size = Math.min(effectiveWidth, effectiveHeight);
}
- size = Math.min(size, MAX_CHART_SIZE);
- return Math.max(MIN_CHART_SIZE, size);
+ size = Math.min(size, maxChartSize);
+ return Math.max(minChartSize, size);
}, [effectiveWidth, effectiveHeight, isRowLayout]);
const chartSizeStyle = useMemo(
@@ -120,10 +124,10 @@ export const RadialChart = <T extends RadialChartData>({
const rechartsProps = useMemo(
() => ({
- width: chartSize,
- height: chartSize,
+ width: "100%",
+ height: "100%",
}),
- [chartSize],
+ [],
);
// Calculate chart radii