Symbol Palette Events in EJ2 Vue Diagram component
There are some events which will get triggered while interacting with the symbol palette. They are explained below.
DragEnter event
DragEnter event triggers when the shape enters the diagram surface while dragging it from symbol palette. You can customize the style of the dragged shape using this event. This allows for dynamic styling changes based on the diagram’s context.
<template>
<div id="app">
<ejs-symbolpalette id="symbolpalette" :palettes="palettes" :symbolHeight="50" :symbolWidth="70">
</ejs-symbolpalette>
<ejs-diagram ref="diagram" id="diagram" width="1000" height="500px" @dragEnter="dragEnter">
</ejs-diagram>
</div>
</template>
<script setup>
import { ref } from 'vue';
import { SymbolPaletteComponent as EjsSymbolpalette, DiagramComponent as EjsDiagram } from "@syncfusion/ej2-vue-diagrams";
// Define the palettes and symbols for the symbol palette
const palettes = ref([
{
id: "basic",
symbols: getBasicShapes(),
title: "Basic Shapes",
},
]);
// Define the basic shapes used in the palette
function getBasicShapes() {
return [
{ id: "rectangle", shape: { type: "Basic", shape: "Rectangle" } },
{ id: "plus", shape: { type: "Basic", shape: "Plus" } },
{ id: "triangle", shape: { type: "Basic", shape: "RightTriangle" } },
];
}
// Access the diagram component using a ref
const diagram = ref(null);
// Define the dragEnter handler
function dragEnter(args) {
console.log(args.element.id);
// Change the fill color of the dragged element
args.element.style.fill = "yellow";
// Ensure updates are applied by triggering data binding
diagram.value.dataBind();
}
</script>
<style>
@import "../node_modules/@syncfusion/ej2-vue-diagrams/styles/tailwind3.css";
@import "../node_modules/@syncfusion/ej2-base/styles/tailwind3.css";
@import "../node_modules/@syncfusion/ej2-popups/styles/tailwind3.css";
@import "../node_modules/@syncfusion/ej2-splitbuttons/styles/tailwind3.css";
@import "../node_modules/@syncfusion/ej2-navigations/styles/tailwind3.css";
</style><template>
<div id="app">
<ejs-symbolpalette id="symbolpalette" :palettes="palettes" :symbolHeight="50" :symbolWidth="70">
</ejs-symbolpalette>
<ejs-diagram ref="diagram" id="diagram" width="1000" height="500px" @dragEnter="dragEnter">
</ejs-diagram>
</div>
</template>
<script>
import { SymbolPaletteComponent, DiagramComponent } from "@syncfusion/ej2-vue-diagrams";
export default {
name: "App",
components: {
"ejs-symbolpalette": SymbolPaletteComponent,
"ejs-diagram": DiagramComponent,
},
data() {
return {
palettes: [
{
id: "basic",
symbols: this.getBasicShapes(),
title: "Basic Shapes",
},
],
};
},
methods: {
getBasicShapes() {
return [
{
id: "rectangle",
shape: {
type: "Basic",
shape: "Rectangle",
},
},
{
id: "plus",
shape: {
type: "Basic",
shape: "Plus",
},
},
{
id: "triangle",
shape: {
type: "Basic",
shape: "RightTriangle",
},
},
];
},
dragEnter(args) {
// Dragged symbol
console.log(args.element.id);
// Customize
args.element.style.fill = "yellow";
this.$refs.diagram.dataBind();
},
},
};
</script>
<style>
@import "../node_modules/@syncfusion/ej2-vue-diagrams/styles/tailwind3.css";
@import "../node_modules/@syncfusion/ej2-base/styles/tailwind3.css";
@import "../node_modules/@syncfusion/ej2-popups/styles/tailwind3.css";
@import "../node_modules/@syncfusion/ej2-splitbuttons/styles/tailwind3.css";
@import "../node_modules/@syncfusion/ej2-navigations/styles/tailwind3.css";
</style>DragLeave event
DragLeave event occurs when a shape leaves the diagram surface after being dragged inside but not dropped. This can be useful for resetting styles or handling any clean-up tasks when a shape is not intended to be placed on the diagram.
<template>
<div id="app">
<ejs-symbolpalette id="symbolpalette" :palettes="palettes" :symbolHeight="50" :symbolWidth="70">
</ejs-symbolpalette>
<ejs-diagram ref="diagram" id="diagram" width="1000" height="500px" @dragLeave="dragLeave">
</ejs-diagram>
</div>
</template>
<script setup>
import { ref } from 'vue';
import { SymbolPaletteComponent as EjsSymbolpalette, DiagramComponent as EjsDiagram } from "@syncfusion/ej2-vue-diagrams";
// Define the palettes and symbols for the symbol palette
const palettes = ref([
{
id: "basic",
symbols: getBasicShapes(),
title: "Basic Shapes",
},
]);
// Define the basic shapes used in the palette
function getBasicShapes() {
return [
{ id: "rectangle", shape: { type: "Basic", shape: "Rectangle" } },
{ id: "plus", shape: { type: "Basic", shape: "Plus" } },
{ id: "triangle", shape: { type: "Basic", shape: "RightTriangle" } },
];
}
// Access the diagram component using a ref
const diagram = ref(null);
// Define the dragLeave handler
function dragLeave(args) {
console.log(args.element.id);
// Additional customizations for drag leave event can be added here
}
</script>
<style>
@import "../node_modules/@syncfusion/ej2-vue-diagrams/styles/tailwind3.css";
@import "../node_modules/@syncfusion/ej2-base/styles/tailwind3.css";
@import "../node_modules/@syncfusion/ej2-popups/styles/tailwind3.css";
@import "../node_modules/@syncfusion/ej2-splitbuttons/styles/tailwind3.css";
@import "../node_modules/@syncfusion/ej2-navigations/styles/tailwind3.css";
</style><template>
<div id="app">
<ejs-symbolpalette id="symbolpalette" :palettes="palettes" :symbolHeight="50" :symbolWidth="70">
</ejs-symbolpalette>
<ejs-diagram ref="diagram" id="diagram" width="1000" height="500px" @dragLeave="dragLeave">
</ejs-diagram>
</div>
</template>
<script>
import { SymbolPaletteComponent, DiagramComponent } from "@syncfusion/ej2-vue-diagrams";
export default {
name: "App",
components: {
"ejs-symbolpalette": SymbolPaletteComponent,
"ejs-diagram": DiagramComponent,
},
data() {
return {
palettes: [
{
id: "basic",
symbols: this.getBasicShapes(),
title: "Basic Shapes",
},
],
};
},
methods: {
getBasicShapes() {
return [
{
id: "rectangle",
shape: {
type: "Basic",
shape: "Rectangle",
},
},
{
id: "plus",
shape: {
type: "Basic",
shape: "Plus",
},
},
{
id: "triangle",
shape: {
type: "Basic",
shape: "RightTriangle",
},
},
];
},
// Define the dragLeave handler
dragLeave(args) {
// Dragged symbol left the diagram area
console.log(args.element.id);
// Additional customizations for drag leave event can be added here
},
},
};
</script>
<style>
@import "../node_modules/@syncfusion/ej2-vue-diagrams/styles/tailwind3.css";
@import "../node_modules/@syncfusion/ej2-base/styles/tailwind3.css";
@import "../node_modules/@syncfusion/ej2-popups/styles/tailwind3.css";
@import "../node_modules/@syncfusion/ej2-splitbuttons/styles/tailwind3.css";
@import "../node_modules/@syncfusion/ej2-navigations/styles/tailwind3.css";
</style>DragOver event
DragOver event triggered when a shape is dragged over diagram while being moved from the symbol palette. This event can be used to provide visual feedback or to determine if the current drop target is valid.
<template>
<div id="app">
<ejs-symbolpalette id="symbolpalette" :palettes="palettes" :symbolHeight="50" :symbolWidth="70">
</ejs-symbolpalette>
<ejs-diagram ref="diagram" id="diagram" width="1000" height="500px" :getNodeDefaults="getNodeDefaults"
@dragOver="dragOver">
</ejs-diagram>
</div>
</template>
<script setup>
import { ref } from 'vue';
import { SymbolPaletteComponent as EjsSymbolpalette, DiagramComponent as EjsDiagram, NodeConstraints } from "@syncfusion/ej2-vue-diagrams";
// Define palettes and shapes
const palettes = ref([
{
id: "basic",
symbols: getBasicShapes(),
title: "Basic Shapes",
},
]);
// Basic shapes for symbol palette
function getBasicShapes() {
return [
{ id: "rectangle", shape: { type: "Basic", shape: "Rectangle" } },
{ id: "plus", shape: { type: "Basic", shape: "Plus" } },
{ id: "triangle", shape: { type: "Basic", shape: "RightTriangle" } },
];
}
// Set default node properties
function getNodeDefaults(node) {
node.constraints = NodeConstraints.Default | NodeConstraints.AllowDrop;
}
// Handle dragOver event
function dragOver(args) {
if (args.target) {
// Target shape id
console.log("Target shape ID:", args.target.id);
}
// Dragged symbol
console.log("Dragged symbol ID:", args.element.id);
// Customize as needed
}
</script>
<style>
@import "../node_modules/@syncfusion/ej2-vue-diagrams/styles/tailwind3.css";
@import "../node_modules/@syncfusion/ej2-base/styles/tailwind3.css";
@import "../node_modules/@syncfusion/ej2-popups/styles/tailwind3.css";
@import "../node_modules/@syncfusion/ej2-splitbuttons/styles/tailwind3.css";
@import "../node_modules/@syncfusion/ej2-navigations/styles/tailwind3.css";
</style><template>
<div id="app">
<ejs-symbolpalette id="symbolpalette" :palettes="palettes" :symbolHeight="50" :symbolWidth="70">
</ejs-symbolpalette>
<ejs-diagram ref="diagram" id="diagram" width="1000" height="500px" :getNodeDefaults="getNodeDefaults"
@dragOver="dragOver">
</ejs-diagram>
</div>
</template>
<script>
import { SymbolPaletteComponent, DiagramComponent, NodeConstraints } from "@syncfusion/ej2-vue-diagrams";
export default {
name: "App",
components: {
"ejs-symbolpalette": SymbolPaletteComponent,
"ejs-diagram": DiagramComponent,
},
data() {
return {
palettes: [
{
id: "basic",
symbols: this.getBasicShapes(),
title: "Basic Shapes",
},
],
};
},
methods: {
getBasicShapes() {
return [
{
id: "rectangle",
shape: {
type: "Basic",
shape: "Rectangle",
},
},
{
id: "plus",
shape: {
type: "Basic",
shape: "Plus",
},
},
{
id: "triangle",
shape: {
type: "Basic",
shape: "RightTriangle",
},
},
];
},
getNodeDefaults(node) {
node.constraints = NodeConstraints.Default | NodeConstraints.AllowDrop;
},
dragOver(args) {
if (args.target) {
// Target shape id
console.log(args.target.id);
}
// Dragged symbol
console.log(args.element.id);
// Customize as needed
},
},
};
</script>
<style>
@import "../node_modules/@syncfusion/ej2-vue-diagrams/styles/tailwind3.css";
@import "../node_modules/@syncfusion/ej2-base/styles/tailwind3.css";
@import "../node_modules/@syncfusion/ej2-popups/styles/tailwind3.css";
@import "../node_modules/@syncfusion/ej2-splitbuttons/styles/tailwind3.css";
@import "../node_modules/@syncfusion/ej2-navigations/styles/tailwind3.css";
</style>Drop event
Drop event triggered when a shape is dropped onto the diagram surface. This event is useful for customizing the shape’s appearance and properties after it is dropped.
<template>
<div id="app">
<ejs-symbolpalette id="symbolpalette" :palettes="palettes" :symbolHeight="50" :symbolWidth="70">
</ejs-symbolpalette>
<ejs-diagram ref="diagram" id="diagram" width="1000" height="500px" @drop="drop">
</ejs-diagram>
</div>
</template>
<script setup>
import { ref } from 'vue';
import { SymbolPaletteComponent as EjsSymbolpalette, DiagramComponent as EjsDiagram } from "@syncfusion/ej2-vue-diagrams";
// Define palettes and shapes
const palettes = ref([
{
id: "basic",
symbols: getBasicShapes(),
title: "Basic Shapes",
},
]);
// Basic shapes for symbol palette
function getBasicShapes() {
return [
{ id: "rectangle", shape: { type: "Basic", shape: "Rectangle" } },
{ id: "plus", shape: { type: "Basic", shape: "Plus" } },
{ id: "triangle", shape: { type: "Basic", shape: "RightTriangle" } },
];
}
// Access diagram component for binding updates
const diagram = ref(null);
// Handle drop event and customize dropped element style
function drop(args) {
// Customize the dropped element style
args.element.style.fill = "yellow";
diagram.value.dataBind();
}
</script>
<style>
@import "../node_modules/@syncfusion/ej2-vue-diagrams/styles/tailwind3.css";
@import "../node_modules/@syncfusion/ej2-base/styles/tailwind3.css";
@import "../node_modules/@syncfusion/ej2-popups/styles/tailwind3.css";
@import "../node_modules/@syncfusion/ej2-splitbuttons/styles/tailwind3.css";
@import "../node_modules/@syncfusion/ej2-navigations/styles/tailwind3.css";
</style><template>
<div id="app">
<ejs-symbolpalette id="symbolpalette" :palettes="palettes" :symbolHeight="50" :symbolWidth="70">
</ejs-symbolpalette>
<ejs-diagram ref="diagram" id="diagram" width="1000" height="500px" @drop="drop">
</ejs-diagram>
</div>
</template>
<script>
import { SymbolPaletteComponent, DiagramComponent } from "@syncfusion/ej2-vue-diagrams";
export default {
name: "App",
components: {
"ejs-symbolpalette": SymbolPaletteComponent,
"ejs-diagram": DiagramComponent,
},
data() {
return {
palettes: [
{
id: "basic",
symbols: this.getBasicShapes(),
title: "Basic Shapes",
},
],
};
},
methods: {
getBasicShapes() {
return [
{
id: "rectangle",
shape: {
type: "Basic",
shape: "Rectangle",
},
},
{
id: "plus",
shape: {
type: "Basic",
shape: "Plus",
},
},
{
id: "triangle",
shape: {
type: "Basic",
shape: "RightTriangle",
},
},
];
},
drop(args) {
// Customize the style of the dropped element
args.element.style.fill = "yellow";
this.$refs.diagram.dataBind();
// Additional customization can go here
},
},
};
</script>
<style>
@import "../node_modules/@syncfusion/ej2-vue-diagrams/styles/tailwind3.css";
@import "../node_modules/@syncfusion/ej2-base/styles/tailwind3.css";
@import "../node_modules/@syncfusion/ej2-popups/styles/tailwind3.css";
@import "../node_modules/@syncfusion/ej2-splitbuttons/styles/tailwind3.css";
@import "../node_modules/@syncfusion/ej2-navigations/styles/tailwind3.css";
</style>PaletteExpanding event
PaletteExpanding event triggered when the palette expanded / collapsed.
<template>
<div id="app">
<ejs-symbolpalette id="symbolpalette" :palettes="palettes" :symbolHeight="50" :symbolWidth="70"
@paletteExpanding="paletteExpanding">
</ejs-symbolpalette>
</div>
</template>
<script setup>
import { ref } from 'vue';
import { SymbolPaletteComponent as EjsSymbolpalette } from "@syncfusion/ej2-vue-diagrams";
// Define palettes with shapes
const palettes = ref([
{
id: "basic",
symbols: getBasicShapes(),
title: "Basic Shapes",
},
]);
// Define basic shapes for the symbol palette
function getBasicShapes() {
return [
{ id: "rectangle", shape: { type: "Basic", shape: "Rectangle" } },
{ id: "plus", shape: { type: "Basic", shape: "Plus" } },
{ id: "triangle", shape: { type: "Basic", shape: "RightTriangle" } },
];
}
// Handle palette expanding/collapsing event
function paletteExpanding(args) {
if (args.isExpanded) {
alert("Palette expanded");
} else {
alert("Palette collapsed");
}
}
</script>
<style>
@import "../node_modules/@syncfusion/ej2-vue-diagrams/styles/tailwind3.css";
@import "../node_modules/@syncfusion/ej2-base/styles/tailwind3.css";
@import "../node_modules/@syncfusion/ej2-popups/styles/tailwind3.css";
@import "../node_modules/@syncfusion/ej2-splitbuttons/styles/tailwind3.css";
@import "../node_modules/@syncfusion/ej2-navigations/styles/tailwind3.css";
</style><template>
<div id="app">
<ejs-symbolpalette id="symbolpalette" :palettes="palettes" :symbolHeight="50" :symbolWidth="70"
@paletteExpanding="paletteExpanding">
</ejs-symbolpalette>
</div>
</template>
<script>
import { SymbolPaletteComponent } from "@syncfusion/ej2-vue-diagrams";
export default {
name: "App",
components: {
"ejs-symbolpalette": SymbolPaletteComponent,
},
data() {
return {
palettes: [
{
id: "basic",
symbols: this.getBasicShapes(),
title: "Basic Shapes",
},
],
};
},
methods: {
getBasicShapes() {
return [
{
id: "rectangle",
shape: {
type: "Basic",
shape: "Rectangle",
},
},
{
id: "plus",
shape: {
type: "Basic",
shape: "Plus",
},
},
{
id: "triangle",
shape: {
type: "Basic",
shape: "RightTriangle",
},
},
];
},
// Handle palette expanding/collapsing event
paletteExpanding(args) {
if (args.isExpanded) {
alert("Palette expanded");
} else {
alert("Palette collapsed");
}
},
},
};
</script>
<style>
@import "../node_modules/@syncfusion/ej2-vue-diagrams/styles/tailwind3.css";
@import "../node_modules/@syncfusion/ej2-base/styles/tailwind3.css";
@import "../node_modules/@syncfusion/ej2-popups/styles/tailwind3.css";
@import "../node_modules/@syncfusion/ej2-splitbuttons/styles/tailwind3.css";
@import "../node_modules/@syncfusion/ej2-navigations/styles/tailwind3.css";
</style>PaletteSelectionChange event
PaletteSelectionChange event triggered after the selection changes in the symbol palette. This event can be used to enable/disable functionality based on the selected symbol.
<template>
<div id="app">
<ejs-symbolpalette id="symbolpalette" :palettes="palettes" :symbolHeight="50" :symbolWidth="70"
@paletteSelectionChange="paletteSelectionChange">
</ejs-symbolpalette>
</div>
</template>
<script setup>
import { ref } from 'vue';
import { SymbolPaletteComponent as EjsSymbolpalette } from "@syncfusion/ej2-vue-diagrams";
// Define palettes with shapes
const palettes = ref([
{
id: "basic",
symbols: getBasicShapes(),
title: "Basic Shapes",
},
]);
// Define basic shapes for the symbol palette
function getBasicShapes() {
return [
{ id: "rectangle", shape: { type: "Basic", shape: "Rectangle" } },
{ id: "plus", shape: { type: "Basic", shape: "Plus" } },
{ id: "triangle", shape: { type: "Basic", shape: "RightTriangle" } },
];
}
// Handle palette selection change event
function paletteSelectionChange(args) {
// Log the selected symbol
console.log(args.newValue);
}
</script>
<style>
@import "../node_modules/@syncfusion/ej2-vue-diagrams/styles/tailwind3.css";
@import "../node_modules/@syncfusion/ej2-base/styles/tailwind3.css";
@import "../node_modules/@syncfusion/ej2-popups/styles/tailwind3.css";
@import "../node_modules/@syncfusion/ej2-splitbuttons/styles/tailwind3.css";
@import "../node_modules/@syncfusion/ej2-navigations/styles/tailwind3.css";
</style><template>
<div id="app">
<ejs-symbolpalette id="symbolpalette" :palettes="palettes" :symbolHeight="50" :symbolWidth="70"
@paletteSelectionChange="paletteSelectionChange">
</ejs-symbolpalette>
</div>
</template>
<script>
import { SymbolPaletteComponent } from "@syncfusion/ej2-vue-diagrams";
export default {
name: "App",
components: {
"ejs-symbolpalette": SymbolPaletteComponent,
},
data() {
return {
palettes: [
{
id: "basic",
symbols: this.getBasicShapes(),
title: "Basic Shapes",
},
],
};
},
methods: {
getBasicShapes() {
return [
{
id: "rectangle",
shape: {
type: "Basic",
shape: "Rectangle",
},
},
{
id: "plus",
shape: {
type: "Basic",
shape: "Plus",
},
},
{
id: "triangle",
shape: {
type: "Basic",
shape: "RightTriangle",
},
},
];
},
// Handle palette selection change event
paletteSelectionChange(args) {
// Log the selected symbol
console.log(args.newValue);
},
},
};
</script>
<style>
@import "../node_modules/@syncfusion/ej2-vue-diagrams/styles/tailwind3.css";
@import "../node_modules/@syncfusion/ej2-base/styles/tailwind3.css";
@import "../node_modules/@syncfusion/ej2-popups/styles/tailwind3.css";
@import "../node_modules/@syncfusion/ej2-splitbuttons/styles/tailwind3.css";
@import "../node_modules/@syncfusion/ej2-navigations/styles/tailwind3.css";
</style>