<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<meta charset="utf-8">
<title>d3+jQuery股权穿透图</title>
<script src="https://cdn.bootcss.com/d3/3.2.7/d3.min.js"></script>
<script src="jquery-3.3.1.min.js"></script>
</head>
<body>
<div class="container" id="treecontainer">
<div class="menu">
<div id="product_tree"></div>
</div>
</body>
<script type="text/javascript">
var container;
var zoom;
var rootData;
var depthInfo;
var rootName;//根节点名称
jQuery(document).ready(function () {
/* resizeScreen();*/
//selectChange();
var child=document.getElementById("product_tree");
child.innerHTML = '';
getData();
});
var getData =function() {
// 测试内容
rootData = {
"downward": {
"direction": "downward",
"name": "origin",
"children": [
{
"name": "上海冰鉴企业征信服务有限公司",
"amount": "50",
"ratio": "55%",
"hasHumanholding":true,
"hasChildren":true,
"isExpand": false,
"children": [
{
"name": "公司名字",
"hasHumanholding":false,
"hasChildren":true,
"amount": "100",
"ratio": "55%",
"children": []
},
{
"name": "公司名字",
"hasHumanholding":false,
"hasChildren":true,
"amount": "100",
"ratio": "55%",
"children": []
}
]
},
{
"name": "上海冰鉴企业征信服务有限公司11",
"amount": "100",
"ratio": "55%",
"hasHumanholding":true,
"hasChildren":true,
"isExpand": false,
"children": [
{
"name": "公司名字",
"hasHumanholding":false,
"hasChildren":true,
"amount": "100",
"ratio": "55%",
"children": []
},
{
"name": "公司名字",
"hasHumanholding":false,
"hasChildren":true,
"amount": "100",
"ratio": "55%",
"children": []
}
]
},
{
"name": "北京冰鉴企业征信服务有限公司",
"amount": "100",
"ratio": "55%",
"hasHumanholding":true,
"hasChildren":true,
"isExpand": false,
"children": [
{
"name": "公司名字",
"hasHumanholding":false,
"hasChildren":true,
"amount": "100",
"ratio": "55%",
"children": []
},
{
"name": "公司名字",
"hasHumanholding":false,
"hasChildren":true,
"amount": "100",
"ratio": "55%",
"children": []
}
]
},
{
"name": "成都量化金服大数据技术服务有限公司",
"hasHumanholding":false,
"hasChildren":true,
"amount": "100",
"ratio": "55%",
"children": []
},
{
"name": "南京冰鉴信息科技有限公司",
"hasHumanholding":false,
"hasChildren":true,
"isExpand": false,
"amount": "100",
"ratio": "55%",
"children": [
{
"name": "公司或股东名字",
"hasHumanholding":false,
"amount": "100",
"ratio": "55%",
"children": []
},
{
"name": "公司或股东名字",
"hasHumanholding":false,
"amount": "100",
"ratio": "55%",
"children": []
},
{
"name": "公司或股东名字",
"hasHumanholding":false,
"amount": "100",
"ratio": "55%",
"children": []
},
{
"name": "公司或股东名字",
"hasHumanholding":false,
"amount": "100",
"ratio": "55%",
"children": []
}
]
}
]
},
"upward": {
"direction": "upward",
"name": "origin",
"children": [
{
"name": "投资方",
"hasHumanholding":false,
"amount": "100",
"ratio": "55%",
"children": [
{
"name": "公司或股东名字",
"hasHumanholding":false,
"amount": "100",
"ratio": "55%",
"children": []
},
{
"name": "公司或股东名字",
"hasHumanholding":false,
"isExpand": false,
"amount": "100",
"ratio": "55%",
"children": [
{
"name": "公司或股东名字",
"hasHumanholding":false,
"amount": "100",
"ratio": "55%",
"children": []
},
{
"name": "公司或股东名字",
"hasHumanholding":false,
"amount": "100",
"ratio": "55%",
"children": []
}
]
},
{
"name": "公司或股东名字",
"hasHumanholding":false,
"amount": "100",
"ratio": "55%",
"children": []
}
]
}
]
}
}
rootName = '我是根节点';
drawing();
};
var drawing = function() {
var _this = this;
// var rootName = ''; //根节点的名字
var rootRectWidth = 0; //根节点rect的宽度
var downwardLength = 0,
upwardLength = 0;
var forUpward = true
var treeChart = function(d3Object) {
this.d3 = d3Object;
this.directions = ['upward', 'downward'];
};
treeChart.pr