diff --git a/flamechart-view.tsx b/flamechart-view.tsx index cd0a3c3..636783c 100644 --- a/flamechart-view.tsx +++ b/flamechart-view.tsx @@ -3,7 +3,7 @@ import {css} from 'aphrodite' import {ReloadableComponent} from './reloadable' import { CallTreeNode } from './profile' -import { Flamechart } from './flamechart' +import { Flamechart, FlamechartFrame } from './flamechart' import * as regl from 'regl' import { vec3, ReglCommand, ReglCommandConstructor } from 'regl' @@ -90,7 +90,6 @@ export class FlamechartPanZoomView extends ReloadableComponent { + const width = frame.end - frame.start + const configSpaceBounds = new Rect( + new Vec2(frame.start, depth + 1), + new Vec2(width, 1) + ) - // Cull text outside the viewport - if (!label.configSpaceBounds.hasInteractionWith(this.props.configSpaceViewportRect)) continue + if (width < minConfigSpaceWidthToRender) return + if (configSpaceBounds.left() > this.props.configSpaceViewportRect.right()) return + if (configSpaceBounds.right() < this.props.configSpaceViewportRect.left()) return + if (configSpaceBounds.top() > this.props.configSpaceViewportRect.bottom()) return - let physicalLabelBounds = configToPhysical.transformRect(label.configSpaceBounds) + if (configSpaceBounds.hasIntersectionWith(this.props.configSpaceViewportRect)) { + let physicalLabelBounds = configToPhysical.transformRect(configSpaceBounds) + + if (physicalLabelBounds.left() < 0) { + physicalLabelBounds = physicalLabelBounds + .withOrigin(physicalLabelBounds.origin.withX(0)) + .withSize(physicalLabelBounds.size.withX(physicalLabelBounds.size.x + physicalLabelBounds.left())) + } + if (physicalLabelBounds.right() > physicalViewSize.x) { + physicalLabelBounds = physicalLabelBounds + .withSize(physicalLabelBounds.size.withX(physicalViewSize.x - physicalLabelBounds.left())) + } - if (physicalLabelBounds.left() < 0) { physicalLabelBounds = physicalLabelBounds - .withOrigin(physicalLabelBounds.origin.withX(0)) - .withSize(physicalLabelBounds.size.withX(physicalLabelBounds.size.x + physicalLabelBounds.left())) - } - if (physicalLabelBounds.right() > physicalViewSize.x) { - physicalLabelBounds = physicalLabelBounds - .withSize(physicalLabelBounds.size.withX(physicalViewSize.x - physicalLabelBounds.left())) + .withOrigin(physicalLabelBounds.origin.plus(PADDING_OFFSET)) + .withSize(physicalLabelBounds.size.minus(SIZE_OFFSET)) + + const trimmedText = trimTextMid(ctx, frame.node.frame.name, physicalLabelBounds.width()) + ctx.fillText(trimmedText, physicalLabelBounds.left(), physicalLabelBounds.top()) } - physicalLabelBounds = physicalLabelBounds - .withOrigin(physicalLabelBounds.origin.plus(PADDING_OFFSET)) - .withSize(physicalLabelBounds.size.minus(SIZE_OFFSET)) + for (let child of frame.children) { + renderFrameLabelAndChildren(child, depth + 1) + } + } - const trimmedText = trimTextMid(ctx, label.node.frame.name, physicalLabelBounds.width()) - ctx.fillText(trimmedText, physicalLabelBounds.left(), physicalLabelBounds.top()) + for (let frame of (this.props.flamechart.getLayers()[0] || [])) { + renderFrameLabelAndChildren(frame) } const left = this.props.configSpaceViewportRect.left() @@ -483,6 +492,7 @@ export class FlamechartPanZoomView extends ReloadableComponent