Skip to content

Commit

Permalink
Merge pull request #161 from itamarst/159-show-subtitle
Browse files Browse the repository at this point in the history
Adjust height based on subtitle.
  • Loading branch information
jonhoo authored Feb 2, 2020
2 parents efa7323 + a7d621c commit c7c5da3
Show file tree
Hide file tree
Showing 4 changed files with 116 additions and 90 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

- Fix bug where subtitles would often be hidden ([#161](https://github.com/jonhoo/inferno/pull/161) by [@itamarst](https://github.com/itamarst))

### Removed

## [0.9.3] - 2020-02-02
Expand Down
28 changes: 26 additions & 2 deletions src/flamegraph/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -235,9 +235,14 @@ pub struct Options<'a> {
}

impl<'a> Options<'a> {
/// Calculate pad top, including title
/// Calculate pad top, including title and subtitle
pub(super) fn ypad1(&self) -> usize {
self.font_size * 3
let subtitle_height = if let Some(_) = self.subtitle {
self.font_size * 2
} else {
0
};
self.font_size * 3 + subtitle_height
}

/// Calculate pad bottom, including labels
Expand Down Expand Up @@ -827,3 +832,22 @@ fn write_usize(buffer: &mut StrStack, value: usize) -> usize {
itoa::fmt(&mut writer, value).unwrap();
writer.finish()
}

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

#[test]
fn top_ypadding_adjusts_for_subtitle() {
let height_without_subtitle = Options {
..Default::default()
}
.ypad1();
let height_with_subtitle = Options {
subtitle: Some(String::from("hello!")),
..Default::default()
}
.ypad1();
assert!(height_with_subtitle > height_without_subtitle);
}
}
88 changes: 44 additions & 44 deletions tests/data/flamegraph/options/subtitle_simple.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
88 changes: 44 additions & 44 deletions tests/data/flamegraph/options/subtitle_with_symbols.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit c7c5da3

Please sign in to comment.