Skip to content

Commit f9c2d2d

Browse files
committed
Fix - Set focus on chart before zooming to avoid scroll bleeding
1 parent cbc9980 commit f9c2d2d

File tree

1 file changed

+37
-33
lines changed

1 file changed

+37
-33
lines changed

src/components/vue-ui-molecule.vue

Lines changed: 37 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -209,40 +209,44 @@ const currentAnimationFrame = ref(null);
209209
210210
211211
function zoomOnNode(node) {
212-
if (currentAnimationFrame.value) {
213-
cancelAnimationFrame(currentAnimationFrame.value);
214-
}
215-
const vb = dynamicViewBox.value.split(' ');
216-
const startX = parseFloat(vb[0]);
217-
const startY = parseFloat(vb[1]);
218-
const startWidth = parseFloat(vb[2]);
219-
const startHeight = parseFloat(vb[3]);
220-
const { x, y } = node.polygonPath.coordinates[0];
221-
const { circleRadius } = node;
222-
const sizer = 8.34;
223-
const targetX = x - circleRadius * sizer;
224-
const targetY = y - circleRadius * sizer;
225-
const targetWidth = circleRadius * sizer * 2;
226-
const targetHeight = circleRadius * sizer * 2;
227-
228-
const distance = Math.sqrt((targetX - startX) ** 2 + (targetY - startY) ** 2);
229-
const numSteps = Math.min(1200, Math.max(20, Math.floor(distance / 10)));
230-
const stepX = (targetX - startX) / numSteps;
231-
const stepY = (targetY - startY) / numSteps;
232-
const stepWidth = (targetWidth - startWidth) / numSteps;
233-
const stepHeight = (targetHeight - startHeight) / numSteps;
234-
let currentStep = 0;
235-
236-
function animateZoom() {
237-
dynamicViewBox.value = `${startX + stepX * currentStep} ${startY + stepY * currentStep} ${startWidth + stepWidth * currentStep} ${startHeight + stepHeight * currentStep}`;
238-
currentStep += moleculeConfig.value.style.chart.zoom.speed;
239-
240-
if (currentStep <= numSteps) {
241-
currentAnimationFrame.value = requestAnimationFrame(animateZoom);
212+
moleculeChart.value.focus();
213+
214+
nextTick(() => {
215+
if (currentAnimationFrame.value) {
216+
cancelAnimationFrame(currentAnimationFrame.value);
242217
}
243-
244-
}
245-
animateZoom();
218+
const vb = dynamicViewBox.value.split(' ');
219+
const startX = parseFloat(vb[0]);
220+
const startY = parseFloat(vb[1]);
221+
const startWidth = parseFloat(vb[2]);
222+
const startHeight = parseFloat(vb[3]);
223+
const { x, y } = node.polygonPath.coordinates[0];
224+
const { circleRadius } = node;
225+
const sizer = 8.34;
226+
const targetX = x - circleRadius * sizer;
227+
const targetY = y - circleRadius * sizer;
228+
const targetWidth = circleRadius * sizer * 2;
229+
const targetHeight = circleRadius * sizer * 2;
230+
231+
const distance = Math.sqrt((targetX - startX) ** 2 + (targetY - startY) ** 2);
232+
const numSteps = Math.min(1200, Math.max(20, Math.floor(distance / 10)));
233+
const stepX = (targetX - startX) / numSteps;
234+
const stepY = (targetY - startY) / numSteps;
235+
const stepWidth = (targetWidth - startWidth) / numSteps;
236+
const stepHeight = (targetHeight - startHeight) / numSteps;
237+
let currentStep = 0;
238+
239+
function animateZoom() {
240+
dynamicViewBox.value = `${startX + stepX * currentStep} ${startY + stepY * currentStep} ${startWidth + stepWidth * currentStep} ${startHeight + stepHeight * currentStep}`;
241+
currentStep += moleculeConfig.value.style.chart.zoom.speed;
242+
243+
if (currentStep <= numSteps) {
244+
currentAnimationFrame.value = requestAnimationFrame(animateZoom);
245+
}
246+
247+
}
248+
animateZoom();
249+
})
246250
}
247251
248252
function zoom(node) {

0 commit comments

Comments
 (0)