Skip to content

docs(Diagram): Add Diagram component documentation #3089

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 23 commits into from
Aug 4, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
411 changes: 411 additions & 0 deletions components/diagram/connections.md

Large diffs are not rendered by default.

118 changes: 118 additions & 0 deletions components/diagram/events.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
---
title: Events
page_title: Diagram - Events
description: Learn about the Blazor Diagram component events and experiment with them in the provided runnable code examples.
slug: diagram-events
tags: telerik,blazor,diagram
published: True
position: 100
---

# Blazor Diagram Events

The Telerik Blazor Diagram fires events that are related to different user actions. This article describes all these events and their event arguments:

* [`OnConnectionClick`](#onconnectionclick)
* [`OnShapeClick`](#onshapeclick)

## OnConnectionClick

The `OnConnectionClick` event fires when the user clicks on a connection, including the connection ends that rest on the shape boundaries. The event argument is of type [`DiagramConnectionClickEventArgs`](slug:Telerik.Blazor.Components.DiagramConnectionClickEventArgs) and it provides information about the linked shapes (if they exist) or about the connection coordinates (if set).

>caption Using the Diagram OnConnectionClick event

````RAZOR.skip-repl
<TelerikDiagram OnConnectionClick="@OnDiagramConnectionClick" />

@code {
private void OnDiagramConnectionClick(DiagramConnectionClickEventArgs args)
{

}
}
````

Also see the [example](#example) below.

## OnShapeClick

The `OnShapeClick` event fires when the user clicks on a shape. The event argument is of type [`DiagramShapeClickEventArgs`](slug:Telerik.Blazor.Components.DiagramShapeClickEventArgs) and provides the shape `Id`.

>caption Using the Diagram OnShapeClick event

````RAZOR.skip-repl
<TelerikDiagram OnShapeClick="@OnDiagramShapeClick" />

@code {
private void OnDiagramShapeClick(DiagramShapeClickEventArgs args)
{

}
}
````

## Example

The following example demonstrates all Diagram events in action.

>caption Using Diagram events

````RAZOR
<TelerikDiagram Height="360px"
OnConnectionClick="@OnDiagramConnectionClick"
OnShapeClick="@OnDiagramShapeClick">
<DiagramLayout Type="@DiagramLayoutType.Tree" />

<DiagramShapes>
<DiagramShape Id="shape1">
<DiagramShapeContent Text="Shape 1">
</DiagramShapeContent>
</DiagramShape>
<DiagramShape Id="shape2">
<DiagramShapeContent Text="Shape 2">
</DiagramShapeContent>
</DiagramShape>
<DiagramShape Id="shape3">
<DiagramShapeContent Text="Shape 3">
</DiagramShapeContent>
</DiagramShape>
</DiagramShapes>

<DiagramConnections>
<DiagramConnection FromId="shape1" ToId="shape2" />
<DiagramConnection FromId="shape1" ToId="shape3" />
<DiagramConnection>
<DiagramConnectionFrom X="300" Y="20" />
<DiagramConnectionTo X="400" Y="200" />
</DiagramConnection>
</DiagramConnections>
</TelerikDiagram>

@DiagramEventLog

@code {
private string DiagramEventLog { get; set; } = string.Empty;

private void OnDiagramConnectionClick(DiagramConnectionClickEventArgs args)
{
if (args.FromX != null)
{
DiagramEventLog = $"Clicked on the connection between coordinates ({args.FromX}, {args.FromY}) and ({args.ToX}, {args.ToY}).";
}
else
{
DiagramEventLog = $"Clicked on the connection between shapes '{args.FromId}' and '{args.ToId}'.";
}
}

private void OnDiagramShapeClick(DiagramShapeClickEventArgs args)
{
DiagramEventLog = $"Clicked on shape '{args.Id}'.";
}
}
````

## See Also

* [Live Demos: Diagram](https://demos.telerik.com/blazor-ui/diagram/overview)
* [Diagram API Reference](slug:Telerik.Blazor.Components.TelerikDiagram)
Loading