Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

use Makie 0.21 #12

Merged
merged 5 commits into from
Aug 20, 2024
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,7 +1,7 @@
name = "MakieDraw"
uuid = "8315f7d3-d5d2-4d16-bebe-3aa4ef51e4f8"
authors = ["Rafael Schouten <[email protected]>"]
version = "0.2.1"
version = "0.2.2"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this be breaking? It will cause a lot of workflows using eg CanvasSelect to fail...

Suggested change
version = "0.2.1"
version = "0.2.2"
version = "0.3.0"

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah I bumped the version before I broke everything


[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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this fix the issue you posted about?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It might create other issues though... like you wont be able to draw over Tyler.jl maps

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was hoping that popups were somehow separate from this system - because they are style as being above any other layer

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If it's just a plot then no...and it looks like you are using Consume(true) in places as well so it shouldn't be an issue there. Why would Tyler be a problem here?

Copy link
Collaborator Author

@rafaqz rafaqz Aug 20, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Like shouldn't popups have a priority of typemax(Int) ? @SimonDanisch how does this work exactly?

How can MakieDraw layers be always above the other layers but below Menu popups in click event order

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Menu has a priority of 65 ^^ so I guess it needs to below that? And all others should have 1 as a default...
Anything unimportant is negative and system stuff should have something like max int, I think.
Definitely needs some better docs

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh good maybe MakieDraw can be 50 then rather than 100

# 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
Loading