Skip to content

Commit

Permalink
Fix #6756 (when scrollable legend switch from "show controller" to "n…
Browse files Browse the repository at this point in the history
…ot show controller", content position should be correct.)
  • Loading branch information
100pah committed Sep 28, 2017
1 parent 2db7e7a commit 3f13fd9
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 8 deletions.
29 changes: 22 additions & 7 deletions src/component/legend/ScrollableLegendView.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,12 @@ define(function (require) {
* @type {module:zrender/container/Group}
*/
this.group.add(this._controllerGroup = new Group());

/**
*
* @private
*/
this._showController;
},

/**
Expand Down Expand Up @@ -140,7 +146,7 @@ define(function (require) {

var contentRect = contentGroup.getBoundingRect();
var controllerRect = controllerGroup.getBoundingRect();
var showController = contentRect[wh] > maxSize[wh];
var showController = this._showController = contentRect[wh] > maxSize[wh];

var contentPos = [-contentRect.x, -contentRect.y];
// Remain contentPos when scroll animation perfroming.
Expand Down Expand Up @@ -204,7 +210,11 @@ define(function (require) {
// Content translate animation.
var pageInfo = this._getPageInfo(legendModel);
pageInfo.pageIndex != null && graphic.updateProps(
contentGroup, {position: pageInfo.contentPosition}, legendModel
contentGroup,
{position: pageInfo.contentPosition},
// When switch from "show controller" to "not show controller", view should be
// updated immediately without animation, otherwise causes weird efffect.
showController ? legendModel : false
);

this._updatePageInfoView(legendModel, pageInfo);
Expand Down Expand Up @@ -281,11 +291,16 @@ define(function (require) {
var pageNextDataIndex;

var targetItemGroup;
contentGroup.eachChild(function (child) {
if (child.__legendDataIndex === currDataIndex) {
targetItemGroup = child;
}
});
if (this._showController) {
contentGroup.eachChild(function (child) {
if (child.__legendDataIndex === currDataIndex) {
targetItemGroup = child;
}
});
}
else {
targetItemGroup = contentGroup.childAt(0);
}

var pageCount = containerRectSize ? Math.ceil(contentRect[wh] / containerRectSize) : 0;

Expand Down
2 changes: 1 addition & 1 deletion test/legend.html
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ <h1>Scroll auto: left: 30, right: 30, bottom: 0, position: 'start'</h1>
<div class="chart" id="scroll-lr"></div>
<h1>Scroll vertically</h1>
<div class="chart" id="scroll-v"></div>
<h1>Scroll vertically, left: 10, top: 'center', position: 'start', height: 50%</h1>
<h1>Scroll vertically, left: 10, top: 'center', position: 'start', height: 50% (Turn the second page and resize it until page button disappear)</h1>
<div class="chart" id="scroll-v2"></div>

<script>
Expand Down

0 comments on commit 3f13fd9

Please sign in to comment.