@coral-ai/charts 0.4.1 → 3.8.1

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.
package/dist/index.d.ts CHANGED
@@ -1,2 +1,60 @@
1
+ import * as react_jsx_runtime from 'react/jsx-runtime';
2
+ import { ReactNode } from 'react';
1
3
 
2
- export { }
4
+ /**
5
+ * Declarative chart spec emitted by an agent's `render_chart` tool call or
6
+ * yielded as a streaming chunk. Keep this minimal — chart components in this
7
+ * package translate the spec into recharts under the hood.
8
+ */
9
+ type CoralChartKind = "bar" | "line";
10
+ type CoralChartSeries = {
11
+ /** Key into each `data` row that holds this series' numeric value. */
12
+ dataKey: string;
13
+ /** Display label shown in the legend + tooltip. */
14
+ label: string;
15
+ };
16
+ type CoralChartSpec = {
17
+ kind: CoralChartKind;
18
+ title: string;
19
+ /** Key into each `data` row that supplies the x-axis label. */
20
+ xKey: string;
21
+ series: CoralChartSeries[];
22
+ /** Each row: `{ [xKey]: string|number, [dataKey of each series]: number }`. */
23
+ data: Array<Record<string, string | number>>;
24
+ };
25
+
26
+ /**
27
+ * Default color palette used by built-in chart components. Designed to read
28
+ * cleanly against the Coral neutral surfaces in both light and dark themes.
29
+ * Override by passing `colors` to any chart, or by editing this list to align
30
+ * a project to a different brand palette.
31
+ */
32
+ declare const CORAL_CHART_PALETTE: string[];
33
+ declare function pickColor(index: number, palette?: readonly string[]): string;
34
+
35
+ declare function ChartFrame({ title, children, }: {
36
+ title: string;
37
+ children: ReactNode;
38
+ }): react_jsx_runtime.JSX.Element;
39
+
40
+ type CoralBarChartProps = {
41
+ spec: CoralChartSpec;
42
+ /** Override the default palette. */
43
+ colors?: readonly string[];
44
+ };
45
+ declare function CoralBarChart({ spec, colors, }: CoralBarChartProps): react_jsx_runtime.JSX.Element;
46
+
47
+ type CoralLineChartProps = {
48
+ spec: CoralChartSpec;
49
+ /** Override the default palette. */
50
+ colors?: readonly string[];
51
+ };
52
+ declare function CoralLineChart({ spec, colors, }: CoralLineChartProps): react_jsx_runtime.JSX.Element;
53
+
54
+ type CoralChartProps = {
55
+ spec: CoralChartSpec;
56
+ colors?: readonly string[];
57
+ };
58
+ declare function CoralChart({ spec, colors }: CoralChartProps): react_jsx_runtime.JSX.Element;
59
+
60
+ export { CORAL_CHART_PALETTE, ChartFrame, CoralBarChart, type CoralBarChartProps, CoralChart, type CoralChartKind, type CoralChartProps, type CoralChartSeries, type CoralChartSpec, CoralLineChart, type CoralLineChartProps, pickColor };
package/dist/index.js CHANGED
@@ -1 +1,128 @@
1
+ // src/palette.ts
2
+ var CORAL_CHART_PALETTE = [
3
+ "#7287ff",
4
+ "#34c6a3",
5
+ "#f5a524",
6
+ "#e85d75",
7
+ "#9b6ad8",
8
+ "#4ab8d9"
9
+ ];
10
+ function pickColor(index, palette = CORAL_CHART_PALETTE) {
11
+ return palette[index % palette.length];
12
+ }
13
+
14
+ // src/ChartFrame.tsx
15
+ import { jsx, jsxs } from "react/jsx-runtime";
16
+ var frameStyle = {
17
+ margin: "12px 0",
18
+ padding: 12,
19
+ border: "1px solid var(--colorNeutralStroke2, #e0e0e0)",
20
+ borderRadius: 8
21
+ };
22
+ var titleStyle = {
23
+ fontWeight: 600,
24
+ marginBottom: 8
25
+ };
26
+ var bodyStyle = {
27
+ width: "100%",
28
+ height: 240
29
+ };
30
+ function ChartFrame({
31
+ title,
32
+ children
33
+ }) {
34
+ return /* @__PURE__ */ jsxs("div", { style: frameStyle, children: [
35
+ /* @__PURE__ */ jsx("div", { style: titleStyle, children: title }),
36
+ /* @__PURE__ */ jsx("div", { style: bodyStyle, children })
37
+ ] });
38
+ }
39
+
40
+ // src/CoralBarChart.tsx
41
+ import {
42
+ Bar,
43
+ BarChart,
44
+ CartesianGrid,
45
+ Legend,
46
+ ResponsiveContainer,
47
+ Tooltip,
48
+ XAxis,
49
+ YAxis
50
+ } from "recharts";
51
+ import { jsx as jsx2, jsxs as jsxs2 } from "react/jsx-runtime";
52
+ function CoralBarChart({
53
+ spec,
54
+ colors = CORAL_CHART_PALETTE
55
+ }) {
56
+ return /* @__PURE__ */ jsx2(ChartFrame, { title: spec.title, children: /* @__PURE__ */ jsx2(ResponsiveContainer, { children: /* @__PURE__ */ jsxs2(BarChart, { data: spec.data, children: [
57
+ /* @__PURE__ */ jsx2(CartesianGrid, { strokeDasharray: "3 3" }),
58
+ /* @__PURE__ */ jsx2(XAxis, { dataKey: spec.xKey }),
59
+ /* @__PURE__ */ jsx2(YAxis, {}),
60
+ /* @__PURE__ */ jsx2(Tooltip, {}),
61
+ /* @__PURE__ */ jsx2(Legend, {}),
62
+ spec.series.map((s, i) => /* @__PURE__ */ jsx2(
63
+ Bar,
64
+ {
65
+ dataKey: s.dataKey,
66
+ name: s.label,
67
+ fill: pickColor(i, colors)
68
+ },
69
+ s.dataKey
70
+ ))
71
+ ] }) }) });
72
+ }
73
+
74
+ // src/CoralLineChart.tsx
75
+ import {
76
+ CartesianGrid as CartesianGrid2,
77
+ Legend as Legend2,
78
+ Line,
79
+ LineChart,
80
+ ResponsiveContainer as ResponsiveContainer2,
81
+ Tooltip as Tooltip2,
82
+ XAxis as XAxis2,
83
+ YAxis as YAxis2
84
+ } from "recharts";
85
+ import { jsx as jsx3, jsxs as jsxs3 } from "react/jsx-runtime";
86
+ function CoralLineChart({
87
+ spec,
88
+ colors = CORAL_CHART_PALETTE
89
+ }) {
90
+ return /* @__PURE__ */ jsx3(ChartFrame, { title: spec.title, children: /* @__PURE__ */ jsx3(ResponsiveContainer2, { children: /* @__PURE__ */ jsxs3(LineChart, { data: spec.data, children: [
91
+ /* @__PURE__ */ jsx3(CartesianGrid2, { strokeDasharray: "3 3" }),
92
+ /* @__PURE__ */ jsx3(XAxis2, { dataKey: spec.xKey }),
93
+ /* @__PURE__ */ jsx3(YAxis2, {}),
94
+ /* @__PURE__ */ jsx3(Tooltip2, {}),
95
+ /* @__PURE__ */ jsx3(Legend2, {}),
96
+ spec.series.map((s, i) => /* @__PURE__ */ jsx3(
97
+ Line,
98
+ {
99
+ type: "monotone",
100
+ dataKey: s.dataKey,
101
+ name: s.label,
102
+ stroke: pickColor(i, colors)
103
+ },
104
+ s.dataKey
105
+ ))
106
+ ] }) }) });
107
+ }
108
+
109
+ // src/CoralChart.tsx
110
+ import { jsx as jsx4 } from "react/jsx-runtime";
111
+ function CoralChart({ spec, colors }) {
112
+ switch (spec.kind) {
113
+ case "line":
114
+ return /* @__PURE__ */ jsx4(CoralLineChart, { spec, colors });
115
+ case "bar":
116
+ default:
117
+ return /* @__PURE__ */ jsx4(CoralBarChart, { spec, colors });
118
+ }
119
+ }
120
+ export {
121
+ CORAL_CHART_PALETTE,
122
+ ChartFrame,
123
+ CoralBarChart,
124
+ CoralChart,
125
+ CoralLineChart,
126
+ pickColor
127
+ };
1
128
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
1
+ {"version":3,"sources":["../src/palette.ts","../src/ChartFrame.tsx","../src/CoralBarChart.tsx","../src/CoralLineChart.tsx","../src/CoralChart.tsx"],"sourcesContent":["/**\n * Default color palette used by built-in chart components. Designed to read\n * cleanly against the Coral neutral surfaces in both light and dark themes.\n * Override by passing `colors` to any chart, or by editing this list to align\n * a project to a different brand palette.\n */\nexport const CORAL_CHART_PALETTE = [\n \"#7287ff\",\n \"#34c6a3\",\n \"#f5a524\",\n \"#e85d75\",\n \"#9b6ad8\",\n \"#4ab8d9\",\n];\n\nexport function pickColor(index: number, palette: readonly string[] = CORAL_CHART_PALETTE): string {\n return palette[index % palette.length];\n}\n","// Shared visual frame around any chart kind: titled bordered card with a\n// fixed-height body that hosts the recharts ResponsiveContainer.\n\nimport { ReactNode } from \"react\";\n\nconst frameStyle: React.CSSProperties = {\n margin: \"12px 0\",\n padding: 12,\n border: \"1px solid var(--colorNeutralStroke2, #e0e0e0)\",\n borderRadius: 8,\n};\n\nconst titleStyle: React.CSSProperties = {\n fontWeight: 600,\n marginBottom: 8,\n};\n\nconst bodyStyle: React.CSSProperties = {\n width: \"100%\",\n height: 240,\n};\n\nexport function ChartFrame({\n title,\n children,\n}: {\n title: string;\n children: ReactNode;\n}) {\n return (\n <div style={frameStyle}>\n <div style={titleStyle}>{title}</div>\n <div style={bodyStyle}>{children}</div>\n </div>\n );\n}\n","// Coral-styled bar chart. Wraps recharts so consumers don't import recharts\n// directly — keeps the underlying library swappable and the public API tiny.\n\nimport {\n Bar,\n BarChart,\n CartesianGrid,\n Legend,\n ResponsiveContainer,\n Tooltip,\n XAxis,\n YAxis,\n} from \"recharts\";\nimport { ChartFrame } from \"./ChartFrame\";\nimport { CORAL_CHART_PALETTE, pickColor } from \"./palette\";\nimport type { CoralChartSpec } from \"./types\";\n\nexport type CoralBarChartProps = {\n spec: CoralChartSpec;\n /** Override the default palette. */\n colors?: readonly string[];\n};\n\nexport function CoralBarChart({\n spec,\n colors = CORAL_CHART_PALETTE,\n}: CoralBarChartProps) {\n return (\n <ChartFrame title={spec.title}>\n <ResponsiveContainer>\n <BarChart data={spec.data}>\n <CartesianGrid strokeDasharray=\"3 3\" />\n <XAxis dataKey={spec.xKey} />\n <YAxis />\n <Tooltip />\n <Legend />\n {spec.series.map((s, i) => (\n <Bar\n key={s.dataKey}\n dataKey={s.dataKey}\n name={s.label}\n fill={pickColor(i, colors)}\n />\n ))}\n </BarChart>\n </ResponsiveContainer>\n </ChartFrame>\n );\n}\n","// Coral-styled line chart. Wraps recharts so consumers don't import recharts\n// directly — keeps the underlying library swappable and the public API tiny.\n\nimport {\n CartesianGrid,\n Legend,\n Line,\n LineChart,\n ResponsiveContainer,\n Tooltip,\n XAxis,\n YAxis,\n} from \"recharts\";\nimport { ChartFrame } from \"./ChartFrame\";\nimport { CORAL_CHART_PALETTE, pickColor } from \"./palette\";\nimport type { CoralChartSpec } from \"./types\";\n\nexport type CoralLineChartProps = {\n spec: CoralChartSpec;\n /** Override the default palette. */\n colors?: readonly string[];\n};\n\nexport function CoralLineChart({\n spec,\n colors = CORAL_CHART_PALETTE,\n}: CoralLineChartProps) {\n return (\n <ChartFrame title={spec.title}>\n <ResponsiveContainer>\n <LineChart data={spec.data}>\n <CartesianGrid strokeDasharray=\"3 3\" />\n <XAxis dataKey={spec.xKey} />\n <YAxis />\n <Tooltip />\n <Legend />\n {spec.series.map((s, i) => (\n <Line\n key={s.dataKey}\n type=\"monotone\"\n dataKey={s.dataKey}\n name={s.label}\n stroke={pickColor(i, colors)}\n />\n ))}\n </LineChart>\n </ResponsiveContainer>\n </ChartFrame>\n );\n}\n","// Dispatcher that renders the right Coral chart for a given spec.kind.\n// Use this when you want a single component that picks bar / line based on\n// what an agent decided to emit; reach for CoralBarChart / CoralLineChart\n// directly when you know the kind statically.\n\nimport { CoralBarChart } from \"./CoralBarChart\";\nimport { CoralLineChart } from \"./CoralLineChart\";\nimport type { CoralChartSpec } from \"./types\";\n\nexport type CoralChartProps = {\n spec: CoralChartSpec;\n colors?: readonly string[];\n};\n\nexport function CoralChart({ spec, colors }: CoralChartProps) {\n switch (spec.kind) {\n case \"line\":\n return <CoralLineChart spec={spec} colors={colors} />;\n case \"bar\":\n default:\n return <CoralBarChart spec={spec} colors={colors} />;\n }\n}\n"],"mappings":";AAMO,IAAM,sBAAsB;AAAA,EACjC;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF;AAEO,SAAS,UAAU,OAAe,UAA6B,qBAA6B;AACjG,SAAO,QAAQ,QAAQ,QAAQ,MAAM;AACvC;;;ACaI,SACE,KADF;AAzBJ,IAAM,aAAkC;AAAA,EACtC,QAAQ;AAAA,EACR,SAAS;AAAA,EACT,QAAQ;AAAA,EACR,cAAc;AAChB;AAEA,IAAM,aAAkC;AAAA,EACtC,YAAY;AAAA,EACZ,cAAc;AAChB;AAEA,IAAM,YAAiC;AAAA,EACrC,OAAO;AAAA,EACP,QAAQ;AACV;AAEO,SAAS,WAAW;AAAA,EACzB;AAAA,EACA;AACF,GAGG;AAC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BAAAD,KAACG,gBAAA,EAAc,iBAAgB,OAAM;AAAA,IACrC,gBAAAH,KAACI,QAAA,EAAM,SAAS,KAAK,MAAM;AAAA,IAC3B,gBAAAJ,KAACK,QAAA,EAAM;AAAA,IACP,gBAAAL,KAACM,UAAA,EAAQ;AAAA,IACT,gBAAAN,KAACO,SAAA,EAAO;AAAA,IACP,KAAK,OAAO,IAAI,CAAC,GAAG,MACnB,gBAAAP;AAAA,MAAC;AAAA;AAAA,QAEC,MAAK;AAAA,QACL,SAAS,EAAE;AAAA,QACX,MAAM,EAAE;AAAA,QACR,QAAQ,UAAU,GAAG,MAAM;AAAA;AAAA,MAJtB,EAAE;AAAA,IAKT,CACD;AAAA,KACH,GACF,GACF;AAEJ;;;AChCa,gBAAAQ,YAAA;AAHN,SAAS,WAAW,EAAE,MAAM,OAAO,GAAoB;AAC5D,UAAQ,KAAK,MAAM;AAAA,IACjB,KAAK;AACH,aAAO,gBAAAA,KAAC,kBAAe,MAAY,QAAgB;AAAA,IACrD,KAAK;AAAA,IACL;AACE,aAAO,gBAAAA,KAAC,iBAAc,MAAY,QAAgB;AAAA,EACtD;AACF;","names":["jsx","jsxs","CartesianGrid","Legend","ResponsiveContainer","Tooltip","XAxis","YAxis","jsx","jsxs","ResponsiveContainer","CartesianGrid","XAxis","YAxis","Tooltip","Legend","jsx"]}
package/package.json CHANGED
@@ -1,8 +1,8 @@
1
1
  {
2
2
  "name": "@coral-ai/charts",
3
- "version": "0.4.1",
3
+ "version": "3.8.1",
4
4
  "private": false,
5
- "description": "Chart primitives for Coral (placeholder — components land in a future release).",
5
+ "description": "Chart primitives for Coral. Recharts-backed under the hood (CoralBarChart, CoralLineChart, CoralChart); version tracks the bundled recharts release.",
6
6
  "license": "MIT",
7
7
  "author": "Eunsoo Lee",
8
8
  "homepage": "https://github.com/mochimilk/coral-ai#readme",
@@ -27,12 +27,18 @@
27
27
  "README.md",
28
28
  "LICENSE"
29
29
  ],
30
+ "dependencies": {
31
+ "recharts": "3.8.1"
32
+ },
30
33
  "peerDependencies": {
31
- "@fluentui/react-components": "^9.0.0",
32
34
  "react": "^19.0.0",
33
35
  "react-dom": "^19.0.0"
34
36
  },
35
37
  "devDependencies": {
38
+ "@types/react": "^19.2.5",
39
+ "@types/react-dom": "^19.2.3",
40
+ "react": "^19.0.0",
41
+ "react-dom": "^19.0.0",
36
42
  "tsup": "^8.5.1"
37
43
  },
38
44
  "publishConfig": {