diff --git a/flamechart-minimap-view.tsx b/flamechart-minimap-view.tsx index 71eb9c0..50db1fe 100644 --- a/flamechart-minimap-view.tsx +++ b/flamechart-minimap-view.tsx @@ -13,6 +13,7 @@ const DEVICE_PIXEL_RATIO = window.devicePixelRatio interface FlamechartMinimapViewProps { flamechart: Flamechart configSpaceViewportRect: Rect + setConfigSpaceViewportRect: (rect: Rect) => void } export class FlamechartMinimapView extends Component { @@ -128,6 +129,92 @@ export class FlamechartMinimapView extends Component { + ev.preventDefault() + this.pan(new Vec2(ev.deltaX, ev.deltaY)) + this.renderCanvas() + } + + private dragStartPos: Vec2 | null = null + private onMouseDown = (ev: MouseEvent) => { + this.dragStartPos = new Vec2(ev.offsetX, ev.offsetY) + } + + private onMouseDrag = (ev: MouseEvent) => { + if (!this.dragStartPos) return + + const logicalStart = this.dragStartPos + const physicalStart = this.logicalToPhysicalViewSpace().transformPosition(logicalStart) + const configStart = this.configSpaceToPhysicalViewSpace().inverseTransformPosition(physicalStart) + + const logicalEnd = new Vec2(ev.offsetX, ev.offsetY) + const physicalEnd = this.logicalToPhysicalViewSpace().transformPosition(logicalEnd) + const configEnd = this.configSpaceToPhysicalViewSpace().inverseTransformPosition(physicalEnd) + + if (!configStart || !configEnd) return + + const left = Math.min(configStart.x, configEnd.x) + const right = Math.max(configStart.x, configEnd.x) + + const width = right - left + const height = this.props.configSpaceViewportRect.height() + + this.setConfigSpaceViewportRect(new Rect( + new Vec2(left, configEnd.y - height / 2), + new Vec2(width, height) + )) + } + + private onMouseMove = (ev: MouseEvent) => { + if (this.dragStartPos) { + ev.preventDefault() + this.onMouseDrag(ev) + return + } + } + + private onWindowMouseUp = (ev: MouseEvent) => { + document.body.style.cursor = 'default' + this.dragStartPos = null + } + private preprocess(flamechart: Flamechart) { if (!this.canvas || !this.regl) return const configSpaceRects: Rect[] = [] @@ -152,9 +239,20 @@ export class FlamechartMinimapView extends Component { document.body.style.cursor = 'grabbing' document.body.style.cursor = '-webkit-grabbing' @@ -450,6 +449,11 @@ export class FlamechartPanZoomView extends ReloadableComponent { + document.body.style.cursor = 'default' + this.lastDragPos = null + } + private onMouseMove = (ev: MouseEvent) => { if (this.lastDragPos) { ev.preventDefault() @@ -508,11 +512,6 @@ export class FlamechartPanZoomView extends ReloadableComponent { - document.body.style.cursor = 'default' - this.lastDragPos = null - } - shouldComponentUpdate() { return false } componentWillReceiveProps(nextProps: FlamechartPanZoomViewProps) { if (this.props.flamechart !== nextProps.flamechart) { @@ -645,6 +644,7 @@ export class FlamechartView extends ReloadableComponent