JSNewtworkX stop layout - graph

i'm using JSNetworkX for graph exploration and rendering.
JSNetworkX is using D3.js for graph render. However, as I work with large graph (json file about 5Mb), I would like to render this graph directly without any animations (so, in placing each node directly without force attraction).
I try to use D3.layout.force().stop() after rendering, but it's without effects.
Because of that, I'm thinking that it has to be done in jsnx.draw, see my code below.
jsnx.draw(G, {
element: 'body',
d3: d3,
layout_attr: {
charge: -1500,
linkDistance: 1,
gravity: 1,
friction: 0.4,
alpha: -100
},
});
force = d3.layout.force();

Unfortunately, you can't do that with the current version. Do you need a force layout at all or do you already have positions for each node? FWIW, if you really have a large graph, even a static layout would be slow, because you'd still have too many SVG elements. The next version will include a WebGL rendered for large graphs.
So, we can't for the moment.

As of v0.3.4, jsnx.draw returns the force layout object so you can do var force = jsnx.draw{/*...*/} then force.stop().

Related

How do I scale a Mobject using a Manim updater?

I can scale a Square mobject as follows with self.play()/Scene.play():
square = Square(fill_color=RED, fill_opacity=1)
self.play(square.animate.scale(3))
self.wait(3)
But I cannot achieve the scale behaviour as above using this simple add_updater method. All I get is a blank screen:
square = Square(fill_color=RED, fill_opacity=1)
def scale_up(mob, dt):
mob.scale(2*dt)
square.add_updater(scale_up)
self.add(square)
self.wait(3)
Questions
How can I achieve the behaviour of No 1 above with add_updater, or other updater techniques?
I know that I can successfully animate an item with updater methods - such as doing mobject.shift() - even without using self.play()/Scene.play(). Can the behaviour of No. 1 above be achieved without using the Scene.play() method?
It appears that you can .scale() an object with scene updaters, instead of Mobject updaters. Why?

How does one use a CDSView with MultiLine on GMAPPlot?

(First Question so apologies)
Bokeh 1.3.4
Situation:
I am trying top map a Bokeh MultiLine using a CDSView and all the existing examples seem to use the "figure" object which has a helper (multi_line) which accepts a view as an argument. I am doing this on top of a GMAPPlot which does not support multi_line (only MultiLine) (see below). The commented out line throws an error saying GMAPPlot does not support multi_line.
plot = GMapPlot(
x_range=Range1d(), y_range=Range1d(), map_options=map_options, sizing_mode='scale_height'
)
.
.
.
sel_sa1s = []
v_bf = [True if sa1_val in sel_sa1s else False for sa1_val in v_source.data['SA1']]
v_view = CDSView(source=v_source, filters=[BooleanFilter(v_bf)])
v_ml = MultiLine(xs="xs",ys="ys",line_color="black", line_width="w")
#v_rend = plot.multi_line(xs="xs",ys="ys",line_color="black", line_width="w", source=v_source, view=v_view)
v_rend = plot.add_glyph(v_source, v_ml, name='votes')
The snippet shown above works and maps the entire network (very crowded) because there is no filter. What I want to have happen is for the filter to be initialised to hide everything then when the user clicks on an area (SA1) it will display the network related to that SA1.
Actually I can do that but only one area at a time and it would be much more efficient to be able to load the whole map and use a filtered view to control which sub-networks are displayed.
It seems that GMAPPlot only likes the pattern:
create glyph
add glyph
So, my question is - how does one use a CDSView in this environment (how does one add it to the renderer?)
Screenshot of unfiltered data set
It seems that GMAPPlot only likes the pattern:
create glyph
add glyph
That has not been true for some time. There is a higher level bokeh.plotting.gmap function that creates and configures GMapPlot instances with deafult axes, etc, and also has all the same methods and conveniences as figure (e.g. multi_line). It will be much less work to go this route than assembling everything by hand from low-level objects.

Google Maps API V3 slow adding Markers using data.addGeoJson

