semiotic 3.1.2 → 3.2.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.
- package/CLAUDE.md +134 -216
- package/LICENSE +197 -10
- package/README.md +1 -0
- package/ai/dist/componentRegistry.js +6 -0
- package/ai/dist/mcp-server.js +115 -5
- package/ai/examples.md +93 -0
- package/ai/schema.json +3916 -878
- package/ai/system-prompt.md +27 -0
- package/dist/components/ThemeProvider.d.ts +5 -3
- package/dist/components/charts/geo/ChoroplethMap.d.ts +1 -1
- package/dist/components/charts/index.d.ts +8 -1
- package/dist/components/charts/ordinal/BarChart.d.ts +1 -0
- package/dist/components/charts/ordinal/BoxPlot.d.ts +1 -0
- package/dist/components/charts/ordinal/DonutChart.d.ts +1 -0
- package/dist/components/charts/ordinal/DotPlot.d.ts +1 -0
- package/dist/components/charts/ordinal/FunnelChart.d.ts +55 -0
- package/dist/components/charts/ordinal/GroupedBarChart.d.ts +1 -0
- package/dist/components/charts/ordinal/Histogram.d.ts +1 -0
- package/dist/components/charts/ordinal/PieChart.d.ts +1 -0
- package/dist/components/charts/ordinal/RidgelinePlot.d.ts +1 -0
- package/dist/components/charts/ordinal/StackedBarChart.d.ts +1 -0
- package/dist/components/charts/ordinal/SwarmPlot.d.ts +1 -0
- package/dist/components/charts/ordinal/ViolinPlot.d.ts +1 -0
- package/dist/components/charts/shared/colorManipulation.d.ts +15 -0
- package/dist/components/charts/shared/formatUtils.d.ts +28 -0
- package/dist/components/charts/shared/hatchPattern.d.ts +35 -0
- package/dist/components/charts/shared/hooks.d.ts +16 -1
- package/dist/components/charts/shared/legendUtils.d.ts +2 -1
- package/dist/components/charts/shared/selectionUtils.d.ts +11 -0
- package/dist/components/charts/shared/statisticalOverlays.d.ts +49 -5
- package/dist/components/charts/shared/types.d.ts +4 -1
- package/dist/components/charts/xy/Heatmap.d.ts +1 -1
- package/dist/components/charts/xy/MultiAxisLineChart.d.ts +71 -0
- package/dist/components/realtime/types.d.ts +2 -0
- package/dist/components/semiotic-ai.d.ts +3 -0
- package/dist/components/semiotic-ordinal.d.ts +3 -0
- package/dist/components/semiotic-themes.d.ts +64 -0
- package/dist/components/semiotic-xy.d.ts +1 -0
- package/dist/components/semiotic.d.ts +11 -5
- package/dist/components/store/ThemeStore.d.ts +22 -2
- package/dist/components/stream/OrdinalSVGOverlay.d.ts +1 -0
- package/dist/components/stream/PipelineStore.d.ts +2 -0
- package/dist/components/stream/SVGOverlay.d.ts +5 -3
- package/dist/components/stream/accessorUtils.d.ts +14 -0
- package/dist/components/stream/networkTypes.d.ts +2 -0
- package/dist/components/stream/ordinalSceneBuilders/barFunnelScene.d.ts +27 -0
- package/dist/components/stream/ordinalSceneBuilders/funnelScene.d.ts +26 -0
- package/dist/components/stream/ordinalTypes.d.ts +16 -2
- package/dist/components/stream/renderers/barFunnelCanvasRenderer.d.ts +12 -0
- package/dist/components/stream/renderers/trapezoidCanvasRenderer.d.ts +15 -0
- package/dist/components/stream/sceneUtils.d.ts +10 -0
- package/dist/components/stream/types.d.ts +10 -3
- package/dist/geo.min.js +1 -1
- package/dist/geo.module.min.js +1 -1
- package/dist/network.min.js +1 -1
- package/dist/network.module.min.js +1 -1
- package/dist/ordinal.min.js +1 -1
- package/dist/ordinal.module.min.js +1 -1
- package/dist/realtime.min.js +1 -1
- package/dist/realtime.module.min.js +1 -1
- package/dist/semiotic-ai-statisticalOverlays-C2PPlmXv.js +1 -0
- package/dist/semiotic-ai.d.ts +3 -0
- package/dist/semiotic-ai.min.js +1 -1
- package/dist/semiotic-ai.module.min.js +1 -1
- package/dist/semiotic-ordinal.d.ts +3 -0
- package/dist/semiotic-statisticalOverlays-D8LhSbQt.js +1 -0
- package/dist/semiotic-themes.d.ts +64 -0
- package/dist/semiotic-themes.min.js +1 -0
- package/dist/semiotic-themes.module.min.js +1 -0
- package/dist/semiotic-xy.d.ts +1 -0
- package/dist/semiotic.d.ts +11 -5
- package/dist/semiotic.min.js +1 -1
- package/dist/semiotic.module.min.js +1 -1
- package/dist/server.min.js +1 -1
- package/dist/server.module.min.js +1 -1
- package/dist/xy-statisticalOverlays-C2PPlmXv.js +1 -0
- package/dist/xy.min.js +1 -1
- package/dist/xy.module.min.js +1 -1
- package/package.json +24 -5
- package/dist/semiotic-ai-statisticalOverlays-C1f7TYyD.js +0 -1
- package/dist/semiotic-statisticalOverlays-C1f7TYyD.js +0 -1
- package/dist/xy-statisticalOverlays-C1f7TYyD.js +0 -1
package/LICENSE
CHANGED
|
@@ -1,13 +1,200 @@
|
|
|
1
|
-
Copyright 2017 Elijah Meeks
|
|
2
1
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
2
|
+
Apache License
|
|
3
|
+
Version 2.0, January 2004
|
|
4
|
+
http://www.apache.org/licenses/
|
|
6
5
|
|
|
7
|
-
|
|
6
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
8
7
|
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
8
|
+
1. Definitions.
|
|
9
|
+
|
|
10
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
11
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
12
|
+
|
|
13
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
14
|
+
the copyright owner that is granting the License.
|
|
15
|
+
|
|
16
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
17
|
+
other entities that control, are controlled by, or are under common
|
|
18
|
+
control with that entity. For the purposes of this definition,
|
|
19
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
20
|
+
direction or management of such entity, whether by contract or
|
|
21
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
22
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
23
|
+
|
|
24
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
25
|
+
exercising permissions granted by this License.
|
|
26
|
+
|
|
27
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
28
|
+
including but not limited to software source code, documentation
|
|
29
|
+
source, and configuration files.
|
|
30
|
+
|
|
31
|
+
"Object" form shall mean any form resulting from mechanical
|
|
32
|
+
transformation or translation of a Source form, including but
|
|
33
|
+
not limited to compiled object code, generated documentation,
|
|
34
|
+
and conversions to other media types.
|
|
35
|
+
|
|
36
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
37
|
+
Object form, made available under the License, as indicated by a
|
|
38
|
+
copyright notice that is included in or attached to the work
|
|
39
|
+
(an example is provided in the Appendix below).
|
|
40
|
+
|
|
41
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
42
|
+
form, that is based on (or derived from) the Work and for which the
|
|
43
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
44
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
45
|
+
of this License, Derivative Works shall not include works that remain
|
|
46
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
47
|
+
the Work and Derivative Works thereof.
|
|
48
|
+
|
|
49
|
+
"Contribution" shall mean any work of authorship, including
|
|
50
|
+
the original version of the Work and any modifications or additions
|
|
51
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
52
|
+
submitted to the Licensor for inclusion in the Work by the copyright owner
|
|
53
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
54
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
55
|
+
means any form of electronic, verbal, or written communication sent
|
|
56
|
+
to the Licensor or its representatives, including but not limited to
|
|
57
|
+
communication on electronic mailing lists, source code control systems,
|
|
58
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
59
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
60
|
+
excluding communication that is conspicuously marked or otherwise
|
|
61
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
62
|
+
|
|
63
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
64
|
+
on behalf of whom a Contribution has been received by the Licensor and
|
|
65
|
+
subsequently incorporated within the Work.
|
|
66
|
+
|
|
67
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
68
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
69
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
70
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
71
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
72
|
+
Work and such Derivative Works in Source or Object form.
|
|
73
|
+
|
|
74
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
75
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
76
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
77
|
+
(except as stated in this section) patent license to make, have made,
|
|
78
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
79
|
+
where such license applies only to those patent claims licensable
|
|
80
|
+
by such Contributor that are necessarily infringed by their
|
|
81
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
82
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
83
|
+
institute patent litigation against any entity (including a
|
|
84
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
85
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
86
|
+
or contributory patent infringement, then any patent licenses
|
|
87
|
+
granted to You under this License for that Work shall terminate
|
|
88
|
+
as of the date such litigation is filed.
|
|
89
|
+
|
|
90
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
91
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
92
|
+
modifications, and in Source or Object form, provided that You
|
|
93
|
+
meet the following conditions:
|
|
94
|
+
|
|
95
|
+
(a) You must give any other recipients of the Work or
|
|
96
|
+
Derivative Works a copy of this License; and
|
|
97
|
+
|
|
98
|
+
(b) You must cause any modified files to carry prominent notices
|
|
99
|
+
stating that You changed the files; and
|
|
100
|
+
|
|
101
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
102
|
+
that You distribute, all copyright, patent, trademark, and
|
|
103
|
+
attribution notices from the Source form of the Work,
|
|
104
|
+
excluding those notices that do not pertain to any part of
|
|
105
|
+
the Derivative Works; and
|
|
106
|
+
|
|
107
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
108
|
+
distribution, then any Derivative Works that You distribute must
|
|
109
|
+
include a readable copy of the attribution notices contained
|
|
110
|
+
within such NOTICE file, excluding any notices that do not
|
|
111
|
+
pertain to any part of the Derivative Works, in at least one
|
|
112
|
+
of the following places: within a NOTICE text file distributed
|
|
113
|
+
as part of the Derivative Works; within the Source form or
|
|
114
|
+
documentation, if provided along with the Derivative Works; or,
|
|
115
|
+
within a display generated by the Derivative Works, if and
|
|
116
|
+
wherever such third-party notices normally appear. The contents
|
|
117
|
+
of the NOTICE file are for informational purposes only and
|
|
118
|
+
do not modify the License. You may add Your own attribution
|
|
119
|
+
notices within Derivative Works that You distribute, alongside
|
|
120
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
121
|
+
that such additional attribution notices cannot be construed
|
|
122
|
+
as modifying the License.
|
|
123
|
+
|
|
124
|
+
You may add Your own copyright statement to Your modifications and
|
|
125
|
+
may provide additional or different license terms and conditions
|
|
126
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
127
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
128
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
129
|
+
the conditions stated in this License.
|
|
130
|
+
|
|
131
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
132
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
133
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
134
|
+
this License, without any additional terms or conditions.
|
|
135
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
136
|
+
the terms of any separate license agreement you may have executed
|
|
137
|
+
with Licensor regarding such Contributions.
|
|
138
|
+
|
|
139
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
140
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
141
|
+
except as required for reasonable and customary use in describing the
|
|
142
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
143
|
+
|
|
144
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
145
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
146
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
147
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
148
|
+
implied, including, without limitation, any warranties or conditions
|
|
149
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
150
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
151
|
+
appropriateness of using or redistributing the Work and assume any
|
|
152
|
+
risks associated with Your exercise of permissions under this License.
|
|
153
|
+
|
|
154
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
155
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
156
|
+
unless required by applicable law (such as deliberate and grossly
|
|
157
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
158
|
+
liable to You for damages, including any direct, indirect, special,
|
|
159
|
+
incidental, or consequential damages of any character arising as a
|
|
160
|
+
result of this License or out of the use or inability to use the
|
|
161
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
162
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
163
|
+
other commercial damages or losses), even if such Contributor
|
|
164
|
+
has been advised of the possibility of such damages.
|
|
165
|
+
|
|
166
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
167
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
168
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
169
|
+
or other liability obligations and/or rights consistent with this
|
|
170
|
+
License. However, in accepting such obligations, You may act only
|
|
171
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
172
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
173
|
+
defend, and hold each Contributor harmless for any liability
|
|
174
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
175
|
+
of your accepting any such warranty or additional liability.
|
|
176
|
+
|
|
177
|
+
END OF TERMS AND CONDITIONS
|
|
178
|
+
|
|
179
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
180
|
+
|
|
181
|
+
To apply the Apache License to your work, attach the following
|
|
182
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
183
|
+
replaced with your own identifying information. (Don't include
|
|
184
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
185
|
+
comment syntax for the file format. Please also get an approval
|
|
186
|
+
for your intended use from the project maintainers.
|
|
187
|
+
|
|
188
|
+
Copyright 2017 Elijah Meeks
|
|
189
|
+
|
|
190
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
191
|
+
you may not use this file except in compliance with the License.
|
|
192
|
+
You may obtain a copy of the License at
|
|
193
|
+
|
|
194
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
195
|
+
|
|
196
|
+
Unless required by applicable law or agreed to in writing, software
|
|
197
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
198
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
199
|
+
See the License for the specific language governing permissions and
|
|
200
|
+
limitations under the License.
|
package/README.md
CHANGED
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
[](https://github.com/nteract/semiotic/actions/workflows/node.js.yml)
|
|
4
4
|
[](https://www.npmjs.com/package/semiotic)
|
|
5
5
|
[](https://www.typescriptlang.org/)
|
|
6
|
+
[](https://glama.ai/mcp/servers/nteract/semiotic)
|
|
6
7
|
|
|
7
8
|
A React data visualization library designed for AI-assisted development.
|
|
8
9
|
|
|
@@ -11,14 +11,20 @@ exports.COMPONENT_REGISTRY = {
|
|
|
11
11
|
BubbleChart: { component: ai_1.BubbleChart, category: "xy" },
|
|
12
12
|
Heatmap: { component: ai_1.Heatmap, category: "xy" },
|
|
13
13
|
ConnectedScatterplot: { component: ai_1.ConnectedScatterplot, category: "xy" },
|
|
14
|
+
QuadrantChart: { component: ai_1.QuadrantChart, category: "xy" },
|
|
15
|
+
MultiAxisLineChart: { component: ai_1.MultiAxisLineChart, category: "xy" },
|
|
14
16
|
BarChart: { component: ai_1.BarChart, category: "ordinal" },
|
|
15
17
|
StackedBarChart: { component: ai_1.StackedBarChart, category: "ordinal" },
|
|
16
18
|
GroupedBarChart: { component: ai_1.GroupedBarChart, category: "ordinal" },
|
|
17
19
|
SwarmPlot: { component: ai_1.SwarmPlot, category: "ordinal" },
|
|
18
20
|
BoxPlot: { component: ai_1.BoxPlot, category: "ordinal" },
|
|
19
21
|
DotPlot: { component: ai_1.DotPlot, category: "ordinal" },
|
|
22
|
+
Histogram: { component: ai_1.Histogram, category: "ordinal" },
|
|
23
|
+
ViolinPlot: { component: ai_1.ViolinPlot, category: "ordinal" },
|
|
24
|
+
RidgelinePlot: { component: ai_1.RidgelinePlot, category: "ordinal" },
|
|
20
25
|
PieChart: { component: ai_1.PieChart, category: "ordinal" },
|
|
21
26
|
DonutChart: { component: ai_1.DonutChart, category: "ordinal" },
|
|
27
|
+
FunnelChart: { component: ai_1.FunnelChart, category: "ordinal" },
|
|
22
28
|
ForceDirectedGraph: { component: ai_1.ForceDirectedGraph, category: "network" },
|
|
23
29
|
ChordDiagram: { component: ai_1.ChordDiagram, category: "network" },
|
|
24
30
|
SankeyDiagram: { component: ai_1.SankeyDiagram, category: "network" },
|
package/ai/dist/mcp-server.js
CHANGED
|
@@ -84,7 +84,7 @@ async function getSchemaHandler(args) {
|
|
|
84
84
|
const renderable = new Set(Object.keys(componentRegistry_1.COMPONENT_REGISTRY));
|
|
85
85
|
const list = all.map(name => renderable.has(name) ? `${name} [renderable]` : name);
|
|
86
86
|
return {
|
|
87
|
-
content: [{ type: "text", text: `Available components (${all.length}):\n${list.join(", ")}\n\nComponents marked [renderable] can be rendered to SVG via renderChart. Others (Realtime*) require a browser environment.\n\nPass { component: '<name>' } to get the prop schema for a specific component.` }],
|
|
87
|
+
content: [{ type: "text", text: `Available components (${all.length}):\n${list.join(", ")}\n\nComponents marked [renderable] can be rendered to SVG via renderChart (pass theme parameter for styled output). Others (Realtime*) require a browser environment.\n\nAll charts support CSS custom properties for theming (--semiotic-bg, --semiotic-text, --semiotic-grid, etc.) and <ThemeProvider>. Use COLOR_BLIND_SAFE_CATEGORICAL (import from semiotic) for accessible color palettes.\n\nPass { component: '<name>' } to get the prop schema for a specific component.` }],
|
|
88
88
|
};
|
|
89
89
|
}
|
|
90
90
|
const entry = schemaByComponent[component];
|
|
@@ -305,13 +305,17 @@ async function suggestChartHandler(args) {
|
|
|
305
305
|
const propsStr = Object.entries(s.props).map(([k, v]) => `${k}=${v}`).join(" ");
|
|
306
306
|
return `${i + 1}. **${s.component}** (${s.confidence} confidence)\n ${s.reason}\n \`<${s.component} ${propsStr} />\``;
|
|
307
307
|
});
|
|
308
|
+
// Theming guidance appended to every recommendation
|
|
309
|
+
const themingTip = `\n---\n**Styling**: All charts respond to CSS custom properties on any ancestor element:\n\`\`\`css\n.my-theme {\n --semiotic-bg: #fff; /* chart background */\n --semiotic-text: #333; /* primary text */\n --semiotic-text-secondary: #666; /* tick labels */\n --semiotic-grid: #e0e0e0; /* grid lines */\n --semiotic-border: #e0e0e0; /* axis lines, borders */\n --semiotic-font-family: sans-serif;\n --semiotic-tooltip-bg: rgba(0,0,0,0.85);\n --semiotic-tooltip-text: white;\n --semiotic-tooltip-radius: 6px;\n}\n\`\`\`\nOr use \`<ThemeProvider theme="dark">\` / \`<ThemeProvider theme={{ colors: {...}, typography: {...} }}>\`.\nFor accessibility, use \`colorScheme={COLOR_BLIND_SAFE_CATEGORICAL}\` (import from \`semiotic\`) — 8-color palette safe for all forms of color blindness.`;
|
|
308
310
|
return {
|
|
309
|
-
content: [{ type: "text", text: lines.join("\n\n") }],
|
|
311
|
+
content: [{ type: "text", text: lines.join("\n\n") + themingTip }],
|
|
310
312
|
};
|
|
311
313
|
}
|
|
312
314
|
async function renderChartHandler(args) {
|
|
313
315
|
const component = args.component;
|
|
314
316
|
const props = args.props ?? {};
|
|
317
|
+
const theme = args.theme;
|
|
318
|
+
const format = args.format || "svg";
|
|
315
319
|
if (!component) {
|
|
316
320
|
return {
|
|
317
321
|
content: [{ type: "text", text: `Missing 'component' field. Provide { component: '<name>', props: { ... } }. Available: ${componentNames.join(", ")}` }],
|
|
@@ -331,8 +335,46 @@ async function renderChartHandler(args) {
|
|
|
331
335
|
isError: true,
|
|
332
336
|
};
|
|
333
337
|
}
|
|
338
|
+
let svg = result.svg;
|
|
339
|
+
// Inject theme CSS custom properties into the SVG root element.
|
|
340
|
+
// We add a <style> block inside the SVG rather than wrapping in a <div>,
|
|
341
|
+
// because sharp requires pure SVG input for PNG rasterization.
|
|
342
|
+
if (theme && Object.keys(theme).length > 0) {
|
|
343
|
+
const validVars = Object.entries(theme)
|
|
344
|
+
.filter(([k]) => k.startsWith("--semiotic-"))
|
|
345
|
+
.map(([k, v]) => `${k}: ${v}`)
|
|
346
|
+
.join("; ");
|
|
347
|
+
if (validVars) {
|
|
348
|
+
svg = svg.replace(/<svg([^>]*)>/, `<svg$1><style>:root { ${validVars} }</style>`);
|
|
349
|
+
}
|
|
350
|
+
}
|
|
351
|
+
// PNG rasterization via sharp (optional dependency)
|
|
352
|
+
if (format === "png") {
|
|
353
|
+
try {
|
|
354
|
+
// Dynamic import — sharp is an optional dependency
|
|
355
|
+
// eslint-disable-next-line @typescript-eslint/no-var-requires
|
|
356
|
+
const sharpMod = await Function('return import("sharp")')();
|
|
357
|
+
const sharpFn = sharpMod.default || sharpMod;
|
|
358
|
+
const pngBuffer = await sharpFn(Buffer.from(svg)).png().toBuffer();
|
|
359
|
+
const base64 = pngBuffer.toString("base64");
|
|
360
|
+
return {
|
|
361
|
+
content: [{ type: "text", text: `data:image/png;base64,${base64}` }],
|
|
362
|
+
};
|
|
363
|
+
}
|
|
364
|
+
catch (err) {
|
|
365
|
+
if (err.code === "MODULE_NOT_FOUND" || err.code === "ERR_MODULE_NOT_FOUND") {
|
|
366
|
+
return {
|
|
367
|
+
content: [{ type: "text", text: `PNG output requires the 'sharp' package. Install it with: npm install sharp\n\nFalling back to SVG output:\n\n${svg}` }],
|
|
368
|
+
};
|
|
369
|
+
}
|
|
370
|
+
return {
|
|
371
|
+
content: [{ type: "text", text: `PNG conversion failed: ${err.message}\n\nSVG output:\n\n${svg}` }],
|
|
372
|
+
isError: true,
|
|
373
|
+
};
|
|
374
|
+
}
|
|
375
|
+
}
|
|
334
376
|
return {
|
|
335
|
-
content: [{ type: "text", text:
|
|
377
|
+
content: [{ type: "text", text: svg }],
|
|
336
378
|
};
|
|
337
379
|
}
|
|
338
380
|
async function diagnoseConfigHandler(args) {
|
|
@@ -385,6 +427,69 @@ async function reportIssueHandler(args) {
|
|
|
385
427
|
content: [{ type: "text", text: `Open this URL to submit the issue:\n\n${url}` }],
|
|
386
428
|
};
|
|
387
429
|
}
|
|
430
|
+
// Named theme presets (inlined to avoid runtime dependency on semiotic-themes bundle)
|
|
431
|
+
const THEME_PRESET_NAMES = [
|
|
432
|
+
"light", "dark", "high-contrast",
|
|
433
|
+
"pastels", "pastels-dark",
|
|
434
|
+
"bi-tool", "bi-tool-dark",
|
|
435
|
+
"italian", "italian-dark",
|
|
436
|
+
"tufte", "tufte-dark",
|
|
437
|
+
"journalist", "journalist-dark",
|
|
438
|
+
"playful", "playful-dark",
|
|
439
|
+
];
|
|
440
|
+
async function applyThemeHandler(args) {
|
|
441
|
+
const name = args.name;
|
|
442
|
+
if (!name) {
|
|
443
|
+
return {
|
|
444
|
+
content: [{ type: "text", text: `Available theme presets:\n${THEME_PRESET_NAMES.join(", ")}\n\nPass { name: "tufte" } to get the CSS custom properties and ThemeProvider usage for that theme.\n\nLight-mode presets: ${THEME_PRESET_NAMES.filter(n => !n.includes("dark")).join(", ")}\nDark-mode presets: ${THEME_PRESET_NAMES.filter(n => n.includes("dark")).join(", ")}` }],
|
|
445
|
+
};
|
|
446
|
+
}
|
|
447
|
+
if (!THEME_PRESET_NAMES.includes(name)) {
|
|
448
|
+
return {
|
|
449
|
+
content: [{ type: "text", text: `Unknown theme "${name}". Available: ${THEME_PRESET_NAMES.join(", ")}` }],
|
|
450
|
+
isError: true,
|
|
451
|
+
};
|
|
452
|
+
}
|
|
453
|
+
const usage = [
|
|
454
|
+
`## Theme: "${name}"`,
|
|
455
|
+
"",
|
|
456
|
+
"### Option 1: ThemeProvider (recommended)",
|
|
457
|
+
"```jsx",
|
|
458
|
+
`import { ThemeProvider } from "semiotic"`,
|
|
459
|
+
`<ThemeProvider theme="${name}">`,
|
|
460
|
+
` <LineChart ... />`,
|
|
461
|
+
`</ThemeProvider>`,
|
|
462
|
+
"```",
|
|
463
|
+
"",
|
|
464
|
+
"### Option 2: Import the theme object",
|
|
465
|
+
"```jsx",
|
|
466
|
+
`import { ${name.replace(/-./g, c => c[1].toUpperCase()).replace(/^./, c => c.toUpperCase()).replace(/Dark$/, '_DARK').replace(/([a-z])([A-Z])/g, '$1_$2').toUpperCase()} } from "semiotic/themes"`,
|
|
467
|
+
`<ThemeProvider theme={themeObject}>`,
|
|
468
|
+
` <BarChart ... />`,
|
|
469
|
+
`</ThemeProvider>`,
|
|
470
|
+
"```",
|
|
471
|
+
"",
|
|
472
|
+
"### Option 3: CSS custom properties (no React required)",
|
|
473
|
+
"```jsx",
|
|
474
|
+
`import { themeToCSS } from "semiotic/themes"`,
|
|
475
|
+
`import { ${name.replace(/-./g, c => c[1].toUpperCase()).replace(/^./, c => c.toUpperCase()).replace(/Dark$/, '_DARK').replace(/([a-z])([A-Z])/g, '$1_$2').toUpperCase()} } from "semiotic/themes"`,
|
|
476
|
+
`const css = themeToCSS(themeObject, ".my-charts")`,
|
|
477
|
+
"// Outputs CSS custom properties string for embedding in a stylesheet",
|
|
478
|
+
"```",
|
|
479
|
+
"",
|
|
480
|
+
"### Option 4: Design tokens JSON",
|
|
481
|
+
"```jsx",
|
|
482
|
+
`import { themeToTokens } from "semiotic/themes"`,
|
|
483
|
+
`const tokens = themeToTokens(themeObject)`,
|
|
484
|
+
"// Style Dictionary / DTCG-compatible token format",
|
|
485
|
+
"```",
|
|
486
|
+
"",
|
|
487
|
+
"For accessibility, consider `\"high-contrast\"` which uses `COLOR_BLIND_SAFE_CATEGORICAL` (Wong 2011 palette).",
|
|
488
|
+
];
|
|
489
|
+
return {
|
|
490
|
+
content: [{ type: "text", text: usage.join("\n") }],
|
|
491
|
+
};
|
|
492
|
+
}
|
|
388
493
|
// ── Server factory ───────────────────────────────────────────────────────
|
|
389
494
|
// Creates a fresh McpServer with all tools registered.
|
|
390
495
|
// HTTP mode needs one instance per session (McpServer can only connect to one transport).
|
|
@@ -399,11 +504,13 @@ function createServer() {
|
|
|
399
504
|
data: zod_1.z.array(zod_1.z.record(zod_1.z.string(), zod_1.z.unknown())).min(1).max(5).describe("1-5 sample data objects"),
|
|
400
505
|
intent: zod_1.z.enum(["comparison", "trend", "distribution", "relationship", "composition", "geographic", "network", "hierarchy"]).optional().describe("Visualization intent to narrow suggestions"),
|
|
401
506
|
}, suggestChartHandler);
|
|
402
|
-
srv.tool("renderChart", `Render a Semiotic chart to static SVG. Returns SVG string or
|
|
507
|
+
srv.tool("renderChart", `Render a Semiotic chart to static SVG or PNG. Returns SVG string (default) or Base64-encoded PNG image. Optionally pass theme CSS custom properties (--semiotic-bg, --semiotic-text, etc.) to style the output. PNG requires the 'sharp' package to be installed. Available components: ${componentNames.join(", ")}.`, {
|
|
403
508
|
component: zod_1.z.string().describe("Chart component name, e.g. 'LineChart', 'BarChart'"),
|
|
404
509
|
props: zod_1.z.record(zod_1.z.string(), zod_1.z.unknown()).optional().describe("Chart props object, e.g. { data: [...], xAccessor: 'x' }."),
|
|
510
|
+
theme: zod_1.z.record(zod_1.z.string(), zod_1.z.string()).optional().describe("CSS custom properties for theming, e.g. { '--semiotic-bg': '#1a1a2e', '--semiotic-text': '#ededed' }. Only --semiotic-* variables are applied."),
|
|
511
|
+
format: zod_1.z.enum(["svg", "png"]).optional().describe("Output format: 'svg' (default) returns SVG markup, 'png' returns a Base64-encoded PNG image. PNG requires the 'sharp' package."),
|
|
405
512
|
}, renderChartHandler);
|
|
406
|
-
srv.tool("diagnoseConfig", "Diagnose a Semiotic chart configuration for common problems (empty data, bad dimensions, missing accessors, wrong data shape, etc). Returns a human-readable diagnostic report with actionable fixes.", {
|
|
513
|
+
srv.tool("diagnoseConfig", "Diagnose a Semiotic chart configuration for common problems (empty data, bad dimensions, missing accessors, wrong data shape, color contrast issues, etc). Checks WCAG color contrast ratios and suggests COLOR_BLIND_SAFE_CATEGORICAL for accessibility. Returns a human-readable diagnostic report with actionable fixes.", {
|
|
407
514
|
component: zod_1.z.string().describe("Chart component name, e.g. 'LineChart'"),
|
|
408
515
|
props: zod_1.z.record(zod_1.z.string(), zod_1.z.unknown()).optional().describe("Chart props object, e.g. { data: [...], xAccessor: 'x' }."),
|
|
409
516
|
}, diagnoseConfigHandler);
|
|
@@ -412,6 +519,9 @@ function createServer() {
|
|
|
412
519
|
body: zod_1.z.string().optional().describe("Issue body with details, reproduction steps, diagnoseConfig output"),
|
|
413
520
|
labels: zod_1.z.union([zod_1.z.array(zod_1.z.string()), zod_1.z.string()]).optional().describe("GitHub labels, e.g. ['bug'] or 'bug'"),
|
|
414
521
|
}, reportIssueHandler);
|
|
522
|
+
srv.tool("applyTheme", `Get usage instructions for a named Semiotic theme preset. Returns ThemeProvider examples, CSS custom properties, and design token export patterns. Available themes: ${THEME_PRESET_NAMES.join(", ")}.`, {
|
|
523
|
+
name: zod_1.z.string().optional().describe("Theme preset name, e.g. 'tufte', 'pastels-dark', 'bi-tool'. Omit to list all available themes."),
|
|
524
|
+
}, applyThemeHandler);
|
|
415
525
|
return srv;
|
|
416
526
|
}
|
|
417
527
|
// ── Startup ──────────────────────────────────────────────────────────────
|
package/ai/examples.md
CHANGED
|
@@ -902,3 +902,96 @@ const containerRef = useRef<HTMLDivElement>(null)
|
|
|
902
902
|
```
|
|
903
903
|
|
|
904
904
|
Key: `exportChart(wrapperDiv, { format, filename, scale, background })`. It queries the wrapper for canvas and SVG elements internally. Default format: PNG with 2x scale.
|
|
905
|
+
|
|
906
|
+
---
|
|
907
|
+
|
|
908
|
+
## Theming & Brand Styling
|
|
909
|
+
|
|
910
|
+
### CSS Custom Properties (no React context needed)
|
|
911
|
+
|
|
912
|
+
```jsx
|
|
913
|
+
// Dark theme via CSS custom properties on a wrapper div
|
|
914
|
+
<div style={{
|
|
915
|
+
"--semiotic-bg": "#1a1a2e",
|
|
916
|
+
"--semiotic-text": "#ededed",
|
|
917
|
+
"--semiotic-text-secondary": "#aaa",
|
|
918
|
+
"--semiotic-grid": "#333",
|
|
919
|
+
"--semiotic-border": "#555",
|
|
920
|
+
"--semiotic-font-family": "'Georgia', serif",
|
|
921
|
+
"--semiotic-tooltip-bg": "#1a1a2e",
|
|
922
|
+
"--semiotic-tooltip-text": "#ededed",
|
|
923
|
+
"--semiotic-tooltip-radius": "8px",
|
|
924
|
+
"--semiotic-tooltip-shadow": "0 4px 12px rgba(0,0,0,0.4)",
|
|
925
|
+
"--semiotic-primary": "#ff6b6b",
|
|
926
|
+
"--semiotic-focus": "#ff6b6b",
|
|
927
|
+
}}>
|
|
928
|
+
<LineChart
|
|
929
|
+
data={[{ x: 1, y: 10 }, { x: 2, y: 20 }, { x: 3, y: 15 }]}
|
|
930
|
+
xAccessor="x" yAccessor="y"
|
|
931
|
+
showGrid
|
|
932
|
+
annotations={[{ type: "y-threshold", value: 18, label: "Target" }]}
|
|
933
|
+
/>
|
|
934
|
+
</div>
|
|
935
|
+
```
|
|
936
|
+
|
|
937
|
+
### ThemeProvider (React context)
|
|
938
|
+
|
|
939
|
+
```jsx
|
|
940
|
+
import { ThemeProvider, DARK_THEME, COLOR_BLIND_SAFE_CATEGORICAL } from "semiotic"
|
|
941
|
+
|
|
942
|
+
// Preset dark theme
|
|
943
|
+
<ThemeProvider theme="dark">
|
|
944
|
+
<BarChart data={data} categoryAccessor="name" valueAccessor="value" />
|
|
945
|
+
</ThemeProvider>
|
|
946
|
+
|
|
947
|
+
// Custom brand theme (partial merge with defaults)
|
|
948
|
+
<ThemeProvider theme={{
|
|
949
|
+
mode: "light",
|
|
950
|
+
colors: {
|
|
951
|
+
primary: "#cc0000",
|
|
952
|
+
categorical: ["#cc0000", "#333333", "#c8a415", "#4682b4"],
|
|
953
|
+
background: "#fafafa",
|
|
954
|
+
text: "#1a1a1a",
|
|
955
|
+
textSecondary: "#666",
|
|
956
|
+
grid: "#e0e0e0",
|
|
957
|
+
border: "#e0e0e0",
|
|
958
|
+
},
|
|
959
|
+
typography: {
|
|
960
|
+
fontFamily: "'Helvetica Neue', Helvetica, Arial, sans-serif",
|
|
961
|
+
titleSize: 16, labelSize: 12, tickSize: 10,
|
|
962
|
+
},
|
|
963
|
+
tooltip: {
|
|
964
|
+
background: "#fafafa",
|
|
965
|
+
text: "#1a1a1a",
|
|
966
|
+
borderRadius: "4px",
|
|
967
|
+
},
|
|
968
|
+
}}>
|
|
969
|
+
<GroupedBarChart data={data} categoryAccessor="quarter" valueAccessor="revenue"
|
|
970
|
+
groupBy="region" colorBy="region" showGrid showLegend />
|
|
971
|
+
</ThemeProvider>
|
|
972
|
+
|
|
973
|
+
// Color-blind safe palette (Wong 2011 — 8 colors)
|
|
974
|
+
<Scatterplot data={data} xAccessor="x" yAccessor="y"
|
|
975
|
+
colorBy="category" colorScheme={COLOR_BLIND_SAFE_CATEGORICAL} />
|
|
976
|
+
```
|
|
977
|
+
|
|
978
|
+
### Annotations with Theme Colors
|
|
979
|
+
|
|
980
|
+
```jsx
|
|
981
|
+
// Annotations inherit --semiotic-primary and --semiotic-text-secondary from theme
|
|
982
|
+
<LineChart
|
|
983
|
+
data={salesData}
|
|
984
|
+
xAccessor="month" yAccessor="revenue"
|
|
985
|
+
annotations={[
|
|
986
|
+
// Threshold line — defaults to --semiotic-primary if no color set
|
|
987
|
+
{ type: "y-threshold", value: 50000, label: "Q3 Target" },
|
|
988
|
+
// Widget annotation at specific data point
|
|
989
|
+
{ type: "widget", month: "Jul", revenue: 72000, dy: -15, content: (
|
|
990
|
+
<span style={{ fontSize: 11, fontWeight: 700 }}>Record month</span>
|
|
991
|
+
)},
|
|
992
|
+
// Enclose a cluster of outliers
|
|
993
|
+
{ type: "enclose", coordinates: outlierPoints, label: "Outlier cluster", padding: 15 },
|
|
994
|
+
]}
|
|
995
|
+
showGrid
|
|
996
|
+
/>
|
|
997
|
+
```
|