smithkit 0.0.0-stage → 0.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (101) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +467 -2
  3. package/dist/lib/Smith.d.ts +103 -0
  4. package/dist/lib/Smith.js +562 -0
  5. package/dist/lib/SmithArcsDefs.d.ts +10 -0
  6. package/dist/lib/SmithArcsDefs.js +10 -0
  7. package/dist/lib/SmithConstantCircle.d.ts +62 -0
  8. package/dist/lib/SmithConstantCircle.js +222 -0
  9. package/dist/lib/arcs/Tick.d.ts +33 -0
  10. package/dist/lib/arcs/Tick.js +40 -0
  11. package/dist/lib/complex/Complex.d.ts +130 -0
  12. package/dist/lib/complex/Complex.js +636 -0
  13. package/dist/lib/components.d.ts +14 -0
  14. package/dist/lib/components.js +26 -0
  15. package/dist/lib/draw/ConstCircles.d.ts +63 -0
  16. package/dist/lib/draw/ConstCircles.js +158 -0
  17. package/dist/lib/draw/ConstConductance.d.ts +4 -0
  18. package/dist/lib/draw/ConstConductance.js +6 -0
  19. package/dist/lib/draw/ConstQCircles.d.ts +29 -0
  20. package/dist/lib/draw/ConstQCircles.js +86 -0
  21. package/dist/lib/draw/ConstReactance.d.ts +4 -0
  22. package/dist/lib/draw/ConstReactance.js +6 -0
  23. package/dist/lib/draw/ConstResistance.d.ts +4 -0
  24. package/dist/lib/draw/ConstResistance.js +6 -0
  25. package/dist/lib/draw/ConstSusceptance.d.ts +4 -0
  26. package/dist/lib/draw/ConstSusceptance.js +6 -0
  27. package/dist/lib/draw/ConstSwrCircles.d.ts +29 -0
  28. package/dist/lib/draw/ConstSwrCircles.js +85 -0
  29. package/dist/lib/draw/MouseGesture.d.ts +6 -0
  30. package/dist/lib/draw/MouseGesture.js +26 -0
  31. package/dist/lib/draw/SmithArc.d.ts +10 -0
  32. package/dist/lib/draw/SmithArc.js +26 -0
  33. package/dist/lib/draw/SmithCircle.d.ts +10 -0
  34. package/dist/lib/draw/SmithCircle.js +24 -0
  35. package/dist/lib/draw/SmithCursor.d.ts +49 -0
  36. package/dist/lib/draw/SmithCursor.js +186 -0
  37. package/dist/lib/draw/SmithData.d.ts +66 -0
  38. package/dist/lib/draw/SmithData.js +366 -0
  39. package/dist/lib/draw/SmithDrawOptions.d.ts +5 -0
  40. package/dist/lib/draw/SmithDrawOptions.js +1 -0
  41. package/dist/lib/draw/SmithGridLayer.d.ts +19 -0
  42. package/dist/lib/draw/SmithGridLayer.js +48 -0
  43. package/dist/lib/draw/SmithGroup.d.ts +11 -0
  44. package/dist/lib/draw/SmithGroup.js +31 -0
  45. package/dist/lib/draw/SmithLine.d.ts +11 -0
  46. package/dist/lib/draw/SmithLine.js +27 -0
  47. package/dist/lib/draw/SmithMarker.d.ts +25 -0
  48. package/dist/lib/draw/SmithMarker.js +122 -0
  49. package/dist/lib/draw/SmithPath.d.ts +8 -0
  50. package/dist/lib/draw/SmithPath.js +20 -0
  51. package/dist/lib/draw/SmithScaler.d.ts +19 -0
  52. package/dist/lib/draw/SmithScaler.js +48 -0
  53. package/dist/lib/draw/SmithShape.d.ts +15 -0
  54. package/dist/lib/draw/SmithShape.js +42 -0
  55. package/dist/lib/draw/SmithSvg.d.ts +9 -0
  56. package/dist/lib/draw/SmithSvg.js +27 -0
  57. package/dist/lib/draw/SmithText.d.ts +22 -0
  58. package/dist/lib/draw/SmithText.js +56 -0
  59. package/dist/lib/formatting.d.ts +7 -0
  60. package/dist/lib/formatting.js +16 -0
  61. package/dist/lib/grid/definitions.d.ts +3 -0
  62. package/dist/lib/grid/definitions.js +123 -0
  63. package/dist/lib/grid/geometry.d.ts +20 -0
  64. package/dist/lib/grid/geometry.js +55 -0
  65. package/dist/lib/grid/labels.d.ts +3 -0
  66. package/dist/lib/grid/labels.js +41 -0
  67. package/dist/lib/grid/types.d.ts +30 -0
  68. package/dist/lib/grid/types.js +6 -0
  69. package/dist/lib/index.d.ts +16 -0
  70. package/dist/lib/index.js +9 -0
  71. package/dist/lib/io/touchstone.d.ts +7 -0
  72. package/dist/lib/io/touchstone.js +72 -0
  73. package/dist/lib/layers.d.ts +48 -0
  74. package/dist/lib/layers.js +73 -0
  75. package/dist/lib/math/complexRatio.d.ts +3 -0
  76. package/dist/lib/math/complexRatio.js +30 -0
  77. package/dist/lib/measurements.d.ts +53 -0
  78. package/dist/lib/measurements.js +19 -0
  79. package/dist/lib/renormalization.d.ts +10 -0
  80. package/dist/lib/renormalization.js +62 -0
  81. package/dist/lib/rf.d.ts +35 -0
  82. package/dist/lib/rf.js +74 -0
  83. package/dist/lib/samples.d.ts +6 -0
  84. package/dist/lib/samples.js +1 -0
  85. package/dist/lib/scales/SmithPeripheralScales.d.ts +13 -0
  86. package/dist/lib/scales/SmithPeripheralScales.js +141 -0
  87. package/dist/lib/scales/SmithScales.d.ts +16 -0
  88. package/dist/lib/scales/SmithScales.js +142 -0
  89. package/dist/lib/scales/peripheralScales.d.ts +12 -0
  90. package/dist/lib/scales/peripheralScales.js +49 -0
  91. package/dist/lib/scales/radialScales.d.ts +12 -0
  92. package/dist/lib/scales/radialScales.js +109 -0
  93. package/dist/lib/shapes/Arc.d.ts +6 -0
  94. package/dist/lib/shapes/Arc.js +1 -0
  95. package/dist/lib/shapes/Circle.d.ts +5 -0
  96. package/dist/lib/shapes/Circle.js +1 -0
  97. package/dist/lib/shapes/Line.d.ts +5 -0
  98. package/dist/lib/shapes/Line.js +1 -0
  99. package/dist/lib/shapes/Point.d.ts +1 -0
  100. package/dist/lib/shapes/Point.js +1 -0
  101. package/package.json +76 -4
