In draw.io, how to move a node in front of another one? - draw.io

I create a Horizontal Tree Layout and create some nodes in Draw.io.
tree node
How to move "item 1" in front of "item 2"?

Unfortunately, it is not possible at the moment but you can vote and track this request here: https://github.com/jgraph/drawio/issues/1680
Regards,

Related

checkboxes for wxtreectrl in wxformbuilder

In wxTreeListCtrl we have wxTL_CHECKBOX, but it selects only one item and not all children of that item. Can we have checkbox feature for wxTreeListCtrl which will select all children of subtree when that parent node is selected? Or do we have such similar feature for any other tree component? I need to build a tree structure where, if we select any one node then all its children nodes should be selected. How to do this?
If you want to select all children of an item when it is checked, you have to do if yourself by calling CheckItemRecursively() method from your wxEVT_TREELIST_ITEM_CHECKED handler.

Creating a syntax tree with pushdown automation?

If I were to create a pushdown automation that accepts a state(name) and those states accept transitions(input, pop, push, nextState). How does all this help me construct a parse tree?
I mean a pushdown automata is great for checking if something is in the language, like if a sequence of tokens or whatever is in the correct order... but syntax trees?
I mean consider the following example:
Foo {
Woo {
Hello World
}
}
The pda can only remember the top item in a stack and the current input. How am I supposed to construct the tree? Should I combine PDA with recursion?
Broadly, each item on the stack contains a list of syntax subtrees. When you push a new item, its list starts off empty. When you shift (consume) a token, you add it to this list. When you pop, you take all the subtrees in the list of the top item, set them as children of the new node, and add this new subtree to the list of the new top of the item stack. Eventually, when you pop the last item off stack, you'll end up with a single subtree, which will be the entire syntax tree.

How to build a non-binary tree (with dependencies) incrementally

