diff --git a/Project.toml b/Project.toml index 1d805e43..17fe2838 100644 --- a/Project.toml +++ b/Project.toml @@ -10,6 +10,7 @@ Dates = "ade2ca70-3891-5945-98fb-dc099432e06a" FFMPEG = "c87230d0-a227-11e9-1b43-d7ebe4e7570a" FixedPointNumbers = "53c48c17-4a7d-5ca2-90c5-79b7896eea93" GR = "28b8d3ca-fb5f-59d9-8090-bfdbd6d07a71" +GeometryBasics = "5c1252a2-5f33-56bf-86c9-59e7332b4326" GeometryTypes = "4d00f742-c7ba-57c2-abde-4428a4b178cb" JSON = "682c06a0-de6a-54ab-a142-c8b1cf79cde6" LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e" @@ -51,6 +52,7 @@ StatsBase = "0.32, 0.33" julia = "1" [extras] +Distributions = "31c24e10-a181-5473-b8eb-7969acd0382f" FileIO = "5789e2e9-d7fb-5bc7-8068-2c6fae9b9549" Gtk = "4c0ca9eb-093a-5379-98c5-f87ac0bbbf44" HDF5 = "f67ccb44-e63f-5c2f-98bd-6dc0ccc4ba2f" @@ -67,4 +69,4 @@ UnicodePlots = "b8865327-cd53-5732-bb35-84acbb429228" VisualRegressionTests = "34922c18-7c2a-561c-bac1-01e79b2c4c92" [targets] -test = ["FileIO", "Gtk", "ImageMagick", "Images", "LibGit2", "OffsetArrays", "PGFPlotsX", "HDF5", "RDatasets", "StaticArrays", "StatsPlots", "Test", "UnicodePlots", "VisualRegressionTests"] +test = ["Distributions", "FileIO", "Gtk", "ImageMagick", "Images", "LibGit2", "OffsetArrays", "PGFPlotsX", "HDF5", "RDatasets", "StaticArrays", "StatsPlots", "Test", "UnicodePlots", "VisualRegressionTests"] diff --git a/src/Plots.jl b/src/Plots.jl index 5c8fb305..2770338c 100644 --- a/src/Plots.jl +++ b/src/Plots.jl @@ -8,7 +8,7 @@ const _current_plots_version = VersionNumber(split(first(filter(line -> occursin using Reexport -import GeometryTypes +import GeometryTypes, GeometryBasics using Dates, Printf, Statistics, Base64, LinearAlgebra, Random import SparseArrays: AbstractSparseMatrix, findnz diff --git a/src/examples.jl b/src/examples.jl index d41add7f..1c39a962 100644 --- a/src/examples.jl +++ b/src/examples.jl @@ -983,6 +983,17 @@ const _examples = PlotExample[ end, ], ), + PlotExample( + "Tuples and `Point`s as data", + "", + [quote + using GeometryBasics + using Distributions + d = MvNormal([1.0 0.75; 0.75 2.0]) + plot([(1,2),(3,2),(2,1),(2,3)]) + scatter!(Point2.(eachcol(rand(d,1000))), alpha=0.25) + end] + ), ] # Some constants for PlotDocs and PlotReferenceImages diff --git a/src/recipes.jl b/src/recipes.jl index cd44bc65..64428396 100644 --- a/src/recipes.jl +++ b/src/recipes.jl @@ -1309,10 +1309,10 @@ end end # -------------------------------------------------------------------- -# Lists of tuples and GeometryTypes.Points +# Lists of tuples and GeometryBasics.Points # -------------------------------------------------------------------- -@recipe f(v::AVec{<:GeometryTypes.Point}) = RecipesPipeline.unzip(v) -@recipe f(p::GeometryTypes.Point) = [p] +@recipe f(v::AVec{<:_Point}) = RecipesPipeline.unzip(v) +@recipe f(p::_Point) = [p] # Special case for 4-tuples in :ohlc series @recipe f(xyuv::AVec{<:Tuple{R1, R2, R3, R4}}) where {R1, R2, R3, R4} = diff --git a/src/utils.jl b/src/utils.jl index c288b8a3..701b13e0 100644 --- a/src/utils.jl +++ b/src/utils.jl @@ -149,16 +149,17 @@ makevec(v::T) where {T} = T[v] maketuple(x::Real) = (x,x) maketuple(x::Tuple{T,S}) where {T,S} = x +const _Point{N,T} = Union{GeometryTypes.Point{N,T}, GeometryBasics.Point{N,T}} for i in 2:4 @eval begin RecipesPipeline.unzip(v::Union{AVec{<:Tuple{Vararg{T,$i} where T}}, - AVec{<:GeometryTypes.Point{$i}}}) = $(Expr(:tuple, (:([t[$j] for t in v]) for j=1:i)...)) + AVec{<:_Point{$i}}}) = $(Expr(:tuple, (:([t[$j] for t in v]) for j=1:i)...)) end end -RecipesPipeline.unzip(v::Union{AVec{<:GeometryTypes.Point{N}}, +RecipesPipeline.unzip(v::Union{AVec{<:_Point{N}}, AVec{<:Tuple{Vararg{T,N} where T}}}) where N = error("$N-dimensional unzip not implemented.") -RecipesPipeline.unzip(v::Union{AVec{<:GeometryTypes.Point}, +RecipesPipeline.unzip(v::Union{AVec{<:_Point}, AVec{<:Tuple}}) = error("Can't unzip points of different dimensions.") # given 2-element lims and a vector of data x, widen lims to account for the extrema of x diff --git a/test/runtests.jl b/test/runtests.jl index 68f50988..15591aee 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -6,7 +6,7 @@ using Test using FileIO using Gtk using LibGit2 -using GeometryTypes +import GeometryTypes, GeometryBasics using Dates include("test_axes.jl") @@ -178,6 +178,7 @@ end for z in zipped @test isequal(collect(zip(Plots.unzip(z)...)), z) @test isequal(collect(zip(Plots.unzip(GeometryTypes.Point.(z))...)), z) + @test isequal(collect(zip(Plots.unzip(GeometryBasics.Point.(z))...)), z) end op1 = Plots.process_clims((1.0, 2.0)) op2 = Plots.process_clims((1, 2.0))