Skip to content
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
10 changes: 8 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,10 @@ export interface AmmeterProps<
> extends CommonComponentProps<PinLabel> {
connections: Connections<AmmeterPinLabels>;
color?: string;
display?: AmmeterDisplayOptions;
graphDisplayName?: string;
graphCenter?: number;
graphOffsetDivs?: number;
graphUnitsPerDiv?: number;
}
```

Expand Down Expand Up @@ -1958,7 +1961,10 @@ export interface VoltageProbeProps extends Omit<CommonComponentProps, "name"> {
connectsTo: string;
referenceTo?: string;
color?: string;
display?: VoltageProbeDisplayOptions;
graphDisplayName?: string;
graphCenter?: number;
graphOffsetDivs?: number;
graphUnitsPerDiv?: number;
}
```

Expand Down
65 changes: 25 additions & 40 deletions generated/COMPONENT_TYPES.md
Original file line number Diff line number Diff line change
Expand Up @@ -868,31 +868,25 @@ export const url = z.preprocess((value) => {
### ammeter

```typescript
export interface AmmeterDisplayOptions {
label?: string
center?: number
offsetDivs?: number
unitsPerDiv?: number
}
export interface AmmeterProps<PinLabel extends string = string>
extends CommonComponentProps<PinLabel> {
connections: Connections<AmmeterPinLabels>
color?: string
display?: AmmeterDisplayOptions
graphDisplayName?: string
graphCenter?: number
graphOffsetDivs?: number
graphUnitsPerDiv?: number
}
export const ammeterDisplayOptions = z.object({
label: z.string().optional(),
center: z.number().optional(),
offsetDivs: z.number().optional(),
unitsPerDiv: z.number().optional(),
})
export const ammeterProps = commonComponentProps.extend({
connections: createConnectionsProp(ammeterPinLabels).refine(
hasAmmeterConnectionPair,
"Ammeter connections must include either pos/neg or pin1/pin2",
),
color: z.string().optional(),
display: ammeterDisplayOptions.optional(),
graphDisplayName: z.string().optional(),
graphCenter: z.number().optional(),
graphOffsetDivs: z.number().optional(),
graphUnitsPerDiv: z.number().optional(),
})
```

Expand Down Expand Up @@ -1436,17 +1430,15 @@ export const courtyardPillProps = pcbLayoutProps
### courtyard-rect

```typescript
export const courtyardRectProps = pcbLayoutProps
.omit({ pcbRotation: true })
.extend({
width: distance,
height: distance,
strokeWidth: distance.optional(),
isFilled: z.boolean().optional(),
hasStroke: z.boolean().optional(),
isStrokeDashed: z.boolean().optional(),
color: z.string().optional(),
})
export const courtyardRectProps = pcbLayoutProps.extend({
width: distance,
height: distance,
strokeWidth: distance.optional(),
isFilled: z.boolean().optional(),
hasStroke: z.boolean().optional(),
isStrokeDashed: z.boolean().optional(),
color: z.string().optional(),
})
```

### crystal
Expand Down Expand Up @@ -4185,13 +4177,10 @@ export interface VoltageProbeProps extends Omit<CommonComponentProps, "name"> {
connectsTo: string
referenceTo?: string
color?: string
display?: VoltageProbeDisplayOptions
}
export interface VoltageProbeDisplayOptions {
label?: string
center?: number
offsetDivs?: number
unitsPerDiv?: number
graphDisplayName?: string
graphCenter?: number
graphOffsetDivs?: number
graphUnitsPerDiv?: number
}
export const voltageProbeProps = commonComponentProps
.omit({ name: true })
Expand All @@ -4200,14 +4189,10 @@ export const voltageProbeProps = commonComponentProps
connectsTo: z.string(),
referenceTo: z.string().optional(),
color: z.string().optional(),
display: z
.object({
label: z.string().optional(),
center: z.number().optional(),
offsetDivs: z.number().optional(),
unitsPerDiv: z.number().optional(),
})
.optional(),
graphDisplayName: z.string().optional(),
graphCenter: z.number().optional(),
graphOffsetDivs: z.number().optional(),
graphUnitsPerDiv: z.number().optional(),
})
```

Expand Down
26 changes: 8 additions & 18 deletions generated/PROPS_OVERVIEW.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,19 +18,14 @@ const validatedProps = chipProps.parse(unknownProps)
## Available Props

```ts
export interface AmmeterDisplayOptions {
label?: string
center?: number
offsetDivs?: number
unitsPerDiv?: number
}


export interface AmmeterProps<PinLabel extends string = string>
extends CommonComponentProps<PinLabel> {
connections: Connections<AmmeterPinLabels>
color?: string
display?: AmmeterDisplayOptions
graphDisplayName?: string
graphCenter?: number
graphOffsetDivs?: number
graphUnitsPerDiv?: number
}


Expand Down Expand Up @@ -2270,20 +2265,15 @@ export interface ViaProps extends CommonLayoutProps {
}


export interface VoltageProbeDisplayOptions {
label?: string
center?: number
offsetDivs?: number
unitsPerDiv?: number
}


export interface VoltageProbeProps extends Omit<CommonComponentProps, "name"> {
name?: string
connectsTo: string
referenceTo?: string
color?: string
display?: VoltageProbeDisplayOptions
graphDisplayName?: string
graphCenter?: number
graphOffsetDivs?: number
graphUnitsPerDiv?: number
}


