rafaqz / DimensionalData.jl

Named dimensions and indexing for julia arrays and other data
https://rafaqz.github.io/DimensionalData.jl/stable/
MIT License
282 stars 42 forks source link

Allow dimensions to be used as AlgebraOfGraphics selectors #823

Closed asinghvi17 closed 2 weeks ago

asinghvi17 commented 1 month ago

This adds AoG selector support to DimensionalData dims, so that things like this just work:

A3 = DimArray(rand(21, 5, 4), (X, Y, Dim{:p}); name = :RandomData)
data(A3) * visual(Heatmap) * mapping(X, :RandomData, Dim{:p}, layout = Y => nonnumeric) |> draw

# before this, you would have to use and know the specific symbols that the dims are:
data(A3) * visual(Heatmap) * mapping(:X, :RandomData,:p, layout = :Y => nonnumeric) |> draw

They actually work anywhere by getting the dimension symbol from DD.name, so you can run these on data(DataFrame(dimtable)) with X as well!

Fix #821

rafaqz commented 1 month ago

Can you add a before/after for that example? Just to know what we gain from the extension

(Would you need to use an Int instead of Y or a Symbol?)

asinghvi17 commented 1 month ago

Before you would just have to put a symbol. But here you can put the dimension type directly. You can also select dimensions with e.g. DD.XDim if you're not sure what the name is, since on a DimTable this actually queries dimensions.

So something like data(some_dimarray_lat_lon_axes) * mapping(XDim, YDim, color = :RandomData) * visual(Scatter) just works. Even if the dim names are Lon and Lat, if they're subtypes of XDim and YDim the selectors will do the job.

rafaqz commented 1 month ago

Ok I'm in

asinghvi17 commented 1 month ago

Ah didn't know that was a thing! Will add it.

rafaqz commented 2 weeks ago

Thanks!!!!