Comments (4)
By the way, is it possible to use the argument scaling.customScalingFunction
?
I tried a python function, but I get an error saying it is not JSON serializable. If I try to give it a string representation of a python or javascript function I get no error, but it doesn't work either.
from pyvis.
Hey @cdanielmachado
So that odd behavior seems to be a result of the default scaling method that the javascript layer is using.
I'll have to play around with the customScalingFunction, since natively it is meant to be a JS function interpreted by VisJS's API. So the python binding would have to be hooked to that in a way.
One thing that can be done is to write your own custom scaling function in javascript and put that in the template thats used to generate the final visual. Of course you would need to reference the VisJS API to see what that looks like.
From their docs at http://visjs.org/docs/network/edges.html:
If edges have value fields, this function determines how the size of the nodes are scaled based on their values. The default function is:
function(min,max,total,value) {
if (max === min) {`
return` 0.5;
}
else {
var scale = 1 / (max - min);
return Math.max(0,(value - min)*scale);
}
}
The function receives the minimum value of the set, the maximum value, the total sum of all values and finally the value of the node or edge it works on. It has to return a value between 0 and 1. The nodes and edges then calculate their size as follows:
var scale = customScalingFunction(min,max,total,value);
var diff = maxWidth - minWidth;
myWidth = minWidth + diff * scale;
Please note: maxWidth and minWidth are the values scaling.max and scaling.min provided in the options.
You might also want to see if you could use the width
argument instead of value, then you can integrate that with your own scaling function?
from pyvis.
Good point, I will try width
instead of value
and let you know how it goes.
from pyvis.
Using width
instead of value
does produce the expected behaviour. I suppose that with width
it uses the given units directly has they are, whereas with value
it applies the scaling function. So no need to define a customized scaling function if we just use the width
parameter directly. 👍
from pyvis.
Related Issues (20)
- AttributeError: 'NoneType' object has no attribute 'render' HOT 4
- How do you change the fonts of the labels on the nodes?
- Be able to set the color of an edge independently of the source node
- Left to Right Orientation?
- Interactive Node in in Output HOT 1
- Use palette to color nodes and add colorbar
- Edge titles does not work? HOT 6
- Pyvis HTML Output does not use 100% of the page HOT 2
- Save as json
- Problem with labels, trying integration with pandas, Latex and Networkx
- No display of node labels if node is numeric HOT 1
- Change node size when label is inside
- Numeric string node ID silently cast from `str` to `int` in in `add_nodes` but not `add_edges`, raises `AssertionError`
- `write_html` opens browser to relative rather than absolute path, doesn't handle absolute paths as name
- Network not handling objects: assert isinstance(n_id, str) or isinstance(n_id, int) HOT 1
- Customizing Filter Menu Attribute Names in pyvis
- Loading Bar Toggle
- ModuleNotFoundError: No module named 'pyvis.network'; 'pyvis' is not a package
- pyvis node labels don't appear sometimes
- Applying physics to individual edges or applying different physics to each edge
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 pyvis.