Skip to content

Commit

Permalink
Makie plot tweaks and fixes (#582)
Browse files Browse the repository at this point in the history
* add Image to makie convert

* add shiftlocus methods for Dimensions and objects with dimensions

* generalise image to AbstractPlot and fix pixel location

* reorganise
  • Loading branch information
rafaqz authored Dec 20, 2023
1 parent f25fb78 commit 019ff7c
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 4 deletions.
9 changes: 7 additions & 2 deletions ext/DimensionalDataMakie.jl
Original file line number Diff line number Diff line change
Expand Up @@ -346,6 +346,11 @@ Makie.plottype(A::AbstractDimArray{<:Any,2}) = Makie.Heatmap
Makie.plottype(A::AbstractDimArray{<:Any,3}) = Makie.Volume

# Conversions
function Makie.convert_arguments(t::Type{<:Makie.AbstractPlot}, A::AbstractDimArray{<:Any,2})
A1 = _prepare_for_makie(A)
xs, ys = map(parent, lookup(A1))
return xs, ys, last(Makie.convert_arguments(t, parent(A1)))
end
function Makie.convert_arguments(t::Makie.PointBased, A::AbstractDimArray{<:Any,1})
A = _prepare_for_makie(A)
xs = parent(lookup(A, 1))
Expand Down Expand Up @@ -432,8 +437,8 @@ function _split_attributes(dim::Dimension)
return attributes, dims[1]
end

function _prepare_for_makie(A, replacements=())
A1 = _permute_xyz(A, replacements) |> _reorder
function _prepare_for_makie(A, replacements=())
_permute_xyz(maybeshiftlocus(Center(), A; dims=(XDim, YDim)), replacements) |> _reorder
end

# Permute the data after replacing the dimensions with X/Y/Z
Expand Down
12 changes: 10 additions & 2 deletions src/Dimensions/dimension.jl
Original file line number Diff line number Diff line change
Expand Up @@ -192,8 +192,16 @@ LookupArrays.index(dim::Dimension{<:Val}) = unwrap(index(val(dim)))

LookupArrays.bounds(dim::Dimension) = bounds(val(dim))
LookupArrays.intervalbounds(dim::Dimension, args...) = intervalbounds(val(dim), args...)
LookupArrays.shiftlocus(locus::Locus, dim::Dimension) = rebuild(dim, shiftlocus(locus, lookup(dim)))
LookupArrays.maybeshiftlocus(locus::Locus, d::Dimension) = rebuild(d, maybeshiftlocus(locus, lookup(d)))
for f in (:shiftlocus, :maybeshiftlocus)
@eval function LookupArrays.$f(locus::Locus, x; dims=Dimensions.dims(x))
newdims = map(Dimensions.dims(x, dims)) do d
LookupArrays.$f(locus, d)
end
return setdims(x, newdims)
end
@eval LookupArrays.$f(locus::Locus, d::Dimension) =
rebuild(d, LookupArrays.$f(locus, lookup(d)))
end

function hasselection(x, selectors::Union{DimTuple,SelTuple,Selector,Dimension})
hasselection(dims(x), selectors)
Expand Down
13 changes: 13 additions & 0 deletions src/Dimensions/utils.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
for f in (:shiftlocus, :maybeshiftlocus)
@eval begin
function LookupArrays.$f(locus::Locus, x; dims=Dimensions.dims(x))
newdims = map(Dimensions.dims(x, dims)) do d
LookupArrays.$f(locus, d)
end
return setdims(x, newdims)
end
function LookupArrays.$f(locus::Locus, d::Dimension)
rebuild(d, LookupArrays.$f(locus, lookup(d)))
end
end
end

0 comments on commit 019ff7c

Please sign in to comment.