I am adding 325 features to 4 different maps (at different zoom levels) using map.data.addGeoJson(). Roughly half the features are markers and half are polygons. The Polygons render nearly instantaneously. But it takes another 6 full seconds for the markers to show up on the map.
If I only build one map, it still takes 0.5-2 seconds for the markers to show.
Is there anything I can do to speed things up?
Here is my code:
function addSites(map, geoJSON) {
map.data.setStyle(setSitesStyle);
map.data.addGeoJson(geoJSON)
}
function setSitesStyle(feature) {
var searchDist = getSearchDistFromListTypes(feature.getProperty('ListTypes').split('~'));
return ({
fillColor: searchDist.FontColor,
strokeColor: searchDist.FontColor,
strokeWeight: 1,
fillOpacity: .5,
clickable: false,
icon: {
url: 'images/' + searchDist.Marker + 's.png',
size: new google.maps.Size(26 , 38),
origin: new google.maps.Point(0, 0),
anchor: new google.maps.Point(13, 34),
label: feature.getProperty('MarkerNo')
}
});
}
Update: I tried using a simple SVG icon and the performance was no different.
The problem was the DOM was pretty darn big on this page and it took a while for Google Maps to add all of the elements to the DOM.
In my case the page was 95% Handlebars.js so what I did was compile all of the handlebars templates and remember the resulting HTML in an array. Then pushed just the map pages' HTML into the DOM and processed the map data (which was darn fast now.) And then finally loaded the rest of the HTML into the DOM which also was pretty quick.
Since multiple maps can be interspersed throughout the page it was a small challenge to figure out a simple and robust way to get it all woven back together correctly, but I am happy in the end.

Tile map isn’t loaded with some images

I made a tilemap. and used it on cocos2d-js.
Just added
this._map = new cc.TMXTiledMap(res.tilemap);
this.addChild(this._map, 0, 1);
in Layer.
But When I use this image,
http://i.imgur.com/f5VG0Nr.png,
http://i.imgur.com/Ugg9GNq.png
this error occured.
[.WebGLRenderingContext]RENDER WARNING: texture bound to texture
unit 0 is not renderable. It maybe non-power-of-2 and have incompatible
texture filtering or is not 'texture complete'
But When I used other image, it works.
like
http://i.imgur.com/Grv0srJ.png,
http://i.imgur.com/v1eWdkE.png,
http://i.imgur.com/BXKRbVx.png
I changed tilemap many times with that images, but same result.
I don't know what is diffrent that images.
Please help me.
Have you tried I believe I encountered this error once:
Have you tried adding all the image files in your resources.js file?

Multiple script/paperscripts in the same paperscope

I'm starting with paper.js. I like the fact that it introduces the possibility to have a script with a text/paperscript mime type, which runs in its on scope. However, scripts can become large pretty soon, so I want to be able to divide it in multiple scripts for readability. I thought I could just add more than one script tag and have them all run in the same scope, but apparently this isn't the case.
Both scripts are loaded and do run, but the second script doesn't seem to be in the paper scope.
I've set up an example here: http://barbata.nl/SO/Maps/ This example has some code, but I'll point out the important bits.
It contains two paperscripts:
Maps.js is the main script, which rasterizes the image and allows moving it around. You can ignore the code in this script, for it works fine so far.
Zoom.js is the script in which I wanted to isolate zooming functionality. It uses jq.mobi to capture the scroll wheel of the mouse, since Paper.js doesn't seem to have that event. It then translates that to a call to onMouseScroll, in a similar way Paper does it.
So far so good. The actual problem arises with the zoomIn and zoomOut functions in zoom.js.
It works if I explicity use the paper object to reference the view I want to zoom:
function zoomIn()
{
if (paper.view.zoom < 2)
{
paper.view.zoom = paper.view.zoom * 2;
}
}
But it fails when I remove paper and just reference the view:
function zoomIn()
{
if (view.zoom < 2)
{
view.zoom = view.zoom * 2;
}
}
This surprises me, as I expected the script to be a Paperscript, running in the Paperscope. It works fine if I put this code in Maps.js, so it seems that although zoom.js is loaded by Paper.js (the developer tools in the browser confirm this), it isn't run in the Paperscope.
My question is: are my findings correct? Am I doing something wrong? What is the right way to divide a Paper.js application into multiple units for readability?
Of course I can get it running, but I want to make sure I do it right.
This is indeed how it works. I've opened an issue on GitHub
I found that the "cleanest" way is to do it with this.install(window). It also makes error finding with Chrome developer tools easier since it is more adapted to reporting on the line errors in java-script than "paperscript".
in index.html (for example):
<script type="text/javascript" src='js/other_lib.js'></script>
<script type="text/paperscript" canvas="canvas">
this.install(window);
/*no code 'required' here */
</script>
<body>
<canvas id="canvas" width="1500" height="500"></canvas>
</body>
Then in the js/other_lib.js i just add code as normal:
var r = new Path.Rectangle([100,100],[200,200]);
r.fillColor = 'black';
/*more code here*/
This should generate a rectangle.
What DOES'T NOT WORK for me (as of Paper.js v0.10.2 Release Date: 9. July 2016) is the object operators. Such as adding vecrots pointc = pointa + pointb; for me this is giving a lot of NaN values.
I have had to edit a few libs to get this working, but the change is simple:
var pointc = new Point(pointa.x+pointb.x,pointa.y + pointb.y);

Resources