Skip to content

Commit

Permalink
Merge branch 'master' into ff/3D_controller
Browse files Browse the repository at this point in the history
  • Loading branch information
ffreyer committed Dec 7, 2023
2 parents f6c7189 + 0275665 commit e3acf66
Show file tree
Hide file tree
Showing 288 changed files with 26,016 additions and 14,046 deletions.
41 changes: 34 additions & 7 deletions .github/workflows/CompatHelper.yml
Original file line number Diff line number Diff line change
@@ -1,18 +1,45 @@
name: CompatHelper
on:
schedule:
- cron: '0 0 * * *' # Everyday at midnight
- cron: 0 0 * * *
workflow_dispatch:
permissions:
contents: write
pull-requests: write
jobs:
CompatHelper:
runs-on: ubuntu-latest
permissions:
contents: write
steps:
- name: Pkg.add("CompatHelper")
run: julia -e 'using Pkg; Pkg.add("CompatHelper")'
- name: CompatHelper.main()
- name: Check if Julia is already available in the PATH
id: julia_in_path
run: which julia
continue-on-error: true
- name: Install Julia, but only if it is not already available in the PATH
uses: julia-actions/setup-julia@v1
with:
version: '1'
arch: ${{ runner.arch }}
if: steps.julia_in_path.outcome != 'success'
- name: "Add the General registry via Git"
run: |
import Pkg
ENV["JULIA_PKG_SERVER"] = ""
Pkg.Registry.add("General")
shell: julia --color=yes {0}
- name: "Install CompatHelper"
run: |
import Pkg
name = "CompatHelper"
uuid = "aa819f21-2bde-4658-8897-bab36330d9b7"
version = "3"
Pkg.add(; name, uuid, version)
shell: julia --color=yes {0}
- name: "Run CompatHelper"
run: |
import CompatHelper
CompatHelper.main(subdirs=["", "MakieCore", "GLMakie", "WGLMakie", "CairoMakie", "RPRMakie"])
shell: julia --color=yes {0}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
COMPATHELPER_PRIV: ${{ secrets.DOCUMENTER_KEY }}
run: julia -e 'using CompatHelper; CompatHelper.main()'
# COMPATHELPER_PRIV: ${{ secrets.COMPATHELPER_PRIV }}
1 change: 1 addition & 0 deletions .github/workflows/Docs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ jobs:
uses: julia-actions/setup-julia@v1
with:
version: '1'
- uses: julia-actions/cache@v1
- name: Build and deploy docs
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
Expand Down
4 changes: 4 additions & 0 deletions .github/workflows/compilation-benchmark.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ on:
branches:
- master
- sd/beta-20
concurrency:
group: ${{ github.workflow }}-${{ github.head_ref || github.run_id }}
cancel-in-progress: true
jobs:
benchmark:
name: ${{ matrix.package }}
Expand All @@ -26,6 +29,7 @@ jobs:
- uses: julia-actions/setup-julia@v1
with:
version: '1'
include-all-prereleases: true
arch: x64
- uses: julia-actions/cache@v1
- name: Benchmark
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/refimages_status.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: "Download artifact"
uses: actions/github-script@v6
uses: actions/github-script@v7
with:
debug: true
script: |
Expand All @@ -39,7 +39,7 @@ jobs:
run: unzip n_missing_refimages.zip

- name: Add reference images status
uses: actions/github-script@v6
uses: actions/github-script@v7
with:
debug: true
github-token: ${{ secrets.GITHUB_TOKEN }}
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/wglmakie.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ on:
- '*'
branches:
- master

concurrency:
group: ${{ github.workflow }}-${{ github.head_ref || github.run_id }}
cancel-in-progress: true
Expand Down
9 changes: 5 additions & 4 deletions CairoMakie/Project.toml
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
name = "CairoMakie"
uuid = "13f3f980-e62b-5c42-98c6-ff1f3baf88f0"
author = ["Simon Danisch <sdanisch@gmail.com>"]
version = "0.10.11"
version = "0.11.3"