Short Description
I need to build a non-binary tree (language doesn't matter for now, but preferably in C++) from a list of items that do have dependencies to each other, but non-recurring and not cyclic.
The data for the nodes are read from a file and incrementally inserted into the tree.
The troubling part is how to handle those nodes which do not have parent-nodes yet that fulfill the dependency of the inserted node.
Detailed Description
Rough Outline
The assignment is easy: represent a bunch of Tasks and Subtasks in a non-binary tree.
This assignment would be quite easy to understand and implement, if not for a tiny condition: the list of Tasks has to be generated incrementally, so do the nodes in the tree.
Scenario
The Tasks are generated asynchronously and have to be added into the tree once the data to a certain Task is received.
This is "simulated" by reading a csv-file which has a certain Task in each line with some data, the most important ones being the PID and PPID attributes.
After a line is read and parsed, a Task is being created and inserted into the tree.
The tree should automatically resolve the dependencies following two simple rules:
Only show the node when the dependency is met (namely when a parent-node has been inserted before), but memorize the (now orphaned) node.
Whenever a Task(node) is added, check if it's a parentnode of one of the above meantioned orphaned ones and reconcile the nodes if rule #1 isn't infringed while doing so.
Please disregard the faulty logic behind this scenario: Normally, there can't be any SubTask without a ParentTask existing (at least in monolithic kernel designs).
And while the List of Tasks certainly do contain the ParentTasks needed to model the tree, it is unknown when the ParentNode-Data is read and inserted into the tree.
Desired outcome
Below is a figure showing the "raw data", a list of (unsorted) Tasks which has been created incrementally while adding one Task after another to the list.
The tree represents the subset of Tasks which has been inserted so far:
Please keep in mind that the tree is completely "naked" until the Tasks with the PIDs 1, 2 and 3 are inserted, because the other nodes are dependent of them.
What I did so far
I've written a Qt-C++ Code with three rough components:
TaskTree which holds a Root-Node (a node without any task-data)
TaskNode which has a field to hold the task-data and a QList<TaskNode> which is, in simple terms, a vector of TaskNodes to reference childnodes
Task has the related attributes (like pid and ppid)
It is no problem to insert a TaskNode if the parentnode already exists.
This only works though in a perfect world, in which the Tasks are sorted upon their respective dependencies AND there's a determined amount of Tasks to be added.
I don't have to tell you that such a scenario is highly unlikely though, so the tree creation has to memorize any orphaned node (which is a node that doesn't have a parent yet, duh).
I've tackled this "memorization" in different ways, but failed alltogether because I couldn't wrap my head around the algorithms behind it.
The two most promising thoughts I had were these:
Insert every orphaned node into a vector. Upon inserting a parentnode, check if it has children in the Orphan-Vector and reconcile. Do this recursively for the newly created subtree to match all possiblities.
Assign the PPID to the tree's RootNode, being 0 for the most top one. When an orphaned node appears, create a new TaskTree, assign the PPID of the orphan to the newly created tree and add the orphan to it.
This creates subtrees which can be quit intricate themselfs if several orphans match one of the trees. After each inserted Node, try to reconcile the subtrees to the root-tree.
Unfortunately I had to give up continuing those two concepts due to several spontaneous SIGSEGV's and other problems occuring because of the recursions etc.
So in the end I'm here trying to find a way to actually make this work without cutting down the complexicity of the problem through assumptions and other cheats...
Do you guys and gals have an idea which algorithm I could use for this problem or what category of problem this even is?
Approach 2 is the right one to take. The pieces that you are missing are that you need an unordered_map called node_needed that maps as yet unseen parent nodes to a vector of child trees that are waiting for it. You need a similar one mapping node_seen to the associated tree for nodes that have been seen.
Then when you see a node you perform the following:
Create TaskTree with only this node.
Add this TaskTree to the node_seen map
If this node's ID is in the parent_needed map:
Add each tree in the parent_needed map to this tree
Remove this node's ID from the parent_needed map
If this node has no parent:
Add this node's tree to the root tree
Else if this node's parent ID is in the node_seen map:
Add this node's tree to the parent tree
Else if this node's parent_ID is in the parent_needed map:
Append this node's tree to the parent_needed vector
Else:
Create a vector containing this node's tree
Add a mapping from this node's parent ID to that vector in the parent_needed map
Assuming no bugs (HAH! Bugs are part of life...), this should work.
After some deliberate design changes, I've come up with - what I think - the easiest way to implement this:
InsertTask(Task newTask)
{
Task parentTask = searchTreeForParent(newTask->ppid)
If (parentTask not found)
{
parentTask = treeRootNode;
}
If (treeRootNode has children)
{
For (every children in treeRootNode: child)
{
If (child->ppid != treeRootNode->pid AND child->ppid == newTask->pid)
{
newTask->addChild(child)
treeRootNode->remove(child)
}
}
}
parentTask->addChild(newTask)
}
The algorithm behind it is pretty easy: You add the new Tasks to the root node if there is no parent node yet and at the same time check if the newly added Task has potential children in the root node (because those orphaned ones were added to the root node before).
So if you actually insert all the Tasks to fulfill the dependencies, you end up with a complete and valid tree.
If you don't supply all the parent nodes, you end up with some of the branches being complete and valid and a bunch of orphaned ones in the root node.
But that's no problem because there is an easy trick to differenciate between a complete branch and orphans: just check if the ppid equals the root node's pid and voila, you output only those branches that are complete.

What is the proper name for a container with these requirements?

I need to implement additional container for my library. I need it for holding profile points in my profiler module. Everything is ready to begin coding, however, I am not sure what is the proper name for this kind of container.
What I need, is data structure described as following:
It's a 'multi-level' container (entries can have children).
There is no root node.
At the 'top level' it holds list of elements.
Elements are stored in order they were added.
Each node can have any number of child nodes.
Example usage:
Container c;
c.push(5);
c.push(7);
c.push_level(); //now, new elements will be added as children of '7'.
c.push(3);
c.push(14);
c.pop_level();
c.push(6); //this entry will be added to 'root list'.
Any ideas?
It is a forest. A forest is essentially a set of trees, each with their own root. Your first level of your container is the set of root nodes in the forest, and then all children are described in lower levels.
Everything except the "Elements are stored in order they were added" corresponds with that of an R-tree: http://en.wikipedia.org/wiki/R-tree

Flex4.6 Add element to top of List

I've got a spark list that gets dynamically filled.
So far the new items appear at the bottom of the list. What I'd like to do is to add them at the top.
The items in the list have a unique ID so some kind of sorting mechanism would probably do the trick as the new items have a greater ID than the old ones.
What I'd like to avoid is some complex method behind this as I'm working on a mobile platform and the list can get quite big so I need this to be as efficient as possible.
The list's data provider is an ArrayList that gets updated using binding.
How can that be done?
Thanks in advance!
u can Add the items at the starting index of the datagrid. Flex datagrid automatically renew all the indexes and add 1 to all existing element indexes. So
YourDataGridId.dataprovider.addItemAt(item,0) will do.