Page settings in EJ2 JavaScript Diagram control
18 Apr 202324 minutes to read
Page settings enable to customize the appearance, width, and height of the diagram page.
Page size and appearance
-
The size and appearance of the diagram pages can be customized with the page settings property.
-
The
width
andheight
properties of page settings define the size of the page and based on the size, theorientation
will be set for the page. In addition to that, the appearance of the page can be customized withsource
and set of appearance specific properties. -
The
color
property is used to customize the background color and border color of the page. -
The
margin
property is used to define the page margin. -
To explore those properties, refer to
Page Settings
.
var diagram;
var connector = {
id: 'connector1',
sourceID: 'node1',
targetID: 'node2',
style: {
strokeColor: '#6BA5D7',
fill: '#6BA5D7'
},
};
var node = {
id: 'node1',
width: 100,
style: {
strokeColor: '#6BA5D7',
fill: '#6BA5D7'
},
height: 100,
offsetX: 100,
offsetY: 100,
annotations: [{
content: 'Node1'
}]
};
var node2 = {
id: 'node2',
width: 100,
style: {
strokeColor: '#6BA5D7',
fill: '#6BA5D7'
},
height: 100,
offsetX: 300,
offsetY: 350,
annotations: [{
content: 'Node3'
}]
};
diagram = new ej.diagrams.Diagram({
width: '1000px',
height: '500px',
nodes: [node, node2],
connectors: [connector],
getNodeDefaults: function(node) {
node.height = 100;
node.width = 100;
node.style.fill = '#6BA5D7';
node.style.strokeColor = 'white';
return node;
},
getConnectorDefaults: function(obj) {
obj.style.strokeColor = '#6BA5D7';
obj.style.fill = '#6BA5D7';
obj.style.strokeWidth = 2;
obj.targetDecorator.style.fill = '#6BA5D7';
obj.targetDecorator.style.strokeColor = '#6BA5D7';
return obj;
},
pageSettings: {
orientation: 'Landscape',
showPageBreaks: true,
background: {
color: 'grey'
},
width: 300,
height: 300,
margin: {
left: 10,
top: 10,
bottom: 10
},
}
}, '#element');
<!DOCTYPE html><html lang="en"><head>
<title>EJ2 Diagram</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="description" content="Typescript UI Controls">
<meta name="author" content="Syncfusion">
<link href="index.css" rel="stylesheet">
<link href="https://cdn.syncfusion.com/ej2/23.2.4/ej2-base/styles/material.css" rel="stylesheet">
<link href="https://cdn.syncfusion.com/ej2/23.2.4/ej2-buttons/styles/material.css" rel="stylesheet">
<link href="https://cdn.syncfusion.com/ej2/23.2.4/ej2-popups/styles/material.css" rel="stylesheet">
<link href="https://cdn.syncfusion.com/ej2/23.2.4/ej2-splitbuttons/styles/material.css" rel="stylesheet">
<link href="https://cdn.syncfusion.com/ej2/23.2.4/ej2-diagrams/styles/material.css" rel="stylesheet">
<link href="https://cdn.syncfusion.com/ej2/23.2.4/ej2-navigations/styles/fabric.css" rel="stylesheet">
<script src="https://cdn.syncfusion.com/ej2/23.2.4/dist/ej2.min.js" type="text/javascript"></script>
<script src="https://cdn.syncfusion.com/ej2/syncfusion-helper.js" type ="text/javascript"></script>
</head>
<body>
<div id="container">
<div id="element"></div>
</div>
<script>
var ele = document.getElementById('container');
if(ele) {
ele.style.visibility = "visible";
}
</script>
<script src="index.js" type="text/javascript"></script>
</body></html>
Set background image
Stretch and align the background image anywhere over the diagram area. The source
property of background
allows you to set the path of the image. The scale
and the align
properties help to stretch/align the background images.
The following code illustrates how to stretch and align the background image.
var diagram;
var connector = {
id: 'connector1',
sourceID: 'node1',
targetID: 'node2'
};
var node = {
id: 'node1',
width: 100,
height: 100,
style: {
strokeColor: '#6BA5D7',
fill: '#6BA5D7'
},
offsetX: 100,
offsetY: 100,
annotations: [{
content: 'Node1'
}]
};
var node2 = {
id: 'node2',
width: 100,
height: 100,
style: {
strokeColor: '#6BA5D7',
fill: '#6BA5D7'
},
offsetX: 300,
offsetY: 350,
annotations: [{
content: 'Node3'
}]
};
diagram = new ej.diagrams.Diagram({
width: '1000px',
height: '500px',
nodes: [node, node2],
connectors: [connector],
getNodeDefaults: function(node) {
node.height = 100;
node.width = 100;
node.style.fill = '#6BA5D7';
node.style.strokeColor = 'white';
return node;
},
getConnectorDefaults: function(obj) {
obj.style.strokeColor = '#6BA5D7';
obj.style.fill = '#6BA5D7';
obj.style.strokeWidth = 2;
obj.targetDecorator.style.fill = '#6BA5D7';
obj.targetDecorator.style.strokeColor = '#6BA5D7';
return obj;
},
pageSettings: {
orientation: 'Landscape',
showPageBreaks: true,
background: {
source: 'https://www.w3schools.com/images/w3schools_green.jpg'
},
width: 300,
height: 300,
margin: {
left: 10,
top: 10,
bottom: 10
},
}
}, '#element');
<!DOCTYPE html><html lang="en"><head>
<title>EJ2 Diagram</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="description" content="Typescript UI Controls">
<meta name="author" content="Syncfusion">
<link href="index.css" rel="stylesheet">
<link href="https://cdn.syncfusion.com/ej2/23.2.4/ej2-base/styles/material.css" rel="stylesheet">
<link href="https://cdn.syncfusion.com/ej2/23.2.4/ej2-buttons/styles/material.css" rel="stylesheet">
<link href="https://cdn.syncfusion.com/ej2/23.2.4/ej2-popups/styles/material.css" rel="stylesheet">
<link href="https://cdn.syncfusion.com/ej2/23.2.4/ej2-splitbuttons/styles/material.css" rel="stylesheet">
<link href="https://cdn.syncfusion.com/ej2/23.2.4/ej2-diagrams/styles/material.css" rel="stylesheet">
<link href="https://cdn.syncfusion.com/ej2/23.2.4/ej2-navigations/styles/fabric.css" rel="stylesheet">
<script src="https://cdn.syncfusion.com/ej2/23.2.4/dist/ej2.min.js" type="text/javascript"></script>
<script src="https://cdn.syncfusion.com/ej2/syncfusion-helper.js" type ="text/javascript"></script>
</head>
<body>
<div id="container">
<div id="element"></div>
</div>
<script>
var ele = document.getElementById('container');
if(ele) {
ele.style.visibility = "visible";
}
</script>
<script src="index.js" type="text/javascript"></script>
</body></html>
Multiple page and page breaks
When multiple page is enabled, the size of the page dynamically increases or decreases in multiples of page width and height and completely fits diagram within the page boundaries. Page breaks is used as a visual guide to see how pages are split into multiple pages.
The multiplePage
and showPageBreak
properties of page settings allow you to enable/disable multiple pages and page breaks respectively.
The following code illustrates how to enable multiple page and page break lines.
var diagram;
var connector = {
id: 'connector1',
sourceID: 'node1',
targetID: 'node2',
style: {
strokeColor: '#6BA5D7',
fill: '#6BA5D7'
},
};
var node = {
id: 'node1',
width: 100,
height: 100,
style: {
strokeColor: '#6BA5D7',
fill: '#6BA5D7'
},
offsetX: 100,
offsetY: 100,
annotations: [{
content: 'Node1'
}]
};
var node2 = {
id: 'node2',
width: 100,
height: 100,
style: {
strokeColor: '#6BA5D7',
fill: '#6BA5D7'
},
offsetX: 300,
offsetY: 350,
annotations: [{
content: 'Node3'
}]
};
diagram = new ej.diagrams.Diagram({
width: '1000px',
height: '500px',
getNodeDefaults: function(node) {
node.height = 100;
node.width = 100;
node.style.fill = '#6BA5D7';
node.style.strokeColor = 'white';
return node;
},
getConnectorDefaults: function(obj) {
obj.style.strokeColor = '#6BA5D7';
obj.style.fill = '#6BA5D7';
obj.style.strokeWidth = 2;
obj.targetDecorator.style.fill = '#6BA5D7';
obj.targetDecorator.style.strokeColor = '#6BA5D7';
return obj;
},
nodes: [node, node2],
connectors: [connector],
pageSettings: {
orientation: 'Landscape',
multiplePage: true,
showPageBreaks: true,
width: 300,
height: 300,
margin: {
left: 10,
top: 10,
bottom: 10
},
}
}, '#element');
<!DOCTYPE html><html lang="en"><head>
<title>EJ2 Diagram</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="description" content="Typescript UI Controls">
<meta name="author" content="Syncfusion">
<link href="index.css" rel="stylesheet">
<link href="https://cdn.syncfusion.com/ej2/23.2.4/ej2-base/styles/material.css" rel="stylesheet">
<link href="https://cdn.syncfusion.com/ej2/23.2.4/ej2-buttons/styles/material.css" rel="stylesheet">
<link href="https://cdn.syncfusion.com/ej2/23.2.4/ej2-popups/styles/material.css" rel="stylesheet">
<link href="https://cdn.syncfusion.com/ej2/23.2.4/ej2-splitbuttons/styles/material.css" rel="stylesheet">
<link href="https://cdn.syncfusion.com/ej2/23.2.4/ej2-diagrams/styles/material.css" rel="stylesheet">
<link href="https://cdn.syncfusion.com/ej2/23.2.4/ej2-navigations/styles/fabric.css" rel="stylesheet">
<script src="https://cdn.syncfusion.com/ej2/23.2.4/dist/ej2.min.js" type="text/javascript"></script>
<script src="https://cdn.syncfusion.com/ej2/syncfusion-helper.js" type ="text/javascript"></script>
</head>
<body>
<div id="container">
<div id="element"></div>
</div>
<script>
var ele = document.getElementById('container');
if(ele) {
ele.style.visibility = "visible";
}
</script>
<script src="index.js" type="text/javascript"></script>
</body></html>
Boundary constraints
The diagram provides support to restrict/customize the interactive region, out of which the elements cannot be dragged, resized, or rotated. The boundaryConstraints
property of page settings allows you to customize the interactive region. To explore the boundary constraints, refer to Boundary Constraints
.
The following code example illustrates how to define boundary constraints with respect to the page.
var diagram;
var connector = {
id: 'connector1',
sourcePoint: {
x: 300,
y: 100
},
targetPoint: {
x: 400,
y: 100
}
};
var node = {
id: 'node1',
width: 150,
height: 100,
offsetX: 100,
offsetY: 100,
style: {
strokeColor: '#6BA5D7',
fill: '#6BA5D7'
},
};
var node2 = {
id: 'node2',
width: 80,
height: 130,
offsetX: 200,
offsetY: 200,
style: {
strokeColor: '#6BA5D7',
fill: '#6BA5D7'
},
};
var node3 = {
id: 'node3',
width: 100,
height: 75,
offsetX: 300,
offsetY: 350,
style: {
strokeColor: '#6BA5D7',
fill: '#6BA5D7'
},
};
diagram = new ej.diagrams.Diagram({
width: 800,
height: 800,
nodes: [node, node2, node3],
connectors: [connector],
pageSettings: {
boundaryConstraints: 'Page',
width: 400,
height: 400,
getNodeDefaults: function(node) {
node.height = 100;
node.width = 100;
node.style.fill = '#6BA5D7';
node.style.strokeColor = 'white';
return node;
},
getConnectorDefaults: function(obj) {
obj.style.strokeColor = '#6BA5D7';
obj.style.fill = '#6BA5D7';
obj.style.strokeWidth = 2;
obj.targetDecorator.style.fill = '#6BA5D7';
obj.targetDecorator.style.strokeColor = '#6BA5D7';
return obj;
},
showPageBreaks: true,
},
}, '#element');
<!DOCTYPE html><html lang="en"><head>
<title>EJ2 Diagram</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="description" content="Typescript UI Controls">
<meta name="author" content="Syncfusion">
<link href="index.css" rel="stylesheet">
<link href="https://cdn.syncfusion.com/ej2/23.2.4/ej2-base/styles/material.css" rel="stylesheet">
<link href="https://cdn.syncfusion.com/ej2/23.2.4/ej2-buttons/styles/material.css" rel="stylesheet">
<link href="https://cdn.syncfusion.com/ej2/23.2.4/ej2-popups/styles/material.css" rel="stylesheet">
<link href="https://cdn.syncfusion.com/ej2/23.2.4/ej2-splitbuttons/styles/material.css" rel="stylesheet">
<link href="https://cdn.syncfusion.com/ej2/23.2.4/ej2-diagrams/styles/material.css" rel="stylesheet">
<link href="https://cdn.syncfusion.com/ej2/23.2.4/ej2-navigations/styles/fabric.css" rel="stylesheet">
<script src="https://cdn.syncfusion.com/ej2/23.2.4/dist/ej2.min.js" type="text/javascript"></script>
<script src="https://cdn.syncfusion.com/ej2/syncfusion-helper.js" type ="text/javascript"></script>
</head>
<body>
<div id="container">
<div id="element"></div>
</div>
<script>
var ele = document.getElementById('container');
if(ele) {
ele.style.visibility = "visible";
}
</script>
<script src="index.js" type="text/javascript"></script>
</body></html>