Skip to content

Commit a7f4d00

Browse files
committed
Fix - Lib - Simplify autoSizeLabelsInsideViewbox using just getBBox
1 parent 880b209 commit a7f4d00

File tree

2 files changed

+10
-52
lines changed

2 files changed

+10
-52
lines changed

src/components/vue-ui-relation-circle.vue

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -276,7 +276,7 @@ function prepareChart() {
276276
relations.value = [];
277277
createPlots();
278278
createRelations();
279-
// autoSizeLabels();
279+
autoSizeLabels();
280280
281281
if (FINAL_CONFIG.value.responsiveProportionalSizing) {
282282
dataLabelSize.value = translateSize({
@@ -326,7 +326,7 @@ function prepareChart() {
326326
createPlots();
327327
createRelations();
328328
}
329-
// autoSizeLabels();
329+
autoSizeLabels();
330330
}
331331
332332
onBeforeUnmount(() => {
@@ -340,13 +340,13 @@ onBeforeUnmount(() => {
340340
}
341341
});
342342
343-
// const { autoSizeLabels } = useAutoSizeLabelsInsideViewbox({
344-
// svgRef,
345-
// fontSize: FINAL_CONFIG.value.style.labels.fontSize,
346-
// minFontSize: FINAL_CONFIG.value.style.labels.minFontSize,
347-
// sizeRef: labelFontSize,
348-
// labelClass: '.vue-ui-relation-circle-legend'
349-
// });
343+
const { autoSizeLabels } = useAutoSizeLabelsInsideViewbox({
344+
svgRef,
345+
fontSize: FINAL_CONFIG.value.style.labels.fontSize,
346+
minFontSize: FINAL_CONFIG.value.style.labels.minFontSize,
347+
sizeRef: labelFontSize,
348+
labelClass: '.vue-ui-relation-circle-legend'
349+
});
350350
351351
function clickOutside(e) {
352352
const target = e.target;

src/useAutoSizeLabelsInsideViewbox.js

Lines changed: 1 addition & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -10,50 +10,8 @@ export function useAutoSizeLabelsInsideViewbox({
1010
}) {
1111
let rafScheduled = null;
1212

13-
function minOf(arr) {
14-
let m = arr[0];
15-
for (let i = 1; i < arr.length; i += 1) if (arr[i] < m) m = arr[i];
16-
return m;
17-
}
18-
function maxOf(arr) {
19-
let m = arr[0];
20-
for (let i = 1; i < arr.length; i += 1) if (arr[i] > m) m = arr[i];
21-
return m;
22-
}
23-
24-
function getTransformedBBox(el) {
25-
const svg = el.ownerSVGElement;
26-
if (!svg) return { x: 0, y: 0, width: 0, height: 0 };
27-
28-
const b = el.getBBox();
29-
const m = el.getCTM();
30-
31-
const corners = [
32-
{ x: b.x, y: b.y },
33-
{ x: b.x + b.width, y: b.y },
34-
{ x: b.x, y: b.y + b.height },
35-
{ x: b.x + b.width, y: b.y + b.height }
36-
].map((p) => {
37-
const pt = svg.createSVGPoint();
38-
pt.x = p.x;
39-
pt.y = p.y;
40-
const t = m ? pt.matrixTransform(m) : pt;
41-
return { x: t.x, y: t.y };
42-
});
43-
44-
const xs = corners.map((p) => p.x);
45-
const ys = corners.map((p) => p.y);
46-
47-
const minX = minOf(xs);
48-
const maxX = maxOf(xs);
49-
const minY = minOf(ys);
50-
const maxY = maxOf(ys);
51-
52-
return { x: minX, y: minY, width: maxX - minX, height: maxY - minY };
53-
}
54-
5513
function fitsWithinBounds(el, bounds, padding = 1) {
56-
const { x, y, width, height } = getTransformedBBox(el);
14+
const { x, y, width, height } = el.getBBox();
5715
const leftOK = x >= bounds.x + padding;
5816
const rightOK = x + width <= bounds.x + bounds.width - padding;
5917
const topOK = y >= bounds.y + padding;

0 commit comments

Comments
 (0)