Skip to content

Commit

Permalink
fix(flamegraph): Changing the model don't show the horizontal scrollbar
Browse files Browse the repository at this point in the history
  • Loading branch information
bric3 committed Jan 17, 2023
1 parent 7bfe278 commit 68ac7a6
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -711,4 +711,8 @@ public void setIcicle(boolean icicle) {
public boolean isIcicle() {
return icicle;
}

public FrameModel<T> getFrameModel() {
return frameModel;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,8 @@ public interface ZoomableComponent {
* @param <T> The type of the node data.
*/
public interface HoverListener<T> {
default void onStopHover(FrameBox<T> previousHoveredFrame, Rectangle prevHoveredFrameRectangle, MouseEvent e) {}
default void onStopHover(FrameBox<T> previousHoveredFrame, Rectangle prevHoveredFrameRectangle, MouseEvent e) {
}

void onFrameHover(FrameBox<T> frame, Rectangle hoveredFrameRectangle, MouseEvent e);

Expand Down Expand Up @@ -717,7 +718,7 @@ public void mouseDragged(MouseEvent e) {
var dy = e.getY() - pressedPoint.y;
var viewPortViewPosition = viewPort.getViewPosition();
viewPort.setViewPosition(new Point(Math.max(0, viewPortViewPosition.x - dx),
Math.max(0, viewPortViewPosition.y - dy)));
Math.max(0, viewPortViewPosition.y - dy)));
pressedPoint = e.getPoint();
e.consume();
}
Expand Down Expand Up @@ -932,8 +933,25 @@ public void addNotify() {
var scrollPane = (JScrollPane) viewport.getParent();
var vsb = scrollPane.getVerticalScrollBar();
vsb.addComponentListener(new ComponentAdapter() {
private int frameModelHashCode = 0;

@Override
public void componentShown(ComponentEvent e) {
// On the first display the flamegraph has the same width as the enclosing container
// but if flamegraph is zoomed-in the canvas width will be different.
// * So don't run this listener to prevent the canvas from being wrongly resized
// if the model didn't change.
// * The guard uses the hash code of the model because the model can be changed,
// and running this listener is necessary to prevent the horizontal scrollbar as well.
if (fgCanvas.flamegraphRenderEngine != null
&& fgCanvas.flamegraphRenderEngine.getFrameModel() != null) {
int newHashCode = fgCanvas.flamegraphRenderEngine.getFrameModel().hashCode();
if (newHashCode == frameModelHashCode) {
return;
}
frameModelHashCode = newHashCode;
}

SwingUtilities.invokeLater(() -> {
var canvasWidth = fgCanvas.getWidth();
if (canvasWidth == 0) {
Expand All @@ -943,11 +961,6 @@ public void componentShown(ComponentEvent e) {
// Adjust the width of the canvas to the width of the viewport rect
// to prevent the horizontal scrollbar from appearing on first display.
fgCanvas.setSize(viewport.getViewRect().width, getHeight());

// On the first display the flamegraph has the same width as the enclosing container
// but if flamegraph is zoomed in the width will be different.
// So we remove this listener to prevent the canvas from being wrongly resized
vsb.removeComponentListener(this);
});
}
});
Expand Down

0 comments on commit 68ac7a6

Please sign in to comment.