[deps]
Base64 = "2a0f44e3-6c83-55bd-87e4-b1978d98bd5f"
CRC32c = "8bf52ea8-c179-5cab-976a-9e18b702a9bc"
Cairo = "159f3aea-2a34-519c-b102-8c37f9878175"
Colors = "5ae59095-9a9b-59fe-a467-6f913c188581"
FFTW = "7a1cc6ca-52ef-59f5-83cd-3a7055c09341"
Expand All @@ -13,17 +13,18 @@ FreeType = "b38be410-82b0-50bf-ab77-7b57e271db43"
GeometryBasics = "5c1252a2-5f33-56bf-86c9-59e7332b4326"
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
Makie = "ee78f7c6-11fb-53f2-987a-cfe4a2b5a57a"
SHA = "ea8e919c-243c-51af-8825-aaa63cd721ce"
PrecompileTools = "aea7be01-6a6a-4083-8856-8a6e6704d82a"

[compat]
CRC32c = "1.0, 1.6"
Cairo = "1.0.4"
Colors = "0.10, 0.11, 0.12"
FFTW = "1"
FileIO = "1.1"
FreeType = "3, 4.0"
GeometryBasics = "0.4.1"
Makie = "=0.19.11"
LinearAlgebra = "1.0, 1.6"
Makie = "=0.20.2"
PrecompileTools = "1.0"
julia = "1.3"

Expand Down
5 changes: 2 additions & 3 deletions CairoMakie/src/CairoMakie.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,12 @@ module CairoMakie

using Makie, LinearAlgebra
using Colors, GeometryBasics, FileIO
import SHA
import Base64
import CRC32c
import Cairo

