How can I get shapes with correct order

Hi everyone,

I have to get activities shapes in the correct order same as render in the modeler.
Problem:
ElementRegistery keeps them in the array but order or sort by added time. That means if you add a user task (call Hello element) between two activities, elementRegistery added this to the end of the array (like push method.) But I need to get this hello element between two shapes in the correct order or sort.

For example:
I have diagram like below:

Ekran Resmi 2021-09-29 12.25.57

So elementRegistery provided data, same as the above.

But when I added a new element between:

Ekran Resmi 2021-09-29 12.26.55

Now “Hello Element”, added to the last index of the elementRegistery. So how can I understand that the “Hello World” element is between Element 2 and Element 3?

Hi Again,

I found the temporary solution with a sort array by x value of an element.

This is my algorithms

  1. filter the shapes by their activity type using the elementRegistry.filter method
  2. sort the array by its x value.

So also It can be extended if you have any sub-processes type.