Skip to content

Commit

Permalink
fix custom dim label (#704)
Browse files Browse the repository at this point in the history
  • Loading branch information
rafaqz committed Apr 28, 2024
1 parent dae6255 commit 37cd1eb
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 5 deletions.
2 changes: 1 addition & 1 deletion ext/DimensionalDataMakie.jl
Expand Up @@ -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),
),
Expand Down
5 changes: 3 additions & 2 deletions src/Dimensions/dimension.jl
Expand Up @@ -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
Expand All @@ -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

Expand Down
4 changes: 2 additions & 2 deletions src/plotrecipes.jl
Expand Up @@ -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
Expand Down Expand Up @@ -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))
Expand Down
1 change: 1 addition & 0 deletions test/dimension.jl
Expand Up @@ -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
Expand Down

0 comments on commit 37cd1eb

Please sign in to comment.