circuitscript 0.0.16 → 0.0.17
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/__tests__/renderData/script5.cst.svg +1 -1
- package/build/src/draw_symbols.js +15 -2
- package/examples/lib.cst +1 -1
- package/libs/lib.cst +1 -1
- package/package.json +1 -1
- package/src/draw_symbols.ts +15 -3
|
@@ -1 +1 @@
|
|
|
1
|
-
<svg xmlns="http://www.w3.org/2000/svg" version="1.1" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:svgjs="http://svgjs.dev/svgjs" width="190" height="310.5" viewBox="-25 -25.5 190 310.5"><g transform="matrix(1,0,0,1,0,0)"><path d="M -20 -20.5 L -20 280 M 0 -20.5 L 0 280 M 20 -20.5 L 20 280 M 40 -20.5 L 40 280 M 60 -20.5 L 60 280 M 80 -20.5 L 80 280 M 100 -20.5 L 100 280 M 120 -20.5 L 120 280 M 140 -20.5 L 140 280 M 160 -20.5 L 160 280" fill="none" stroke-dasharray="1,19" stroke-width="1" stroke="#aaaaaa"></path></g><g transform="matrix(1,0,0,1,20,90)"><g><path d="M -10 0 L 10 0 L 0 10 Z" stroke-width="1" stroke="#333333" fill="#ffffff"></path><path d="M 0 -10 L 0 0" stroke-width="2" stroke="#333333"></path><g transform="matrix(1,0,0,1,0,20)"><text fill="#333333" font-family="Open Sans-Regular, Arial" font-size="10" text-anchor="middle" dominant-baseline="text-top" font-weight="regular" transform="matrix(1,0,0,1,0,0)" svgjs:data="{"leading":"1.3"}"><tspan dy="0" x="0" svgjs:data="{"newLined":true}">GND</tspan></text></g></g></g><g transform="matrix(1,0,0,1,70,60)"><g><path d="M 10.000000000000002 -9.999999999999998 L 9.999999999999998 10.000000000000002 L -10 -1.2246467991473533e-15 Z" stroke-width="1" stroke="#333333" fill="#ffffff"></path><path d="M -10.000000000000002 9.999999999999998 L -9.999999999999998 -10.000000000000002" stroke-width="1" stroke="#333333" fill="none"></path><path d="M 9.797174393178826e-16 -8 L -4.999999999999998 -18" stroke-width="1" stroke="#333333" fill="none"></path><path d="M -2.999999999999999 -8 L -7.999999999999998 -18" stroke-width="1" stroke="#333333" fill="none"></path><path d="M 30 3.67394039744206e-15 L 10 1.2246467991473533e-15 M -30 -3.67394039744206e-15 L -10 -1.2246467991473533e-15" stroke-width="2" stroke="#333333"></path><g transform="matrix(1,0,0,1,12
|
|
1
|
+
<svg xmlns="http://www.w3.org/2000/svg" version="1.1" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:svgjs="http://svgjs.dev/svgjs" width="190" height="310.5" viewBox="-25 -25.5 190 310.5"><g transform="matrix(1,0,0,1,0,0)"><path d="M -20 -20.5 L -20 280 M 0 -20.5 L 0 280 M 20 -20.5 L 20 280 M 40 -20.5 L 40 280 M 60 -20.5 L 60 280 M 80 -20.5 L 80 280 M 100 -20.5 L 100 280 M 120 -20.5 L 120 280 M 140 -20.5 L 140 280 M 160 -20.5 L 160 280" fill="none" stroke-dasharray="1,19" stroke-width="1" stroke="#aaaaaa"></path></g><g transform="matrix(1,0,0,1,20,90)"><g><path d="M -10 0 L 10 0 L 0 10 Z" stroke-width="1" stroke="#333333" fill="#ffffff"></path><path d="M 0 -10 L 0 0" stroke-width="2" stroke="#333333"></path><g transform="matrix(1,0,0,1,0,20)"><text fill="#333333" font-family="Open Sans-Regular, Arial" font-size="10" text-anchor="middle" dominant-baseline="text-top" font-weight="regular" transform="matrix(1,0,0,1,0,0)" svgjs:data="{"leading":"1.3"}"><tspan dy="0" x="0" svgjs:data="{"newLined":true}">GND</tspan></text></g></g></g><g transform="matrix(1,0,0,1,70,60)"><g><path d="M 10.000000000000002 -9.999999999999998 L 9.999999999999998 10.000000000000002 L -10 -1.2246467991473533e-15 Z" stroke-width="1" stroke="#333333" fill="#ffffff"></path><path d="M -10.000000000000002 9.999999999999998 L -9.999999999999998 -10.000000000000002" stroke-width="1" stroke="#333333" fill="none"></path><path d="M 9.797174393178826e-16 -8 L -4.999999999999998 -18" stroke-width="1" stroke="#333333" fill="none"></path><path d="M -2.999999999999999 -8 L -7.999999999999998 -18" stroke-width="1" stroke="#333333" fill="none"></path><path d="M 30 3.67394039744206e-15 L 10 1.2246467991473533e-15 M -30 -3.67394039744206e-15 L -10 -1.2246467991473533e-15" stroke-width="2" stroke="#333333"></path><g transform="matrix(1,0,0,1,12,2)"><text fill="#333333" font-family="Open Sans-Regular, Arial" font-size="8" text-anchor="start" dominant-baseline="hanging" font-weight="regular" transform="matrix(1,0,0,1,0,0)" svgjs:data="{"leading":"1.3"}"><tspan dy="0" x="0" svgjs:data="{"newLined":true}">1</tspan></text></g><g transform="matrix(1,0,0,1,-12,2)"><text fill="#333333" font-family="Open Sans-Regular, Arial" font-size="8" text-anchor="end" dominant-baseline="hanging" font-weight="regular" transform="matrix(1,0,0,1,0,0)" svgjs:data="{"leading":"1.3"}"><tspan dy="0" x="0" svgjs:data="{"newLined":true}">2</tspan></text></g><g transform="matrix(1,0,0,1,-15,-5)"><text fill="#333333" font-family="Open Sans-Regular, Arial" font-size="10" text-anchor="end" dominant-baseline="text-top" font-weight="regular" transform="matrix(1,0,0,1,0,0)" svgjs:data="{"leading":"1.3"}"><tspan dy="0" x="0" svgjs:data="{"newLined":true}">D1</tspan></text></g><g transform="matrix(1,0,0,1,-15,-25)"><text fill="#333333" font-family="Open Sans-Regular, Arial" font-size="10" text-anchor="end" dominant-baseline="hanging" font-weight="regular" transform="matrix(1,0,0,1,0,0)" svgjs:data="{"leading":"1.3"}"><tspan dy="0" x="0" svgjs:data="{"newLined":true}">GREEN</tspan></text></g></g></g><g transform="matrix(1,0,0,1,120,30.000000000000007)"><g><path d="M -15 0 L 15 0" stroke-width="1" stroke="#333333" fill="none"></path><path d="M 0 10 L 0 0" stroke-width="2" stroke="#333333"></path><g transform="matrix(1,0,0,1,0,-5)"><text fill="#333333" font-family="Open Sans-Regular, Arial" font-size="10" text-anchor="middle" dominant-baseline="text-top" font-weight="regular" transform="matrix(1,0,0,1,0,0)" svgjs:data="{"leading":"1.3"}"><tspan dy="0" x="0" svgjs:data="{"newLined":true}">5v</tspan></text></g></g></g><g transform="matrix(1,0,0,1,20,170)"><g><path d="M -15 0 L 15 0" stroke-width="1" stroke="#333333" fill="none"></path><path d="M 0 10 L 0 0" stroke-width="2" stroke="#333333"></path><g transform="matrix(1,0,0,1,0,-5)"><text fill="#333333" font-family="Open Sans-Regular, Arial" font-size="10" text-anchor="middle" dominant-baseline="text-top" font-weight="regular" transform="matrix(1,0,0,1,0,0)" svgjs:data="{"leading":"1.3"}"><tspan dy="0" x="0" svgjs:data="{"newLined":true}">5v</tspan></text></g></g></g><g transform="matrix(1,0,0,1,70,200)"><g><path d="M -10 10 L -10 -10 L 10 0 Z" stroke-width="1" stroke="#333333" fill="#ffffff"></path><path d="M 10 -10 L 10 10" stroke-width="1" stroke="#333333" fill="none"></path><path d="M 0 8 L 5 18" stroke-width="1" stroke="#333333" fill="none"></path><path d="M 3 8 L 8 18" stroke-width="1" stroke="#333333" fill="none"></path><path d="M -30 0 L -10 0 M 30 0 L 10 0" stroke-width="2" stroke="#333333"></path><g transform="matrix(1,0,0,1,-12,-2)"><text fill="#333333" font-family="Open Sans-Regular, Arial" font-size="8" text-anchor="end" dominant-baseline="text-top" font-weight="regular" transform="matrix(1,0,0,1,0,0)" svgjs:data="{"leading":"1.3"}"><tspan dy="0" x="0" svgjs:data="{"newLined":true}">1</tspan></text></g><g transform="matrix(1,0,0,1,12,-2)"><text fill="#333333" font-family="Open Sans-Regular, Arial" font-size="8" text-anchor="start" dominant-baseline="text-top" font-weight="regular" transform="matrix(1,0,0,1,0,0)" svgjs:data="{"leading":"1.3"}"><tspan dy="0" x="0" svgjs:data="{"newLined":true}">2</tspan></text></g><g transform="matrix(1,0,0,1,15,5)"><text fill="#333333" font-family="Open Sans-Regular, Arial" font-size="10" text-anchor="start" dominant-baseline="hanging" font-weight="regular" transform="matrix(1,0,0,1,0,0)" svgjs:data="{"leading":"1.3"}"><tspan dy="0" x="0" svgjs:data="{"newLined":true}">D2</tspan></text></g><g transform="matrix(1,0,0,1,15,25)"><text fill="#333333" font-family="Open Sans-Regular, Arial" font-size="10" text-anchor="start" dominant-baseline="text-top" font-weight="regular" transform="matrix(1,0,0,1,0,0)" svgjs:data="{"leading":"1.3"}"><tspan dy="0" x="0" svgjs:data="{"newLined":true}">RED</tspan></text></g></g></g><g transform="matrix(1,0,0,1,120,230)"><g><path d="M -10 0 L 10 0 L 0 10 Z" stroke-width="1" stroke="#333333" fill="#ffffff"></path><path d="M 0 -10 L 0 0" stroke-width="2" stroke="#333333"></path><g transform="matrix(1,0,0,1,0,20)"><text fill="#333333" font-family="Open Sans-Regular, Arial" font-size="10" text-anchor="middle" dominant-baseline="text-top" font-weight="regular" transform="matrix(1,0,0,1,0,0)" svgjs:data="{"leading":"1.3"}"><tspan dy="0" x="0" svgjs:data="{"newLined":true}">GND</tspan></text></g></g></g><g><line x1="20" y1="80" x2="20" y2="60" stroke-linecap="square" stroke-width="1" stroke="#008400" fill="none"></line><line x1="20" y1="60" x2="40" y2="60" stroke-linecap="square" stroke-width="1" stroke="#008400" fill="none"></line><line x1="100" y1="200" x2="120" y2="200" stroke-linecap="square" stroke-width="1" stroke="#008400" fill="none"></line><line x1="120" y1="200" x2="120" y2="220" stroke-linecap="square" stroke-width="1" stroke="#008400" fill="none"></line><line x1="100" y1="60.00000000000001" x2="120" y2="60.00000000000001" stroke-linecap="square" stroke-width="1" stroke="#008400" fill="none"></line><line x1="120" y1="60.00000000000001" x2="120" y2="40.00000000000001" stroke-linecap="square" stroke-width="1" stroke="#008400" fill="none"></line><line x1="20" y1="180" x2="20" y2="200" stroke-linecap="square" stroke-width="1" stroke="#008400" fill="none"></line><line x1="20" y1="200" x2="40" y2="200" stroke-linecap="square" stroke-width="1" stroke="#008400" fill="none"></line></g><g></g></svg>
|
|
@@ -102,9 +102,11 @@ export class SymbolGraphic {
|
|
|
102
102
|
let anchorStyle = 'start';
|
|
103
103
|
let dominantBaseline = 'auto';
|
|
104
104
|
let useAnchor = anchor;
|
|
105
|
+
let useDominantBaseline = vanchor;
|
|
105
106
|
const isRotation180 = Math.abs(this.angle) === 180;
|
|
106
107
|
if (isRotation180) {
|
|
107
108
|
useAnchor = this.flipTextAnchor(anchor);
|
|
109
|
+
useDominantBaseline = this.flipDominantBaseline(vanchor);
|
|
108
110
|
}
|
|
109
111
|
switch (useAnchor) {
|
|
110
112
|
case HorizontalAlign.Left:
|
|
@@ -117,7 +119,7 @@ export class SymbolGraphic {
|
|
|
117
119
|
anchorStyle = 'end';
|
|
118
120
|
break;
|
|
119
121
|
}
|
|
120
|
-
switch (
|
|
122
|
+
switch (useDominantBaseline) {
|
|
121
123
|
case VerticalAlign.Top:
|
|
122
124
|
dominantBaseline = 'hanging';
|
|
123
125
|
break;
|
|
@@ -144,7 +146,7 @@ export class SymbolGraphic {
|
|
|
144
146
|
let useRotateAngle = 0;
|
|
145
147
|
if (isRotation180) {
|
|
146
148
|
translateX = -position[0];
|
|
147
|
-
translateY = position[1];
|
|
149
|
+
translateY = -position[1];
|
|
148
150
|
useRotateAngle = 0;
|
|
149
151
|
}
|
|
150
152
|
else {
|
|
@@ -168,6 +170,17 @@ export class SymbolGraphic {
|
|
|
168
170
|
return HorizontalAlign.Middle;
|
|
169
171
|
}
|
|
170
172
|
}
|
|
173
|
+
flipDominantBaseline(value) {
|
|
174
|
+
if (value === VerticalAlign.Top) {
|
|
175
|
+
return VerticalAlign.Bottom;
|
|
176
|
+
}
|
|
177
|
+
else if (value === VerticalAlign.Bottom) {
|
|
178
|
+
return VerticalAlign.Top;
|
|
179
|
+
}
|
|
180
|
+
else {
|
|
181
|
+
return VerticalAlign.Middle;
|
|
182
|
+
}
|
|
183
|
+
}
|
|
171
184
|
setLabelValue(labelId, labelValue) {
|
|
172
185
|
this.labelTexts.set(labelId, labelValue);
|
|
173
186
|
}
|
package/examples/lib.cst
CHANGED
package/libs/lib.cst
CHANGED
package/package.json
CHANGED
package/src/draw_symbols.ts
CHANGED
|
@@ -161,11 +161,13 @@ export abstract class SymbolGraphic {
|
|
|
161
161
|
let dominantBaseline = 'auto';
|
|
162
162
|
|
|
163
163
|
let useAnchor = anchor;
|
|
164
|
+
let useDominantBaseline = vanchor;
|
|
164
165
|
const isRotation180 = Math.abs(this.angle) === 180;
|
|
165
166
|
|
|
166
|
-
if (isRotation180){
|
|
167
|
+
if (isRotation180) {
|
|
167
168
|
// Special case to flip the text instead of rotating
|
|
168
169
|
useAnchor = this.flipTextAnchor(anchor);
|
|
170
|
+
useDominantBaseline = this.flipDominantBaseline(vanchor);
|
|
169
171
|
}
|
|
170
172
|
|
|
171
173
|
switch(useAnchor){
|
|
@@ -182,7 +184,7 @@ export abstract class SymbolGraphic {
|
|
|
182
184
|
break;
|
|
183
185
|
}
|
|
184
186
|
|
|
185
|
-
switch(
|
|
187
|
+
switch(useDominantBaseline){
|
|
186
188
|
case VerticalAlign.Top:
|
|
187
189
|
dominantBaseline = 'hanging';
|
|
188
190
|
break;
|
|
@@ -215,7 +217,7 @@ export abstract class SymbolGraphic {
|
|
|
215
217
|
|
|
216
218
|
if (isRotation180){
|
|
217
219
|
translateX = -position[0];
|
|
218
|
-
translateY = position[1];
|
|
220
|
+
translateY = -position[1];
|
|
219
221
|
useRotateAngle = 0;
|
|
220
222
|
} else {
|
|
221
223
|
translateX = position[0];
|
|
@@ -242,6 +244,16 @@ export abstract class SymbolGraphic {
|
|
|
242
244
|
}
|
|
243
245
|
}
|
|
244
246
|
|
|
247
|
+
flipDominantBaseline(value: VerticalAlign): VerticalAlign {
|
|
248
|
+
if (value === VerticalAlign.Top) {
|
|
249
|
+
return VerticalAlign.Bottom;
|
|
250
|
+
} else if (value === VerticalAlign.Bottom) {
|
|
251
|
+
return VerticalAlign.Top;
|
|
252
|
+
} else {
|
|
253
|
+
return VerticalAlign.Middle;
|
|
254
|
+
}
|
|
255
|
+
}
|
|
256
|
+
|
|
245
257
|
setLabelValue(labelId: string, labelValue: string): void {
|
|
246
258
|
this.labelTexts.set(labelId, labelValue);
|
|
247
259
|
}
|