在vis.network中,是否可以将节点设置为重心?

问题描述

我正在使用vis.js来显示网络图。 拖动节点后,我需要保持“边缘长度”,因此我使用了物理选项。 我的问题是,拖动的节点始终会弹回到其原始位置,这是因为这些选项。

physics: {
    forceAtlas2Based: {
          gravitationalConstant: -150,centralGravity: 0.005,springLength: 180,springConstant: 0.18,},maxVeLocity: 146,solver: "forceAtlas2Based",timestep: 0.35,stabilization: {
            enabled: true,iterations: 1000,updateInterval: 25
    }
}

所以我现在在想的是,是否有一种方法,可以将“中心”更改为被拖动的节点,以便物理重心围绕它旋转?

有没有一种方法可以使网络恢复稳定,而不会使拖动的节点弹回其初始位置?

解决方法

当前无法将所选节点设置为重心。但是您可以在某些事件(例如class Renderer::Post def self.create_doc_xml(root) doc = LibXML::XML::Document.new doc.encoding = LibXML::XML::Encoding::UTF_8 doc.root = LibXML::XML::Node.new(root) doc end def self.create_node(name,value=nil,type=nil) node = LibXML::XML::Node.new(name) node.content = value.to_s unless value.nil? LibXML::XML::Attr.new(node,'type',type) unless type.nil? node end def self.xml(post) doc = create_doc_xml('post') doc.root << create_node('content',post.content.to_s) doc.root << create_node('created-at',post.created_at.iso8601,'dateTime') doc.root << create_node('published',post.published.to_s,'boolean') # author doc.root << (author = create_node('author')) author << create_node('name',post.author.name.to_s) author << create_node('age',post.author.age.to_s,'integer') author << create_node('email',post.author.email.to_s) # comments doc.root << (comments = create_node('comments',nil,'array')) post.comments.each do |comment| comments << (node_comment = create_node('comment')) node_comment << create_node('created-at',comment.created_at.iso8601,'dateTime') node_comment << create_node('message',comment.message) # user node_comment << (user = create_node('user')) user << create_node('name',comment.user.name.to_s) user << create_node('age',comment.user.age.to_s,'integer') user << create_node('email',comment.user.email.to_s) node_comment << create_node('attachment',comment.attachment) end doc.to_s end end mass上更改它们的参数,例如dragStart

dragEnd

您还可以运行network.on("dragStart",function(e){ const id = network.getNode(e.nodes[0]).id nodes.update([ { id,mass: 5 } ]) }) network.stopSimulation()停止物理模拟。