From 37cd1eb53c1f86750318315e1471e7e59a678896 Mon Sep 17 00:00:00 2001 From: Rafael Schouten Date: Sun, 28 Apr 2024 15:33:53 +0200 Subject: [PATCH] fix custom dim label (#704) --- ext/DimensionalDataMakie.jl | 2 +- src/Dimensions/dimension.jl | 5 +++-- src/plotrecipes.jl | 4 ++-- test/dimension.jl | 1 + 4 files changed, 7 insertions(+), 5 deletions(-) diff --git a/ext/DimensionalDataMakie.jl b/ext/DimensionalDataMakie.jl index e9dda35a7..4bf582fe5 100644 --- a/ext/DimensionalDataMakie.jl +++ b/ext/DimensionalDataMakie.jl @@ -97,7 +97,7 @@ function _pointbased1(A, attributes; set_axis_attributes=true) axis_attributes = if set_axis_attributes Attributes(; axis=(; - xlabel=string(name(dims(A, 1))), + xlabel=string(label(dims(A, 1))), ylabel=DD.label(A), title=DD.refdims_title(A), ), diff --git a/src/Dimensions/dimension.jl b/src/Dimensions/dimension.jl index d1b8c603a..297a0e4cf 100644 --- a/src/Dimensions/dimension.jl +++ b/src/Dimensions/dimension.jl @@ -419,7 +419,7 @@ macro dim(typ::Symbol, supertyp::Symbol, args...) dimmacro(typ, supertyp, args...) end -function dimmacro(typ, supertype, name::String=string(typ)) +function dimmacro(typ, supertype, label::String=string(typ)) quote Base.@__doc__ struct $typ{T} <: $supertype{T} val::T @@ -439,8 +439,9 @@ function dimmacro(typ, supertype, name::String=string(typ)) end $typ() = $typ(:) $Dimensions.name(::Type{<:$typ}) = $(QuoteNode(Symbol(typ))) - $Dimensions.label(::Type{<:$typ}) = $name $Dimensions.name2dim(::Val{$(QuoteNode(typ))}) = $typ() + $Dimensions.label(::$typ) = $label + $Dimensions.label(::Type{<:$typ}) = $label end |> esc end diff --git a/src/plotrecipes.jl b/src/plotrecipes.jl index 2ee1627ea..7781045dc 100644 --- a/src/plotrecipes.jl +++ b/src/plotrecipes.jl @@ -48,7 +48,7 @@ end dim = dims(A, 1) :xguide --> label(dim) :yguide --> label(A) - :label --> string(name(A)) + :label --> string(label(A)) _xticks!(plotattributes, s, dim) _withaxes(dim, A) end @@ -169,7 +169,7 @@ function refdims_title(refdims::Tuple; kw...) join(map(rd -> refdims_title(rd; kw...), refdims), ", ") end function refdims_title(refdim::Dimension; kw...) - string(name(refdim), ": ", refdims_title(lookup(refdim), refdim; kw...)) + string(label(refdim), ": ", refdims_title(lookup(refdim), refdim; kw...)) end function refdims_title(lookup::AbstractSampled, refdim::Dimension; kw...) start, stop = map(string, bounds(refdim)) diff --git a/test/dimension.jl b/test/dimension.jl index 2231b07f5..dbcb6b622 100644 --- a/test/dimension.jl +++ b/test/dimension.jl @@ -11,6 +11,7 @@ using DimensionalData.Lookups, DimensionalData.Dimensions @test metadata(TestDim(Sampled(1:1; metadata=Metadata(a=1)))) == Metadata(a=1) @test units(TestDim) == nothing @test label(TestDim) == "Testname" + @test label(TestDim()) == "Testname" @test eltype(TestDim(1)) == Int @test eltype(TestDim([1, 2, 3])) <: Int @test length(TestDim(1)) == 1