using Makie: Scene, Lines, Text, Image, Heatmap, Scatter, @key_str, broadcast_foreach
using Makie: convert_attribute, @extractvalue, LineSegments, to_ndim, NativeFont
using Makie: @info, @get_attribute, Combined, MakieScreen
using Makie: @info, @get_attribute, Plot, MakieScreen
using Makie: to_value, to_colormap, extrema_nan
using Makie.Observables
using Makie: spaces, is_data_space, is_pixel_space, is_relative_space, is_clip_space
Expand Down
23 changes: 12 additions & 11 deletions CairoMakie/src/display.jl
Original file line number Diff line number Diff line change
Expand Up @@ -76,18 +76,18 @@ function Makie.backend_show(screen::Screen{SVG}, io::IO, ::MIME"image/svg+xml",
svg = replace(svg, id => "surface$i")
end

# salt svg ids with the first 8 characters of the base64 encoded
# sha512 hash to avoid collisions across svgs when embedding them on
# websites. the hash and therefore the salt will always be the same for the same file
# salt svg ids with the 8 hex characters of the crc32 checksum to avoid collisions
# across svgs when embedding them on websites.
# the hash and therefore the salt will always be the same for the same file
# so the output is deterministic
salt = String(Base64.base64encode(SHA.sha512(svg)))[1:8]

ids = sort(unique(collect(m[1] for m in eachmatch(r"id\s*=\s*\"([^\"]*)\"", svg))))

for id in ids
svg = replace(svg, id => "$id-$salt")
end

salt = repr(CRC32c.crc32c(svg))[end-7:end]

# matches:
# id="someid"
# xlink:href="someid" (but not xlink:href="data:someothercontent" which is how image data is attached)
# url(#someid)
svg = replace(svg, r"((?:(?:id|xlink:href)=\"(?!data:)[^\"]+)|url\(#[^)]+)" => SubstitutionString("\\1-$salt"))
print(io, svg)
return screen
end
Expand Down Expand Up @@ -117,6 +117,7 @@ end

const DISABLED_MIMES = Set{String}()
const SUPPORTED_MIMES = Set([
map(x->string(x()), Makie.WEB_MIMES)...,
"image/svg+xml",
"application/pdf",
"application/postscript",
Expand Down
32 changes: 17 additions & 15 deletions CairoMakie/src/infrastructure.jl
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ function cairo_draw(screen::Screen, scene::Scene)
end

"""
is_cairomakie_atomic_plot(plot::Combined)::Bool
is_cairomakie_atomic_plot(plot::Plot)::Bool
Returns whether the plot is considered atomic for the CairoMakie backend.
This is overridden for `Poly`, `Band`, and `Tricontourf` so we can apply
Expand All @@ -66,14 +66,14 @@ CairoMakie can treat them as atomic plots and render them directly.
Plots with children are by default recursed into. This can be overridden
by defining specific dispatches for `is_cairomakie_atomic_plot` for a given plot type.
"""
is_cairomakie_atomic_plot(plot::Combined) = isempty(plot.plots) || to_value(get(plot, :rasterize, false)) != false
is_cairomakie_atomic_plot(plot::Plot) = isempty(plot.plots) || to_value(get(plot, :rasterize, false)) != false

"""
check_parent_plots(f, plot::Combined)::Bool
check_parent_plots(f, plot::Plot)::Bool
Returns whether the plot's parent tree satisfies the predicate `f`.
`f` must return a `Bool` and take a plot as its only argument.
"""
function check_parent_plots(f, plot::Combined)
function check_parent_plots(f, plot::Plot)
if f(plot)
check_parent_plots(f, parent(plot))
else
Expand All @@ -87,11 +87,9 @@ end

function prepare_for_scene(screen::Screen, scene::Scene)

# get the root area to correct for its pixel size when translating
root_area = Makie.root(scene).px_area[]

root_area_height = widths(root_area)[2]
scene_area = pixelarea(scene)[]
# get the root area to correct for its size when translating
root_area_height = widths(Makie.root(scene))[2]
scene_area = viewport(scene)[]
scene_height = widths(scene_area)[2]
scene_x_origin, scene_y_origin = scene_area.origin

Expand All @@ -103,7 +101,7 @@ function prepare_for_scene(screen::Screen, scene::Scene)
top_offset = root_area_height - scene_height - scene_y_origin
Cairo.translate(screen.context, scene_x_origin, top_offset)

# clip the scene to its pixelarea
# clip the scene to its viewport
Cairo.rectangle(screen.context, 0, 0, widths(scene_area)...)
Cairo.clip(screen.context)

Expand All @@ -116,15 +114,15 @@ function draw_background(screen::Screen, scene::Scene)
if scene.clear[]
bg = scene.backgroundcolor[]
Cairo.set_source_rgba(cr, red(bg), green(bg), blue(bg), alpha(bg));
r = pixelarea(scene)[]
r = viewport(scene)[]
Cairo.rectangle(cr, origin(r)..., widths(r)...) # background
fill(cr)
end
Cairo.restore(cr)
foreach(child_scene-> draw_background(screen, child_scene), scene.children)
end

function draw_plot(scene::Scene, screen::Screen, primitive::Combined)
function draw_plot(scene::Scene, screen::Screen, primitive::Plot)
if to_value(get(primitive, :visible, true))
if isempty(primitive.plots)
Cairo.save(screen.context)
Expand All @@ -145,11 +143,11 @@ end
# instead of the whole Scene
# - Recognize when a screen is an image surface, and set scale to render the plot
# at the scale of the device pixel
function draw_plot_as_image(scene::Scene, screen::Screen, primitive::Combined, scale::Number = 1)
function draw_plot_as_image(scene::Scene, screen::Screen, primitive::Plot, scale::Number = 1)
# you can provide `p.rasterize = scale::Int` or `p.rasterize = true`, both of which are numbers

# Extract scene width in pixels
w, h = Int.(scene.px_area[].widths)
# Extract scene width in device indepentent units
w, h = size(scene)
# Create a new Screen which renders directly to an image surface,
# specifically for the plot's parent scene.
scr = Screen(scene; px_per_unit = scale)
Expand Down Expand Up @@ -178,3 +176,7 @@ end
function draw_atomic(::Scene, ::Screen, x)
@warn "$(typeof(x)) is not supported by cairo right now"
end

function draw_atomic(::Scene, ::Screen, x::Makie.PlotList)
# Doesn't need drawing
end
38 changes: 32 additions & 6 deletions CairoMakie/src/overrides.jl
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ complex and slower to draw than standard paths with single color.
function draw_plot(scene::Scene, screen::Screen, poly::Poly)
# dispatch on input arguments to poly to use smarter drawing methods than
# meshes if possible
draw_poly(scene, screen, poly, to_value.(poly.input_args)...)
return draw_poly(scene, screen, poly, to_value.(poly.args)...)
end

# Override `is_cairomakie_atomic_plot` to allow `poly` to remain a unit,
Expand Down Expand Up @@ -73,25 +73,26 @@ function draw_poly(scene::Scene, screen::Screen, poly, points_list::Vector{<:Vec
end

draw_poly(scene::Scene, screen::Screen, poly, rect::Rect2) = draw_poly(scene, screen, poly, [rect])
draw_poly(scene::Scene, screen::Screen, poly, bezierpath::BezierPath) = draw_poly(scene, screen, poly, [bezierpath])

function draw_poly(scene::Scene, screen::Screen, poly, rects::Vector{<:Rect2})
function draw_poly(scene::Scene, screen::Screen, poly, shapes::Vector{<:Union{Rect2,BezierPath}})
model = poly.model[]
space = to_value(get(poly, :space, :data))
projected_rects = project_rect.(Ref(scene), space, rects, Ref(model))
projected_shapes = project_shape.(Ref(scene), space, shapes, Ref(model))

color = to_cairo_color(poly.color[], poly)

linestyle = Makie.convert_attribute(poly.linestyle[], key"linestyle"())
if isnothing(linestyle)
linestyle_diffed = nothing
elseif linestyle isa AbstractVector{Float64}
elseif linestyle isa AbstractVector{<:Real}
linestyle_diffed = diff(Float64.(linestyle))
else
error("Wrong type for linestyle: $(poly.linestyle[]).")
end
strokecolor = to_cairo_color(poly.strokecolor[], poly)
broadcast_foreach(projected_rects, color, strokecolor, poly.strokewidth[]) do r, c, sc, sw
Cairo.rectangle(screen.context, origin(r)..., widths(r)...)
broadcast_foreach(projected_shapes, color, strokecolor, poly.strokewidth[]) do shape, c, sc, sw
create_shape_path!(screen.context, shape)
set_source(screen.context, c)
Cairo.fill_preserve(screen.context)
isnothing(linestyle_diffed) || Cairo.set_dash(screen.context, linestyle_diffed .* sw)
Expand All @@ -101,6 +102,31 @@ function draw_poly(scene::Scene, screen::Screen, poly, rects::Vector{<:Rect2})
end
end

function project_shape(scene, space, shape::BezierPath, model)
commands = Makie.PathCommand[]
for cmd in shape.commands
if cmd isa EllipticalArc
bezier = Makie.elliptical_arc_to_beziers(cmd)
for b in bezier.commands
push!(commands, project_command(b, scene, space, model))
end
else
push!(commands, project_command(cmd, scene, space, model))
end
end
BezierPath(commands)
end

function create_shape_path!(ctx, r::Rect2)
Cairo.rectangle(ctx, origin(r)..., widths(r)...)
end

function create_shape_path!(ctx, b::BezierPath)
for cmd in b.commands
path_command(ctx, cmd)
end
end

function polypath(ctx, polygon)
isempty(polygon) && return nothing
ext = decompose(Point2f, polygon.exterior)
Expand Down
6 changes: 6 additions & 0 deletions CairoMakie/src/precompiles.jl
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,9 @@ let
include(shared_precompile)
end
end
precompile(draw_atomic_scatter, (Scene, Cairo.CairoContext, Tuple{typeof(identity),typeof(identity)},
Vector{ColorTypes.RGBA{Float32}}, Vec{2,Float32}, ColorTypes.RGBA{Float32},
Float32, BezierPath, Vec{2,Float32}, Quaternionf,
Mat4f, Vector{Point{2,Float32}},
Mat4f, Makie.FreeTypeAbstraction.FTFont, Symbol,
Symbol))
Loading

0 comments on commit e3acf66

Please sign in to comment.