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 a Blazor Server application by following this guide

1. Define the SVG Content

To render complex shapes and structures, use the <g> element to group multiple <path> 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:

We hope you enjoyed learning how to render SVG nodes with include multiple path elements within a single node for both diagram and symbol palette components.
You can refer to our Blazor Diagram feature tour page to learn about its other groundbreaking features, documentation, and how to quickly get started with configuration specifications. You can also explore our Blazor Diagram example to understand how to create and manipulate data.

For current customers, our Blazor components are available on the License and Downloads page. If you are new to Syncfusion®, you can try our 30-day free trial to evaluate our Blazor Diagram and other Blazor components.

If you have any questions 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