Expand Down
24 changes: 8 additions & 16 deletions lib/components/ammeter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,14 @@ import { z } from "zod"
export const ammeterPinLabels = ["pin1", "pin2", "pos", "neg"] as const
export type AmmeterPinLabels = (typeof ammeterPinLabels)[number]

export interface AmmeterDisplayOptions {
label?: string
center?: number
offsetDivs?: number
unitsPerDiv?: number
}

export interface AmmeterProps<PinLabel extends string = string>
extends CommonComponentProps<PinLabel> {
connections: Connections<AmmeterPinLabels>
color?: string
display?: AmmeterDisplayOptions
graphDisplayName?: string
graphCenter?: number
graphOffsetDivs?: number
graphUnitsPerDiv?: number
}

const hasAmmeterConnectionPair = (
Expand All @@ -33,20 +29,16 @@ const hasAmmeterConnectionPair = (
)
}

export const ammeterDisplayOptions = z.object({
label: z.string().optional(),
center: z.number().optional(),
offsetDivs: z.number().optional(),
unitsPerDiv: z.number().optional(),
})

export const ammeterProps = commonComponentProps.extend({
connections: createConnectionsProp(ammeterPinLabels).refine(
hasAmmeterConnectionPair,
"Ammeter connections must include either pos/neg or pin1/pin2",
),
color: z.string().optional(),
display: ammeterDisplayOptions.optional(),
graphDisplayName: z.string().optional(),
graphCenter: z.number().optional(),
graphOffsetDivs: z.number().optional(),
graphUnitsPerDiv: z.number().optional(),
})

export const ammeterPins = ammeterPinLabels
Expand Down
24 changes: 8 additions & 16 deletions lib/components/voltageprobe.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,10 @@ export interface VoltageProbeProps extends Omit<CommonComponentProps, "name"> {
connectsTo: string
referenceTo?: string
color?: string
display?: VoltageProbeDisplayOptions
}

export interface VoltageProbeDisplayOptions {
label?: string
center?: number
offsetDivs?: number
unitsPerDiv?: number
graphDisplayName?: string
graphCenter?: number
graphOffsetDivs?: number
graphUnitsPerDiv?: number
}

export const voltageProbeProps = commonComponentProps
Expand All @@ -27,14 +23,10 @@ export const voltageProbeProps = commonComponentProps
connectsTo: z.string(),
referenceTo: z.string().optional(),
color: z.string().optional(),
display: z
.object({
label: z.string().optional(),
center: z.number().optional(),
offsetDivs: z.number().optional(),
unitsPerDiv: z.number().optional(),
})
.optional(),
graphDisplayName: z.string().optional(),
graphCenter: z.number().optional(),
graphOffsetDivs: z.number().optional(),
graphUnitsPerDiv: z.number().optional(),
})

expectTypesMatch<VoltageProbeProps, z.input<typeof voltageProbeProps>>(true)
22 changes: 9 additions & 13 deletions tests/ammeter.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,30 +35,26 @@ test("should parse ammeter with pin1 and pin2 connections", () => {
})
})

test("should parse ammeter with color and display options", () => {
test("should parse ammeter with color and display props", () => {
const raw: AmmeterProps = {
name: "A3",
color: "green",
connections: {
pos: "net.IN",
neg: "net.OUT",
},
display: {
label: "I_LOAD",
center: 0,
offsetDivs: 2,
unitsPerDiv: 0.01,
},
graphDisplayName: "I_LOAD",
graphCenter: 0,
graphOffsetDivs: 2,
graphUnitsPerDiv: 0.01,
}

const parsed = ammeterProps.parse(raw)
expect(parsed.color).toBe("green")
expect(parsed.display).toEqual({
label: "I_LOAD",
center: 0,
offsetDivs: 2,
unitsPerDiv: 0.01,
})
expect(parsed.graphDisplayName).toBe("I_LOAD")
expect(parsed.graphCenter).toBe(0)
expect(parsed.graphOffsetDivs).toBe(2)
expect(parsed.graphUnitsPerDiv).toBe(0.01)
})

test("should reject missing ammeter connections", () => {
Expand Down
22 changes: 9 additions & 13 deletions tests/voltageprobe.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,25 +43,21 @@ test("should parse voltageprobe with referenceTo", () => {
expect(parsed.referenceTo).toBe(".R1 > .p2")
})

test("should parse voltageprobe with display options", () => {
test("should parse voltageprobe with display props", () => {
const raw: VoltageProbeProps = {
connectsTo: ".DUT .U1 .VOUT",
referenceTo: "net.GND",
name: "VOUT_PROBE",
display: {
label: "VO",
center: 3.3,
offsetDivs: 3,
unitsPerDiv: 0.05,
},
graphDisplayName: "VO",
graphCenter: 3.3,
graphOffsetDivs: 3,
graphUnitsPerDiv: 0.05,
}
const parsed = voltageProbeProps.parse(raw)
expect(parsed.display).toEqual({
label: "VO",
center: 3.3,
offsetDivs: 3,
unitsPerDiv: 0.05,
})
expect(parsed.graphDisplayName).toBe("VO")
expect(parsed.graphCenter).toBe(3.3)
expect(parsed.graphOffsetDivs).toBe(3)
expect(parsed.graphUnitsPerDiv).toBe(0.05)
})

test("should not parse voltageprobe with array connectsTo", () => {
Expand Down
Loading