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

DataInspector callback attributes #2261

Closed
wants to merge 25 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
8db1b06
add inspector_label attribute
ffreyer Sep 9, 2022
4fbfaf1
add hover and clear callback attributes
ffreyer Sep 9, 2022
70799be
Add support for pasting text into a textbox
ConnectedSystems Sep 18, 2022
b2d9b06
Add notice to NEWS.md
ConnectedSystems Sep 18, 2022
6b0e527
Add test for textbox copy/paste behavior
ConnectedSystems Sep 18, 2022
811b90f
cleanup test
ffreyer Sep 19, 2022
24bca23
fix dependencies
ffreyer Sep 19, 2022
ed20518
try setting up xclip
ffreyer Sep 19, 2022
d86c1e3
Clean up try/catch
ConnectedSystems Sep 20, 2022
6aa3668
Make GLMakie relocatable (#2282)
ConnectedSystems Sep 22, 2022
27aa070
Merge branch 'copy-paste-textbox' of https://github.com/ConnectedSyst…
SimonDanisch Sep 22, 2022
aefbef4
improve wording
SimonDanisch Sep 22, 2022
e2e5010
Tricontourf plot (#2226)
jkrumbiegel Sep 23, 2022
03fb7ac
fix changing input types (#2297)
SimonDanisch Sep 23, 2022
087dfbd
Add makie latex string note (#2292)
jeremiahpslewis Sep 26, 2022
c2e5a7a
Hexbin recipe (continuation of 2201) (#2236)
jkrumbiegel Sep 27, 2022
38296f5
better performance for Menus and fix clicks on items (#2299)
SimonDanisch Sep 27, 2022
fb977a3
use premultiplied alpha for cairo argb surfaces (#2304)
jkrumbiegel Sep 27, 2022
f92f083
Improve valign halign observable types (#2305)
jkrumbiegel Sep 27, 2022
b6e8b37
remove deprecated Mat2f0 (#2307)
SimonDanisch Sep 28, 2022
c373d3f
use new MiniQhull with BinaryProvider (#2308)
SimonDanisch Sep 30, 2022
feaa8c0
Merge branch 'ff/Tooltip' into ff/inspector_callbacks
ffreyer Oct 8, 2022
8e87078
avoid WGLMakie errors
ffreyer Oct 8, 2022
aab2bed
fix incomplete color variable
ffreyer Oct 8, 2022
2878481
Merge branch 'master' into ff/inspector_callbacks
ffreyer Oct 8, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ jobs:
with:
version: ${{ matrix.version }}
arch: ${{ matrix.arch }}
run: sudo apt-get -y install xclip
- uses: julia-actions/cache@v1
- name: Install Julia dependencies
shell: julia --project=monorepo {0}
Expand Down
35 changes: 35 additions & 0 deletions CairoMakie/src/overrides.jl
Original file line number Diff line number Diff line change
Expand Up @@ -186,3 +186,38 @@ function draw_plot(scene::Scene, screen::CairoScreen,

nothing
end

#################################################################################
# Tricontourf #
# Tricontourf creates many disjoint polygons that are adjacent and form contour #
# bands, however, at the gaps we see white antialiasing artifacts. Therefore #
# we override behavior and draw each band in one go #
#################################################################################

function draw_plot(scene::Scene, screen::CairoScreen, tric::Tricontourf)

pol = only(tric.plots)::Poly
colornumbers = pol.color[]
colors = numbers_to_colors(colornumbers, pol)

polygons = pol[1][]

model = pol.model[]
space = to_value(get(pol, :space, :data))
projected_polys = project_polygon.(Ref(scene), space, polygons, Ref(model))

function draw_tripolys(polys, colornumbers, colors)
for (i, (pol, colnum, col)) in enumerate(zip(polys, colornumbers, colors))
polypath(screen.context, pol)
if i == length(colornumbers) || colnum != colornumbers[i+1]
Cairo.set_source_rgba(screen.context, rgbatuple(col)...)
Cairo.fill(screen.context)
end
end
return
end

draw_tripolys(projected_polys, colornumbers, colors)

return
end
8 changes: 8 additions & 0 deletions CairoMakie/src/primitives.jl
Original file line number Diff line number Diff line change
Expand Up @@ -557,6 +557,14 @@ end

regularly_spaced_array_to_range(arr::AbstractRange) = arr

function premultiplied_rgba(a::AbstractArray{<:ColorAlpha})
map(premultiplied_rgba, a)
end
premultiplied_rgba(a::AbstractArray{<:Color}) = RGBA.(a)

premultiplied_rgba(r::RGBA) = RGBA(r.r * r.alpha, r.g * r.alpha, r.b * r.alpha, r.alpha)
premultiplied_rgba(c::Colorant) = premultiplied_rgba(RGBA(c))

function draw_atomic(scene::Scene, screen::CairoScreen, @nospecialize(primitive::Union{Heatmap, Image}))
ctx = screen.context
image = primitive[3][]
Expand Down
2 changes: 1 addition & 1 deletion CairoMakie/src/utils.jl
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ function rgbatuple(c)
return rgbatuple(colorant)
end

to_uint32_color(c) = reinterpret(UInt32, convert(ARGB32, c))
to_uint32_color(c) = reinterpret(UInt32, convert(ARGB32, premultiplied_rgba(c)))

########################################
# Image/heatmap -> ARGBSurface #
Expand Down
4 changes: 2 additions & 2 deletions GLMakie/src/GLAbstraction/GLShader.jl
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ function gl_convert(cache::ShaderCache, lazyshader::AbstractLazyShader, data)
# Tuple(Source, ShaderType)
if all(paths) do x
isa(x, Tuple) && length(x) == 2 &&
isa(first(x), String) &&
isa(first(x), AbstractString) &&
isa(last(x), GLenum)
end
# we don't cache view & templates for shader strings!
Expand All @@ -231,7 +231,7 @@ function gl_convert(cache::ShaderCache, lazyshader::AbstractLazyShader, data)
end
return compile_program([shaders...], fragdatalocation)
end
if !all(x-> isa(x, String), paths)
if !all(x -> isa(x, AbstractString), paths)
error("Please supply only paths or tuples of (source, typ) for Lazy Shader
Found: $paths"
)
Expand Down
5 changes: 4 additions & 1 deletion GLMakie/src/GLMakie.jl
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ using Makie: ClosedInterval, (..)
using Makie: inline!, to_native
using Makie: spaces, is_data_space, is_pixel_space, is_relative_space, is_clip_space
import Makie: to_font, glyph_uv_width!, el32convert, Shape, CIRCLE, RECTANGLE, ROUNDED_RECTANGLE, DISTANCEFIELD, TRIANGLE
import Makie: RelocatableFolders

using ShaderAbstractions
using FreeTypeAbstraction
Expand All @@ -43,7 +44,9 @@ export Sampler, Buffer
struct GLBackend <: Makie.AbstractBackend
end

loadshader(name) = normpath(joinpath(@__DIR__, "..", "assets", "shader", name))
const GL_ASSET_DIR = RelocatableFolders.@path joinpath(@__DIR__, "..", "assets")
const SHADER_DIR = RelocatableFolders.@path joinpath(GL_ASSET_DIR, "shader")
loadshader(name) = joinpath(SHADER_DIR, name)

# don't put this into try catch, to not mess with normal errors
include("gl_backend.jl")
Expand Down
6 changes: 5 additions & 1 deletion GLMakie/src/drawing_primitives.jl
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,11 @@ function cached_robj!(robj_func, screen, scene, x::AbstractPlot)
pollevents(screen)
robj = get!(screen.cache, objectid(x)) do
filtered = filter(x.attributes) do (k, v)
!(k in (:transformation, :tickranges, :ticklabels, :raw, :SSAO, :lightposition, :material))
!in(k, (
:transformation, :tickranges, :ticklabels, :raw, :SSAO,
:lightposition, :material,
:inspector_label, :inspector_hover, :inspector_clear
))
end

gl_attributes = Dict{Symbol, Any}(map(filtered) do key_value
Expand Down
2 changes: 1 addition & 1 deletion GLMakie/src/screen.jl
Original file line number Diff line number Diff line change
Expand Up @@ -314,7 +314,7 @@ Loads the makie loading icon and embedds it in an image the size of resolution
"""
function get_loading_image(resolution)
icon = Matrix{N0f8}(undef, 192, 192)
open(joinpath(@__DIR__, "..", "assets", "loading.bin")) do io
open(joinpath(GL_ASSET_DIR, "loading.bin")) do io
read!(io, icon)
end
img = zeros(RGBA{N0f8}, resolution...)
Expand Down
6 changes: 6 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

## master

- Add `tooltip` as a plot recipe [#2095](https://github.com/JuliaPlots/Makie.jl/pull/2095)
- **Breaking** Refactor `DataInspector` to use `tooltip`. This results in changes in the attributes of DataInspector. See pr [#2095](https://github.com/JuliaPlots/Makie.jl/pull/2095)
- `hexbin` is now available as a recipe [#368] (https://github.com/JuliaPlots/Makie.jl/pull/2201)
- Added the `tricontourf` plotting function [#2226](https://github.com/JuliaPlots/Makie.jl/pull/2226).
- Fix per character attributes in text [#2244](https://github.com/JuliaPlots/Makie.jl/pull/2244)
- `Axis` does now accept both a `Bool` and a `Tuple{Bool, Bool}` as values for `xtrimspine` and `ytrimspine` to trim only one end of the spine [#2171](https://github.com/JuliaPlots/Makie.jl/pull/2171).
- Added `BezierPath` which can be constructed from SVG like command list, SVG string or from a `Polygon`.
Expand All @@ -12,6 +16,8 @@
Added single image marker support to WGLMakie [#979](https://github.com/MakieOrg/Makie.jl/pull/979).
- Allow `CairoMakie` to render `scatter` with images as markers [#2080](https://github.com/MakieOrg/Makie.jl/pull/2080).
- Reworked text drawing and added ability to draw special characters via glyph indices in order to draw more LaTeX math characters with MathTeXEngine v0.5 [#2139](https://github.com/MakieOrg/Makie.jl/pull/2139).
- Allow text to be copy/pasted into textbox [#2281](https://github.com/MakieOrg/Makie.jl/pull/2281)


## v0.17.13

Expand Down
5 changes: 5 additions & 0 deletions Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ FreeTypeAbstraction = "663a7486-cb36-511b-a19d-713bb74d65c9"
GeometryBasics = "5c1252a2-5f33-56bf-86c9-59e7332b4326"
GridLayoutBase = "3955a311-db13-416c-9275-1d80ed98e5e9"
ImageIO = "82e4d734-157c-48bb-816b-45c225c6df19"
InteractiveUtils = "b77e0a4c-d291-57a0-90e8-8db25a27a240"
IntervalSets = "8197267c-284f-5f27-9208-e0e47529a953"
Isoband = "f1662d9f-8043-43de-a69a-05efc1cc6ff4"
KernelDensity = "5ab0869b-81aa-558d-bb23-cbf5423bbe9b"
Expand All @@ -31,6 +32,7 @@ MakieCore = "20f20a25-4f0e-4fdf-b5d1-57303727442b"
Markdown = "d6f4376e-aef5-505a-96c1-9c027394607a"
Match = "7eb4fadd-790c-5f42-8a69-bfa0b872bfbf"
MathTeXEngine = "0a4f8689-d25c-4efe-a92b-7142dfc1aa53"
MiniQhull = "978d7f02-9e05-4691-894f-ae31a51d76ca"
Observables = "510215fc-4207-5dde-b226-833fc4488ee2"
OffsetArrays = "6fe1bfb0-de20-5000-8ca7-80f57d26f881"
Packing = "19eb6ba3-879d-56ad-ad62-d5c202156566"
Expand All @@ -48,6 +50,7 @@ Statistics = "10745b16-79ce-11e8-11f9-7d13ad32a3b2"
StatsBase = "2913bbd2-ae8a-5f71-8c99-4fb6c76f3a91"
StatsFuns = "4c63d2b9-4356-54db-8cca-17b64c39e42c"
StructArrays = "09ab397b-f2b6-538f-b94a-2f83cf4a842a"
TriplotBase = "981d1d27-644d-49a2-9326-4793e63143c3"
UnicodeFun = "1cfade01-22cf-5700-b092-accc4b62d6e1"

[compat]
Expand All @@ -74,6 +77,7 @@ KernelDensity = "0.5, 0.6"
LaTeXStrings = "1.2"
MakieCore = "=0.4.0"
Match = "1.1"
MiniQhull = "0.4"
MathTeXEngine = "0.5"
Observables = "0.5.1"
OffsetArrays = "1"
Expand All @@ -87,5 +91,6 @@ SnoopPrecompile = "1.0"
StatsBase = "0.31, 0.32, 0.33"
StatsFuns = "0.9, 1.0"
StructArrays = "0.3, 0.4, 0.5, 0.6"
TriplotBase = "=0.1.0"
UnicodeFun = "0.4"
julia = "1.3"
184 changes: 183 additions & 1 deletion ReferenceTests/src/tests/examples2d.jl
Original file line number Diff line number Diff line change
Expand Up @@ -545,6 +545,81 @@ end
f
end


@reference_test "Tooltip" begin
fig, ax, p = scatter(Point2f(0,0))
xlims!(ax, -10, 10)
ylims!(ax, -5, 5)
tt = tooltip!(ax, Point2f(0), text = "left", placement = :left)
tt.backgroundcolor[] = :red
tooltip!(
ax, 0, 0, "above with \nnewline\nand offset",
placement = :above, textpadding = (8, 5, 3, 2), align = 0.8
)
tooltip!(ax, Point2f(0), "below", placement = :below, outline_color = :red, outline_linestyle = :dot)
tooltip!(
ax, 0, 0, text = "right", placement = :right, textsize = 30,
outline_linewidth = 5, offset = 30, triangle_size = 15,
strokewidth = 2f0, strokecolor = :cyan
)
fig
end

@reference_test "tricontourf" begin
x = RNG.randn(50)
y = RNG.randn(50)
z = -sqrt.(x .^ 2 .+ y .^ 2) .+ 0.1 .* RNG.randn.()

f, ax, tr = tricontourf(x, y, z)
scatter!(x, y, color = z, strokewidth = 1, strokecolor = :black)
Colorbar(f[1, 2], tr)
f
end

@reference_test "tricontourf extendhigh extendlow" begin
x = RNG.randn(50)
y = RNG.randn(50)
z = -sqrt.(x .^ 2 .+ y .^ 2) .+ 0.1 .* RNG.randn.()

f, ax, tr = tricontourf(x, y, z, levels = -1.8:0.2:-0.4, extendhigh = :red, extendlow = :orange)
scatter!(x, y, color = z, strokewidth = 1, strokecolor = :black)
Colorbar(f[1, 2], tr)
f
end

@reference_test "tricontourf relative mode" begin
x = RNG.randn(50)
y = RNG.randn(50)
z = -sqrt.(x .^ 2 .+ y .^ 2) .+ 0.1 .* RNG.randn.()

f, ax, tr = tricontourf(x, y, z, mode = :relative, levels = 0.2:0.1:1, colormap = :batlow)
scatter!(x, y, color = z, strokewidth = 1, strokecolor = :black, colormap = :batlow)
Colorbar(f[1, 2], tr)
f
end

@reference_test "tricontourf manual vs delaunay" begin
n = 20
angles = range(0, 2pi, length = n+1)[1:end-1]
x = [cos.(angles); 2 .* cos.(angles .+ pi/n)]
y = [sin.(angles); 2 .* sin.(angles .+ pi/n)]
z = (x .- 0.5).^2 + (y .- 0.5).^2 .+ 0.5 .* RNG.randn.()

triangulation_inner = reduce(hcat, map(i -> [0, 1, n] .+ i, 1:n))
triangulation_outer = reduce(hcat, map(i -> [n-1, n, 0] .+ i, 1:n))
triangulation = hcat(triangulation_inner, triangulation_outer)

f, ax, _ = tricontourf(x, y, z, triangulation = triangulation,
axis = (; aspect = 1, title = "Manual triangulation"))
scatter!(x, y, color = z, strokewidth = 1, strokecolor = :black)

tricontourf(f[1, 2], x, y, z, triangulation = Makie.DelaunayTriangulation(),
axis = (; aspect = 1, title = "Delaunay triangulation"))
scatter!(x, y, color = z, strokewidth = 1, strokecolor = :black)

f
end

@reference_test "marker offset in data space" begin
f = Figure()
ax = Axis(f[1, 1]; xticks=0:1, yticks=0:10)
Expand All @@ -571,4 +646,111 @@ end

f
end
end
end

@reference_test "hexbin bin int" begin
f = Figure(resolution = (800, 800))

x = RNG.rand(300)
y = RNG.rand(300)

for i in 2:5
ax = Axis(f[fldmod1(i-1, 2)...], title = "bins = $i", aspect = DataAspect())
hexbin!(ax, x, y, bins = i)
wireframe!(ax, Rect2f(Point2f.(x, y)), color = :red)
scatter!(ax, x, y, color = :red, markersize = 5)
end

f
end

@reference_test "hexbin bin tuple" begin
f = Figure(resolution = (800, 800))

x = RNG.rand(300)
y = RNG.rand(300)

for i in 2:5
ax = Axis(f[fldmod1(i-1, 2)...], title = "bins = (3, $i)", aspect = DataAspect())
hexbin!(ax, x, y, bins = (3, i))
wireframe!(ax, Rect2f(Point2f.(x, y)), color = :red)
scatter!(ax, x, y, color = :red, markersize = 5)
end

f
end



@reference_test "hexbin two cellsizes" begin
f = Figure(resolution = (800, 800))

x = RNG.rand(300)
y = RNG.rand(300)

for (i, cellsize) in enumerate([0.1, 0.15, 0.2, 0.25])
ax = Axis(f[fldmod1(i, 2)...], title = "cellsize = ($cellsize, $cellsize)", aspect = DataAspect())
hexbin!(ax, x, y, cellsize = (cellsize, cellsize))
wireframe!(ax, Rect2f(Point2f.(x, y)), color = :red)
scatter!(ax, x, y, color = :red, markersize = 5)
end

f
end

@reference_test "hexbin one cellsize" begin
f = Figure(resolution = (800, 800))

x = RNG.rand(300)
y = RNG.rand(300)

for (i, cellsize) in enumerate([0.1, 0.15, 0.2, 0.25])
ax = Axis(f[fldmod1(i, 2)...], title = "cellsize = $cellsize", aspect = DataAspect())
hexbin!(ax, x, y, cellsize = cellsize)
wireframe!(ax, Rect2f(Point2f.(x, y)), color = :red)
scatter!(ax, x, y, color = :red, markersize = 5)
end

f
end

@reference_test "hexbin threshold" begin
f = Figure(resolution = (800, 800))

x = RNG.randn(100000)
y = RNG.randn(100000)

for (i, threshold) in enumerate([1, 10, 100, 500])
ax = Axis(f[fldmod1(i, 2)...], title = "threshold = $threshold", aspect = DataAspect())
hexbin!(ax, x, y, cellsize = 0.4, threshold = threshold)
end
f
end

@reference_test "hexbin scale" begin
x = RNG.randn(100000)
y = RNG.randn(100000)

f = Figure()
hexbin(f[1, 1], x, y, bins = 40,
axis = (aspect = DataAspect(), title = "scale = identity"))
hexbin(f[1, 2], x, y, bins = 40, scale=log10,
axis = (aspect = DataAspect(), title = "scale = log10"))
f
end

# Scatter needs working highclip/lowclip first
# @reference_test "hexbin colorrange highclip lowclip" begin
# x = RNG.randn(100000)
# y = RNG.randn(100000)

# hexbin(x, y,
# bins = 40,
# axis = (aspect = DataAspect(),),
# colorrange = (10, 300),
# highclip = :red,
# lowclip = :pink,
# strokewidth = 1,
# strokecolor = :gray30
# )
# end