Skip to content

Commit

Permalink
Improve histogram
Browse files Browse the repository at this point in the history
  • Loading branch information
ehmicky committed Sep 26, 2021
1 parent ce78958 commit a110fa8
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 18 deletions.
33 changes: 17 additions & 16 deletions src/report/reporters/histogram/abscissa.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,34 +44,34 @@ const getBottomFullLine = function ({
min,
max,
}) {
const paddedMin = getPaddedMin(min)
const paddedMin = getPaddedStat(min)
const bottomLine = separatorColor(getBottomLine(contentWidth, medianIndex))
const paddedMax = getPaddedMax(max)
const paddedMax = getPaddedStat(max)
return `${combinationTitles}${paddedMin}${bottomLine}${paddedMax}\n`
}

const getPaddedMin = function ({ prettyPaddedColor }) {
return `${STAT_PADDING}${prettyPaddedColor}${STAT_PADDING}${separatorColor(
TICK_LEFT,
)}`
}

const getPaddedMax = function ({ prettyPaddedColor }) {
return `${separatorColor(
TICK_RIGHT,
)}${STAT_PADDING}${prettyPaddedColor}${STAT_PADDING}`
const getPaddedStat = function ({ prettyPaddedColor }) {
return `${STAT_PADDING}${prettyPaddedColor}${STAT_PADDING}`
}

export const getPaddedStatLength = function ({ prettyPadded }) {
return prettyPadded.length + STAT_PADDING_WIDTH * 2 + TICK_LEFT.length
return prettyPadded.length + STAT_PADDING_WIDTH * 2
}

const STAT_PADDING_WIDTH = 1
const STAT_PADDING = ' '.repeat(STAT_PADDING_WIDTH)

export const getTickLength = function () {
return TICK_LEFT.length
}

const getBottomLine = function (contentWidth, medianIndex) {
const startPadding = HORIZONTAL_LINE.repeat(medianIndex)
return `${startPadding}${TICK_MIDDLE}`.padEnd(contentWidth, HORIZONTAL_LINE)
const bottomLine = `${startPadding}${TICK_MIDDLE}`.padEnd(
contentWidth,
HORIZONTAL_LINE,
)
return `${TICK_LEFT}${bottomLine}${TICK_RIGHT}`
}

const getLabelLine = function ({
Expand All @@ -81,11 +81,12 @@ const getLabelLine = function ({
median,
medianIndex,
}) {
const tickLength = getTickLength()
const centeredMedian = centerString(
median.prettyColor,
medianIndex,
contentWidth,
contentWidth + tickLength * 2,
)
const initialSpace = ' '.repeat(titlesWidth + minBlockWidth)
const initialSpace = ' '.repeat(titlesWidth + minBlockWidth - tickLength)
return `${initialSpace}${centeredMedian}\n`
}
6 changes: 4 additions & 2 deletions src/report/reporters/histogram/width.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { getCombinationTitlePad } from '../../utils/combination_title.js'

import { getPaddedStatLength } from './abscissa.js'
import { getPaddedStatLength, getTickLength } from './abscissa.js'

// Compute the width of each column.
export const getWidths = function (combinations, mini, screenWidth) {
Expand All @@ -18,7 +18,9 @@ const getMinMaxBlockWidth = function (combinations, mini, statName) {
return mini
? 0
: Math.max(
...combinations.map(({ stats }) => getPaddedStatWidth(stats[statName])),
...combinations.map(
({ stats }) => getPaddedStatWidth(stats[statName]) + getTickLength(),
),
)
}

Expand Down

0 comments on commit a110fa8

Please sign in to comment.