Skip to content

Commit

Permalink
Refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
ehmicky committed Sep 5, 2021
1 parent 7ace666 commit e00325f
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 24 deletions.
27 changes: 23 additions & 4 deletions src/report/reporters/histogram/abscissa.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
import { separatorColor } from '../../utils/colors.js'

import { TICK_MIDDLE, HORIZONTAL_LINE } from './characters.js'
import { padMinStat, padMaxStat } from './min_max.js'
import {
TICK_LEFT,
TICK_RIGHT,
TICK_MIDDLE,
HORIZONTAL_LINE,
} from './characters.js'

// Retrieve the horizontal line and the abscissa below the main content.
// Includes the tick above the median and its label.
Expand All @@ -17,13 +21,28 @@ export const getAbscissa = function ({
}) {
const titlesSpace = ' '.repeat(titlesWidth)
const minSpace = ' '.repeat(minBlockWidth)
const paddedMin = padMinStat(min)
const paddedMax = padMaxStat(max)
const paddedMin = getPaddedMin(min)
const paddedMax = getPaddedMax(max)
const bottomLine = separatorColor(getBottomLine(contentWidth, medianIndex))
const label = getLabel(contentWidth, median, medianIndex)
return `${combinationTitles}${paddedMin}${bottomLine}${paddedMax}\n${titlesSpace}${minSpace}${label}\n`
}

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

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

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

const getBottomLine = function (contentWidth, medianIndex) {
const startPadding = HORIZONTAL_LINE.repeat(medianIndex)
return `${startPadding}${TICK_MIDDLE}`.padEnd(contentWidth, HORIZONTAL_LINE)
Expand Down
23 changes: 3 additions & 20 deletions src/report/reporters/histogram/min_max.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
import stringWidth from 'string-width'

import { separatorColor } from '../../utils/colors.js'

import { TICK_LEFT, TICK_RIGHT } from './characters.js'
import { getPaddedMin, getPaddedMax } from './abscissa.js'

// Retrieve the width of those blocks
const getBlockWidth = function (getStat, combinations, mini) {
Expand All @@ -22,27 +20,12 @@ const getCombinationWidth = function ({ stats }, getStat) {
}

const getMinStat = function ({ min }) {
return min === undefined ? '' : padMinStat(min)
return min === undefined ? '' : getPaddedMin(min)
}

const getMaxStat = function ({ max }) {
return max === undefined ? '' : padMaxStat(max)
}

export const padMinStat = function (min) {
return `${PADDING}${min.prettyPaddedColor}${PADDING}${separatorColor(
TICK_LEFT,
)}`
return max === undefined ? '' : getPaddedMax(max)
}

export const padMaxStat = function (max) {
return `${separatorColor(TICK_RIGHT)}${PADDING}${
max.prettyPaddedColor
}${PADDING}`
}

const PADDING_WIDTH = 1
const PADDING = ' '.repeat(PADDING_WIDTH)

export const getMinBlockWidth = getBlockWidth.bind(undefined, getMinStat)
export const getMaxBlockWidth = getBlockWidth.bind(undefined, getMaxStat)

0 comments on commit e00325f

Please sign in to comment.