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

Keyboard shortcuts and minimap UX #93

Merged
merged 23 commits into from
Oct 20, 2017
Merged
Show file tree
Hide file tree
Changes from 17 commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
b24825f
WIP - Drag to change view-range on trace minimap
tiffon Sep 25, 2017
f574cd0
WIP - Drag to change view-range on trace minimap
tiffon Sep 25, 2017
d3b5a4f
Merge branch 'master' into issue-23-trace-minimap-navigate-zoom
tiffon Sep 26, 2017
aef4225
Small adjustments to visuals of minimap UX
tiffon Sep 26, 2017
82a790d
Merge branch 'master' into issue-23-trace-minimap-navigate-zoom
tiffon Sep 26, 2017
50144fb
Refactor trace minimap mouse UX
tiffon Sep 27, 2017
ada62fe
Pan, scroll, zoom shortcuts; clearer minimap
tiffon Oct 3, 2017
d27a809
Merge branch 'master' into issue-23-trace-minimap-navigate-zoom
tiffon Oct 3, 2017
c2745de
Restructure components/TracePage#state.viewRange
tiffon Oct 4, 2017
d2cd518
Perf improved when expanding row details (~60%)
tiffon Oct 5, 2017
7ab6fde
Consolidate dragging into DraggableManager
tiffon Oct 9, 2017
2e33716
Column resize uses DraggableManager in trace view
tiffon Oct 9, 2017
1e260f4
Misc cleanup
tiffon Oct 9, 2017
05efc77
Dragging trace timeline time-labels zooms in
tiffon Oct 11, 2017
45bd040
Fix some tests, fix Draggable bug on resize window
tiffon Oct 11, 2017
6aad7ed
Test fixes, new tests for SpanGraph/ViewingLayer
tiffon Oct 11, 2017
4ef1c55
Add more tests
tiffon Oct 15, 2017
272cd64
Additional comments, misc tweaks
tiffon Oct 16, 2017
3cc5817
Fix trace minimap and timeline colors differ
tiffon Oct 17, 2017
7a6fb5e
Bind methods in the class body instead of ctor
tiffon Oct 19, 2017
f41bcf6
Better add-license adjustment
tiffon Oct 19, 2017
b2b8ae5
Use shallow instead of mount
tiffon Oct 19, 2017
2f22b02
Fix "Exapnded" typo
tiffon Oct 19, 2017
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
6 changes: 4 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
"basscss": "^8.0.3",
"chance": "^1.0.10",
"classnames": "^2.2.5",
"combokeys": "^3.0.0",
"cytoscape": "^3.2.1",
"cytoscape-dagre": "^2.0.0",
"d3-scale": "^1.0.6",
Expand Down Expand Up @@ -65,7 +66,8 @@
"reselect": "^3.0.1",
"semantic-ui-css": "^2.2.12",
"semantic-ui-react": "^0.71.4",
"store": "^2.0.12"
"store": "^2.0.12",
"tween-functions": "^1.2.0"
},
"scripts": {
"start": "react-scripts start",
Expand All @@ -83,7 +85,7 @@
"clear-homepage": "json -I -f package.json -e 'delete this.homepage'",
"deploy-docs": "./bin/deploy-docs.sh",
"postpublish": "npm run build:docs && npm run deploy-docs",
"add-license": "uber-licence",
"add-license": "uber-licence && git co flow-typed",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why git co flow-type?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cd src

"precommit": "lint-staged"
},
"lint-staged": {
Expand Down
206 changes: 206 additions & 0 deletions src/components/TracePage/ScrollManager.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,206 @@
// @flow

// Copyright (c) 2017 Uber Technologies, Inc.
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.

import type { Span, Trace } from '../../types';

export type Accessors = {
getViewRange: () => [number, number],
getSearchedSpanIDs: () => ?Set<string>,
getCollapsedChildren: () => ?Set<string>,
getViewHeight: () => number,
getBottomRowIndexVisible: () => number,
getTopRowIndexVisible: () => number,
getRowPosition: number => { height: number, y: number },
mapRowIndexToSpanIndex: number => number,
mapSpanIndexToRowIndex: number => number,
};

interface Scroller {
scrollTo: number => void,
scrollBy: number => void,
}

function isSpanHidden(span: Span, childrenAreHidden: Set<string>, spansMap: Map<string, ?Span>) {
const parentIDs = new Set();
let { references } = span;
let parentID: ?string;
const checkRef = ref => {
if (ref.refType === 'CHILD_OF') {
parentID = ref.spanID;
parentIDs.add(parentID);
return childrenAreHidden.has(parentID);
}
return false;
};
while (Array.isArray(references) && references.length) {
const isHidden = references.some(checkRef);
if (isHidden) {
return { isHidden, parentIDs };
}
if (!parentID) {
break;
}
const parent = spansMap.get(parentID);
parentID = undefined;
references = parent && parent.references;
}
return { parentIDs, isHidden: false };
}

export default class ScrollManager {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm a bit impartial about the OOP vs functional style here. Seems like the codebase has a mix of it now? I can see why you went with OOP given the implementation, but do you think we should be consistent? More specifically, to reduce state and unintended side effects in modules.

_trace: ?Trace;
_scroller: Scroller;
_accessors: ?Accessors;

constructor(trace: ?Trace, scroller: Scroller) {
this._trace = trace;
this._scroller = scroller;
this._accessors = undefined;

this.scrollToNextVisibleSpan = this.scrollToNextVisibleSpan.bind(this);
this.scrollToPrevVisibleSpan = this.scrollToPrevVisibleSpan.bind(this);
this.scrollPageDown = this.scrollPageDown.bind(this);
this.scrollPageUp = this.scrollPageUp.bind(this);
this.setAccessors = this.setAccessors.bind(this);
}

_scrollPast(rowIndex: number, direction: 1 | -1) {
const xrs = this._accessors;
if (!xrs) {
throw new Error('Accessors not set');
}
const isUp = direction < 0;
const position = xrs.getRowPosition(rowIndex);
if (!position) {
console.warn('Invalid row index');
return;
}
let { y } = position;
const vh = xrs.getViewHeight();
if (!isUp) {
y += position.height;
// scrollTop is based on the top of the window
y -= vh;
}
y += direction * 0.5 * vh;
this._scroller.scrollTo(y);
}

_scrollToVisibleSpan(direction: 1 | -1) {
const xrs = this._accessors;
if (!xrs) {
throw new Error('Accessors not set');
}
if (!this._trace) {
return;
}
const { duration, spans, startTime: traceStartTime } = this._trace;
const isUp = direction < 0;
const boundaryRow = isUp ? xrs.getTopRowIndexVisible() : xrs.getBottomRowIndexVisible();
const spanIndex = xrs.mapRowIndexToSpanIndex(boundaryRow);
if ((spanIndex === 0 && isUp) || (spanIndex === spans.length - 1 && !isUp)) {
return;
}
// fullViewSpanIndex is one row inside the view window unless already at the top or bottom
let fullViewSpanIndex = spanIndex;
if (spanIndex !== 0 && spanIndex !== spans.length - 1) {
fullViewSpanIndex -= direction;
}
const [viewStart, viewEnd] = xrs.getViewRange();
const checkVisibility = viewStart !== 0 || viewEnd !== 1;
// use NaN as fallback to make flow happy
const startTime = checkVisibility ? traceStartTime + duration * viewStart : NaN;
const endTime = checkVisibility ? traceStartTime + duration * viewEnd : NaN;
const findMatches = xrs.getSearchedSpanIDs();
const _collapsed = xrs.getCollapsedChildren();
const childrenAreHidden = _collapsed ? new Set(_collapsed) : null;
// use empty Map as fallback to make flow happy
const spansMap = childrenAreHidden ? new Map(spans.map(s => [s.spanID, s])) : new Map();
const boundary = direction < 0 ? -1 : spans.length;
let nextSpanIndex: number;
for (let i = fullViewSpanIndex + direction; i !== boundary; i += direction) {
const span = spans[i];
const { duration: spanDuration, spanID, startTime: spanStartTime } = span;
const spanEndTime = spanStartTime + spanDuration;
if (checkVisibility && (spanStartTime > endTime || spanEndTime < startTime)) {
// span is not visible within the view range
continue;
}
if (findMatches && !findMatches.has(spanID)) {
// skip to search matches (when searching)
continue;
}
if (childrenAreHidden) {
// make sure the span is not collapsed
const { isHidden, parentIDs } = isSpanHidden(span, childrenAreHidden, spansMap);
if (isHidden) {
childrenAreHidden.add(...parentIDs);
continue;
}
}
nextSpanIndex = i;
break;
}
if (!nextSpanIndex || nextSpanIndex === boundary) {
// might as well scroll to the top or bottom
nextSpanIndex = boundary - direction;
}
const nextRow = xrs.mapSpanIndexToRowIndex(nextSpanIndex);
this._scrollPast(nextRow, direction);
}

setTrace(trace: ?Trace) {
this._trace = trace;
}

setAccessors = function setAccessors(accessors: Accessors) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can't you just do

{
  setAccessors(accessors) {
    this.accessors = accessors
  }
}

And then remove all those bindings in the constructor?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Investigate

this._accessors = accessors;
};

scrollPageDown = function scrollPageDown() {
if (!this._scroller || !this._accessors) {
return;
}
this._scroller.scrollBy(0.95 * this._accessors.getViewHeight(), true);
};

scrollPageUp = function scrollPageUp() {
if (!this._scroller || !this._accessors) {
return;
}
this._scroller.scrollBy(-0.95 * this._accessors.getViewHeight(), true);
};

scrollToNextVisibleSpan = function scrollToNextVisibleSpan() {
this._scrollToVisibleSpan(1);
};

scrollToPrevVisibleSpan = function scrollToPrevVisibleSpan() {
this._scrollToVisibleSpan(-1);
};

destroy() {
this._trace = undefined;
this._scroller = (undefined: any);
this._accessors = undefined;
}
}
Loading