smithkit 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 +124 -59
- package/dist/lib/MarkerMeasurements.d.ts +6 -0
- package/dist/lib/MarkerMeasurements.js +22 -0
- package/dist/lib/Smith.d.ts +9 -2
- package/dist/lib/Smith.js +78 -35
- package/dist/lib/SmithFormatter.d.ts +10 -0
- package/dist/lib/SmithFormatter.js +19 -0
- package/dist/lib/grid/CircleLayerControl.d.ts +15 -0
- package/dist/lib/grid/CircleLayerControl.js +40 -0
- package/dist/lib/{draw → grid}/ConstCircles.d.ts +6 -6
- package/dist/lib/{draw → grid}/ConstCircles.js +12 -5
- package/dist/lib/{draw → grid}/ConstQCircles.d.ts +2 -2
- package/dist/lib/{draw → grid}/ConstQCircles.js +3 -3
- package/dist/lib/{draw → grid}/ConstSwrCircles.d.ts +2 -2
- package/dist/lib/{draw → grid}/ConstSwrCircles.js +3 -3
- package/dist/lib/grid/GridDefinitions.d.ts +12 -0
- package/dist/lib/grid/GridDefinitions.js +138 -0
- package/dist/lib/grid/GridGeometry.d.ts +26 -0
- package/dist/lib/grid/GridGeometry.js +58 -0
- package/dist/lib/grid/GridLabels.d.ts +8 -0
- package/dist/lib/grid/GridLabels.js +45 -0
- package/dist/lib/grid/GridLayerControl.d.ts +12 -0
- package/dist/lib/grid/GridLayerControl.js +39 -0
- package/dist/lib/grid/LayerControl.d.ts +6 -0
- package/dist/lib/grid/LayerControl.js +16 -0
- package/dist/lib/{draw → grid}/SmithGridLayer.d.ts +5 -4
- package/dist/lib/{draw → grid}/SmithGridLayer.js +26 -9
- package/dist/lib/grid/types.d.ts +1 -1
- package/dist/lib/index.d.ts +8 -10
- package/dist/lib/index.js +5 -7
- package/dist/lib/{draw → interaction}/SmithCursor.d.ts +3 -3
- package/dist/lib/{draw → interaction}/SmithCursor.js +6 -6
- package/dist/lib/io/Touchstone.d.ts +10 -0
- package/dist/lib/io/Touchstone.js +75 -0
- package/dist/lib/layers.d.ts +2 -8
- package/dist/lib/layers.js +1 -73
- package/dist/lib/{complex → math}/Complex.d.ts +1 -0
- package/dist/lib/{complex → math}/Complex.js +1 -1
- package/dist/lib/math/geometry.d.ts +14 -0
- package/dist/lib/measurements.d.ts +2 -4
- package/dist/lib/measurements.js +1 -19
- package/dist/lib/rf/RfCalculations.d.ts +65 -0
- package/dist/lib/rf/RfCalculations.js +161 -0
- package/dist/lib/{SmithConstantCircle.d.ts → rf/SmithConstantCircle.d.ts} +2 -3
- package/dist/lib/{SmithConstantCircle.js → rf/SmithConstantCircle.js} +3 -4
- package/dist/lib/scales/PeripheralScaleDefinitions.d.ts +16 -0
- package/dist/lib/scales/PeripheralScaleDefinitions.js +54 -0
- package/dist/lib/scales/RadialScaleDefinitions.d.ts +15 -0
- package/dist/lib/scales/RadialScaleDefinitions.js +112 -0
- package/dist/lib/scales/SmithPeripheralScales.d.ts +7 -2
- package/dist/lib/scales/SmithPeripheralScales.js +65 -28
- package/dist/lib/scales/SmithScales.d.ts +3 -1
- package/dist/lib/scales/SmithScales.js +20 -6
- package/dist/lib/svg/LabelLayout.d.ts +17 -0
- package/dist/lib/svg/LabelLayout.js +145 -0
- package/dist/lib/{draw → svg}/SmithArc.d.ts +1 -1
- package/dist/lib/{draw → svg}/SmithCircle.d.ts +1 -1
- package/dist/lib/{draw → svg}/SmithLine.d.ts +1 -1
- package/dist/lib/{draw → svg}/SmithScaler.d.ts +1 -4
- package/dist/lib/{draw → svg}/SmithText.d.ts +1 -1
- package/dist/lib/svg/SvgExporter.d.ts +14 -0
- package/dist/lib/svg/SvgExporter.js +137 -0
- package/dist/lib/{draw → traces}/SmithData.d.ts +24 -35
- package/dist/lib/traces/SmithData.js +195 -0
- package/dist/lib/{draw → traces}/SmithMarker.d.ts +14 -3
- package/dist/lib/traces/SmithMarker.js +237 -0
- package/dist/lib/traces/TraceModel.d.ts +31 -0
- package/dist/lib/traces/TraceModel.js +123 -0
- package/dist/lib/traces/TraceRenderer.d.ts +33 -0
- package/dist/lib/traces/TraceRenderer.js +152 -0
- package/package.json +4 -1
- package/dist/lib/SmithArcsDefs.d.ts +0 -10
- package/dist/lib/SmithArcsDefs.js +0 -10
- package/dist/lib/components.d.ts +0 -14
- package/dist/lib/components.js +0 -26
- package/dist/lib/draw/SmithData.js +0 -366
- package/dist/lib/draw/SmithMarker.js +0 -122
- package/dist/lib/formatting.d.ts +0 -7
- package/dist/lib/formatting.js +0 -16
- package/dist/lib/grid/definitions.d.ts +0 -3
- package/dist/lib/grid/definitions.js +0 -123
- package/dist/lib/grid/geometry.d.ts +0 -20
- package/dist/lib/grid/geometry.js +0 -55
- package/dist/lib/grid/labels.d.ts +0 -3
- package/dist/lib/grid/labels.js +0 -41
- package/dist/lib/io/touchstone.d.ts +0 -7
- package/dist/lib/io/touchstone.js +0 -72
- package/dist/lib/math/complexRatio.d.ts +0 -3
- package/dist/lib/math/complexRatio.js +0 -30
- package/dist/lib/renormalization.d.ts +0 -10
- package/dist/lib/renormalization.js +0 -62
- package/dist/lib/rf.d.ts +0 -35
- package/dist/lib/rf.js +0 -74
- package/dist/lib/scales/peripheralScales.d.ts +0 -12
- package/dist/lib/scales/peripheralScales.js +0 -49
- package/dist/lib/scales/radialScales.d.ts +0 -12
- package/dist/lib/scales/radialScales.js +0 -109
- package/dist/lib/shapes/Arc.d.ts +0 -6
- package/dist/lib/shapes/Circle.d.ts +0 -5
- package/dist/lib/shapes/Circle.js +0 -1
- package/dist/lib/shapes/Line.d.ts +0 -5
- package/dist/lib/shapes/Line.js +0 -1
- package/dist/lib/shapes/Point.d.ts +0 -1
- package/dist/lib/shapes/Point.js +0 -1
- /package/dist/lib/{draw → grid}/ConstConductance.d.ts +0 -0
- /package/dist/lib/{draw → grid}/ConstConductance.js +0 -0
- /package/dist/lib/{draw → grid}/ConstReactance.d.ts +0 -0
- /package/dist/lib/{draw → grid}/ConstReactance.js +0 -0
- /package/dist/lib/{draw → grid}/ConstResistance.d.ts +0 -0
- /package/dist/lib/{draw → grid}/ConstResistance.js +0 -0
- /package/dist/lib/{draw → grid}/ConstSusceptance.d.ts +0 -0
- /package/dist/lib/{draw → grid}/ConstSusceptance.js +0 -0
- /package/dist/lib/{arcs → grid}/Tick.d.ts +0 -0
- /package/dist/lib/{arcs → grid}/Tick.js +0 -0
- /package/dist/lib/{draw → interaction}/MouseGesture.d.ts +0 -0
- /package/dist/lib/{draw → interaction}/MouseGesture.js +0 -0
- /package/dist/lib/{draw/SmithDrawOptions.js → math/geometry.js} +0 -0
- /package/dist/lib/{draw → svg}/SmithArc.js +0 -0
- /package/dist/lib/{draw → svg}/SmithCircle.js +0 -0
- /package/dist/lib/{draw → svg}/SmithDrawOptions.d.ts +0 -0
- /package/dist/lib/{shapes/Arc.js → svg/SmithDrawOptions.js} +0 -0
- /package/dist/lib/{draw → svg}/SmithGroup.d.ts +0 -0
- /package/dist/lib/{draw → svg}/SmithGroup.js +0 -0
- /package/dist/lib/{draw → svg}/SmithLine.js +0 -0
- /package/dist/lib/{draw → svg}/SmithPath.d.ts +0 -0
- /package/dist/lib/{draw → svg}/SmithPath.js +0 -0
- /package/dist/lib/{draw → svg}/SmithScaler.js +0 -0
- /package/dist/lib/{draw → svg}/SmithShape.d.ts +0 -0
- /package/dist/lib/{draw → svg}/SmithShape.js +0 -0
- /package/dist/lib/{draw → svg}/SmithSvg.d.ts +0 -0
- /package/dist/lib/{draw → svg}/SmithSvg.js +0 -0
- /package/dist/lib/{draw → svg}/SmithText.js +0 -0
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import { SmithConstantCircle } from '../rf/SmithConstantCircle.js';
|
|
2
|
+
import { Complex } from '../math/Complex.js';
|
|
3
|
+
export class GridGeometry {
|
|
4
|
+
constructor() { }
|
|
5
|
+
static calcs = new SmithConstantCircle();
|
|
6
|
+
static circles = {
|
|
7
|
+
resistance: (value) => GridGeometry.calcs.resistanceCircle(value),
|
|
8
|
+
reactance: (value) => GridGeometry.calcs.reactanceCircle(value),
|
|
9
|
+
conductance: (value) => GridGeometry.calcs.conductanceCircle(value),
|
|
10
|
+
susceptance: (value) => GridGeometry.calcs.susceptanceCircle(value),
|
|
11
|
+
};
|
|
12
|
+
static clipping = {
|
|
13
|
+
resistance: 'reactance',
|
|
14
|
+
reactance: 'resistance',
|
|
15
|
+
conductance: 'susceptance',
|
|
16
|
+
susceptance: 'conductance',
|
|
17
|
+
};
|
|
18
|
+
/** Normalized geometry only: no DOM, D3, or pixel coordinates. */
|
|
19
|
+
static shapes(kind, data) {
|
|
20
|
+
const circle = GridGeometry.circles[kind];
|
|
21
|
+
const clip = GridGeometry.circles[GridGeometry.clipping[kind]];
|
|
22
|
+
return {
|
|
23
|
+
lines: data.lines,
|
|
24
|
+
circles: data.circles.map(circle),
|
|
25
|
+
arcs: data.arcs.map(([value, limits, options]) => {
|
|
26
|
+
const c = circle(value);
|
|
27
|
+
const [a, b] = limits.map(([limit, index]) => GridGeometry.calcs.circleCircleIntersection(c, clip(limit))[index]);
|
|
28
|
+
return [a, b, c.r, options[0], options[1]];
|
|
29
|
+
}),
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
static label(kind, definition) {
|
|
33
|
+
const { point, transform, dp, textAnchor, dominantBaseline } = definition;
|
|
34
|
+
const admittance = kind === 'conductance' || kind === 'susceptance';
|
|
35
|
+
const real = kind === 'resistance' || kind === 'conductance';
|
|
36
|
+
const rc = admittance
|
|
37
|
+
? GridGeometry.calcs.admittanceToRflCoeff(Complex.from(point.r, point.i))
|
|
38
|
+
: GridGeometry.calcs.impedanceToRflCoeff(Complex.from(point.r, point.i));
|
|
39
|
+
if (!rc) {
|
|
40
|
+
throw new Error('Invalid grid label coordinates.');
|
|
41
|
+
}
|
|
42
|
+
const value = real ? point.r : point.i;
|
|
43
|
+
const circle = GridGeometry.circles[kind](value);
|
|
44
|
+
let rotate = -GridGeometry.calcs.tangentToCircleAngle(circle, rc.toVector()) + transform.rotate;
|
|
45
|
+
if (admittance && rotate !== 90) {
|
|
46
|
+
rotate += 180;
|
|
47
|
+
}
|
|
48
|
+
return {
|
|
49
|
+
point: rc.toVector(),
|
|
50
|
+
text: value.toFixed(dp),
|
|
51
|
+
rotate,
|
|
52
|
+
dx: transform.dx,
|
|
53
|
+
dy: transform.dy,
|
|
54
|
+
textAnchor,
|
|
55
|
+
dominantBaseline,
|
|
56
|
+
};
|
|
57
|
+
}
|
|
58
|
+
}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { Tick } from './Tick.js';
|
|
2
|
+
export class GridLabels {
|
|
3
|
+
constructor() { }
|
|
4
|
+
static values = [
|
|
5
|
+
0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9, 1, 1.2, 1.4, 1.6, 1.8, 2, 3, 4, 5, 10, 20, 50,
|
|
6
|
+
];
|
|
7
|
+
static interiorValues = [0.2, 0.4, 0.6, 0.8, 1];
|
|
8
|
+
static resistance() {
|
|
9
|
+
const axis = [0, ...GridLabels.values].map((r) => new Tick({
|
|
10
|
+
point: { r, i: 0 },
|
|
11
|
+
dp: r === 0 || r >= 10 ? 0 : 1,
|
|
12
|
+
// Keep the zero inside the rim and clear of the opposite grid's high-value labels.
|
|
13
|
+
transform: { dx: r === 0 ? 0.02 : 0.005, dy: r === 0 ? 0.02 : -0.005 },
|
|
14
|
+
dominantBaseline: r === 0 ? 'hanging' : 'baseline',
|
|
15
|
+
}));
|
|
16
|
+
const interior = [1, -1].flatMap((i) => [...GridLabels.interiorValues].reverse().map((r) => new Tick({
|
|
17
|
+
point: { r, i },
|
|
18
|
+
dp: 1,
|
|
19
|
+
transform: { dx: i * 0.005, dy: -0.005, rotate: i < 0 ? 180 : 0 },
|
|
20
|
+
textAnchor: i < 0 ? 'end' : 'start',
|
|
21
|
+
})));
|
|
22
|
+
return [...axis, ...interior];
|
|
23
|
+
}
|
|
24
|
+
static reactance() {
|
|
25
|
+
return [1, -1].flatMap((sign) => [
|
|
26
|
+
...GridLabels.interiorValues.map((i) => ({ r: 1, i: sign * i })),
|
|
27
|
+
...GridLabels.values.map((i) => ({ r: 0, i: sign * i })),
|
|
28
|
+
].map((point) => new Tick({
|
|
29
|
+
point,
|
|
30
|
+
dp: Math.abs(point.i) >= 10 ? 0 : 1,
|
|
31
|
+
transform: {
|
|
32
|
+
dx: -sign * 0.005,
|
|
33
|
+
dy: -0.005,
|
|
34
|
+
rotate: sign > 0
|
|
35
|
+
? point.r === 1 || point.i < 1
|
|
36
|
+
? 180
|
|
37
|
+
: 0
|
|
38
|
+
: point.r === 0 && point.i < -1
|
|
39
|
+
? 180
|
|
40
|
+
: 0,
|
|
41
|
+
},
|
|
42
|
+
textAnchor: sign > 0 ? 'end' : 'start',
|
|
43
|
+
})));
|
|
44
|
+
}
|
|
45
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { ConstCircles } from './ConstCircles.js';
|
|
2
|
+
import type { GridLayer, GridStyle } from '../layers.js';
|
|
3
|
+
import { LayerControl } from './LayerControl.js';
|
|
4
|
+
/** Exposes grid controls without exposing the SVG renderer. */
|
|
5
|
+
export declare class GridLayerControl extends LayerControl implements GridLayer {
|
|
6
|
+
private readonly layer;
|
|
7
|
+
private readonly changed;
|
|
8
|
+
constructor(layer: ConstCircles, assertAlive: () => void, changed: () => void);
|
|
9
|
+
setVisible(visible: boolean): void;
|
|
10
|
+
setMinorVisible(visible: boolean): void;
|
|
11
|
+
setStyle(style: Partial<GridStyle>): void;
|
|
12
|
+
}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { LayerControl } from './LayerControl.js';
|
|
2
|
+
/** Exposes grid controls without exposing the SVG renderer. */
|
|
3
|
+
export class GridLayerControl extends LayerControl {
|
|
4
|
+
layer;
|
|
5
|
+
changed;
|
|
6
|
+
constructor(layer, assertAlive, changed) {
|
|
7
|
+
super(assertAlive);
|
|
8
|
+
this.layer = layer;
|
|
9
|
+
this.changed = changed;
|
|
10
|
+
}
|
|
11
|
+
setVisible(visible) {
|
|
12
|
+
this.assertAlive();
|
|
13
|
+
this.layer.visibility(visible);
|
|
14
|
+
this.changed();
|
|
15
|
+
}
|
|
16
|
+
setMinorVisible(visible) {
|
|
17
|
+
this.assertAlive();
|
|
18
|
+
this.layer.displayMinor(visible);
|
|
19
|
+
}
|
|
20
|
+
setStyle(style) {
|
|
21
|
+
this.assertAlive();
|
|
22
|
+
this.validateLengths(style, ['majorWidth', 'minorWidth', 'textFontSize']);
|
|
23
|
+
const properties = {
|
|
24
|
+
stroke: 'Stroke',
|
|
25
|
+
majorWidth: 'MajorWidth',
|
|
26
|
+
minorWidth: 'MinorWidth',
|
|
27
|
+
textColor: 'TextColor',
|
|
28
|
+
textFontFamily: 'TextFontFamily',
|
|
29
|
+
textFontSize: 'TextFontSize',
|
|
30
|
+
};
|
|
31
|
+
for (const key of Object.keys(properties)) {
|
|
32
|
+
const value = style[key];
|
|
33
|
+
if (value !== undefined) {
|
|
34
|
+
this.layer[properties[key]] = String(value);
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
this.changed();
|
|
38
|
+
}
|
|
39
|
+
}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
/** Shared lifecycle and style validation for chart layer adapters. */
|
|
2
|
+
export declare abstract class LayerControl {
|
|
3
|
+
protected readonly assertAlive: () => void;
|
|
4
|
+
protected constructor(assertAlive: () => void);
|
|
5
|
+
protected validateLengths<T>(style: T, keys: readonly (keyof T)[]): void;
|
|
6
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/** Shared lifecycle and style validation for chart layer adapters. */
|
|
2
|
+
export class LayerControl {
|
|
3
|
+
assertAlive;
|
|
4
|
+
constructor(assertAlive) {
|
|
5
|
+
this.assertAlive = assertAlive;
|
|
6
|
+
}
|
|
7
|
+
validateLengths(style, keys) {
|
|
8
|
+
for (const key of keys) {
|
|
9
|
+
const value = style[key];
|
|
10
|
+
if (value !== undefined &&
|
|
11
|
+
(typeof value !== 'number' || !Number.isFinite(value) || value <= 0)) {
|
|
12
|
+
throw new RangeError(`${String(key)} must be a positive finite number.`);
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { ConstCircles } from './ConstCircles.js';
|
|
2
|
-
import { SmithGroup } from '
|
|
3
|
-
import type { SmithScaler } from '
|
|
4
|
-
import type { SmithTicksData } from '
|
|
5
|
-
import { type GridKind } from '
|
|
2
|
+
import { SmithGroup } from '../svg/SmithGroup.js';
|
|
3
|
+
import type { SmithScaler } from '../svg/SmithScaler.js';
|
|
4
|
+
import type { SmithTicksData } from './types.js';
|
|
5
|
+
import { type GridKind } from './GridGeometry.js';
|
|
6
6
|
export interface GridLayerParams {
|
|
7
7
|
scaler: SmithScaler;
|
|
8
8
|
showMinor: boolean;
|
|
@@ -15,5 +15,6 @@ export declare class SmithGridLayer extends ConstCircles {
|
|
|
15
15
|
protected minor: SmithGroup;
|
|
16
16
|
protected texts: SmithGroup;
|
|
17
17
|
constructor(params: GridLayerParams, kind: GridKind);
|
|
18
|
+
private static labelPriority;
|
|
18
19
|
private drawGrid;
|
|
19
20
|
}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { ConstCircles } from './ConstCircles.js';
|
|
2
|
-
import { SmithGroup } from '
|
|
3
|
-
import { SmithText } from '
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
2
|
+
import { SmithGroup } from '../svg/SmithGroup.js';
|
|
3
|
+
import { SmithText } from '../svg/SmithText.js';
|
|
4
|
+
import { GridGeometry } from './GridGeometry.js';
|
|
5
|
+
import { GridLabels } from './GridLabels.js';
|
|
6
6
|
/** SVG adapter shared by the four constant impedance/admittance layers. */
|
|
7
7
|
export class SmithGridLayer extends ConstCircles {
|
|
8
8
|
kind;
|
|
@@ -20,23 +20,40 @@ export class SmithGridLayer extends ConstCircles {
|
|
|
20
20
|
.attr('stroke', 'none')
|
|
21
21
|
.attr('font-size', '7')
|
|
22
22
|
.attr('font-family', 'Verdana');
|
|
23
|
-
for (const tick of real ?
|
|
24
|
-
const label =
|
|
25
|
-
|
|
23
|
+
for (const tick of real ? GridLabels.resistance() : GridLabels.reactance()) {
|
|
24
|
+
const label = GridGeometry.label(kind, tick.definition);
|
|
25
|
+
const text = new SmithText(this.scaler.point(label.point), label.text, {
|
|
26
26
|
rotate: label.rotate,
|
|
27
27
|
dx: this.scaler.r(label.dx).toString(),
|
|
28
28
|
dy: this.scaler.r(label.dy).toString(),
|
|
29
29
|
textAnchor: label.textAnchor,
|
|
30
30
|
dominantBaseline: label.dominantBaseline,
|
|
31
|
-
})
|
|
31
|
+
});
|
|
32
|
+
text.Element.attr('data-label-priority', SmithGridLayer.labelPriority(tick.definition.point.r, tick.definition.point.i));
|
|
33
|
+
this.texts.append(text);
|
|
32
34
|
}
|
|
33
35
|
this.build();
|
|
34
36
|
if (!params.showMinor) {
|
|
35
37
|
this.minor.hide();
|
|
36
38
|
}
|
|
37
39
|
}
|
|
40
|
+
static labelPriority(real, imaginary) {
|
|
41
|
+
const value = Math.abs(imaginary === 0 ? real : imaginary);
|
|
42
|
+
const importance = value === 0
|
|
43
|
+
? 300
|
|
44
|
+
: value === 1
|
|
45
|
+
? 100
|
|
46
|
+
: value === 50
|
|
47
|
+
? 90
|
|
48
|
+
: [0.5, 2].includes(value)
|
|
49
|
+
? 80
|
|
50
|
+
: [0.2, 5, 10].includes(value)
|
|
51
|
+
? 70
|
|
52
|
+
: 40;
|
|
53
|
+
return importance + (imaginary === 0 ? 20 : real === 0 ? 10 : 0);
|
|
54
|
+
}
|
|
38
55
|
drawGrid(definitions, width) {
|
|
39
|
-
const geometry =
|
|
56
|
+
const geometry = GridGeometry.shapes(this.kind, definitions);
|
|
40
57
|
const group = new SmithGroup();
|
|
41
58
|
this.drawShapes(group.Element, this.opts.stroke, width, {
|
|
42
59
|
lines: geometry.lines.map((line) => this.scaler.line(line)),
|
package/dist/lib/grid/types.d.ts
CHANGED
package/dist/lib/index.d.ts
CHANGED
|
@@ -1,16 +1,14 @@
|
|
|
1
1
|
export { Smith, SmithEventType } from './Smith.js';
|
|
2
2
|
export type { SmithEvent } from './Smith.js';
|
|
3
|
-
export { Complex } from './
|
|
3
|
+
export { Complex } from './math/Complex.js';
|
|
4
4
|
export type { TraceSamples, TraceSample } from './samples.js';
|
|
5
|
-
export {
|
|
6
|
-
export type { TouchstoneData } from './io/
|
|
5
|
+
export { Touchstone } from './io/Touchstone.js';
|
|
6
|
+
export type { TouchstoneData } from './io/Touchstone.js';
|
|
7
7
|
export { SmithScales } from './scales/SmithScales.js';
|
|
8
|
-
export {
|
|
8
|
+
export { MarkerMeasurements } from './MarkerMeasurements.js';
|
|
9
9
|
export type { TraceOptions, TraceUpdateOptions, MarkerSelectionStrategy, TraceStyle, TraceRenderMode, TraceInfo, MarkerInfo, MarkerSnapshot, MarkerComparison, } from './measurements.js';
|
|
10
|
-
export {
|
|
11
|
-
export type { SmithReading } from './rf.js';
|
|
10
|
+
export { RfCalculations } from './rf/RfCalculations.js';
|
|
11
|
+
export type { SmithReading } from './rf/RfCalculations.js';
|
|
12
12
|
export type { GridStyle, CircleStyle, GridLayer, CircleLayer, ChartLayers, PeripheralScales, } from './layers.js';
|
|
13
|
-
export {
|
|
14
|
-
export {
|
|
15
|
-
export { reactanceToComponent } from './components.js';
|
|
16
|
-
export type { ReactiveComponent } from './components.js';
|
|
13
|
+
export { SmithFormatter } from './SmithFormatter.js';
|
|
14
|
+
export type { ReactiveComponent } from './rf/RfCalculations.js';
|
package/dist/lib/index.js
CHANGED
|
@@ -1,9 +1,7 @@
|
|
|
1
1
|
export { Smith, SmithEventType } from './Smith.js';
|
|
2
|
-
export { Complex } from './
|
|
3
|
-
export {
|
|
2
|
+
export { Complex } from './math/Complex.js';
|
|
3
|
+
export { Touchstone } from './io/Touchstone.js';
|
|
4
4
|
export { SmithScales } from './scales/SmithScales.js';
|
|
5
|
-
export {
|
|
6
|
-
export {
|
|
7
|
-
export {
|
|
8
|
-
export { formatNumber, formatComplex, formatComplexPolar } from './formatting.js';
|
|
9
|
-
export { reactanceToComponent } from './components.js';
|
|
5
|
+
export { MarkerMeasurements } from './MarkerMeasurements.js';
|
|
6
|
+
export { RfCalculations } from './rf/RfCalculations.js';
|
|
7
|
+
export { SmithFormatter } from './SmithFormatter.js';
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { SmithGroup } from '
|
|
2
|
-
import { SmithScaler } from '
|
|
3
|
-
import { Complex } from '../
|
|
1
|
+
import { SmithGroup } from '../svg/SmithGroup.js';
|
|
2
|
+
import { SmithScaler } from '../svg/SmithScaler.js';
|
|
3
|
+
import { Complex } from '../math/Complex.js';
|
|
4
4
|
interface DrawOptions {
|
|
5
5
|
point: {
|
|
6
6
|
radius: number;
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import { SmithGroup } from '
|
|
2
|
-
import { SmithCircle } from '
|
|
3
|
-
import { SmithLine } from '
|
|
4
|
-
import { SmithArc } from '
|
|
5
|
-
import { SmithConstantCircle } from '../SmithConstantCircle.js';
|
|
6
|
-
import { Complex } from '../
|
|
1
|
+
import { SmithGroup } from '../svg/SmithGroup.js';
|
|
2
|
+
import { SmithCircle } from '../svg/SmithCircle.js';
|
|
3
|
+
import { SmithLine } from '../svg/SmithLine.js';
|
|
4
|
+
import { SmithArc } from '../svg/SmithArc.js';
|
|
5
|
+
import { SmithConstantCircle } from '../rf/SmithConstantCircle.js';
|
|
6
|
+
import { Complex } from '../math/Complex.js';
|
|
7
7
|
export class SmithCursor {
|
|
8
8
|
scaler;
|
|
9
9
|
epsilon = 1.5e-4;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { TraceSamples } from '../samples.js';
|
|
2
|
+
export interface TouchstoneData {
|
|
3
|
+
samples: TraceSamples;
|
|
4
|
+
referenceImpedanceOhms: number;
|
|
5
|
+
}
|
|
6
|
+
export declare class Touchstone {
|
|
7
|
+
private constructor();
|
|
8
|
+
/** Read one-port Touchstone 1.x data; frequencies in the result are always Hz. */
|
|
9
|
+
static parse(text: string): TouchstoneData;
|
|
10
|
+
}
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
export class Touchstone {
|
|
2
|
+
constructor() { }
|
|
3
|
+
/** Read one-port Touchstone 1.x data; frequencies in the result are always Hz. */
|
|
4
|
+
static parse(text) {
|
|
5
|
+
const units = { HZ: 1, KHZ: 1e3, MHZ: 1e6, GHZ: 1e9 };
|
|
6
|
+
let frequencyScale = 1e9;
|
|
7
|
+
let format = 'MA';
|
|
8
|
+
let referenceImpedanceOhms = 50;
|
|
9
|
+
let optionsSeen = false;
|
|
10
|
+
const samples = [];
|
|
11
|
+
for (const [index, raw] of text
|
|
12
|
+
.replace(/^\uFEFF/, '')
|
|
13
|
+
.split(/\r?\n/)
|
|
14
|
+
.entries()) {
|
|
15
|
+
const line = raw.split('!')[0].trim();
|
|
16
|
+
if (!line) {
|
|
17
|
+
continue;
|
|
18
|
+
}
|
|
19
|
+
const fail = (message) => {
|
|
20
|
+
throw new Error(`Line ${index + 1}: ${message}`);
|
|
21
|
+
};
|
|
22
|
+
if (line.startsWith('[')) {
|
|
23
|
+
fail('Only Touchstone 1.x one-port files (.s1p) are supported.');
|
|
24
|
+
}
|
|
25
|
+
if (line.startsWith('#')) {
|
|
26
|
+
if (optionsSeen || samples.length) {
|
|
27
|
+
fail('The option line must appear once, before the data.');
|
|
28
|
+
}
|
|
29
|
+
optionsSeen = true;
|
|
30
|
+
const options = line.slice(1).trim().toUpperCase().split(/\s+/).filter(Boolean);
|
|
31
|
+
if (!options.length) {
|
|
32
|
+
continue;
|
|
33
|
+
}
|
|
34
|
+
const [unit = 'GHZ', parameter = 'S', representation = 'MA', r = 'R', impedance = '50'] = options;
|
|
35
|
+
if (!(unit in units) ||
|
|
36
|
+
parameter !== 'S' ||
|
|
37
|
+
!['RI', 'MA', 'DB'].includes(representation) ||
|
|
38
|
+
r !== 'R' ||
|
|
39
|
+
options.length > 5) {
|
|
40
|
+
fail('Expected: # Hz|kHz|MHz|GHz S RI|MA|DB R impedance.');
|
|
41
|
+
}
|
|
42
|
+
frequencyScale = units[unit];
|
|
43
|
+
format = representation;
|
|
44
|
+
referenceImpedanceOhms = Number(impedance);
|
|
45
|
+
if (!Number.isFinite(referenceImpedanceOhms) || referenceImpedanceOhms <= 0) {
|
|
46
|
+
fail('Reference impedance must be positive.');
|
|
47
|
+
}
|
|
48
|
+
continue;
|
|
49
|
+
}
|
|
50
|
+
const fields = line.split(/\s+/).map(Number);
|
|
51
|
+
if (fields.length !== 3 || !fields.every(Number.isFinite)) {
|
|
52
|
+
fail('Expected frequency and two finite S11 components.');
|
|
53
|
+
}
|
|
54
|
+
const [frequency, a, b] = fields;
|
|
55
|
+
const frequencyHz = frequency * frequencyScale;
|
|
56
|
+
if (frequencyHz < 0 || !Number.isFinite(frequencyHz)) {
|
|
57
|
+
fail('Frequency must be finite and non-negative.');
|
|
58
|
+
}
|
|
59
|
+
if (format === 'MA' && a < 0) {
|
|
60
|
+
fail('Magnitude must be non-negative.');
|
|
61
|
+
}
|
|
62
|
+
const magnitude = format === 'DB' ? 10 ** (a / 20) : a;
|
|
63
|
+
const radians = (b * Math.PI) / 180;
|
|
64
|
+
const reflectionCoefficient = format === 'RI' ? [a, b] : [magnitude * Math.cos(radians), magnitude * Math.sin(radians)];
|
|
65
|
+
if (!reflectionCoefficient.every(Number.isFinite)) {
|
|
66
|
+
fail('S11 is outside the supported numeric range.');
|
|
67
|
+
}
|
|
68
|
+
samples.push({ frequencyHz, reflectionCoefficient });
|
|
69
|
+
}
|
|
70
|
+
if (!samples.length) {
|
|
71
|
+
throw new Error('The file contains no S11 samples.');
|
|
72
|
+
}
|
|
73
|
+
return { samples, referenceImpedanceOhms };
|
|
74
|
+
}
|
|
75
|
+
}
|
package/dist/lib/layers.d.ts
CHANGED
|
@@ -1,7 +1,4 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
import type { ConstQCircles } from './draw/ConstQCircles.js';
|
|
3
|
-
import type { ConstSwrCircles } from './draw/ConstSwrCircles.js';
|
|
4
|
-
import type { Complex } from './complex/Complex.js';
|
|
1
|
+
import type { Complex } from './math/Complex.js';
|
|
5
2
|
export interface GridStyle {
|
|
6
3
|
stroke: string;
|
|
7
4
|
/** Non-scaling stroke width in CSS pixels. */
|
|
@@ -10,7 +7,7 @@ export interface GridStyle {
|
|
|
10
7
|
minorWidth: number;
|
|
11
8
|
textColor: string;
|
|
12
9
|
textFontFamily: string;
|
|
13
|
-
/**
|
|
10
|
+
/** Base font size in chart units; adaptive layout enforces a 9 CSS px minimum in the default view. */
|
|
14
11
|
textFontSize: number;
|
|
15
12
|
}
|
|
16
13
|
export interface CircleStyle {
|
|
@@ -43,6 +40,3 @@ export interface PeripheralScales {
|
|
|
43
40
|
/** Pass null to clear the indicators. */
|
|
44
41
|
update(reflectionCoefficient: Complex | null): void;
|
|
45
42
|
}
|
|
46
|
-
/** Keep renderer instances out of the public chart API. */
|
|
47
|
-
export declare function gridLayer(layer: ConstCircles, assertAlive: () => void): GridLayer;
|
|
48
|
-
export declare function circleLayer(layer: ConstQCircles | ConstSwrCircles, minimum: number, assertAlive: () => void): CircleLayer;
|
package/dist/lib/layers.js
CHANGED
|
@@ -1,73 +1 @@
|
|
|
1
|
-
|
|
2
|
-
export function gridLayer(layer, assertAlive) {
|
|
3
|
-
return {
|
|
4
|
-
setVisible(visible) {
|
|
5
|
-
assertAlive();
|
|
6
|
-
layer.visibility(visible);
|
|
7
|
-
},
|
|
8
|
-
setMinorVisible(visible) {
|
|
9
|
-
assertAlive();
|
|
10
|
-
layer.displayMinor(visible);
|
|
11
|
-
},
|
|
12
|
-
setStyle(style) {
|
|
13
|
-
assertAlive();
|
|
14
|
-
validateLengths(style, ['majorWidth', 'minorWidth', 'textFontSize']);
|
|
15
|
-
const properties = {
|
|
16
|
-
stroke: 'Stroke',
|
|
17
|
-
majorWidth: 'MajorWidth',
|
|
18
|
-
minorWidth: 'MinorWidth',
|
|
19
|
-
textColor: 'TextColor',
|
|
20
|
-
textFontFamily: 'TextFontFamily',
|
|
21
|
-
textFontSize: 'TextFontSize',
|
|
22
|
-
};
|
|
23
|
-
for (const key of Object.keys(properties)) {
|
|
24
|
-
const value = style[key];
|
|
25
|
-
if (value !== undefined) {
|
|
26
|
-
layer[properties[key]] = String(value);
|
|
27
|
-
}
|
|
28
|
-
}
|
|
29
|
-
},
|
|
30
|
-
};
|
|
31
|
-
}
|
|
32
|
-
export function circleLayer(layer, minimum, assertAlive) {
|
|
33
|
-
const validate = (value) => {
|
|
34
|
-
if (!Number.isFinite(value) || value < minimum || value <= 0) {
|
|
35
|
-
throw new RangeError(`Circle value must be finite, positive, and at least ${minimum}.`);
|
|
36
|
-
}
|
|
37
|
-
};
|
|
38
|
-
return {
|
|
39
|
-
setVisible(visible) {
|
|
40
|
-
assertAlive();
|
|
41
|
-
layer.visibility(visible);
|
|
42
|
-
},
|
|
43
|
-
setStyle(style) {
|
|
44
|
-
assertAlive();
|
|
45
|
-
validateLengths(style, ['strokeWidth']);
|
|
46
|
-
if (style.stroke !== undefined) {
|
|
47
|
-
layer.Stroke = style.stroke;
|
|
48
|
-
}
|
|
49
|
-
if (style.strokeWidth !== undefined) {
|
|
50
|
-
layer.StrokeWidth = String(style.strokeWidth);
|
|
51
|
-
}
|
|
52
|
-
},
|
|
53
|
-
addValue(value) {
|
|
54
|
-
assertAlive();
|
|
55
|
-
validate(value);
|
|
56
|
-
layer.append(value);
|
|
57
|
-
},
|
|
58
|
-
removeValue(value) {
|
|
59
|
-
assertAlive();
|
|
60
|
-
validate(value);
|
|
61
|
-
layer.remove(value);
|
|
62
|
-
},
|
|
63
|
-
};
|
|
64
|
-
}
|
|
65
|
-
function validateLengths(style, keys) {
|
|
66
|
-
for (const key of keys) {
|
|
67
|
-
const value = style[key];
|
|
68
|
-
if (value !== undefined &&
|
|
69
|
-
(typeof value !== 'number' || !Number.isFinite(value) || value <= 0)) {
|
|
70
|
-
throw new RangeError(`${String(key)} must be a positive finite number.`);
|
|
71
|
-
}
|
|
72
|
-
}
|
|
73
|
-
}
|
|
1
|
+
export {};
|
|
@@ -126,5 +126,6 @@ export declare class Complex {
|
|
|
126
126
|
static equals(z1: Complex, z2: Complex, epsilon?: number): boolean;
|
|
127
127
|
static toPolar(z: Complex): [number, number];
|
|
128
128
|
static toVector(z: Complex): [number, number];
|
|
129
|
+
/** Format Cartesian components with Number.toFixed(dp), defaulting to three decimal places. */
|
|
129
130
|
static toString(z: Complex, dp?: number): string;
|
|
130
131
|
}
|
|
@@ -626,7 +626,7 @@ export class Complex {
|
|
|
626
626
|
static toVector(z) {
|
|
627
627
|
return [z.re, z.im];
|
|
628
628
|
}
|
|
629
|
-
|
|
629
|
+
/** Format Cartesian components with Number.toFixed(dp), defaulting to three decimal places. */
|
|
630
630
|
static toString(z, dp = 3) {
|
|
631
631
|
const re = z.re.toFixed(dp);
|
|
632
632
|
const im = Math.abs(z.im).toFixed(dp);
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { Complex } from './
|
|
2
|
-
import type { SmithReading } from './rf.js';
|
|
1
|
+
import { Complex } from './math/Complex.js';
|
|
2
|
+
import type { SmithReading } from './rf/RfCalculations.js';
|
|
3
3
|
export type TraceRenderMode = 'points' | 'line' | 'both';
|
|
4
4
|
export interface TraceStyle {
|
|
5
5
|
mode: TraceRenderMode;
|
|
@@ -49,5 +49,3 @@ export interface MarkerComparison {
|
|
|
49
49
|
/** Shortest signed B − A phase difference in [−180, 180); undefined at Γ = 0. */
|
|
50
50
|
readonly phaseDeltaDegrees: number | undefined;
|
|
51
51
|
}
|
|
52
|
-
/** Compare B against A without a chart or browser. Frequencies must be finite and non-negative. */
|
|
53
|
-
export declare function compareMarkerReadings(a: Pick<MarkerSnapshot, 'frequencyHz' | 'impedanceOhms' | 'reflectionCoefficient'>, b: Pick<MarkerSnapshot, 'frequencyHz' | 'impedanceOhms' | 'reflectionCoefficient'>): MarkerComparison;
|
package/dist/lib/measurements.js
CHANGED
|
@@ -1,19 +1 @@
|
|
|
1
|
-
|
|
2
|
-
export function compareMarkerReadings(a, b) {
|
|
3
|
-
if (![a.frequencyHz, b.frequencyHz].every((frequencyHz) => Number.isFinite(frequencyHz) && frequencyHz >= 0)) {
|
|
4
|
-
throw new RangeError('Marker frequencies must be finite and non-negative.');
|
|
5
|
-
}
|
|
6
|
-
const isFinite = (value) => Number.isFinite(value.re) && Number.isFinite(value.im);
|
|
7
|
-
const hasPhase = (gamma) => isFinite(gamma) && (gamma.re !== 0 || gamma.im !== 0);
|
|
8
|
-
const phaseDelta = hasPhase(a.reflectionCoefficient) && hasPhase(b.reflectionCoefficient)
|
|
9
|
-
? ((b.reflectionCoefficient.arg() - a.reflectionCoefficient.arg()) * 180) / Math.PI
|
|
10
|
-
: undefined;
|
|
11
|
-
const impedanceDelta = a.impedanceOhms && b.impedanceOhms && isFinite(a.impedanceOhms) && isFinite(b.impedanceOhms)
|
|
12
|
-
? b.impedanceOhms.sub(a.impedanceOhms)
|
|
13
|
-
: undefined;
|
|
14
|
-
return {
|
|
15
|
-
frequencyDeltaHz: b.frequencyHz - a.frequencyHz,
|
|
16
|
-
impedanceDeltaOhms: impedanceDelta && isFinite(impedanceDelta) ? impedanceDelta : undefined,
|
|
17
|
-
phaseDeltaDegrees: phaseDelta === undefined ? undefined : ((phaseDelta + 540) % 360) - 180,
|
|
18
|
-
};
|
|
19
|
-
}
|
|
1
|
+
export {};
|