Skip to content

Commit

Permalink
Improve stats prettify
Browse files Browse the repository at this point in the history
  • Loading branch information
ehmicky committed Sep 5, 2021
1 parent 6883916 commit 287a173
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 25 deletions.
30 changes: 16 additions & 14 deletions src/report/normalize/stats/colors.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,26 +13,28 @@ export const addStatColor = function ({
return combination
}

const { raw, pretty, prettyPadded } = stat
const prettyColor = addItemsColor(pretty, { raw, name, stats })
const prettyPaddedColor = addItemsColor(prettyPadded, { raw, name, stats })
return {
...combination,
stats: { ...stats, [name]: { ...stat, prettyColor, prettyPaddedColor } },
}
const statA = Array.isArray(stat)
? stat.map((singleStat) => addItemsColor({ stat: singleStat, name, stats }))
: addItemsColor({ stat })
return { ...combination, stats: { ...stats, [name]: statA } }
}

const addItemsColor = function ({
stat,
stat: { raw, pretty, prettyPadded },
name,
stats,
}) {
const prettyColor = addItemColor(pretty, { raw, name, stats })
const prettyPaddedColor = addItemColor(prettyPadded, { raw, name, stats })
return { ...stat, prettyColor, prettyPaddedColor }
}

const addItemsColor = function (pretty, { raw, name, stats }) {
const addItemColor = function (pretty, { raw, name, stats }) {
if (pretty === '') {
return ''
}

return Array.isArray(pretty)
? pretty.map((item) => addItemColor(item, { raw, name, stats }))
: addItemColor(pretty, { raw, name, stats })
}

const addItemColor = function (pretty, { raw, name, stats }) {
const prettyA = addSuffixColors(pretty)
const prettyB = addSpecificColors(prettyA, { raw, name, stats })
return prettyB
Expand Down
17 changes: 9 additions & 8 deletions src/report/normalize/stats/padding.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,13 @@ const addItemsPadded = function ({
return combination
}

const { pretty } = stat
const prettyPadded = Array.isArray(pretty)
? pretty.map((item) => item.padStart(padding))
: pretty.padStart(padding)
return {
...combination,
stats: { ...stats, [name]: { ...stat, prettyPadded } },
}
const statA = Array.isArray(stat)
? stat.map((singleStat) => addItemPadded(singleStat, padding))
: addItemPadded(stat, padding)
return { ...combination, stats: { ...stats, [name]: statA } }
}

const addItemPadded = function (stat, padding) {
const prettyPadded = stat.pretty.padStart(padding)
return { ...stat, prettyPadded }
}
6 changes: 3 additions & 3 deletions src/report/normalize/stats/prettify.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,18 +45,18 @@ const addStatPretty = function ({
return combination
}

const pretty = Array.isArray(raw)
const stat = Array.isArray(raw)
? raw.map((item) =>
addItemPretty({ raw: item, signed, scale, unit, decimals, stats }),
)
: addItemPretty({ raw, signed, scale, unit, decimals, stats })
return { ...combination, stats: { ...stats, [name]: { raw, pretty } } }
return { ...combination, stats: { ...stats, [name]: stat } }
}

const addItemPretty = function ({ raw, signed, scale, unit, decimals, stats }) {
const scaledRaw = raw / scale
const roundedRaw = scaledRaw.toFixed(decimals)
const pretty = `${roundedRaw}${unit}`
const prettyA = addSign(pretty, signed, stats)
return prettyA
return { raw, pretty: prettyA }
}

0 comments on commit 287a173

Please sign in to comment.