@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.
- package/README.md +111 -14
- package/dist/ExcelWriter-3ZSYUH4T.cjs +154 -0
- package/dist/GraphType.js +24 -38
- package/dist/PdfWriter-6HJFYMCO.cjs +205 -0
- package/dist/catalog-YWX6FHRM.cjs +8 -0
- package/dist/catalog.js +5 -1
- package/dist/charts/bars/index.js +2 -12
- package/dist/charts/comparison/EffectForestPlot.js +1 -1
- package/dist/charts/comparison/index.js +1 -8
- package/dist/charts/demography/Nomogram.js +3 -3
- package/dist/charts/density/HexbinChart.js +6 -4
- package/dist/charts/diagrams/ArchitectureCanvas.js +68 -0
- package/dist/charts/diagrams/ArchitectureDiagram.js +331 -0
- package/dist/charts/diagrams/ArchitectureLayout.js +106 -0
- package/dist/charts/diagrams/ArchitectureLinkLabels.js +78 -0
- package/dist/charts/diagrams/ArchitectureModel.js +108 -0
- package/dist/charts/diagrams/ArchitectureRouter.js +348 -0
- package/dist/charts/diagrams/ArchitectureSamples.js +312 -0
- package/dist/charts/diagrams/ArchitectureShapes.js +130 -0
- package/dist/charts/diagrams/ArchitectureText.js +25 -0
- package/dist/charts/diagrams/DiagramText.js +38 -0
- package/dist/charts/diagrams/EntityRelationshipDiagram.js +465 -0
- package/dist/charts/diagrams/ErCrowsFoot.js +33 -0
- package/dist/charts/diagrams/ErSamples.js +205 -0
- package/dist/charts/diagrams/ErSchema.js +122 -0
- package/dist/charts/diagrams/LogicCircuit.js +154 -0
- package/dist/charts/diagrams/LogicCircuitLayout.js +600 -0
- package/dist/charts/diagrams/LogicCircuitSamples.js +66 -0
- package/dist/charts/diagrams/LogicGateDiagram.js +216 -0
- package/dist/charts/diagrams/LogicGateSymbol.js +113 -0
- package/dist/charts/diagrams/NetworkTopologyDiagram.js +247 -0
- package/dist/charts/diagrams/SequenceDiagram.js +351 -0
- package/dist/charts/diagrams/SequenceLayout.js +422 -0
- package/dist/charts/diagrams/SequenceModel.js +221 -0
- package/dist/charts/diagrams/TopologyLayout.js +143 -0
- package/dist/charts/diagrams/architectureEnums.js +50 -0
- package/dist/charts/diagrams/index.js +26 -0
- package/dist/charts/diagrams/logicEnums.js +42 -0
- package/dist/charts/diagrams/sequenceEnums.js +40 -0
- package/dist/charts/distribution/HistogramChart.js +25 -3
- package/dist/charts/distribution/index.js +1 -3
- package/dist/charts/earthscience/HovmollerDiagram.js +477 -0
- package/dist/charts/earthscience/HovmollerEnums.js +42 -0
- package/dist/charts/earthscience/HovmollerField.js +180 -0
- package/dist/charts/earthscience/HovmollerSample.js +40 -0
- package/dist/charts/earthscience/HovmollerSpeed.js +71 -0
- package/dist/charts/earthscience/index.js +10 -2
- package/dist/charts/engineering/ConstellationDiagram.js +26 -6
- package/dist/charts/engineering/EyeDiagram.js +2 -1
- package/dist/charts/engineering/PoleZeroPlot.js +32 -8
- package/dist/charts/financial/RelativeStrengthRotation.js +434 -0
- package/dist/charts/financial/RelativeStrengthRotationMath.js +71 -0
- package/dist/charts/financial/RelativeStrengthRotationSamples.js +27 -0
- package/dist/charts/financial/index.js +5 -3
- package/dist/charts/flow/index.js +1 -5
- package/dist/charts/frameworks/AnsoffMatrix.js +523 -0
- package/dist/charts/frameworks/FrameworkText.js +98 -0
- package/dist/charts/frameworks/NpsGauge.js +279 -0
- package/dist/charts/frameworks/NpsSurvey.js +58 -0
- package/dist/charts/frameworks/PerceptualMap.js +419 -0
- package/dist/charts/frameworks/PerceptualProjection.js +142 -0
- package/dist/charts/frameworks/PositioningSamples.js +191 -0
- package/dist/charts/frameworks/RaciMatrix.js +458 -0
- package/dist/charts/frameworks/RaciPlan.js +81 -0
- package/dist/charts/frameworks/RaciSamples.js +76 -0
- package/dist/charts/frameworks/SwotMatrix.js +358 -0
- package/dist/charts/frameworks/SwotSamples.js +85 -0
- package/dist/charts/frameworks/VanWestendorpChart.js +187 -0
- package/dist/charts/frameworks/VanWestendorpSurvey.js +197 -0
- package/dist/charts/frameworks/index.js +26 -0
- package/dist/charts/frameworks/raciEnums.js +30 -0
- package/dist/charts/frameworks/swotEnums.js +34 -0
- package/dist/charts/genomics/CircosPlot.js +1 -1
- package/dist/charts/geoflows/GeoFlowChart.js +2 -2
- package/dist/charts/geoflows/GeoFlowSample.js +2 -1
- package/dist/charts/geomaps/FloorPlanMap.js +324 -0
- package/dist/charts/geomaps/FloorPlanModel.js +179 -0
- package/dist/charts/geomaps/FloorPlanSamples.js +416 -0
- package/dist/charts/geomaps/GeoLand.js +2 -2
- package/dist/charts/geomaps/GeoSamples.js +2 -1
- package/dist/charts/geomaps/GraticuleMap.js +2 -2
- package/dist/charts/geomaps/RoomLabelFit.js +200 -0
- package/dist/charts/geomaps/TissotMap.js +2 -2
- package/dist/charts/geomaps/index.js +8 -4
- package/dist/charts/hierarchy/SunburstChart.js +17 -10
- package/dist/charts/hierarchy/index.js +2 -11
- package/dist/charts/indicators/BulletChart.js +8 -2
- package/dist/charts/indicators/SpeedometerChart.js +1 -1
- package/dist/charts/indicators/ThermometerChart.js +1 -1
- package/dist/charts/lifescience/LoessFit.js +113 -0
- package/dist/charts/lifescience/MaPlot.js +337 -0
- package/dist/charts/lifescience/MaPlotSamples.js +35 -0
- package/dist/charts/lifescience/OncoGlyph.js +137 -0
- package/dist/charts/lifescience/OncoPrint.js +373 -0
- package/dist/charts/lifescience/OncoPrintMatrix.js +107 -0
- package/dist/charts/lifescience/OncoPrintSamples.js +142 -0
- package/dist/charts/lifescience/PedigreeChart.js +306 -0
- package/dist/charts/lifescience/PedigreeLayout.js +261 -0
- package/dist/charts/lifescience/PedigreeRows.js +70 -0
- package/dist/charts/lifescience/PedigreeSamples.js +161 -0
- package/dist/charts/lifescience/PedigreeSymbol.js +47 -0
- package/dist/charts/lifescience/RamachandranPlot.js +364 -0
- package/dist/charts/lifescience/RamachandranRegions.js +2712 -0
- package/dist/charts/lifescience/RamachandranSamples.js +235 -0
- package/dist/charts/lifescience/index.js +25 -0
- package/dist/charts/lifescience/pedigreeEnums.js +21 -0
- package/dist/charts/lifescience/ramachandranEnums.js +34 -0
- package/dist/charts/linesareas/DualAxisChart.js +1 -1
- package/dist/charts/linesareas/LineEnums.js +1 -15
- package/dist/charts/linesareas/MultiLineChart.js +1 -1
- package/dist/charts/linesareas/TrendChart.js +15 -5
- package/dist/charts/linesareas/index.js +2 -6
- package/dist/charts/massive/MassiveChart.js +3 -2
- package/dist/charts/mathematical/FourierSeriesChart.js +7 -1
- package/dist/charts/mathematical/index.js +2 -6
- package/dist/charts/matrix/GridPlot.js +27 -2
- package/dist/charts/matrix/TilegramChart.js +2 -2
- package/dist/charts/mlcharts/AttentionGrid.js +79 -0
- package/dist/charts/mlcharts/AttentionHeatmap.js +329 -0
- package/dist/charts/mlcharts/AttentionModel.js +132 -0
- package/dist/charts/mlcharts/AttentionSamples.js +82 -0
- package/dist/charts/mlcharts/CellNumber.js +8 -0
- package/dist/charts/mlcharts/CurveDiagnosticSamples.js +95 -0
- package/dist/charts/mlcharts/CurvePickMark.js +31 -0
- package/dist/charts/mlcharts/DecisionBoundaryChart.js +316 -0
- package/dist/charts/mlcharts/DecisionSamples.js +60 -0
- package/dist/charts/mlcharts/DecisionSurface.js +130 -0
- package/dist/charts/mlcharts/DistinctTicks.js +13 -0
- package/dist/charts/mlcharts/ElbowMath.js +153 -0
- package/dist/charts/mlcharts/ElbowPlot.js +273 -0
- package/dist/charts/mlcharts/ExplainabilitySamples.js +70 -0
- package/dist/charts/mlcharts/FeatureImportanceChart.js +150 -0
- package/dist/charts/mlcharts/ImportanceRanking.js +98 -0
- package/dist/charts/mlcharts/LearningCurveChart.js +276 -0
- package/dist/charts/mlcharts/LearningCurveMath.js +92 -0
- package/dist/charts/mlcharts/PartialDependence.js +92 -0
- package/dist/charts/mlcharts/PartialDependencePlot.js +225 -0
- package/dist/charts/mlcharts/WideLabel.js +28 -0
- package/dist/charts/mlcharts/curveDiagnosticEnums.js +37 -0
- package/dist/charts/mlcharts/index.js +32 -0
- package/dist/charts/proportion/index.js +5 -9
- package/dist/charts/scatter/CategoryScatterBase.js +1 -4
- package/dist/charts/scatter/ConnectedScatter.js +7 -4
- package/dist/charts/scatter/MarginalScatter.js +13 -8
- package/dist/charts/scatter/index.js +4 -17
- package/dist/charts/scientific/SpectrogramChart.js +9 -3
- package/dist/charts/scientific/index.js +2 -2
- package/dist/charts/signals/index.js +3 -13
- package/dist/charts/statistics/LorenzCurve.js +7 -4
- package/dist/charts/threebars/Candlestick3DChart.js +18 -2
- package/dist/charts/threeglobe/GlobeChart.js +2 -2
- package/dist/charts/threeglobe/GlobeSamples.js +2 -1
- package/dist/charts/threeglobe/RingGlobe.js +1 -1
- package/dist/charts/threenetwork/ConeTreeChart.js +2 -1
- package/dist/charts/threenetwork/Gantt3DChart.js +3 -2
- package/dist/charts/threesurfaces/Ridgeline3DChart.js +22 -4
- package/dist/charts/threevolume/LorenzAttractor.js +19 -0
- package/dist/charts/threevolume/VolumeRaycastChart.js +4 -3
- package/dist/charts/threevolume/volumeEnums.js +1 -0
- package/dist/charts/timeline/index.js +2 -10
- package/dist/chunk-753UBLV2.cjs +33 -0
- package/dist/chunk-VX54A7KA.cjs +17 -0
- package/dist/{chunk-W5GAAAZY.cjs → chunk-WAODDPYX.cjs} +24874 -17620
- package/dist/chunk-Z3JPIJSC.cjs +338 -0
- package/dist/core/CartesianChart.js +87 -11
- package/dist/core/Chart.js +63 -15
- package/dist/core/Chart2D.js +54 -17
- package/dist/core/Chart3D.js +56 -20
- package/dist/core/ChartExportError.js +2 -0
- package/dist/core/ChartExporter.js +50 -8
- package/dist/core/ColumnCheck.js +53 -0
- package/dist/core/Context2D.js +29 -15
- package/dist/core/Context3D.js +7 -2
- package/dist/core/ExcelWriter.js +152 -0
- package/dist/core/ExportText.js +28 -0
- package/dist/core/MarkOrigin.js +88 -0
- package/dist/core/MarkStyle.js +294 -0
- package/dist/core/Palette.js +27 -7
- package/dist/core/PdfPage.js +13 -0
- package/dist/core/PdfWriter.js +245 -0
- package/dist/core/Scales.js +52 -2
- package/dist/core/SceneOverlay.js +4 -4
- package/dist/core/TextFit.js +37 -0
- package/dist/core/Theme.js +28 -1
- package/dist/core/enums.js +33 -1
- package/dist/core/pathMorph.js +15 -0
- package/dist/data/SampleData.js +1 -17
- package/dist/data/WorldSample.js +23 -0
- package/dist/index.cjs +810 -691
- package/dist/index.d.cts +8390 -2925
- package/dist/index.d.ts +8392 -2927
- package/dist/index.js +106 -56
- package/dist/react/ChartView.js +18 -8
- package/dist/react/GraphHandle.js +2 -0
- package/dist/react/components.js +74 -116
- package/package.json +13 -3
- package/dist/catalog-4UP2YFNR.cjs +0 -7
- package/dist/charts/bars/BulletBar.js +0 -184
- package/dist/charts/bars/ErrorBarColumn.js +0 -147
- package/dist/charts/bars/HistogramBar.js +0 -217
- package/dist/charts/bars/MarimekkoBar.js +0 -191
- package/dist/charts/bars/ParetoBar.js +0 -143
- package/dist/charts/comparison/PanelChart.js +0 -70
- package/dist/charts/comparison/SmallMultipleBars.js +0 -134
- package/dist/charts/comparison/SpanChart.js +0 -118
- package/dist/charts/comparison/TrellisChart.js +0 -158
- package/dist/charts/distribution/RidgeSlabs3DChart.js +0 -169
- package/dist/charts/financial/Candlestick3D.js +0 -157
- package/dist/charts/flow/BumpFlow.js +0 -212
- package/dist/charts/flow/StreamFlow.js +0 -174
- package/dist/charts/geomaps/ThiessenMap.js +0 -106
- package/dist/charts/hierarchy/ConeTree3D.js +0 -135
- package/dist/charts/hierarchy/Hierarchy3DChart.js +0 -27
- package/dist/charts/hierarchy/SpherePack3D.js +0 -81
- package/dist/charts/hierarchy/SunburstTower3D.js +0 -93
- package/dist/charts/hierarchy/TreemapSkyline3D.js +0 -98
- package/dist/charts/linesareas/ConnectedScatterTime.js +0 -206
- package/dist/charts/linesareas/SmallMultipleLines.js +0 -153
- package/dist/charts/mathematical/ParametricSurface3D.js +0 -234
- package/dist/charts/mathematical/StrangeAttractor3D.js +0 -251
- package/dist/charts/proportion/ConeFunnel.js +0 -126
- package/dist/charts/proportion/ExtrudedPieChart.js +0 -123
- package/dist/charts/scatter/BeeswarmScatter.js +0 -151
- package/dist/charts/scatter/BinnedScatterBase.js +0 -51
- package/dist/charts/scatter/ContourScatter.js +0 -116
- package/dist/charts/scatter/GridBinScatter.js +0 -98
- package/dist/charts/scatter/HexbinScatter.js +0 -74
- package/dist/charts/scatter/StripScatter.js +0 -107
- package/dist/charts/scatter/SunflowerScatter.js +0 -109
- package/dist/charts/signals/ConstellationChart.js +0 -153
- package/dist/charts/signals/CorrelogramChart.js +0 -171
- package/dist/charts/signals/EyeDiagramChart.js +0 -155
- package/dist/charts/signals/PoleZeroChart.js +0 -164
- package/dist/charts/signals/SpectrogramChart.js +0 -79
- package/dist/charts/timeline/CalendarSkylineChart.js +0 -128
- package/dist/charts/timeline/ScheduleBlocksChart.js +0 -119
- package/dist/charts/timeline/SpiralTimeline.js +0 -154
- 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 };
|