Skip to content
Open
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
15 changes: 3 additions & 12 deletions packages/react-ui/src/genui-lib/Charts/PieChart.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { defineComponent } from "@openuidev/react-lang";
import React from "react";
import { z } from "zod/v4";
import { PieChart as PieChartComponent } from "../../components/Charts";
import { asArray, buildSliceData } from "../helpers";
import { buildLabeledValueData, buildSliceData } from "../helpers";

export const PieChartSchema = z.object({
labels: z.array(z.string()),
Expand All @@ -17,16 +17,8 @@ export const PieChart = defineComponent({
props: PieChartSchema,
description: "Circular slices; use plucked arrays: PieChart(data.categories, data.values)",
component: ({ props }) => {
const labels = asArray(props.labels) as string[];
const values = asArray(props.values) as number[];

// New format: labels[] + values[]
if (labels.length > 0 && values.length > 0) {
const data = labels.map((cat, i) => ({
category: cat,
value: typeof values[i] === "number" ? values[i] : 0,
}));
if (!data.length) return null;
const data = buildLabeledValueData(props.labels, props.values);
if (data.length > 0) {
return React.createElement(PieChartComponent, {
data,
categoryKey: "category",
Expand All @@ -36,7 +28,6 @@ export const PieChart = defineComponent({
});
}

// Legacy fallback: Slice[] objects (backwards compat)
const sliceData = buildSliceData(props.labels);
if (sliceData.length) {
return React.createElement(PieChartComponent, {
Expand Down
13 changes: 3 additions & 10 deletions packages/react-ui/src/genui-lib/Charts/RadialChart.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { defineComponent } from "@openuidev/react-lang";
import React from "react";
import { z } from "zod/v4";
import { RadialChart as RadialChartComponent } from "../../components/Charts";
import { asArray, buildSliceData } from "../helpers";
import { buildLabeledValueData, buildSliceData } from "../helpers";

export const RadialChartSchema = z.object({
labels: z.array(z.string()),
Expand All @@ -16,15 +16,8 @@ export const RadialChart = defineComponent({
props: RadialChartSchema,
description: "Radial bars; use plucked arrays: RadialChart(data.categories, data.values)",
component: ({ props }) => {
const labels = asArray(props.labels) as string[];
const values = asArray(props.values) as number[];

if (labels.length > 0 && values.length > 0) {
const data = labels.map((cat, i) => ({
category: cat,
value: typeof values[i] === "number" ? values[i] : 0,
}));
if (!data.length) return null;
const data = buildLabeledValueData(props.labels, props.values);
if (data.length > 0) {
return React.createElement(RadialChartComponent, {
data,
categoryKey: "category",
Expand Down
21 changes: 2 additions & 19 deletions packages/react-ui/src/genui-lib/Charts/ScatterChart.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { defineComponent } from "@openuidev/react-lang";
import React from "react";
import { z } from "zod/v4";
import { ScatterChart as ScatterChartComponent } from "../../components/Charts";
import { asArray, hasAllProps } from "../helpers";
import { buildScatterChartData, hasAllProps } from "../helpers";
import { ScatterSeriesSchema } from "./ScatterSeries";

export const ScatterChartSchema = z.object({
Expand All @@ -13,30 +13,13 @@ export const ScatterChartSchema = z.object({
yLabel: z.string().optional(),
});

const unwrap = (node: any) => (node?.type === "element" ? node.props : node);

export const ScatterChart = defineComponent({
name: "ScatterChart",
props: ScatterChartSchema,
description: "X/Y scatter plot; use for correlations, distributions, and clustering",
component: ({ props }) => {
if (!hasAllProps(props as Record<string, unknown>, "datasets")) return null;
const rawDatasets = asArray((props as any).datasets);
const data = rawDatasets.map((ds: any) => {
const dsProps = unwrap(ds);
const rawPoints = asArray(dsProps?.points);
return {
name: (dsProps?.name ?? "") as string,
data: rawPoints.map((pt: any) => {
const ptProps = unwrap(pt);
return {
x: Number(ptProps?.x),
y: Number(ptProps?.y),
...(ptProps?.z != null ? { z: Number(ptProps.z) } : {}),
};
}),
};
});
const data = buildScatterChartData((props as Record<string, unknown>).datasets);
if (!data.length) return null;
return React.createElement(ScatterChartComponent, {
data,
Expand Down
13 changes: 3 additions & 10 deletions packages/react-ui/src/genui-lib/Charts/SingleStackedBarChart.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { defineComponent } from "@openuidev/react-lang";
import React from "react";
import { z } from "zod/v4";
import { SingleStackedBar as SingleStackedBarChartComponent } from "../../components/Charts";
import { asArray, buildSliceData } from "../helpers";
import { buildLabeledValueData, buildSliceData } from "../helpers";

export const SingleStackedBarChartSchema = z.object({
labels: z.array(z.string()),
Expand All @@ -17,15 +17,8 @@ export const SingleStackedBarChart = defineComponent({
description:
"Single horizontal stacked bar; use plucked arrays: SingleStackedBarChart(data.categories, data.values)",
component: ({ props }) => {
const labels = asArray(props.labels) as string[];
const values = asArray(props.values) as number[];

if (labels.length > 0 && values.length > 0) {
const data = labels.map((cat, i) => ({
category: cat,
value: typeof values[i] === "number" ? values[i] : 0,
}));
if (!data.length) return null;
const data = buildLabeledValueData(props.labels, props.values);
if (data.length > 0) {
return React.createElement(SingleStackedBarChartComponent, {
data,
categoryKey: "category",
Expand Down
Loading