* [task#128767] modify the calculation logic for position.
This commit is contained in:
+40
-21
@@ -109,14 +109,15 @@ function afterFinish()
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
function calculateCardPosition(region)
|
||||
function calculateCardPosition(region, index)
|
||||
{
|
||||
const h = 300; // 卡片高度
|
||||
const minW = 256; // 最小宽度
|
||||
const maxW = 400; // 最大宽度
|
||||
const h = 200; // 卡片高度
|
||||
const minW = 200; // 最小宽度
|
||||
const maxW = 280; // 最大宽度
|
||||
const d = 10; // 间距
|
||||
const rows = flattenData(region.rows);
|
||||
const rows = Object.values(region.rows);
|
||||
const rowsCount = rows.length;
|
||||
const positions = [];
|
||||
|
||||
let r = 0;
|
||||
while (r < rowsCount)
|
||||
@@ -126,30 +127,30 @@ function calculateCardPosition(region)
|
||||
|
||||
for(let i = r; i < r + h && i < rowsCount; i++)
|
||||
{
|
||||
if(rows[i]?.right) totalWidth += rows[i].right - rows[i].left;
|
||||
if(totalWidth >= minW)
|
||||
const rowsData = rows[i];
|
||||
for(let j = 0; j < rowsData.length; j++)
|
||||
{
|
||||
validStartRow = r;
|
||||
break;
|
||||
if(rowsData[j][0]) totalWidth += rowsData[j][1] - rowsData[j][0];
|
||||
if(totalWidth >= minW)
|
||||
{
|
||||
validStartRow = r;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if(validStartRow !== -1)
|
||||
if(validStartRow != -1)
|
||||
{
|
||||
let left = rows[validStartRow]?.left || 0;
|
||||
let right = rows[Math.min(validStartRow + h - 1, rowsCount - 1)]?.right || 0;
|
||||
let rowN = Math.floor((right - left + d) / (minW + d));
|
||||
let w = (right - left + d) / rowN;
|
||||
const {left, right} = getMaxLeftAndMinRight(rows, validStartRow, h);
|
||||
let rowN = Math.floor((right - left + d) / (minW + d));
|
||||
let w = (right - left + d) / rowN;
|
||||
|
||||
for(let i = 0; i < rowN; i++)
|
||||
{
|
||||
let blockLeft = left + i * (w + d);
|
||||
let blockTop = rows[validStartRow].top;
|
||||
let blockWidth = Math.min(w, maxW);
|
||||
let blockHeight = h;
|
||||
|
||||
// TODO: 绘制卡片
|
||||
console.log(`Block ${i + 1}: Left: ${blockLeft}, Top: ${blockTop}, Width: ${blockWidth}, Height: ${blockHeight}`);
|
||||
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});
|
||||
}
|
||||
r += h;
|
||||
}
|
||||
@@ -158,6 +159,24 @@ function calculateCardPosition(region)
|
||||
r++;
|
||||
}
|
||||
}
|
||||
|
||||
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`,
|
||||
height: `${h}px`,
|
||||
});
|
||||
});
|
||||
$('.card').removeClass('hidden');
|
||||
}
|
||||
else
|
||||
{
|
||||
// TODO: 处理卡片数量超过位置数量的情况
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user