Skip to content

Commit

Permalink
Rename showStats to mini
Browse files Browse the repository at this point in the history
  • Loading branch information
ehmicky committed Sep 5, 2021
1 parent 2fee253 commit e2c6bcc
Show file tree
Hide file tree
Showing 7 changed files with 49 additions and 49 deletions.
46 changes: 23 additions & 23 deletions src/report/reporters/boxplot/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,24 +8,24 @@ import { NAME_SEPARATOR_COLORED } from '../../utils/separator.js'

// Reporter showing boxplot of measures (min, p25, median, p75, max)
const reportTerminal = function ({ combinations, screenWidth }) {
const showStats = true
const width = getContentWidth(combinations, showStats, screenWidth)
const mini = false
const width = getContentWidth(combinations, mini, screenWidth)
const { minAll, maxAll } = getMinMaxAll(combinations)
return combinations.map((combination) =>
serializeBoxPlot({ combination, minAll, maxAll, width, showStats }),
serializeBoxPlot({ combination, minAll, maxAll, width, mini }),
)
}

const getMinMaxAll = function (combinations) {
combinations.filter(isMeasuredCombination)
}

const getContentWidth = function (combinations, showStats, screenWidth) {
const getContentWidth = function (combinations, mini, screenWidth) {
return Math.max(
screenWidth -
getTitleBlockWidth(combinations) -
getMinBlockWidth(combinations, showStats) -
getMaxBlockWidth(combinations, showStats),
getMinBlockWidth(combinations, mini) -
getMaxBlockWidth(combinations, mini),
1,
)
}
Expand All @@ -38,17 +38,17 @@ const serializeBoxPlot = function ({
minAll,
maxAll,
width,
showStats,
mini,
}) {
const titleBlock = getTitleBlock(combination, showStats)
const titleBlock = getTitleBlock(combination, mini)

if (!isMeasuredCombination(combination)) {
return titleBlock
}

const minBlock = getMinBlock(quantiles, showStats)
const content = getContent({ quantiles, minAll, maxAll, showStats, width })
const maxBlock = getMaxBlock(quantiles, showStats)
const minBlock = getMinBlock(quantiles, mini)
const content = getContent({ quantiles, minAll, maxAll, mini, width })
const maxBlock = getMaxBlock(quantiles, mini)
return concatBlocks([titleBlock, minBlock, content, maxBlock])
}

Expand All @@ -58,9 +58,9 @@ const isMeasuredCombination = function ({ stats: { quantiles } }) {
}

// Retrieve sidebar with the combination name
const getTitleBlock = function (combination, showStats) {
const getTitleBlock = function (combination, mini) {
const titleBlockContents = getTitleBlockContents(combination)
const bottomNewlines = getBottomNewlines(showStats)
const bottomNewlines = getBottomNewlines(mini)
return `${titleBlockContents}\n${bottomNewlines}`
}

Expand All @@ -72,28 +72,28 @@ const getTitleBlockContents = function (combination) {
return `${getCombinationNameColor(combination)}${NAME_SEPARATOR_COLORED}`
}

const getBottomNewlines = function (showStats) {
const bottomNewlinesHeight = showStats ? LABELS_HEIGHT : 0
const getBottomNewlines = function (mini) {
const bottomNewlinesHeight = mini ? 0 : LABELS_HEIGHT
return '\n'.repeat(bottomNewlinesHeight)
}

const LABELS_HEIGHT = 1

// Retrieve the blocks that show the lowest|highest value of the histogram, on
// the left|right of it
const getBlock = function (getStat, quantiles, showStats) {
return showStats ? getStat(quantiles) : ''
const getBlock = function (getStat, quantiles, mini) {
return mini ? '' : getStat(quantiles)
}

// Retrieve the width of those blocks
const getBlockWidth = function (getStat, combinations, showStats) {
return showStats
? Math.max(
const getBlockWidth = function (getStat, combinations, mini) {
return mini
? 0
: Math.max(
...combinations.map((combination) =>
getCombinationWidth(combination, getStat),
),
)
: 0
}

const getCombinationWidth = function ({ stats: { quantiles } }, getStat) {
Expand All @@ -118,11 +118,11 @@ const getMinBlockWidth = getBlockWidth.bind(undefined, getMinStat)
const getMaxBlock = getBlock.bind(undefined, getMaxStat)
const getMaxBlockWidth = getBlockWidth.bind(undefined, getMaxStat)

const getContent = function ({ quantiles, minAll, maxAll, width, showStats }) {
const getContent = function ({ quantiles, minAll, maxAll, width, mini }) {
const positions = getPositions({ quantiles, minAll, maxAll, width })
const box = getBox(positions, width)

if (!showStats) {
if (mini) {
return box
}

Expand Down
2 changes: 1 addition & 1 deletion src/report/reporters/debug/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ const reportTerminal = function ({ combinations, screenWidth, history }) {
const statsTables = getStatsTables(combinations, screenWidth)
const timeSeries = getTimeSeries(history, combinations, screenWidth)
const histograms = serializeHistograms(combinations, {
showStats: false,
mini: true,
screenWidth,
})
return [statsTables, timeSeries, histograms].join('\n\n')
Expand Down
2 changes: 1 addition & 1 deletion src/report/reporters/histogram.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { serializeHistograms } from '../utils/histogram/main.js'

// Reporter showing distribution of measures with a histogram
const reportTerminal = function ({ combinations, screenWidth }) {
return serializeHistograms(combinations, { showStats: true, screenWidth })
return serializeHistograms(combinations, { mini: false, screenWidth })
}

export const histogram = { reportTerminal }
4 changes: 2 additions & 2 deletions src/report/utils/histogram/content.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ export const getContent = function ({
stats: { histogram },
height,
width,
showStats,
mini,
}) {
const { positions, meanIndex, meanMaxWidth } = getMeanPositions(stats, width)
const rows = getHistogramRows({
Expand All @@ -19,7 +19,7 @@ export const getContent = function ({
meanMaxWidth,
})

if (!showStats) {
if (mini) {
return rows
}

Expand Down
22 changes: 11 additions & 11 deletions src/report/utils/histogram/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,25 +13,25 @@ import { getTitleBlock, getTitleBlockWidth } from './title.js'
// Serialize combinations' histograms for reporting
export const serializeHistograms = function (
combinations,
{ showStats, screenWidth },
{ mini, screenWidth },
) {
const height = DEFAULT_HEIGHT
const width = getContentWidth(combinations, showStats, screenWidth)
const width = getContentWidth(combinations, mini, screenWidth)
return combinations
.map((combination) =>
serializeHistogram({ combination, width, height, showStats }),
serializeHistogram({ combination, width, height, mini }),
)
.join('\n')
}

const DEFAULT_HEIGHT = 2 * EXTRA_HEIGHT

const getContentWidth = function (combinations, showStats, screenWidth) {
const getContentWidth = function (combinations, mini, screenWidth) {
return Math.max(
screenWidth -
getTitleBlockWidth(combinations) -
getMinBlockWidth(combinations, showStats) -
getMaxBlockWidth(combinations, showStats),
getMinBlockWidth(combinations, mini) -
getMaxBlockWidth(combinations, mini),
1,
)
}
Expand All @@ -41,17 +41,17 @@ const serializeHistogram = function ({
combination: { stats },
width,
height,
showStats,
mini,
}) {
const titleBlock = getTitleBlock(combination, height, showStats)
const titleBlock = getTitleBlock(combination, height, mini)

if (hasLowLoops(stats)) {
return titleBlock
}

const minBlock = getMinBlock({ stats, height, showStats })
const content = getContent({ stats, height, width, showStats })
const maxBlock = getMaxBlock({ stats, height, showStats })
const minBlock = getMinBlock({ stats, height, mini })
const content = getContent({ stats, height, width, mini })
const maxBlock = getMaxBlock({ stats, height, mini })
return concatBlocks([titleBlock, minBlock, content, maxBlock])
}

Expand Down
8 changes: 4 additions & 4 deletions src/report/utils/histogram/min_max.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ import { TICK_LEFT, TICK_RIGHT } from './characters.js'

// Retrieve the blocks that show the lowest|highest value of the histogram, on
// the left|right of it
const getBlock = function (getStat, { stats, height, showStats }) {
if (!showStats) {
const getBlock = function (getStat, { stats, height, mini }) {
if (mini) {
return ''
}

Expand All @@ -17,8 +17,8 @@ const getBlock = function (getStat, { stats, height, showStats }) {
}

// Retrieve the width of those blocks
const getBlockWidth = function (getStat, combinations, showStats) {
if (!showStats) {
const getBlockWidth = function (getStat, combinations, mini) {
if (mini) {
return 0
}

Expand Down
14 changes: 7 additions & 7 deletions src/report/utils/histogram/title.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ import { NAME_SEPARATOR_COLORED } from '../separator.js'
import { ABSCISSA_BOTTOM_HEIGHT, ABSCISSA_LABELS_HEIGHT } from './abscissa.js'

// Retrieve sidebar with the combination name
export const getTitleBlock = function (combination, height, showStats) {
const topNewlines = getTopNewlines(height, showStats)
const bottomNewlines = getBottomNewlines(showStats)
export const getTitleBlock = function (combination, height, mini) {
const topNewlines = getTopNewlines(height, mini)
const bottomNewlines = getBottomNewlines(mini)
const titleBlockContents = getTitleBlockContents(combination)
return `${topNewlines}${titleBlockContents}\n${bottomNewlines}`
}
Expand All @@ -21,12 +21,12 @@ const getTitleBlockContents = function (combination) {
return `${getCombinationNameColor(combination)}${NAME_SEPARATOR_COLORED}`
}

const getTopNewlines = function (height, showStats) {
const topNewlinesHeight = height - (showStats ? 0 : ABSCISSA_BOTTOM_HEIGHT)
const getTopNewlines = function (height, mini) {
const topNewlinesHeight = height - (mini ? ABSCISSA_BOTTOM_HEIGHT : 0)
return '\n'.repeat(topNewlinesHeight)
}

const getBottomNewlines = function (showStats) {
const bottomNewlinesHeight = showStats ? ABSCISSA_LABELS_HEIGHT : 0
const getBottomNewlines = function (mini) {
const bottomNewlinesHeight = mini ? 0 : ABSCISSA_LABELS_HEIGHT
return '\n'.repeat(bottomNewlinesHeight)
}

0 comments on commit e2c6bcc

Please sign in to comment.