smithkit 0.1.0 → 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.
- package/README.md +5 -19
- package/dist/lib/Smith.js +11 -0
- package/dist/lib/draw/ConstCircles.d.ts +2 -0
- package/dist/lib/draw/ConstCircles.js +10 -3
- package/dist/lib/scales/SmithPeripheralScales.d.ts +3 -0
- package/dist/lib/scales/SmithPeripheralScales.js +19 -2
- package/dist/lib/scales/SmithScales.js +12 -4
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -20,29 +20,15 @@ interactive SVG Smith charts, RF calculations, and S11 measurement exploration.
|
|
|
20
20
|
|
|
21
21
|
## Installation
|
|
22
22
|
|
|
23
|
-
|
|
23
|
+
Install from npm:
|
|
24
24
|
|
|
25
25
|
```sh
|
|
26
|
-
npm install smithkit
|
|
26
|
+
npm install smithkit
|
|
27
27
|
```
|
|
28
28
|
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
git clone https://github.com/rosek86/smithkit.git
|
|
33
|
-
cd smithkit
|
|
34
|
-
npm ci
|
|
35
|
-
npm pack
|
|
36
|
-
```
|
|
37
|
-
|
|
38
|
-
Install the resulting archive in your application:
|
|
39
|
-
|
|
40
|
-
```sh
|
|
41
|
-
npm install /path/to/smithkit/smithkit-0.1.0.tgz
|
|
42
|
-
```
|
|
43
|
-
|
|
44
|
-
Building requires Node.js 24 or later. Browser applications need SVG, ES2022,
|
|
45
|
-
and an ESM-compatible build tool. No library stylesheet is required.
|
|
29
|
+
Browser applications need SVG, ES2022, and an ESM-compatible build tool.
|
|
30
|
+
No library stylesheet is required. To build the library from source, see
|
|
31
|
+
[Contributing](https://github.com/rosek86/smithkit/blob/main/CONTRIBUTING.md).
|
|
46
32
|
|
|
47
33
|
For a complete application using the installed package, see the
|
|
48
34
|
[standalone integration example](https://github.com/rosek86/smithkit/tree/main/examples/basic).
|
package/dist/lib/Smith.js
CHANGED
|
@@ -123,6 +123,17 @@ export class Smith {
|
|
|
123
123
|
this.container.append(cursorContainer);
|
|
124
124
|
this.container.append(this.dataContainer);
|
|
125
125
|
this.container.append(this.markerContainer);
|
|
126
|
+
const labels = new SmithGroup().attr('data-layer', 'labels').attr('pointer-events', 'none');
|
|
127
|
+
for (const [name, layer] of [
|
|
128
|
+
['conductance', this.constConductance],
|
|
129
|
+
['susceptance', this.constSusceptance],
|
|
130
|
+
['resistance', this.constResistance],
|
|
131
|
+
['reactance', this.constReactance],
|
|
132
|
+
]) {
|
|
133
|
+
labels.append(layer.labels.attr('data-label-layer', name));
|
|
134
|
+
}
|
|
135
|
+
labels.append(this.peripheralScaleRenderer.labels);
|
|
136
|
+
this.container.append(labels);
|
|
126
137
|
const assertAlive = () => this.assertAlive();
|
|
127
138
|
this.layers = {
|
|
128
139
|
resistance: gridLayer(this.constResistance, assertAlive),
|
|
@@ -41,6 +41,8 @@ export declare abstract class ConstCircles {
|
|
|
41
41
|
showMinor(): void;
|
|
42
42
|
hideMinor(): void;
|
|
43
43
|
protected build(): SmithGroup;
|
|
44
|
+
/** Mount labels separately so every grid line is painted before any label. */
|
|
45
|
+
get labels(): SmithGroup;
|
|
44
46
|
draw(): SmithGroup;
|
|
45
47
|
setDrawOptions(opts: ConstCirclesDrawOptions): void;
|
|
46
48
|
set Stroke(stroke: string);
|
|
@@ -12,17 +12,19 @@ export class ConstCircles {
|
|
|
12
12
|
}
|
|
13
13
|
visibility(visible) {
|
|
14
14
|
if (visible) {
|
|
15
|
-
this.
|
|
15
|
+
this.show();
|
|
16
16
|
}
|
|
17
17
|
else {
|
|
18
|
-
this.
|
|
18
|
+
this.hide();
|
|
19
19
|
}
|
|
20
20
|
}
|
|
21
21
|
show() {
|
|
22
22
|
this.container.show();
|
|
23
|
+
this.texts.show();
|
|
23
24
|
}
|
|
24
25
|
hide() {
|
|
25
26
|
this.container.hide();
|
|
27
|
+
this.texts.hide();
|
|
26
28
|
}
|
|
27
29
|
displayMinor(display) {
|
|
28
30
|
if (display) {
|
|
@@ -39,7 +41,12 @@ export class ConstCircles {
|
|
|
39
41
|
this.minor.hide();
|
|
40
42
|
}
|
|
41
43
|
build() {
|
|
42
|
-
|
|
44
|
+
this.texts.hide();
|
|
45
|
+
return this.container.append(this.minor).append(this.major).hide();
|
|
46
|
+
}
|
|
47
|
+
/** Mount labels separately so every grid line is painted before any label. */
|
|
48
|
+
get labels() {
|
|
49
|
+
return this.texts;
|
|
43
50
|
}
|
|
44
51
|
draw() {
|
|
45
52
|
return this.container;
|
|
@@ -2,9 +2,12 @@ import type { Complex } from '../complex/Complex.js';
|
|
|
2
2
|
import { SmithGroup } from '../draw/SmithGroup.js';
|
|
3
3
|
/** Peripheral rulers in the chart's 500-unit coordinate system. */
|
|
4
4
|
export declare class SmithPeripheralScales extends SmithGroup {
|
|
5
|
+
readonly labels: SmithGroup;
|
|
5
6
|
private readonly scales;
|
|
6
7
|
private readonly axes;
|
|
7
8
|
constructor();
|
|
9
|
+
show(): SmithGroup;
|
|
10
|
+
hide(): SmithGroup;
|
|
8
11
|
/** Connect to the same cursor or marker data as the independent parameter scales. */
|
|
9
12
|
update(gamma: Complex | null): void;
|
|
10
13
|
}
|
|
@@ -10,6 +10,9 @@ function point(radius, degrees) {
|
|
|
10
10
|
}
|
|
11
11
|
/** Peripheral rulers in the chart's 500-unit coordinate system. */
|
|
12
12
|
export class SmithPeripheralScales extends SmithGroup {
|
|
13
|
+
labels = new SmithGroup()
|
|
14
|
+
.attr('data-label-layer', 'peripheral-scales')
|
|
15
|
+
.attr('pointer-events', 'none');
|
|
13
16
|
scales = peripheralScales();
|
|
14
17
|
axes = this.Element.attr('data-layer', 'peripheral-scales')
|
|
15
18
|
.attr('pointer-events', 'none')
|
|
@@ -21,7 +24,13 @@ export class SmithPeripheralScales extends SmithGroup {
|
|
|
21
24
|
.attr('aria-label', (scale) => scale.title);
|
|
22
25
|
constructor() {
|
|
23
26
|
super();
|
|
27
|
+
const labelAxes = this.labels.Element.selectAll('g')
|
|
28
|
+
.data(this.scales)
|
|
29
|
+
.join('g')
|
|
30
|
+
.attr('data-label-scale', (scale) => scale.id)
|
|
31
|
+
.nodes();
|
|
24
32
|
this.axes.each(function (scale, index) {
|
|
33
|
+
const labelAxis = select(labelAxes[index]);
|
|
25
34
|
const axis = select(this);
|
|
26
35
|
const radius = firstRadius + index * ringSpacing;
|
|
27
36
|
const captionAngle = scale.unit === 'λ' ? 180 : 0;
|
|
@@ -53,7 +62,7 @@ export class SmithPeripheralScales extends SmithGroup {
|
|
|
53
62
|
if (major && captionDistance > 25) {
|
|
54
63
|
const [x, y] = point(radius + 8, angle);
|
|
55
64
|
const rotation = angle >= 0 ? 90 - angle : -90 - angle;
|
|
56
|
-
|
|
65
|
+
labelAxis
|
|
57
66
|
.append('text')
|
|
58
67
|
.attr('x', x)
|
|
59
68
|
.attr('y', y)
|
|
@@ -81,7 +90,7 @@ export class SmithPeripheralScales extends SmithGroup {
|
|
|
81
90
|
? 'WAVELENGTHS TOWARD GENERATOR →'
|
|
82
91
|
: '← WAVELENGTHS TOWARD LOAD'
|
|
83
92
|
: scale.title.toUpperCase();
|
|
84
|
-
|
|
93
|
+
labelAxis
|
|
85
94
|
.append('text')
|
|
86
95
|
.attr('class', 'peripheral-caption')
|
|
87
96
|
.attr('text-anchor', 'middle')
|
|
@@ -104,6 +113,14 @@ export class SmithPeripheralScales extends SmithGroup {
|
|
|
104
113
|
.attr('stroke-width', 1);
|
|
105
114
|
});
|
|
106
115
|
}
|
|
116
|
+
show() {
|
|
117
|
+
this.labels.show();
|
|
118
|
+
return super.show();
|
|
119
|
+
}
|
|
120
|
+
hide() {
|
|
121
|
+
this.labels.hide();
|
|
122
|
+
return super.hide();
|
|
123
|
+
}
|
|
107
124
|
/** Connect to the same cursor or marker data as the independent parameter scales. */
|
|
108
125
|
update(gamma) {
|
|
109
126
|
const valid = gamma !== null && Number.isFinite(gamma.abs()) && gamma.abs() <= 1;
|
|
@@ -24,7 +24,8 @@ export class SmithScales {
|
|
|
24
24
|
.style('width', '100%')
|
|
25
25
|
.style('height', 'auto');
|
|
26
26
|
constructor() {
|
|
27
|
-
this.axes
|
|
27
|
+
const labels = this.axes.append('g').attr('data-role', 'labels').attr('pointer-events', 'none');
|
|
28
|
+
labels
|
|
28
29
|
.append('text')
|
|
29
30
|
.attr('x', this.start)
|
|
30
31
|
.attr('y', 12)
|
|
@@ -32,7 +33,7 @@ export class SmithScales {
|
|
|
32
33
|
.attr('font-size', 12)
|
|
33
34
|
.attr('fill', '#334155')
|
|
34
35
|
.text((scale) => scale.title);
|
|
35
|
-
|
|
36
|
+
labels
|
|
36
37
|
.append('text')
|
|
37
38
|
.attr('class', 'scale-value')
|
|
38
39
|
.attr('x', this.start)
|
|
@@ -55,12 +56,18 @@ export class SmithScales {
|
|
|
55
56
|
const length = this.length;
|
|
56
57
|
this.axes.each(function (scale) {
|
|
57
58
|
const ticks = select(this)
|
|
58
|
-
.selectAll('g')
|
|
59
|
+
.selectAll('g.scale-tick')
|
|
59
60
|
.data(scale.values)
|
|
60
61
|
.join('g')
|
|
62
|
+
.attr('class', 'scale-tick')
|
|
61
63
|
.attr('transform', (value) => `translate(${start + length * scale.position(value)},36)`);
|
|
62
64
|
ticks.append('line').attr('y2', 5).attr('stroke', '#64748b').attr('stroke-width', 1);
|
|
63
|
-
|
|
65
|
+
select(this)
|
|
66
|
+
.select('[data-role=labels]')
|
|
67
|
+
.selectAll('g')
|
|
68
|
+
.data(scale.values)
|
|
69
|
+
.join('g')
|
|
70
|
+
.attr('transform', (value) => `translate(${start + length * scale.position(value)},36)`)
|
|
64
71
|
.append('text')
|
|
65
72
|
.attr('y', 17)
|
|
66
73
|
.attr('font-size', 10)
|
|
@@ -79,6 +86,7 @@ export class SmithScales {
|
|
|
79
86
|
.attr('fill', '#dc2626')
|
|
80
87
|
.attr('stroke', 'white')
|
|
81
88
|
.attr('stroke-width', 1);
|
|
89
|
+
labels.raise();
|
|
82
90
|
this.axes.append('title').text((scale) => scale.description ?? scale.title);
|
|
83
91
|
}
|
|
84
92
|
draw(target) {
|