Skip to content

Commit

Permalink
Fix linting
Browse files Browse the repository at this point in the history
  • Loading branch information
ehmicky committed Sep 5, 2021
1 parent 5432ffc commit 7cf76ff
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 56 deletions.
35 changes: 6 additions & 29 deletions src/report/reporters/boxplot/width.js
Original file line number Diff line number Diff line change
@@ -1,38 +1,15 @@
import { getCombinationPaddedName } from '../../utils/name.js'
import { getColWidths } from '../../utils/width.js'

import { getPaddedStatLength } from './box.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.
// Compute the width of each column.
export const getWidths = function (combinations, mini, screenWidth) {
const titlesWidth = getCombinationPaddedName(combinations[0]).length
const minBlockWidth = getMinMaxBlockWidth(combinations, mini, 'min')
const maxBlockWidth = getMinMaxBlockWidth(combinations, mini, 'max')
const contentWidth = Math.max(
screenWidth - titlesWidth - minBlockWidth - maxBlockWidth,
1,
)
return { titlesWidth, minBlockWidth, contentWidth }
const minWidths = combinations.map(getBoxPlotColWidth.bind(undefined, 'min'))
const maxWidths = combinations.map(getBoxPlotColWidth.bind(undefined, 'max'))
return getColWidths({ combinations, minWidths, maxWidths, mini, screenWidth })
}

const getMinMaxBlockWidth = function (combinations, mini, statName) {
if (mini) {
return 0
}

return Math.max(
...combinations.map((combination) =>
getSingleMinMaxWidth(combination, statName),
),
)
}

const getSingleMinMaxWidth = function ({ quantiles }, statName) {
const getBoxPlotColWidth = function (statName, { quantiles }) {
return quantiles === undefined
? 0
: getPaddedStatLength(quantiles[statName].pretty)
Expand Down
35 changes: 8 additions & 27 deletions src/report/reporters/histogram/width.js
Original file line number Diff line number Diff line change
@@ -1,38 +1,19 @@
import { getCombinationPaddedName } from '../../utils/name.js'
import { getColWidths } from '../../utils/width.js'

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

// Compute the width of each columns 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.
// Compute the width of each column.
export const getWidths = function (combinations, mini, screenWidth) {
const titlesWidth = getCombinationPaddedName(combinations[0]).length
const minBlockWidth = getMinMaxBlockWidth(combinations, mini, 'min')
const maxBlockWidth = getMinMaxBlockWidth(combinations, mini, 'max')
const contentWidth = Math.max(
screenWidth - titlesWidth - minBlockWidth - maxBlockWidth,
1,
const minWidths = combinations.map(
getHistogramColWidth.bind(undefined, 'min'),
)
return { titlesWidth, minBlockWidth, contentWidth }
}

const getMinMaxBlockWidth = function (combinations, mini, statName) {
if (mini) {
return 0
}

return Math.max(
...combinations.map((combination) =>
getSingleMinMaxWidth(combination, statName),
),
const maxWidths = combinations.map(
getHistogramColWidth.bind(undefined, 'max'),
)
return getColWidths({ combinations, minWidths, maxWidths, mini, screenWidth })
}

const getSingleMinMaxWidth = function ({ stats }, statName) {
const getHistogramColWidth = function (statName, { stats }) {
return stats[statName] === undefined
? 0
: getPaddedStatLength(stats[statName])
Expand Down
30 changes: 30 additions & 0 deletions src/report/utils/width.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
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)
}

0 comments on commit 7cf76ff

Please sign in to comment.