Recipe for GeometryBasics.Point

This commit is contained in:
yha 2020-06-18 21:18:34 +03:00
parent 709a8a9609
commit d353dca531
6 changed files with 24 additions and 9 deletions

View File

@ -10,6 +10,7 @@ Dates = "ade2ca70-3891-5945-98fb-dc099432e06a"
FFMPEG = "c87230d0-a227-11e9-1b43-d7ebe4e7570a" FFMPEG = "c87230d0-a227-11e9-1b43-d7ebe4e7570a"
FixedPointNumbers = "53c48c17-4a7d-5ca2-90c5-79b7896eea93" FixedPointNumbers = "53c48c17-4a7d-5ca2-90c5-79b7896eea93"
GR = "28b8d3ca-fb5f-59d9-8090-bfdbd6d07a71" GR = "28b8d3ca-fb5f-59d9-8090-bfdbd6d07a71"
GeometryBasics = "5c1252a2-5f33-56bf-86c9-59e7332b4326"
GeometryTypes = "4d00f742-c7ba-57c2-abde-4428a4b178cb" GeometryTypes = "4d00f742-c7ba-57c2-abde-4428a4b178cb"
JSON = "682c06a0-de6a-54ab-a142-c8b1cf79cde6" JSON = "682c06a0-de6a-54ab-a142-c8b1cf79cde6"
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e" LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
@ -51,6 +52,7 @@ StatsBase = "0.32, 0.33"
julia = "1" julia = "1"
[extras] [extras]
Distributions = "31c24e10-a181-5473-b8eb-7969acd0382f"
FileIO = "5789e2e9-d7fb-5bc7-8068-2c6fae9b9549" FileIO = "5789e2e9-d7fb-5bc7-8068-2c6fae9b9549"
Gtk = "4c0ca9eb-093a-5379-98c5-f87ac0bbbf44" Gtk = "4c0ca9eb-093a-5379-98c5-f87ac0bbbf44"
HDF5 = "f67ccb44-e63f-5c2f-98bd-6dc0ccc4ba2f" HDF5 = "f67ccb44-e63f-5c2f-98bd-6dc0ccc4ba2f"
@ -67,4 +69,4 @@ UnicodePlots = "b8865327-cd53-5732-bb35-84acbb429228"
VisualRegressionTests = "34922c18-7c2a-561c-bac1-01e79b2c4c92" VisualRegressionTests = "34922c18-7c2a-561c-bac1-01e79b2c4c92"
[targets] [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"]

View File

@ -8,7 +8,7 @@ const _current_plots_version = VersionNumber(split(first(filter(line -> occursin
using Reexport using Reexport
import GeometryTypes import GeometryTypes, GeometryBasics
using Dates, Printf, Statistics, Base64, LinearAlgebra, Random using Dates, Printf, Statistics, Base64, LinearAlgebra, Random
import SparseArrays: AbstractSparseMatrix, findnz import SparseArrays: AbstractSparseMatrix, findnz

View File

@ -983,6 +983,17 @@ const _examples = PlotExample[
end, 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 # Some constants for PlotDocs and PlotReferenceImages

View File

@ -1309,10 +1309,10 @@ end
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(v::AVec{<:_Point}) = RecipesPipeline.unzip(v)
@recipe f(p::GeometryTypes.Point) = [p] @recipe f(p::_Point) = [p]
# Special case for 4-tuples in :ohlc series # Special case for 4-tuples in :ohlc series
@recipe f(xyuv::AVec{<:Tuple{R1, R2, R3, R4}}) where {R1, R2, R3, R4} = @recipe f(xyuv::AVec{<:Tuple{R1, R2, R3, R4}}) where {R1, R2, R3, R4} =

View File

@ -149,16 +149,17 @@ makevec(v::T) where {T} = T[v]
maketuple(x::Real) = (x,x) maketuple(x::Real) = (x,x)
maketuple(x::Tuple{T,S}) where {T,S} = 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 for i in 2:4
@eval begin @eval begin
RecipesPipeline.unzip(v::Union{AVec{<:Tuple{Vararg{T,$i} where T}}, 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
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.") 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.") 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 # given 2-element lims and a vector of data x, widen lims to account for the extrema of x

View File

@ -6,7 +6,7 @@ using Test
using FileIO using FileIO
using Gtk using Gtk
using LibGit2 using LibGit2
using GeometryTypes import GeometryTypes, GeometryBasics
using Dates using Dates
include("test_axes.jl") include("test_axes.jl")
@ -178,6 +178,7 @@ end
for z in zipped for z in zipped
@test isequal(collect(zip(Plots.unzip(z)...)), z) @test isequal(collect(zip(Plots.unzip(z)...)), z)
@test isequal(collect(zip(Plots.unzip(GeometryTypes.Point.(z))...)), z) @test isequal(collect(zip(Plots.unzip(GeometryTypes.Point.(z))...)), z)
@test isequal(collect(zip(Plots.unzip(GeometryBasics.Point.(z))...)), z)
end end
op1 = Plots.process_clims((1.0, 2.0)) op1 = Plots.process_clims((1.0, 2.0))
op2 = Plots.process_clims((1, 2.0)) op2 = Plots.process_clims((1, 2.0))