Closed ggebbie closed 2 months ago
Do you have a screen shot? I don't really use Pluto so I don't run into this
A 3x3 DimArray has a large offset between the Dimension label and numerical values such that the output needs to hide a column to fit on the screen.
edit: looks like I can simplify my statement with
Vol = fill(Vol0, model_dims)
edit2: the units are uniform and could be written "outside" of the matrix instead of applied to each element. This would save space.
For a variable without units, all entries of the 3x3 matrix can be viewed on screen.
Changing the printing style via
ENV["UNITFUL_FANCY_EXPONENTS"] = true
or false makes no difference.
Interesting, it could be DD, but I would guess that Unitful.jl is not telling Julia how to print unitful quantities properly in a mixed array. Notice that the string is offset to the end of the whole number rather than the decimal point like it is without units. That's just the Base.print_matrix
behaviour of units, not something I specifically wrote for DD.
Probably DD should stop using these base matrix display methods, as they're buggy like this, but it's a bit of work to write the layout logic from scratch.
Yes, looks like this is unitful. To demonstrate with a mixed unit matrix: the decimal points should line up, but we have the same horrible effect as in DD printing.
julia> using Unitful
julia> [1.99809802u"s" 2.339098; 1.0 2.0u"km/hr"]
2×2 Matrix{Quantity{Float64}}:
1.9981 s 2.3391
1.0 2.0 km hr^-1
And thats because they don't define a Base.alignment
method so it hits the fallback for Number
,
which puts everything to the left of the decimal point. This fixes the problem for me:
function Base.alignment(io::IO, x::Unitful.Quantity)
total = Base.alignment_from_show(io, x)[1]
parent = Base.alignment(io, ustrip(x))
return parent[1], parent[2] + total - sum(parent)
end
So:
julia> [1.99809802u"s" 2.339098; 1.0 2.0u"km/hr"]
2×2 Matrix{Quantity{Float64}}:
1.9981 s 2.3391
1.0 2.0 km hr^-1
And DD printing looks fine to me too.
Looks really nice now. I think this will make a big impact for those who are trying to follow my Pluto notebook, plus it will help emphasize the usefulness of DimensionalData.jl. Much appreciated!
Updated printing:
A 3x3 DimArray with units on the parent matrix cannot be fully displayed to screen in a Pluto notebook.