Skip to content

Commit ecdc964

Browse files
authored
Merge pull request #1053 from mcFrax/fix-animate-selection-frame-progression
Fix selection fade frame progression
2 parents b54c7e9 + 183be48 commit ecdc964

File tree

2 files changed

+33
-11
lines changed

2 files changed

+33
-11
lines changed

auto_tests/tests/highlight_series_background.js

+29
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,35 @@ describe("highlight-series-background", function() {
123123
}, 500);
124124
});
125125

126+
it('testSelectionAnimationWithReducedFPS', function() {
127+
var graph = setupGraph(0.7,'rgb(255,0,0)');
128+
var frameCallback, middleFrameNum, lastFrameNum, cleanupCallback;
129+
utils.repeatAndCleanup = function (repeatFn, maxFrames, framePeriodInMillis, cleanupFn) {
130+
frameCallback = repeatFn;
131+
cleanupCallback = cleanupFn;
132+
middleFrameNum = Math.round(maxFrames / 2) - 1;
133+
lastFrameNum = maxFrames - 1;
134+
frameCallback(0);
135+
}
136+
var expectedFinalAlpha = 76;
137+
138+
assert.deepEqual(Util.samplePixel(graph.canvas_, 100, 100), [0,0,0,0]);
139+
140+
graph.setSelection(0, 'y', true);
141+
142+
frameCallback(middleFrameNum);
143+
var colorAfterMiddleFrame = Util.samplePixel(graph.canvas_, 100, 100);
144+
145+
frameCallback(lastFrameNum);
146+
cleanupCallback();
147+
var colorAtTheEnd = Util.samplePixel(graph.canvas_, 100, 100);
148+
149+
assert.deepEqual(
150+
[colorAfterMiddleFrame, colorAtTheEnd],
151+
[[255,0,0, expectedFinalAlpha / 2], [255,0,0, expectedFinalAlpha]],
152+
);
153+
});
154+
126155
it('testGetSelectionZeroCanvasY', function () {
127156
var graph = document.getElementById("graph");
128157
var calls = []

src/dygraph.js

+4-11
Original file line numberDiff line numberDiff line change
@@ -1715,27 +1715,20 @@ Dygraph.prototype.animateSelection_ = function(direction) {
17151715

17161716
var thisId = ++this.animateId;
17171717
var that = this;
1718-
var cleanupIfClearing = function() {
1719-
// if we haven't reached fadeLevel 0 in the max frame time,
1720-
// ensure that the clear happens and just go to 0
1721-
if (that.fadeLevel !== 0 && direction < 0) {
1722-
that.fadeLevel = 0;
1723-
that.clearSelection();
1724-
}
1725-
};
1718+
17261719
utils.repeatAndCleanup(
1727-
function(n) {
1720+
function(step) {
17281721
// ignore simultaneous animations
17291722
if (that.animateId != thisId) return;
17301723

1731-
that.fadeLevel += direction;
1724+
that.fadeLevel = start + (step + 1) * direction;
17321725
if (that.fadeLevel === 0) {
17331726
that.clearSelection();
17341727
} else {
17351728
that.updateSelection_(that.fadeLevel / totalSteps);
17361729
}
17371730
},
1738-
steps, millis, cleanupIfClearing);
1731+
steps, millis, function() {});
17391732
};
17401733

17411734
/**

0 commit comments

Comments
 (0)