Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[amp-analytics] Don't calculate intersectRatio again. #5965

Merged
merged 1 commit into from Nov 2, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 5 additions & 1 deletion extensions/amp-analytics/0.1/test/test-visibility-impl.js
Expand Up @@ -86,10 +86,14 @@ describe('amp-analytics.visibility', () => {
function makeIntersectionEntry(boundingClientRect, rootBounds) {
boundingClientRect = layoutRectLtwh.apply(null, boundingClientRect);
rootBounds = layoutRectLtwh.apply(null, rootBounds);
const intersect = rectIntersection(boundingClientRect, rootBounds);
const ratio = (intersect.width * intersect.height)
/ (boundingClientRect.width * boundingClientRect.height);
return {
intersectionRect: rectIntersection(boundingClientRect, rootBounds),
intersectionRect: intersect,
boundingClientRect,
rootBounds,
intersectionRatio: ratio,
};
}

Expand Down
4 changes: 2 additions & 2 deletions extensions/amp-analytics/0.1/visibility-impl.js
Expand Up @@ -331,8 +331,8 @@ export class Visibility {
const change = res.element.getIntersectionChangeEntry();
const ir = change.intersectionRect;
const br = change.boundingClientRect;
const visible = br.height * br.width == 0 ? 0 :
ir.width * ir.height * 100 / (br.height * br.width);
const visible =
isNaN(change.intersectionRatio) ? 0 : change.intersectionRatio * 100;

const listeners = this.listeners_[res.getId()];
for (let c = listeners.length - 1; c >= 0; c--) {
Expand Down