Skip to content
This repository was archived by the owner on Feb 6, 2024. It is now read-only.

Commit b028bc8

Browse files
Merge pull request #9 from deckgo/feat/improve-positioning
feat: improve positioning of extracted texts
2 parents aefbfc3 + 741dd9d commit b028bc8

File tree

2 files changed

+8
-3
lines changed

2 files changed

+8
-3
lines changed

CHANGELOG.md

+4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# 1.0.4 (2021-04-05)
22

3+
### Features
4+
5+
- improve positioning of extracted texts
6+
37
### Fix
48

59
- default fill color (such as "black")

src/utils/svg.utils.ts

+4-3
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,6 @@ const initDeckGoDRR = ({text, svg, tspan}: {text: SVGTextElement; svg: SVGGraphi
4949
return deckGoDrr;
5050
}
5151

52-
const svgBbox: DOMRect = svg.getBBox();
5352
const textBbox: DOMRect = (tspan || text).getBBox();
5453

5554
const translate: RegExpExecArray | null = /translate\((.*?)\)/g.exec(text.getAttribute('transform') || '');
@@ -68,8 +67,10 @@ const initDeckGoDRR = ({text, svg, tspan}: {text: SVGTextElement; svg: SVGGraphi
6867
}
6968
}
7069

71-
const targetY: number = (100 * y) / (svgBbox.height - svgBbox.y);
72-
const targetX: number = (100 * x) / (svgBbox.width - svgBbox.x);
70+
const {width, height} = svgSize(svg);
71+
72+
const targetY: number = (100 * y) / height;
73+
const targetX: number = (100 * x) / width;
7374

7475
deckGoDrr.style.setProperty('--top', `${targetY}%`);
7576
deckGoDrr.style.setProperty('--left', `${targetX}%`);

0 commit comments

Comments
 (0)