Skip to content

Commit

Permalink
Fix viewport issues
Browse files Browse the repository at this point in the history
  • Loading branch information
gregtatum committed Feb 13, 2017
1 parent 807cc6f commit 89f381d
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions src/content/components/FlameChartViewport.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ class FlameChartViewport extends Component {
_mouseWheelListener(event) {
event.preventDefault();
const { containerLeft, containerWidth } = this.state;
const mouseCenter = (event.screenX - containerLeft) / containerWidth;
const mouseCenter = (event.clientX - containerLeft) / containerWidth;
const deltaY = event.deltaMode === LINE_SCROLL_MODE
? event.deltaY * SCROLL_LINE_SIZE
: event.deltaY;
Expand Down Expand Up @@ -130,15 +130,20 @@ class FlameChartViewport extends Component {
// Calculate top and bottom in terms of pixels.
let newViewportTop = viewportTop - (event.clientY - dragY);
let newViewportBottom = newViewportTop + containerHeight;
if (newViewportTop < 0) {
newViewportTop = 0;
newViewportBottom = containerHeight;
}

// Constrain the viewport to the bottom.
if (newViewportBottom > maxViewportHeight) {
newViewportTop = maxViewportHeight - containerHeight;
newViewportBottom = maxViewportHeight;
}

// Constrain the viewport to the top. This must be after constraining to the bottom
// so if the view is extra small the content is anchored to the top, and not the bottom.
if (newViewportTop < 0) {
newViewportTop = 0;
newViewportBottom = containerHeight;
}

this.setState({
dragX: event.clientX,
dragY: event.clientY,
Expand Down

0 comments on commit 89f381d

Please sign in to comment.