/*
x:画布宽度
y:画布宽度
columnNum:横向列数
rowNum:纵向行数
width:节点宽度
height:节点高度
padding:左右两侧的边距
labelName:各个节点的名称,注意行列转换
*/
function a (x,y,columnNum,rowNum,width,height,padding = 30,labelName = [[]]) {
let column = []
let row = []
let node = []
let dot = []
let attr = {
name:'',
value:'',
num:'',
rate:'',
symbol:'',
symbolSize:'',
itemStyle:{},
label:{}
}
let columnPadding = (x - padding*2 -width * columnNum)/(columnNum-1)
let rowPadding = (y - height * rowNum)/(rowNum-1)
for(let i = 0;i < columnNum;i ++){
column.push((width *( i + 0.5) + columnPadding * i + 30).toFixed(0))
}
for(let i = 0;i < rowNum;i ++){
row.push((height * ( i + 0.5 ) + rowPadding * i).toFixed(0))
}
//行
for(let i = 0;i < rowNum;i ++){
//列
for(let j = 0;j < columnNum;j ++){
if(labelName[j][i]!= ''){
node.push({
name:labelName[j][i],
value:[column[j],row[i]],
index: node.length,
num:0,
rate:0,
symbol:'rect',
symbolSize:[width,height],
itemStyle:{},
label:{},
leftDot:[column[j]- width/2,row[i]],
rightDot:[column[j]+ width/2,row[i]]
})
//第一列没有左侧连接点
if(j !=0 ){
dot.push({
name:dot.length + 1,
value:[column[j]- width/2 - columnPadding / 2,row[i]],
index: dot.length + 1,
symbolSize:0,
itemStyle:{},
label:{
show:false
},
})
dot.push({
name:dot.length + 1,
value:[column[j]- width/2,row[i]],
index: dot.length + 1,
symbolSize:0,
itemStyle:{},
label:{
show:false
},
})
}
//最后一列没有右侧连接点
if(j < (columnNum - 1)){
dot.push({
name:dot.length + 1,
value:[column[j]+ width/2,row[i]],
index: dot.length + 1,
symbolSize:0,
itemStyle:{},
label:{
show:false
},
})
}
}
}
}
console.log("列坐标",columnPadding,column)
console.log("行坐标",rowPadding,row)
console.log("各个坐标:",node[0].name)
console.log("各个点:",dot[0].name)
console.log("节点数目:",node.length)
console.log("连接点数目:",dot.length)
return node.concat(dot)
}
/*
第一级和最后一级都只有一个节点居中
x:画布宽度
y:画布宽度
columnNum:横向列数
rowNum:纵向行数
width:节点宽度
height:节点高度
padding:左右两侧的边距
labelName:各个节点的名称,注意行列转换
*/
function b (x,y,columnNum,rowNum,width,height,padding = 30,labelName = [[]]){
let column = []
let row = []
let node = []
let dot = []
let columnPadding = (x - padding*2 -width * columnNum)/(columnNum-1)
let rowPadding = (y - height * rowNum)/(rowNum-1)
for(let i = 0;i < columnNum;i ++){
column.push((width *( i + 0.5) + columnPadding * i + 30).toFixed(0))
}
for(let i = 0;i < rowNum;i ++){
row.push((height * ( i + 0.5 ) + rowPadding * i).toFixed(0))
}
// 第一列节点
node.push({
name:labelName[0][0],
value:[column[0],height / 2 ],
index: node.length,
num:0,
rate:0,
symbol:'rect',
symbolSize:[width,height],
itemStyle:{},
label:{},
leftDot:null,
rightDot:[column[0]+ width/2,height / 2]
})
// 最后一列节点
node.push({
name:labelName[columnNum-1][0],
value:[column[columnNum-1],height / 2],
index: node.length,
num:0,
rate:0,
symbol:'rect',
symbolSize:[width,height],
itemStyle:{},
label:{},
leftDot:[column[columnNum-1]- width/2,height / 2],
rightDot:null
})
//行
for(let i = 1;i < rowNum-1;i ++){
//列
for(let j = 1;j < columnNum-1;j ++){
if(labelName[j][i]!= ''){
node.push({
name:labelName[j][i],
value:[column[j],row[i]],
index: node.length,
num:0,
rate:0,
symbol:'rect',
symbolSize:[width,height],
itemStyle:{},
label:{},
leftDot:[column[j]- width/2,row[i]],
rightDot:[column[j]+ width/2,row[i]]
})
//第一列没有左侧连接点
if(j !=0 ){
//中间点
dot.push({
name:dot.length + 1,
value:[column[j]- width/2 - columnPadding / 2,row[i]],
index: dot.length + 1,
symbolSize:0,
itemStyle:{},
label:{
show:false
},
})
//左侧点
dot.push({
name:dot.length + 1,
value:[column[j]- width/2,row[i]],
index: dot.length + 1,
symbolSize:0,
itemStyle:{},
label:{
show:false
},
})
}
//最后一列没有右侧连接点
if(j < (columnNum - 1)){
//右侧点
dot.push({
name:dot.length + 1,
value:[column[j]+ width/2,row[i]],
index: dot.length + 1,
symbolSize:0,
itemStyle:{},
label:{
show:false
},
})
}
}
}
}
console.log("列坐标",columnPadding,column)
console.log("行坐标",rowPadding,row)
console.log("各个坐标:",node[0].name)
console.log("各个点:",dot[0].name)
console.log("节点数目:",node.length)
console.log("连接点数目:",dot.length)
return node.concat(dot)
}
function links(arr=[]){
let link = []
}
let name = [
['中央资金','','',''],
['省级下达本级','省级下达下级','省级未分配',''],
['','','',''],
['','','',''],
['','','',''],
['','','',''],
['','','',''],
['','','','']
]
let name2 = [
['中央资金'],
['省级下达本级','省级下达下级','省级未分配',''],
['','','',''],
['','','',''],
['','','',''],
['','','',''],
['','','',''],
['支付金额']
]
// let node = a(1920,330,8,4,185,65,30,name)
let node2 = b(1920,330,8,4,185,65,30,name2)
// console.log('节点数目',node.length)
console