Exporting React-Flow-Renderer Nodes orderBy their position in canvar - reactjs

I have nodes and edges in two different state objects ordered by when they are added in canvas in React-Flow-Renderer. now I want to get JSON of nodes sorted by their position (Top-Left to bottom right). How can I achieve this without effecting performance?

Related

Problem in designing an algorithm that moves structures in an array[][] in a certain way

I am a beginner C programmer.
I have been failing to find an algorythm that can solve the following problem:
On an array "board[x][y]" with two dimensions, which contains
following arranged elements:
Floor (white), Item (blue), Backpack (green) and Player (orange), the Player can move and can move Items by directly "touching" them, in a way that they move into the same direction and
stay attatched. "Touching" is defined by an Item being on either of
the four sides of the Player.
Graphic 1 describing predicted movement
If there is a Backpack attatched to the Player, the Backpack itself
acts as kind of a sticky attachment, moving all Items attached to that
Backpack, including other Backpacks.
Graphic 2 describing predicted movement
Is there an algorithm that can sucessfully move the resulting "structures" formable by the rules, only moving Items "attached"? If you can help me find a way or guide me on a path, I'd be very happy to learn about it.
Thank you in advance.
Store in a list the positions of the player and of the attached items and backpacks. When you perform a move, all elements in the list move. After the move, consider the player and backpacks in the list, and add the neighboring items or backpacks that are not already there.
[But see my second comment.]

Saving SVG element points in the database

We are developing a drawer SVG based. The user can add elements to it and so on. The elements of the SVG have theirs points saved in the database. When the application loads, the SVG is drawn properly. Here it works fine!
Now the user can move elements around and rotate them. Once those actions are made, the new points of the elements should be sent to the database. The problem with this is that using transform we are changing the user coordinate system and with that the points of all other elements.
My first thought was to iterate throughout all the SVG elements and update their points when the points of one single element changes.
What is the best practice when working with SVG?

DIstinct edges in arbor.js

How do I draw edges that are non-overlapping using arbor.js ? for example, I have 2 nodes A and B in my graph. There is a directed edge from A->B and another one from B->A. How do I display these edges in such a way that they don't overlap ?
well,you have the edge renderer at your disposal, so you can draw an arc-ed line in canvas between the two points...(to do this,use particlesystem.eachedge and see if B and A are connected, then make a arc-ed edge)

Drag multiple items on a canvas and maintain same distance

I have a Canvas that contains, let's say rectangles to be simple. These rectangles can be single selected, multi selected(two or more rectangles). When I have multi selected rectangles, I want to drag all selected rectangles and maintain the distance between these rectangles.
Any suggestions how to achieve that kind of behaivor?
Best regards,
Gabriel
Well when moving, add the delta in the mousemove event to all elements current Canvas position, that way you will keep the distance between the objects.

WPF 3D - Positioning Visual3D elements in a 3D scene using nested Model3DGroup transforms?

I have a 3D scene where my 3D models are being loaded in the code behind from XAML files.
Each model is comprised of a tree of nested Model3DGroups each of which has various transformations applied to it to position and orient the next subcomponent of the model in the tree. This model is then used as the content of a ModelVisual3D so that it can be displayed to the screen.
I want to attach a child ModelVisual3D to a 'parent' ModelVisual3D. This child ModelVisual3D needs to use all of the nested transformations of the parent ModelVisual3D.Content to correctly position and orient itself in the virtual space. For example, the first ModelVisual3D is a robot arm which has various moveable joints and I want to attach a tool on the end of this arm--another ModelVisual3D. How can I access this composite transform from the parent ModelVisual3Ds content property to allow me to position the next ModelVisual3D correctly relative to its parent?
As you have no doubt observed, when you group Model3Ds in a Model3DGroup the Transform properties of the children combine with those of the parent.
It sounds like you are asking how to compute the net transform down to a particular Model3D within a tree of Model3Ds that make up what you are calling your "model". To do this you need to know (or be able to scan and discover) the path from your root Model3DGroup down to the Model3D you want to find the transform for.
Once you have this path, all that is required is to combine the Transform properties at each level. To do this, simply construct a Transform3DGroup and add the individual transforms to it.
For example, if your robot arm has Model3D components named "UpperArm", "LowerArm", and "Hand", and you wanted to find out the position and angle of the hand you might do:
var combined = new Transform3DGroup();
combined.Children.Add(UpperArm.Transform);
combined.Children.Add(LowerArm.Transform);
combined.Children.Add(Hand.Transform);
Now you can find the (0,0,0) location on the hand as follows:
combined.Transform(new Point3D(0,0,0));
Similarly you can find other points and use them to position your other ModelVisual3D.

Resources