How to Set Swimlane to Viewport Dynamically in JavaScript Diagram?
This article explains how to set the Swimlane size to the viewport size dynamically in JavaScript Diagram.
In the JavaScript Diagram component, you can dynamically adjust the swimlane’s width and height to match the viewport size by using the created event, which triggers once the diagram is fully rendered. Within this event, you can retrieve the current viewport dimensions using diagram.scroller.viewPortWidth and diagram.scroller.viewPortHeight, and then apply these values to the swimlane’s width and height properties. For example:
function created() {
let swimlane = diagram.nameTable['swimlane'];
const actualWidth = diagram.scroller.viewPortWidth;
const actualHeight = diagram.scroller.viewPortHeight;
swimlane.width = actualWidth;
swimlane.height = actualHeight;
diagram.dataBind();
}
In this code snippet, we access the swimlane node via its ID using diagram.nameTable[‘swimlane’], retrieve the viewport width and height, assign those dimensions to the swimlane, and finally call diagram.dataBind() to apply the updates. This ensures the swimlane dynamically fits the visible canvas area, making the diagram responsive to different screen sizes.
Refer to the working sample for additional details and implementation: Sample
Conclusion
We hope you enjoyed learning on how to set swimlane size to the viewport size dynamically 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, BoldDesk Support, or feedback portal. We are always happy to assist you!