Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added [sch_componet_name and MPN] to createSvgObjectsFromSchematicComponentWithBox fn #153

Merged
merged 6 commits into from
Dec 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file modified bun.lockb
Binary file not shown.
2 changes: 1 addition & 1 deletion lib/sch/convert-circuit-json-to-schematic-svg.ts
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ export function convertCircuitJsonToSchematicSvg(
schTraceSvgs.push(...createSchematicTrace(elm, transform))
} else if (elm.type === "schematic_net_label") {
schNetLabel.push(...createSvgObjectsForSchNetLabel(elm, transform))
} else if (elm.type === "schematic_text") {
} else if (elm.type === "schematic_text" && !elm.schematic_component_id) {
schText.push(createSvgSchText(elm, transform))
} else if (elm.type === "schematic_voltage_probe") {
voltageProbeSvgs.push(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import { createSvgObjectsFromSchematicComponentWithSymbol } from "./create-svg-o
import { createSvgObjectsFromSchPortOnBox } from "./create-svg-objects-from-sch-port-on-box"
import { getSchStrokeSize } from "lib/utils/get-sch-stroke-size"
import { getSchScreenFontSize } from "lib/utils/get-sch-font-size"
import { createSvgSchText } from "./create-svg-objects-for-sch-text"

export const createSvgObjectsFromSchematicComponentWithBox = ({
component: schComponent,
Expand Down Expand Up @@ -72,6 +73,15 @@ export const createSvgObjectsFromSchematicComponentWithBox = ({
children: [],
})

const schTexts = su(circuitJson as any).schematic_text.list()

for (const schText of schTexts) {
if (
schText.schematic_component_id === schComponent.schematic_component_id
) {
svgObjects.push(createSvgSchText(schText, transform))
}
}
// // Process ports
const schematicPorts = su(circuitJson as any).schematic_port.list({
schematic_component_id: schComponent.schematic_component_id,
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
"@storybook/react": "^8.2.5",
"@storybook/react-vite": "^8.2.5",
"@storybook/test": "^8.2.5",
"@tscircuit/core": "^0.0.229",
"@tscircuit/core": "^0.0.233",
"@tscircuit/plop": "^0.0.10",
"@types/bun": "^1.1.9",
"biome": "^0.3.3",
Expand Down
4 changes: 2 additions & 2 deletions tests/sch/__snapshots__/kicad-theme-demo.snap.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 2 additions & 2 deletions tests/sch/__snapshots__/rp2040.snap.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion tests/sch/__snapshots__/schText.snap.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 3 additions & 1 deletion tests/sch/component-wrapper.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,9 @@ test("component wrapper has correct attributes", () => {

circuit.render()
const circuitJson = circuit.getCircuitJson()
const svg = convertCircuitJsonToSchematicSvg(circuitJson)
const svg = convertCircuitJsonToSchematicSvg(
circuitJson as SchematicComponent[],
)

expect(svg).toContain('data-circuit-json-type="schematic_component"')
expect(svg).toContain("data-schematic-component-id")
Expand Down
3 changes: 2 additions & 1 deletion tests/sch/resistor.test.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { expect, test } from "bun:test"
import type { AnyCircuitElement } from "circuit-json"
import { convertCircuitJsonToSchematicSvg } from "lib/index"
import { getTestFixture } from "tests/fixtures/get-test-fixture"

Expand Down Expand Up @@ -30,7 +31,7 @@ test("schematic resistor", () => {
}
}
return elm
}),
}) as AnyCircuitElement[],
),
).toMatchSvgSnapshot(import.meta.path)
})
3 changes: 2 additions & 1 deletion tests/sch/rotated-resistor.test.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { test, expect } from "bun:test"
import type { AnyCircuitElement } from "circuit-json"
import { convertCircuitJsonToSchematicSvg } from "lib"
import { getTestFixture } from "tests/fixtures/get-test-fixture"

Expand All @@ -25,7 +26,7 @@ test("schematic rotated resistor", () => {
...c,
symbol_name: "boxresistor_vert",
}
}),
}) as AnyCircuitElement[],
),
).toMatchSvgSnapshot(import.meta.path)
})
5 changes: 4 additions & 1 deletion tests/sch/trace-overlap.test.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { test, expect } from "bun:test"
import type { AnyCircuitElement } from "circuit-json"
import { convertCircuitJsonToSchematicSvg } from "lib"
import { getTestFixture } from "tests/fixtures/get-test-fixture"

Expand Down Expand Up @@ -30,6 +31,8 @@ test("schematic trace overlap", () => {
)

expect(
convertCircuitJsonToSchematicSvg(circuit.getCircuitJson()),
convertCircuitJsonToSchematicSvg(
circuit.getCircuitJson() as AnyCircuitElement[],
),
).toMatchSvgSnapshot(import.meta.path)
})
1 change: 0 additions & 1 deletion tests/sch/transform-attribute.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ test("svg should have data-real-to-screen-transform attribute", () => {

// Extract the transform value and verify it's a valid matrix string
const match = svg.match(/data-real-to-screen-transform="([^"]+)"/)

// @ts-ignore
expect(match[1]).toMatchInlineSnapshot(
`"matrix(54.5454545455,0,0,-54.5454545455,600,300)"`,
Expand Down
3 changes: 2 additions & 1 deletion tests/sch/unknown-symbol.test.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { test, expect } from "bun:test"
import type { AnyCircuitElement } from "circuit-json"
import { convertCircuitJsonToSchematicSvg } from "lib"
import { getTestFixture } from "tests/fixtures/get-test-fixture"

Expand Down Expand Up @@ -32,7 +33,7 @@ test("schematic rotated resistor", () => {
c.symbol_name = "INTENTIONALLY_NONEXISTENT_SYMBOL!!"
}
return c
}),
}) as AnyCircuitElement[],
),
).toMatchSvgSnapshot(import.meta.path)
})
Loading