From be9ea3a409b49cb46797b49e2eb503f18ea49e52 Mon Sep 17 00:00:00 2001 From: Shibo Date: Sun, 22 Dec 2024 22:41:22 +0200 Subject: [PATCH] cleanup --- bun.lockb | Bin 293150 -> 293150 bytes ...-objects-from-sch-component-with-symbol.ts | 32 +++++------------- package.json | 2 +- tests/sch/transform-attribute.test.tsx | 2 +- 4 files changed, 11 insertions(+), 25 deletions(-) diff --git a/bun.lockb b/bun.lockb index 778d5b6af9a279597190fc19d6ea2918b1ef3405..6fb578651524ed637a90de0b1c57544bff33523f 100755 GIT binary patch delta 1441 zcmXYuZA?yK7{||ZdVf(py^y8!ERna7mm)%`5jEOuHs5?OV>V+pA8aa0EwAz6Hk;^! z(!|E%`RoI0ZAQpuhWUssO3K^fcRl{s&VTp+{I2W#&wcLGITq|33pO?f`u*sUI^Xj= zQwp*=&P{+d3e7M;HHbyy^CHCa8pUF`AGBer$<>ee8RaL`iUaLc>!esbY@b-OSORRn zSc~hjh*N4M(aKS)RV*2nE7k_%@}{8|W~g>IY7wV3o(dY!*cq`jSf$3#iUncSV&`1N z7b4E9l|ie(4u!fPmWe-tY$F{oJF6^o3|ZZD9Tw3`i!0Jzz-mW$OA*=lNqtD4*i6`U zvD@y0Mckof={e}2T8}h73$_E6$od$@<>jJ6n4R5#EB;EvAl#mujn-l82%l&?A75!r z>M6{=GlV8Ai+bjoEMiEl0#LVF&&B4zdhm9v_7^Oo5Z%MuvA%Re7BQ^WJWxB{>J_WK zya?5by=FB#AAKe(o%M|ijS}$|Zs`lrTr<==u|@bInEkEyFgvrws0B?&6Yh{jOlo`y zsL*}~^+RkazDlt_#fo7yF#9vV+(RN7eyg<{v`gcEU|ik`)UV^5(%eeeeX+k{C9s_^ z`-64@7E_9fH5U+D1+y)OSpEMj#aqpdv$s)EZuc0U6|MO-pblhT9wW9Ee-T;5ik0Ip zMTqCcxw{q-uhx3-751}?H9>3x{s7EAIZ><6o&7;&YJ1(RFSL_gs$4f>}%n(OhzqL53@)XcLl^qjHg;lEjxL62QEq20H ze5A!mrP4_i+E9oVu?+l9WCv-5*{m|r9%RwwTCBxIQar=y$*eZQOKLG1KctIX7R!d6 z7rWx#T8pcstovBBO{qI7&w;IlC9>Xy@p!qY7-qA(?@B+>q8n~s=Ap$H8{tEh=i@6a zNj!qtJqyrR>qYdqeb(Z!QiY%nrEKC>UW7XFHrA(N#rW%Z8*8uYu@=ving}|Kw|LHK zo0p&(u@|gnC!r7YPh)-Q3i@gB3T``2K@-dnuf?X~OJMf5-oR{T(@-PILPKu5wfLs; z>7Zi!9mIFB8Tcx-{UKHg3&ZTs{B*ZzQU6P+S)lbQ{|)2uW}_P#=U>&$f!!3d+uA2{ z(K@{SL0_y4U#hx5Y#wZgJ_W2%|Jg`yJ}=I8Bck1g0j?FJ`h}ntWH*l$TZC^#7I9+b z_*28g^Wxn#YmuPT67U($IFmI|Y$<*#%&wdyR)N2Tx9g2?{%2Yw^J?c>hR*7MDJrjm zorc-rQ^l(BQLqK9Ay;QD(v(^bir{URbg>oqx%f)f46!i2Of1v2TZ=4SdAwEV0sefb&BPhN92T8(!VgF$+zNU7#Q r+k-#tHVy{oV&5^v_kJYtORyus?~UyK6LbfDT~pYPiiG{>-d+Cyb_taP diff --git a/lib/sch/svg-object-fns/create-svg-objects-from-sch-component-with-symbol.ts b/lib/sch/svg-object-fns/create-svg-objects-from-sch-component-with-symbol.ts index 22f13df..88fadf8 100644 --- a/lib/sch/svg-object-fns/create-svg-objects-from-sch-component-with-symbol.ts +++ b/lib/sch/svg-object-fns/create-svg-objects-from-sch-component-with-symbol.ts @@ -181,33 +181,19 @@ export const createSvgObjectsFromSchematicComponentWithSymbol = ({ textValue = schComponent.symbol_display_value ?? "" } - const getTextOffset = ( - bounds: { minX: number; maxX: number; minY: number; maxY: number }, - anchor: TextPrimitive["anchor"], - transform: Matrix, - ) => { - const symbolHeight = Math.abs(bounds.maxY - bounds.minY) - const offsetFactor = 0.1 + const symbolHeight = Math.abs(bounds.maxY - bounds.minY) + const offsetFactor = 0.1 + const baseOffset = symbolHeight * offsetFactor + const transformScale = Math.abs(transformFromSymbolToReal.a) - const baseOffset = symbolHeight * offsetFactor + let verticalOffset = 0 - const transformScale = Math.abs(transform.a) - - if (anchor.includes("bottom")) { - return baseOffset * transformScale - } - if (anchor.includes("top")) { - return -baseOffset * transformScale - } - return 0 + if (text.anchor.includes("bottom")) { + verticalOffset = baseOffset * transformScale + } else if (text.anchor.includes("top")) { + verticalOffset = -baseOffset * transformScale } - const verticalOffset = getTextOffset( - bounds, - text.anchor, - transformFromSymbolToReal, - ) - const dominantBaseline = text.anchor.includes("bottom") ? "auto" : text.anchor.includes("top") diff --git a/package.json b/package.json index 60cd91a..c3719b6 100644 --- a/package.json +++ b/package.json @@ -33,7 +33,7 @@ "@types/bun": "^1.1.9", "biome": "^0.3.3", "bun-match-svg": "^0.0.6", - "circuit-json": "^0.0.111", + "circuit-json": "^0.0.119", "esbuild": "^0.20.2", "performance-now": "^2.1.0", "react": "^18.3.1", diff --git a/tests/sch/transform-attribute.test.tsx b/tests/sch/transform-attribute.test.tsx index 5b2204a..f7c065b 100644 --- a/tests/sch/transform-attribute.test.tsx +++ b/tests/sch/transform-attribute.test.tsx @@ -1,7 +1,7 @@ import { test, expect } from "bun:test" import { convertCircuitJsonToSchematicSvg } from "lib" -test.skip("svg should have data-real-to-screen-transform attribute", () => { +test("svg should have data-real-to-screen-transform attribute", () => { const svg = convertCircuitJsonToSchematicSvg([ { type: "schematic_box",