Skip to content

Commit

Permalink
Improve label of histogram
Browse files Browse the repository at this point in the history
  • Loading branch information
ehmicky committed Sep 5, 2021
1 parent 7cf76ff commit 58cb670
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions src/report/reporters/histogram/abscissa.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,10 +80,11 @@ const getLabelLine = function ({
median,
medianIndex,
}) {
const labelPaddingWidth = Math.min(
medianIndex,
contentWidth - median.pretty.length,
)
const leftSpace = ' '.repeat(titlesWidth + minBlockWidth + labelPaddingWidth)
return `${leftSpace}${median.prettyColor}\n`
const leftShift = Math.max(Math.floor((median.pretty.length - 1) / 2), 0)
const shiftedIndex = medianIndex - leftShift
const maxContentIndex = contentWidth - median.pretty.length
const contentIndex = Math.min(Math.max(shiftedIndex, 0), maxContentIndex)
const labelIndex = contentIndex + titlesWidth + minBlockWidth
const labelLeft = ' '.repeat(labelIndex)
return `${labelLeft}${median.prettyColor}\n`
}

0 comments on commit 58cb670

Please sign in to comment.