Skip to content

Commit

Permalink
Merge pull request #115 from tscircuit/feat/label-name-for-pin
Browse files Browse the repository at this point in the history
Use the source port name for the pin text
  • Loading branch information
imrishabh18 authored Nov 10, 2024
2 parents ddda9de + 2e8de18 commit ddb7a57
Showing 1 changed file with 11 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import type {
AnyCircuitElement,
SchematicComponent,
SchematicPort,
SourcePort,
} from "circuit-json"
import type { SvgObject } from "lib/svg-object"
import { colorMap } from "lib/utils/colors"
Expand All @@ -18,6 +19,13 @@ export const createSvgObjectsForSchPortPinNumberText = (params: {
const svgObjects: SvgObject[] = []
const { schPort, schComponent, transform, circuitJson } = params

// Find the source port using the source_port_id from the schematic port
const sourcePort = circuitJson.find(
(element) =>
element.type === "source_port" &&
element.source_port_id === schPort.source_port_id,
)

const realPinNumberPos = {
x: schPort.center.x,
y: schPort.center.y,
Expand Down Expand Up @@ -47,6 +55,8 @@ export const createSvgObjectsForSchPortPinNumberText = (params: {
screenPinNumberTextPos.y -= 2 //px
}

const pinLabel = (sourcePort as SourcePort).name.replace("pin", "")

svgObjects.push({
name: "text",
type: "element",
Expand All @@ -68,7 +78,7 @@ export const createSvgObjectsForSchPortPinNumberText = (params: {
children: [
{
type: "text",
value: schPort.pin_number?.toString() || "",
value: pinLabel,
name: "",
attributes: {},
children: [],
Expand Down

0 comments on commit ddb7a57

Please sign in to comment.