How to stretch node width to viewport width in Javascript Diagram?
To stretch a node’s width to fit the viewport width, you can adjust the node size based on the diagram’s viewport settings.The viewPortWidth and currentZoom properties within the diagram’s scrollSettings help you calculate the appropriate node width, ensuring it aligns with the visible area of the diagram.
Below Code Snippet explains how to stretch node width to viewport width
function updateImageNode() {
let node = diagram.getObject('headerNode');
node.width =
diagram.scrollSettings.viewPortWidth +
diagram.scrollSettings.viewPortWidth * diagram.scrollSettings.currentZoom;
// Lock the zoom level to maintain a consistent view
diagram.scrollSettings.maxZoom = diagram.scrollSettings.currentZoom;
diagram.scrollSettings.minZoom = diagram.scrollSettings.currentZoom;
}
The updateImageNode function sets the headerNode width to account for the viewport width and current zoom. It then locks the zoom level by setting maxZoom and minZoom to the current zoom, maintaining a consistent view.
Sample : Click here for sample
Conclusion
I hope you enjoyed learning how to stretch node width to viewport width in Javascript Diagram
You can refer to our JavaScript Diagram feature tour page to know about its other groundbreaking feature representations and documentation, and how to quickly get started for configuration specifications. You can also explore our JavaScript Diagram example to understand how to create and manipulate data.
For current customers, you can check out our components from the License and Downloads page. If you are new to Syncfusion®, you can try our 30-day free trial to check out our other controls.
If you have any queries or require clarifications, please let us know in the comments section below. You can also contact us through our support forums, Direct-Trac, or feedback portal. We are always happy to assist you!