|
|
@@ -48,22 +48,14 @@ export default function distributeCommand(data: Data, type: DistributeType) {
|
|
48
|
48
|
|
|
49
|
49
|
switch (type) {
|
|
50
|
50
|
case DistributeType.Horizontal: {
|
|
51
|
|
- const sortedByCenter = entries.sort(
|
|
52
|
|
- ([a], [b]) => centers[a][0] - centers[b][0]
|
|
53
|
|
- )
|
|
54
|
|
-
|
|
55
|
|
- const span = sortedByCenter.reduce((a, c) => a + c[1].width, 0)
|
|
|
51
|
+ const span = entries.reduce((a, c) => a + c[1].width, 0)
|
|
56
|
52
|
|
|
57
|
53
|
if (span > commonBounds.width) {
|
|
58
|
|
- const left = sortedByCenter.sort(
|
|
59
|
|
- (a, b) => a[1].minX - b[1].minX
|
|
60
|
|
- )[0]
|
|
|
54
|
+ const left = entries.sort((a, b) => a[1].minX - b[1].minX)[0]
|
|
61
|
55
|
|
|
62
|
|
- const right = sortedByCenter.sort(
|
|
63
|
|
- (a, b) => b[1].maxX - a[1].maxX
|
|
64
|
|
- )[0]
|
|
|
56
|
+ const right = entries.sort((a, b) => b[1].maxX - a[1].maxX)[0]
|
|
65
|
57
|
|
|
66
|
|
- const entriesToMove = sortedByCenter
|
|
|
58
|
+ const entriesToMove = entries
|
|
67
|
59
|
.filter((a) => a !== left && a !== right)
|
|
68
|
60
|
.sort((a, b) => centers[a[0]][0] - centers[b[0]][0])
|
|
69
|
61
|
|
|
|
@@ -81,8 +73,12 @@ export default function distributeCommand(data: Data, type: DistributeType) {
|
|
81
|
73
|
])
|
|
82
|
74
|
}
|
|
83
|
75
|
} else {
|
|
84
|
|
- const step = (commonBounds.width - span) / (len - 1)
|
|
|
76
|
+ const sortedByCenter = entries.sort(
|
|
|
77
|
+ (a, b) => centers[a[0]][0] - centers[b[0]][0]
|
|
|
78
|
+ )
|
|
|
79
|
+
|
|
85
|
80
|
let x = commonBounds.minX
|
|
|
81
|
+ const step = (commonBounds.width - span) / (len - 1)
|
|
86
|
82
|
|
|
87
|
83
|
for (let i = 0; i < sortedByCenter.length - 1; i++) {
|
|
88
|
84
|
const [id, bounds] = sortedByCenter[i]
|
|
|
@@ -94,22 +90,14 @@ export default function distributeCommand(data: Data, type: DistributeType) {
|
|
94
|
90
|
break
|
|
95
|
91
|
}
|
|
96
|
92
|
case DistributeType.Vertical: {
|
|
97
|
|
- const sortedByCenter = entries.sort(
|
|
98
|
|
- ([a], [b]) => centers[a][1] - centers[b][1]
|
|
99
|
|
- )
|
|
100
|
|
-
|
|
101
|
|
- const span = sortedByCenter.reduce((a, c) => a + c[1].height, 0)
|
|
|
93
|
+ const span = entries.reduce((a, c) => a + c[1].height, 0)
|
|
102
|
94
|
|
|
103
|
95
|
if (span > commonBounds.height) {
|
|
104
|
|
- const top = sortedByCenter.sort(
|
|
105
|
|
- (a, b) => a[1].minY - b[1].minY
|
|
106
|
|
- )[0]
|
|
|
96
|
+ const top = entries.sort((a, b) => a[1].minY - b[1].minY)[0]
|
|
107
|
97
|
|
|
108
|
|
- const bottom = sortedByCenter.sort(
|
|
109
|
|
- (a, b) => b[1].maxY - a[1].maxY
|
|
110
|
|
- )[0]
|
|
|
98
|
+ const bottom = entries.sort((a, b) => b[1].maxY - a[1].maxY)[0]
|
|
111
|
99
|
|
|
112
|
|
- const entriesToMove = sortedByCenter
|
|
|
100
|
+ const entriesToMove = entries
|
|
113
|
101
|
.filter((a) => a !== top && a !== bottom)
|
|
114
|
102
|
.sort((a, b) => centers[a[0]][1] - centers[b[0]][1])
|
|
115
|
103
|
|
|
|
@@ -127,8 +115,12 @@ export default function distributeCommand(data: Data, type: DistributeType) {
|
|
127
|
115
|
])
|
|
128
|
116
|
}
|
|
129
|
117
|
} else {
|
|
130
|
|
- const step = (commonBounds.height - span) / (len - 1)
|
|
|
118
|
+ const sortedByCenter = entries.sort(
|
|
|
119
|
+ (a, b) => centers[a[0]][1] - centers[b[0]][1]
|
|
|
120
|
+ )
|
|
|
121
|
+
|
|
131
|
122
|
let y = commonBounds.minY
|
|
|
123
|
+ const step = (commonBounds.height - span) / (len - 1)
|
|
132
|
124
|
|
|
133
|
125
|
for (let i = 0; i < sortedByCenter.length - 1; i++) {
|
|
134
|
126
|
const [id, bounds] = sortedByCenter[i]
|