Skip to content

Commit f7c4c66

Browse files
Fixed analog issues
1 parent 86b5c23 commit f7c4c66

File tree

16 files changed

+59
-59
lines changed

16 files changed

+59
-59
lines changed

src/app/analog/models/AnalogComponent.ts

-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@ export abstract class AnalogComponent extends Component {
3030
super(size, initialProps);
3131

3232
this.ports = new PortSet<AnalogPort>(this, portCount, portPositioner, AnalogPort);
33-
this.props = initialProps;
3433
}
3534

3635
public setDesigner(designer?: AnalogCircuitDesigner): void {

src/app/analog/models/eeobjects/essentials/Capacitor.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ export class Capacitor extends AnalogComponent {
2424
public constructor() {
2525
super(
2626
new ClampedValue(2),
27-
V(20, 60), new LeftRightPositioner(),
27+
V(0.4, 0.6), new LeftRightPositioner(),
2828
InitialProps,
2929
);
3030
}

src/app/analog/models/eeobjects/essentials/Ground.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ export class Ground extends AnalogComponent {
1818
public constructor() {
1919
super(
2020
new ClampedValue(1),
21-
V(60, 30), new SidePositioner("top")
21+
V(1.2, 0.6), new SidePositioner("top")
2222
);
2323
}
2424

src/app/analog/models/eeobjects/essentials/Inductor.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ export class Inductor extends AnalogComponent {
2424
public constructor() {
2525
super(
2626
new ClampedValue(2),
27-
V(40, 240*40/104), new TopBottomPositioner(),
27+
V(0.8, 240*0.8/104), new TopBottomPositioner(),
2828
InitialProps,
2929
);
3030
}

src/app/analog/models/eeobjects/essentials/Resistor.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ export class Resistor extends AnalogComponent {
2424
public constructor() {
2525
super(
2626
new ClampedValue(2),
27-
V(60, 50), new LeftRightPositioner(),
27+
V(1.2, 1), new LeftRightPositioner(),
2828
InitialProps,
2929
);
3030
}

src/app/analog/models/eeobjects/measurement/Oscilloscope.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,9 @@ const [Info, InitialProps] = GenPropInfo({
2424
"size": {
2525
type: "veci",
2626
label: "Display Size",
27-
initial: V(800, 400),
28-
min: V(400, 200),
29-
step: V(100, 100),
27+
initial: V(16, 8),
28+
min: V(8, 4),
29+
step: V(2, 2),
3030
},
3131
},
3232
});

src/app/analog/models/eeobjects/other/Label.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ export class Label extends AnalogComponent {
3131
public constructor() {
3232
super(
3333
new ClampedValue(0),
34-
V(60, 30), undefined,
34+
V(1.2, 0.6), undefined,
3535
InitialProps,
3636
);
3737
}

src/app/analog/models/eeobjects/sources/CurrentSource.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ export class CurrentSource extends AnalogComponent {
2424
public constructor() {
2525
super(
2626
new ClampedValue(2),
27-
V(50, 50), new TopBottomPositioner(),
27+
V(1, 1), new TopBottomPositioner(),
2828
InitialProps,
2929
);
3030
}

src/app/analog/models/eeobjects/sources/VoltageSource.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ export class VoltageSource extends AnalogComponent {
7676
public constructor() {
7777
super(
7878
new ClampedValue(2),
79-
V(50, 50), new TopBottomPositioner(),
79+
V(1, 1), new TopBottomPositioner(),
8080
InitialProps,
8181
);
8282
}

src/app/analog/models/ports/positioners/SidePositioner.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,8 @@ export class SidePositioner extends Positioner<AnalogPort> {
3838
: this.side === "right"
3939
? V(1, 0)
4040
: this.side === "top"
41-
? V(0, -1)
42-
: V(0, 1)
41+
? V(0, 1)
42+
: V(0, -1)
4343
);
4444

4545
p1.setOriginPos(dir.scale(size/2));

src/app/analog/models/ports/positioners/TopBottomPositioner.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,11 @@ export class TopBottomPositioner extends Positioner<AnalogPort> {
2727
public override updatePortPositions([p1, p2]: AnalogPort[]): void {
2828
const height = p1.getParent().getSize().y;
2929

30-
p1.setOriginPos(V(0, -height/2));
31-
p1.setTargetPos(V(0, -(height/2+IO_PORT_LENGTH)));
30+
p1.setOriginPos(V(0, height/2));
31+
p1.setTargetPos(V(0, (height/2+IO_PORT_LENGTH)));
3232

33-
p2.setOriginPos(V(0, height/2));
34-
p2.setTargetPos(V(0, height/2+IO_PORT_LENGTH));
33+
p2.setOriginPos(V(0, -height/2));
34+
p2.setTargetPos(V(0, -(height/2+IO_PORT_LENGTH)));
3535
}
3636

3737
}

src/app/analog/rendering/renderers/ComponentRenderer.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ export const ComponentRenderer = (() => {
7474
// TODO: figure out how to get around this
7575
if (object instanceof Label) {
7676
// Calculate size
77-
const width = renderer.getTextWidth(object.getName()) + 20;
77+
const width = renderer.getTextWidth(object.getName()) + 0.4;
7878
object.setSize(V(width, size.y));
7979

8080
drawBox(renderer, object.getTransform(), selected, object.getProp("color") as string);

src/app/analog/rendering/renderers/OscilloscopeRenderer.ts

+37-34
Original file line numberDiff line numberDiff line change
@@ -12,47 +12,50 @@ import {Margin, Rect} from "math/Rect";
1212
import {Renderer} from "core/rendering/Renderer";
1313
import {Style} from "core/rendering/Style";
1414

15+
import {Line} from "core/rendering/shapes/Line";
1516
import {Rectangle} from "core/rendering/shapes/Rectangle";
1617

1718
import {AnalogCircuitInfo} from "analog/utils/AnalogCircuitInfo";
1819

1920
import {Oscilloscope} from "analog/models/eeobjects";
2021

2122

22-
const GRAPH_LINE_WIDTH = 1;
23+
const GRAPH_LINE_WIDTH = 0.02;
24+
const AXIS_LINE_WIDTH = 0.02;
25+
const GRID_LINE_WIDTH = 0.01;
2326

24-
const DISPLAY_PADDING = Margin(15, 15);
27+
const DISPLAY_PADDING = Margin(0.3, 0.3);
2528

26-
const AXIS_PTS = 5 / 400; // 5 pts / 400 units of size
27-
const AXIS_MARK_FONT_SIZE = 12;
28-
const AXIS_LABEL_FONT_SIZE = 15;
29+
const AXIS_PTS = 5 / 8; // 5 pts / 8 units of size
30+
const AXIS_MARK_FONT_SIZE = 0.25;
31+
const AXIS_LABEL_FONT_SIZE = 0.3;
2932

30-
const AXIS_MARK_LENGTH = 8;
33+
const AXIS_MARK_LENGTH = 0.16;
3134

3235
const AXIS_MARK_FONT = `lighter ${AXIS_MARK_FONT_SIZE}px arial`;
3336
const AXIS_LABEL_FONT = `lighter ${AXIS_LABEL_FONT_SIZE}px arial`;
34-
const AXIS_TEXT_OFFSET = AXIS_MARK_LENGTH/2 + 4;
37+
const AXIS_TEXT_OFFSET = AXIS_MARK_LENGTH/2 + 0.08;
3538

3639
const AXES_INFO_MARGIN = Margin(
37-
12 + AXIS_LABEL_FONT_SIZE*2 + AXIS_MARK_FONT_SIZE,
40+
0.24 + AXIS_LABEL_FONT_SIZE*2 + AXIS_MARK_FONT_SIZE,
3841
0,
39-
12 + AXIS_LABEL_FONT_SIZE + AXIS_MARK_FONT_SIZE,
42+
0.24 + AXIS_LABEL_FONT_SIZE + AXIS_MARK_FONT_SIZE,
4043
0,
4144
);
4245
const AXES_MARGIN = Margin(
43-
AXIS_MARK_LENGTH/2 + 4,
44-
10,
45-
AXIS_MARK_LENGTH/2 + 4,
46-
10,
46+
AXIS_MARK_LENGTH/2 + 0.08,
47+
0.2,
48+
AXIS_MARK_LENGTH/2 + 0.08,
49+
0.2,
4750
);
4851

4952

5053
const GRID_PTS = 2; // (N+1) grid points / 1 axis pt
5154

52-
const LEGEND_AREA = 100;
53-
const LEGEND_PADDING = Margin(10, 10, 0, 0);
54-
const LEGEND_TITLE_FONT_SIZE = 15;
55-
const LEGEND_ENTRY_FONT_SIZE = 10;
55+
const LEGEND_AREA = 2;
56+
const LEGEND_PADDING = Margin(0.2, 0.2, 0, 0);
57+
const LEGEND_TITLE_FONT_SIZE = 0.3;
58+
const LEGEND_ENTRY_FONT_SIZE = 0.2;
5659
const LEGEND_TITLE_FONT = `normal ${LEGEND_TITLE_FONT_SIZE}px arial`;
5760
const LEGEND_ENTRY_FONT = `lighter ${LEGEND_ENTRY_FONT_SIZE}px arial`;
5861

@@ -118,7 +121,7 @@ export const OscilloscopeRenderer = ({
118121
// axesGridRect: => Area just for axes + grid + plot
119122
// plotRect : => Area just for the plot
120123
// legendRect : => Area for the legend
121-
const baseRect = new Rect(V(0, 0), size, false);
124+
const baseRect = new Rect(V(0, 0), size);
122125
const innerRect = baseRect.subMargin(DISPLAY_PADDING);
123126
const axesInfoRect = innerRect.subMargin((showLegend ? { right: LEGEND_AREA } : {}));
124127
const axesGridRect = axesInfoRect.subMargin((showAxes ? AXES_INFO_MARGIN : {}));
@@ -127,12 +130,12 @@ export const OscilloscopeRenderer = ({
127130

128131
// Debug drawing
129132
if (info.debugOptions.debugSelectionBounds) {
130-
renderer.draw(toShape(baseRect), new Style("#999999", "#000000", 1));
131-
renderer.draw(toShape(innerRect), new Style("#ff0000", "#000000", 1));
132-
renderer.draw(toShape(axesInfoRect), new Style("#00ff00", "#000000", 1));
133-
renderer.draw(toShape(axesGridRect), new Style("#0000ff", "#000000", 1));
134-
renderer.draw(toShape(plotRect), new Style("#ff00ff", "#000000", 1));
135-
renderer.draw(toShape(legendRect), new Style("#00ffff", "#000000", 1));
133+
renderer.draw(toShape(baseRect), new Style("#999999", "#000000", 0.02));
134+
renderer.draw(toShape(innerRect), new Style("#ff0000", "#000000", 0.02));
135+
renderer.draw(toShape(axesInfoRect), new Style("#00ff00", "#000000", 0.02));
136+
renderer.draw(toShape(axesGridRect), new Style("#0000ff", "#000000", 0.02));
137+
renderer.draw(toShape(plotRect), new Style("#ff00ff", "#000000", 0.02));
138+
renderer.draw(toShape(legendRect), new Style("#00ffff", "#000000", 0.02));
136139
}
137140

138141
if (showGrid)
@@ -148,8 +151,8 @@ export const OscilloscopeRenderer = ({
148151

149152
function getMarks(bounds: Rect) {
150153
const num = V(
151-
Math.max(5, Math.ceil(AXIS_PTS * size.x)),
152-
Math.max(5, Math.ceil(AXIS_PTS * size.y))
154+
Math.max(0.1, Math.ceil(AXIS_PTS * size.x)),
155+
Math.max(0.1, Math.ceil(AXIS_PTS * size.y))
153156
);
154157
return {
155158
xs: linspace(bounds.left, bounds.right, num.x),
@@ -162,7 +165,7 @@ export const OscilloscopeRenderer = ({
162165
function drawGrid(bounds: Rect, innerBounds: Rect) {
163166
renderer.save();
164167
renderer.setPathStyle({ lineCap: "square" });
165-
renderer.setStyle(new Style(undefined, GRID_LINE_COLOR, 0.5), 0.5);
168+
renderer.setStyle(new Style(undefined, GRID_LINE_COLOR, GRID_LINE_WIDTH), 0.5);
166169

167170
const marks = getMarks(innerBounds);
168171

@@ -183,7 +186,7 @@ export const OscilloscopeRenderer = ({
183186
function drawAxes(outerBounds: Rect, bounds: Rect, innerBounds: Rect) {
184187
renderer.save();
185188
renderer.setPathStyle({ lineCap: "square" });
186-
renderer.setStyle(new Style(undefined, "#000000", 1));
189+
renderer.setStyle(new Style(undefined, "#000000", AXIS_LINE_WIDTH));
187190

188191
// Draw each axis
189192
renderer.strokePath([bounds.topLeft, bounds.bottomLeft, bounds.bottomRight]);
@@ -196,7 +199,7 @@ export const OscilloscopeRenderer = ({
196199

197200
// Draw axis mark text
198201
marks.xVals.forEach((text, i) => {
199-
const pos = V(marks.xs[i], bounds.bottom + AXIS_TEXT_OFFSET);
202+
const pos = V(marks.xs[i], bounds.bottom - AXIS_TEXT_OFFSET);
200203
renderer.text(text, pos, "center", "#000000", AXIS_MARK_FONT, "top");
201204
});
202205
marks.yVals.forEach((text, i) => {
@@ -218,10 +221,10 @@ export const OscilloscopeRenderer = ({
218221

219222
renderer.text("Legend", V(bounds.left, bounds.top), "left", "#000000", LEGEND_TITLE_FONT, "top");
220223

221-
const boxSize = 10;
224+
const boxSize = 0.2;
222225
enabledVecIDs.forEach((id, i) => {
223226
const color = vecs[id].color;
224-
const y = bounds.top + 20 + i * (boxSize + 5);
227+
const y = bounds.top - i * (boxSize + 0.1) - 0.7;
225228

226229
// Draw box
227230
const box = Rect.From({
@@ -233,7 +236,7 @@ export const OscilloscopeRenderer = ({
233236
renderer.draw(toShape(box), new Style(color), 1);
234237

235238
// Draw text
236-
renderer.text(id, V(box.right + 5, box.y), "left", "#000000", LEGEND_ENTRY_FONT, "middle");
239+
renderer.text(id, V(box.right + 0.1, box.y), "left", "#000000", LEGEND_ENTRY_FONT, "middle");
237240
});
238241

239242
renderer.restore();
@@ -244,14 +247,14 @@ export const OscilloscopeRenderer = ({
244247
renderer.setPathStyle({ lineCap: "round" });
245248

246249
// Get data bounds as a rectangle
247-
const dataBounds = Rect.From({ left: minX, right: maxX, bottom: minVal, top: maxVal }, false);
250+
const dataBounds = Rect.From({ left: minX, right: maxX, bottom: minVal, top: maxVal });
248251

249252
const scale = V(bounds.width / dataBounds.width, bounds.height / dataBounds.height);
250253

251254
sampledData.forEach((data, i) => {
252255
// Calculate position for each data point
253256
const positions = data.map(
254-
(s, i) => V(xData[i], -s)
257+
(s, i) => V(xData[i], s)
255258
.sub(dataBounds.center)
256259
.scale(scale)
257260
.add(bounds.center)

src/app/core/rendering/Renderer.ts

+2-3
Original file line numberDiff line numberDiff line change
@@ -89,10 +89,9 @@ export class Renderer {
8989
this.context.textAlign = textAlign;
9090
this.context.textBaseline = textBaseline;
9191

92+
this.translate(pos);
9293
// Flip y-axis scale
9394
this.context.scale(1, -1);
94-
95-
this.translate(pos);
9695
if (angle !== 0)
9796
this.rotate(angle);
9897
this.context.fillText(txt, 0, 0);
@@ -137,7 +136,7 @@ export class Renderer {
137136
if (baseline === "middle")
138137
this.pathLine(pos.sub(0, len/2), pos.add(0, len/2));
139138
else
140-
this.pathLine(pos, pos.sub(0, len));
139+
this.pathLine(pos, pos.add(0, len));
141140
}
142141
public vLines(xs: number[], y0: number, len: number, baseline: "bottom"|"middle") {
143142
xs.forEach((x) => this.vLine(V(x, y0), len, baseline));

src/app/core/utils/Units.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ export const FrequencyInfo = (key: string, label: string, initial = 0, initialU:
4949
);
5050

5151
export const AngleInfo = (key: string, label: string, initial = 0,
52-
initialU: "rad" | "deg" = "deg", step = 1) => ({
52+
initialU: "rad" | "deg" = "deg", step = 1): Record<string, PropInfoWithInitial> => ({
5353
[key]: {
5454
type: "float" as const,
5555
label, initial, step,

src/site/pages/analog/src/containers/MainDesigner/index.tsx

+2-3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import {CreateGroupPlaceAction} from "core/actions/addition/PlaceAction";
21
import {useLayoutEffect, useState} from "react";
32

43
import {HEADER_HEIGHT} from "shared/utils/Constants";
@@ -8,7 +7,7 @@ import {V} from "Vector";
87
import {Cursor} from "core/utils/CircuitInfo";
98
import {Input} from "core/utils/Input";
109

11-
10+
import {PlaceGroup} from "core/actions/units/Place";
1211
import {DeselectAll} from "core/actions/units/Select";
1312

1413
import {AnalogCircuitInfo} from "analog/utils/AnalogCircuitInfo";
@@ -97,7 +96,7 @@ export const MainDesigner = ({ info, canvas }: Props) => {
9796
pos = info.camera.getWorldPos(pos.sub(V(0, canvas.current.getBoundingClientRect().top)));
9897

9998
info.history.add(
100-
CreateGroupPlaceAction(info.designer, AnalogCreateN(pos, itemId, info.designer, num))
99+
PlaceGroup(info.designer, AnalogCreateN(pos, itemId, info.designer, num))
101100
);
102101
info.renderer.render();
103102
}}>

0 commit comments

Comments
 (0)