Skip to content

Commit

Permalink
fix: use lastItemWidth to cache
Browse files Browse the repository at this point in the history
  • Loading branch information
kkxxkk2019 committed Jul 18, 2024
1 parent e5241f3 commit eb4e009
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions packages/vrender-components/src/legend/discrete/discrete.ts
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,7 @@ export class DiscreteLegend extends LegendBase<DiscreteLegendAttrs> {

let { doWrap, maxWidthInCol, startX, startY, pages } = this._itemContext;
let item: LegendItemDatum;
let lastItemWidth = 0;

for (let index = startIndex, len = legendItems.length; index < len; index++) {
if (lazyload && pages > this._itemContext.currentPage * maxPages) {
Expand Down Expand Up @@ -256,6 +257,7 @@ export class DiscreteLegend extends LegendBase<DiscreteLegendAttrs> {
this._itemHeight = Math.max(this._itemHeight, itemHeight);

this._itemMaxWidth = Math.max(itemWidth, this._itemMaxWidth);
maxWidthInCol = Math.max(itemWidth, maxWidthInCol);

if (isHorizontal) {
// 水平布局
Expand Down Expand Up @@ -291,11 +293,10 @@ export class DiscreteLegend extends LegendBase<DiscreteLegendAttrs> {
pages += 1;
doWrap = true;
startY = 0;
startX += maxWidthInCol + spaceCol;
maxWidthInCol = itemWidth;
if (index > 0) {
startX += lastItemWidth + spaceCol;
}
} else if (maxHeight < startY + itemHeight) {
maxWidthInCol = Math.max(itemWidth, maxWidthInCol);

// 检测是否换列:如果用户声明了 maxHeight 并且超出了,则进行换列
pages += 1;
doWrap = true;
Expand All @@ -314,6 +315,7 @@ export class DiscreteLegend extends LegendBase<DiscreteLegendAttrs> {
}

itemsContainer.add(itemGroup);
lastItemWidth = itemWidth;
}

this._itemContext.doWrap = doWrap;
Expand Down

0 comments on commit eb4e009

Please sign in to comment.