From 301ae5e1c86ff8448886e9cbcd0fcbdb5abd6c9f Mon Sep 17 00:00:00 2001 From: Rafael Schouten Date: Sun, 18 Aug 2024 16:26:24 +0200 Subject: [PATCH 1/5] use Makie 0.21 --- Project.toml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Project.toml b/Project.toml index 1adce7b..74560aa 100644 --- a/Project.toml +++ b/Project.toml @@ -1,7 +1,7 @@ name = "MakieDraw" uuid = "8315f7d3-d5d2-4d16-bebe-3aa4ef51e4f8" authors = ["Rafael Schouten "] -version = "0.2.1" +version = "0.2.2" [deps] GeometryBasics = "5c1252a2-5f33-56bf-86c9-59e7332b4326" @@ -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" From 35ace550a4196bf79689e09d80e46badce436695 Mon Sep 17 00:00:00 2001 From: Rafael Schouten Date: Sun, 18 Aug 2024 18:56:20 +0200 Subject: [PATCH 2/5] remove auto detection for CanvasSelect, and depbug --- Project.toml | 1 + src/canvas_select.jl | 32 +++++--------------------------- src/geometry_canvas.jl | 12 +++++++----- test/runtests.jl | 14 +++++++------- 4 files changed, 20 insertions(+), 39 deletions(-) diff --git a/Project.toml b/Project.toml index 74560aa..70c7243 100644 --- a/Project.toml +++ b/Project.toml @@ -4,6 +4,7 @@ authors = ["Rafael Schouten "] version = "0.2.2" [deps] +GLMakie = "e9467ef8-e4e7-5192-8a1a-b1aee30e663a" GeometryBasics = "5c1252a2-5f33-56bf-86c9-59e7332b4326" Makie = "ee78f7c6-11fb-53f2-987a-cfe4a2b5a57a" Tables = "bd369af6-aec1-5ad0-b16a-f7cc5008161c" diff --git a/src/canvas_select.jl b/src/canvas_select.jl index 3958976..25da7bd 100644 --- a/src/canvas_select.jl +++ b/src/canvas_select.jl @@ -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) @@ -55,7 +54,7 @@ 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 @@ -63,24 +62,3 @@ 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 diff --git a/src/geometry_canvas.jl b/src/geometry_canvas.jl index c39c32a..9684f28 100644 --- a/src/geometry_canvas.jl +++ b/src/geometry_canvas.jl @@ -163,7 +163,6 @@ 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 @@ -171,7 +170,9 @@ end _current_point_obs(::Type{<:Point}) = Observable(1) _current_point_obs(::Type) = Observable((1, 1)) -_geomtype(T) = T +_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}) = Point2f function _initialise_properties(figure, properties, propertynames, current_point, input_layout, text_input) @@ -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 @@ -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) @@ -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) diff --git a/test/runtests.jl b/test/runtests.jl index c4904b9..cb762e0 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -1,25 +1,25 @@ using MakieDraw using Test -using Makie +using GLMakie using GeometryBasics 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); @@ -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 From cd5d43a6831db23b39c54178b7e0c0f9e2a6e995 Mon Sep 17 00:00:00 2001 From: Rafael Schouten Date: Sun, 18 Aug 2024 19:01:59 +0200 Subject: [PATCH 3/5] use Makie in tests --- test/runtests.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/runtests.jl b/test/runtests.jl index cb762e0..d6fd41d 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -1,6 +1,6 @@ using MakieDraw using Test -using GLMakie +using Makie using GeometryBasics using GeoJSON using GeoInterface From 8b1ec0a495ddec77bb258a18118b26b097537af6 Mon Sep 17 00:00:00 2001 From: Rafael Schouten Date: Sun, 18 Aug 2024 19:28:51 +0200 Subject: [PATCH 4/5] no GLMakie dep --- Project.toml | 1 - 1 file changed, 1 deletion(-) diff --git a/Project.toml b/Project.toml index 70c7243..74560aa 100644 --- a/Project.toml +++ b/Project.toml @@ -4,7 +4,6 @@ authors = ["Rafael Schouten "] version = "0.2.2" [deps] -GLMakie = "e9467ef8-e4e7-5192-8a1a-b1aee30e663a" GeometryBasics = "5c1252a2-5f33-56bf-86c9-59e7332b4326" Makie = "ee78f7c6-11fb-53f2-987a-cfe4a2b5a57a" Tables = "bd369af6-aec1-5ad0-b16a-f7cc5008161c" From ff02075990241c00ffc3342cb5eb5bc46d016399 Mon Sep 17 00:00:00 2001 From: Rafael Schouten Date: Tue, 20 Aug 2024 18:19:41 +0200 Subject: [PATCH 5/5] Update src/geometry_canvas.jl Co-authored-by: Anshul Singhvi --- src/geometry_canvas.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/geometry_canvas.jl b/src/geometry_canvas.jl index 9684f28..b168ea3 100644 --- a/src/geometry_canvas.jl +++ b/src/geometry_canvas.jl @@ -173,7 +173,7 @@ _current_point_obs(::Type) = Observable((1, 1)) _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}) = Point2f +_geomtype(::Type{<:Point}) = Point2{Float64} function _initialise_properties(figure, properties, propertynames, current_point, input_layout, text_input) properties = if isnothing(properties) && propertynames isa Tuple