v8: 节点显示股权比例标签 + 点击企业放大显示整条线路
This commit is contained in:
+50
-5
@@ -135,8 +135,20 @@ var baseOption = {
|
|||||||
top:'4%', bottom:'4%', left:'2%', right:'2%',
|
top:'4%', bottom:'4%', left:'2%', right:'2%',
|
||||||
symbol:'circle', symbolSize:7,
|
symbol:'circle', symbolSize:7,
|
||||||
initialTreeDepth:1, expandAndCollapse:true, roam:true,
|
initialTreeDepth:1, expandAndCollapse:true, roam:true,
|
||||||
label:{ position:'bottom', fontSize:11, color:'#333', formatter:'{b}', distance:4 },
|
label:{ position:'bottom', fontSize:11, color:'#333',
|
||||||
leaves:{ label:{ position:'bottom', fontSize:11, color:'#333' } },
|
formatter:function(p){
|
||||||
|
var nm = p.data ? p.data.name : '';
|
||||||
|
var rt = p.data && p.data.ratio;
|
||||||
|
if (rt != null && rt > 0) return nm + ' (' + Math.round(rt*100) + '%)';
|
||||||
|
return nm;
|
||||||
|
}, distance:4 },
|
||||||
|
leaves:{ label:{ position:'bottom', fontSize:11, color:'#333',
|
||||||
|
formatter:function(p){
|
||||||
|
var nm = p.data ? p.data.name : '';
|
||||||
|
var rt = p.data && p.data.ratio;
|
||||||
|
if (rt != null && rt > 0) return nm + ' (' + Math.round(rt*100) + '%)';
|
||||||
|
return nm;
|
||||||
|
} } },
|
||||||
emphasis:{ focus:'descendant' },
|
emphasis:{ focus:'descendant' },
|
||||||
edgeShape:'polyline',
|
edgeShape:'polyline',
|
||||||
lineStyle:{ color:'#999', width:1.2, curveness:0 },
|
lineStyle:{ color:'#999', width:1.2, curveness:0 },
|
||||||
@@ -157,7 +169,19 @@ function setZoom(z) {
|
|||||||
}
|
}
|
||||||
document.getElementById('btnZoomIn').onclick = function(){ setZoom(zoom * 1.25); };
|
document.getElementById('btnZoomIn').onclick = function(){ setZoom(zoom * 1.25); };
|
||||||
document.getElementById('btnZoomOut').onclick = function(){ setZoom(zoom / 1.25); };
|
document.getElementById('btnZoomOut').onclick = function(){ setZoom(zoom / 1.25); };
|
||||||
document.getElementById('btnReset').onclick = function(){ zoom = 1.0; applySize(); showTip('已重置视图'); };
|
document.getElementById('btnReset').onclick = function(){
|
||||||
|
zoom = 1.0;
|
||||||
|
chart.setOption({ series:[{ data: [rootNode], initialTreeDepth:1,
|
||||||
|
label:{ position:'bottom', fontSize:11, color:'#333',
|
||||||
|
formatter:function(p){
|
||||||
|
var nm = p.data ? p.data.name : '';
|
||||||
|
var rt = p.data && p.data.ratio;
|
||||||
|
if (rt != null && rt > 0) return nm + ' (' + Math.round(rt*100) + '%)';
|
||||||
|
return nm;
|
||||||
|
}, distance:4 } }] });
|
||||||
|
applySize();
|
||||||
|
showTip('已重置视图');
|
||||||
|
};
|
||||||
|
|
||||||
function collectParents(n, arr) {
|
function collectParents(n, arr) {
|
||||||
if (n.children && n.children.length) { arr.push(n.name); n.children.forEach(function(c){ collectParents(c, arr); }); }
|
if (n.children && n.children.length) { arr.push(n.name); n.children.forEach(function(c){ collectParents(c, arr); }); }
|
||||||
@@ -263,9 +287,30 @@ clearBtn.onclick = function(){
|
|||||||
chart.setOption({ series:[{ data: [rootNode], initialTreeDepth:1, label:{formatter:'{b}', rich:{}} }] });
|
chart.setOption({ series:[{ data: [rootNode], initialTreeDepth:1, label:{formatter:'{b}', rich:{}} }] });
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// 点击节点 → 放大显示整条股权路径(剪枝 + 自动 fit)
|
||||||
chart.on('click', function(p){
|
chart.on('click', function(p){
|
||||||
if (p.data && p.data.children && p.data.children.length) {
|
if (!p.data || !p.data.name) return;
|
||||||
showTip('「'+p.data.name+'」共 ' + p.data.children.length + ' 家子公司');
|
var nm = p.data.name;
|
||||||
|
var path = findPath(nm, rootNode, []);
|
||||||
|
if (path && path.length) {
|
||||||
|
var pruned = prunePath(nm);
|
||||||
|
if (pruned) {
|
||||||
|
chart.setOption({
|
||||||
|
series: [{
|
||||||
|
data: pruned,
|
||||||
|
initialTreeDepth: 99,
|
||||||
|
label: {
|
||||||
|
formatter: function(p2){
|
||||||
|
var n2 = p2.data ? p2.data.name : '';
|
||||||
|
var rt = p2.data && p2.data.ratio;
|
||||||
|
if (rt != null && rt > 0) return n2 + ' (' + Math.round(rt*100) + '%)';
|
||||||
|
return n2;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}]
|
||||||
|
});
|
||||||
|
showTip('已放大显示「'+nm+'」的完整股权线路,点击🔄重置或搜索框清除返回全貌');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
</script>
|
</script>
|
||||||
|
|||||||
Reference in New Issue
Block a user