@@ -0,0 +1,11 @@
1
+ import * as d3 from 'd3';
2
+ import { SmithShape } from './SmithShape.js';
3
+ import { SmithDrawOptions } from './SmithDrawOptions.js';
4
+ export declare class SmithGroup extends SmithShape {
5
+ constructor(options?: SmithDrawOptions);
6
+ get Element(): d3.Selection<SVGElement, unknown, null, undefined>;
7
+ attr(name: string, value: Parameters<d3.Selection<SVGElement, unknown, null, undefined>['attr']>[1]): SmithGroup;
8
+ show(): SmithGroup;
9
+ hide(): SmithGroup;
10
+ append(el: SmithShape | null): SmithGroup;
11
+ }
@@ -0,0 +1,31 @@
1
+ import * as d3 from 'd3';
2
+ import { SmithShape } from './SmithShape.js';
3
+ export class SmithGroup extends SmithShape {
4
+ constructor(options) {
5
+ super(d3.select(document.createElementNS('http://www.w3.org/2000/svg', 'g')));
6
+ if (options) {
7
+ this.setDrawOptions(options);
8
+ }
9
+ }
10
+ get Element() {
11
+ return this.element;
12
+ }
13
+ attr(name, value) {
14
+ this.element.attr(name, value);
15
+ return this;
16
+ }
17
+ show() {
18
+ this.element.attr('opacity', null);
19
+ return this;
20
+ }
21
+ hide() {
22
+ this.element.attr('opacity', '0');
23
+ return this;
24
+ }
25
+ append(el) {
26
+ if (el !== null) {
27
+ this.element.append(() => el.Node);
28
+ }
29
+ return this;
30
+ }
31
+ }
@@ -0,0 +1,11 @@
1
+ import { Point } from '../shapes/Point.js';
2
+ import { SmithShape } from './SmithShape.js';
3
+ import { SmithDrawOptions } from './SmithDrawOptions.js';
4
+ export declare class SmithLine extends SmithShape {
5
+ constructor(p1: Point, p2: Point, options?: SmithDrawOptions);
6
+ move(p1: Point, p2: Point): SmithLine;
7
+ hide(): void;
8
+ show(): void;
9
+ nonScalingStroke(): void;
10
+ setStrokeLinecap(linecap: string): void;
11
+ }
@@ -0,0 +1,27 @@
1
+ import * as d3 from 'd3';
2
+ import { SmithShape } from './SmithShape.js';
3
+ export class SmithLine extends SmithShape {
4
+ constructor(p1, p2, options) {
5
+ super(d3.select(document.createElementNS('http://www.w3.org/2000/svg', 'line')));
6
+ if (options) {
7
+ this.setDrawOptions(options);
8
+ }
9
+ this.move(p1, p2);
10
+ }
11
+ move(p1, p2) {
12
+ this.element.attr('x1', p1[0]).attr('y1', p1[1]).attr('x2', p2[0]).attr('y2', p2[1]);
13
+ return this;
14
+ }
15
+ hide() {
16
+ this.Element.attr('opacity', '0');
17
+ }
18
+ show() {
19
+ this.Element.attr('opacity', null);
20
+ }
21
+ nonScalingStroke() {
22
+ this.Element.attr('vector-effect', 'non-scaling-stroke');
23
+ }
24
+ setStrokeLinecap(linecap) {
25
+ this.Element.attr('stroke-linecap', linecap);
26
+ }
27
+ }
@@ -0,0 +1,25 @@
1
+ import { SmithShape } from './SmithShape.js';
2
+ import { Point } from '../shapes/Point.js';
3
+ export declare class SmithMarker extends SmithShape {
4
+ private dragStateHandler;
5
+ private readonly size;
6
+ private mouseGesture;
7
+ private activeDrags;
8
+ private destroyed;
9
+ private triangle;
10
+ private inner;
11
+ private text;
12
+ private rc;
13
+ private dragHandler;
14
+ constructor(marker: number, color: string, dragStateHandler?: ((dragging: boolean) => void) | null);
15
+ destroy(): void;
16
+ cancelDrag(): void;
17
+ setColor(color: string): void;
18
+ private onDrag;
19
+ get Position(): Point;
20
+ move(p: Point): void;
21
+ zoom(k: number): void;
22
+ show(): void;
23
+ hide(): void;
24
+ setDragHandler(handler: (p: Point) => void): void;
25
+ }
@@ -0,0 +1,122 @@
1
+ import * as d3 from 'd3';
2
+ import { MouseGesture } from './MouseGesture.js';
3
+ import { SmithShape } from './SmithShape.js';
4
+ export class SmithMarker extends SmithShape {
5
+ dragStateHandler;
6
+ size = 18;
7
+ mouseGesture = new MouseGesture();
8
+ activeDrags = new Set();
9
+ destroyed = false;
10
+ triangle;
11
+ inner;
12
+ text;
13
+ rc = [0, 0];
14
+ dragHandler = null;
15
+ constructor(marker, color, dragStateHandler = null) {
16
+ super(d3.select(document.createElementNS('http://www.w3.org/2000/svg', 'g')));
17
+ this.dragStateHandler = dragStateHandler;
18
+ const g = this.Element.style('cursor', 'var(--smithkit-marker-cursor, grab)');
19
+ this.triangle = g
20
+ .append('polygon')
21
+ .attr('stroke', 'none')
22
+ .attr('fill', 'gray')
23
+ .attr('transform', 'translate(0,0)');
24
+ this.inner = g
25
+ .append('polygon')
26
+ .attr('stroke', 'none')
27
+ .attr('fill', color)
28
+ .attr('transform', 'translate(0,0)');
29
+ this.text = g
30
+ .append('text')
31
+ .attr('pointer-events', 'none')
32
+ .attr('transform', 'translate(0,0)')
33
+ .attr('font-family', 'Verdana')
34
+ .attr('font-weight', 'normal')
35
+ .attr('text-anchor', 'middle')
36
+ .attr('dominant-baseline', 'middle')
37
+ .attr('x', '0')
38
+ .attr('y', '0')
39
+ .attr('fill', 'white')
40
+ .text(marker.toString());
41
+ this.zoom(1);
42
+ const drag = d3
43
+ .drag()
44
+ .on('start', (event) => {
45
+ if (this.destroyed) {
46
+ return;
47
+ }
48
+ this.mouseGesture.capture(event.sourceEvent, 'drag');
49
+ const wasIdle = this.activeDrags.size === 0;
50
+ this.activeDrags.add(event.identifier);
51
+ if (wasIdle) {
52
+ this.dragStateHandler?.(true);
53
+ }
54
+ })
55
+ .on('drag', (event) => this.onDrag(event))
56
+ .on('end', (event) => {
57
+ if (this.activeDrags.delete(event.identifier) && this.activeDrags.size === 0) {
58
+ this.dragStateHandler?.(false);
59
+ }
60
+ });
61
+ this.triangle.call(drag);
62
+ this.inner.call(drag);
63
+ }
64
+ destroy() {
65
+ if (this.destroyed) {
66
+ return;
67
+ }
68
+ this.destroyed = true;
69
+ this.dragHandler = null;
70
+ this.cancelDrag();
71
+ this.dragStateHandler = null;
72
+ this.Element.selectAll('*').on('.drag', null).interrupt();
73
+ this.Element.remove();
74
+ }
75
+ cancelDrag() {
76
+ if (this.activeDrags.size > 0) {
77
+ this.activeDrags.clear();
78
+ this.dragStateHandler?.(false);
79
+ }
80
+ this.mouseGesture.destroy();
81
+ }
82
+ setColor(color) {
83
+ this.inner.attr('fill', color);
84
+ }
85
+ onDrag(event) {
86
+ if (this.dragHandler) {
87
+ this.dragHandler([event.x, event.y]);
88
+ }
89
+ }
90
+ get Position() {
91
+ return this.rc;
92
+ }
93
+ move(p) {
94
+ this.rc = p;
95
+ this.triangle.attr('transform', `translate(${p[0]},${p[1]})`);
96
+ this.inner.attr('transform', `translate(${p[0]},${p[1]})`);
97
+ this.text.attr('x', `${p[0]}`).attr('y', `${p[1]}`);
98
+ }
99
+ zoom(k) {
100
+ const size = this.size / k;
101
+ const h = size / 12;
102
+ const dy = -size / 1.6;
103
+ const fs = size / 1.8;
104
+ // calculate inner triangle
105
+ const alpha = Math.atan(1 / 2);
106
+ const beta = Math.PI / 2 - alpha;
107
+ const x = h / Math.sin(alpha);
108
+ const y = h / Math.sin(beta) + h / Math.tan(beta);
109
+ this.triangle.attr('points', `0,0 ${size / 2},${-size} ${-size / 2},${-size}`);
110
+ this.inner.attr('points', `0,${-x} ${size / 2 - y},${-size + h} ${-size / 2 + y},${-size + h}`);
111
+ this.text.attr('font-size', `${fs}`).attr('dy', `${dy}`);
112
+ }
113
+ show() {
114
+ this.Element.attr('opacity', null);
115
+ }
116
+ hide() {
117
+ this.Element.attr('opacity', '0');
118
+ }
119
+ setDragHandler(handler) {
120
+ this.dragHandler = handler;
121
+ }
122
+ }
@@ -0,0 +1,8 @@
1
+ import { SmithShape } from './SmithShape.js';
2
+ import { SmithDrawOptions } from './SmithDrawOptions.js';
3
+ export declare class SmithPath extends SmithShape {
4
+ constructor(options?: SmithDrawOptions);
5
+ move(d: string): SmithPath;
6
+ hide(): void;
7
+ show(): void;
8
+ }
@@ -0,0 +1,20 @@
1
+ import * as d3 from 'd3';
2
+ import { SmithShape } from './SmithShape.js';
3
+ export class SmithPath extends SmithShape {
4
+ constructor(options) {
5
+ super(d3.select(document.createElementNS('http://www.w3.org/2000/svg', 'path')));
6
+ if (options) {
7
+ this.setDrawOptions(options);
8
+ }
9
+ }
10
+ move(d) {
11
+ this.element.attr('d', d);
12
+ return this;
13
+ }
14
+ hide() {
15
+ this.Element.attr('opacity', '0');
16
+ }
17
+ show() {
18
+ this.Element.attr('opacity', null);
19
+ }
20
+ }
@@ -0,0 +1,19 @@
1
+ import * as d3 from 'd3';
2
+ import { Circle } from '../shapes/Circle.js';
3
+ import { Point } from '../shapes/Point.js';
4
+ import { Line } from '../shapes/Line.js';
5
+ import { Arc } from '../shapes/Arc.js';
6
+ export declare class SmithScaler {
7
+ readonly x: d3.ScaleLinear<number, number>;
8
+ readonly y: d3.ScaleLinear<number, number>;
9
+ readonly r: d3.ScaleLinear<number, number>;
10
+ constructor(x: d3.ScaleLinear<number, number>, y: d3.ScaleLinear<number, number>, r: d3.ScaleLinear<number, number>);
11
+ point(p: Readonly<Point>): Point;
12
+ pointInvert(p: Readonly<Point>): Point;
13
+ line(l: Line): Line;
14
+ lineInvert(l: Line): Line;
15
+ circle(c: Circle): Circle;
16
+ circleInvert(c: Circle): Circle;
17
+ arc(a: Arc): Arc;
18
+ arcInvert(a: Arc): Arc;
19
+ }
@@ -0,0 +1,48 @@
1
+ export class SmithScaler {
2
+ x;
3
+ y;
4
+ r;
5
+ constructor(x, y, r) {
6
+ this.x = x;
7
+ this.y = y;
8
+ this.r = r;
9
+ }
10
+ point(p) {
11
+ return [this.x(p[0]), this.y(p[1])];
12
+ }
13
+ pointInvert(p) {
14
+ return [this.x.invert(p[0]), this.y.invert(p[1])];
15
+ }
16
+ line(l) {
17
+ return { p1: this.point(l.p1), p2: this.point(l.p2) };
18
+ }
19
+ lineInvert(l) {
20
+ return { p1: this.pointInvert(l.p1), p2: this.pointInvert(l.p2) };
21
+ }
22
+ circle(c) {
23
+ return {
24
+ p: this.point(c.p),
25
+ r: this.r(c.r),
26
+ };
27
+ }
28
+ circleInvert(c) {
29
+ return {
30
+ p: this.pointInvert(c.p),
31
+ r: this.r.invert(c.r),
32
+ };
33
+ }
34
+ arc(a) {
35
+ return {
36
+ p1: this.point(a.p1),
37
+ p2: this.point(a.p2),
38
+ r: this.r(a.r),
39
+ };
40
+ }
41
+ arcInvert(a) {
42
+ return {
43
+ p1: this.pointInvert(a.p1),
44
+ p2: this.pointInvert(a.p2),
45
+ r: this.r.invert(a.r),
46
+ };
47
+ }
48
+ }
@@ -0,0 +1,15 @@
1
+ import * as d3 from 'd3';
2
+ import { SmithDrawOptions } from './SmithDrawOptions.js';
3
+ export declare class SmithShape {
4
+ protected element: d3.Selection<SVGElement, unknown, null, undefined>;
5
+ constructor(element: d3.Selection<SVGElement, unknown, null, undefined>);
6
+ setDrawOptions(opts: SmithDrawOptions): SmithShape;
7
+ set Stroke(color: string);
8
+ get Stroke(): string;
9
+ set StrokeWidth(width: string);
10
+ get StrokeWidth(): string;
11
+ set Fill(color: string);
12
+ get Fill(): string;
13
+ get Node(): SVGElement | null;
14
+ get Element(): d3.Selection<SVGElement, unknown, null, undefined>;
15
+ }
@@ -0,0 +1,42 @@
1
+ export class SmithShape {
2
+ element;
3
+ constructor(element) {
4
+ this.element = element;
5
+ }
6
+ setDrawOptions(opts) {
7
+ if (opts.stroke) {
8
+ this.Stroke = opts.stroke;
9
+ }
10
+ if (opts.strokeWidth) {
11
+ this.StrokeWidth = opts.strokeWidth;
12
+ }
13
+ if (opts.fill) {
14
+ this.Fill = opts.fill;
15
+ }
16
+ return this;
17
+ }
18
+ set Stroke(color) {
19
+ this.element.attr('stroke', color);
20
+ }
21
+ get Stroke() {
22
+ return this.element.attr('stroke');
23
+ }
24
+ set StrokeWidth(width) {
25
+ this.element.attr('stroke-width', width);
26
+ }
27
+ get StrokeWidth() {
28
+ return this.element.attr('stroke-width');
29
+ }
30
+ set Fill(color) {
31
+ this.element.attr('fill', color);
32
+ }
33
+ get Fill() {
34
+ return this.element.attr('fill');
35
+ }
36
+ get Node() {
37
+ return this.element.node();
38
+ }
39
+ get Element() {
40
+ return this.element;
41
+ }
42
+ }
@@ -0,0 +1,9 @@
1
+ import * as d3 from 'd3';
2
+ import { SmithShape } from './SmithShape.js';
3
+ export declare class SmithSvg {
4
+ private container;
5
+ constructor(size: number);
6
+ get Node(): SVGElement | null;
7
+ append(el: SmithShape | null): SmithSvg;
8
+ get Element(): d3.Selection<SVGElement, unknown, null, undefined>;
9
+ }
@@ -0,0 +1,27 @@
1
+ import * as d3 from 'd3';
2
+ export class SmithSvg {
3
+ container;
4
+ constructor(size) {
5
+ this.container = d3
6
+ .select(document.createElementNS('http://www.w3.org/2000/svg', 'svg'))
7
+ .attr('version', '1.1')
8
+ .attr('xmlns', 'http://www.w3.org/2000/svg')
9
+ .attr('width', '100%')
10
+ .attr('height', '100%')
11
+ .attr('viewBox', `0 0 ${size} ${size}`)
12
+ .style('overflow', 'hidden')
13
+ .attr('preserveAspectRatio', 'xMidYMid meet');
14
+ }
15
+ get Node() {
16
+ return this.container.node();
17
+ }
18
+ append(el) {
19
+ if (el !== null) {
20
+ this.container.append(() => el.Node);
21
+ }
22
+ return this;
23
+ }
24
+ get Element() {
25
+ return this.container;
26
+ }
27
+ }
@@ -0,0 +1,22 @@
1
+ import { Point } from '../shapes/Point.js';
2
+ import { SmithShape } from './SmithShape.js';
3
+ interface TextOptions {
4
+ dx?: string;
5
+ dy?: string;
6
+ stroke?: string;
7
+ fill?: string;
8
+ fontFamily?: string;
9
+ fontSize?: string;
10
+ textAnchor?: string;
11
+ rotate?: number;
12
+ dominantBaseline?: string;
13
+ }
14
+ export declare class SmithText extends SmithShape {
15
+ private p;
16
+ constructor(p: Point, text: string, opts?: TextOptions);
17
+ move(p: Point): SmithText;
18
+ text(text: string): SmithText;
19
+ setTextOptions(opts: TextOptions): SmithText;
20
+ setDominantBaseline(db: string): void;
21
+ }
22
+ export {};
@@ -0,0 +1,56 @@
1
+ import * as d3 from 'd3';
2
+ import { SmithShape } from './SmithShape.js';
3
+ export class SmithText extends SmithShape {
4
+ p;
5
+ constructor(p, text, opts) {
6
+ super(d3.select(document.createElementNS('http://www.w3.org/2000/svg', 'text')));
7
+ this.p = p;
8
+ this.element.attr('pointer-events', 'none').text(text);
9
+ if (opts) {
10
+ this.setTextOptions(opts);
11
+ }
12
+ this.move(p);
13
+ }
14
+ move(p) {
15
+ this.element.attr('x', p[0]).attr('y', p[1]);
16
+ this.p = p;
17
+ return this;
18
+ }
19
+ text(text) {
20
+ this.element.text(text);
21
+ return this;
22
+ }
23
+ setTextOptions(opts) {
24
+ if (opts.dx) {
25
+ this.element.attr('dx', opts.dx);
26
+ }
27
+ if (opts.dy) {
28
+ this.element.attr('dy', opts.dy);
29
+ }
30
+ if (opts.stroke) {
31
+ this.element.attr('stroke', opts.stroke);
32
+ }
33
+ if (opts.fill) {
34
+ this.element.attr('fill', opts.fill);
35
+ }
36
+ if (opts.fontFamily) {
37
+ this.element.attr('font-family', opts.fontFamily);
38
+ }
39
+ if (opts.fontSize) {
40
+ this.element.attr('font-size', opts.fontSize);
41
+ }
42
+ if (opts.textAnchor) {
43
+ this.element.attr('text-anchor', opts.textAnchor);
44
+ }
45
+ if (opts.dominantBaseline) {
46
+ this.element.attr('dominant-baseline', opts.dominantBaseline);
47
+ }
48
+ if (opts.rotate !== undefined) {
49
+ this.element.attr('transform', `rotate(${opts.rotate}, ${this.p[0]}, ${this.p[1]})`);
50
+ }
51
+ return this;
52
+ }
53
+ setDominantBaseline(db) {
54
+ this.element.attr('dominant-baseline', db);
55
+ }
56
+ }
@@ -0,0 +1,7 @@
1
+ import type { Complex } from './complex/Complex.js';
2
+ /** Format with three significant digits and an SI prefix; includes spacing before the unit. */
3
+ export declare function formatNumber(value: number): string;
4
+ /** Format Cartesian components to decimalPlaces fractional digits. */
5
+ export declare function formatComplex(value: Complex, unit?: string, decimalPlaces?: number): string;
6
+ /** Format magnitude and phase in degrees to decimalPlaces fractional digits. */
7
+ export declare function formatComplexPolar(value: Complex, unit?: string, decimalPlaces?: number): string;
@@ -0,0 +1,16 @@
1
+ import { format } from 'd3';
2
+ /** Format with three significant digits and an SI prefix; includes spacing before the unit. */
3
+ export function formatNumber(value) {
4
+ const formatted = format('.3~s')(value);
5
+ return Number.isFinite(value) && /[a-zA-Zµ]$/.test(formatted)
6
+ ? formatted.replace(/([a-zA-Zµ])$/, ' $1')
7
+ : formatted + ' ';
8
+ }
9
+ /** Format Cartesian components to decimalPlaces fractional digits. */
10
+ export function formatComplex(value, unit = '', decimalPlaces = 3) {
11
+ return `${value.toString(decimalPlaces)} ${unit === '' ? '' : `[${unit}]`}`;
12
+ }
13
+ /** Format magnitude and phase in degrees to decimalPlaces fractional digits. */
14
+ export function formatComplexPolar(value, unit = '', decimalPlaces = 3) {
15
+ return `${value.abs().toFixed(decimalPlaces)} ${unit} ∠${((value.arg() * 180) / Math.PI).toFixed(decimalPlaces)}°`;
16
+ }
@@ -0,0 +1,3 @@
1
+ import type { SmithTicksData } from './types.js';
2
+ /** Build fresh definitions so callers cannot mutate another chart's grid. */
3
+ export declare function createGridDefinitions(): SmithTicksData;
@@ -0,0 +1,123 @@
1
+ function resistanceArcs(bands) {
2
+ return bands.flatMap(([values, from, to, largeArc]) => values.map((value) => [
3
+ value,
4
+ [
5
+ [from, from < 0 ? 1 : 0],
6
+ [to, to < 0 ? 1 : 0],
7
+ ],
8
+ [largeArc, from > to],
9
+ ]));
10
+ }
11
+ function reactanceArcs(bands) {
12
+ return bands.flatMap(([values, outer, inner]) => values.flatMap((value) => [
13
+ [
14
+ value,
15
+ [
16
+ [outer, 1],
17
+ [inner, 1],
18
+ ],
19
+ [false, false],
20
+ ],
21
+ [
22
+ -value,
23
+ [
24
+ [outer, 0],
25
+ [inner, 0],
26
+ ],
27
+ [false, true],
28
+ ],
29
+ ]));
30
+ }
31
+ const resistanceMajor = [
32
+ [[0.05, 0.15], 0.2, -0.2, false],
33
+ [[0.1, 0.3, 0.5, 0.7, 0.9], 2, -2, true],
34
+ [[0.2, 0.4, 0.6, 0.8, 1.2, 1.4, 1.6, 1.8], 5, -5, true],
35
+ [[1, 3, 5], 10, -10, true],
36
+ [[2, 4], 20, -20, true],
37
+ [[20], 50, -50, true],
38
+ ];
39
+ const resistanceMinor = [
40
+ [[0.02, 0.04, 0.06, 0.08, 0.12, 0.14, 0.16, 0.18], 0.2, 0.5, false],
41
+ [[0.02, 0.04, 0.06, 0.08, 0.12, 0.14, 0.16, 0.18], -0.2, -0.5, false],
42
+ [[0.05, 0.15, 0.25, 0.35, 0.45], 0.5, 1, false],
43
+ [[0.05, 0.15, 0.25, 0.35, 0.45], -0.5, -1, false],
44
+ [
45
+ [
46
+ 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,
47
+ 0.19,
48
+ ],
49
+ 0.2,
50
+ -0.2,
51
+ false,
52
+ ],
53
+ [[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],
54
+ [[0.55, 0.65, 0.75, 0.85, 0.95], 2, -2, true],
55
+ [[1.1, 1.3, 1.5, 1.7, 1.9], 2, -2, false],
56
+ [[2.2, 2.4, 2.6, 2.8, 3.2, 3.4, 3.6, 3.8], 5, -5, true],
57
+ [[4.2, 4.4, 4.6, 4.8], 5, -5, false],
58
+ [[6, 8, 12, 14, 16, 18], 20, -20, true],
59
+ [[7, 9], 10, -10, true],
60
+ [[30, 40], 50, -50, true],
61
+ ];
62
+ const reactanceMajor = [
63
+ [[0.05, 0.15], 0.2, 0],
64
+ [[0.1, 0.3, 0.5, 0.7, 0.9], 2, 0],
65
+ [[0.2, 0.4, 0.6, 0.8, 1.2, 1.4, 1.6, 1.8], 5, 0],
66
+ [[1, 3, 5], 10, 0],
67
+ [[2, 4, 10], 20, 0],
68
+ [[20], 50, 0],
69
+ ];
70
+ const reactanceMinor = [
71
+ [
72
+ [
73
+ 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,
74
+ 0.19,
75
+ ],
76
+ 0.2,
77
+ 0,
78
+ ],
79
+ [[0.02, 0.04, 0.06, 0.08, 0.12, 0.14, 0.16, 0.18], 0.5, 0.2],
80
+ [[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],
81
+ [[0.05, 0.15, 0.25, 0.35, 0.45], 1, 0.5],
82
+ [[0.55, 0.65, 0.75, 0.85, 0.95], 1, 0],
83
+ [[1.1, 1.3, 1.5, 1.7, 1.9], 2, 0],
84
+ [[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],
85
+ [[6, 8, 14, 16, 18], 20, 0],
86
+ [[7, 9], 10, 0],
87
+ [[12, 30, 40], 50, 0],
88
+ ];
89
+ /** Build fresh definitions so callers cannot mutate another chart's grid. */
90
+ export function createGridDefinitions() {
91
+ return {
92
+ resistance: {
93
+ major: { lines: [], circles: [10, 50], arcs: resistanceArcs(resistanceMajor) },
94
+ minor: { lines: [], circles: [], arcs: resistanceArcs(resistanceMinor) },
95
+ },
96
+ reactance: {
97
+ major: {
98
+ lines: [{ p1: [-1, 0], p2: [1, 0] }],
99
+ circles: [],
100
+ arcs: [
101
+ ...reactanceArcs(reactanceMajor),
102
+ [
103
+ 50,
104
+ [
105
+ [0, 0],
106
+ [0, 1],
107
+ ],
108
+ [false, false],
109
+ ],
110
+ [
111
+ -50,
112
+ [
113
+ [0, 1],
114
+ [0, 0],
115
+ ],
116
+ [false, true],
117
+ ],
118
+ ],
119
+ },
120
+ minor: { lines: [], circles: [], arcs: reactanceArcs(reactanceMinor) },
121
+ },
122
+ };
123
+ }