Skip to content
This repository was archived by the owner on Jul 13, 2021. It is now read-only.
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
61 changes: 59 additions & 2 deletions src/conversions.jl
Original file line number Diff line number Diff line change
Expand Up @@ -285,6 +285,63 @@ function el32convert(x::AbstractArray{T, N}) where {T<:Union{Missing, <: Number}
end

"""

convert_arguments(PB, LineString)

Takes an input `LineString` and decomposes it to points.
"""
function convert_arguments(PB::PointBased, linestring::LineString)
return convert_arguments(PB, decompose(Point, linestring))
end

"""

convert_arguments(PB, Union{Array{<:LineString}, MultiLineString})

Takes an input `Array{LineString}` or a `MultiLineString` and decomposes it to points.
"""
function convert_arguments(PB::PointBased, linestring::Union{Array{<:LineString}, MultiLineString})
arr = convert_arguments(PB, linestring[1])[1]
for ls in 2:length(linestring)
push!(arr, Point2f0(NaN))
append!(arr, convert_arguments(PB, linestring[ls])[1])
end
return (arr,)
end

"""

convert_arguments(PB, Polygon)

Takes an input `Polygon` and decomposes it to points.
"""
function convert_arguments(PB::PointBased, pol::Polygon)
if isempty(pol.interiors)
return convert_arguments(PB, pol.exterior)
else
arr = convert_arguments(PB, pol.exterior)[1]
push!(arr, Point2f0(NaN))
append!(arr, convert_arguments(PB, pol.interiors)[1])
return (arr,)
end
end

"""

convert_arguments(PB, Union{Array{<:Polygon}, MultiPolygon})

Takes an input `Array{Polygon}` or a `MultiPolygon` and decomposes it to points.
"""
function convert_arguments(PB::PointBased, mp::Union{Array{<:Polygon}, MultiPolygon})
arr = convert_arguments(PB, mp[1])[1]
for p in 2:length(mp)
push!(arr, Point2f0(NaN))
append!(arr, convert_arguments(PB, mp[p])[1])
end
return (arr,)
end

"""
convert_arguments(P, Matrix)::Tuple{ClosedInterval, ClosedInterval, Matrix}

Takes an `AbstractMatrix`, converts the dimesions `n` and `m` into `ClosedInterval`,
Expand Down Expand Up @@ -582,10 +639,10 @@ function convert_attribute(p::Palette{N}, ::key"color") where {N}
p.colors[p.i[]]
end

convert_attribute(c::Colorant, ::key"color") = convert(RGBAf0, c)
convert_attribute(c::Colorant, ::key"color") = convert(RGBA{Float32}, c)
convert_attribute(c::Symbol, k::key"color") = convert_attribute(string(c), k)
function convert_attribute(c::String, ::key"color")
return parse(RGBAf0, c)
return parse(RGBA{Float32}, c)
end

# Do we really need all colors to be RGBAf0?!
Expand Down
6 changes: 6 additions & 0 deletions src/interfaces.jl
Original file line number Diff line number Diff line change
Expand Up @@ -495,6 +495,12 @@ plottype(::RealVector) = Lines
plottype(::AbstractMatrix{<: Real}) = Heatmap
plottype(::Array{<: AbstractFloat, 3}) = Volume
plottype(::AbstractString) = Text
plottype(::LineString) = Lines
plottype(::Array{<:LineString}) = Lines
plottype(::MultiLineString) = Lines
plottype(::Polygon) = Lines
plottype(::Array{<:Polygon}) = Lines
plottype(::MultiPolygon) = Lines

"""
plottype(P1::Type{<: Combined{T1}}, P2::Type{<: Combined{T2}})
Expand Down
42 changes: 42 additions & 0 deletions test/conversions.jl
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,48 @@ end
for (val, fval) in xy
@test fval ≈ sin(val) atol=1f-6
end

pts = [Point(1, 2), Point(4,5), Point(10, 8), Point(1, 2)]
ls=LineString(pts)
p = convert_arguments(AbstractPlotting.PointBased(), ls)
@test p[1] == pts

pts1 = [Point(5, 2), Point(4,8), Point(2, 8), Point(5, 2)]
ls1 = LineString(pts1)
lsa = [ls, ls1]
p1 = convert_arguments(AbstractPlotting.PointBased(), lsa)
@test p1[1][1:4] == pts
@test p1[1][6:9] == pts1

mls = MultiLineString(lsa)
p2 = convert_arguments(AbstractPlotting.PointBased(), mls)
@test p2[1][1:4] == pts
@test p2[1][6:9] == pts1

pol_e = Polygon(ls)
p3_e = convert_arguments(AbstractPlotting.PointBased(), pol_e)
@test p3_e[1] == pts

pol = Polygon(ls, [ls1])
p3 = convert_arguments(AbstractPlotting.PointBased(), pol)
@test p3[1][1:4] == pts
@test p3[1][6:9] == pts1

pts2 = Point{2, Int}[(5, 1), (3, 3), (4, 8), (1, 2), (5, 1)]
pts3 = Point{2, Int}[(2, 2), (2, 3),(3, 4), (2, 2)]
pts4 = Point{2, Int}[(2, 2), (3, 8),(5, 6), (3, 4), (2, 2)]
ls2 = LineString(pts2)
ls3 = LineString(pts3)
ls4 = LineString(pts4)
pol1 = Polygon(ls2, [ls3, ls4])
apol = [pol, pol1]
p4 = convert_arguments(AbstractPlotting.PointBased(), apol)
mpol = MultiPolygon([pol, pol1])
@test p4[1][1:4] == pts
@test p4[1][6:9] == pts1
@test p4[1][11:15] == pts2
@test p4[1][17:20] == pts3
@test p4[1][22:26] == pts4
end

@testset "Categorical values" begin
Expand Down