Skip to content

Formatting

This library provides functions for formatting data following the SSZVIS style guide.

Formatting Functions

sszvis.formatNumber(x)

A number greater than 9'999 will have a thousands separator space. Also, numbers will be shortened if they have insignificant decimals.

FunctionExampleResult
formatNumbersszvis.formatNumber(16000)16 000
sszvis.formatNumber(5000)5000
sszvis.formatNumber(42.1)42.1
sszvis.formatNumber(42.001)42

sszvis.formatPreciseNumber(p, d)

p = The desired precision d = The number to be formatted

A number will be formatted to a particular precision. It is a function that accepts numbers and returns formatted values. This function is "curried", meaning that it is a function with multiple arguments, but when you call it with less than the full number of arguments, it returns a function that takes less arguments and has the arguments you did provide "pre-filled" as parameters.

FunctionExampleResult
formatPreciseNumbersszvis.formatPreciseNumber(2, 14.1234)14.12
sszvis.formatPreciseNumber(3, 14.1234)14.123
sszvis.formatPreciseNumber(0, 14.1234)14

sszvis.formatPercent(x)

A number will be transformed into a percent format. Formats percentages on the range 0–100.

FunctionExampleResult
formatPercentsszvis.formatPercent(55.3)55.3 %
sszvis.formatPercent(7)7 %
sszvis.formatPercent(0.245875)0.25 %

sszvis.formatFractionPercent(x)

A number will be transformed into a percent format. Format percentages on the range 0–1.

FunctionExampleResult
formatFractionPercentsszvis.formatFractionPercent(55.3)5530 %
sszvis.formatFractionPercent(7)700 %
sszvis.formatFractionPercent(0.245875)24.59 %

sszvis.formatText(x)

Any given data is returned as a string and will be formatted as Text.

FunctionExampleResult
formatTextsszvis.formatText(16000)'16000'
sszvis.formatText("Jahr")'Jahr'

sszvis.formatAge(x)

A number will be formatted as an age. Means that any decimal number will be rounded to a full number.

FunctionExampleResult
formatAgesszvis.formatAge(55.54359375)56
sszvis.formatAge(555435)555435

sszvis.formatYear(x)

A date object will be formatted as a year. Gives the date's year.

FunctionExampleResult
formatYearsszvis.formatYear(new Date())2020

sszvis.formatMonth(x)

A date object will be formatted as a month. It will return a capitalized three-letter abbreviation of the German month name.

FunctionExampleResult
formatMonthsszvis.formatMonth(new Date())JAN

sszvis.formatNone()

This is a Formatter for no label, only returning an empty string.

FunctionExampleResult
formatNonesszvis.formatNone("500 People participated.")
sszvis.formatNone(500343)

Live examples

formatNumber

In this example, all Numbers in the y-Axis greater than 9999 use a thousands separator space.

Stacked Bar Chart
Loading the chart…

formatFractionPercent

In this example, all Numbers in the y-Axis have been transformed into a percent format.

Line Chart — Ordinal
Loading the chart…