Appearance of a nodes in Vue Diagram control
28 Mar 202524 minutes to read
Common values to the node.
The getNodeDefaults
property in the EJ2 Diagram control allows you to define default settings for nodes based on specific conditions or requirements.
The following code example shows how to use getNodeDefaults function.
<template>
<div id="app">
<ejs-diagram id="diagram" :width='width' :height='height' :nodes='nodes' :getNodeDefaults='getNodeDefaults'></ejs-diagram>
</div>
</template>
<script setup>
import { DiagramComponent as EjsDiagram } from '@syncfusion/ej2-vue-diagrams';
const nodes = [
{
id:'node1',
// Position of the node
offsetX: 250,
offsetY: 250,
// Size of the node
width: 100,
height: 100,
zIndex:2,
annotations:[{content:'Node1'}],
style:{fill:'white',strokeColor:'black'}
},
{
id:'node2',
// Position of the node
offsetX: 270,
offsetY: 270,
// Size of the node
width: 100,
height: 100,
zIndex:1,
annotations:[{content:'Node2'}],
style:{fill:'white',strokeColor:'black'}
},
];
const getNodeDefaults = (obj) => {
obj.style = {fill:'yellow',strokeColor:'green',strokeWidth:3}
};
const width = "100%";
const height = "700px";
</script>
<style>
@import "../node_modules/@syncfusion/ej2-vue-diagrams/styles/material.css";
</style>
<template>
<div id="app">
<ejs-diagram
id="diagram"
ref="diagram"
:width="width"
:height="height"
:nodes="nodes"
:getNodeDefaults="getNodeDefaults"
></ejs-diagram>
</div>
</template>
<script>
import { DiagramComponent } from '@syncfusion/ej2-vue-diagrams';
let nodes = [
{
id:'node1',
// Position of the node
offsetX: 250,
offsetY: 250,
// Size of the node
width: 100,
height: 100,
zIndex:2,
annotations:[{content:'Node1'}],
style:{fill:'white',strokeColor:'black'}
},
{
id:'node2',
// Position of the node
offsetX: 270,
offsetY: 270,
// Size of the node
width: 100,
height: 100,
zIndex:1,
annotations:[{content:'Node2'}],
style:{fill:'white',strokeColor:'black'}
},
];
export default {
name: 'App',
components: {
'ejs-diagram': DiagramComponent,
},
data() {
return {
width: '100%',
height: '700px',
nodes: nodes,
getNodeDefaults: (obj) => {
obj.style = {fill:'yellow',strokeColor:'green',strokeWidth:3}
},
};
},
};
</script>
<style>
@import "../node_modules/@syncfusion/ej2-vue-diagrams/styles/material.css";
</style>
NOTE
The value we set in the getNodeDefaults has the higher priority in rendering.
Appearance
Apply style to the node
The appearance of a node can be customized by changing its fill
color, strokeDashArray
, strokeWidth
, strokeColor
and opacity
. The visible
property of the node enables or disables the visibility of the node.
The following code illustrates how to customize the appearance of the shape.
<template>
<div id="app">
<ejs-diagram id="diagram" :width='width' :height='height' :nodes='nodes'></ejs-diagram>
</div>
</template>
<script setup>
import { DiagramComponent as EjsDiagram } from '@syncfusion/ej2-vue-diagrams';
const nodes = [
{
// Position of the node
offsetX: 250,
offsetY: 250,
// Size of the node
width: 100,
height: 100,
visible: true,
style: {
fill: '#6AA8D7',
strokeColor: 'white',
strokeWidth: 5,
strokeDashArray: '3',
opacity: 0.7,
},
// Text(label) added to the node
},
{
// Position of the node
offsetX: 450,
offsetY: 250,
// Size of the node
width: 100,
height: 100,
visible: false,
style: {
fill: '#6AA8D7',
strokeColor: 'white',
strokeWidth: 5,
strokeDashArray: '3',
opacity: 0.7,
},
// Text(label) added to the node
},
];
const width = "100%";
const height = "700px";
</script>
<style>
@import "../node_modules/@syncfusion/ej2-vue-diagrams/styles/material.css";
</style>
<template>
<div id="app">
<ejs-diagram
id="diagram"
ref="diagram"
:width="width"
:height="height"
:nodes="nodes"
></ejs-diagram>
</div>
</template>
<script>
import { DiagramComponent } from '@syncfusion/ej2-vue-diagrams';
let nodes = [
{
// Position of the node
offsetX: 250,
offsetY: 250,
// Size of the node
width: 100,
height: 100,
visible: true,
style: {
fill: '#6AA8D7',
strokeColor: 'white',
strokeWidth: 5,
strokeDashArray: '3',
opacity: 0.7,
},
// Text(label) added to the node
},
{
// Position of the node
offsetX: 450,
offsetY: 250,
// Size of the node
width: 100,
height: 100,
visible: false,
style: {
fill: '#6AA8D7',
strokeColor: 'white',
strokeWidth: 5,
strokeDashArray: '3',
opacity: 0.7,
},
// Text(label) added to the node
},
];
export default {
name: 'App',
components: {
'ejs-diagram': DiagramComponent,
},
data() {
return {
width: '100%',
height: '700px',
nodes: nodes,
};
},
};
</script>
<style>
@import "../node_modules/@syncfusion/ej2-vue-diagrams/styles/material.css";
</style>
Apply gradient style to node
The gradient
property of the node allows you to define and apply the gradient effect to that node.
The gradient stop property defines the color and a position, where the previous color transition ends and a new color transition starts.
The gradient stop’s opacity property defines the transparency level of the region.
There are two types of gradients as follows:
-
Linear gradient
-
Radial gradient
Linear gradient
-
LinearGradient
defines a smooth transition between a set of colors (so-called stops) on a line. -
A linear gradient’s x1, y1, x2, y2 properties are used to define the position (relative to the node) of the rectangular region that needs to be painted.
<template>
<div id="app">
<ejs-diagram id="diagram" :width='width' :height='height' :nodes='nodes'></ejs-diagram>
</div>
</template>
<script setup>
import { DiagramComponent as EjsDiagram } from '@syncfusion/ej2-vue-diagrams';
const linearGradient = {
//Start point of linear gradient
x1: 0,
y1: 0,
//End point of linear gradient
x2: 50,
y2: 50,
//Sets an array of stop objects
stops: [
{ color: 'white', offset: 0 },
{ color: '#6BA5D7', offset: 100 },
],
type: 'Linear',
};
const nodes = [
{
// Position of the node
offsetX: 200,
offsetY: 250,
// Size of the node
width: 100,
height: 100,
style: { gradient: linearGradient, strokeColor: 'white' },
// Text(label) added to the node
},
];
const width = "100%";
const height = "700px";
</script>
<style>
@import "../node_modules/@syncfusion/ej2-vue-diagrams/styles/material.css";
</style>
<template>
<div id="app">
<ejs-diagram
id="diagram"
ref="diagram"
:width="width"
:height="height"
:nodes="nodes"
></ejs-diagram>
</div>
</template>
<script>
import { DiagramComponent } from '@syncfusion/ej2-vue-diagrams';
let linearGradient;
linearGradient = {
//Start point of linear gradient
x1: 0,
y1: 0,
//End point of linear gradient
x2: 50,
y2: 50,
//Sets an array of stop objects
stops: [
{ color: 'white', offset: 0 },
{ color: '#6BA5D7', offset: 100 },
],
type: 'Linear',
};
let nodes = [
{
// Position of the node
offsetX: 200,
offsetY: 250,
// Size of the node
width: 100,
height: 100,
style: { gradient: linearGradient, strokeColor: 'white' },
// Text(label) added to the node
},
];
export default {
name: 'App',
components: {
'ejs-diagram': DiagramComponent,
},
data() {
return {
width: '100%',
height: '700px',
nodes: nodes,
};
},
};
</script>
<style>
@import "../node_modules/@syncfusion/ej2-vue-diagrams/styles/material.css";
</style>
Radial gradient
-
RadialGradient
defines a smooth transition between stops on a circle. -
A radial gradient’s cx, cy, fx, fy properties are used to define the position (relative to the node) of the outermost or the innermost circle of the radial gradient.
<template>
<div id="app">
<ejs-diagram id="diagram" :width='width' :height='height' :nodes='nodes'></ejs-diagram>
</div>
</template>
<script setup>
import { DiagramComponent as EjsDiagram } from '@syncfusion/ej2-vue-diagrams';
const radialGradient = {
//Center point of outer circle
cx: 50, cy: 50,
//Center point of inner circle
fx: 25, fy: 25,
//Radius of a radial gradient
r: 50,
//Sets an array of stop objects
stops: [{ color: 'white', offset: 0 },
{ color: '#6BA5D7', offset: 100 }],
type: 'Radial'
};
const nodes = [{
// Position of the node
offsetX: 350,
offsetY: 250,
// Size of the node
width: 100,
height: 100,
style: {gradient: radialGradient, strokeColor: 'white' }
}];
const width = "100%";
const height = "700px";
</script>
<style>
@import "../node_modules/@syncfusion/ej2-vue-diagrams/styles/material.css";
</style>
<template>
<div id="app">
<ejs-diagram
id="diagram"
ref="diagram"
:width="width"
:height="height"
:nodes="nodes"
></ejs-diagram>
</div>
</template>
<script>
import { DiagramComponent } from '@syncfusion/ej2-vue-diagrams';
let radialGradient = {
//Center point of outer circle
cx: 50, cy: 50,
//Center point of inner circle
fx: 25, fy: 25,
//Radius of a radial gradient
r: 50,
//Sets an array of stop objects
stops: [{ color: 'white', offset: 0 },
{ color: '#6BA5D7', offset: 100 }],
type: 'Radial'
};
let nodes = [{
// Position of the node
offsetX: 350,
offsetY: 250,
// Size of the node
width: 100,
height: 100,
style: {gradient: radialGradient, strokeColor: 'white' }
}];
export default {
name: 'App',
components: {
'ejs-diagram': DiagramComponent,
},
data() {
return {
width: '100%',
height: '700px',
nodes: nodes,
};
},
};
</script>
<style>
@import "../node_modules/@syncfusion/ej2-vue-diagrams/styles/material.css";
</style>
Customize the style of node selector
Customize the style of main node selector indicator
In diagram, multiple nodes can be selected.
While selecting multiple nodes, a highlighter will be rendered to indicate the selection of each nodes.
The border style of the first node in the multiple selection can be customized by using the className [e-diagram-first-selection-indicator
].
Use the following CSS to customize the style of main node on multiple selection.
.e-diagram-first-selection-indicator{
stroke-width: 5px;
stroke: red;
stroke-dasharray: 1,1;
}
Apply rotate angle and corner radius to the node
-
Rotate angle
: TherotateAngle
property allows you to rotate nodes within the diagram. It’s particularly useful when you want to represent nodes from different perspectives or angles. -
Corner radius
: ThecornerRadius
property allows you to round the corners of nodes in the diagram.
It adds a visual styling effect to the nodes, making them appear softer or more polished.
The following code shows how to set the rotate angle and corner radius for the node.
<template>
<div id="app">
<ejs-diagram id="diagram" :width='width' :height='height' :nodes='nodes'></ejs-diagram>
</div>
</template>
<script setup>
import { DiagramComponent as EjsDiagram } from '@syncfusion/ej2-vue-diagrams';
const nodes = [{
// Position of the node
offsetX: 250,
offsetY: 250,
// Size of the node
width: 100,
height: 100,
visible: true,
//Sets the rotation angle of the node
rotateAngle:45,
//Sets the corner radius of the node
shape:{cornerRadius:15}
// Text(label) added to the node
}];
const width = "100%";
const height = "700px";
</script>
<style>
@import "../node_modules/@syncfusion/ej2-vue-diagrams/styles/material.css";
</style>
<template>
<div id="app">
<ejs-diagram
id="diagram"
ref="diagram"
:width="width"
:height="height"
:nodes="nodes"
></ejs-diagram>
</div>
</template>
<script>
import { DiagramComponent } from '@syncfusion/ej2-vue-diagrams';
let nodes = [{
// Position of the node
offsetX: 250,
offsetY: 250,
// Size of the node
width: 100,
height: 100,
visible: true,
//Sets the rotation angle of the node
rotateAngle:45,
//Sets the corner radius of the node
shape:{cornerRadius:15}
// Text(label) added to the node
}];
export default {
name: 'App',
components: {
'ejs-diagram': DiagramComponent,
},
data() {
return {
width: '100%',
height: '700px',
nodes: nodes,
};
},
};
</script>
<style>
@import "../node_modules/@syncfusion/ej2-vue-diagrams/styles/material.css";
</style>
Apply shadow effect to node
Diagram provides support to add shadow
effect to a node that is disabled, by default. It can be enabled with the
constraints property of the node. The following code illustrates how to drop shadow.
<template>
<div id="app">
<ejs-diagram id="diagram" :width='width' :height='height' :nodes='nodes'></ejs-diagram>
</div>
</template>
<script setup>
import { DiagramComponent as EjsDiagram, NodeConstraints } from '@syncfusion/ej2-vue-diagrams';
let nodes = [{
// Position of the node
offsetX: 250,
offsetY: 250,
// Size of the node
width: 100,
height: 100,
style: { fill: '#6BA5D7', strokeColor: 'white' },
constraints: NodeConstraints.Default | NodeConstraints.Shadow,
// Text(label) added to the node
}];
const width = "100%";
const height = "700px";
</script>
<style>
@import "../node_modules/@syncfusion/ej2-vue-diagrams/styles/material.css";
</style>
<template>
<div id="app">
<ejs-diagram
id="diagram"
ref="diagram"
:width="width"
:height="height"
:nodes="nodes"
></ejs-diagram>
</div>
</template>
<script>
import { DiagramComponent, NodeConstraints } from '@syncfusion/ej2-vue-diagrams';
let nodes = [{
// Position of the node
offsetX: 250,
offsetY: 250,
// Size of the node
width: 100,
height: 100,
style: { fill: '#6BA5D7', strokeColor: 'white' },
constraints: NodeConstraints.Default | NodeConstraints.Shadow,
// Text(label) added to the node
}];
export default {
name: 'App',
components: {
'ejs-diagram': DiagramComponent,
},
data() {
return {
width: '100%',
height: '700px',
nodes: nodes,
};
},
};
</script>
<style>
@import "../node_modules/@syncfusion/ej2-vue-diagrams/styles/material.css";
</style>
Customizing shadow effect of the node
The angle
, distance
, and opacity
of the shadow can be customized with the shadow property of the node. The following code example illustrates how to customize shadow.
<template>
<div id="app">
<ejs-diagram id="diagram" :width='width' :height='height' :nodes='nodes'></ejs-diagram>
</div>
</template>
<script setup>
import { DiagramComponent as EjsDiagram , NodeConstraints} from '@syncfusion/ej2-vue-diagrams';
const nodes = [{
// Position of the node
offsetX: 250,
offsetY: 250,
// Size of the node
width: 100,
height: 100,
style: { fill: '#6BA5D7', strokeColor: 'white' },
constraints: NodeConstraints.Default | NodeConstraints.Shadow,
shadow: {angle: 50, opacity: 0.8, distance: 9}
}];
const width = "100%";
const height = "700px";
</script>
<style>
@import "../node_modules/@syncfusion/ej2-vue-diagrams/styles/material.css";
</style>
<template>
<div id="app">
<ejs-diagram
id="diagram"
ref="diagram"
:width="width"
:height="height"
:nodes="nodes"
></ejs-diagram>
</div>
</template>
<script>
import { DiagramComponent, NodeConstraints } from '@syncfusion/ej2-vue-diagrams';
var nodes = [{
// Position of the node
offsetX: 250,
offsetY: 250,
// Size of the node
width: 100,
height: 100,
style: { fill: '#6BA5D7', strokeColor: 'white' },
constraints: NodeConstraints.Default | NodeConstraints.Shadow,
shadow: {angle: 50, opacity: 0.8, distance: 9}
}];
export default {
name: 'App',
components: {
'ejs-diagram': DiagramComponent,
},
data() {
return {
width: '100%',
height: '700px',
nodes: nodes,
};
},
};
</script>
<style>
@import "../node_modules/@syncfusion/ej2-vue-diagrams/styles/material.css";
</style>
Provide additional information to the node
The addInfo
property of the node allows you to maintain additional information to the node. You can specify either object or string value.
The following code shows how to set the AddInfo value.
let addInfo = { type: 'Node', info: 'Rectangle Node' };
var nodes = [
{
// Position of the node
offsetX: 400,
offsetY: 250,
//Additional informations about the node.
addInfo: addInfo,
// Size of the node
width: 100,
height: 100,
},
];
Constraints
The constraints
property of the node allows you to enable/disable certain behaviors of the node. For more information about node constraints refer to the Node Constraints
Stack order
The nodes zIndex
property specifies the stack order of the node. A node with greater stack order is always in front of a node with a lower stack order.
<template>
<div id="app">
<ejs-diagram id="diagram" :width='width' :height='height' :nodes='nodes'></ejs-diagram>
</div>
</template>
<script setup>
import { DiagramComponent as EjsDiagram } from '@syncfusion/ej2-vue-diagrams';
const nodes = [
{
id: 'Start',
width: 100,
height: 100,
offsetX: 270,
offsetY: 170,
zIndex: 2,
annotations: [
{
content: 'Node 1',
},
],
},
{
id: 'end',
width: 100,
height: 100,
offsetX: 300,
offsetY: 200,
zIntex: 1,
annotations: [
{
content: 'Node 2',
},
],
},
];
const width = "100%";
const height = "700px";
</script>
<style>
@import "../node_modules/@syncfusion/ej2-vue-diagrams/styles/material.css";
</style>
<template>
<div id="app">
<ejs-diagram
id="diagram"
ref="diagram"
:width="width"
:height="height"
:nodes="nodes"
></ejs-diagram>
</div>
</template>
<script>
import { DiagramComponent } from '@syncfusion/ej2-vue-diagrams';
let nodes = [
{
id: 'Start',
width: 100,
height: 100,
offsetX: 270,
offsetY: 170,
zIndex: 2,
annotations: [
{
content: 'Node 1',
},
],
},
{
id: 'end',
width: 100,
height: 100,
offsetX: 300,
offsetY: 200,
zIntex: 1,
annotations: [
{
content: 'Node 2',
},
],
},
];
export default {
name: 'App',
components: {
'ejs-diagram': DiagramComponent,
},
data() {
return {
width: '100%',
height: '700px',
nodes: nodes,
};
},
};
</script>
<style>
@import "../node_modules/@syncfusion/ej2-vue-diagrams/styles/material.css";
</style>
NOTE
By default, the zIndex will be generated automatically based on the order of the diagram elements added to the diagram. The default value will be Number.MIN_VALUE.
Pivot
Node rotation angle will be based on Pivot
values which range from 0 to 1 like offset values. By default, the Pivot values are set to X= 0.5 and Y=0.5.
The following table illustrates how pivot relates offset values with node boundaries.
Pivot | Offset |
---|---|
(0.5,0.5) | offsetX and offsetY values are considered as the node’s center point. |
(0,0) | offsetX and offsetY values are considered as the top-left corner of the node. |
(1,1) | offsetX and offsetY values are considered as the bottom-right corner of the node. |
The following code illustrates how to change the pivot
value.
<template>
<div id="app">
<ejs-diagram id="diagram" :width='width' :height='height' :nodes='nodes'></ejs-diagram>
</div>
</template>
<script setup>
import { DiagramComponent as EjsDiagram } from '@syncfusion/ej2-vue-diagrams';
const nodes = [
{
// Position of the node
offsetX: 250,
offsetY: 250,
// Size of the node
width: 100,
height: 100,
style: { fill: '#6BA5D7', strokeColor: 'white' },
pivot: { x: 0, y: 0 },
},
];
const width = "100%";
const height = "700px";
onMounted(function () {
this.$refs.diagram.ej2Instances.select([
this.$refs.diagram.ej2Instances.nodes[0]])
})
</script>
<style>
@import "../node_modules/@syncfusion/ej2-vue-diagrams/styles/material.css";
</style>
<template>
<div id="app">
<ejs-diagram
id="diagram"
ref="diagram"
:width="width"
:height="height"
:nodes="nodes"
></ejs-diagram>
</div>
</template>
<script>
import { DiagramComponent } from '@syncfusion/ej2-vue-diagrams';
let nodes = [
{
// Position of the node
offsetX: 250,
offsetY: 250,
// Size of the node
width: 100,
height: 100,
style: { fill: '#6BA5D7', strokeColor: 'white' },
pivot: { x: 0, y: 0 },
},
];
export default {
name: 'App',
components: {
'ejs-diagram': DiagramComponent,
},
data() {
return {
width: '100%',
height: '700px',
nodes: nodes,
};
},
mounted: function () {
this.$refs.diagram.ej2Instances.select([
this.$refs.diagram.ej2Instances.nodes[0]])
},
};
</script>
<style>
@import "../node_modules/@syncfusion/ej2-vue-diagrams/styles/material.css";
</style>
Get connected connector from node
Node has the InEdges and OutEdges read-only property. In this property, you can find what are all the connectors that are connected to the node, and then you can fetch these connectors by using the getObject
method in the diagram.
var node = {
id: 'node1',
// Position of the node
offsetX: 450,
offsetY: 100,
// Size of the node
width: 80,
height: 50,
style: { fill: '#6BA5D7', strokeColor: 'white' },
};
var node2 = {
id: 'node2',
// Position of the node
offsetX: 350,
offsetY: 200,
// Size of the node
width: 80,
height: 50,
style: { fill: '#6BA5D7', strokeColor: 'white' },
};
var node3 = {
id: 'node3',
// Position of the node
offsetX: 450,
offsetY: 200,
// Size of the node
width: 80,
height: 50,
style: { fill: '#6BA5D7', strokeColor: 'white' },
};
var node4 = {
id: 'node4',
// Position of the node
offsetX: 550,
offsetY: 200,
// Size of the node
width: 80,
height: 50,
style: { fill: '#6BA5D7', strokeColor: 'white' },
};
var connector = {
id: 'connector1', sourceID: 'node1', targetID: 'node2', type: 'Orthogonal'
};
var connector2 = {
id: 'connector2', sourceID: 'node1', targetID: 'node3', type: 'Orthogonal'
};
var connector3 = {
id: 'connector3', sourceID: 'node1', targetID: 'node4', type: 'Orthogonal'
};
var diagram = new Diagram({
width: '100%', height: 600, nodes: [node, node2, node3, node4],
connectors: [connector, connector2, connector3]
}, '#element');
diagram.getObject(diagram.nodes[0].outEdges[0]);