@particle-academy/fancy-echarts 2.0.3 → 3.0.2

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,220 @@
1
+ # Diagram
2
+
3
+ A high-level diagram component supporting ERD, flowchart, mindmap, and org-chart layouts. Accepts a schema of entities and relations, auto-layouts positions, and supports drag-to-move, export, and import.
4
+
5
+ `Diagram` is the low-level engine. For most use cases prefer one of the four presets below — they wire up sensible defaults and friendlier per-domain schemas.
6
+
7
+ ## Import
8
+
9
+ ```tsx
10
+ import {
11
+ Diagram, // low-level engine
12
+ DataDiagram, // ERD/UML preset
13
+ Flowchart, // boxes + arrows
14
+ Mindmap, // radial tree
15
+ OrgChart, // top-down hierarchy
16
+ } from "@particle-academy/fancy-echarts";
17
+ ```
18
+
19
+ ## Specialized variants
20
+
21
+ ### DataDiagram
22
+
23
+ ERD/UML preset. Pre-applies `type="erd"`, `downloadable`, `exportFormats={["erd","uml"]}`, `minimap`. Pass any `DiagramProps` to override.
24
+
25
+ ```tsx
26
+ <DataDiagram schema={erdSchema} />
27
+ ```
28
+
29
+ ### Flowchart
30
+
31
+ Friendlier `{ nodes, edges }` schema for boxes-and-arrows diagrams. Auto-grids any nodes that don't supply `x`/`y`.
32
+
33
+ ```tsx
34
+ <Flowchart
35
+ nodes={[
36
+ { id: "start", label: "Start" },
37
+ { id: "review", label: "Review" },
38
+ { id: "ship", label: "Ship" },
39
+ ]}
40
+ edges={[
41
+ { from: "start", to: "review" },
42
+ { from: "review", to: "ship", label: "approve" },
43
+ ]}
44
+ />
45
+ ```
46
+
47
+ ### Mindmap
48
+
49
+ Radial layout from a single root. Children fan outward on concentric rings; angular wedges are sized by subtree leaf count so dense branches get more room.
50
+
51
+ ```tsx
52
+ <Mindmap
53
+ root={{
54
+ id: "root", label: "Product",
55
+ children: [
56
+ { id: "ux", label: "UX", children: [{ id: "ia", label: "IA" }, { id: "vi", label: "Visual" }] },
57
+ { id: "eng", label: "Engineering" },
58
+ { id: "biz", label: "Business" },
59
+ ],
60
+ }}
61
+ />
62
+ ```
63
+
64
+ ### OrgChart
65
+
66
+ Top-down hierarchy. Each parent is centered over the span of its descendants; manhattan-routed connectors with an open-triangle marker on the child end give it a UML-inheritance feel.
67
+
68
+ ```tsx
69
+ <OrgChart
70
+ root={{
71
+ id: "ceo", label: "CEO",
72
+ children: [
73
+ { id: "cto", label: "CTO", children: [{ id: "eng-mgr", label: "Eng Mgr" }] },
74
+ { id: "cfo", label: "CFO" },
75
+ ],
76
+ }}
77
+ />
78
+ ```
79
+
80
+ ## Basic Usage (Schema-driven)
81
+
82
+ ```tsx
83
+ const schema = {
84
+ entities: [
85
+ {
86
+ name: "users",
87
+ fields: [
88
+ { name: "id", type: "bigint", primary: true },
89
+ { name: "name", type: "varchar" },
90
+ { name: "email", type: "varchar" },
91
+ ],
92
+ },
93
+ {
94
+ name: "posts",
95
+ fields: [
96
+ { name: "id", type: "bigint", primary: true },
97
+ { name: "user_id", type: "bigint", foreign: true },
98
+ { name: "title", type: "varchar" },
99
+ { name: "body", type: "text", nullable: true },
100
+ ],
101
+ },
102
+ ],
103
+ relations: [
104
+ { from: "users", to: "posts", type: "one-to-many" },
105
+ ],
106
+ };
107
+
108
+ <Diagram schema={schema} className="h-[600px]" downloadable minimap />
109
+ ```
110
+
111
+ ## Props
112
+
113
+ ### Diagram (root)
114
+
115
+ | Prop | Type | Default | Description |
116
+ |------|------|---------|-------------|
117
+ | schema | `DiagramSchema` | - | Declarative schema of entities and relations |
118
+ | type | `"erd" \| "flowchart" \| "general"` | `"general"` | Diagram type (affects relation rendering) |
119
+ | viewport | `ViewportState` | - | Controlled viewport |
120
+ | defaultViewport | `ViewportState` | - | Default viewport (auto-computed from schema if omitted) |
121
+ | onViewportChange | `(viewport: ViewportState) => void` | - | Viewport change callback |
122
+ | downloadable | `boolean` | `false` | Enable download toolbar action |
123
+ | importable | `boolean` | `false` | Enable import toolbar action |
124
+ | exportFormats | `ExportFormat[]` | `["erd"]` | Export format options: `"erd"`, `"uml"`, `"dfd"` |
125
+ | onImport | `(schema: DiagramSchema) => void` | - | Callback when a schema is imported |
126
+ | minimap | `boolean` | `false` | Show minimap overlay |
127
+ | className | `string` | - | Additional CSS classes |
128
+
129
+ ### Diagram.Entity
130
+
131
+ | Prop | Type | Default | Description |
132
+ |------|------|---------|-------------|
133
+ | id | `string` | - | Unique identifier (defaults to `name`) |
134
+ | name | `string` | - | Entity name (required) |
135
+ | x | `number` | - | X position |
136
+ | y | `number` | - | Y position |
137
+ | color | `string` | - | Header color |
138
+ | draggable | `boolean` | - | Allow drag-to-move |
139
+ | onPositionChange | `(x: number, y: number) => void` | - | Drag callback |
140
+ | children | `ReactNode` | - | Field children |
141
+ | className | `string` | - | Additional CSS classes |
142
+
143
+ ### Diagram.Field
144
+
145
+ | Prop | Type | Default | Description |
146
+ |------|------|---------|-------------|
147
+ | name | `string` | - | Field name (required) |
148
+ | type | `string` | - | Data type label |
149
+ | primary | `boolean` | - | Primary key indicator |
150
+ | foreign | `boolean` | - | Foreign key indicator |
151
+ | nullable | `boolean` | - | Nullable indicator |
152
+ | className | `string` | - | Additional CSS classes |
153
+
154
+ ### Diagram.Relation
155
+
156
+ | Prop | Type | Default | Description |
157
+ |------|------|---------|-------------|
158
+ | from | `string` | - | Source entity id (required) |
159
+ | to | `string` | - | Target entity id (required) |
160
+ | fromField | `string` | - | Source field name |
161
+ | toField | `string` | - | Target field name |
162
+ | type | `RelationType` | - | Shorthand that sets `fromMarker` / `toMarker` / `lineStyle`. See **Relation types** below |
163
+ | fromMarker | `MarkerType` | depends on `type` | Marker shape at the source end |
164
+ | toMarker | `MarkerType` | depends on `type` | Marker shape at the target end |
165
+ | lineStyle | `'solid' \| 'dashed' \| 'dotted'` | from `type` | Line stroke style |
166
+ | routing | `'manhattan' \| 'bezier' \| 'straight'` | `'manhattan'` | Path routing algorithm |
167
+ | color | `string` | `'#71717a'` | Stroke color |
168
+ | strokeWidth | `number` | `2` | Stroke width |
169
+ | label | `string` | - | Edge label rendered at the path midpoint |
170
+ | className | `string` | - | Additional CSS classes |
171
+
172
+ ### Relation types (`type` shorthand)
173
+
174
+ | Type | fromMarker | toMarker | lineStyle |
175
+ |------|-----------|----------|-----------|
176
+ | `one-to-one` | one | one | solid |
177
+ | `one-to-many` | one | many | solid |
178
+ | `many-to-one` | many | one | solid |
179
+ | `many-to-many` | many | many | solid |
180
+ | `association` | none | arrow | solid |
181
+ | `aggregation` | diamond-open | none | solid |
182
+ | `composition` | diamond | none | solid |
183
+ | `inheritance` | none | triangle-open | solid |
184
+ | `implementation` | none | triangle-open | dashed |
185
+ | `dependency` | none | arrow | dashed |
186
+ | `custom` | (caller's `fromMarker`) | (caller's `toMarker`) | solid |
187
+
188
+ ### MarkerType
189
+
190
+ `'none'`, `'arrow'`, `'arrow-open'`, `'circle'`, `'circle-open'`, `'square'`, `'square-open'`, `'diamond'`, `'diamond-open'`, `'triangle'`, `'triangle-open'`, `'one'`, `'many'`, `'optional-one'`, `'optional-many'`, `'cross'`, or any string starting with `emoji:` (e.g. `'emoji:🎯'`) for an emoji/text marker.
191
+
192
+ ### Routing
193
+
194
+ - **manhattan** (default) — right-angle elbows. Picks the side of each entity that faces the other, with a vertical (or horizontal) mid-line that automatically dodges entities lying along the path. Best for ERD/UML.
195
+ - **bezier** — smooth cubic curve with horizontal/vertical control points perpendicular to each side.
196
+ - **straight** — direct line between the two anchor points.
197
+
198
+ ### Diagram.Toolbar
199
+
200
+ | Prop | Type | Default | Description |
201
+ |------|------|---------|-------------|
202
+ | className | `string` | - | Additional CSS classes |
203
+
204
+ ## Declarative Children
205
+
206
+ You can also compose entities and relations as JSX children instead of (or alongside) the schema prop:
207
+
208
+ ```tsx
209
+ <Diagram type="erd" className="h-[500px]">
210
+ <Diagram.Entity name="categories" x={0} y={0} draggable>
211
+ <Diagram.Field name="id" type="int" primary />
212
+ <Diagram.Field name="name" type="varchar" />
213
+ </Diagram.Entity>
214
+ <Diagram.Entity name="products" x={300} y={0} draggable>
215
+ <Diagram.Field name="id" type="int" primary />
216
+ <Diagram.Field name="category_id" type="int" foreign />
217
+ </Diagram.Entity>
218
+ <Diagram.Relation from="categories" to="products" type="one-to-many" />
219
+ </Diagram>
220
+ ```
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@particle-academy/fancy-echarts",
3
- "version": "2.0.3",
3
+ "version": "3.0.2",
4
4
  "description": "React component library wrapping Apache ECharts with typed components for every chart type",
5
5
  "repository": {
6
6
  "type": "git",