Skip to content
This repository has been archived by the owner on Jun 29, 2021. It is now read-only.

switch to GeometryBasics #120

Merged
merged 4 commits into from
Apr 10, 2020
Merged
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
4 changes: 2 additions & 2 deletions Project.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name = "StatsMakie"
uuid = "65254759-4cff-5aa5-8326-61ce017a8c70"
version = "0.1.5"
version = "0.2"

[deps]
AbstractPlotting = "537997a7-5e4e-5d89-9595-2241ea00577e"
Expand All @@ -17,7 +17,7 @@ StructArrays = "09ab397b-f2b6-538f-b94a-2f83cf4a842a"
Tables = "bd369af6-aec1-5ad0-b16a-f7cc5008161c"

[compat]
AbstractPlotting = "0.9.27"
AbstractPlotting = "0.10"
Distributions = "0.17, 0.18, 0.19, 0.20, 0.21, 0.22, 0.23"
GLM = "1.3"
IntervalSets = "0.3, 0.4"
Expand Down
2 changes: 1 addition & 1 deletion src/StatsMakie.jl
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ using AbstractPlotting
import AbstractPlotting: conversion_trait, convert_arguments, used_attributes, plot!, combine, to_plotspec
using AbstractPlotting: plottype, Plot, PlotFunc, to_tuple
using AbstractPlotting: node_pairs, extrema_nan, automatic, default_theme
using AbstractPlotting: GeometryTypes
using AbstractPlotting: GeometryBasics
using AbstractPlotting: ConversionTrait, el32convert, categoric_labels, categoric_position, categoric_range

# Moved in https://github.com/JuliaGizmos/Observables.jl/pull/40
Expand Down
32 changes: 17 additions & 15 deletions src/recipes/crossbar.jl
Original file line number Diff line number Diff line change
Expand Up @@ -70,30 +70,32 @@ function AbstractPlotting.plot!(plot::CrossBar)
end
# when notchmin = ymin || notchmax == ymax, fill disappears from
# half the box. first ∘ StatsBase.rle removes adjacent duplicates.
boxes =
GeometryTypes.GLNormalMesh.(first.(StatsBase.rle.(Base.vect.(
fpoint.(l, ymin),
fpoint.(r, ymin),
fpoint.(r, nmin),
fpoint.(m .+ nw .* hw, y), # notch right
fpoint.(r, nmax),
fpoint.(r, ymax),
fpoint.(l, ymax),
fpoint.(l, nmax),
fpoint.(m .- nw .* hw, y), # notch left
fpoint.(l, nmin),
))))
points = first.(StatsBase.rle.(Base.vect.(
fpoint.(l, ymin),
fpoint.(r, ymin),
fpoint.(r, nmin),
fpoint.(m .+ nw .* hw, y), # notch right
fpoint.(r, nmax),
fpoint.(r, ymax),
fpoint.(l, ymax),
fpoint.(l, nmax),
fpoint.(m .- nw .* hw, y), # notch left
fpoint.(l, nmin),
)))
boxes = if points isa AbstractVector{<: Point} # poly
[GeometryBasics.triangle_mesh(points)]
else # multiple polys (Vector{Vector{<:Point}})
GeometryBasics.triangle_mesh.(points)
end
midlines = Pair.(fpoint.(m .- nw .* hw, y), fpoint.(m .+ nw .* hw, y))
else
boxes = frect.(l, ymin, bw, ymax .- ymin)
midlines = Pair.(fpoint.(l, y), fpoint.(r, y))
end

return [boxes;], [midlines;]
end
boxes = @lift($signals[1])
midlines = @lift($signals[2])

poly!(
plot,
boxes,
Expand Down
22 changes: 11 additions & 11 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ using AbstractPlotting, StatsMakie, StatsBase
using Test

using Random: seed!
using AbstractPlotting.GeometryTypes: HyperRectangle
using AbstractPlotting.GeometryBasics: FRect2D
using Distributions
using KernelDensity: kde

Expand All @@ -12,17 +12,17 @@ seed!(0)
p = crossbar(1, 3, 2, 4)
@test p.plots[end] isa CrossBar
@test p.plots[end].plots[1] isa Poly
@test p.plots[end].plots[1][1][] == HyperRectangle{2,Float32}[HyperRectangle{2,Float32}(Float32[0.6, 2.0], Float32[0.8, 2.0]),]
@test p.plots[end].plots[1][1][] == [FRect2D(Float32[0.6, 2.0], Float32[0.8, 2.0]),]
@test p.plots[end].plots[2] isa LineSegments
@test p.plots[end].plots[2][1][] == Point{2,Float32}[Float32[0.6, 3.0], Float32[1.4, 3.0]]

p = crossbar(1, 3, 2, 4; show_notch = true, notchmin = 2.5, notchmax = 3.5)
p = crossbar(1, 3, 2, 4; show_notch = true, notchmin = 2.5, notchmax = 3.5);
@test p.plots[end] isa CrossBar
@test p.plots[end].plots[1] isa Poly
@test p.plots[end].plots[1][1][][1] isa AbstractPlotting.AbstractMesh
poly = Point{2,Float32}[[0.6, 2.0], [1.4, 2.0], [1.4, 2.5], [1.2, 3.0], [1.4, 3.5],
[1.4, 4.0], [0.6, 4.0], [0.6, 3.5], [0.8, 3.0], [0.6, 2.5]]
@test map(Point2f0, p.plots[end].plots[1][1][][1].vertices) == poly
@test map(Point2f0, p.plots[end].plots[1][1][][1].position) == poly
@test p.plots[end].plots[2] isa LineSegments
@test p.plots[end].plots[2][1][] == Point{2,Float32}[Float32[0.8, 3.0], Float32[1.2, 3.0]]
end
Expand Down Expand Up @@ -61,12 +61,12 @@ end
@test plts[3] isa CrossBar
@test plts[3].plots[1] isa Poly

poly = HyperRectangle{2,Float32}[
HyperRectangle{2,Float32}(Float32[0.6, 5.75], Float32[0.8, 9.5]),
HyperRectangle{2,Float32}(Float32[1.6, 25.75], Float32[0.8, 9.5]),
HyperRectangle{2,Float32}(Float32[2.6, 45.75], Float32[0.8, 9.5]),
HyperRectangle{2,Float32}(Float32[3.6, 65.75], Float32[0.8, 9.5]),
HyperRectangle{2,Float32}(Float32[4.6, 85.75], Float32[0.8, 9.5]),
poly = [
FRect2D(Float32[0.6, 5.75], Float32[0.8, 9.5]),
FRect2D(Float32[1.6, 25.75], Float32[0.8, 9.5]),
FRect2D(Float32[2.6, 45.75], Float32[0.8, 9.5]),
FRect2D(Float32[3.6, 65.75], Float32[0.8, 9.5]),
FRect2D(Float32[4.6, 85.75], Float32[0.8, 9.5]),
]

@test plts[3].plots[1][1][] == poly
Expand Down Expand Up @@ -102,7 +102,7 @@ end
meshes = plts[3].plots[1][1][]
@testset for (i, mesh) in enumerate(meshes)
@test mesh isa AbstractPlotting.AbstractMesh
vertices = map(Point2f0, mesh.vertices)
vertices = map(Point2f0, mesh.position)
@test vertices ≈ notch_boxes[i]
end
end
Expand Down