Skip to content

Commit

Permalink
Fix histogram
Browse files Browse the repository at this point in the history
  • Loading branch information
ehmicky committed Aug 29, 2021
1 parent c3834f4 commit 3f13e05
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 12 deletions.
5 changes: 3 additions & 2 deletions src/report/reporters/debug/main.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { serializeHistograms } from '../../utils/histogram/main.js'
import { joinSections } from '../../utils/join.js'
import { joinSections, joinSubSections } from '../../utils/join.js'
import { prettifyStats } from '../../utils/stats/main.js'
import { addTitles } from '../../utils/title.js'

Expand All @@ -17,7 +17,8 @@ const reportTerminal = function ({ combinations, screenWidth, history }) {
showStats: false,
screenWidth,
})
return joinSections([tables, timeSeries, ...histograms])
const histogram = joinSubSections(histograms)
return joinSections([tables, timeSeries, histogram])
}

export const debug = { reportTerminal, debugStats: true }
4 changes: 2 additions & 2 deletions src/report/reporters/histogram.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { serializeHistograms } from '../utils/histogram/main.js'
import { joinSections } from '../utils/join.js'
import { joinSubSections } from '../utils/join.js'
import { prettifyStats } from '../utils/stats/main.js'
import { addTitles } from '../utils/title.js'

Expand All @@ -11,7 +11,7 @@ const reportTerminal = function ({ combinations, screenWidth }) {
showStats: true,
screenWidth,
})
return joinSections(histograms)
return joinSubSections(histograms)
}

export const histogram = { reportTerminal }
5 changes: 5 additions & 0 deletions src/report/utils/histogram/abscissa.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,3 +87,8 @@ const trimWidth = function (labels, labelsLength, width) {

return labelsA
}

// How many terminal lines the bottom line takes
export const ABSCISSA_BOTTOM_HEIGHT = 1
// How many terminal lines the labels take
export const ABSCISSA_LABELS_HEIGHT = 1
21 changes: 13 additions & 8 deletions src/report/utils/histogram/title.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,14 @@ import stringWidth from 'string-width'
import { getCombinationNameColor } from '../name.js'
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 newlines = getNewlines(height, showStats)
return `${newlines}${getTitleBlockContents(combination)}`
const topNewlines = getTopNewlines(height, showStats)
const bottomNewlines = getBottomNewlines(showStats)
const titleBlockContents = getTitleBlockContents(combination)
return `${topNewlines}${titleBlockContents}\n${bottomNewlines}`
}

export const getTitleBlockWidth = function ([combination]) {
Expand All @@ -17,11 +21,12 @@ const getTitleBlockContents = function (combination) {
return `${getCombinationNameColor(combination)}${NAME_SEPARATOR_COLORED}`
}

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

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

0 comments on commit 3f13e05

Please sign in to comment.