diff --git a/src/array.jl b/src/array.jl index bda6da0bb..ec53289c4 100644 --- a/src/array.jl +++ b/src/array.jl @@ -59,6 +59,7 @@ Base.size(A::AbDimArray) = size(data(A)) Base.axes(A::AbDimArray) = axes(data(A)) Base.iterate(A::AbDimArray, args...) = iterate(data(A), args...) Base.IndexStyle(A::AbstractDimensionalArray) = Base.IndexStyle(data(A)) +Base.parent(A::AbDimArray) = data(A) Base.@propagate_inbounds Base.getindex(A::AbDimArray, I::StandardIndices...) = rebuildsliced(A, getindex(data(A), I...), I) @@ -152,6 +153,11 @@ julia> A[Near(DateTime(2001, 5, 4)), Between(20, 50)]; """ DimensionalArray(A::AbstractArray, dims, name::String=""; refdims=(), metadata=nothing) = DimensionalArray(A, formatdims(A, _to_tuple(dims)), refdims, name, metadata) +DimensionalArray(A::AbstractDimensionalArray; dims=dims(A), refdims=refdims(A), name=name(A), metadata=metadata(A)) = + DimensionalArray(A, formatdims(data(A), _to_tuple(dims)), refdims, name, metadata) +DimensionalArray(; data, dims, refdims=(), name="", metadata=nothing) = + DimensionalArray(A, formatdims(A, _to_tuple(dims)), refdims, name, metadata) + _to_tuple(t::T where T <: Tuple) = t _to_tuple(t) = tuple(t) diff --git a/src/mode.jl b/src/mode.jl index 60d7ce4ed..aceadcac9 100644 --- a/src/mode.jl +++ b/src/mode.jl @@ -530,6 +530,7 @@ _orderof(index::AbstractArray) = begin end sorted ? Ordered(index=indord) : Unordered() end +≈ _indexorder(index::AbstractArray) = first(index) <= last(index) ? Forward() : Reverse() @@ -546,7 +547,7 @@ identify(span::Regular, dimtype::Type, index::AbstractArray) = identify(span::Regular{AutoStep}, dimtype::Type, index::AbstractRange) = Regular(step(index)) identify(span::Regular, dimtype::Type, index::AbstractRange) = begin - step(span) ≈ step(index) || throw(ArgumentError("mode step $(step(span)) does not match index step $(step(index))")) + step(span) isa Number && !(step(span) ≈ step(index)) && throw(ArgumentError("mode step $(step(span)) does not match index step $(step(index))")) span end identify(span::Irregular{Nothing}, dimtype, index) = diff --git a/src/plotrecipes.jl b/src/plotrecipes.jl index 8a72ab959..ba1e95eff 100644 --- a/src/plotrecipes.jl +++ b/src/plotrecipes.jl @@ -1,16 +1,23 @@ struct HeatMapLike end +struct ImageLike end struct WireframeLike end struct SeriesLike end struct HistogramLike end struct ViolinLike end -@recipe function f(A::AbstractDimensionalArray) +struct DimensionalPlot end + +@recipe function f(A::AbstractDimensionalArray) + DimensionalPlot(), A +end + +@recipe function f(::DimensionalPlot, A::AbstractArray) Afwd = forwardorder(A) sertype = get(plotattributes, :seriestype, :none) if !(sertype in [:marginalhist]) :title --> refdims_title(Afwd) end - if sertype in [:heatmap, :contour, :volume, :marginalhist, :image, + if sertype in [:heatmap, :contour, :volume, :marginalhist, :surface, :contour3d, :wireframe, :scatter3d] HeatMapLike(), Afwd elseif sertype in [:histogram, :stephist, :density, :barhist, :scatterhist, :ea_histogram] @@ -31,7 +38,7 @@ struct ViolinLike end end end -@recipe function f(::SeriesLike, A::AbstractDimensionalArray{T,1}) where T +@recipe function f(::SeriesLike, A::AbstractArray{T,1}) where T dim = dims(A, 1) :ylabel --> label(A) :xlabel --> label(dim) @@ -90,7 +97,11 @@ end :ylabel --> label(y) :zlabel --> label(A) :colorbar_title --> label(A) - val(x), val(y), data(A) + data(A) +end + +@recipe function f(::ImageLike, A::AbstractArray{T,2}) where T + data(A) end maybe_permute(A, dims) = all(hasdim(A, dims)) ? permutedims(A, dims) : A @@ -102,7 +113,6 @@ refdims_title(A::AbstractArray) = join(map(refdims_title, refdims(A)), ", ") refdims_title(dim::Dimension) = string(name(dim), ": ", refdims_title(mode(dim), dim)) refdims_title(mode::AbstractSampled, dim::Dimension) = begin start, stop = map(string, bounds(dim)) - println("bounds: ", bounds(dim)) if start == stop start else diff --git a/test/plotrecipes.jl b/test/plotrecipes.jl index e90ead41d..09b681600 100644 --- a/test/plotrecipes.jl +++ b/test/plotrecipes.jl @@ -10,6 +10,7 @@ sticks(da1) histogram(da1) stephist(da1) barhist(da1) +heatmap(da1) scatterhist(da1) histogram2d(da1) hline(da1) @@ -35,6 +36,8 @@ da2 = DimensionalArray(A2, (X(1:10:400), Y(1:5:100)), "Normal") # Plots plot(da2) bar(da2) +violin(da2) +boxplot(da2) sticks(da2) histogram(da2) stephist(da2) @@ -44,10 +47,11 @@ histogram2d(data(da2)) histogram2d(da2) hline(da2) vline(da2) +plot(da2; seriestype=:line) +# Don't display dims currently heatmap(da2) contour(da2) wireframe(da2) -plot(da2; seriestype=:line) # StatsPlots density(da2) @@ -57,7 +61,7 @@ violin(da2) ea_histogram(da2) # Not sure how recipes work for this -andrewsplot(da2) +# andrewsplot(da2) # TODO handle everything @@ -76,8 +80,8 @@ andrewsplot(da2) # plot(data(da2); seriestype=:barbins) # plot(data(da2); seriestype=:contour3d) # pie(da2) - +# # Crashes GR for some reason # im2 = RGB24.(rand(10, 10)) -# da_im2 = DimensionalArray(im2, (X(1:10), Y(1:10)), "Image") -# plot(da_im2; seriestype=:image) +# da_im2 = DimensionalArray(im2, (X(10:10:100), Y(10:10:100)), "Image") +# da_im2 |> plot diff --git a/test/runtests.jl b/test/runtests.jl index 01eef62dc..49db6812b 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -11,12 +11,12 @@ include("methods.jl") include("prettyprinting.jl") if !Sys.iswindows() include("plotrecipes.jl") -end -# Test documentation -docsetup = quote - using DimensionalData, Random - Random.seed!(1234) + # Test documentation + docsetup = quote + using DimensionalData, Random + Random.seed!(1234) + end + DocMeta.setdocmeta!(DimensionalData, :DocTestSetup, docsetup; recursive=true) + doctest(DimensionalData) end -DocMeta.setdocmeta!(DimensionalData, :DocTestSetup, docsetup; recursive=true) -doctest(DimensionalData) diff --git a/test/selector.jl b/test/selector.jl index 163001b65..dd76c0ba2 100644 --- a/test/selector.jl +++ b/test/selector.jl @@ -6,7 +6,6 @@ a = [1 2 3 4 5 6 7 8 9 10 11 12] -using DimensionalData dims_ = X(10:10:20; mode=Sampled(sampling=Intervals())), Y(5:7; mode=Sampled(sampling=Intervals())) A = DimensionalArray([1 2 3; 4 5 6], dims_) @@ -376,10 +375,10 @@ end for idx in indices from2d = view(da, idx) @test from2d == view(data(da), idx) - @test !(parent(from2d) isa AbstractDimensionalArray) - from1d = view(da[Y <| At(10)], idx) + @test from2d isa SubArray + from1d = view(da[Y(At(10))], idx) @test from1d == view(data(da)[1, :], idx) - @test parent(from1d) isa AbstractDimensionalArray + @test from1d isa AbstractDimensionalArray end end