端到端功能 连线处理相关代码提交
This commit is contained in:
parent
f99c09f33f
commit
1506bf1270
Binary file not shown.
@ -94,9 +94,10 @@ public class GraphLayout {
|
||||
}
|
||||
|
||||
/**
|
||||
* 横向分布
|
||||
* 节点布局
|
||||
*/
|
||||
public double[][] layOut(){
|
||||
public double[][] horizLayOut(){
|
||||
double realTimeY = 0.0; // 实时记录图形最高的Y
|
||||
for (int i = 0; i < nodeList.size(); i++) {
|
||||
// 第一个节点直接放到画布的左上角
|
||||
@ -137,6 +138,7 @@ public class GraphLayout {
|
||||
}
|
||||
|
||||
/**
|
||||
* 横向分布
|
||||
* 计算当前节点所有后置节点的位置
|
||||
* @param nodeIndex
|
||||
*/
|
||||
@ -163,6 +165,73 @@ public class GraphLayout {
|
||||
return realTimeY;
|
||||
}
|
||||
|
||||
/**
|
||||
* 纵向分布
|
||||
* 节点布局
|
||||
* @return 节点坐标
|
||||
*/
|
||||
public double[][] vertLayOut(){
|
||||
double realTimeX = 0.0; // 实时记录图形最高的Y
|
||||
for (int i = 0; i < nodeList.size(); i++) {
|
||||
// 第一个节点直接放到画布的左上角
|
||||
if (i == 0) {
|
||||
position[i][0] = 100.0;
|
||||
position[i][1] = 100.0;
|
||||
realTimeX = 100.0;
|
||||
isPosition[i] = true;
|
||||
if (existOutLink(i)){ // 如果存在后置节点 并且后置节点还未渲染
|
||||
realTimeX = calculationRearNodePoiInVertLayOut(i, realTimeX);
|
||||
}
|
||||
continue;
|
||||
}
|
||||
if (!isPosition[i]){
|
||||
position[i][0] = realTimeX + shapeW + horizInterval;
|
||||
position[i][1] = 100.0;
|
||||
realTimeX = position[i][0];
|
||||
if (existOutLink(i)){
|
||||
realTimeX = calculationRearNodePoiInVertLayOut(i, realTimeX);
|
||||
}
|
||||
}
|
||||
}
|
||||
// 确定画布的宽度与高度
|
||||
double w = Arrays.stream(position).mapToDouble(position -> position[0]).max().orElse(0.0);
|
||||
double h = Arrays.stream(position).mapToDouble(position -> position[1]).max().orElse(0.0);
|
||||
|
||||
this.canvasWidth = w + 200.0;
|
||||
this.canvasHeight = h + 200.0;
|
||||
|
||||
// 打印节点坐标与画布大小
|
||||
System.out.printf("画布(%.2f, %.2f)", canvasWidth, canvasHeight);
|
||||
for (int i = 0; i < position.length; i++) {
|
||||
System.out.printf("坐标(%.2f, %.2f)", position[i][0], position[i][1]);
|
||||
}
|
||||
|
||||
return position;
|
||||
}
|
||||
|
||||
private double calculationRearNodePoiInVertLayOut(int nodeIndex, double realTimeX){
|
||||
// 获取后置节点的索引
|
||||
List<Integer> rearNodeIndexSet = getRearNodeIndex(nodeIndex);
|
||||
for (int i = 0; i < rearNodeIndexSet.size(); i++) {
|
||||
int rearNodeIndex = rearNodeIndexSet.get(i).intValue();
|
||||
if (!isPosition[rearNodeIndex]) {
|
||||
position[rearNodeIndex][1] = position[nodeIndex][1] + shapeH + vertInterval; // 当前节点的坐标y = 前置节点的坐标y + 图形高度 + 垂直间隔
|
||||
if (i == 0){
|
||||
position[rearNodeIndex][0] = position[nodeIndex][0]; // 当前节点的如果为第一个后置节点 则 坐标x的值一致
|
||||
}else {
|
||||
position[rearNodeIndex][0] = position[nodeIndex][0] + shapeW + i * horizInterval; // 非第一个后置节点的坐标x = 上一个节点的坐标x + 图形宽度 + 第几个后置节点 * 横向间隔
|
||||
realTimeX = position[rearNodeIndex][0];
|
||||
}
|
||||
isPosition[rearNodeIndex] = true;
|
||||
|
||||
if (existOutLink(rearNodeIndex)){
|
||||
realTimeX = calculationRearNodePoiInVertLayOut(rearNodeIndex, realTimeX);
|
||||
}
|
||||
}
|
||||
}
|
||||
return realTimeX;
|
||||
}
|
||||
|
||||
|
||||
public static void main(String[] args) {
|
||||
// 生成邻接矩阵
|
||||
@ -182,6 +251,6 @@ public class GraphLayout {
|
||||
nodes.add(node3);
|
||||
nodes.add(node4);
|
||||
GraphLayout graphLayout = new GraphLayout(matrix, nodes);
|
||||
graphLayout.layOut();
|
||||
graphLayout.horizLayOut();
|
||||
}
|
||||
}
|
||||
|
||||
@ -136,16 +136,14 @@ public class GraphLinkerRender {
|
||||
: new double[]{toX + SubProcessConst.SUB_PROCESS_SHAPE_W, toY + SubProcessConst.SUB_PROCESS_SHAPE_H / 2};
|
||||
return new double[][]{startPoint, {turnPointX, toY + (SubProcessConst.SUB_PROCESS_SHAPE_H / 2)},{turnPointX, toY + (SubProcessConst.SUB_PROCESS_SHAPE_H / 2)}, endPoint};
|
||||
}else if (fromX == toX) { // 垂直
|
||||
double[] startPoint = (fromY < toY)
|
||||
? new double[]{fromX + SubProcessConst.SUB_PROCESS_SHAPE_W / 2, fromY + SubProcessConst.SUB_PROCESS_SHAPE_H}
|
||||
: new double[]{fromX + SubProcessConst.SUB_PROCESS_SHAPE_W, fromY + SubProcessConst.SUB_PROCESS_SHAPE_H / 2};
|
||||
double turnPointY = (fromY < toY)
|
||||
? fromY + SubProcessConst.SUB_PROCESS_SHAPE_H + (toY - (fromY + SubProcessConst.SUB_PROCESS_SHAPE_H)) / 2
|
||||
: toY + SubProcessConst.SUB_PROCESS_SHAPE_H + (fromY - (toY + SubProcessConst.SUB_PROCESS_SHAPE_H)) / 2;
|
||||
double[] endPoint = (fromY < toY)
|
||||
? new double[]{toX + SubProcessConst.SUB_PROCESS_SHAPE_W / 2, toY}
|
||||
: new double[]{toX + SubProcessConst.SUB_PROCESS_SHAPE_W / 2, toY};
|
||||
return new double[][]{startPoint, {fromX + (SubProcessConst.SUB_PROCESS_SHAPE_W / 2), turnPointY},{fromX + (SubProcessConst.SUB_PROCESS_SHAPE_W / 2), turnPointY}, endPoint};
|
||||
// 节点横向分布 连线按照大原则 垂直 不存在 fromY < toY 的情况 也就是不存在 连线从上到下直连的情况
|
||||
double[] startPoint = new double[]{fromX + SubProcessConst.SUB_PROCESS_SHAPE_W, fromY + SubProcessConst.SUB_PROCESS_SHAPE_H / 2};
|
||||
double[] endPoint = new double[]{toX + SubProcessConst.SUB_PROCESS_SHAPE_W / 2, toY};
|
||||
return new double[][]{startPoint,
|
||||
{fromX + SubProcessConst.SUB_PROCESS_SHAPE_W + SubProcessConst.SHAPE_HORIZ_INTERVAL / 2, fromY + SubProcessConst.SUB_PROCESS_SHAPE_H / 2},
|
||||
{fromX + SubProcessConst.SUB_PROCESS_SHAPE_W + SubProcessConst.SHAPE_HORIZ_INTERVAL / 2, toY - SubProcessConst.SHAPE_VERT_INTERVAL / 2},
|
||||
{toX + SubProcessConst.SUB_PROCESS_SHAPE_W / 2, toY - SubProcessConst.SHAPE_VERT_INTERVAL / 2},
|
||||
endPoint};
|
||||
}else {
|
||||
if (fromX < toX && fromY > toY){ // 目标节点在第一象限
|
||||
double[] startPoint = new double[]{fromX + SubProcessConst.SUB_PROCESS_SHAPE_W, fromY + SubProcessConst.SUB_PROCESS_SHAPE_H / 2};
|
||||
|
||||
@ -265,7 +265,7 @@ public class SubProcessWeb extends ActionWeb {
|
||||
|
||||
// 获取节点分布
|
||||
GraphLayout graphLayout = new GraphLayout(graphAdjMatrix.getAdjMatrix(), nodeList);
|
||||
double[][] position = graphLayout.layOut();
|
||||
double[][] position = graphLayout.horizLayOut();
|
||||
|
||||
// 组装连线
|
||||
GraphLinkerRender linkerRender = new GraphLinkerRender(nodeList, position, graphAdjMatrix);
|
||||
|
||||
Loading…
Reference in New Issue
Block a user