简体   繁体   English

PyVis Graph 显示一些节点颜色为绿色,一些节点颜色为黄色,即使这些节点被指定为绿色

[英]PyVis Graph shows some nodes colour as green and some as yellow even though the nodes are assigned with colour green

I have generated a PyVis graph but the graph output has just one problem and seems i can't find the reason and lost to no ideas anymore, i am not sure if it is a bug in PyVis drawing or I have made an error in generating the graph.我已经生成了一个 PyVis 图表,但是图表 output 只有一个问题,似乎我找不到原因并且失去了任何想法,我不确定这是 PyVis 绘图中的错误还是我在生成时出错了图表。 Please advise, i am keen to know the cause here.请告知,我很想知道这里的原因。

The PyVis graph I have generated contains 196 nodes and 367 edges exactly.我生成的 PyVis 图正好包含 196 个节点和 367 条边。 Of those 196 nodes, certain group of nodes are assigned with specific colours.在这 196 个节点中,某些节点组被分配了特定的颜色。 About 42 nodes are assigned with colour "green" (using hex colour code #00ff00) and their shape has been changed to be a Square here for easy visual in an attempt to show my problem.大约 42 个节点被分配了颜色“绿色”(使用十六进制颜色代码 #00ff00),并且它们的形状已更改为此处的正方形,以便于视觉显示我的问题。 Of those 42 nodes, 13 of them are not showing green but instead show yellow as their colour, even though the source code still have those nodes colour as green (in hex code), however the visual shows yellow.在这 42 个节点中,其中 13 个没有显示绿色,而是显示黄色作为它们的颜色,即使源代码仍然将这些节点颜色为绿色(在十六进制代码中),但是视觉显示为黄色。

Below one line code is me trying to point to the source code line of one node and its color is set to #00ff00.下面一行代码是我试图指向一个节点的源代码行,它的颜色设置为#00ff00。

{"color": "#00ff00", "font": {"color": "white", "face": "Verdana", "size": 90}, "group": "gp_b", "id": "node__120", "label": "node__120", "level": 3, "shape": "square", "size": 500} ,

The graph's full html code example is provided here linked to jsfiddle, please see if you can help me locate the problem and a fix.此处提供了该图的完整 html 代码示例,链接到 jsfiddle,请查看您是否可以帮助我找到问题并进行修复。 Thanks in advance.提前致谢。

https://jsfiddle.net/shashi12345/2pf781ba/1/ https://jsfiddle.net/shashi12345/2pf781ba/1/

Additional info:-附加信息:-

Basically, the graph is first created using Python.基本上,图表首先使用 Python 创建。 I used NetworkX version 2.8.5, added nodes and edges and their attributes, and then imported that into PyVis all within Python.我使用了 NetworkX 版本 2.8.5,添加了节点和边及其属性,然后将其导入到 PyVis 中,所有这些都在 Python 中。 PyVis version i am using is 0.2.1.我使用的 PyVis 版本是 0.2.1。 And the graph is generated/saved as html file from PyVis.并且该图从 PyVis 生成/保存为 html 文件。

The vis.js vis-network library requires groups to be defined in the options as descibred in the documentation here . vis.js vis-network 库要求在 此处的文档中描述的选项中定义组。 All square nodes are added to a group named gp_b however this isn't present in the vis-network options.所有方形节点都被添加到一个名为gp_b的组中,但是这在 vis-network 选项中不存在。 It is odd that this results in the behaviour being seen, but it could be resolved in a number of ways described below.奇怪的是,这会导致行为被看到,但它可以通过以下描述的多种方式解决。

As per the PyVis documentation here the options passed to vis.js can be configured which as is needed for some options below.根据此处的 PyVis 文档,可以配置传递给 vis.js 的选项,这是以下某些选项所需要的。

Adding Group to Options将组添加到选项

Adding the group gp_b to the options without any styling defined fixes the issue, for example:将组gp_b添加到未定义任何样式的选项可解决此问题,例如:

var options = {
  groups:{
    useDefaultGroups: true,
    gp_b:{ }
  },
  // Other options
}

Adding Group to Options With Styles使用 Styles 将组添加到选项

Alternatively the styling could be removed from the nodes and instead placed on the group, for example:或者,样式可以从节点中删除,而是放在组上,例如:

var options = {
  groups:{
    useDefaultGroups: true,
    gp_b:{
      color: '#00ff00'
    }
  },
  // Other options
}

Removing Group from Nodes从节点中删除组

The group could also be removed from the nodes, this way they are not expecing style information from the group and will just the color they have defined.该组也可以从节点中删除,这样它们就不会从组中获取样式信息,而只会使用它们定义的颜色。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM