@mstone6969/graph 0.1.0 → 0.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.
Files changed (238) hide show
  1. package/README.md +111 -14
  2. package/dist/ExcelWriter-3ZSYUH4T.cjs +154 -0
  3. package/dist/GraphType.js +24 -38
  4. package/dist/PdfWriter-6HJFYMCO.cjs +205 -0
  5. package/dist/catalog-YWX6FHRM.cjs +8 -0
  6. package/dist/catalog.js +5 -1
  7. package/dist/charts/bars/index.js +2 -12
  8. package/dist/charts/comparison/EffectForestPlot.js +1 -1
  9. package/dist/charts/comparison/index.js +1 -8
  10. package/dist/charts/demography/Nomogram.js +3 -3
  11. package/dist/charts/density/HexbinChart.js +6 -4
  12. package/dist/charts/diagrams/ArchitectureCanvas.js +68 -0
  13. package/dist/charts/diagrams/ArchitectureDiagram.js +331 -0
  14. package/dist/charts/diagrams/ArchitectureLayout.js +106 -0
  15. package/dist/charts/diagrams/ArchitectureLinkLabels.js +78 -0
  16. package/dist/charts/diagrams/ArchitectureModel.js +108 -0
  17. package/dist/charts/diagrams/ArchitectureRouter.js +348 -0
  18. package/dist/charts/diagrams/ArchitectureSamples.js +312 -0
  19. package/dist/charts/diagrams/ArchitectureShapes.js +130 -0
  20. package/dist/charts/diagrams/ArchitectureText.js +25 -0
  21. package/dist/charts/diagrams/DiagramText.js +38 -0
  22. package/dist/charts/diagrams/EntityRelationshipDiagram.js +465 -0
  23. package/dist/charts/diagrams/ErCrowsFoot.js +33 -0
  24. package/dist/charts/diagrams/ErSamples.js +205 -0
  25. package/dist/charts/diagrams/ErSchema.js +122 -0
  26. package/dist/charts/diagrams/LogicCircuit.js +154 -0
  27. package/dist/charts/diagrams/LogicCircuitLayout.js +600 -0
  28. package/dist/charts/diagrams/LogicCircuitSamples.js +66 -0
  29. package/dist/charts/diagrams/LogicGateDiagram.js +216 -0
  30. package/dist/charts/diagrams/LogicGateSymbol.js +113 -0
  31. package/dist/charts/diagrams/NetworkTopologyDiagram.js +247 -0
  32. package/dist/charts/diagrams/SequenceDiagram.js +351 -0
  33. package/dist/charts/diagrams/SequenceLayout.js +422 -0
  34. package/dist/charts/diagrams/SequenceModel.js +221 -0
  35. package/dist/charts/diagrams/TopologyLayout.js +143 -0
  36. package/dist/charts/diagrams/architectureEnums.js +50 -0
  37. package/dist/charts/diagrams/index.js +26 -0
  38. package/dist/charts/diagrams/logicEnums.js +42 -0
  39. package/dist/charts/diagrams/sequenceEnums.js +40 -0
  40. package/dist/charts/distribution/HistogramChart.js +25 -3
  41. package/dist/charts/distribution/index.js +1 -3
  42. package/dist/charts/earthscience/HovmollerDiagram.js +477 -0
  43. package/dist/charts/earthscience/HovmollerEnums.js +42 -0
  44. package/dist/charts/earthscience/HovmollerField.js +180 -0
  45. package/dist/charts/earthscience/HovmollerSample.js +40 -0
  46. package/dist/charts/earthscience/HovmollerSpeed.js +71 -0
  47. package/dist/charts/earthscience/index.js +10 -2
  48. package/dist/charts/engineering/ConstellationDiagram.js +26 -6
  49. package/dist/charts/engineering/EyeDiagram.js +2 -1
  50. package/dist/charts/engineering/PoleZeroPlot.js +32 -8
  51. package/dist/charts/financial/RelativeStrengthRotation.js +434 -0
  52. package/dist/charts/financial/RelativeStrengthRotationMath.js +71 -0
  53. package/dist/charts/financial/RelativeStrengthRotationSamples.js +27 -0
  54. package/dist/charts/financial/index.js +5 -3
  55. package/dist/charts/flow/index.js +1 -5
  56. package/dist/charts/frameworks/AnsoffMatrix.js +523 -0
  57. package/dist/charts/frameworks/FrameworkText.js +98 -0
  58. package/dist/charts/frameworks/NpsGauge.js +279 -0
  59. package/dist/charts/frameworks/NpsSurvey.js +58 -0
  60. package/dist/charts/frameworks/PerceptualMap.js +419 -0
  61. package/dist/charts/frameworks/PerceptualProjection.js +142 -0
  62. package/dist/charts/frameworks/PositioningSamples.js +191 -0
  63. package/dist/charts/frameworks/RaciMatrix.js +458 -0
  64. package/dist/charts/frameworks/RaciPlan.js +81 -0
  65. package/dist/charts/frameworks/RaciSamples.js +76 -0
  66. package/dist/charts/frameworks/SwotMatrix.js +358 -0
  67. package/dist/charts/frameworks/SwotSamples.js +85 -0
  68. package/dist/charts/frameworks/VanWestendorpChart.js +187 -0
  69. package/dist/charts/frameworks/VanWestendorpSurvey.js +197 -0
  70. package/dist/charts/frameworks/index.js +26 -0
  71. package/dist/charts/frameworks/raciEnums.js +30 -0
  72. package/dist/charts/frameworks/swotEnums.js +34 -0
  73. package/dist/charts/genomics/CircosPlot.js +1 -1
  74. package/dist/charts/geoflows/GeoFlowChart.js +2 -2
  75. package/dist/charts/geoflows/GeoFlowSample.js +2 -1
  76. package/dist/charts/geomaps/FloorPlanMap.js +324 -0
  77. package/dist/charts/geomaps/FloorPlanModel.js +179 -0
  78. package/dist/charts/geomaps/FloorPlanSamples.js +416 -0
  79. package/dist/charts/geomaps/GeoLand.js +2 -2
  80. package/dist/charts/geomaps/GeoSamples.js +2 -1
  81. package/dist/charts/geomaps/GraticuleMap.js +2 -2
  82. package/dist/charts/geomaps/RoomLabelFit.js +200 -0
  83. package/dist/charts/geomaps/TissotMap.js +2 -2
  84. package/dist/charts/geomaps/index.js +8 -4
  85. package/dist/charts/hierarchy/SunburstChart.js +17 -10
  86. package/dist/charts/hierarchy/index.js +2 -11
  87. package/dist/charts/indicators/BulletChart.js +8 -2
  88. package/dist/charts/indicators/SpeedometerChart.js +1 -1
  89. package/dist/charts/indicators/ThermometerChart.js +1 -1
  90. package/dist/charts/lifescience/LoessFit.js +113 -0
  91. package/dist/charts/lifescience/MaPlot.js +337 -0
  92. package/dist/charts/lifescience/MaPlotSamples.js +35 -0
  93. package/dist/charts/lifescience/OncoGlyph.js +137 -0
  94. package/dist/charts/lifescience/OncoPrint.js +373 -0
  95. package/dist/charts/lifescience/OncoPrintMatrix.js +107 -0
  96. package/dist/charts/lifescience/OncoPrintSamples.js +142 -0
  97. package/dist/charts/lifescience/PedigreeChart.js +306 -0
  98. package/dist/charts/lifescience/PedigreeLayout.js +261 -0
  99. package/dist/charts/lifescience/PedigreeRows.js +70 -0
  100. package/dist/charts/lifescience/PedigreeSamples.js +161 -0
  101. package/dist/charts/lifescience/PedigreeSymbol.js +47 -0
  102. package/dist/charts/lifescience/RamachandranPlot.js +364 -0
  103. package/dist/charts/lifescience/RamachandranRegions.js +2712 -0
  104. package/dist/charts/lifescience/RamachandranSamples.js +235 -0
  105. package/dist/charts/lifescience/index.js +25 -0
  106. package/dist/charts/lifescience/pedigreeEnums.js +21 -0
  107. package/dist/charts/lifescience/ramachandranEnums.js +34 -0
  108. package/dist/charts/linesareas/DualAxisChart.js +1 -1
  109. package/dist/charts/linesareas/LineEnums.js +1 -15
  110. package/dist/charts/linesareas/MultiLineChart.js +1 -1
  111. package/dist/charts/linesareas/TrendChart.js +15 -5
  112. package/dist/charts/linesareas/index.js +2 -6
  113. package/dist/charts/massive/MassiveChart.js +3 -2
  114. package/dist/charts/mathematical/FourierSeriesChart.js +7 -1
  115. package/dist/charts/mathematical/index.js +2 -6
  116. package/dist/charts/matrix/GridPlot.js +27 -2
  117. package/dist/charts/matrix/TilegramChart.js +2 -2
  118. package/dist/charts/mlcharts/AttentionGrid.js +79 -0
  119. package/dist/charts/mlcharts/AttentionHeatmap.js +329 -0
  120. package/dist/charts/mlcharts/AttentionModel.js +132 -0
  121. package/dist/charts/mlcharts/AttentionSamples.js +82 -0
  122. package/dist/charts/mlcharts/CellNumber.js +8 -0
  123. package/dist/charts/mlcharts/CurveDiagnosticSamples.js +95 -0
  124. package/dist/charts/mlcharts/CurvePickMark.js +31 -0
  125. package/dist/charts/mlcharts/DecisionBoundaryChart.js +316 -0
  126. package/dist/charts/mlcharts/DecisionSamples.js +60 -0
  127. package/dist/charts/mlcharts/DecisionSurface.js +130 -0
  128. package/dist/charts/mlcharts/DistinctTicks.js +13 -0
  129. package/dist/charts/mlcharts/ElbowMath.js +153 -0
  130. package/dist/charts/mlcharts/ElbowPlot.js +273 -0
  131. package/dist/charts/mlcharts/ExplainabilitySamples.js +70 -0
  132. package/dist/charts/mlcharts/FeatureImportanceChart.js +150 -0
  133. package/dist/charts/mlcharts/ImportanceRanking.js +98 -0
  134. package/dist/charts/mlcharts/LearningCurveChart.js +276 -0
  135. package/dist/charts/mlcharts/LearningCurveMath.js +92 -0
  136. package/dist/charts/mlcharts/PartialDependence.js +92 -0
  137. package/dist/charts/mlcharts/PartialDependencePlot.js +225 -0
  138. package/dist/charts/mlcharts/WideLabel.js +28 -0
  139. package/dist/charts/mlcharts/curveDiagnosticEnums.js +37 -0
  140. package/dist/charts/mlcharts/index.js +32 -0
  141. package/dist/charts/proportion/index.js +5 -9
  142. package/dist/charts/scatter/CategoryScatterBase.js +1 -4
  143. package/dist/charts/scatter/ConnectedScatter.js +7 -4
  144. package/dist/charts/scatter/MarginalScatter.js +13 -8
  145. package/dist/charts/scatter/index.js +4 -17
  146. package/dist/charts/scientific/SpectrogramChart.js +9 -3
  147. package/dist/charts/scientific/index.js +2 -2
  148. package/dist/charts/signals/index.js +3 -13
  149. package/dist/charts/statistics/LorenzCurve.js +7 -4
  150. package/dist/charts/threebars/Candlestick3DChart.js +18 -2
  151. package/dist/charts/threeglobe/GlobeChart.js +2 -2
  152. package/dist/charts/threeglobe/GlobeSamples.js +2 -1
  153. package/dist/charts/threeglobe/RingGlobe.js +1 -1
  154. package/dist/charts/threenetwork/ConeTreeChart.js +2 -1
  155. package/dist/charts/threenetwork/Gantt3DChart.js +3 -2
  156. package/dist/charts/threesurfaces/Ridgeline3DChart.js +22 -4
  157. package/dist/charts/threevolume/LorenzAttractor.js +19 -0
  158. package/dist/charts/threevolume/VolumeRaycastChart.js +4 -3
  159. package/dist/charts/threevolume/volumeEnums.js +1 -0
  160. package/dist/charts/timeline/index.js +2 -10
  161. package/dist/chunk-753UBLV2.cjs +33 -0
  162. package/dist/chunk-VX54A7KA.cjs +17 -0
  163. package/dist/{chunk-W5GAAAZY.cjs → chunk-WAODDPYX.cjs} +24874 -17620
  164. package/dist/chunk-Z3JPIJSC.cjs +338 -0
  165. package/dist/core/CartesianChart.js +87 -11
  166. package/dist/core/Chart.js +63 -15
  167. package/dist/core/Chart2D.js +54 -17
  168. package/dist/core/Chart3D.js +56 -20
  169. package/dist/core/ChartExportError.js +2 -0
  170. package/dist/core/ChartExporter.js +50 -8
  171. package/dist/core/ColumnCheck.js +53 -0
  172. package/dist/core/Context2D.js +29 -15
  173. package/dist/core/Context3D.js +7 -2
  174. package/dist/core/ExcelWriter.js +152 -0
  175. package/dist/core/ExportText.js +28 -0
  176. package/dist/core/MarkOrigin.js +88 -0
  177. package/dist/core/MarkStyle.js +294 -0
  178. package/dist/core/Palette.js +27 -7
  179. package/dist/core/PdfPage.js +13 -0
  180. package/dist/core/PdfWriter.js +245 -0
  181. package/dist/core/Scales.js +52 -2
  182. package/dist/core/SceneOverlay.js +4 -4
  183. package/dist/core/TextFit.js +37 -0
  184. package/dist/core/Theme.js +28 -1
  185. package/dist/core/enums.js +33 -1
  186. package/dist/core/pathMorph.js +15 -0
  187. package/dist/data/SampleData.js +1 -17
  188. package/dist/data/WorldSample.js +23 -0
  189. package/dist/index.cjs +810 -691
  190. package/dist/index.d.cts +8390 -2925
  191. package/dist/index.d.ts +8392 -2927
  192. package/dist/index.js +106 -56
  193. package/dist/react/ChartView.js +18 -8
  194. package/dist/react/GraphHandle.js +2 -0
  195. package/dist/react/components.js +74 -116
  196. package/package.json +13 -3
  197. package/dist/catalog-4UP2YFNR.cjs +0 -7
  198. package/dist/charts/bars/BulletBar.js +0 -184
  199. package/dist/charts/bars/ErrorBarColumn.js +0 -147
  200. package/dist/charts/bars/HistogramBar.js +0 -217
  201. package/dist/charts/bars/MarimekkoBar.js +0 -191
  202. package/dist/charts/bars/ParetoBar.js +0 -143
  203. package/dist/charts/comparison/PanelChart.js +0 -70
  204. package/dist/charts/comparison/SmallMultipleBars.js +0 -134
  205. package/dist/charts/comparison/SpanChart.js +0 -118
  206. package/dist/charts/comparison/TrellisChart.js +0 -158
  207. package/dist/charts/distribution/RidgeSlabs3DChart.js +0 -169
  208. package/dist/charts/financial/Candlestick3D.js +0 -157
  209. package/dist/charts/flow/BumpFlow.js +0 -212
  210. package/dist/charts/flow/StreamFlow.js +0 -174
  211. package/dist/charts/geomaps/ThiessenMap.js +0 -106
  212. package/dist/charts/hierarchy/ConeTree3D.js +0 -135
  213. package/dist/charts/hierarchy/Hierarchy3DChart.js +0 -27
  214. package/dist/charts/hierarchy/SpherePack3D.js +0 -81
  215. package/dist/charts/hierarchy/SunburstTower3D.js +0 -93
  216. package/dist/charts/hierarchy/TreemapSkyline3D.js +0 -98
  217. package/dist/charts/linesareas/ConnectedScatterTime.js +0 -206
  218. package/dist/charts/linesareas/SmallMultipleLines.js +0 -153
  219. package/dist/charts/mathematical/ParametricSurface3D.js +0 -234
  220. package/dist/charts/mathematical/StrangeAttractor3D.js +0 -251
  221. package/dist/charts/proportion/ConeFunnel.js +0 -126
  222. package/dist/charts/proportion/ExtrudedPieChart.js +0 -123
  223. package/dist/charts/scatter/BeeswarmScatter.js +0 -151
  224. package/dist/charts/scatter/BinnedScatterBase.js +0 -51
  225. package/dist/charts/scatter/ContourScatter.js +0 -116
  226. package/dist/charts/scatter/GridBinScatter.js +0 -98
  227. package/dist/charts/scatter/HexbinScatter.js +0 -74
  228. package/dist/charts/scatter/StripScatter.js +0 -107
  229. package/dist/charts/scatter/SunflowerScatter.js +0 -109
  230. package/dist/charts/signals/ConstellationChart.js +0 -153
  231. package/dist/charts/signals/CorrelogramChart.js +0 -171
  232. package/dist/charts/signals/EyeDiagramChart.js +0 -155
  233. package/dist/charts/signals/PoleZeroChart.js +0 -164
  234. package/dist/charts/signals/SpectrogramChart.js +0 -79
  235. package/dist/charts/timeline/CalendarSkylineChart.js +0 -128
  236. package/dist/charts/timeline/ScheduleBlocksChart.js +0 -119
  237. package/dist/charts/timeline/SpiralTimeline.js +0 -154
  238. package/dist/charts/timeline/StreamTimeline.js +0 -141
