@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
@@ -1,171 +0,0 @@
1
- import { ChartFamily, DataShape, Dimension } from "../../core/enums.js";
2
- import { SignalChart } from "./SignalChart.js";
3
- import { SignalDsp } from "./SignalDsp.js";
4
- import { SignalSamples } from "./SignalSamples.js";
5
- import { SignalScales } from "./SignalScales.js";
6
- import { area, scaleLinear } from "d3";
7
- // src/charts/signals/CorrelogramChart.ts
8
- var CorrelogramFunction = /* @__PURE__ */ function(CorrelogramFunction) {
9
- CorrelogramFunction["Auto"] = "autocorrelation";
10
- CorrelogramFunction["Partial"] = "partial";
11
- CorrelogramFunction["Cross"] = "cross-correlation";
12
- return CorrelogramFunction;
13
- }({});
14
- var CorrelogramMark = /* @__PURE__ */ function(CorrelogramMark) {
15
- CorrelogramMark["Stem"] = "stem";
16
- CorrelogramMark["Bars"] = "bars";
17
- CorrelogramMark["Area"] = "area";
18
- return CorrelogramMark;
19
- }({});
20
- var CorrelogramBand = /* @__PURE__ */ function(CorrelogramBand) {
21
- CorrelogramBand["White"] = "white-noise";
22
- CorrelogramBand["Bartlett"] = "bartlett";
23
- CorrelogramBand["None"] = "none";
24
- return CorrelogramBand;
25
- }({});
26
- var Z = 1.96;
27
- /** Correlation of a signal with its own past, for finding periods and AR order, or the delay between two signals. */
28
- var CorrelogramChart = class extends SignalChart {
29
- static meta = {
30
- id: "signal-correlogram",
31
- name: "Correlogram",
32
- family: ChartFamily.Scientific,
33
- dimension: Dimension.Two,
34
- shape: DataShape.Table,
35
- description: "Plots auto, partial or cross-correlation against lag, with significance bands, to expose periods and delays.",
36
- tags: [
37
- "acf",
38
- "pacf",
39
- "ccf",
40
- "lag",
41
- "time series"
42
- ],
43
- sample: (seed) => SignalSamples.noise(seed, 512, 2).flatMap(({ name, noise }, channel) => noise.map((step, i) => {
44
- const at = i - channel * 3;
45
- return {
46
- t: i,
47
- series: name,
48
- value: +(Math.sin(at / 3.2) + .5 * Math.sin(at / 1.3) + step * .5).toFixed(4)
49
- };
50
- })),
51
- variants: {
52
- fn: Object.values(CorrelogramFunction),
53
- mark: Object.values(CorrelogramMark),
54
- band: Object.values(CorrelogramBand),
55
- twoSided: [false, true]
56
- },
57
- valid: (values) => {
58
- if (values.fn === "autocorrelation") return true;
59
- if (values.band === "bartlett") return false;
60
- return values.fn === "partial" ? values.twoSided === false : values.twoSided === true;
61
- }
62
- };
63
- defaults() {
64
- return {
65
- ...super.defaults(),
66
- xLabel: "Lag (samples)",
67
- yLabel: "Correlation",
68
- fn: "autocorrelation",
69
- mark: "stem",
70
- band: "white-noise",
71
- twoSided: false
72
- };
73
- }
74
- get legended() {
75
- return false;
76
- }
77
- series(width) {
78
- const { fn, twoSided, band, maxLag } = this.options, a = this.first, n = a.v.length, b = this.channels[1] ?? a;
79
- const both = twoSided || fn === "cross-correlation", pitch = both ? 9 : 8;
80
- const reach = Math.max(1, Math.min(maxLag ?? 60, Math.floor(width / (both ? 2 * pitch : pitch)), n - 1));
81
- const white = n ? Z / Math.sqrt(n) : 0;
82
- if (fn === "cross-correlation") return SignalDsp.correlate(a.v, b.v, reach).map((point) => ({
83
- ...point,
84
- limit: white
85
- }));
86
- const auto = SignalDsp.autocorrelation(a.v, reach), values = fn === "partial" ? SignalDsp.partial(auto) : auto;
87
- let running = 1;
88
- const lags = values.map((value, lag) => {
89
- const limit = band === "bartlett" ? Z * Math.sqrt(running / (n || 1)) : white;
90
- if (lag > 0) running += 2 * auto[lag] ** 2;
91
- return {
92
- lag,
93
- value,
94
- limit
95
- };
96
- });
97
- return both ? [...lags.slice(1).reverse().map((item) => ({
98
- ...item,
99
- lag: -item.lag
100
- })), ...lags] : lags;
101
- }
102
- scales(ctx) {
103
- const { width, height } = ctx.plot, lags = this.series(width);
104
- const reach = Math.max(1, ...lags.map((item) => Math.abs(item.lag)));
105
- const negative = lags.some((item) => item.lag < 0);
106
- return {
107
- x: scaleLinear([negative ? -reach - 1 : -1, reach + 1], [0, width]),
108
- y: scaleLinear([-1, 1], [height, 0])
109
- };
110
- }
111
- plotMarks(ctx, { x, y }) {
112
- const { mark, band } = this.options, { width } = ctx.plot, lags = this.series(width);
113
- const color = ctx.palette.color(this.first.name), base = y(0);
114
- if (band !== "none") {
115
- const shape = area().x((item) => x(item.lag)).y0((item) => y(-item.limit)).y1((item) => y(item.limit));
116
- this.fill(ctx, "band", [lags], () => 0, (list) => shape(list) ?? "", () => ctx.theme.grid, .8);
117
- }
118
- this.rule(ctx, "zero", [0], y);
119
- const tip = (item) => ({
120
- title: `Lag ${item.lag}`,
121
- color,
122
- rows: [["Correlation", SignalScales.number(item.value)], ["Significant", Math.abs(item.value) > item.limit ? "Yes" : "No"]]
123
- });
124
- if (mark === "area") {
125
- const shape = area().x((item) => x(item.lag)).y0(base).y1((item) => y(item.value));
126
- this.fill(ctx, "value", [lags], () => 0, (list) => shape(list) ?? "", () => color, .8);
127
- this.probe(ctx, (px) => {
128
- const near = lags.reduce((best, item) => !best || Math.abs(x(item.lag) - px) < Math.abs(x(best.lag) - px) ? item : best, null);
129
- return near && {
130
- x: x(near.lag),
131
- tip: tip(near),
132
- datum: near
133
- };
134
- });
135
- return;
136
- }
137
- if (mark === "bars") {
138
- const pitch = lags.length > 1 ? Math.abs(x(lags[1].lag) - x(lags[0].lag)) : 8, thick = Math.max(2, pitch - 2);
139
- const bars = ctx.marks("bars", "rect", lags, (item) => item.lag).attr("fill", color).attr("rx", Math.min(2, thick / 2));
140
- ctx.set(bars, {
141
- x: (item) => x(item.lag) - thick / 2,
142
- width: thick,
143
- y: (item) => Math.min(y(item.value), base),
144
- height: (item) => Math.abs(y(item.value) - base)
145
- }, {
146
- y: base,
147
- height: 0
148
- }, 5);
149
- ctx.hover(bars, tip);
150
- return;
151
- }
152
- const rods = ctx.marks("rods", "line", lags, (item) => item.lag).attr("stroke", color).attr("stroke-width", 2);
153
- ctx.set(rods, {
154
- x1: (item) => x(item.lag),
155
- x2: (item) => x(item.lag),
156
- y1: base,
157
- y2: (item) => y(item.value)
158
- }, { y2: base }, 5);
159
- const heads = ctx.marks("heads", "circle", lags, (item) => item.lag).attr("fill", color).attr("stroke", ctx.theme.surface).attr("stroke-width", 2);
160
- ctx.set(heads, {
161
- cx: (item) => x(item.lag),
162
- cy: (item) => y(item.value),
163
- r: 4
164
- }, {
165
- cy: base,
166
- r: 0
167
- }, 5);
168
- ctx.hover(heads, tip);
169
- }
170
- };
171
- export { CorrelogramBand, CorrelogramChart, CorrelogramFunction, CorrelogramMark };
@@ -1,155 +0,0 @@
1
- import { ChartFamily, DataShape, Dimension } from "../../core/enums.js";
2
- import { SignalChart } from "./SignalChart.js";
3
- import { SignalDsp } from "./SignalDsp.js";
4
- import { SignalRaster } from "./SignalRaster.js";
5
- import { SignalSamples } from "./SignalSamples.js";
6
- import { SignalScales } from "./SignalScales.js";
7
- import { max, scaleLinear } from "d3";
8
- // src/charts/signals/EyeDiagramChart.ts
9
- var EyeDisplay = /* @__PURE__ */ function(EyeDisplay) {
10
- EyeDisplay["Traces"] = "traces";
11
- EyeDisplay["Density"] = "density";
12
- return EyeDisplay;
13
- }({});
14
- var OVERSAMPLE = 16;
15
- var CELL = 3;
16
- var MOST = 160;
17
- /** Overlays bit periods of a serial link so that noise and jitter show as a closing eye. */
18
- var EyeDiagramChart = class extends SignalChart {
19
- static meta = {
20
- id: "signal-eye-diagram",
21
- name: "Eye diagram",
22
- family: ChartFamily.Scientific,
23
- dimension: Dimension.Two,
24
- shape: DataShape.Table,
25
- description: "Folds a digital signal over its symbol period so that noise, jitter and timing margin read as an eye opening.",
26
- tags: [
27
- "serdes",
28
- "signal integrity",
29
- "jitter",
30
- "mask test"
31
- ],
32
- sample: (seed) => {
33
- const [{ noise }] = SignalSamples.noise(seed, 3200, 1), bits = Array.from({ length: 200 }, (_, i) => noise[i * OVERSAMPLE] > 0 ? 1 : -1);
34
- let level = 0;
35
- return noise.map((step, i) => {
36
- level += (bits[Math.floor(i / OVERSAMPLE)] - level) * .28;
37
- return {
38
- t: i / OVERSAMPLE,
39
- series: "Lane 0",
40
- value: +(level + step * .045).toFixed(4)
41
- };
42
- });
43
- },
44
- variants: {
45
- display: Object.values(EyeDisplay),
46
- span: [2, 1],
47
- mask: [true, false],
48
- measure: [true, false]
49
- }
50
- };
51
- defaults() {
52
- return {
53
- ...super.defaults(),
54
- xLabel: "Time (UI)",
55
- yLabel: "Amplitude",
56
- grid: false,
57
- display: "traces",
58
- samplesPerSymbol: OVERSAMPLE,
59
- span: 2,
60
- mask: true,
61
- measure: true
62
- };
63
- }
64
- get legended() {
65
- return false;
66
- }
67
- get levels() {
68
- const { v } = this.first, centre = v.reduce((sum, value) => sum + value, 0) / (v.length || 1);
69
- const highs = v.filter((value) => value > centre), lows = v.filter((value) => value <= centre);
70
- const mean = (values) => values.reduce((sum, value) => sum + value, 0) / (values.length || 1);
71
- const high = mean(highs), low = mean(lows);
72
- return {
73
- high,
74
- low,
75
- mid: (high + low) / 2
76
- };
77
- }
78
- /** Samples into a symbol at which transitions cross mid level: circular mean over all crossings. */
79
- get phase() {
80
- const { v } = this.first, per = this.options.samplesPerSymbol, { mid } = this.levels;
81
- let sin = 0, cos = 0;
82
- for (let i = 1; i < v.length; i++) if ((v[i - 1] - mid) * (v[i] - mid) < 0) {
83
- const angle = 2 * Math.PI * i / per;
84
- sin += Math.sin(angle);
85
- cos += Math.cos(angle);
86
- }
87
- return Math.round((Math.atan2(sin, cos) / (2 * Math.PI) + 1) % 1 * per);
88
- }
89
- /** One sweep per symbol, each a list of [ui, value] with transitions on whole UIs. */
90
- get sweeps() {
91
- const { samplesPerSymbol, span } = this.options, { v } = this.first, per = samplesPerSymbol, length = per * span, out = [];
92
- for (let start = this.phase; start + length < v.length && out.length < MOST; start += per) out.push(Array.from({ length: length + 1 }, (_, i) => [i / per, v[start + i]]));
93
- return out;
94
- }
95
- scales(ctx) {
96
- const reach = this.peak * 1.2;
97
- return {
98
- x: scaleLinear([0, this.options.span], [0, ctx.plot.width]),
99
- y: scaleLinear([-reach, reach], [ctx.plot.height, 0])
100
- };
101
- }
102
- plotMarks(ctx, { x, y }) {
103
- const { display, mask, measure, span } = this.options, sweeps = this.sweeps, color = ctx.palette.color(this.first.name);
104
- if (display === "traces") this.stroke(ctx, "sweeps", sweeps, (_, i) => i, (sweep) => this.path(sweep, x, y), () => color, 1).attr("stroke-opacity", .28);
105
- else this.density(ctx, sweeps, x, y);
106
- const { high, low, mid } = this.levels, centers = Array.from({ length: span }, (_, i) => i + .5), half = (high - low) * .34;
107
- if (mask) {
108
- const d = centers.map((c) => `M${x(c - .22)} ${y(mid)}L${x(c - .1)} ${y(mid + half)}H${x(c + .1)}L${x(c + .22)} ${y(mid)}L${x(c + .1)} ${y(mid - half)}H${x(c - .1)}Z`).join("");
109
- ctx.marks("mask", "path", [d], (_, i) => i).attr("d", (shape) => shape).attr("fill", ctx.theme.surface).attr("fill-opacity", .8).attr("stroke", ctx.theme.ink).attr("stroke-width", 1);
110
- }
111
- if (measure) this.measure(ctx, sweeps, x, y, centers[0], high, low);
112
- this.probe(ctx, (px, py) => ({
113
- x: px,
114
- tip: {
115
- title: `${SignalScales.number(x.invert(px))} UI`,
116
- rows: [["Amplitude", SignalScales.number(y.invert(py))], ["Traces", sweeps.length]]
117
- },
118
- datum: { ui: x.invert(px) }
119
- }));
120
- }
121
- density(ctx, sweeps, x, y) {
122
- const { width, height } = ctx.plot, columns = Math.ceil(width / CELL), rows = Math.ceil(height / CELL);
123
- const counts = new Array(columns * rows).fill(0);
124
- for (const sweep of sweeps) for (let i = 1; i < sweep.length; i++) {
125
- const [ax, ay] = [x(sweep[i - 1][0]), y(sweep[i - 1][1])], [bx, by] = [x(sweep[i][0]), y(sweep[i][1])], steps = Math.ceil(Math.max(Math.abs(bx - ax), Math.abs(by - ay)) / CELL) + 1;
126
- for (let s = 0; s < steps; s++) {
127
- const c = Math.floor((ax + (bx - ax) * s / steps) / CELL), r = Math.floor((ay + (by - ay) * s / steps) / CELL);
128
- if (c >= 0 && c < columns && r >= 0 && r < rows) counts[r * columns + c]++;
129
- }
130
- }
131
- const top = max(counts) || 1, cells = [];
132
- counts.forEach((count, i) => {
133
- if (count) cells.push({
134
- x: i % columns * CELL,
135
- y: Math.floor(i / columns) * CELL,
136
- width: CELL,
137
- height: CELL,
138
- level: Math.max(.12, Math.sqrt(count / top))
139
- });
140
- });
141
- SignalRaster.paint(ctx, "density", cells, ctx.palette.sequential);
142
- }
143
- /** Eye height from the inner rails at centre; eye width from where inner traces cross the mid level. */
144
- measure(ctx, sweeps, x, y, centre, high, low) {
145
- const mid = (high + low) / 2, values = sweeps.map((sweep) => SignalDsp.interpolate(sweep.map((point) => point[0]), sweep.map((point) => point[1]), centre));
146
- const upper = Math.min(...values.filter((value) => value >= mid), high), lower = Math.max(...values.filter((value) => value < mid), low);
147
- const crossings = sweeps.flatMap((sweep) => sweep.flatMap(([ui, value], i) => i && (sweep[i - 1][1] - mid) * (value - mid) < 0 ? [ui] : []));
148
- const left = Math.max(0, ...crossings.filter((ui) => ui < centre)), right = Math.min(centre + .5, ...crossings.filter((ui) => ui >= centre));
149
- const d = `M${x(centre)} ${y(upper)}V${y(lower)}M${x(left)} ${y(mid)}H${x(right)}`;
150
- ctx.marks("eye-rulers", "path", [d], (_, i) => i).attr("d", (shape) => shape).attr("fill", "none").attr("stroke", ctx.theme.ink).attr("stroke-width", 1);
151
- const line = `Height ${SignalScales.number(upper - lower)} Width ${SignalScales.number(right - left)} UI`;
152
- ctx.text(ctx.marks("eye-text", "text", [line], (_, i) => i).attr("x", ctx.plot.width - 4).attr("y", 12).attr("text-anchor", "end").text((text) => text), 11, "ink");
153
- }
154
- };
155
- export { EyeDiagramChart, EyeDisplay };
@@ -1,164 +0,0 @@
1
- import { ChartFamily, DataShape, Dimension } from "../../core/enums.js";
2
- import { SampleData } from "../../data/SampleData.js";
3
- import { SignalChart } from "./SignalChart.js";
4
- import { SignalScales } from "./SignalScales.js";
5
- import { scaleLinear } from "d3";
6
- // src/charts/signals/PoleZeroChart.ts
7
- var PolePlane = /* @__PURE__ */ function(PolePlane) {
8
- PolePlane["Z"] = "z-plane";
9
- PolePlane["S"] = "s-plane";
10
- return PolePlane;
11
- }({});
12
- var RADIAL = [
13
- .25,
14
- .5,
15
- .75
16
- ];
17
- var ARC = 5;
18
- /** Poles and zeros of a transfer function, with stability read off the unit circle or left half-plane. */
19
- var PoleZeroChart = class extends SignalChart {
20
- static meta = {
21
- id: "signal-pole-zero",
22
- name: "Pole-zero plot",
23
- family: ChartFamily.Scientific,
24
- dimension: Dimension.Two,
25
- shape: DataShape.Table,
26
- description: "Places a system’s poles and zeros on the complex plane, showing stability, damping and notch frequencies.",
27
- tags: [
28
- "z-plane",
29
- "s-plane",
30
- "root locus",
31
- "stability",
32
- "transfer function"
33
- ],
34
- sample: (seed) => SampleData.categories(seed, 4, 2).map((row, i) => {
35
- const pole = i < 4, order = i % 4, angle = pole ? .32 + order * .3 : 1.25 + order * .22 + +row.value / 100 * .1;
36
- const radius = pole ? .92 - order * .1 + +row.value / 100 * .03 : 1;
37
- return {
38
- re: +(radius * Math.cos(angle)).toFixed(4),
39
- im: +((order % 2 ? -1 : 1) * radius * Math.sin(angle)).toFixed(4),
40
- kind: pole ? "pole" : "zero"
41
- };
42
- }).flatMap((row) => [row, {
43
- ...row,
44
- im: -row.im
45
- }]),
46
- variants: {
47
- plane: Object.values(PolePlane),
48
- guides: [true, false],
49
- stable: [true, false],
50
- pairs: [false, true]
51
- }
52
- };
53
- defaults() {
54
- return {
55
- ...super.defaults(),
56
- re: "re",
57
- im: "im",
58
- kind: "kind",
59
- xLabel: "Real",
60
- yLabel: "Imaginary",
61
- grid: false,
62
- plane: "z-plane",
63
- guides: true,
64
- stable: true,
65
- pairs: false
66
- };
67
- }
68
- get legended() {
69
- return this.roots.length > 0;
70
- }
71
- get z() {
72
- return this.options.plane === "z-plane";
73
- }
74
- /** Roots in the display plane; z maps to s by the inverse bilinear transform. */
75
- get roots() {
76
- const { data, re, im, kind } = this.options;
77
- return (data ?? []).flatMap((row, i) => {
78
- const a = +row[re], b = +row[im];
79
- if (!Number.isFinite(a) || !Number.isFinite(b) || row[re] === null) return [];
80
- const pole = String(row[kind] ?? "pole") === "pole";
81
- if (this.z) return [{
82
- key: `${i}`,
83
- re: a,
84
- im: b,
85
- pole
86
- }];
87
- const bottom = (a + 1) ** 2 + b ** 2;
88
- return bottom < 1e-9 ? [] : [{
89
- key: `${i}`,
90
- re: (a * a + b * b - 1) / bottom,
91
- im: 2 * b / bottom,
92
- pole
93
- }];
94
- });
95
- }
96
- scales(ctx) {
97
- const { width, height } = ctx.plot, roots = this.roots, ratio = width / height;
98
- const reach = Math.max(this.z ? 1.25 : 1.6, ...roots.map((root) => Math.max(Math.abs(root.re) / ratio, Math.abs(root.im)) * 1.15));
99
- return {
100
- x: scaleLinear([-reach * ratio, reach * ratio], [0, width]),
101
- y: scaleLinear([-reach, reach], [height, 0])
102
- };
103
- }
104
- plotMarks(ctx, { x, y }) {
105
- const { guides, stable, pairs } = this.options, { width, height } = ctx.plot, roots = this.roots, scale = Math.abs(x(1) - x(0));
106
- if (stable) {
107
- if (this.z) ctx.marks("stable", "circle", [0]).attr("cx", x(0)).attr("cy", y(0)).attr("r", scale).attr("fill", ctx.theme.grid).attr("opacity", .55);
108
- else ctx.marks("stable", "rect", [0]).attr("x", 0).attr("y", 0).attr("width", x(0)).attr("height", height).attr("fill", ctx.theme.grid).attr("opacity", .55);
109
- }
110
- ctx.marks("axes", "path", [0]).attr("fill", "none").attr("stroke", ctx.theme.axis).attr("d", `M${x(0)} 0V${height}M0 ${y(0)}H${width}`);
111
- if (this.z) ctx.marks("unit", "circle", [0]).attr("cx", x(0)).attr("cy", y(0)).attr("r", scale).attr("fill", "none").attr("stroke", ctx.theme.inkMuted).attr("stroke-width", 1);
112
- if (guides) this.guides(ctx, x, y, scale);
113
- if (pairs) {
114
- const conjugates = roots.filter((root) => root.im > 1e-6).map((root) => ({
115
- root,
116
- twin: roots.find((other) => other.pole === root.pole && Math.abs(other.re - root.re) < .001 && Math.abs(other.im + root.im) < .001)
117
- })).filter((pair) => pair.twin);
118
- ctx.marks("pairs", "line", conjugates, (pair) => pair.root.key).attr("stroke", ctx.theme.axis).attr("stroke-dasharray", "3 3").attr("x1", (pair) => x(pair.root.re)).attr("x2", (pair) => x(pair.twin.re)).attr("y1", (pair) => y(pair.root.im)).attr("y2", (pair) => y(pair.twin.im));
119
- }
120
- const color = (root) => ctx.palette.color(root.pole ? "Pole" : "Zero");
121
- const r = 5, shape = (root) => root.pole ? `M-${r} -${r}L${r} ${r}M${r} -${r}L-${r} ${r}` : `M-${r} 0a${r} ${r} 0 1 0 10 0a${r} ${r} 0 1 0 -10 0`;
122
- const marks = ctx.marks("roots", "path", roots, (root) => root.key).attr("d", shape).attr("fill", ctx.theme.surface).attr("fill-opacity", (root) => root.pole ? 0 : 1).attr("stroke", color).attr("stroke-width", 2).attr("stroke-linecap", "round");
123
- ctx.set(marks, {
124
- transform: (root) => `translate(${x(root.re)},${y(root.im)})`,
125
- opacity: 1
126
- }, { opacity: 0 }, 25);
127
- ctx.hover(marks, (root) => ({
128
- title: root.pole ? "Pole" : "Zero",
129
- color: color(root),
130
- rows: [["Value", `${SignalScales.number(root.re)} ${root.im < 0 ? "−" : "+"} ${SignalScales.number(Math.abs(root.im))}j`], ["Magnitude", SignalScales.number(Math.hypot(root.re, root.im))]]
131
- }));
132
- }
133
- guides(ctx, x, y, scale) {
134
- if (this.z) {
135
- ctx.marks("rings", "circle", RADIAL, (r) => r).attr("cx", x(0)).attr("cy", y(0)).attr("r", (r) => r * scale).attr("fill", "none").attr("stroke", ctx.theme.grid).attr("stroke-width", 1);
136
- const spokes = Array.from({ length: 10 }, (_, i) => i * Math.PI / ARC);
137
- ctx.marks("spokes", "line", spokes, (angle) => angle).attr("x1", x(0)).attr("y1", y(0)).attr("x2", (angle) => x(Math.cos(angle))).attr("y2", (angle) => y(Math.sin(angle))).attr("stroke", ctx.theme.grid).attr("stroke-width", 1);
138
- return;
139
- }
140
- const limit = Math.min(x.domain()[1], y.domain()[1]);
141
- ctx.marks("rings", "circle", [
142
- .5,
143
- 1,
144
- 1.5,
145
- 2,
146
- 3,
147
- 4
148
- ].filter((r) => r <= limit), (r) => r).attr("cx", x(0)).attr("cy", y(0)).attr("r", (r) => r * scale).attr("fill", "none").attr("stroke", ctx.theme.grid).attr("stroke-width", 1);
149
- const rays = [
150
- .2,
151
- .5,
152
- .8
153
- ].flatMap((damping) => [1, -1].map((sign) => {
154
- const angle = Math.acos(damping) * sign, reach = Math.min(-x.domain()[0] / Math.cos(angle) * Math.sign(Math.cos(angle)), y.domain()[1] / Math.abs(Math.sin(angle)));
155
- return {
156
- key: `${damping}${sign}`,
157
- angle,
158
- reach
159
- };
160
- }));
161
- ctx.marks("spokes", "line", rays, (ray) => ray.key).attr("x1", x(0)).attr("y1", y(0)).attr("x2", (ray) => x(-Math.cos(ray.angle) * ray.reach)).attr("y2", (ray) => y(Math.sin(ray.angle) * ray.reach)).attr("stroke", ctx.theme.grid).attr("stroke-width", 1);
162
- }
163
- };
164
- export { PolePlane, PoleZeroChart };
@@ -1,79 +0,0 @@
1
- import { ChartFamily, DataShape, Dimension } from "../../core/enums.js";
2
- import { SignalDsp } from "./SignalDsp.js";
3
- import { SignalAmplitude, SignalFrequencyScale, SignalWindow } from "./SignalEnums.js";
4
- import { SignalSamples } from "./SignalSamples.js";
5
- import { SignalScales } from "./SignalScales.js";
6
- import { TimeFrequencyChart } from "./TimeFrequencyChart.js";
7
- import { bisectLeft } from "d3";
8
- // src/charts/signals/SpectrogramChart.ts
9
- var FRAMES = 120;
10
- /** Shows how a signal's spectrum changes over time. */
11
- var SignalSpectrogramChart = class extends TimeFrequencyChart {
12
- static meta = {
13
- id: "signal-spectrogram",
14
- name: "Spectrogram",
15
- family: ChartFamily.Scientific,
16
- dimension: Dimension.Two,
17
- shape: DataShape.Table,
18
- description: "Maps short-time spectra across time so that sweeps, tones and clicks show as shapes.",
19
- tags: [
20
- "stft",
21
- "sonogram",
22
- "voiceprint",
23
- "mel"
24
- ],
25
- sample: (seed) => SignalSamples.chirp(seed),
26
- variants: {
27
- frameSize: [
28
- 256,
29
- 64,
30
- 1024
31
- ],
32
- frequency: Object.values(SignalFrequencyScale),
33
- amplitude: Object.values(SignalAmplitude),
34
- ridge: [false, true]
35
- }
36
- };
37
- defaults() {
38
- return {
39
- ...super.defaults(),
40
- yLabel: "Frequency (Hz)",
41
- frameSize: 256,
42
- frequency: SignalFrequencyScale.Linear,
43
- amplitude: SignalAmplitude.Decibel,
44
- window: SignalWindow.Hann,
45
- range: 70
46
- };
47
- }
48
- cache;
49
- get frames() {
50
- const { frameSize, window } = this.options, channel = this.channel, key = `${channel.v.length}|${frameSize}|${window}|${channel.name}|${channel.v[0]}`;
51
- if (this.cache?.key !== key) this.cache = {
52
- key,
53
- frames: SignalDsp.stft(channel.v, channel.rate, window, frameSize, FRAMES, channel.t[0] ?? 0)
54
- };
55
- return this.cache.frames;
56
- }
57
- yAxis(height) {
58
- const { freqs } = this.frames, top = freqs[freqs.length - 1] ?? 10;
59
- return SignalScales.frequency(this.options.frequency, [this.options.frequency === SignalFrequencyScale.Log ? freqs[0] ?? 1 : 0, top], [height, 0]);
60
- }
61
- field() {
62
- const { times, freqs, mags } = this.frames, { range, amplitude } = this.options;
63
- if (!mags.length) return null;
64
- const top = Math.max(1e-12, ...mags.map((frame) => Math.max(...frame))), decibel = amplitude === SignalAmplitude.Decibel, step = freqs[0];
65
- return {
66
- read: (time, freq) => {
67
- const frame = mags[Math.min(mags.length - 1, Math.max(0, bisectLeft(times, time)))];
68
- const bin = Math.max(0, Math.min(freqs.length - 1, Math.round(freq / step) - 1));
69
- return decibel ? SignalDsp.decibel(frame[bin], top, -range) : frame[bin];
70
- },
71
- shade: (value) => decibel ? 1 + value / range : Math.sqrt(value / top),
72
- signed: false,
73
- low: decibel ? `-${range}` : "0",
74
- high: decibel ? "0 dB" : "Max",
75
- unit: decibel ? "Level (dB)" : "Magnitude"
76
- };
77
- }
78
- };
79
- export { SignalSpectrogramChart };