Skip to content

Commit

Permalink
Move details bar to top in icicle mode. (#177)
Browse files Browse the repository at this point in the history
  • Loading branch information
itamarst authored Jun 3, 2020
1 parent aba81a3 commit b4b2757
Show file tree
Hide file tree
Showing 4 changed files with 768 additions and 732 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Changed

- In icicle/inverted mode, the details bar is now at the top where it can actually be seen. [#177](https://github.com/jonhoo/inferno/pull/177)

### Removed

## [0.9.8] - 2020-05-30
Expand Down
35 changes: 32 additions & 3 deletions src/flamegraph/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -248,12 +248,25 @@ impl<'a> Options<'a> {
} else {
0
};
self.font_size * 3 + subtitle_height
if self.direction == Direction::Straight {
self.font_size * 3 + subtitle_height
} else {
// Inverted (icicle) mode, put the details on top. The +4 is to add
// a little bit more space between the title (or subtitle if there
// is one) and the details.
self.font_size * 4 + subtitle_height + 4
}
}

/// Calculate pad bottom, including labels
pub(super) fn ypad2(&self) -> usize {
self.font_size * 2 + 10
if self.direction == Direction::Straight {
self.font_size * 2 + 10
} else {
// Inverted (icicle) mode, put the details on top, so don't need
// room at the bottom.
self.font_size + 10
}
}
}

Expand Down Expand Up @@ -849,8 +862,9 @@ fn write_usize(buffer: &mut StrStack, value: usize) -> usize {

#[cfg(test)]
mod tests {
use super::Options;
use super::{Direction, Options};

// If there's a subtitle, we need to adjust the top height:
#[test]
fn top_ypadding_adjusts_for_subtitle() {
let height_without_subtitle = Options {
Expand All @@ -864,4 +878,19 @@ mod tests {
.ypad1();
assert!(height_with_subtitle > height_without_subtitle);
}

// In inverted (icicle) mode, the details move from bottom to top, so
// ypadding shifts accordingly.
#[test]
fn ypadding_adjust_for_inverted_mode() {
let regular = Options {
..Default::default()
};
let inverted = Options {
direction: Direction::Inverted,
..Default::default()
};
assert!(inverted.ypad1() > regular.ypad1());
assert!(inverted.ypad2() < regular.ypad2());
}
}
7 changes: 6 additions & 1 deletion src/flamegraph/svg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,12 @@ var truncate_text_right = {};",
&mut buf,
TextItem {
x: Dimension::Pixels(super::XPAD),
y: (style_options.imageheight - (opt.ypad2() / 2)) as f64,
y: if opt.direction == Direction::Straight {
(style_options.imageheight - (opt.ypad2() / 2))
} else {
// Inverted (icicle) mode, put the details on top:
opt.ypad1() - opt.font_size
} as f64,
text: " ".into(),
extra: iter::once(("id", "details")),
},
Expand Down
Loading

0 comments on commit b4b2757

Please sign in to comment.