GitHunt
MI

michakraus/Showoff.jl

Nicely format an array of n things for tables and plots

Showoff

Build Status
Coverage Status

Showoff provides an interface for consistently formatting an array of n things,
e.g. numbers, dates, unitful values. It's used in Gadfly, Plots and Makie to
label axes and keys.

It defines a function called showoff that takes an AbstractArray of some
type, and returns an array of strings of the same length.

If you want your type to look nice when plotted, just define a showoff
function. Here's an example.

using Showoff

struct Percent
    value::Float64
end

function Showoff.showoff(xs::AbstractArray{Percent})
    return [string(x, "%") for x in showoff([x.value for x in xs])]
end

Now we (and more importantly, Gadfly) can print percentages like:

map(println, showoff([Percent(100 * rand()) for _ in 1:20]))
60.505943%
73.255897%
97.477079%
43.330976%
69.023165%
52.580184%
13.011683%
22.718034%
93.843776%
29.875979%
64.110999%
91.203653%
91.534161%
80.684188%
81.674362%
11.530227%
30.498260%
38.876922%
35.444115%
8.857208%

Notice, that compared to show, these all have the same number of digits
trailing the ., and look nice when right-aligned.

When no specialized showoff is defined, it falls back on the show function.

This package was originally written by Daniel C. Jones.

Languages

Julia100.0%
Other
Created March 11, 2020
Updated November 27, 2020