GithubHelp home page GithubHelp logo

Comments (4)

cdanielmachado avatar cdanielmachado commented on July 26, 2024

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.

boludo00 avatar boludo00 commented on July 26, 2024

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.

cdanielmachado avatar cdanielmachado commented on July 26, 2024

Good point, I will try width instead of value and let you know how it goes.

from pyvis.

cdanielmachado avatar cdanielmachado commented on July 26, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.