smithkit 0.1.1 → 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 +119 -40
- 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 +68 -36
- 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 +4 -6
- package/dist/lib/{draw → grid}/ConstCircles.js +2 -2
- 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 +4 -2
- package/dist/lib/scales/SmithPeripheralScales.js +46 -26
- package/dist/lib/scales/SmithScales.d.ts +3 -1
- package/dist/lib/scales/SmithScales.js +8 -2
- 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,19 @@
|
|
|
1
|
+
import { format } from 'd3';
|
|
2
|
+
export class SmithFormatter {
|
|
3
|
+
constructor() { }
|
|
4
|
+
/** Format with three significant digits and an SI prefix; includes spacing before the unit. */
|
|
5
|
+
static number(value) {
|
|
6
|
+
const formatted = format('.3~s')(value);
|
|
7
|
+
return Number.isFinite(value) && /[a-zA-Zµ]$/.test(formatted)
|
|
8
|
+
? formatted.replace(/([a-zA-Zµ])$/, ' $1')
|
|
9
|
+
: formatted + ' ';
|
|
10
|
+
}
|
|
11
|
+
/** Format Cartesian components to decimalPlaces fractional digits. */
|
|
12
|
+
static complex(value, unit = '', decimalPlaces = 3) {
|
|
13
|
+
return `${value.toString(decimalPlaces)} ${unit === '' ? '' : `[${unit}]`}`;
|
|
14
|
+
}
|
|
15
|
+
/** Format magnitude and phase in degrees to decimalPlaces fractional digits. */
|
|
16
|
+
static polar(value, unit = '', decimalPlaces = 3) {
|
|
17
|
+
return `${value.abs().toFixed(decimalPlaces)} ${unit} ∠${((value.arg() * 180) / Math.PI).toFixed(decimalPlaces)}°`;
|
|
18
|
+
}
|
|
19
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { ConstQCircles } from './ConstQCircles.js';
|
|
2
|
+
import type { ConstSwrCircles } from './ConstSwrCircles.js';
|
|
3
|
+
import type { CircleLayer, CircleStyle } from '../layers.js';
|
|
4
|
+
import { LayerControl } from './LayerControl.js';
|
|
5
|
+
/** Exposes Q/VSWR circle controls without exposing the SVG renderer. */
|
|
6
|
+
export declare class CircleLayerControl extends LayerControl implements CircleLayer {
|
|
7
|
+
private readonly layer;
|
|
8
|
+
private readonly minimum;
|
|
9
|
+
constructor(layer: ConstQCircles | ConstSwrCircles, minimum: number, assertAlive: () => void);
|
|
10
|
+
setVisible(visible: boolean): void;
|
|
11
|
+
setStyle(style: Partial<CircleStyle>): void;
|
|
12
|
+
addValue(value: number): void;
|
|
13
|
+
removeValue(value: number): void;
|
|
14
|
+
private validateValue;
|
|
15
|
+
}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { LayerControl } from './LayerControl.js';
|
|
2
|
+
/** Exposes Q/VSWR circle controls without exposing the SVG renderer. */
|
|
3
|
+
export class CircleLayerControl extends LayerControl {
|
|
4
|
+
layer;
|
|
5
|
+
minimum;
|
|
6
|
+
constructor(layer, minimum, assertAlive) {
|
|
7
|
+
super(assertAlive);
|
|
8
|
+
this.layer = layer;
|
|
9
|
+
this.minimum = minimum;
|
|
10
|
+
}
|
|
11
|
+
setVisible(visible) {
|
|
12
|
+
this.assertAlive();
|
|
13
|
+
this.layer.visibility(visible);
|
|
14
|
+
}
|
|
15
|
+
setStyle(style) {
|
|
16
|
+
this.assertAlive();
|
|
17
|
+
this.validateLengths(style, ['strokeWidth']);
|
|
18
|
+
if (style.stroke !== undefined) {
|
|
19
|
+
this.layer.Stroke = style.stroke;
|
|
20
|
+
}
|
|
21
|
+
if (style.strokeWidth !== undefined) {
|
|
22
|
+
this.layer.StrokeWidth = String(style.strokeWidth);
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
addValue(value) {
|
|
26
|
+
this.assertAlive();
|
|
27
|
+
this.validateValue(value);
|
|
28
|
+
this.layer.append(value);
|
|
29
|
+
}
|
|
30
|
+
removeValue(value) {
|
|
31
|
+
this.assertAlive();
|
|
32
|
+
this.validateValue(value);
|
|
33
|
+
this.layer.remove(value);
|
|
34
|
+
}
|
|
35
|
+
validateValue(value) {
|
|
36
|
+
if (!Number.isFinite(value) || value < this.minimum || value <= 0) {
|
|
37
|
+
throw new RangeError(`Circle value must be finite, positive, and at least ${this.minimum}.`);
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
}
|
|
@@ -1,10 +1,8 @@
|
|
|
1
1
|
import type * as d3 from 'd3';
|
|
2
|
-
import { SmithGroup } from '
|
|
3
|
-
import { SmithScaler } from '
|
|
4
|
-
import { Line } from '../
|
|
5
|
-
import {
|
|
6
|
-
import { Point } from '../shapes/Point.js';
|
|
7
|
-
import { SmithConstantCircle } from '../SmithConstantCircle.js';
|
|
2
|
+
import { SmithGroup } from '../svg/SmithGroup.js';
|
|
3
|
+
import { SmithScaler } from '../svg/SmithScaler.js';
|
|
4
|
+
import type { Line, Circle, Point } from '../math/geometry.js';
|
|
5
|
+
import { SmithConstantCircle } from '../rf/SmithConstantCircle.js';
|
|
8
6
|
export interface ArcData {
|
|
9
7
|
p1: Point;
|
|
10
8
|
p2: Point;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { SmithGroup } from '
|
|
2
|
-
import { SmithConstantCircle } from '../SmithConstantCircle.js';
|
|
1
|
+
import { SmithGroup } from '../svg/SmithGroup.js';
|
|
2
|
+
import { SmithConstantCircle } from '../rf/SmithConstantCircle.js';
|
|
3
3
|
export class ConstCircles {
|
|
4
4
|
scaler;
|
|
5
5
|
calcs = new SmithConstantCircle();
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { SmithGroup } from '
|
|
2
|
-
import { SmithScaler } from '
|
|
1
|
+
import { SmithGroup } from '../svg/SmithGroup.js';
|
|
2
|
+
import { SmithScaler } from '../svg/SmithScaler.js';
|
|
3
3
|
interface ConstQDrawOptions {
|
|
4
4
|
stroke: string;
|
|
5
5
|
strokeWidth: string;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { SmithGroup } from '
|
|
2
|
-
import { SmithArc } from '
|
|
3
|
-
import { SmithConstantCircle } from '../SmithConstantCircle.js';
|
|
1
|
+
import { SmithGroup } from '../svg/SmithGroup.js';
|
|
2
|
+
import { SmithArc } from '../svg/SmithArc.js';
|
|
3
|
+
import { SmithConstantCircle } from '../rf/SmithConstantCircle.js';
|
|
4
4
|
export class ConstQCircles {
|
|
5
5
|
scaler;
|
|
6
6
|
calcs = new SmithConstantCircle();
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { SmithGroup } from '
|
|
2
|
-
import { SmithScaler } from '
|
|
1
|
+
import { SmithGroup } from '../svg/SmithGroup.js';
|
|
2
|
+
import { SmithScaler } from '../svg/SmithScaler.js';
|
|
3
3
|
interface ConstSwrDrawOptions {
|
|
4
4
|
stroke: string;
|
|
5
5
|
strokeWidth: string;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { SmithGroup } from '
|
|
2
|
-
import { SmithCircle } from '
|
|
3
|
-
import { SmithConstantCircle } from '../SmithConstantCircle.js';
|
|
1
|
+
import { SmithGroup } from '../svg/SmithGroup.js';
|
|
2
|
+
import { SmithCircle } from '../svg/SmithCircle.js';
|
|
3
|
+
import { SmithConstantCircle } from '../rf/SmithConstantCircle.js';
|
|
4
4
|
export class ConstSwrCircles {
|
|
5
5
|
scaler;
|
|
6
6
|
calcs = new SmithConstantCircle();
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { SmithTicksData } from './types.js';
|
|
2
|
+
export declare class GridDefinitions {
|
|
3
|
+
private constructor();
|
|
4
|
+
private static readonly resistanceMajor;
|
|
5
|
+
private static readonly resistanceMinor;
|
|
6
|
+
private static readonly reactanceMajor;
|
|
7
|
+
private static readonly reactanceMinor;
|
|
8
|
+
private static resistanceArcs;
|
|
9
|
+
private static reactanceArcs;
|
|
10
|
+
/** Build fresh definitions so callers cannot mutate another chart's grid. */
|
|
11
|
+
static create(): SmithTicksData;
|
|
12
|
+
}
|
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
export class GridDefinitions {
|
|
2
|
+
constructor() { }
|
|
3
|
+
static resistanceMajor = [
|
|
4
|
+
[[0.05, 0.15], 0.2, -0.2, false],
|
|
5
|
+
[[0.1, 0.3, 0.5, 0.7, 0.9], 2, -2, true],
|
|
6
|
+
[[0.2, 0.4, 0.6, 0.8, 1.2, 1.4, 1.6, 1.8], 5, -5, true],
|
|
7
|
+
[[1, 3, 5], 10, -10, true],
|
|
8
|
+
[[2, 4], 20, -20, true],
|
|
9
|
+
[[20], 50, -50, true],
|
|
10
|
+
];
|
|
11
|
+
static resistanceMinor = [
|
|
12
|
+
[[0.02, 0.04, 0.06, 0.08, 0.12, 0.14, 0.16, 0.18], 0.2, 0.5, false],
|
|
13
|
+
[[0.02, 0.04, 0.06, 0.08, 0.12, 0.14, 0.16, 0.18], -0.2, -0.5, false],
|
|
14
|
+
[[0.05, 0.15, 0.25, 0.35, 0.45], 0.5, 1, false],
|
|
15
|
+
[[0.05, 0.15, 0.25, 0.35, 0.45], -0.5, -1, false],
|
|
16
|
+
[
|
|
17
|
+
[
|
|
18
|
+
0.01, 0.02, 0.03, 0.04, 0.06, 0.07, 0.08, 0.09, 0.11, 0.12, 0.13, 0.14, 0.16, 0.17, 0.18,
|
|
19
|
+
0.19,
|
|
20
|
+
],
|
|
21
|
+
0.2,
|
|
22
|
+
-0.2,
|
|
23
|
+
false,
|
|
24
|
+
],
|
|
25
|
+
[[0.22, 0.24, 0.26, 0.28, 0.32, 0.34, 0.36, 0.38, 0.42, 0.44, 0.46, 0.48], 0.5, -0.5, false],
|
|
26
|
+
[[0.55, 0.65, 0.75, 0.85, 0.95], 2, -2, true],
|
|
27
|
+
[[1.1, 1.3, 1.5, 1.7, 1.9], 2, -2, false],
|
|
28
|
+
[[2.2, 2.4, 2.6, 2.8, 3.2, 3.4, 3.6, 3.8], 5, -5, true],
|
|
29
|
+
[[4.2, 4.4, 4.6, 4.8], 5, -5, false],
|
|
30
|
+
[[6, 8, 12, 14, 16, 18], 20, -20, true],
|
|
31
|
+
[[7, 9], 10, -10, true],
|
|
32
|
+
[[30, 40], 50, -50, true],
|
|
33
|
+
];
|
|
34
|
+
static reactanceMajor = [
|
|
35
|
+
[[0.05, 0.15], 0.2, 0],
|
|
36
|
+
[[0.1, 0.3, 0.5, 0.7, 0.9], 2, 0],
|
|
37
|
+
[[0.2, 0.4, 0.6, 0.8, 1.2, 1.4, 1.6, 1.8], 5, 0],
|
|
38
|
+
[[1, 3, 5], 10, 0],
|
|
39
|
+
[[2, 4, 10], 20, 0],
|
|
40
|
+
[[20], 50, 0],
|
|
41
|
+
];
|
|
42
|
+
static reactanceMinor = [
|
|
43
|
+
[
|
|
44
|
+
[
|
|
45
|
+
0.01, 0.02, 0.03, 0.04, 0.06, 0.07, 0.08, 0.09, 0.11, 0.12, 0.13, 0.14, 0.16, 0.17, 0.18,
|
|
46
|
+
0.19,
|
|
47
|
+
],
|
|
48
|
+
0.2,
|
|
49
|
+
0,
|
|
50
|
+
],
|
|
51
|
+
[[0.02, 0.04, 0.06, 0.08, 0.12, 0.14, 0.16, 0.18], 0.5, 0.2],
|
|
52
|
+
[[0.22, 0.24, 0.26, 0.28, 0.32, 0.34, 0.36, 0.38, 0.42, 0.44, 0.46, 0.48], 0.5, 0],
|
|
53
|
+
[[0.05, 0.15, 0.25, 0.35, 0.45], 1, 0.5],
|
|
54
|
+
[[0.55, 0.65, 0.75, 0.85, 0.95], 1, 0],
|
|
55
|
+
[[1.1, 1.3, 1.5, 1.7, 1.9], 2, 0],
|
|
56
|
+
[[2.2, 2.4, 2.6, 2.8, 3.2, 3.4, 3.6, 3.8, 4.2, 4.4, 4.6, 4.8], 5, 0],
|
|
57
|
+
[[6, 8, 14, 16, 18], 20, 0],
|
|
58
|
+
[[7, 9], 10, 0],
|
|
59
|
+
[[12, 30, 40], 50, 0],
|
|
60
|
+
];
|
|
61
|
+
static resistanceArcs(bands) {
|
|
62
|
+
return bands.flatMap(([values, from, to, largeArc]) => values.map((value) => [
|
|
63
|
+
value,
|
|
64
|
+
[
|
|
65
|
+
[from, from < 0 ? 1 : 0],
|
|
66
|
+
[to, to < 0 ? 1 : 0],
|
|
67
|
+
],
|
|
68
|
+
[largeArc, from > to],
|
|
69
|
+
]));
|
|
70
|
+
}
|
|
71
|
+
static reactanceArcs(bands) {
|
|
72
|
+
return bands.flatMap(([values, outer, inner]) => values.flatMap((value) => [
|
|
73
|
+
[
|
|
74
|
+
value,
|
|
75
|
+
[
|
|
76
|
+
[outer, 1],
|
|
77
|
+
[inner, 1],
|
|
78
|
+
],
|
|
79
|
+
[false, false],
|
|
80
|
+
],
|
|
81
|
+
[
|
|
82
|
+
-value,
|
|
83
|
+
[
|
|
84
|
+
[outer, 0],
|
|
85
|
+
[inner, 0],
|
|
86
|
+
],
|
|
87
|
+
[false, true],
|
|
88
|
+
],
|
|
89
|
+
]));
|
|
90
|
+
}
|
|
91
|
+
/** Build fresh definitions so callers cannot mutate another chart's grid. */
|
|
92
|
+
static create() {
|
|
93
|
+
return {
|
|
94
|
+
resistance: {
|
|
95
|
+
major: {
|
|
96
|
+
lines: [],
|
|
97
|
+
circles: [10, 50],
|
|
98
|
+
arcs: GridDefinitions.resistanceArcs(GridDefinitions.resistanceMajor),
|
|
99
|
+
},
|
|
100
|
+
minor: {
|
|
101
|
+
lines: [],
|
|
102
|
+
circles: [],
|
|
103
|
+
arcs: GridDefinitions.resistanceArcs(GridDefinitions.resistanceMinor),
|
|
104
|
+
},
|
|
105
|
+
},
|
|
106
|
+
reactance: {
|
|
107
|
+
major: {
|
|
108
|
+
lines: [{ p1: [-1, 0], p2: [1, 0] }],
|
|
109
|
+
circles: [],
|
|
110
|
+
arcs: [
|
|
111
|
+
...GridDefinitions.reactanceArcs(GridDefinitions.reactanceMajor),
|
|
112
|
+
[
|
|
113
|
+
50,
|
|
114
|
+
[
|
|
115
|
+
[0, 0],
|
|
116
|
+
[0, 1],
|
|
117
|
+
],
|
|
118
|
+
[false, false],
|
|
119
|
+
],
|
|
120
|
+
[
|
|
121
|
+
-50,
|
|
122
|
+
[
|
|
123
|
+
[0, 1],
|
|
124
|
+
[0, 0],
|
|
125
|
+
],
|
|
126
|
+
[false, true],
|
|
127
|
+
],
|
|
128
|
+
],
|
|
129
|
+
},
|
|
130
|
+
minor: {
|
|
131
|
+
lines: [],
|
|
132
|
+
circles: [],
|
|
133
|
+
arcs: GridDefinitions.reactanceArcs(GridDefinitions.reactanceMinor),
|
|
134
|
+
},
|
|
135
|
+
},
|
|
136
|
+
};
|
|
137
|
+
}
|
|
138
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import type { TickDefRequired } from './Tick.js';
|
|
2
|
+
import type { SmithTicksShapes } from './types.js';
|
|
3
|
+
import type { Point } from '../math/geometry.js';
|
|
4
|
+
export type GridKind = 'resistance' | 'reactance' | 'conductance' | 'susceptance';
|
|
5
|
+
export type GridArc = [Point, Point, number, boolean, boolean];
|
|
6
|
+
export declare class GridGeometry {
|
|
7
|
+
private constructor();
|
|
8
|
+
private static readonly calcs;
|
|
9
|
+
private static readonly circles;
|
|
10
|
+
private static readonly clipping;
|
|
11
|
+
/** Normalized geometry only: no DOM, D3, or pixel coordinates. */
|
|
12
|
+
static shapes(kind: GridKind, data: SmithTicksShapes): {
|
|
13
|
+
lines: import("../math/geometry.js").Line[];
|
|
14
|
+
circles: import("../math/geometry.js").Circle[];
|
|
15
|
+
arcs: GridArc[];
|
|
16
|
+
};
|
|
17
|
+
static label(kind: GridKind, definition: TickDefRequired): {
|
|
18
|
+
point: [number, number];
|
|
19
|
+
text: string;
|
|
20
|
+
rotate: number;
|
|
21
|
+
dx: number;
|
|
22
|
+
dy: number;
|
|
23
|
+
textAnchor: string;
|
|
24
|
+
dominantBaseline: string;
|
|
25
|
+
};
|
|
26
|
+
}
|
|
@@ -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;
|