From 15cd66ede14c84e8c91489f1b4ec38a10a8d8aef Mon Sep 17 00:00:00 2001 From: Rishabh Gupta Date: Fri, 13 Sep 2024 20:59:19 +0530 Subject: [PATCH 1/2] feat: size of svg --- src/lib/circuit-to-pcb-svg.ts | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/src/lib/circuit-to-pcb-svg.ts b/src/lib/circuit-to-pcb-svg.ts index baeb13a..ce1ad40 100644 --- a/src/lib/circuit-to-pcb-svg.ts +++ b/src/lib/circuit-to-pcb-svg.ts @@ -31,7 +31,12 @@ interface PointObjectNotation { y: number } -function circuitJsonToPcbSvg(soup: AnySoupElement[]): string { +interface Options { + width?: number + height?: number +} + +function circuitJsonToPcbSvg(soup: AnySoupElement[], options?: Options): string { let minX = Number.POSITIVE_INFINITY let minY = Number.POSITIVE_INFINITY let maxX = Number.NEGATIVE_INFINITY @@ -52,8 +57,8 @@ function circuitJsonToPcbSvg(soup: AnySoupElement[]): string { const circuitWidth = maxX - minX + 2 * padding const circuitHeight = maxY - minY + 2 * padding - const svgWidth = 800 - const svgHeight = 600 + const svgWidth = options?.width ?? 800 + const svgHeight = options?.height ?? 600 const paths: PointObjectNotation[][] = [] for (const item of soup) { if ("route" in item && item.route !== undefined) { From e664b6f9f745f1fe76c97e81718f4b06155c27c3 Mon Sep 17 00:00:00 2001 From: Rishabh Gupta Date: Fri, 13 Sep 2024 21:01:35 +0530 Subject: [PATCH 2/2] format --- src/lib/circuit-to-pcb-svg.ts | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/lib/circuit-to-pcb-svg.ts b/src/lib/circuit-to-pcb-svg.ts index ce1ad40..c4f98a9 100644 --- a/src/lib/circuit-to-pcb-svg.ts +++ b/src/lib/circuit-to-pcb-svg.ts @@ -9,11 +9,11 @@ import { } from "transformation-matrix" import { createSvgObjectsFromPcbFabricationNotePath } from "./svg-object-fns/create-svg-objects-from-pcb-fabrication-note-path" import { createSvgObjectsFromPcbFabricationNoteText } from "./svg-object-fns/create-svg-objects-from-pcb-fabrication-note-text" +import { createSvgObjectsFromPcbHole } from "./svg-object-fns/create-svg-objects-from-pcb-plated-hole" import { createSvgObjectsFromPcbSilkscreenPath } from "./svg-object-fns/create-svg-objects-from-pcb-silkscreen-path" import { createSvgObjectsFromPcbSilkscreenText } from "./svg-object-fns/create-svg-objects-from-pcb-silkscreen-text" import { createSvgObjectsFromPcbTrace } from "./svg-object-fns/create-svg-objects-from-pcb-trace" import { createSvgObjectsFromSmtPad } from "./svg-object-fns/create-svg-objects-from-smt-pads" -import { createSvgObjectsFromPcbHole } from "./svg-object-fns/create-svg-objects-from-pcb-plated-hole" const OBJECT_ORDER: AnySoupElement["type"][] = [ "pcb_plated_hole", @@ -36,7 +36,10 @@ interface Options { height?: number } -function circuitJsonToPcbSvg(soup: AnySoupElement[], options?: Options): string { +function circuitJsonToPcbSvg( + soup: AnySoupElement[], + options?: Options, +): string { let minX = Number.POSITIVE_INFINITY let minY = Number.POSITIVE_INFINITY let maxX = Number.NEGATIVE_INFINITY