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 b972523 commit 568200c
Showing 1 changed file with 28 additions and 18 deletions.
46 changes: 28 additions & 18 deletions src/report/reporters/boxplot/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -135,10 +135,25 @@ const serializeBoxPlot = function ({
return titleBlock
}

const minBlock = getMinMaxBlock(quantiles, 'min', mini)
const content = getContent({ quantiles, minAll, maxAll, mini, contentWidth })
const maxBlock = getMinMaxBlock(quantiles, 'max', mini)
return concatBlocks([titleBlock, minBlock, content, maxBlock])
if (mini) {
const miniContent = getMiniContent({
quantiles,
minAll,
maxAll,
contentWidth,
})
return concatBlocks([titleBlock, miniContent])
}

const minBlock = getMinMaxBlock(quantiles, 'min')
const fullContent = getFullContent({
quantiles,
minAll,
maxAll,
contentWidth,
})
const maxBlock = getMinMaxBlock(quantiles, 'max')
return concatBlocks([titleBlock, minBlock, fullContent, maxBlock])
}

// When the combination has not been measured yet
Expand All @@ -165,8 +180,8 @@ const getBottomNewlines = function (mini) {
const LABELS_HEIGHT = 1

// Retrieve the blocks that show the min|max on the left|right
const getMinMaxBlock = function (quantiles, statName, mini) {
return mini ? '' : getStat(quantiles, statName)
const getMinMaxBlock = function (quantiles, statName) {
return getStat(quantiles, statName)
}

// Retrieve the width of those blocks
Expand Down Expand Up @@ -196,25 +211,20 @@ const addPadding = function (string) {
return `${PADDING}${string}${PADDING}`
}

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

if (mini) {
return box
}

const labels = getLabels(positions, contentWidth)
return `${box}
${labels}`
}

const getMiniContent = function ({ quantiles, minAll, maxAll, contentWidth }) {
const positions = getPositions({ quantiles, minAll, maxAll, contentWidth })
const box = getBox(positions, contentWidth)
return box
}

const getPositions = function ({ quantiles, minAll, maxAll, contentWidth }) {
return mapObj(quantiles, (name, stat) =>
getPosition({ name, stat, minAll, maxAll, contentWidth }),
Expand Down

0 comments on commit 568200c

Please sign in to comment.