v8: 节点显示股权比例标签 + 点击企业放大显示整条线路

This commit is contained in:
2026-08-06 17:22:43 +08:00
parent 87a3aa4f06
commit 6e8dd48d4c
+50 -5
View File
@@ -135,8 +135,20 @@ var baseOption = {
top:'4%', bottom:'4%', left:'2%', right:'2%',
symbol:'circle', symbolSize:7,
initialTreeDepth:1, expandAndCollapse:true, roam:true,
label:{ position:'bottom', fontSize:11, color:'#333', formatter:'{b}', distance:4 },
leaves:{ label:{ position:'bottom', fontSize:11, color:'#333' } },
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' },
edgeShape:'polyline',
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('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) {
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:{}} }] });
};
// 点击节点 → 放大显示整条股权路径(剪枝 + 自动 fit)
chart.on('click', function(p){
if (p.data && p.data.children && p.data.children.length) {
showTip('「'+p.data.name+'」共 ' + p.data.children.length + ' 家子公司');
if (!p.data || !p.data.name) return;
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>