Need to adjust vectors position on JSXGraph number line while resizing a browser screen. Think to utilize in-build method startResizeObserver() to get a tick height and then recalculate vectors y-coordinate. But came that startResizeObserver doesn't work at all. Please, any suggestions. thank you!
// Here is my board with resize attribute:
brdRef.current = JSXGraph.initBoard(id, {
boundingbox: [topLeftX, topLeftY, bottomRightX, bottomRightY],
resize: { enabled: true, throttle: 500 },
});
useEffect(() => {
if (brdRef.current) {
console.log('startResizeObserver useEffect started');
brdRef.current.startResizeObserver();
brdRef.current.on('resize', divResized);
}
return () => {
if (brdRef.current) {
brdRef.current.off('resize', divResized);
}
};
}, []);
// my divResized method to get a tick height
const divResized = () => {
if (!divRef.current) return;
const svgElement = divRef.current.querySelector('svg');
if (svgElement) {
const rect = svgElement.getBoundingClientRect();
const svgHeight = rect.height;
if (brdRef.current) {
tickHeightRef.current = svgHeight / (Math.abs(boundingBox.topLeftY) + Math.abs(boundingBox.bottomRightY));
}
const arrowKeys = Object.keys(brdRef.current.objects).filter(key => {
const obj: BoardObject = brdRef.current.objects[key];
return obj.elType === 'arrow';
});
arrowKeys.forEach(arrowKey => {
const vectorObj = brdRef.current.objects[arrowKey];
console.log('vectorObj', vectorObj);
if (vectorMethodsRef.current) {
vectorMethodsRef.current.adjustPointYPosition(vectorObj, tickHeightRef.current);
}
});
brdRef.current.update();
}
};
Usually, the integrated ResizeObserver of JSXGraph should work quite stable. However in your case, it is advisable to start your own ResizeOserver. This can be done like this:
See it live at https://jsfiddle.net/8nvL5og4/3/. The question is if you can achieve your desired functionality with JSXGraph internal methods?