Skip to content

Commit

Permalink
Move file
Browse files Browse the repository at this point in the history
  • Loading branch information
ehmicky committed Sep 5, 2021
1 parent 8ea03b9 commit e701e24
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 49 deletions.
46 changes: 0 additions & 46 deletions src/report/reporters/histogram/content.js

This file was deleted.

52 changes: 50 additions & 2 deletions src/report/reporters/histogram/main.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import { getCombNamePaddedColor } from '../../utils/name.js'

import { getAbscissa } from './abscissa.js'
import { EXTRA_HEIGHT } from './characters.js'
import { getContent } from './content.js'
import { getEmptyCombination } from './empty.js'
import { getHistogramRows } from './rows.js'
import { getWidths } from './width.js'

// Reporter showing distribution of measures with a histogram
Expand Down Expand Up @@ -61,4 +62,51 @@ const serializeHistogram = function ({
})
}

export const histogram = { reportTerminal, capabilities: { debugStats: true } }
// Retrieve histogram main content
const getContent = function ({
stats: { histogram, median, min, max },
height,
combinationTitles,
titleBlockWidth,
minBlockWidth,
contentWidth,
mini,
}) {
const medianIndex = getMedianIndex({ median, min, max, contentWidth })
const rows = getHistogramRows({
histogram,
combinationTitles,
titleBlockWidth,
minBlockWidth,
contentWidth,
height,
medianIndex,
mini,
})
const abscissa = mini
? ''
: getAbscissa({
combinationTitles,
titleBlockWidth,
minBlockWidth,
contentWidth,
median,
medianIndex,
min,
max,
})
return `${rows}${abscissa}`
}

// Compute the position of the median tick on the screen.
// When `histogram` has a single item, it is in the first bucket.
const getMedianIndex = function ({ median, min, max, contentWidth }) {
const percentage =
max.raw === min.raw ? 0 : (median.raw - min.raw) / (max.raw - min.raw)
return Math.min(Math.floor(percentage * contentWidth), contentWidth - 1)
}

export const histogramReporter = {
reportTerminal,
capabilities: { debugStats: true },
}
2 changes: 1 addition & 1 deletion src/report/reporters/main.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { boxplot } from './boxplot/main.js'
import { debug } from './debug.js'
import { histogram } from './histogram/main.js'
import { histogramReporter as histogram } from './histogram/main.js'
import { historyReporter as history } from './history.js'

export const REPORTERS = { debug, boxplot, histogram, history }

0 comments on commit e701e24

Please sign in to comment.