@@ -15,11 +15,26 @@ import './flow_chart_library.dart';
15
15
import './ui/draw_arrow.dart' ;
16
16
import './ui/segment_handler.dart' ;
17
17
18
+ /// 普通节点默认尺寸
19
+ const Size defaultElementSize = Size (250 , 60 );
20
+
21
+ /// 组节点默认尺寸
22
+ const Size defaultGroupElementSize = Size (320 , 80 );
23
+
24
+ /// 节点的padding
25
+ const double elementPadding = 10 ;
26
+
27
+ /// 默认的锚点大小
28
+ const double defaultHandlerSize = 20 ;
29
+
18
30
/// 组节点内子节点的间距
19
- const double groupElementSpacing = 20 ;
31
+ const double groupElementSpacing = 10 ;
32
+
33
+ /// plus节点默认大小
34
+ const double defaultPlusSize = 26 ;
20
35
21
36
/// 节点间默认距离
22
- const int defaultNodeDistance = 50 ;
37
+ const int defaultNodeDistance = 35 ;
23
38
24
39
class GroupLayoutData {
25
40
final String id;
@@ -281,13 +296,10 @@ class Dashboard extends ChangeNotifier {
281
296
elements
282
297
.where ((element) => element.taskType == TaskType .group)
283
298
.map ((groupElement) {
284
- final childElements = elements
285
- .where ((element) => element.parentId == groupElement.id)
286
- .toList ();
287
299
final groupLayoutData = GroupLayoutData (
288
300
id: groupElement.id,
289
301
columnsLayoutData: getGroupColumnLayoutData (groupElement.id),
290
- rowsLayoutData: getGroupRowLayoutData (childElements, groupElement.id),
302
+ rowsLayoutData: getGroupRowLayoutData (groupElement.id),
291
303
);
292
304
_allGroupsLayoutData[groupElement.id] = groupLayoutData;
293
305
}).toList ();
@@ -749,8 +761,7 @@ class Dashboard extends ChangeNotifier {
749
761
}
750
762
751
763
// 获取行布局数据
752
- List <List <FlowElement >> getGroupRowLayoutData (
753
- List <FlowElement > childElements, String groupId) {
764
+ List <List <FlowElement >> getGroupRowLayoutData (String groupId) {
754
765
FlowElement ? groupElement = findElementById (groupId);
755
766
List <List <FlowElement >> groupRowLayoutData = [];
756
767
if (groupElement != null ) {
@@ -1191,6 +1202,7 @@ class Dashboard extends ChangeNotifier {
1191
1202
// 删除组节点需要删除所有其子节点
1192
1203
if (removedElement.taskType == TaskType .group) {
1193
1204
elements.removeWhere ((element) => element.parentId == removedElement.id);
1205
+ allGroupsLayoutData.remove (removedElement.id);
1194
1206
}
1195
1207
// 移除当前节点所有的连接
1196
1208
for (final e in elements) {
@@ -1222,21 +1234,26 @@ class Dashboard extends ChangeNotifier {
1222
1234
.where ((ele) => ele.parentId == removedElement.parentId)
1223
1235
.toList ();
1224
1236
final groupElement = findElementById (removedElement.parentId)! ;
1237
+ final lastGroupColumnLayoutData =
1238
+ getGroupColumnLayoutData (removedElement.parentId);
1225
1239
final removedElementColumnIndex = groupElement.colsElementIds
1226
1240
.indexWhere ((elementIds) => elementIds.contains (removedElementId));
1227
1241
final removedElementRowIndex = groupElement.rowsElementIds
1228
1242
.indexWhere ((elementIds) => elementIds.contains (removedElementId));
1229
1243
final lastColsLength = groupElement.colsElementIds.length;
1230
1244
final lastRowsLength = groupElement.rowsElementIds.length;
1231
1245
if (removedElementColumnIndex != - 1 && removedElementRowIndex != - 1 ) {
1232
- groupElement.colsElementIds[removedElementColumnIndex]
1233
- [removedElementRowIndex] = "" ;
1246
+ if (removedEleNextEle != null ) {
1247
+ groupElement.colsElementIds[removedElementColumnIndex]
1248
+ .removeAt (removedElementRowIndex);
1249
+ groupElement.colsElementIds[removedElementColumnIndex].add ("" );
1250
+ } else {
1251
+ groupElement.colsElementIds[removedElementColumnIndex]
1252
+ [removedElementRowIndex] = "" ;
1253
+ }
1234
1254
groupElement.colsElementIds =
1235
1255
cleanLastEmptyItems (groupElement.colsElementIds);
1236
- groupElement.rowsElementIds[removedElementRowIndex]
1237
- [removedElementColumnIndex] = "" ;
1238
- groupElement.rowsElementIds =
1239
- cleanLastEmptyItems (groupElement.rowsElementIds);
1256
+ groupElement.rowsElementIds = transpose (groupElement.colsElementIds);
1240
1257
}
1241
1258
final colsLength = groupElement.colsElementIds.length;
1242
1259
final rowsLength = groupElement.rowsElementIds.length;
@@ -1256,12 +1273,32 @@ class Dashboard extends ChangeNotifier {
1256
1273
decreaseWidth =
1257
1274
removedElement.size.width + currentGroupElementSpacing;
1258
1275
}
1276
+ if (rowsLength == 0 ) {
1277
+ decreaseHeight =
1278
+ (defaultNodeDistance + defaultHandlerSize) * zoomFactor;
1279
+ }
1259
1280
}
1281
+ } else {
1282
+ final sourceElementBottomHandlerPos =
1283
+ sourceElement.getHandlerPosition (Alignment .bottomCenter);
1284
+ final removedEleBottomHandlerPos =
1285
+ removedElement.getHandlerPosition (Alignment .bottomCenter);
1286
+ decreaseHeight =
1287
+ removedEleBottomHandlerPos.dy - sourceElementBottomHandlerPos.dy;
1260
1288
}
1261
- final lastGroupColumnLayoutData =
1262
- getGroupColumnLayoutData (removedElement.parentId);
1263
1289
1264
- // 移除当前节点
1290
+ List <FlowElement > bottomOfRemovedElements = [];
1291
+ for (List <FlowElement > columnElements in lastGroupColumnLayoutData) {
1292
+ if (columnElements.first.position.dx == removedElement.position.dx) {
1293
+ bottomOfRemovedElements = columnElements.where ((ele) {
1294
+ return double .parse (ele.position.dy.toStringAsFixed (4 )) >
1295
+ double .parse (removedElement.position.dy.toStringAsFixed (4 ));
1296
+ }).toList ();
1297
+ break ;
1298
+ }
1299
+ }
1300
+
1301
+ /// 移除当前节点
1265
1302
elements.removeWhere ((element) {
1266
1303
if (element.id == removedElementId) {
1267
1304
return true ;
@@ -1270,52 +1307,32 @@ class Dashboard extends ChangeNotifier {
1270
1307
}
1271
1308
});
1272
1309
1273
- // 移除当前节点所有的连接
1310
+ /// 移除当前节点所有的连接
1274
1311
for (final e in elements) {
1275
1312
e.next.removeWhere ((handlerParams) {
1276
1313
return removedElementId.contains (handlerParams.destElementId);
1277
1314
});
1278
1315
}
1279
1316
1280
- List <FlowElement > bottomOfRemovedElements = [];
1281
- for (List <FlowElement > columnElements in lastGroupColumnLayoutData) {
1282
- if (columnElements.first.position.dx == removedElement.position.dx) {
1283
- bottomOfRemovedElements = columnElements.where ((ele) {
1284
- return double .parse (ele.position.dy.toStringAsFixed (4 )) >
1285
- double .parse (removedElement.position.dy.toStringAsFixed (4 ));
1286
- }).toList ();
1287
- break ;
1288
- }
1289
- }
1317
+ /// 移除节点后,更新组内其他节点位置和连线
1290
1318
updateLayOutAfterDelElementInGroup (
1291
1319
removedElement, sourceElement, bottomOfRemovedElements, decreaseHeight);
1292
1320
1321
+ /// 更新组节点大小和位置
1293
1322
List <FlowElement > childElements = elements
1294
1323
.where ((ele) => ele.parentId == removedElement.parentId)
1295
1324
.toList ();
1296
- final diffElementRows = rowsLength - lastRowsLength;
1325
+ int diffElementRows = rowsLength - lastRowsLength;
1297
1326
final diffElementCols = colsLength - lastColsLength;
1298
- if (diffElementCols < 0 ) {
1327
+ if (diffElementCols < 0 && colsLength > 0 ) {
1299
1328
decreaseWidth = removedElement.size.width + currentGroupElementSpacing;
1300
1329
}
1301
- if (sourceElement != null ) {
1302
- final sourceElementBottomHandlerPos =
1303
- sourceElement.getHandlerPosition (Alignment .bottomCenter);
1304
- final removedEleBottomHandlerPos =
1305
- removedElement.getHandlerPosition (Alignment .bottomCenter);
1306
- decreaseHeight =
1307
- removedEleBottomHandlerPos.dy - sourceElementBottomHandlerPos.dy;
1308
- }
1309
-
1310
- (defaultNodeDistance * 2 + defaultHandlerSize * 2 ) * zoomFactor;
1311
1330
1312
- /// 判断是否需要更新组节点的大小
1313
- /// 关于高度:如果删除的节点导致行数变少了,需要更新组节点的高度
1314
1331
final newGroupElementSize = Size (groupElement.size.width - decreaseWidth,
1315
1332
groupElement.size.height + decreaseHeight * diffElementRows);
1316
1333
1317
- ///关于宽度:如果删除的节点导致列数变少了,需要更新组节点的宽度
1318
1334
groupElement.size = newGroupElementSize;
1335
+
1319
1336
if (decreaseWidth != 0 ) {
1320
1337
// 更新组节点位置
1321
1338
groupElement.position = Offset (
@@ -1330,7 +1347,8 @@ class Dashboard extends ChangeNotifier {
1330
1347
element.position.dy));
1331
1348
}
1332
1349
}
1333
- // 如果行数减少了则追加调整组外后续节点的垂直位置
1350
+
1351
+ /// 如果行数减少了则追加调整组外后续节点的垂直位置
1334
1352
if (diffElementRows < 0 ) {
1335
1353
for (var element in elements) {
1336
1354
if (element.position.dy > removedElement.position.dy - decreaseHeight &&
@@ -1633,15 +1651,18 @@ class Dashboard extends ChangeNotifier {
1633
1651
1634
1652
List <List <String >> cleanLastEmptyItems (List <List <String >> matrix) {
1635
1653
if (matrix.isEmpty) return matrix;
1636
-
1637
1654
// 如果所有子数组的最后一项都为空字符串,则移除最后一项
1638
1655
if (matrix.every ((row) => row.isNotEmpty && row.last.isEmpty)) {
1639
- return matrix.map ((row) => row.sublist (0 , row.length - 1 )).toList ();
1656
+ return matrix
1657
+ .map ((row) => row.sublist (0 , row.length - 1 ))
1658
+ .where ((row) => row.isNotEmpty)
1659
+ .toList ();
1640
1660
}
1641
1661
1642
1662
// 否则,过滤掉空子数组并返回原始数组
1643
1663
return matrix
1644
1664
.where ((row) => row.where ((item) => item != "" ).isNotEmpty)
1665
+ .where ((row) => row.isNotEmpty)
1645
1666
.toList ();
1646
1667
}
1647
1668
}
0 commit comments