Skip to content

Commit

Permalink
fix:formatters allow for no formatting (#328)
Browse files Browse the repository at this point in the history
  • Loading branch information
zoesteinkamp authored Oct 21, 2020
1 parent e88b79f commit c1c1fb9
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions giraffe/src/utils/formatters.ts
Original file line number Diff line number Diff line change
Expand Up @@ -259,13 +259,15 @@ interface BinaryPrefixFormatterFactoryOptions {
suffix?: string
significantDigits?: number
trimZeros?: boolean
format?: boolean
}

export const binaryPrefixFormatter = ({
prefix = '',
suffix = '',
significantDigits = 6,
trimZeros = true,
format = true,
}: BinaryPrefixFormatterFactoryOptions = {}): BinaryPrefixFormatter => {
const formatSigFigs = d3Format(
`.${significantDigits}${trimZeros ? '~' : ''}f`
Expand All @@ -279,6 +281,10 @@ export const binaryPrefixFormatter = ({

const decimalFormattedNumber = formatSigFigs(binaryFormattedNumber)

if (format != true) {
return `${prefix}${x}${suffix}`
}

return `${prefix}${decimalFormattedNumber}${binaryPrefix}${suffix}`
}

Expand All @@ -300,20 +306,25 @@ interface SIPrefixFormatterFactoryOptions {
suffix?: string
significantDigits?: number
trimZeros?: boolean
format?: boolean
}

export const siPrefixFormatter = ({
prefix = '',
suffix = '',
significantDigits = 6,
trimZeros = true,
format = true,
}: SIPrefixFormatterFactoryOptions = {}): SIPrefixFormatter => {
let formatter
const formatSIPrefix = d3Format(
`.${significantDigits}${trimZeros ? '~' : ''}s`
)

const formatter = (x: number): string =>
`${prefix}${formatSIPrefix(x)}${suffix}`
if (format != true) {
formatter = (x: number): string => `${prefix}${x}${suffix}`
}
formatter = (x: number): string => `${prefix}${formatSIPrefix(x)}${suffix}`

formatter._GIRAFFE_FORMATTER_TYPE = FormatterType.SIPrefix as FormatterType.SIPrefix

Expand Down

0 comments on commit c1c1fb9

Please sign in to comment.