Skip to content

Commit

Permalink
update: calc flow height
Browse files Browse the repository at this point in the history
  • Loading branch information
falstack committed Aug 13, 2019
1 parent 3ff274a commit fc5a237
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 16 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "vue-flow-render",
"version": "1.0.4",
"version": "1.0.5",
"main": "dist/vue-flow-render.umd.min.js",
"files": [
"dist"
Expand Down
42 changes: 27 additions & 15 deletions src/render.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@ export default {
},
total: {
type: Number,
required: true
required: true,
default: 0
},
item: {
type: Object,
Expand Down Expand Up @@ -213,25 +214,37 @@ export default {
}
if (this.isSameHeight) {
const height = this.height
const end = items ? items.length : total - offset
for (let i = 0; i < end; i++) {
const top = height * Math.floor((i + offset) / column)
cache[i + offset] = {
height,
top,
bottom: height + top
const end = items ? items.length + offset : total
if (this.isSingleColumn) {
for (let i = offset; i < end; i++) {
const top = height * Math.floor(i / column)
cache[i] = {
top,
height,
bottom: height + top
}
}
this.flowHeight = height * Math.ceil(total / column)
} else {
for (let i = offset; i < end; i++) {
const top = height * i
cache[i] = {
top,
height,
bottom: height + top
}
}
this.flowHeight = height * total
}
this.flowHeight = height * total / column
} else {
if (this.isSingleColumn) {
let beforeHeight = offset ? cache[offset - 1].bottom : 0
items.forEach((item, index) => {
const hgt = parseInt(item.data.style.height, 10)
cache[index + offset] = {
height: hgt,
top: beforeHeight,
bottom: hgt + beforeHeight
bottom: hgt + beforeHeight,
height: hgt
}
beforeHeight += hgt
})
Expand All @@ -247,13 +260,12 @@ export default {
offsets = new Array(column).fill(0)
}
items.forEach((item, index) => {
const realIndex = index + offset
const beforeHeight = Math.min(...offsets)
const hgt = parseInt(item.data.style.height, 10)
cache[realIndex] = {
height: hgt,
cache[index + offset] = {
top: beforeHeight,
bottom: hgt + beforeHeight
bottom: hgt + beforeHeight,
height: hgt
}
offsets[offsets.indexOf(beforeHeight)] += hgt
})
Expand Down

0 comments on commit fc5a237

Please sign in to comment.