Articles in this section
Category / Section

How to render SVG nodes to include multiple path elements within a single node for both diagram and symbol palette rendering?

3 mins read

Rendering SVG nodes with multiple path elements in Syncfusion.Blazor.Diagram and Syncfusion.Blazor.Diagram.SymbolPalette components allows you to create complex visual elements. This guide will walk you through the necessary steps to achieve this in a Blazor application.

Prerequisites:
Create Blazor Server application

1. Define the SVG Content

To render complex shapes and structures, use the element to group multiple elements. This example SVG illustrates how to define multiple path elements within a single node:

<g xmlns="http://www.w3.org/2000/svg" id="Server" stroke="none" stroke-width="1" fill="none" fill-rule="evenodd">
   <!-- Define multiple path elements -->
   <path d="M 0 18 L 0 36 L 6 36 L 6 30 L 18 30 L 18 36 L 24 36 L 24 30 L 26 30 L 26 3 L 18 3 L 0 18 M 18 0 L 36 0 L 36 6 L 60 6 L 60 24 L 48 36 L 48 30 L 36 30 L 36 36 L 30 36 L 30 30 L 27 30 L 27 0 L 18 0 Z" id="Truckshape" stroke="black" stroke-width="1" fill="yellow" style="transform: translate(20px, 30px);" />
   <path d="M 12 6 C 12 9.31 9.31 12 6 12 C 2.69 12 0 9.31 0 6 C 0 2.69 2.69 0 6 0 C 9.31 0 12 2.69 12 6 Z" id="Wheel1" stroke="black" stroke-width="5" fill="whitesmoke" style="transform: translate(55px, 55px);" />
   <path d="M 12 6 C 12 9.31 9.31 12 6 12 C 2.69 12 0 9.31 0 6 C 0 2.69 2.69 0 6 0 C 9.31 0 12 2.69 12 6 Z" id="Wheel2" stroke="black" stroke-width="5" fill="whitesmoke" style="transform: translate(26px, 55px);" />
   <path d="M 18 6 L 24 6 24 12 15 12 18 6 z" id="Loader" stroke="black" stroke-width="1" fill="whitesmoke" style="transform: translate(20px, 28px);" />
</g> 

2. Configure the Symbol Palette

To display the SVG in the Symbol Palette, define it within the SymbolPaletteTemplates section:

<SymbolPaletteTemplates>
   <NodeTemplate>
       <g xmlns="http://www.w3.org/2000/svg" id="Server" stroke="none" stroke-width="1" fill="none" fill-rule="evenodd">
           <!-- SVG path elements here -->
       </g>
   </NodeTemplate>
</SymbolPaletteTemplates> 

This NodeTemplate renders the custom SVG within the Symbol Palette, allowing you to reuse the complex SVG structure as a symbol.

3. Configure the Diagram

Similarly, configure the DiagramTemplates section to render the SVG node within the Diagram component. This ensures consistency across both Diagram and Symbol Palette elements:

<DiagramTemplates>
   <NodeTemplate>
       <g xmlns="http://www.w3.org/2000/svg" id="Server" stroke="none" stroke-width="1" fill="none" fill-rule="evenodd">
           <!-- SVG path elements here -->
       </g>
   </NodeTemplate>
</DiagramTemplates> 

Output:

image.png

You can download the complete working sample from here.

Conclusion:

I hope you enjoyed learning how to render SVG nodes to include multiple path elements within a single node for both diagram and symbol palette rendering.
You can refer to our Blazor 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 Blazor 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, support portal, or feedback portal. We are always happy to assist you!

Did you find this information helpful?
Yes
No
Help us improve this page
Please provide feedback or comments
Comments (0)
Please  to leave a comment
Access denied
Access denied