Skip to content

Commit 94e27e4

Browse files
github-actions[bot]KB Bot
andauthored
Added new kb article diagram-center-items-rad-diagram (#618)
Co-authored-by: KB Bot <[email protected]>
1 parent 141a879 commit 94e27e4

File tree

1 file changed

+66
-0
lines changed

1 file changed

+66
-0
lines changed
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
---
2+
title: Centering Items in RadDiagram
3+
description: Learn how to horizontally center items within the RadDiagram control in ASP.NET AJAX.
4+
type: how-to
5+
page_title: How to Center Shapes in RadDiagram for ASP.NET AJAX
6+
slug: diagram-center-items-rad-diagram
7+
tags: rad-diagram, asp.net-ajax, center, items, shapes
8+
res_type: kb
9+
ticketid: 1668422
10+
---
11+
12+
## Environment
13+
14+
<table>
15+
<tbody>
16+
<tr>
17+
<td>Product</td>
18+
<td>RadDiagram for ASP.NET AJAX</td>
19+
</tr>
20+
<tr>
21+
<td>Version</td>
22+
<td>all</td>
23+
</tr>
24+
</tbody>
25+
</table>
26+
27+
## Description
28+
29+
Centering items horizontally within the RadDiagram control is a common requirement. This task can be achieved by utilizing the `bringIntoView()` method of the underlying diagram widget.
30+
31+
This KB article also answers the following questions:
32+
- How to ensure all RadDiagram shapes are visible in the viewport?
33+
- How to automatically adjust the zoom to fit all shapes in RadDiagram?
34+
- How to use the `bringIntoView()` method with RadDiagram in ASP.NET AJAX?
35+
36+
## Solution
37+
38+
To center all or specific shapes within the RadDiagram's viewport, utilize the `bringIntoView()` method. This method can zoom out the diagram as needed to ensure all specified shapes fit within its viewport.
39+
40+
Here's how you can implement this on the client-side `OnLoad` event of the RadDiagram:
41+
42+
1. Define the RadDiagram in your ASP.NET AJAX page with a client-side `OnLoad` event handler:
43+
44+
```asp
45+
<telerik:RadDiagram ID="RadDiagram1" runat="server">
46+
<ClientEvents OnLoad="onLoad" />
47+
...
48+
</telerik:RadDiagram>
49+
```
50+
51+
2. Implement the `onLoad` function in JavaScript to use the `bringIntoView()` method. Pass all diagram shapes to this method to ensure they are centered and visible in the diagram's viewport:
52+
53+
```javascript
54+
function onLoad(diagram, args) {
55+
var diagramWidget = diagram.get_kendoWidget();
56+
diagramWidget.bringIntoView(diagramWidget.shapes);
57+
}
58+
```
59+
60+
By passing the diagram's shapes to the `bringIntoView()` method, the RadDiagram will adjust its zoom level as needed to fit all shapes within the viewport, effectively centering them.
61+
62+
## See Also
63+
64+
- [RadDiagram Overview](https://docs.telerik.com/devtools/aspnet-ajax/controls/diagram/overview)
65+
- [bringIntoView() Method Documentation](https://docs.telerik.com/kendo-ui/api/javascript/dataviz/ui/diagram/methods/bringintoview)
66+
- [How to Show All Diagram Items So They Fit in the Viewport](https://www.telerik.com/support/kb/aspnet-ajax/diagrams/details/how-to-show-all-diagram-items-so-they-fit-in-the-viewport)

0 commit comments

Comments
 (0)