* [task#128767] fix the issues of validStartRow.
This commit is contained in:
+34
-17
@@ -111,10 +111,10 @@ function afterFinish()
|
||||
*/
|
||||
function calculateCardPosition(region, index)
|
||||
{
|
||||
const h = 200; // 卡片高度
|
||||
const minW = 200; // 最小宽度
|
||||
const h = 180; // 卡片高度
|
||||
const minW = 180; // 最小宽度
|
||||
const maxW = 280; // 最大宽度
|
||||
const d = 10; // 间距
|
||||
const d = 8; // 间距
|
||||
const rows = Object.values(region.rows);
|
||||
const rowsCount = rows.length;
|
||||
const positions = [];
|
||||
@@ -128,20 +128,25 @@ function calculateCardPosition(region, index)
|
||||
for(let i = r; i < r + h && i < rowsCount; i++)
|
||||
{
|
||||
const rowsData = rows[i];
|
||||
let isValid = false;
|
||||
|
||||
for(let j = 0; j < rowsData.length; j++)
|
||||
{
|
||||
if(rowsData[j][0]) totalWidth += rowsData[j][1] - rowsData[j][0];
|
||||
if(totalWidth >= minW)
|
||||
const width = rowsData[j][1] - rowsData[j][0];
|
||||
if(width >= minW)
|
||||
{
|
||||
validStartRow = r;
|
||||
totalWidth += width;
|
||||
isValid = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if(isValid) validStartRow = i;
|
||||
}
|
||||
|
||||
if(validStartRow != -1)
|
||||
{
|
||||
const {left, right} = getMaxLeftAndMinRight(rows, validStartRow, h);
|
||||
let {left, right} = getMaxLeftAndMinRight(rows, validStartRow, h);
|
||||
right -= 16;
|
||||
let rowN = Math.floor((right - left + d) / (minW + d));
|
||||
let w = (right - left + d) / rowN;
|
||||
|
||||
@@ -150,7 +155,7 @@ function calculateCardPosition(region, index)
|
||||
let blockLeft = left + i * (w + d);
|
||||
let blockTop = rows[validStartRow][0][2];
|
||||
let blockWidth = Math.min(w, maxW);
|
||||
positions.push({left: blockLeft, top: blockTop, width: blockWidth});
|
||||
positions.push([blockLeft, blockTop, blockWidth]);
|
||||
}
|
||||
r += h;
|
||||
}
|
||||
@@ -160,14 +165,27 @@ function calculateCardPosition(region, index)
|
||||
}
|
||||
}
|
||||
|
||||
let isFirst = true;
|
||||
let firstTop = 0;
|
||||
positions.forEach((item) => {
|
||||
if(isFirst)
|
||||
{
|
||||
isFirst = false;
|
||||
firstTop = item[1];
|
||||
}
|
||||
else
|
||||
{
|
||||
if(item[1] > firstTop) item[1] += d;
|
||||
}
|
||||
});
|
||||
const cards = $(`#runResult .card.in_area-${index}`);
|
||||
if(cards.length <= positions.length)
|
||||
{
|
||||
cards.each((i, card) => {
|
||||
$(card).css({
|
||||
left: `${positions[i].left}px`,
|
||||
top: `${positions[i].top}px`,
|
||||
width: `${positions[i].width}px`,
|
||||
left: `${positions[i][0]}px`,
|
||||
top: `${positions[i][1]}px`,
|
||||
width: `${positions[i][2]}px`,
|
||||
height: `${h}px`,
|
||||
});
|
||||
});
|
||||
@@ -198,10 +216,9 @@ function getMaxLeftAndMinRight(rows, start, h)
|
||||
{
|
||||
if(rows[i])
|
||||
{
|
||||
const rowData = rows[i];
|
||||
const flattenedRow = flattenData(rowData);
|
||||
const maxLeft = flattenedRow.reduce((max, item) => item[0] > max ? item[0] : max, -Infinity);
|
||||
const minRight = flattenedRow.reduce((min, item) => item[1] < min ? item[1] : min, Infinity);
|
||||
const rowData = rows[i];
|
||||
const maxLeft = rowData[0][0];
|
||||
const minRight = rowData[rowData.length - 1][1];
|
||||
|
||||
left = Math.max(left, maxLeft);
|
||||
right = Math.min(right, minRight);
|
||||
@@ -306,7 +323,7 @@ function getCanvasSize(width = 0, height = 0)
|
||||
if(model3cKey == 'link') return {width: 420, height: 400};
|
||||
|
||||
const mode = $(`#canvas_${model3cKey}`).closest('.model-canvas').data('mode');
|
||||
if(mode == 'view') return {width: 2000, height: 2000};
|
||||
if(mode == 'view') return {width: 2600, height: 2600};
|
||||
|
||||
const maxWidth = $('.think-model-content').length ? ($('.think-model-content').width() - 50) : 400;
|
||||
const maxHeight = maxWidth;
|
||||
@@ -401,7 +418,7 @@ function findRegions(pixels, width, height)
|
||||
const visited = {};
|
||||
const regions = [];
|
||||
const mode = $(`#canvas_${model3cKey}`).closest('.model-canvas').data('mode');
|
||||
const minArea = mode == 'view' ? 500 : 100;
|
||||
const minArea = mode == 'view' ? 600 : 100;
|
||||
for(let y = 0; y < height; y++)
|
||||
{
|
||||
for(let x = 0; x < width; x++)
|
||||
|
||||
Reference in New Issue
Block a user