Skip to content

Commit

Permalink
use Makie 0.21 (#12)
Browse files Browse the repository at this point in the history
* use Makie 0.21

* remove auto detection for CanvasSelect, and depbug

* use Makie in tests

* no GLMakie dep

* Update src/geometry_canvas.jl

Co-authored-by: Anshul Singhvi <[email protected]>

---------

Co-authored-by: Anshul Singhvi <[email protected]>
  • Loading branch information
rafaqz and asinghvi17 authored Aug 20, 2024
1 parent be7f300 commit 8e13213
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 41 deletions.
4 changes: 2 additions & 2 deletions Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "MakieDraw"
uuid = "8315f7d3-d5d2-4d16-bebe-3aa4ef51e4f8"
authors = ["Rafael Schouten <[email protected]>"]
version = "0.2.1"
version = "0.2.2"

[deps]
GeometryBasics = "5c1252a2-5f33-56bf-86c9-59e7332b4326"
Expand All @@ -10,7 +10,7 @@ Tables = "bd369af6-aec1-5ad0-b16a-f7cc5008161c"

[compat]
GeometryBasics = "0.4"
Makie = "0.20"
Makie = "0.21"
Tables = "1"
julia = "1.6"

Expand Down
32 changes: 5 additions & 27 deletions src/canvas_select.jl
Original file line number Diff line number Diff line change
Expand Up @@ -24,24 +24,23 @@ layers = Dict(
:poly=>poly_canvas.active,
)
MakieDraw.CanvasSelect(figure[2, 1], axis; layers)
MakieDraw.CanvasSelect(figure[2, 1]; layers)
```
"""
struct CanvasSelect{L} <: AbstractCanvasSelect
layers::L
menu::Menu
axis::Axis
end
function CanvasSelect(m::Menu, ax::Axis; layers=Dict{Symbol,Observable{Bool}}())
function CanvasSelect(m::Menu; layers=Dict{Symbol,Observable{Bool}}())
on(m.selection) do selected
for (key, active) in layers
active[] = key == Symbol(selected)
notify(active)
end
end
CanvasSelect(layers, m, ax)
CanvasSelect(layers, m)
end
function CanvasSelect(fig::Union{Figure,GridPosition}, ax::Axis; layers=[])
function CanvasSelect(fig::Union{Figure,GridPosition}; layers=Dict{Symbol,Observable{Bool}}())
found_active = false
default = "none"
for (key, active) in pairs(layers)
Expand All @@ -55,32 +54,11 @@ function CanvasSelect(fig::Union{Figure,GridPosition}, ax::Axis; layers=[])
end
options = map(string, collect(keys(layers)))
m = Menu(fig; options, default)
CanvasSelect(m, ax; layers)
CanvasSelect(m; layers)
end

layers(ls::AbstractCanvasSelect) = ls.layers

Base.push!(ls::AbstractCanvasSelect, x::Pair{Symbol,Observable{Bool}}) = push!(layers(ls), x)
Base.getindex(ls::AbstractCanvasSelect, key::Symbol) = layers(ls)[key]
Base.setindex!(ls::AbstractCanvasSelect, x::Observable{Bool}, key::Symbol) = layers(ls)[key] = x

function addtoswitchers!(c::GeometryCanvas)
for x in c.figure.content
# Find all AbstractCanvasSelect on this Axis
if x isa AbstractCanvasSelect # && x.axis == ax
if haskey(x, c.name)
# Add the first number to the name that doesn't exist yet
i = 1
while true
key = Symbol(c.name, i)
if !haskey(x, key)
x[key] = c.active
break
end
end
else
x[c.name] = c.active
end
end
end
end
14 changes: 8 additions & 6 deletions src/geometry_canvas.jl
Original file line number Diff line number Diff line change
Expand Up @@ -163,16 +163,17 @@ function GeometryCanvas{T}(obj=Observable(_geomtype(T)[]);
draw!(figure, axis, canvas;
scatter_kw, lines_kw, poly_kw, current_point_kw, show_current_point
)
addtoswitchers!(canvas)
add_events!(canvas; mouse_property)
return canvas
end

_current_point_obs(::Type{<:Point}) = Observable(1)
_current_point_obs(::Type) = Observable((1, 1))

_geomtype(T) = T
_geomtype(::Type{<:Point}) = Point2f
_geomtype(T::Type) = T
_geomtype(::Type{LineString}) = LineString{2,Float64,Point{2,Float64}}
_geomtype(::Type{Polygon}) = Polygon{2,Float64,Point{2,Float64}}
_geomtype(::Type{<:Point}) = Point2{Float64}

function _initialise_properties(figure, properties, propertynames, current_point, input_layout, text_input)
properties = if isnothing(properties) && propertynames isa Tuple
Expand Down Expand Up @@ -328,6 +329,7 @@ function draw!(fig, ax::Axis, c::GeometryCanvas{<:LineString};
scatter_kw=(;), lines_kw=(;), poly_kw=(;), current_point_kw=(;),
show_current_point=false,
)
@show typeof(c.geoms)
l = if isnothing(c.color)
lines!(ax, c.geoms; lines_kw...)
else
Expand Down Expand Up @@ -365,9 +367,9 @@ function draw!(fig, ax::Axis, c::GeometryCanvas{<:Polygon};
# This will need all new polygons to be a line stored in a separate Observable
# that we plot like LineString.
p = if isnothing(c.color)
mesh!(ax, c.geoms)
poly!(ax, c.geoms)
else
mesh!(ax, c.geoms; color=c.color, poly_kw...)
poly!(ax, c.geoms; color=c.color, poly_kw...)
end
translate!(p, 0, 0, 98)
draw_points!(fig, ax, c; scatter_kw)
Expand Down Expand Up @@ -425,7 +427,7 @@ function add_events!(c::GeometryCanvas{<:Point};


# Mouse down event
on(events(ax.scene).mousebutton, priority=100) do event
on(events(ax.scene).mousebutton, priority=-100) do event
# If this canvas is not active dont respond to mouse events
(; geoms, points, dragging, active, section) = c
active[] || return Consume(false)
Expand Down
12 changes: 6 additions & 6 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,20 @@ using GeoJSON
using GeoInterface

figure = Figure()
axis = Axis(figure[1:10, 1:10])
axis = Axis(figure[1, 1])

paint_canvas = PaintCanvas(falses(100, 100); figure, axis)

paint_canvas.active[] = false
paint_canvas.active[] = true

line_canvas = GeometryCanvas{LineString}(; figure, axis)

line_canvas.active[] = false

point_canvas = GeometryCanvas{Point}(; figure, axis)

point_canvas.active[] = false

# poly_canvas = GeometryCanvas{Polygon}(; figure, axis)
# poly_canvas.active[] = false

polys = [Polygon([Point(1.0, 2.0), Point(2.0, 3.0), Point(3.0, 1.0), Point(1.0, 2.0)])]
poly_canvas = GeometryCanvas(polys; figure, axis);

Expand All @@ -30,7 +30,7 @@ layers = Dict(
:poly=>poly_canvas.active,
)

MakieDraw.CanvasSelect(figure[2, 1], axis; layers)
MakieDraw.CanvasSelect(figure[2, 1]; layers)

# Write the polygons to JSON
# Have to convert here because GeometryBasics `isgeometry` has a bug, see PR #193
Expand Down

0 comments on commit 8e13213

Please sign in to comment.