python网络构建,如何使用python构建交互式网络

I want to build an interactive network on the lines of :-

Class, Subclass, Company, Product,

Chocolate, Wafer chocolate, Nestle, KitKat,

Chocolate, White chocolate, Nestle, Milkybar,

Chocolate, White chocolate, Nestle, Milkybar,

Chocolate, Caramel chocolate, Nestle, BarOne,

Chocolate, Milk chocolate, Nestle, Nestle Milk chocolate,

Chocolate, Milk chocolate, Nestle, Nestle Milk chocolate,

Chocolate, Milk chocolate, Nestle, Nestle Milk chocolate,

Chocolate, Milk chocolate, Nestle, Nestle Milk chocolate,

Chocolate, Milk chocolate, Cadbury, Dairy milk,

The Parent node would be "Chocolate" and further children would be :-

Chocolate--> Subclass-->Company--->Product. (each of these should be click-expand-collapse)

The size of each node should depend on number of children.

Moreover if you click on a node it should expand/collapse to show its children nodes.

Is there any way I could do this in python. I looked at d3 but its way too complicated to understand. Is there an easier pythonic way to do this in a web-browser interactively ?

解决方案

You can use d3.js to do that. There is a good example to check. You can also use collapse Tree in case you don't wanna use a graph.

Using the script in the tutorial, your example should work like this. If you are not looking to use collaspe/expand structure. You can use d3.js to build a graph, and it would look like this.

root = {

"name": "Chocolate", "tag":"class",

"children": [

{

"name": "Wafer", "tag":"subclass",

"children": [

{

"name": "Nestle", "tag":"company",

"children": [

{"name": "KitKat", "tag":"product"}

]

}

]

},

{

"name": "White", "tag":"subclass",

"children": [

{

"name": "Nestle", "tag":"company",

"children": [

{"name": "Milkybar", "tag":"product"}

]

}

]

},

{

"name": "Caramel", "tag":"subclass",

"children": [

{

"name": "Nestle", "tag":"company",

"children": [

{"name": "BarOne", "tag":"product"}

]

}

]

},

{

"name": "Milk", "tag":"subclass",

"children": [

{

"name": "Nestle", "tag":"company",

"children": [

{"name": "Nestle Milk", "tag":"product"}

]

}, {

"name": "Cadbury", "tag":"company",

"children": [

{"name": "Dairy Milk", "tag":"product"}

]

}

]

}

]

};

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值