@object-ui/plugin-charts 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,16 @@
1
+ import { ChartConfig } from './ChartContainerImpl';
2
+ export interface AdvancedChartImplProps {
3
+ chartType?: 'bar' | 'line' | 'area' | 'pie';
4
+ data?: Array<Record<string, any>>;
5
+ config?: ChartConfig;
6
+ xAxisKey?: string;
7
+ series?: Array<{
8
+ dataKey: string;
9
+ }>;
10
+ className?: string;
11
+ }
12
+ /**
13
+ * AdvancedChartImpl - The heavy implementation that imports Recharts with full features
14
+ * This component is lazy-loaded to avoid including Recharts in the initial bundle
15
+ */
16
+ export default function AdvancedChartImpl({ chartType, data, config, xAxisKey, series, className, }: AdvancedChartImplProps): import("react/jsx-runtime").JSX.Element;
@@ -0,0 +1,31 @@
1
+ import { ResponsiveContainer, Tooltip, Legend } from 'recharts';
2
+ import * as React from "react";
3
+ declare const THEMES: {
4
+ readonly light: "";
5
+ readonly dark: ".dark";
6
+ };
7
+ export type ChartConfig = {
8
+ [k in string]: {
9
+ label?: React.ReactNode;
10
+ icon?: React.ComponentType;
11
+ } & ({
12
+ color?: string;
13
+ theme?: never;
14
+ } | {
15
+ color?: never;
16
+ theme: Record<keyof typeof THEMES, string>;
17
+ });
18
+ };
19
+ declare function ChartContainer({ id, className, children, config, ...props }: React.ComponentProps<"div"> & {
20
+ config: ChartConfig;
21
+ children: React.ComponentProps<typeof ResponsiveContainer>["children"];
22
+ }): import("react/jsx-runtime").JSX.Element;
23
+ declare const ChartStyle: ({ id, config }: {
24
+ id: string;
25
+ config: ChartConfig;
26
+ }) => import("react/jsx-runtime").JSX.Element | null;
27
+ declare const ChartTooltip: typeof Tooltip;
28
+ declare function ChartTooltipContent({ active, payload, className, indicator, hideLabel, hideIndicator, label, labelFormatter, labelClassName, formatter, color, nameKey, labelKey, }: any): import("react/jsx-runtime").JSX.Element | null;
29
+ declare const ChartLegend: typeof Legend;
30
+ declare function ChartLegendContent({ className, hideIcon, payload, verticalAlign, nameKey, }: any): import("react/jsx-runtime").JSX.Element | null;
31
+ export { ChartContainer, ChartTooltip, ChartTooltipContent, ChartLegend, ChartLegendContent, ChartStyle, };
@@ -0,0 +1,13 @@
1
+ export interface ChartImplProps {
2
+ data?: Array<Record<string, any>>;
3
+ dataKey?: string;
4
+ xAxisKey?: string;
5
+ height?: number;
6
+ className?: string;
7
+ color?: string;
8
+ }
9
+ /**
10
+ * ChartImpl - The heavy implementation that imports Recharts
11
+ * This component is lazy-loaded to avoid including Recharts in the initial bundle
12
+ */
13
+ export default function ChartImpl({ data, dataKey, xAxisKey, height, className, color, }: ChartImplProps): import("react/jsx-runtime").JSX.Element;
@@ -0,0 +1,42 @@
1
+ import { default as React } from 'react';
2
+ export type { BarChartSchema } from './types';
3
+ export interface ChartBarRendererProps {
4
+ schema: {
5
+ type: string;
6
+ id?: string;
7
+ className?: string;
8
+ data?: Array<Record<string, any>>;
9
+ dataKey?: string;
10
+ xAxisKey?: string;
11
+ height?: number;
12
+ color?: string;
13
+ };
14
+ }
15
+ /**
16
+ * ChartBarRenderer - The public API for the bar chart component
17
+ * This wrapper handles lazy loading internally using React.Suspense
18
+ */
19
+ export declare const ChartBarRenderer: React.FC<ChartBarRendererProps>;
20
+ export interface ChartRendererProps {
21
+ schema: {
22
+ type: string;
23
+ id?: string;
24
+ className?: string;
25
+ chartType?: 'bar' | 'line' | 'area';
26
+ data?: Array<Record<string, any>>;
27
+ config?: Record<string, any>;
28
+ xAxisKey?: string;
29
+ series?: Array<{
30
+ dataKey: string;
31
+ }>;
32
+ };
33
+ }
34
+ /**
35
+ * ChartRenderer - The public API for the advanced chart component
36
+ * Supports multiple chart types (bar, line, area) with full configuration
37
+ */
38
+ export declare const ChartRenderer: React.FC<ChartRendererProps>;
39
+ export declare const chartComponents: {
40
+ 'chart-bar': React.FC<ChartBarRendererProps>;
41
+ chart: React.FC<ChartRendererProps>;
42
+ };
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,47 @@
1
+ import { BaseSchema } from '@object-ui/types';
2
+ /**
3
+ * Bar Chart component schema.
4
+ * Renders a bar chart using Recharts library.
5
+ *
6
+ * @example
7
+ * ```typescript
8
+ * import type { BarChartSchema } from '@object-ui/plugin-charts';
9
+ *
10
+ * const chartSchema: BarChartSchema = {
11
+ * type: 'chart-bar',
12
+ * data: [
13
+ * { name: 'Jan', value: 400 },
14
+ * { name: 'Feb', value: 300 }
15
+ * ],
16
+ * dataKey: 'value',
17
+ * xAxisKey: 'name'
18
+ * }
19
+ * ```
20
+ */
21
+ export interface BarChartSchema extends BaseSchema {
22
+ type: 'chart-bar';
23
+ /**
24
+ * Array of data points to display in the chart.
25
+ */
26
+ data?: Array<Record<string, any>>;
27
+ /**
28
+ * Key in the data object for the Y-axis values.
29
+ * @default 'value'
30
+ */
31
+ dataKey?: string;
32
+ /**
33
+ * Key in the data object for the X-axis labels.
34
+ * @default 'name'
35
+ */
36
+ xAxisKey?: string;
37
+ /**
38
+ * Height of the chart in pixels.
39
+ * @default 400
40
+ */
41
+ height?: number;
42
+ /**
43
+ * Color of the bars.
44
+ * @default '#8884d8'
45
+ */
46
+ color?: string;
47
+ }
package/package.json ADDED
@@ -0,0 +1,42 @@
1
+ {
2
+ "name": "@object-ui/plugin-charts",
3
+ "version": "0.3.0",
4
+ "type": "module",
5
+ "license": "MIT",
6
+ "main": "dist/index.umd.cjs",
7
+ "module": "dist/index.js",
8
+ "types": "dist/index.d.ts",
9
+ "exports": {
10
+ ".": {
11
+ "types": "./dist/index.d.ts",
12
+ "import": "./dist/index.js",
13
+ "require": "./dist/index.umd.cjs"
14
+ }
15
+ },
16
+ "dependencies": {
17
+ "recharts": "^2.15.0",
18
+ "@object-ui/components": "0.3.0",
19
+ "@object-ui/core": "0.3.0",
20
+ "@object-ui/react": "0.3.0",
21
+ "@object-ui/types": "0.3.0"
22
+ },
23
+ "peerDependencies": {
24
+ "react": "^18.0.0 || ^19.0.0",
25
+ "react-dom": "^18.0.0 || ^19.0.0"
26
+ },
27
+ "devDependencies": {
28
+ "@types/react": "^18.3.12",
29
+ "@types/react-dom": "^18.3.1",
30
+ "@vitejs/plugin-react": "^4.2.1",
31
+ "typescript": "^5.9.3",
32
+ "vite": "^7.3.1",
33
+ "vite-plugin-dts": "^4.5.4"
34
+ },
35
+ "scripts": {
36
+ "build": "vite build",
37
+ "test": "vitest run",
38
+ "test:watch": "vitest",
39
+ "type-check": "tsc --noEmit",
40
+ "lint": "eslint ."
41
+ }
42
+ }
@@ -0,0 +1,162 @@
1
+ import * as React from "react"
2
+ import {
3
+ Bar,
4
+ BarChart,
5
+ Line,
6
+ LineChart,
7
+ Area,
8
+ AreaChart,
9
+ Pie,
10
+ PieChart,
11
+ Cell,
12
+ XAxis,
13
+ YAxis,
14
+ CartesianGrid,
15
+ } from 'recharts';
16
+ import {
17
+ ChartContainer,
18
+ ChartTooltip,
19
+ ChartTooltipContent,
20
+ ChartLegend,
21
+ ChartLegendContent,
22
+ ChartConfig
23
+ } from './ChartContainerImpl';
24
+
25
+ // Default color fallback for chart series
26
+ const DEFAULT_CHART_COLOR = 'hsl(var(--primary))';
27
+
28
+ // Simple color map for Tailwind names (Mock - ideal would be computed styles)
29
+ const TW_COLORS: Record<string, string> = {
30
+ slate: '#64748b',
31
+ gray: '#6b7280',
32
+ zinc: '#71717a',
33
+ neutral: '#737373',
34
+ stone: '#78716c',
35
+ red: '#ef4444',
36
+ orange: '#f97316',
37
+ amber: '#f59e0b',
38
+ yellow: '#eab308',
39
+ lime: '#84cc16',
40
+ green: '#22c55e',
41
+ emerald: '#10b981',
42
+ teal: '#14b8a6',
43
+ cyan: '#06b6d4',
44
+ sky: '#0ea5e9',
45
+ blue: '#3b82f6',
46
+ indigo: '#6366f1',
47
+ violet: '#8b5cf6',
48
+ purple: '#a855f7',
49
+ fuchsia: '#d946ef',
50
+ pink: '#ec4899',
51
+ rose: '#f43f5e',
52
+ };
53
+
54
+ const resolveColor = (color: string) => TW_COLORS[color] || color;
55
+
56
+ export interface AdvancedChartImplProps {
57
+ chartType?: 'bar' | 'line' | 'area' | 'pie';
58
+ data?: Array<Record<string, any>>;
59
+ config?: ChartConfig;
60
+ xAxisKey?: string;
61
+ series?: Array<{ dataKey: string }>;
62
+ className?: string;
63
+ }
64
+
65
+ /**
66
+ * AdvancedChartImpl - The heavy implementation that imports Recharts with full features
67
+ * This component is lazy-loaded to avoid including Recharts in the initial bundle
68
+ */
69
+ export default function AdvancedChartImpl({
70
+ chartType = 'bar',
71
+ data = [],
72
+ config = {},
73
+ xAxisKey = 'name',
74
+ series = [],
75
+ className = '',
76
+ }: AdvancedChartImplProps) {
77
+ const ChartComponent = {
78
+ bar: BarChart,
79
+ line: LineChart,
80
+ area: AreaChart,
81
+ pie: PieChart,
82
+ }[chartType] || BarChart;
83
+
84
+ console.log('📈 Rendering Chart:', { chartType, dataLength: data.length, config, series, xAxisKey });
85
+
86
+ if (chartType === 'pie') {
87
+ return (
88
+ <ChartContainer config={config} className={className}>
89
+ <PieChart>
90
+ <ChartTooltip cursor={false} content={<ChartTooltipContent hideLabel />} />
91
+ <Pie
92
+ data={data}
93
+ dataKey={series[0]?.dataKey || 'value'}
94
+ nameKey={xAxisKey || 'name'}
95
+ innerRadius={60}
96
+ strokeWidth={5}
97
+ paddingAngle={2}
98
+ outerRadius={80}
99
+ >
100
+ {data.map((entry, index) => {
101
+ // 1. Try config by nameKey (category)
102
+ let c = config[entry[xAxisKey]]?.color;
103
+
104
+ // 2. Try series config (if only 1 series defined with color list, logic fails here usually)
105
+ if (!c) {
106
+ // Fallback: If 'colors' array was passed in schema, my adapter put it in config[seriesKey]?
107
+ // Actually my adapter logic in index.tsx was: config[seriesKey].color = colors[idx]
108
+ // But here we are iterating DATA items, not SERIES.
109
+ // So we need a cycling palette.
110
+ // Let's assume the user didn't provide per-category config here, so we cycle default colors.
111
+ const palette = [
112
+ 'hsl(var(--chart-1))',
113
+ 'hsl(var(--chart-2))',
114
+ 'hsl(var(--chart-3))',
115
+ 'hsl(var(--chart-4))',
116
+ 'hsl(var(--chart-5))'
117
+ ];
118
+ // Check if we can get colors from the first series config?
119
+ // No, let's just use the palette or resolveColor from entry if provided in data.
120
+ c = palette[index % palette.length];
121
+ }
122
+
123
+ return <Cell key={`cell-${index}`} fill={resolveColor(c)} />;
124
+ })}
125
+ </Pie>
126
+ <ChartLegend content={<ChartLegendContent nameKey={xAxisKey} />} />
127
+ </PieChart>
128
+ </ChartContainer>
129
+ );
130
+ }
131
+
132
+ return (
133
+ <ChartContainer config={config} className={className}>
134
+ <ChartComponent data={data}>
135
+ <CartesianGrid vertical={false} />
136
+ <XAxis
137
+ dataKey={xAxisKey}
138
+ tickLine={false}
139
+ tickMargin={10}
140
+ axisLine={false}
141
+ tickFormatter={(value) => (value && typeof value === 'string') ? value.slice(0, 3) : value}
142
+ />
143
+ <ChartTooltip content={<ChartTooltipContent />} />
144
+ <ChartLegend content={<ChartLegendContent />} />
145
+ {series.map((s: any) => {
146
+ const color = resolveColor(config[s.dataKey]?.color || DEFAULT_CHART_COLOR);
147
+
148
+ if (chartType === 'bar') {
149
+ return <Bar key={s.dataKey} dataKey={s.dataKey} fill={color} radius={4} />;
150
+ }
151
+ if (chartType === 'line') {
152
+ return <Line key={s.dataKey} type="monotone" dataKey={s.dataKey} stroke={color} strokeWidth={2} dot={false} />;
153
+ }
154
+ if (chartType === 'area') {
155
+ return <Area key={s.dataKey} type="monotone" dataKey={s.dataKey} fill={color} stroke={color} fillOpacity={0.4} />;
156
+ }
157
+ return null;
158
+ })}
159
+ </ChartComponent>
160
+ </ChartContainer>
161
+ );
162
+ }