Skip to content

Commit 9e7ecaa

Browse files
committed
Fix schematic box text alignment with bottom pins
1 parent a6120cf commit 9e7ecaa

14 files changed

Lines changed: 131 additions & 151 deletions

lib/components/base-components/NormalComponent/NormalComponent.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -860,9 +860,9 @@ export class NormalComponent<
860860
source_component_id: this.source_component_id!,
861861
schematic_sheet_id: this._resolveSchematicSheetId(),
862862
})
863+
const hasTopPins = schPortArrangement?.topSide !== undefined
863864
const hasTopOrBottomPins =
864-
schPortArrangement?.topSide !== undefined ||
865-
schPortArrangement?.bottomSide !== undefined
865+
hasTopPins || schPortArrangement?.bottomSide !== undefined
866866
const schematic_box_width = dimensions?.getSize().width
867867
const schematic_box_height = dimensions?.getSize().height
868868
const manufacturer_part_number_schematic_text = db.schematic_text.insert({
@@ -871,7 +871,7 @@ export class NormalComponent<
871871
anchor: "left",
872872
rotation: 0,
873873
position: {
874-
x: hasTopOrBottomPins
874+
x: hasTopPins
875875
? center.x + (schematic_box_width ?? 0) / 2 + 0.1
876876
: center.x - (schematic_box_width ?? 0) / 2,
877877
y: hasTopOrBottomPins
@@ -888,7 +888,7 @@ export class NormalComponent<
888888
anchor: "left",
889889
rotation: 0,
890890
position: {
891-
x: hasTopOrBottomPins
891+
x: hasTopPins
892892
? center.x + (schematic_box_width ?? 0) / 2 + 0.1
893893
: center.x - (schematic_box_width ?? 0) / 2,
894894
y: hasTopOrBottomPins

tests/components/normal-components/__snapshots__/connector-usbc-inner-symbol-schematic.snap.svg

Lines changed: 3 additions & 16 deletions
Loading

tests/components/normal-components/__snapshots__/connector-usbc-schematic-text-position-schematic.snap.svg

Lines changed: 12 additions & 0 deletions
Loading

tests/components/normal-components/__snapshots__/parts-engine-fetch-circuit-json-mfn-fallback-schematic.snap.svg

Lines changed: 3 additions & 16 deletions
Loading

tests/components/normal-components/__snapshots__/parts-engine-fetch-circuit-json-schematic.snap.svg

Lines changed: 3 additions & 16 deletions
Loading
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
import { expect, test } from "bun:test"
2+
import type { PartsEngine } from "@tscircuit/props"
3+
import type { AnyCircuitElement } from "circuit-json"
4+
import usbCC165948CircuitJson from "tests/fixtures/assets/usb-c-C165948.circuit.json"
5+
import { getTestFixture } from "tests/fixtures/get-test-fixture"
6+
7+
test("USB-C connector text is aligned with the schematic box left edge", async () => {
8+
const { circuit } = getTestFixture()
9+
10+
const mockPartsEngine: PartsEngine = {
11+
findPart: async () => ({ jlcpcb: ["C165948"] }),
12+
fetchPartCircuitJson: async ({ supplierPartNumber }) => {
13+
if (supplierPartNumber === "C165948") {
14+
return usbCC165948CircuitJson as AnyCircuitElement[]
15+
}
16+
return undefined
17+
},
18+
}
19+
20+
circuit.add(
21+
<board partsEngine={mockPartsEngine} width="20mm" height="20mm">
22+
<connector
23+
name="J_USB"
24+
manufacturerPartNumber="HRO-TYPE-C-31-M-12"
25+
standard="usb_c"
26+
/>
27+
</board>,
28+
)
29+
30+
await circuit.renderUntilSettled()
31+
32+
const schematicComponent = circuit.db.schematic_component.list()[0]
33+
const expectedLeftEdge =
34+
schematicComponent.center.x - schematicComponent.size.width / 2
35+
const schematicTextPositions = circuit.db.schematic_text
36+
.list()
37+
.map(({ position }) => position.x)
38+
39+
expect(schematicTextPositions).toEqual([expectedLeftEdge, expectedLeftEdge])
40+
expect(circuit).toMatchSchematicSnapshot(import.meta.path)
41+
})

tests/examples/__snapshots__/example8-schematic-box-four-sides-schematic.snap.svg

Lines changed: 3 additions & 8 deletions
Loading

tests/repros/__snapshots__/repro-usbc-not-connected-schematic.snap.svg

Lines changed: 3 additions & 18 deletions
Loading

tests/repros/__snapshots__/repro-usbc-parts-engine-failure-empty-schematic-schematic.snap.svg

Lines changed: 2 additions & 2 deletions
Loading

tests/repros/__snapshots__/repro-usbc-trace-too-long-schematic.snap.svg

Lines changed: 15 additions & 15 deletions
Loading

0 commit comments

Comments
 (0)