@@ -0,0 +1,205 @@
1
+ import { ErCardinality } from "./ErSchema.js";
2
+ // src/charts/diagrams/ErSamples.ts
3
+ var SHOP = [
4
+ [
5
+ "customers",
6
+ "id",
7
+ "uuid",
8
+ "PK"
9
+ ],
10
+ [
11
+ "customers",
12
+ "email",
13
+ "text",
14
+ "UK"
15
+ ],
16
+ [
17
+ "customers",
18
+ "name",
19
+ "text",
20
+ ""
21
+ ],
22
+ [
23
+ "customers",
24
+ "referred_by",
25
+ "uuid",
26
+ "",
27
+ "customers.id",
28
+ "YES",
29
+ "refers"
30
+ ],
31
+ [
32
+ "profiles",
33
+ "customer_id",
34
+ "uuid",
35
+ "PK",
36
+ "customers.id",
37
+ "NO",
38
+ "has"
39
+ ],
40
+ [
41
+ "profiles",
42
+ "avatar_url",
43
+ "text",
44
+ "",
45
+ void 0,
46
+ "YES"
47
+ ],
48
+ [
49
+ "orders",
50
+ "id",
51
+ "uuid",
52
+ "PK"
53
+ ],
54
+ [
55
+ "orders",
56
+ "customer_id",
57
+ "uuid",
58
+ "",
59
+ "customers.id",
60
+ "NO",
61
+ "places"
62
+ ],
63
+ [
64
+ "orders",
65
+ "placed_at",
66
+ "timestamptz",
67
+ ""
68
+ ],
69
+ [
70
+ "orders",
71
+ "status",
72
+ "text",
73
+ ""
74
+ ],
75
+ [
76
+ "order_lines",
77
+ "order_id",
78
+ "uuid",
79
+ "PK",
80
+ "orders.id",
81
+ "NO",
82
+ "contains",
83
+ ErCardinality.OneOrMany
84
+ ],
85
+ [
86
+ "order_lines",
87
+ "line_no",
88
+ "int",
89
+ "PK"
90
+ ],
91
+ [
92
+ "order_lines",
93
+ "product_id",
94
+ "uuid",
95
+ "",
96
+ "products.id",
97
+ "NO",
98
+ "sold as"
99
+ ],
100
+ [
101
+ "order_lines",
102
+ "quantity",
103
+ "int",
104
+ ""
105
+ ],
106
+ [
107
+ "products",
108
+ "id",
109
+ "uuid",
110
+ "PK"
111
+ ],
112
+ [
113
+ "products",
114
+ "sku",
115
+ "text",
116
+ "UK"
117
+ ],
118
+ [
119
+ "products",
120
+ "category_id",
121
+ "uuid",
122
+ "",
123
+ "categories.id",
124
+ "YES",
125
+ "groups"
126
+ ],
127
+ [
128
+ "products",
129
+ "price",
130
+ "numeric",
131
+ ""
132
+ ],
133
+ [
134
+ "categories",
135
+ "id",
136
+ "uuid",
137
+ "PK"
138
+ ],
139
+ [
140
+ "categories",
141
+ "name",
142
+ "text",
143
+ ""
144
+ ],
145
+ [
146
+ "payments",
147
+ "id",
148
+ "uuid",
149
+ "PK"
150
+ ],
151
+ [
152
+ "payments",
153
+ "order_id",
154
+ "uuid",
155
+ "UK",
156
+ "orders.id",
157
+ "NO",
158
+ "settled by"
159
+ ],
160
+ [
161
+ "payments",
162
+ "amount",
163
+ "numeric",
164
+ ""
165
+ ]
166
+ ];
167
+ var COUPONS = [
168
+ [
169
+ "coupons",
170
+ "code",
171
+ "text",
172
+ "PK"
173
+ ],
174
+ [
175
+ "coupons",
176
+ "percent_off",
177
+ "int",
178
+ ""
179
+ ],
180
+ [
181
+ "orders",
182
+ "coupon_code",
183
+ "text",
184
+ "",
185
+ "coupons.code",
186
+ "YES",
187
+ "discounts"
188
+ ]
189
+ ];
190
+ /** A synthetic online shop schema, invented for the sample: it describes no real database. Odd seeds add coupons. */
191
+ var ErSamples = class {
192
+ static shop(seed) {
193
+ return (seed % 2 ? [...SHOP, ...COUPONS] : SHOP).map(([table, column, type, key, references, nullable, relation, childEnd]) => ({
194
+ table,
195
+ column,
196
+ type,
197
+ key,
198
+ references,
199
+ nullable: nullable ?? "NO",
200
+ relation,
201
+ childEnd
202
+ }));
203
+ }
204
+ };
205
+ export { ErSamples };
@@ -0,0 +1,122 @@
1
+ // src/charts/diagrams/ErSchema.ts
2
+ /** Crow's foot end marks: the outer symbol is the minimum, the one against the entity the maximum. */
3
+ var ErCardinality = /* @__PURE__ */ function(ErCardinality) {
4
+ ErCardinality["ExactlyOne"] = "exactly-one";
5
+ ErCardinality["ZeroOrOne"] = "zero-or-one";
6
+ ErCardinality["OneOrMany"] = "one-or-many";
7
+ ErCardinality["ZeroOrMany"] = "zero-or-many";
8
+ return ErCardinality;
9
+ }({});
10
+ var PRIMARY = /* @__PURE__ */ new Set([
11
+ "PK",
12
+ "PRI",
13
+ "PRIMARY"
14
+ ]);
15
+ var UNIQUE = /* @__PURE__ */ new Set([
16
+ "UK",
17
+ "UQ",
18
+ "UNI",
19
+ "UNIQUE"
20
+ ]);
21
+ var NULLABLE = /* @__PURE__ */ new Set([
22
+ "YES",
23
+ "Y",
24
+ "TRUE",
25
+ "1",
26
+ "NULL",
27
+ "NULLABLE"
28
+ ]);
29
+ var ENDS = new Set(Object.values(ErCardinality));
30
+ var text = (cell) => cell === null || cell === void 0 ? "" : String(cell).trim();
31
+ var end = (cell, fallback) => ENDS.has(text(cell)) ? text(cell) : fallback;
32
+ var bare = (name) => name.replace(/["`\[\]]/g, "").trim().toLowerCase();
33
+ var leaf = (name) => name.slice(name.lastIndexOf(".") + 1);
34
+ /** The table part of a reference: `orders.id`, `public.orders.id`, `orders(id)`, or a bare `orders`. */
35
+ function targetTable(reference) {
36
+ const call = reference.indexOf("(");
37
+ if (call >= 0) return reference.slice(0, call).trim();
38
+ const dot = reference.lastIndexOf(".");
39
+ return dot < 0 ? reference : reference.slice(0, dot);
40
+ }
41
+ /**
42
+ * Finds the table a reference means, the way SQL resolves it: ignoring quotes and case, and with a
43
+ * schema prefix on either side. `information_schema` often gives `table_name` unqualified while the
44
+ * reference is qualified. A short name that fits two tables resolves to neither.
45
+ */
46
+ function resolver(tables) {
47
+ const full = new Map(tables.map((id) => [bare(id), id]));
48
+ const short = /* @__PURE__ */ new Map();
49
+ for (const id of tables) short.set(leaf(bare(id)), short.has(leaf(bare(id))) ? null : id);
50
+ return (reference) => {
51
+ const whole = bare(reference), table = bare(targetTable(reference));
52
+ return full.get(whole) ?? full.get(table) ?? short.get(leaf(table)) ?? void 0;
53
+ };
54
+ }
55
+ /** Turns one-row-per-column schema rows into tables and foreign key relationships. */
56
+ var ErSchema = class {
57
+ static read(rows, fields) {
58
+ const tables = /* @__PURE__ */ new Map();
59
+ const groups = /* @__PURE__ */ new Map();
60
+ for (const row of rows) {
61
+ if (row === null || typeof row !== "object") continue;
62
+ const id = text(row[fields.table]), name = text(row[fields.column]);
63
+ if (!id) continue;
64
+ if (!tables.has(id)) tables.set(id, {
65
+ id,
66
+ columns: []
67
+ });
68
+ const table = tables.get(id);
69
+ if (!name || table.columns.some((column) => column.name === name)) continue;
70
+ const tokens = text(row[fields.key]).toUpperCase().split(/[\s,;/+]+/);
71
+ const references = text(row[fields.references]);
72
+ const column = {
73
+ name,
74
+ references,
75
+ type: text(row[fields.dataType]),
76
+ foreign: !!references,
77
+ primary: tokens.some((token) => PRIMARY.has(token)),
78
+ unique: tokens.some((token) => UNIQUE.has(token)),
79
+ nullable: NULLABLE.has(text(row[fields.nullable]).toUpperCase())
80
+ };
81
+ table.columns.push(column);
82
+ if (!references) continue;
83
+ const parent = targetTable(references), constraint = text(row[fields.constraint]);
84
+ const key = `${id}\0${constraint || name}\0${parent}`;
85
+ const group = groups.get(key) ?? {
86
+ child: id,
87
+ parent,
88
+ constraint,
89
+ rows: [],
90
+ columns: []
91
+ };
92
+ group.rows.push(row);
93
+ group.columns.push(column);
94
+ groups.set(key, group);
95
+ }
96
+ const resolve = resolver([...tables.keys()]);
97
+ const relationships = [...groups.entries()].flatMap(([key, group]) => {
98
+ const parent = resolve(text(group.rows[0][fields.references]));
99
+ if (parent === void 0) return [];
100
+ const { child, constraint, columns } = group, first = group.rows[0];
101
+ const primaries = tables.get(child).columns.filter((column) => column.primary);
102
+ const single = columns.length === primaries.length && columns.every((column) => column.primary) || columns.length === 1 && columns[0].unique;
103
+ return [{
104
+ key,
105
+ child,
106
+ parent,
107
+ constraint,
108
+ columns: columns.map((column) => column.name),
109
+ references: columns.map((column) => column.references),
110
+ label: text(first[fields.relation]),
111
+ parentEnd: end(first[fields.parentEnd], columns.some((column) => column.nullable) ? "zero-or-one" : "exactly-one"),
112
+ childEnd: end(first[fields.childEnd], single ? "zero-or-one" : "zero-or-many"),
113
+ identifying: columns.every((column) => column.primary)
114
+ }];
115
+ });
116
+ return {
117
+ tables: [...tables.values()],
118
+ relationships
119
+ };
120
+ }
121
+ };
122
+ export { ErCardinality, ErSchema };
@@ -0,0 +1,154 @@
1
+ import { LogicGateKind, LogicState } from "./logicEnums.js";
2
+ // src/charts/diagrams/LogicCircuit.ts
3
+ var KINDS = new Set(Object.values(LogicGateKind));
4
+ var ALIASES = {
5
+ buf: LogicGateKind.Buffer,
6
+ inv: LogicGateKind.Not,
7
+ inverter: LogicGateKind.Not
8
+ };
9
+ var TRUE = /* @__PURE__ */ new Set([
10
+ "1",
11
+ "true",
12
+ "t",
13
+ "high",
14
+ "h"
15
+ ]);
16
+ var FALSE = /* @__PURE__ */ new Set([
17
+ "0",
18
+ "false",
19
+ "f",
20
+ "low",
21
+ "l"
22
+ ]);
23
+ var SINGLE = /* @__PURE__ */ new Set([
24
+ LogicGateKind.Not,
25
+ LogicGateKind.Buffer,
26
+ LogicGateKind.Output
27
+ ]);
28
+ var { True, False, Unknown } = LogicState;
29
+ /**
30
+ * A gate-level netlist evaluated by ternary (Kleene 0/1/X) simulation, after Eichelberger (1965):
31
+ * every net starts at X and gates are re-evaluated to a fixed point. The gate functions are
32
+ * monotone in X, so this always settles: a stable latch resolves when its inputs force it and
33
+ * stays X when they do not, and an oscillator stays X. XOR and XNOR of more than two inputs are
34
+ * odd and even parity, as in Verilog's primitives.
35
+ */
36
+ var LogicCircuit = class LogicCircuit {
37
+ static fields = {
38
+ id: "id",
39
+ kind: "type",
40
+ label: "label",
41
+ value: "value",
42
+ from: "from",
43
+ to: "to"
44
+ };
45
+ nodes = /* @__PURE__ */ new Map();
46
+ /** Rows that could not be used, in plain words. */
47
+ issues = [];
48
+ constructor(data, fields = {}) {
49
+ const names = {
50
+ ...LogicCircuit.fields,
51
+ ...fields
52
+ };
53
+ const given = this.#readGates(data?.gates ?? [], names);
54
+ this.#readWires(data?.wires ?? [], names);
55
+ this.#settle(given);
56
+ }
57
+ static parseState(value) {
58
+ const text = String(value ?? "").trim().toLowerCase();
59
+ return TRUE.has(text) ? True : FALSE.has(text) ? False : Unknown;
60
+ }
61
+ static evaluate(kind, inputs) {
62
+ switch (kind) {
63
+ case LogicGateKind.Output:
64
+ case LogicGateKind.Buffer: return inputs[0] ?? Unknown;
65
+ case LogicGateKind.Not: return LogicCircuit.#invert(inputs[0] ?? Unknown);
66
+ case LogicGateKind.And: return LogicCircuit.#and(inputs);
67
+ case LogicGateKind.Nand: return LogicCircuit.#invert(LogicCircuit.#and(inputs));
68
+ case LogicGateKind.Or: return LogicCircuit.#or(inputs);
69
+ case LogicGateKind.Nor: return LogicCircuit.#invert(LogicCircuit.#or(inputs));
70
+ case LogicGateKind.Xor: return LogicCircuit.#parity(inputs);
71
+ case LogicGateKind.Xnor: return LogicCircuit.#invert(LogicCircuit.#parity(inputs));
72
+ default: return Unknown;
73
+ }
74
+ }
75
+ static #invert(state) {
76
+ return state === Unknown ? Unknown : state === True ? False : True;
77
+ }
78
+ static #and(inputs) {
79
+ if (!inputs.length) return Unknown;
80
+ return inputs.includes(False) ? False : inputs.includes(Unknown) ? Unknown : True;
81
+ }
82
+ static #or(inputs) {
83
+ if (!inputs.length) return Unknown;
84
+ return inputs.includes(True) ? True : inputs.includes(Unknown) ? Unknown : False;
85
+ }
86
+ static #parity(inputs) {
87
+ if (!inputs.length || inputs.includes(Unknown)) return Unknown;
88
+ return inputs.filter((state) => state === True).length % 2 ? True : False;
89
+ }
90
+ static #kind(value) {
91
+ const text = String(value ?? "").trim().toLowerCase();
92
+ return KINDS.has(text) && text !== LogicGateKind.Unknown ? text : ALIASES[text] ?? null;
93
+ }
94
+ #readGates(rows, names) {
95
+ const given = /* @__PURE__ */ new Map();
96
+ for (const row of rows) {
97
+ const raw = row?.[names.id];
98
+ if (raw === null || raw === void 0 || raw === "") {
99
+ this.issues.push("Gate row without an id was skipped");
100
+ continue;
101
+ }
102
+ const id = String(raw);
103
+ if (this.nodes.has(id)) {
104
+ this.issues.push(`Duplicate gate ${id} was skipped`);
105
+ continue;
106
+ }
107
+ const kind = LogicCircuit.#kind(row[names.kind]);
108
+ if (!kind) this.issues.push(`Gate ${id} has unknown type ${String(row[names.kind])}`);
109
+ this.nodes.set(id, {
110
+ id,
111
+ kind: kind ?? LogicGateKind.Unknown,
112
+ label: String(row[names.label] ?? id),
113
+ inputs: [],
114
+ state: Unknown
115
+ });
116
+ if (kind === LogicGateKind.Input) given.set(id, LogicCircuit.parseState(row[names.value]));
117
+ }
118
+ return given;
119
+ }
120
+ #readWires(rows, names) {
121
+ for (const row of rows) {
122
+ const from = this.nodes.get(String(row?.[names.from]));
123
+ const to = this.nodes.get(String(row?.[names.to]));
124
+ const name = `${String(row?.[names.from])} to ${String(row?.[names.to])}`;
125
+ if (!from || !to) this.issues.push(`Wire ${name} names a missing gate`);
126
+ else if (from.kind === LogicGateKind.Output) this.issues.push(`Wire ${name} leaves an output`);
127
+ else if (to.kind === LogicGateKind.Input) this.issues.push(`Wire ${name} drives an input`);
128
+ else if (SINGLE.has(to.kind) && to.inputs.length) this.issues.push(`Wire ${name} is a second driver of a one-input pin`);
129
+ else to.inputs.push(from.id);
130
+ }
131
+ for (const node of this.nodes.values()) {
132
+ const least = node.kind === LogicGateKind.Input ? 0 : SINGLE.has(node.kind) ? 1 : 2;
133
+ while (node.inputs.length < least) node.inputs.push(null);
134
+ }
135
+ }
136
+ #settle(given) {
137
+ const nodes = [...this.nodes.values()];
138
+ for (const node of nodes) node.state = given.get(node.id) ?? Unknown;
139
+ const logic = nodes.filter((node) => node.kind !== LogicGateKind.Input);
140
+ let changed = true;
141
+ while (changed) {
142
+ changed = false;
143
+ for (const node of logic) {
144
+ const inputs = node.inputs.map((id) => id === null ? Unknown : this.nodes.get(id).state);
145
+ const state = LogicCircuit.evaluate(node.kind, inputs);
146
+ if (state !== node.state) {
147
+ node.state = state;
148
+ changed = true;
149
+ }
150
+ }
151
+ }
152
+ }
153
+ };
154
+ export { LogicCircuit };