Skip to content

Commit fc5a237

Browse files
committed
update: calc flow height
1 parent 3ff274a commit fc5a237

File tree

2 files changed

+28
-16
lines changed

2 files changed

+28
-16
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "vue-flow-render",
3-
"version": "1.0.4",
3+
"version": "1.0.5",
44
"main": "dist/vue-flow-render.umd.min.js",
55
"files": [
66
"dist"

src/render.js

Lines changed: 27 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,8 @@ export default {
3434
},
3535
total: {
3636
type: Number,
37-
required: true
37+
required: true,
38+
default: 0
3839
},
3940
item: {
4041
type: Object,
@@ -213,25 +214,37 @@ export default {
213214
}
214215
if (this.isSameHeight) {
215216
const height = this.height
216-
const end = items ? items.length : total - offset
217-
for (let i = 0; i < end; i++) {
218-
const top = height * Math.floor((i + offset) / column)
219-
cache[i + offset] = {
220-
height,
221-
top,
222-
bottom: height + top
217+
const end = items ? items.length + offset : total
218+
if (this.isSingleColumn) {
219+
for (let i = offset; i < end; i++) {
220+
const top = height * Math.floor(i / column)
221+
cache[i] = {
222+
top,
223+
height,
224+
bottom: height + top
225+
}
223226
}
227+
this.flowHeight = height * Math.ceil(total / column)
228+
} else {
229+
for (let i = offset; i < end; i++) {
230+
const top = height * i
231+
cache[i] = {
232+
top,
233+
height,
234+
bottom: height + top
235+
}
236+
}
237+
this.flowHeight = height * total
224238
}
225-
this.flowHeight = height * total / column
226239
} else {
227240
if (this.isSingleColumn) {
228241
let beforeHeight = offset ? cache[offset - 1].bottom : 0
229242
items.forEach((item, index) => {
230243
const hgt = parseInt(item.data.style.height, 10)
231244
cache[index + offset] = {
232-
height: hgt,
233245
top: beforeHeight,
234-
bottom: hgt + beforeHeight
246+
bottom: hgt + beforeHeight,
247+
height: hgt
235248
}
236249
beforeHeight += hgt
237250
})
@@ -247,13 +260,12 @@ export default {
247260
offsets = new Array(column).fill(0)
248261
}
249262
items.forEach((item, index) => {
250-
const realIndex = index + offset
251263
const beforeHeight = Math.min(...offsets)
252264
const hgt = parseInt(item.data.style.height, 10)
253-
cache[realIndex] = {
254-
height: hgt,
265+
cache[index + offset] = {
255266
top: beforeHeight,
256-
bottom: hgt + beforeHeight
267+
bottom: hgt + beforeHeight,
268+
height: hgt
257269
}
258270
offsets[offsets.indexOf(beforeHeight)] += hgt
259271
})

0 commit comments

Comments
 (0)