javascript - Set default scale in vis js network - Stack Overflow

I am using vis.js library to create a network topology. After I create the network using:network = new

I am using vis.js library to create a network topology. After I create the network using:

network = new vis.Network(container, data, options);

where container is the canvas on which I am drawing.

data :

{
    nodes: Nodes,
    edges: Edges
};

options :

{ 
    autoResize: true,
    nodes: {
        shape: 'image',
        size:  25,
        font: {
            size: 16,
            color: 'darkbrown'
        },
        borderWidth: 0,
        shadow: true
    },
    edges: {
        smooth: {
            forceDirection: "none"
        }
    },
    physics: {
        forceAtlas2Based: {
            springLength: 80,
            springConstant: 0.27
        },
        minVelocity: 0.75,
        solver: "forceAtlas2Based",
        timestep: 0.34
    },
    layout: {
        randomSeed: undefined
    },
    interaction: {
        hover: true
    }
}

After it is drawn the default scale(1) is very large with respect to my canvas. I want to resize the scale. I have tried this way :

network = new vis.Network(container, data, options); //network is drawn

var scaleOption = { scale : 0.5 }; -(1) 

network.moveTo(scaleOption); -(2)

It doesn't work this way. However, if (1) and (2) are fired inside a particular event say :

network.on("click",function(params) {

    var scaleOption = { scale : 0.5 };
    network.moveTo(scaleOption);
}); 

It works. I need to set the scale right at the beginning, i.e. right after topology is drawn(before the occurence of any such event). AfterDrawing event is continuously fired after the topology is drawn, so that fails too. Any way to resolve this?

I am using vis.js library to create a network topology. After I create the network using:

network = new vis.Network(container, data, options);

where container is the canvas on which I am drawing.

data :

{
    nodes: Nodes,
    edges: Edges
};

options :

{ 
    autoResize: true,
    nodes: {
        shape: 'image',
        size:  25,
        font: {
            size: 16,
            color: 'darkbrown'
        },
        borderWidth: 0,
        shadow: true
    },
    edges: {
        smooth: {
            forceDirection: "none"
        }
    },
    physics: {
        forceAtlas2Based: {
            springLength: 80,
            springConstant: 0.27
        },
        minVelocity: 0.75,
        solver: "forceAtlas2Based",
        timestep: 0.34
    },
    layout: {
        randomSeed: undefined
    },
    interaction: {
        hover: true
    }
}

After it is drawn the default scale(1) is very large with respect to my canvas. I want to resize the scale. I have tried this way :

network = new vis.Network(container, data, options); //network is drawn

var scaleOption = { scale : 0.5 }; -(1) 

network.moveTo(scaleOption); -(2)

It doesn't work this way. However, if (1) and (2) are fired inside a particular event say :

network.on("click",function(params) {

    var scaleOption = { scale : 0.5 };
    network.moveTo(scaleOption);
}); 

It works. I need to set the scale right at the beginning, i.e. right after topology is drawn(before the occurence of any such event). AfterDrawing event is continuously fired after the topology is drawn, so that fails too. Any way to resolve this?

Share Improve this question edited Feb 16, 2018 at 10:00 YakovL 8,37513 gold badges73 silver badges113 bronze badges asked Mar 21, 2017 at 7:24 Prasita MukherjeePrasita Mukherjee 1012 silver badges9 bronze badges 0
Add a ment  | 

1 Answer 1

Reset to default 7

Use stabilized event and once method to scale down your network for the first time it is drawn.

network.once('stabilized', function() {
    var scaleOption = { scale : 0.5 };
    network.moveTo(scaleOption);
})

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1742396812a4436114.html

相关推荐

  • javascript - Set default scale in vis js network - Stack Overflow

    I am using vis.js library to create a network topology. After I create the network using:network = new

    18小时前
    20

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信