Skip to content

Commit

Permalink
Merge pull request #111 from tscircuit/improved-labeled-points
Browse files Browse the repository at this point in the history
fix labelled points not appearing at correct position, make sans-serif
  • Loading branch information
seveibar authored Nov 8, 2024
2 parents 77a0782 + dc3365c commit a9ef919
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 8 deletions.
13 changes: 7 additions & 6 deletions lib/sch/draw-schematic-labeled-points.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@ export function drawSchematicLabeledPoints(params: {

for (const point of points) {
// Transform offset points for X marker
const [x1, y1] = applyToPoint(transform, [point.x - 0.1, -(point.y - 0.1)])
const [x2, y2] = applyToPoint(transform, [point.x + 0.1, -(point.y + 0.1)])
const [x3, y3] = applyToPoint(transform, [point.x - 0.1, -(point.y + 0.1)])
const [x4, y4] = applyToPoint(transform, [point.x + 0.1, -(point.y - 0.1)])
const [x1, y1] = applyToPoint(transform, [point.x - 0.1, point.y - 0.1])
const [x2, y2] = applyToPoint(transform, [point.x + 0.1, point.y + 0.1])
const [x3, y3] = applyToPoint(transform, [point.x - 0.1, point.y + 0.1])
const [x4, y4] = applyToPoint(transform, [point.x + 0.1, point.y - 0.1])

// Add X marker
labeledPointsGroup.push({
Expand All @@ -37,7 +37,7 @@ export function drawSchematicLabeledPoints(params: {
// Transform label position
const [labelX, labelY] = applyToPoint(transform, [
point.x + 0.15,
-(point.y - 0.15),
point.y - 0.15,
])

// Add label
Expand All @@ -48,9 +48,10 @@ export function drawSchematicLabeledPoints(params: {
x: labelX.toString(),
y: labelY.toString(),
fill: colorMap.schematic.grid,
"font-size": (0.15 * Math.abs(transform.a)).toString(),
"font-size": (0.1 * Math.abs(transform.a)).toString(),
"fill-opacity": "0.7",
"text-anchor": "start",
"font-family": "sans-serif",
"dominant-baseline": "middle",
},
children: [
Expand Down
2 changes: 1 addition & 1 deletion tests/sch/__snapshots__/grid-and-points.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/grid-and-points.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ test("schematic with grid and labeled points", () => {
grid: { cellSize: 0.5, labelCells: true },
labeledPoints: [
{ x: 0, y: 0, label: "Origin" },
{ x: 1, y: 1, label: "Point A" },
{ x: 0.75, y: 0.75, label: "Point A" },
],
},
),
Expand Down

0 comments on commit a9ef919

Please sign in to comment.