Comments (8)
Ah, I see! Sounds reasonable. Also, I suggest once this is implemented and tests run smoothly we bump the whole thing up to v0.1
from netwulf.
Actually, the problem is in the else
, where, if nodes have x
and y
properties but the graph has no xlim
and ylim
properties, node-positions are recomputed such as to use the entire canvas space available. It's nice if someone gives their node position in obscure coordinate ranges (like GPS coordinates, grid positions in nanometers, etc). I think the proper way to fix this is:
- In
bind_positions_to_network
, addxlim
andylim
attributes to theG.graph
object (graph
is a dictionary attribute that annx.Graph
has dedicated for storing graph attributes) such that, innetwulf.visualize
,nx.node_link_data(G)
produces a dictionary that has an entry'graph': {'xlim': [lowerx, upperx], 'ymin': [lowery, uppery]}
, then - In the vis.js every lookup in
graph
ormasterGraph
forxlim
andylim
get changed fromgraph['xlim']
to `graph['graph']['xlim'].
I'll try this and report back.
from netwulf.
Changes to netwulf
(a305733):
- In
tools.py
:bind_positions_to_network
->bind_properties_to_network
. The updated function defaults to binding all properties to thenx.Graph
object, but has an argument for untoggling binding for each property.xlim
andylim
are now stored in theG.graph
dict. - In
interactive.py
: I made a small update so the dictionary resulting fromnx.node_link_data(G)
is flattened, before it is saved. Thus, it ends up almost identical to theposted_network_properties
thatvisualize
returns.
There's still a problem then config['zoom']
is changed. This needs to be fixed in https://github.com/ulfaslak/network_styling_with_d3.
from netwulf.
Alright, I thought about this a bit now. From a user's perspective it makes sense that setting config['zoom']
should be equivalent to pulling the slider... But it gets a little complicated due to the way zoom is implemented in the visualization. Nodes have d3 simulation coordinates, but using the zoomScaler
nodes are rendered elsewhere. For example, a node with coordinates x, y
is rendered is in zoomScaler(x), zoomScaler(y)
. So the zoomScaler
is basically a (two-way) may between simulation coordinates and canvas coordinates (and vice versa). Now, when we return the node coordinates to Python, it is the canvas coordinates we return, simply because it simplifies re-rendering the graph in Matplotlib. This is all fine. The problem, however, is when we overwrite config['zoom']
the program suddenly no longer knows what the simulation coordinates were. Even worse, as-is it will assume that the simulation coordinates are those obtained with a zoomScaler
initiated with a different config['zoom']
value.
So if we e.g. lower config['zoom']
from 1.5 to 0.66, it's like saying "actually these canvas coordinates are contracted compared to the simulation coordinates". So the simulation coordinates are now different (more spread out), and the rendered network is contracted 0.66 in relation to that. Effectively, the nodes are going to appear to be in the same position on the canvas, only with smaller node sizes.
A way to enable the "user-intuitive" behavior would be to:
- Return to Python, not the canvas coordinates, but the simulation coordinates
- Change the
draw_netwulf
function so it also takes theconfig
as input and then uses config['zoom'] to put the nodes in the "canvas positions".
Alternatively, we return to Python the simulation node-positions in the original 'x' and 'y' keys and then add extra keys called 'x_canvas', and 'y_canvas', that only matplotlib uses.
from netwulf.
Btw, no need to wrap your head around all of that, I mostly wrote it out to understand it myself. I'll go for the alternative solution. For reproduction, it's much more elegant that we return the simulation coordinates.
from netwulf.
Now you can try this:
from netwulf.tools import bind_properties_to_network
from netwulf import visualize
import networkx as nx
G = nx.Graph()
G.add_nodes_from(range(10))
G.add_nodes_from("abcde")
G.add_edges_from([("a","b")])
props, config = visualize(G)
config['zoom'] = 0.666
bind_properties_to_network(G, props)
visualize(G, config=config)
from netwulf.
works flawlessly now, thanks!
from netwulf.
even though config['zoom'] = 0.666
is not necessary anymore now
from netwulf.
Related Issues (20)
- label position examples are deprecated in the docs
- visualization with initially given positions is unfrozen when node properties are changed
- When nodes are dragged, labels stay on for that node HOT 6
- Getting Dataset does not have a key 'nodes' HOT 3
- Highlight connected nodes and edges HOT 2
- Problem with node attributes (specifically `bipartite') HOT 12
- Colouring nodes by property (e.g., degree) HOT 2
- Is netwulf available in anaconda? HOT 2
- ntwulf.visualize does not accept network as a dict HOT 5
- Netwulf changes the current working directory HOT 1
- Visualizing in google collab HOT 1
- Can't post visualization back to python HOT 2
- netwulf visualize ignores edge colors HOT 4
- Adding changes in CHANGELOG.md HOT 3
- is netwulf supports directed networkx ? HOT 4
- how to make .exe in Windows with pyinstaller and netwulf included [SOLVED] HOT 1
- some questions HOT 1
- Show edge labels
- nodes disappear when clicking on the nodes on a touchscreen HOT 2
- Canvas size ,self-loops ,large graphs? HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from netwulf.