circuitscript 0.1.0 → 0.1.3
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/dist/cjs/BaseVisitor.js +13 -8
- package/dist/cjs/antlr/CircuitScriptLexer.js +80 -80
- package/dist/cjs/antlr/CircuitScriptParser.js +599 -657
- package/dist/cjs/builtinMethods.js +27 -8
- package/dist/cjs/draw_symbols.js +320 -197
- package/dist/cjs/execute.js +114 -116
- package/dist/cjs/export.js +2 -4
- package/dist/cjs/geometry.js +52 -19
- package/dist/cjs/globals.js +17 -12
- package/dist/cjs/helpers.js +16 -3
- package/dist/cjs/layout.js +473 -354
- package/dist/cjs/logger.js +8 -1
- package/dist/cjs/objects/ClassComponent.js +22 -22
- package/dist/cjs/objects/ExecutionScope.js +10 -4
- package/dist/cjs/objects/Frame.js +11 -2
- package/dist/cjs/objects/ParamDefinition.js +123 -4
- package/dist/cjs/objects/PinDefinition.js +1 -4
- package/dist/cjs/render.js +76 -138
- package/dist/cjs/sizing.js +33 -7
- package/dist/cjs/utils.js +86 -2
- package/dist/cjs/visitor.js +224 -255
- package/dist/esm/BaseVisitor.mjs +15 -10
- package/dist/esm/antlr/CircuitScriptLexer.mjs +80 -80
- package/dist/esm/antlr/CircuitScriptParser.mjs +599 -657
- package/dist/esm/builtinMethods.mjs +24 -8
- package/dist/esm/draw_symbols.mjs +322 -200
- package/dist/esm/execute.mjs +116 -118
- package/dist/esm/export.mjs +2 -4
- package/dist/esm/geometry.mjs +52 -19
- package/dist/esm/globals.mjs +17 -12
- package/dist/esm/helpers.mjs +17 -4
- package/dist/esm/layout.mjs +479 -360
- package/dist/esm/logger.mjs +8 -1
- package/dist/esm/objects/ClassComponent.mjs +21 -26
- package/dist/esm/objects/ExecutionScope.mjs +10 -4
- package/dist/esm/objects/Frame.mjs +10 -1
- package/dist/esm/objects/ParamDefinition.mjs +122 -3
- package/dist/esm/objects/PinDefinition.mjs +0 -2
- package/dist/esm/render.mjs +79 -141
- package/dist/esm/sizing.mjs +34 -8
- package/dist/esm/utils.mjs +80 -1
- package/dist/esm/visitor.mjs +226 -257
- package/dist/types/BaseVisitor.d.ts +1 -1
- package/dist/types/antlr/CircuitScriptParser.d.ts +2 -3
- package/dist/types/draw_symbols.d.ts +72 -45
- package/dist/types/execute.d.ts +15 -10
- package/dist/types/geometry.d.ts +31 -19
- package/dist/types/globals.d.ts +15 -11
- package/dist/types/helpers.d.ts +2 -1
- package/dist/types/layout.d.ts +35 -54
- package/dist/types/logger.d.ts +1 -1
- package/dist/types/objects/ClassComponent.d.ts +19 -16
- package/dist/types/objects/ExecutionScope.d.ts +3 -2
- package/dist/types/objects/Frame.d.ts +9 -2
- package/dist/types/objects/ParamDefinition.d.ts +32 -2
- package/dist/types/objects/PinDefinition.d.ts +0 -2
- package/dist/types/render.d.ts +2 -1
- package/dist/types/utils.d.ts +14 -1
- package/dist/types/visitor.d.ts +4 -5
- package/libs/lib.cst +25 -8
- package/package.json +7 -3
package/dist/cjs/render.js
CHANGED
|
@@ -22,19 +22,21 @@ function createSvgCanvas() {
|
|
|
22
22
|
(0, sizing_js_1.applyFontsToSVG)(canvas);
|
|
23
23
|
return canvas;
|
|
24
24
|
}
|
|
25
|
-
function renderSheetsToSVG(sheetFrames) {
|
|
25
|
+
function renderSheetsToSVG(sheetFrames, logger) {
|
|
26
26
|
const canvas = createSvgCanvas();
|
|
27
27
|
sheetFrames.forEach((sheet, index) => {
|
|
28
28
|
const sheetGroup = canvas.group();
|
|
29
|
-
sheetGroup.id('sheet-' + index);
|
|
29
|
+
sheetGroup.id('sheet-' + index).addClass('sheet');
|
|
30
|
+
logger.add('rendering sheet: sheet-' + index);
|
|
30
31
|
const { components, wires, junctions, mergedWires, frames, textObjects } = sheet;
|
|
31
32
|
const allFrames = [sheet.frame, ...frames];
|
|
32
33
|
let gridBounds = null;
|
|
33
34
|
let extendGrid = true;
|
|
34
35
|
let xOffset = 0;
|
|
35
36
|
let yOffset = 0;
|
|
36
|
-
let sheetYOffset = 0;
|
|
37
|
+
let sheetYOffset = (0, ParamDefinition_js_1.numeric)(0);
|
|
37
38
|
if (sheet.frame.frame) {
|
|
39
|
+
logger.add('drawing frame');
|
|
38
40
|
const frameComponent = sheet.frame.frame.parameters
|
|
39
41
|
.get(Frame_js_1.FrameParamKeys.SheetType);
|
|
40
42
|
if (frameComponent) {
|
|
@@ -42,34 +44,43 @@ function renderSheetsToSVG(sheetFrames) {
|
|
|
42
44
|
throw 'Invalid graphic object for sheet frame';
|
|
43
45
|
}
|
|
44
46
|
const frameRects = (0, layout_js_1.ExtractDrawingRects)(frameComponent.displayProp) ?? [];
|
|
45
|
-
let originalWidthMM = 0;
|
|
46
|
-
let originalHeightMM = 0;
|
|
47
|
-
let widthMM = 0;
|
|
48
|
-
let heightMM = 0;
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
47
|
+
let originalWidthMM = (0, ParamDefinition_js_1.numeric)(0);
|
|
48
|
+
let originalHeightMM = (0, ParamDefinition_js_1.numeric)(0);
|
|
49
|
+
let widthMM = (0, ParamDefinition_js_1.numeric)(0);
|
|
50
|
+
let heightMM = (0, ParamDefinition_js_1.numeric)(0);
|
|
51
|
+
const paperRect = frameRects.find(item => item.className === 'paper-area');
|
|
52
|
+
const plotRect = frameRects.find(item => item.className === 'plot-area');
|
|
53
|
+
if (paperRect) {
|
|
54
|
+
originalWidthMM = (0, helpers_js_1.milsToMM)(paperRect.width);
|
|
55
|
+
originalHeightMM = (0, helpers_js_1.milsToMM)(paperRect.height);
|
|
56
|
+
logger.add('first frame size: ' + originalWidthMM.toNumber()
|
|
57
|
+
+ ' ' + originalHeightMM.toNumber());
|
|
52
58
|
}
|
|
53
|
-
if (
|
|
54
|
-
widthMM = (0, helpers_js_1.milsToMM)(
|
|
55
|
-
heightMM = (0, helpers_js_1.milsToMM)(
|
|
59
|
+
if (plotRect) {
|
|
60
|
+
widthMM = (0, helpers_js_1.milsToMM)(plotRect.width);
|
|
61
|
+
heightMM = (0, helpers_js_1.milsToMM)(plotRect.height);
|
|
62
|
+
logger.add('second frame size: ' + widthMM.toNumber()
|
|
63
|
+
+ ' ' + heightMM.toNumber());
|
|
56
64
|
}
|
|
57
|
-
xOffset = (originalWidthMM
|
|
58
|
-
yOffset = (originalHeightMM
|
|
59
|
-
|
|
65
|
+
xOffset = (originalWidthMM.sub(widthMM)).half().toNumber();
|
|
66
|
+
yOffset = (originalHeightMM.sub(heightMM)).half().toNumber();
|
|
67
|
+
logger.add('offset', xOffset, yOffset);
|
|
68
|
+
sheetYOffset = originalHeightMM.add(globals_js_1.defaultPageSpacingMM).mul(index);
|
|
60
69
|
gridBounds = {
|
|
61
70
|
xmin: 0,
|
|
62
71
|
ymin: 0,
|
|
63
|
-
xmax: widthMM,
|
|
64
|
-
ymax: heightMM
|
|
72
|
+
xmax: widthMM.toNumber(),
|
|
73
|
+
ymax: heightMM.toNumber()
|
|
65
74
|
};
|
|
66
75
|
extendGrid = false;
|
|
67
76
|
}
|
|
68
77
|
}
|
|
69
|
-
|
|
70
|
-
|
|
78
|
+
logger.add('sheet contents offset: ' + xOffset + ' ' + yOffset);
|
|
79
|
+
logger.add('generating svg children in sheet');
|
|
80
|
+
const sheetElements = sheetGroup.group().addClass('sheet-elements');
|
|
81
|
+
generateSVGChild(sheetElements, components, wires, junctions, mergedWires, allFrames, textObjects, gridBounds, extendGrid, logger);
|
|
71
82
|
sheetElements.translate(xOffset, yOffset);
|
|
72
|
-
sheetGroup.translate(0, sheetYOffset);
|
|
83
|
+
sheetGroup.translate(0, sheetYOffset.toNumber());
|
|
73
84
|
});
|
|
74
85
|
return canvas;
|
|
75
86
|
}
|
|
@@ -114,16 +125,18 @@ function generatePdfOutput(doc, canvas, sheetSize, sheetSizeDefined, zoomScale =
|
|
|
114
125
|
});
|
|
115
126
|
}
|
|
116
127
|
exports.generatePdfOutput = generatePdfOutput;
|
|
117
|
-
function generateSVGChild(canvas, components, wires, junctions, mergedWires, frameObjects, textObjects, gridBounds, extendGrid) {
|
|
128
|
+
function generateSVGChild(canvas, components, wires, junctions, mergedWires, frameObjects, textObjects, gridBounds, extendGrid, logger) {
|
|
118
129
|
const displayWireId = false;
|
|
119
130
|
if (gridBounds === null) {
|
|
131
|
+
logger.add('get grid bounds');
|
|
120
132
|
gridBounds = (0, layout_js_1.getBounds)(components, wires, junctions, frameObjects);
|
|
121
133
|
}
|
|
122
|
-
|
|
134
|
+
logger.add('grid bounds', gridBounds.xmin, gridBounds.ymin, gridBounds.xmax, gridBounds.ymax);
|
|
135
|
+
drawGrid(canvas.group().translate(0, 0), gridBounds, extendGrid, logger);
|
|
123
136
|
components.forEach(item => {
|
|
124
137
|
const { x, y, width, height } = item;
|
|
125
138
|
const symbolGroup = canvas.group();
|
|
126
|
-
symbolGroup.translate(x, y);
|
|
139
|
+
symbolGroup.translate(x.toNumber(), y.toNumber());
|
|
127
140
|
const { symbol = null } = item;
|
|
128
141
|
if (symbol !== null && symbol) {
|
|
129
142
|
const extra = {};
|
|
@@ -160,7 +173,7 @@ function generateSVGChild(canvas, components, wires, junctions, mergedWires, fra
|
|
|
160
173
|
family: 'Arial',
|
|
161
174
|
size: 50 * globals_js_1.fontDisplayScale,
|
|
162
175
|
})
|
|
163
|
-
.translate(wire.x
|
|
176
|
+
.translate(wire.x.add(5).toNumber(), wire.y.add(5).toNumber());
|
|
164
177
|
});
|
|
165
178
|
}
|
|
166
179
|
const mergedWireGroup = canvas.group();
|
|
@@ -177,10 +190,13 @@ function generateSVGChild(canvas, components, wires, junctions, mergedWires, fra
|
|
|
177
190
|
})
|
|
178
191
|
.fill('none');
|
|
179
192
|
});
|
|
193
|
+
const halfJunctionSize = globals_js_1.junctionSize.half();
|
|
180
194
|
intersectPoints.forEach(point => {
|
|
181
|
-
const [x, y,
|
|
182
|
-
|
|
183
|
-
|
|
195
|
+
const [x, y,] = point;
|
|
196
|
+
const translateX = (0, ParamDefinition_js_1.numeric)(x).sub(halfJunctionSize);
|
|
197
|
+
const translateY = (0, ParamDefinition_js_1.numeric)(y).sub(halfJunctionSize);
|
|
198
|
+
mergedWireGroup.circle(globals_js_1.junctionSize.toNumber())
|
|
199
|
+
.translate(translateX.toNumber(), translateY.toNumber())
|
|
184
200
|
.fill(globals_js_1.ColorScheme.JunctionColor)
|
|
185
201
|
.stroke('none');
|
|
186
202
|
});
|
|
@@ -194,11 +210,11 @@ function generateSVGChild(canvas, components, wires, junctions, mergedWires, fra
|
|
|
194
210
|
drawSheetFrameBorder(frameGroup, item);
|
|
195
211
|
}
|
|
196
212
|
else {
|
|
197
|
-
if (borderWidth > 0) {
|
|
198
|
-
if (item.
|
|
213
|
+
if (borderWidth.toNumber() > 0) {
|
|
214
|
+
if (item.renderType === layout_js_1.RenderFrameType.Container) {
|
|
199
215
|
strokeColor = '#111';
|
|
200
216
|
}
|
|
201
|
-
else if (item.
|
|
217
|
+
else if (item.renderType === layout_js_1.RenderFrameType.Elements) {
|
|
202
218
|
strokeColor = '#aaa';
|
|
203
219
|
if (!globals_js_1.RenderFlags.ShowElementFrames) {
|
|
204
220
|
return;
|
|
@@ -206,52 +222,61 @@ function generateSVGChild(canvas, components, wires, junctions, mergedWires, fra
|
|
|
206
222
|
}
|
|
207
223
|
const tmpRect = frameGroup.rect(width, height)
|
|
208
224
|
.fill('none')
|
|
209
|
-
.stroke({
|
|
210
|
-
|
|
225
|
+
.stroke({
|
|
226
|
+
width: (0, helpers_js_1.milsToMM)(borderWidth).toNumber(),
|
|
227
|
+
color: strokeColor
|
|
228
|
+
});
|
|
229
|
+
tmpRect.translate(item.x.toNumber(), item.y.toNumber());
|
|
211
230
|
}
|
|
212
231
|
}
|
|
213
232
|
});
|
|
214
233
|
textObjects.forEach(item => {
|
|
215
234
|
const { x, y, symbol } = item;
|
|
216
235
|
const innerGroup = canvas.group();
|
|
217
|
-
innerGroup.translate(x, y);
|
|
236
|
+
innerGroup.translate(x.toNumber(), y.toNumber());
|
|
218
237
|
symbol.draw(innerGroup);
|
|
219
238
|
});
|
|
220
|
-
const originSize = (0, helpers_js_1.milsToMM)(10);
|
|
239
|
+
const originSize = (0, helpers_js_1.milsToMM)(10).toNumber();
|
|
221
240
|
globals_js_1.RenderFlags.ShowOrigin && canvas.group().translate(0, 0)
|
|
222
241
|
.circle(originSize)
|
|
223
242
|
.translate(-originSize / 2, -originSize / 2)
|
|
224
243
|
.stroke('none').fill('red');
|
|
225
244
|
}
|
|
226
|
-
function drawGrid(group, canvasSize, extendGrid) {
|
|
245
|
+
function drawGrid(group, canvasSize, extendGrid, logger) {
|
|
227
246
|
const gridSize = globals_js_1.defaultGridSizeUnits;
|
|
228
247
|
const { xmin, ymin, xmax, ymax } = canvasSize;
|
|
229
248
|
const extraValue = extendGrid ? 1 : 0;
|
|
230
|
-
const gridStartX = (Math.floor(xmin / gridSize)
|
|
231
|
-
const gridStartY = (Math.floor(ymin / gridSize)
|
|
249
|
+
const gridStartX = ((0, ParamDefinition_js_1.numeric)(Math.floor(xmin / gridSize)).sub(extraValue)).mul(gridSize);
|
|
250
|
+
const gridStartY = ((0, ParamDefinition_js_1.numeric)(Math.floor(ymin / gridSize)).sub(extraValue)).mul(gridSize);
|
|
232
251
|
const gridEndX = extendGrid
|
|
233
|
-
? (Math.ceil(xmax / gridSize)
|
|
234
|
-
: (xmax
|
|
252
|
+
? ((0, ParamDefinition_js_1.numeric)(Math.ceil(xmax / gridSize)).add(extraValue)).mul(gridSize)
|
|
253
|
+
: ((0, ParamDefinition_js_1.numeric)(xmax).sub(xmin));
|
|
235
254
|
const gridEndY = extendGrid
|
|
236
|
-
? (Math.ceil(ymax / gridSize)
|
|
237
|
-
: (ymax
|
|
238
|
-
const numCols = Math.floor((
|
|
255
|
+
? ((0, ParamDefinition_js_1.numeric)(Math.ceil(ymax / gridSize)).add(extraValue)).mul(gridSize)
|
|
256
|
+
: ((0, ParamDefinition_js_1.numeric)(ymax).sub(ymin));
|
|
257
|
+
const numCols = Math.floor(gridEndX.sub(gridStartX).div(gridSize).toNumber())
|
|
239
258
|
+ (extendGrid ? 1 : 0);
|
|
259
|
+
const originSize = (0, helpers_js_1.milsToMM)(10).toNumber();
|
|
260
|
+
globals_js_1.RenderFlags.ShowGridOrigin && group.circle(originSize)
|
|
261
|
+
.translate(-originSize / 2, -originSize / 2)
|
|
262
|
+
.stroke('none').fill('blue');
|
|
240
263
|
const lines = [];
|
|
241
264
|
const smallOffset = (0, helpers_js_1.milsToMM)(3);
|
|
242
|
-
const startY = gridStartY
|
|
243
|
-
const endY = gridEndY
|
|
265
|
+
const startY = gridStartY.sub(smallOffset.half());
|
|
266
|
+
const endY = gridEndY.add(smallOffset);
|
|
267
|
+
const numericGridSize = (0, ParamDefinition_js_1.numeric)(gridSize);
|
|
244
268
|
for (let i = 0; i < numCols; i++) {
|
|
245
|
-
const startX = gridStartX
|
|
246
|
-
lines.push(`M ${startX} ${startY} L ${startX} ${endY}`);
|
|
269
|
+
const startX = gridStartX.add(numericGridSize.mul(i)).toNumber();
|
|
270
|
+
lines.push(`M ${startX} ${startY.toNumber()} L ${startX} ${endY.toNumber()}`);
|
|
247
271
|
}
|
|
248
272
|
const strokeSize = (0, helpers_js_1.milsToMM)(3);
|
|
249
|
-
group.
|
|
273
|
+
group.addClass('grid')
|
|
274
|
+
.path(lines.join(" "))
|
|
250
275
|
.attr({
|
|
251
|
-
'stroke-dasharray': `${strokeSize},${
|
|
276
|
+
'stroke-dasharray': `${strokeSize.toNumber()},${numericGridSize.sub(strokeSize).toNumber()}`,
|
|
252
277
|
})
|
|
253
278
|
.stroke({
|
|
254
|
-
width: strokeSize,
|
|
279
|
+
width: strokeSize.toNumber(),
|
|
255
280
|
color: '#000'
|
|
256
281
|
});
|
|
257
282
|
}
|
|
@@ -268,94 +293,7 @@ function drawSheetFrameBorder(frameGroup, frame) {
|
|
|
268
293
|
symbol.draw(sheetFrameGroup);
|
|
269
294
|
const offsetX = (0, helpers_js_1.milsToMM)(frameComponent.getParam('offset_x'));
|
|
270
295
|
const offsetY = (0, helpers_js_1.milsToMM)(frameComponent.getParam('offset_y'));
|
|
271
|
-
sheetFrameGroup.translate(-offsetX, -offsetY);
|
|
272
|
-
}
|
|
273
|
-
}
|
|
274
|
-
}
|
|
275
|
-
function drawSheetFrameBorderDirect(frameGroup, frame, borderWidth, strokeColor, width, height) {
|
|
276
|
-
const commonStroke = {
|
|
277
|
-
width: (0, helpers_js_1.milsToMM)(borderWidth),
|
|
278
|
-
color: strokeColor
|
|
279
|
-
};
|
|
280
|
-
const commonFont = {
|
|
281
|
-
family: globals_js_1.defaultFont,
|
|
282
|
-
size: 50 * globals_js_1.fontDisplayScale,
|
|
283
|
-
'dominant-baseline': 'middle',
|
|
284
|
-
'text-anchor': 'middle',
|
|
285
|
-
};
|
|
286
|
-
let rows = 1;
|
|
287
|
-
let columns = 1;
|
|
288
|
-
let showGridReference = true;
|
|
289
|
-
if (helpers_js_1.PaperGridReferences[frame.size]) {
|
|
290
|
-
[rows, columns] = helpers_js_1.PaperGridReferences[frame.size];
|
|
291
|
-
}
|
|
292
|
-
else {
|
|
293
|
-
showGridReference = false;
|
|
294
|
-
}
|
|
295
|
-
if (!showGridReference) {
|
|
296
|
-
return;
|
|
297
|
-
}
|
|
298
|
-
const outerMargin = 2;
|
|
299
|
-
const outerWidth = width + outerMargin * 2;
|
|
300
|
-
const outerHeight = height + outerMargin * 2;
|
|
301
|
-
const outerRect = frameGroup.rect(outerWidth, outerHeight)
|
|
302
|
-
.fill('none')
|
|
303
|
-
.stroke(commonStroke);
|
|
304
|
-
outerRect.translate(frame.x - outerMargin, frame.y - outerMargin);
|
|
305
|
-
const gridWidth = outerWidth / columns;
|
|
306
|
-
const gridHeight = outerHeight / rows;
|
|
307
|
-
const pathPoints = [];
|
|
308
|
-
for (let i = 1; i < rows + 1; i++) {
|
|
309
|
-
const lineStartX = frame.x - outerMargin;
|
|
310
|
-
const lineStartX2 = frame.x - outerMargin + outerWidth - outerMargin;
|
|
311
|
-
const lineY = frame.y - outerMargin + (gridHeight * i);
|
|
312
|
-
if (i < rows) {
|
|
313
|
-
pathPoints.push(...[
|
|
314
|
-
"M", lineStartX, lineY, "L", lineStartX + outerMargin, lineY,
|
|
315
|
-
"M", lineStartX2, lineY, "L", lineStartX2 + outerMargin, lineY
|
|
316
|
-
]);
|
|
296
|
+
sheetFrameGroup.translate(-offsetX.toNumber(), -offsetY.toNumber());
|
|
317
297
|
}
|
|
318
|
-
const displayValue = String.fromCharCode(i + 64);
|
|
319
|
-
frameGroup.text(displayValue)
|
|
320
|
-
.font(commonFont)
|
|
321
|
-
.translate(lineStartX + outerMargin / 2, lineY - gridHeight / 2);
|
|
322
|
-
frameGroup.text(displayValue)
|
|
323
|
-
.font(commonFont)
|
|
324
|
-
.translate(lineStartX2 + outerMargin / 2, lineY - gridHeight / 2);
|
|
325
|
-
}
|
|
326
|
-
for (let i = 1; i < columns + 1; i++) {
|
|
327
|
-
const lineStartY = frame.y - outerMargin;
|
|
328
|
-
const lineStartY2 = frame.y - outerMargin + outerHeight - outerMargin;
|
|
329
|
-
const lineX = frame.x - outerMargin + (gridWidth * i);
|
|
330
|
-
if (i < columns) {
|
|
331
|
-
pathPoints.push(...[
|
|
332
|
-
"M", lineX, lineStartY, "L", lineX, lineStartY + outerMargin,
|
|
333
|
-
"M", lineX, lineStartY2, "L", lineX, lineStartY2 + outerMargin
|
|
334
|
-
]);
|
|
335
|
-
}
|
|
336
|
-
frameGroup.text(i.toString())
|
|
337
|
-
.font(commonFont)
|
|
338
|
-
.translate(lineX - gridWidth / 2, lineStartY + outerMargin / 2 + (0, helpers_js_1.milsToMM)(10));
|
|
339
|
-
frameGroup.text(i.toString())
|
|
340
|
-
.font(commonFont)
|
|
341
|
-
.translate(lineX - gridWidth / 2, lineStartY2 + outerMargin / 2 + (0, helpers_js_1.milsToMM)(10));
|
|
342
|
-
}
|
|
343
|
-
frameGroup.path(pathPoints).stroke(commonStroke);
|
|
344
|
-
const titleWidth = (0, helpers_js_1.milsToMM)(3000);
|
|
345
|
-
const titleHeight = (0, helpers_js_1.milsToMM)(1000);
|
|
346
|
-
const rowHeight = (0, helpers_js_1.milsToMM)(200);
|
|
347
|
-
const points = [
|
|
348
|
-
"M", width - titleWidth, height,
|
|
349
|
-
"L", width - titleWidth, height - titleHeight,
|
|
350
|
-
"L", width, height - titleHeight,
|
|
351
|
-
"M", width - titleWidth, height - rowHeight,
|
|
352
|
-
"L", width, height - rowHeight,
|
|
353
|
-
"M", width - titleWidth, height - rowHeight * 2,
|
|
354
|
-
"L", width, height - rowHeight * 2,
|
|
355
|
-
"M", width - titleWidth, height - rowHeight * 3,
|
|
356
|
-
"L", width, height - rowHeight * 3
|
|
357
|
-
];
|
|
358
|
-
frameGroup.path(points).stroke(commonStroke).fill('none');
|
|
359
|
-
if (frame.containsTitle) {
|
|
360
298
|
}
|
|
361
299
|
}
|
package/dist/cjs/sizing.js
CHANGED
|
@@ -67,27 +67,53 @@ function measureTextSize2(text, fontFamily, fontSize, fontWeight = 'regular', an
|
|
|
67
67
|
}
|
|
68
68
|
const key = `${text}-${fontFamily}-${fontSize}-${fontWeight}-${anchor}-${vanchor}`;
|
|
69
69
|
if (measureTextSizeCache[key] === undefined) {
|
|
70
|
-
let dominantBaseline =
|
|
70
|
+
let dominantBaseline = geometry_js_1.VerticalAlignProp.Hanging;
|
|
71
71
|
switch (vanchor) {
|
|
72
72
|
case geometry_js_1.VerticalAlign.Top:
|
|
73
|
-
dominantBaseline =
|
|
73
|
+
dominantBaseline = geometry_js_1.VerticalAlignProp.Hanging;
|
|
74
74
|
break;
|
|
75
75
|
case geometry_js_1.VerticalAlign.Middle:
|
|
76
|
-
dominantBaseline =
|
|
76
|
+
dominantBaseline = geometry_js_1.VerticalAlignProp.Central;
|
|
77
77
|
break;
|
|
78
78
|
case geometry_js_1.VerticalAlign.Bottom:
|
|
79
|
-
dominantBaseline =
|
|
79
|
+
dominantBaseline = geometry_js_1.VerticalAlignProp.TextTop;
|
|
80
|
+
break;
|
|
81
|
+
}
|
|
82
|
+
let useAnchor = geometry_js_1.HorizontalAlignProp.Start;
|
|
83
|
+
switch (anchor) {
|
|
84
|
+
case geometry_js_1.HorizontalAlign.Left:
|
|
85
|
+
useAnchor = geometry_js_1.HorizontalAlignProp.Start;
|
|
86
|
+
break;
|
|
87
|
+
case geometry_js_1.HorizontalAlign.Middle:
|
|
88
|
+
useAnchor = geometry_js_1.HorizontalAlignProp.Middle;
|
|
89
|
+
break;
|
|
90
|
+
case geometry_js_1.HorizontalAlign.Right:
|
|
91
|
+
useAnchor = geometry_js_1.HorizontalAlignProp.End;
|
|
80
92
|
break;
|
|
81
93
|
}
|
|
82
94
|
fontFamily = globals_js_1.defaultFont;
|
|
83
95
|
const tmpTextElement = MainCanvas.text(text).font({
|
|
84
96
|
family: fontFamily,
|
|
85
97
|
size: fontSize,
|
|
86
|
-
anchor:
|
|
98
|
+
anchor: useAnchor,
|
|
87
99
|
'dominant-baseline': dominantBaseline,
|
|
88
100
|
weight: fontWeight,
|
|
89
|
-
})
|
|
90
|
-
|
|
101
|
+
})
|
|
102
|
+
.attr("xml:space", "preserve")
|
|
103
|
+
.fill('#333');
|
|
104
|
+
let textbox = tmpTextElement.bbox();
|
|
105
|
+
const tmpTextBox = { ...textbox };
|
|
106
|
+
if (dominantBaseline === geometry_js_1.VerticalAlignProp.Hanging) {
|
|
107
|
+
tmpTextBox.y = textbox.cy - textbox.height;
|
|
108
|
+
tmpTextBox.y2 = tmpTextBox.y + textbox.height;
|
|
109
|
+
textbox = tmpTextBox;
|
|
110
|
+
}
|
|
111
|
+
else if (dominantBaseline === geometry_js_1.VerticalAlignProp.Central) {
|
|
112
|
+
tmpTextBox.y -= textbox.cy;
|
|
113
|
+
tmpTextBox.y2 -= textbox.cy;
|
|
114
|
+
tmpTextBox.cy = 0;
|
|
115
|
+
textbox = tmpTextBox;
|
|
116
|
+
}
|
|
91
117
|
const { width, height } = textbox;
|
|
92
118
|
tmpTextElement.remove();
|
|
93
119
|
measureTextSizeCache[key] = {
|
package/dist/cjs/utils.js
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.combineMaps = exports.throwWithContext = exports.roundValue = exports.getPortType = exports.getBoundsSize = exports.toNearestGrid = exports.resizeToNearestGrid = exports.printBounds = exports.resizeBounds = exports.SimpleStopwatch = void 0;
|
|
3
|
+
exports.areasOverlap = exports.isPointWithinArea = exports.resolveToNumericValue = exports.getNumberExponentialText = exports.getNumberExponential = exports.combineMaps = exports.throwWithContext = exports.roundValue = exports.getPortType = exports.getBoundsSize = exports.toNearestGrid = exports.resizeToNearestGrid = exports.printBounds = exports.resizeBounds = exports.SimpleStopwatch = void 0;
|
|
4
|
+
const big_js_1 = require("big.js");
|
|
5
|
+
const ParamDefinition_1 = require("./objects/ParamDefinition");
|
|
4
6
|
class SimpleStopwatch {
|
|
5
7
|
constructor() {
|
|
6
8
|
this.startTime = new Date();
|
|
@@ -73,7 +75,7 @@ function getPortType(component) {
|
|
|
73
75
|
}
|
|
74
76
|
exports.getPortType = getPortType;
|
|
75
77
|
function roundValue(value) {
|
|
76
|
-
return
|
|
78
|
+
return resolveToNumericValue(new big_js_1.Big(value.toBigNumber().toFixed(7)));
|
|
77
79
|
}
|
|
78
80
|
exports.roundValue = roundValue;
|
|
79
81
|
function throwWithContext(context, message) {
|
|
@@ -100,3 +102,85 @@ function combineMaps(map1, map2) {
|
|
|
100
102
|
return newMap;
|
|
101
103
|
}
|
|
102
104
|
exports.combineMaps = combineMaps;
|
|
105
|
+
function getNumberExponential(value) {
|
|
106
|
+
value = value.trim();
|
|
107
|
+
switch (value) {
|
|
108
|
+
case 'G':
|
|
109
|
+
return 9;
|
|
110
|
+
case 'M':
|
|
111
|
+
return 6;
|
|
112
|
+
case 'k':
|
|
113
|
+
case 'K':
|
|
114
|
+
return 3;
|
|
115
|
+
case 'm':
|
|
116
|
+
return -3;
|
|
117
|
+
case 'u':
|
|
118
|
+
return -6;
|
|
119
|
+
case 'n':
|
|
120
|
+
return -9;
|
|
121
|
+
case 'p':
|
|
122
|
+
return -12;
|
|
123
|
+
case 'f':
|
|
124
|
+
return -15;
|
|
125
|
+
default:
|
|
126
|
+
return 0;
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
exports.getNumberExponential = getNumberExponential;
|
|
130
|
+
function getNumberExponentialText(value) {
|
|
131
|
+
switch (value) {
|
|
132
|
+
case -15:
|
|
133
|
+
return 'f';
|
|
134
|
+
case -12:
|
|
135
|
+
return 'p';
|
|
136
|
+
case -9:
|
|
137
|
+
return 'n';
|
|
138
|
+
case -6:
|
|
139
|
+
return 'u';
|
|
140
|
+
case -3:
|
|
141
|
+
return 'm';
|
|
142
|
+
case 3:
|
|
143
|
+
return 'k';
|
|
144
|
+
case 6:
|
|
145
|
+
return 'M';
|
|
146
|
+
case 9:
|
|
147
|
+
return 'G';
|
|
148
|
+
case 0:
|
|
149
|
+
default:
|
|
150
|
+
return '';
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
exports.getNumberExponentialText = getNumberExponentialText;
|
|
154
|
+
function resolveToNumericValue(value) {
|
|
155
|
+
if (value.toNumber() === 0) {
|
|
156
|
+
return new ParamDefinition_1.NumericValue(0);
|
|
157
|
+
}
|
|
158
|
+
const isNeg = value.lt(0);
|
|
159
|
+
const positiveValue = isNeg ? value.neg() : value;
|
|
160
|
+
const prefixPart = Math.floor(Math.log10(positiveValue.toNumber()) / 3);
|
|
161
|
+
let useValue = value;
|
|
162
|
+
if (prefixPart !== 0) {
|
|
163
|
+
const tmpValue1 = positiveValue.div(Math.pow(10, prefixPart * 3));
|
|
164
|
+
useValue = isNeg ? tmpValue1.neg() : tmpValue1;
|
|
165
|
+
}
|
|
166
|
+
return new ParamDefinition_1.NumericValue(useValue, prefixPart * 3);
|
|
167
|
+
}
|
|
168
|
+
exports.resolveToNumericValue = resolveToNumericValue;
|
|
169
|
+
function isPointWithinArea(point, bounds) {
|
|
170
|
+
const [xPt, yPt] = point;
|
|
171
|
+
const [xmin, ymin, xmax, ymax] = bounds;
|
|
172
|
+
return (xPt > xmin && xPt < xmax && yPt > ymin && yPt < ymax);
|
|
173
|
+
}
|
|
174
|
+
exports.isPointWithinArea = isPointWithinArea;
|
|
175
|
+
function areasOverlap(area1, area2) {
|
|
176
|
+
const [xmin, ymin, xmax, ymax] = area1;
|
|
177
|
+
const pt1 = [xmin, ymin];
|
|
178
|
+
const pt2 = [xmin, ymax];
|
|
179
|
+
const pt3 = [xmax, ymin];
|
|
180
|
+
const pt4 = [xmax, ymax];
|
|
181
|
+
return isPointWithinArea(pt1, area2)
|
|
182
|
+
|| isPointWithinArea(pt2, area2)
|
|
183
|
+
|| isPointWithinArea(pt3, area2)
|
|
184
|
+
|| isPointWithinArea(pt4, area2);
|
|
185
|
+
}
|
|
186
|
+
exports.areasOverlap = areasOverlap;
|