Prevent overlapping nodes with arbor.js - visualization

I am trying to do an animation using arbor.js. I want to display about 50 to 100 weighted nodes, where the weight defines the size of the node. I was able to display all the nodes but the heavier nodes concentrate in the center and overlap each other. There is a lot of empty space in the canvas that can be used to spread out the nodes.
Is there a setting I can use to not have the nodes overlap?

When creating your particle system use more repulsion, ie. 10000 instead of the default 1000:
arbor.ParticleSystem(10000);
This will not prevent overlapping, but may fix your display problem.

Related

1 large sktilemapnode or smaller sktilemapnode

I'm going to be using sktilemapnodes for my 2d iOS platformer. What is better or more efficient?
Using a single size sktilemapnode that is the entire level or breaking the area up into multiple sktilemap nodes.
Example:
I have 3 layers of backgrounds that I'm going to use for a parallax background effect.
1st Layer (furthest back) is just a gradient sky. I have it broken up into 512x512 px tiles. I only have 8 different tiles that can be used as a 1x8 grid of tiles. I could then continue this pattern left/right or up/down in order to have the sky be as large as I need it to be.
Question: My question is whether I should use 1 tile map node for the entire sky, or if I should break it up into smaller chunks that are repeatable (like the 1x8 grid). If I break it up into smaller chunks I wouldn't need it to be so big, and as the camera moves around in my game I can move these chunks around.
I'm wondering if this would consume less resources this way.
2nd Layer are hills. I have about 8 different tiles that are 128x64 px each. I can arrange them into a repeatable pattern to my liking. So again I can have a tilemapnode that is the size of the pattern that I can repeat, and I can create multiple nodes or I can just create the entire map in 1 node.
3rd layer is a little different because it is basically a pattern image of trees that holds 27 512x512 px tiles. 9x3 grid. But again, I can use 1 node, or multiple.
I'm just concerned with efficiency. What is going to give me the most bang for my buck so that I can have room to process other game objects. This is just the background u know....
With the Tilemapnode, I'm not sure if tiles that are not visible are not processed each cycle or if I need to do some sort of check manually. I want to have the options of having massive maps on certain levels. I'm new to using sktilemapnodes, so I'm trying to figure out how I would use them in the most efficient way possible.
Each SKTileMapNode is a single node. Apple does a good job of making sure that multiple map nodes don't use too many resources. That is why there is a single node for a map instead of a node for every tile in a map. It is common practice to layer multiple SKTileMapNode(s) to create a parallax effect or simply to create layers.
For example, a platform game with mountains in the background and clouds behind that would use a single SKTileMapNode for the mountains and a single one for clouds. This gives the added benefit of being able to use transparency in tiles.

Adding and removing multiple nodes efficiently, without any lag

In my game, at specific intervals, a function is called that adds multiple nodes to the scene (between 2 and 6 nodes). These individual nodes are all the same - they consist of the same blender model, same SCNCone, same spotlight and same physics bodies - (The blender model is low-poly, nothing extreme).
When it's time to call the next interval of nodes, the nodes that were called previously are removed (including their actions). This process repeats until the player has died. Now when the nodes are removed and new ones are added, it creates noticeable lag for roughly a second, and doesn't appear smooth.
I'm wondering whether there is a more efficient way to add and remove these nodes that could possibly eliminate lag? Since these nodes are all visibly the same, would cloning a node multiple times be better than re-creating the same node over and over within a for loop?
Any advice on efficiency or better practises would be greatly appreciated too.
Thanks!
Edit: Just a thought, should I have a node at every required position, and basically un-hide and give them actions when needed, and once they've done their job, fade out, put back at initial position, remove actions and hide?
This would mean I would need about 20 nodes in the scene at all times, but at least there would be no need to add any more, or remove any.
Start by turning ON statistics.
scnView.showStatistics = YES;
Click on the + at the bottom left of the screen to the stats screen.
What could be causing the lag? Quick things to check are:
1. Is the geometry too complex?
2. Are the textures too large?
3. Are there too many draw calls?
Cloning is better.
Yes, I think your idea at the end will avoid the lag. If the nodes being added are the same as the nodes being removed it will be more efficient just to hide and reset them.
If you are creating the nodes each time it is likely that is causing the lag, and you could even remove and add them from the scene but instead of creating them when needed store them in an array ready to be reused.

Additional forces to networkx spring_layout

I would like to add additional forces to networkx spring_layout.
I have a directected graph and I would like nodes to move to different sides according to the edges that they have. Nodes that have more outgoing edges should drift to nodes that have more ingoing edges should drift right. Another alternative would be. That these groups of nodes would drift towards each other, nodes with outgoing edges would get closer while nodes with ingoing edges would also get closer to each other.
I managed to look into to the source code of spring_layout of networkx http://networkx.lanl.gov/archive/networkx-0.37/networkx.drawing.layout-pysrc.html#spring_layout
but everything there is just beyond my comprehension
G.DiGraph()
G.add_edges_from([(1,5),(2,5),(3,5),(5,6),(5,7)])
The layout should show edges 1,2,3 closer to each other, the same regarding 6 and 7.
I imagine, that I could solve this by adding invisible edges via using MultiDiGraph. I could count ingoing and outgoing edges of each node and add invisible edges that connect the two groups. However, I am very sure that there are better ways of solving the problem.
Adding weights into the mix would be a good way to group things (with those invisible nodes). But the layouts have no way of knowing left from right. To get the exact layout you want you could specify each point's x,y coordinates.
import networkx as nx
G=nx.Graph()
G.add_node(1,pos=(1,1))
G.add_node(2,pos=(2,3))
G.add_node(3,pos=(3,4))
G.add_node(4,pos=(4,5))
G.add_node(5,pos=(5,6))
G.add_node(6,pos=(6,7))
G.add_node(7,pos=(7,9))
G.add_edges_from([(1,5),(2,5),(3,5),(5,6),(5,7)])
pos=nx.get_node_attributes(G,'pos')
nx.draw(G,pos)

Prevent two particular nodes from overlapping in arbor.js

I have drawn a graph using arborjs with about 15-20 nodes. Is there a way to ensure that two particular nodes never overlap. In fact, it would be better if they have a quite large distance between them or are simply situated at the extremes of the canvas.

Multiple Annotations (IOS) Easiest way

Im using Annotations in IOS to display London Tube stations, but im looking at numbers and there are 280 or so.
Whats the easiest way to do this?
Individually or is there another option?
Cheers for all the advice
David
The performance is good with 280 annotations, the appearance is not. You have to group them into clusters when the user zooms out.
One way to do it is:
Decide how many cluster annotations you want to show.
Split the screen in x*y tiles so roughly x*y =~ numClusters and x/y=480/320=1.5
Add a cluster annotation per tile (it's a normal cluster with an array containing 0 or more annotations).
Run the k-means algorithm:
Iterate all annotations and add each one to the closest cluster.
Calculate a new center for each cluster, which will be an average of the centers of all its members.
Empty each cluster.
Repeat until no cluster moves any longer.
Remove empty clusters, if any.
You end up with numClusters clusters positioned according to the annotation density.
You can also leave a number of normal annotations on their own if they are away from the clusters. Depends on how you want it to look.