How to correctly rotate an IGroup in a zoomed/scrolled RadDiagram using the RotationService?

1 Answer 52 Views
Diagram, DiagramRibbonBar, DiagramToolBox
Yves
Top achievements
Rank 1
Yves asked on 19 Oct 2022, 06:40 AM | edited on 19 Oct 2022, 06:42 AM

I'm currently working on a project where we are using a RadDiagram to dynamically display and plan a distribution hall. Here we are using different elements/shapes in the diagram to represent storage shelves and spaces/spots in those shelves. We want to draw these shelves and their spots either horizontally from left to right or vertically from bottom to top. We want to do this by first drawing the shelve and its spots horizontally and then rotate the shelve using a custom RotationService, that rotates the shelve group programatically. This however has an unwanted side effect, which can be inspected in the provided demo app and below:

The rotation via the custom RotationService appears to move the shelve in the diagram to a "random" position depending on the RadDiagram zoom and scroll position. So a shelve can be drawn and rotated as expected in the first initialization of the diagram.

Initial Diagram creation:

If the diagrams zoom level and scroll position isn't changed a shelve can be selected and rotated using the switch button. This also works as expected.

Shelve rotation without zoom:

If however the zoom of the diagram is changed or the scroll position is changed, following a rotation of a shelve or the redraw of the whole diagram using the refresh button, the vertically rotated shape is moved to a differen position.
If the rotation of the shelve is repeated multiple times the postion of the rotated shape appears to migrate to a point in the diagram. If the shelve reaches this point it will start to rotate properly again, without further change in position.

Shelve rotation with zoom:

Refresh with zoom and different scroll positions:

As seen above the rotated shelve is drawn in different positions each time the diagrams zoom or scroll is changed. Is this due to a wrong implementation of the RotationService as seen in the Demo_Project or is it due to a bug?

 

 

1 Answer, 1 is accepted

Sort by
1
Accepted
Dinko | Tech Support Engineer
Telerik team
answered on 21 Oct 2022, 01:40 PM

Hi Yves,

Thank you for the detailed description.

I have debugged the project and observed this behavior. It took me some time to find the reason behind this. In a few words, in the custom RotationService, you need to pass the bounds of the items inside the group, not the group itself. You can do that by calling the GetEnclosingBoundsRotated() extension method of the collection of IDiagramItem. This method will get the enclosing bounds of a group of shapes. Check the following code snippet.

public void RotateGroup(IGroup group, ShelveOrientation newOrientation)
{
    var groupItems = group.Items.OfType<IDiagramItem>();
    var shelve = groupItems.Where(x => x is RadDiagramShape shape && shape.Tag is ShelveModel).Select(x => ((RadDiagramShape)x).Tag).FirstOrDefault() as ShelveModel;
    this.InitializeRotate(groupItems, 0, groupItems.GetEnclosingBoundsRotated());
    this.StartRotate(new Point());

    customAngle = getRotationAngle(newOrientation, shelve.Orientation);

    this.Rotate(new Point());
    this.customAngle = null;

    this.CompleteRotate(new Point());
}

After passing the enclosing bounds of the shapes, the reported behavior in your post is not observed anymore on my side. Can you give it a try and let me know how it goes?

Regards,
Dinko | Tech Support Engineer
Progress Telerik

Virtual Classroom, the free self-paced technical training that gets you up to speed with Telerik and Kendo UI products quickly just got a fresh new look + new and improved content including a brand new Blazor course! Check it out at https://learn.telerik.com/.

Yves
Top achievements
Rank 1
commented on 24 Oct 2022, 11:28 AM

This indeed fixed the problem. Thank you very much!!
Tags
Diagram, DiagramRibbonBar, DiagramToolBox
Asked by
Yves
Top achievements
Rank 1
Answers by
Dinko | Tech Support Engineer
Telerik team
Share this question
or