Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 10 additions & 5 deletions src/component/legend/ScrollableLegendView.ts
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,9 @@ class ScrollableLegendView extends LegendView {
const contentRect = contentGroup.getBoundingRect();
const controllerRect = controllerGroup.getBoundingRect();
const showController = this._showController = contentRect[wh] > maxSize[wh];
const contentSize = Math.max(contentRect[hw], controllerRect[hw]);
const mainSize = Math.min(contentSize, maxSize[hw]);
const crossOverflow = contentSize > maxSize[hw];

// In case that the inner elements of contentGroup layout do not based on [0, 0]
const contentPos = [-contentRect.x, -contentRect.y];
Expand Down Expand Up @@ -293,8 +296,8 @@ class ScrollableLegendView extends LegendView {
}
}

// Always align controller to content as 'middle'.
controllerPos[1 - orientIdx] += contentRect[hw] / 2 - controllerRect[hw] / 2;
// Always align controller to visible content as 'middle'.
controllerPos[1 - orientIdx] += mainSize / 2 - controllerRect[hw] / 2;

contentGroup.setPosition(contentPos);
containerGroup.setPosition(containerPos);
Expand All @@ -307,15 +310,17 @@ class ScrollableLegendView extends LegendView {

// Consider content may be overflow (should be clipped).
mainRect[wh] = showController ? maxSize[wh] : contentRect[wh];
mainRect[hw] = Math.max(contentRect[hw], controllerRect[hw]);
mainRect[hw] = mainSize;

// `containerRect[yx] + containerPos[1 - orientIdx]` is 0.
mainRect[yx] = Math.min(0, controllerRect[yx] + controllerPos[1 - orientIdx]);

containerGroup.__rectSize = maxSize[wh];
if (showController) {
if (showController || crossOverflow) {
const clipShape = {x: 0, y: 0} as graphic.Rect['shape'];
clipShape[wh] = Math.max(maxSize[wh] - controllerRect[wh] - pageButtonGap, 0);
clipShape[wh] = showController
? Math.max(maxSize[wh] - controllerRect[wh] - pageButtonGap, 0)
: mainRect[wh];
clipShape[hw] = mainRect[hw];
containerGroup.setClipPath(new graphic.Rect({shape: clipShape}));
// Consider content may be larger than container, container rect
Expand Down
105 changes: 105 additions & 0 deletions test/ut/spec/component/legend/scrollableLegend.test.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.