From b2162797e1556bfb420de954da1e953fc7dafe82 Mon Sep 17 00:00:00 2001 From: ehmicky Date: Sun, 5 Sep 2021 17:38:53 +0200 Subject: [PATCH] Refactoring --- src/report/reporters/histogram/width.js | 23 ++++++++++++++++++- src/report/utils/width.js | 30 ------------------------- 2 files changed, 22 insertions(+), 31 deletions(-) delete mode 100644 src/report/utils/width.js diff --git a/src/report/reporters/histogram/width.js b/src/report/reporters/histogram/width.js index 9e1c78f6e..31a56e4b1 100644 --- a/src/report/reporters/histogram/width.js +++ b/src/report/reporters/histogram/width.js @@ -1,4 +1,4 @@ -import { getColWidths } from '../../utils/width.js' +import { getCombinationPaddedName } from '../../utils/name.js' import { getPaddedStatLength } from './abscissa.js' @@ -18,3 +18,24 @@ const getHistogramColWidth = function (statName, { stats }) { ? 0 : getPaddedStatLength(stats[statName]) } + +const getColWidths = function ({ + combinations, + minWidths, + maxWidths, + mini, + screenWidth, +}) { + const titlesWidth = getCombinationPaddedName(combinations[0]).length + const minBlockWidth = getMinMaxBlockWidth(combinations, mini, minWidths) + const maxBlockWidth = getMinMaxBlockWidth(combinations, mini, maxWidths) + const contentWidth = Math.max( + screenWidth - titlesWidth - minBlockWidth - maxBlockWidth, + 1, + ) + return { titlesWidth, minBlockWidth, contentWidth } +} + +const getMinMaxBlockWidth = function (combinations, mini, widths) { + return mini ? 0 : Math.max(...widths) +} diff --git a/src/report/utils/width.js b/src/report/utils/width.js deleted file mode 100644 index ea32f27db..000000000 --- a/src/report/utils/width.js +++ /dev/null @@ -1,30 +0,0 @@ -import { getCombinationPaddedName } from './name.js' - -// Compute the width of each column for reporters which show the following ones -// for each combination: -// - Title -// - Min -// - Main content -// - Max -// This is used for example by the `histogram` and `boxplot` reporters. -// Using shared logic ensures those reporters are aligned when shown together. -export const getColWidths = function ({ - combinations, - minWidths, - maxWidths, - mini, - screenWidth, -}) { - const titlesWidth = getCombinationPaddedName(combinations[0]).length - const minBlockWidth = getMinMaxBlockWidth(combinations, mini, minWidths) - const maxBlockWidth = getMinMaxBlockWidth(combinations, mini, maxWidths) - const contentWidth = Math.max( - screenWidth - titlesWidth - minBlockWidth - maxBlockWidth, - 1, - ) - return { titlesWidth, minBlockWidth, contentWidth } -} - -const getMinMaxBlockWidth = function (combinations, mini, widths) { - return mini ? 0 : Math.max(...widths) -}