Skip to content

Commit

Permalink
Merge branch 'breaking-0.22' into sd/metamesh
Browse files Browse the repository at this point in the history
  • Loading branch information
ffreyer authored Oct 23, 2024
2 parents c8fbe39 + 16e3536 commit 4cad6ad
Show file tree
Hide file tree
Showing 17 changed files with 117 additions and 57 deletions.
7 changes: 6 additions & 1 deletion .github/workflows/compilation-benchmark.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -38,4 +38,9 @@ jobs:
GITHUB_TOKEN: ${{ secrets.BENCHMARK_KEY }}
PR_NUMBER: ${{ github.event.number }}
run: >
DISPLAY=:0 xvfb-run -s '-screen 0 1024x768x24' julia --project=./metrics/ttfp/ ./metrics/ttfp/run-benchmark.jl ${{ matrix.package }} 7 ${{ github.event.pull_request.base.ref }}
DISPLAY=:0 xvfb-run -s '-screen 0 1024x768x24' julia --project=./metrics/ttfp/ ./metrics/ttfp/run-benchmark.jl ${{ matrix.package }} 20 ${{ github.event.pull_request.base.ref }}
- name: Upload measurements as artifact
uses: actions/upload-artifact@v4
with:
name: ${{ matrix.package }}
path: ./json
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,15 @@

## [Unreleased]

- Improved CairoMakie's 2D mesh drawing performance by ~30% [#4132](https://github.com/MakieOrg/Makie.jl/pull/4132).
- Allow `width` to be set per box in `boxplot` [#4447](https://github.com/MakieOrg/Makie.jl/pull/4447).
- For `Textbox`es in which a fixed width is specified, the text is now scrolled
if the width is exceeded [#4293](https://github.com/MakieOrg/Makie.jl/pull/4293)
- Changed image, heatmap and surface picking indices to correctly index the relevant matrix arguments. [#4459](https://github.com/MakieOrg/Makie.jl/pull/4459)
- Improved performance of `record` by avoiding unnecessary copying in common cases [#4475](https://github.com/MakieOrg/Makie.jl/pull/4475).
- Updated to GeoemtryBasic 0.5 [#4319](https://github.com/MakieOrg/Makie.jl/pull/4319)
- Fix usage of `AggMean()` and other aggregations operating on 3d data for `datashader` [#4346](https://github.com/MakieOrg/Makie.jl/pull/4346).
- Use polys for axis3 [#4463](https://github.com/MakieOrg/Makie.jl/pull/4463).
- Changed default for `circular_rotation` in Camera3D to false, so that the camera doesn't change rotation direction anymore [4492](https://github.com/MakieOrg/Makie.jl/pull/4492)
- Fixed `pick(scene, rect2)` in WGLMakie [#4488](https://github.com/MakieOrg/Makie.jl/pull/4488)

Expand Down
10 changes: 5 additions & 5 deletions CairoMakie/src/primitives.jl
Original file line number Diff line number Diff line change
Expand Up @@ -892,11 +892,11 @@ function draw_atomic(scene::Scene, screen::Screen, @nospecialize(primitive::Maki
return nothing
end

function draw_mesh2D(scene, screen, @nospecialize(plot), @nospecialize(mesh))
function draw_mesh2D(scene, screen, @nospecialize(plot::Makie.Mesh), @nospecialize(mesh::GeometryBasics.Mesh))
space = to_value(get(plot, :space, :data))::Symbol
transform_func = Makie.transform_func(plot)
model = plot.model[]::Mat4d
vs = project_position(scene, transform_func, space, decompose(Point, mesh), model)
vs = project_position(scene, transform_func, space, GeometryBasics.coordinates(mesh), model)::Vector{Point2f}
fs = decompose(GLTriangleFace, mesh)::Vector{GLTriangleFace}
uv = decompose_uv(mesh)::Union{Nothing, Vector{Vec2f}}
# Note: This assume the function is only called from mesh plots
Expand Down Expand Up @@ -927,9 +927,9 @@ function draw_mesh2D(screen, per_face_cols, vs::Vector{<: Point2}, fs::Vector{GL

Cairo.mesh_pattern_begin_patch(pattern)

Cairo.mesh_pattern_move_to(pattern, t1...)
Cairo.mesh_pattern_line_to(pattern, t2...)
Cairo.mesh_pattern_line_to(pattern, t3...)
Cairo.mesh_pattern_move_to(pattern, t1[1], t1[2])
Cairo.mesh_pattern_line_to(pattern, t2[1], t2[2])
Cairo.mesh_pattern_line_to(pattern, t3[1], t3[2])

mesh_pattern_set_corner_color(pattern, 0, c1)
mesh_pattern_set_corner_color(pattern, 1, c2)
Expand Down
2 changes: 2 additions & 0 deletions CairoMakie/test/svg_tests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ end
@testset "SVG rasterization" begin
@test svg_isnt_rasterized(Scene())
@test svg_isnt_rasterized(begin f = Figure(); Axis(f[1, 1]); f end)
@test svg_isnt_rasterized(begin f = Figure(); Axis3(f[1, 1]); f end)
@test svg_isnt_rasterized(begin f = Figure(); PolarAxis(f[1, 1]); f end)
@test svg_isnt_rasterized(scatter(1:3))
@test svg_isnt_rasterized(lines(1:3))
@test svg_isnt_rasterized(heatmap(rand(5, 5)))
Expand Down
2 changes: 1 addition & 1 deletion MakieCore/Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ IntervalSets = "8197267c-284f-5f27-9208-e0e47529a953"
Observables = "510215fc-4207-5dde-b226-833fc4488ee2"

[compat]
ColorTypes = "0.8, 0.9, 0.10, 0.11"
ColorTypes = "0.8, 0.9, 0.10, 0.11, 0.12"
GeometryBasics = "0.4.11"
IntervalSets = "0.6, 0.7"
Observables = "0.5.1"
Expand Down
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ Base64 = "1.0, 1.6"
CRC32c = "1.0, 1.6"
ColorBrewer = "0.4"
ColorSchemes = "3.5"
ColorTypes = "0.8, 0.9, 0.10, 0.11"
ColorTypes = "0.8, 0.9, 0.10, 0.11, 0.12"
Colors = "0.9, 0.10, 0.11, 0.12"
Contour = "0.5, 0.6"
DelaunayTriangulation = "1.0"
Expand Down
13 changes: 6 additions & 7 deletions ReferenceTests/src/tests/examples2d.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1613,8 +1613,8 @@ end
boxplot(fig[1, 1], categories, values)

dodge = RNG.rand(1:2, 900)
boxplot(fig[1, 2], categories, values, dodge = dodge, show_notch = true,
color = map(d->d==1 ? :blue : :red, dodge),
boxplot(fig[1, 2], categories, values, dodge = dodge, show_notch = true,
color = map(d->d==1 ? :blue : :red, dodge),
outliercolor = RNG.rand([:red, :green, :blue, :black, :orange], 900)
)

Expand All @@ -1631,16 +1631,15 @@ end

weights = 1.0 ./ (1.0 .+ abs.(values))
boxplot!(ax_vert, categories, values, orientation=:vertical, weights = weights,
gap = 0.5,
show_notch = true, notchwidth = 0.75,
gap = 0.5,
show_notch = true, notchwidth = 0.75,
markersize = 5, strokewidth = 2.0, strokecolor = :black,
medianlinewidth = 5, mediancolor = :orange,
whiskerwidth = 1.0, whiskerlinewidth = 3, whiskercolor = :green,
outlierstrokewidth = 1.0, outlierstrokecolor = :red,
width = 1.5,

width = 1.5,
)
boxplot!(ax_horiz, categories, values; orientation=:horizontal)
boxplot!(ax_horiz, categories, values; orientation=:horizontal, width = categories ./ 3)

fig
end
Expand Down
9 changes: 5 additions & 4 deletions ReferenceTests/src/tests/generic_components.jl
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# For things that aren't as plot related

@reference_test "picking" begin
# @reference_test "picking"
begin
scene = Scene(size = (230, 370))
campixel!(scene)

Expand All @@ -23,7 +24,7 @@

# reversed axis
i2 = image!(scene, 210..180, 20..50, rand(RGBf, 2, 2))
s2 = surface!(scene, 210..180, 80..110, rand(2, 2))
s2 = surface!(scene, 210..180, 80..110, [1 2; 3 4], interpolate = false)
hm2 = heatmap!(scene, [210, 180], [140, 170], [1 2; 3 4])

scene # for easy reviewing of the plot
Expand All @@ -33,8 +34,8 @@

# verify that heatmap path is used for heatmaps
if Symbol(Makie.current_backend()) == :WGLMakie
@test length(faces(WGLMakie.create_shader(scene, hm).vertexarray)) > 2
@test length(faces(WGLMakie.create_shader(scene, hm2).vertexarray)) > 2
@test length(WGLMakie.create_shader(scene, hm).vertexarray.buffers[:faces]) > 2
@test length(WGLMakie.create_shader(scene, hm2).vertexarray.buffers[:faces]) > 2
elseif Symbol(Makie.current_backend()) == :GLMakie
screen = scene.current_screens[1]
for plt in (hm, hm2)
Expand Down
8 changes: 6 additions & 2 deletions WGLMakie/src/imagelike.jl
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,12 @@ function create_shader(mscene::Scene, plot::Surface)
# https://github.com/MakieOrg/Makie.jl/pull/2598#discussion_r1152552196
uv = Buffer(lift(plot, rect) do r
Nx, Ny = r.nvertices
f = Vec2f(1 / Nx, 1 / Ny)
[f .* Vec2f(0.5 + i, 0.5 + j) for j in Ny-1:-1:0 for i in 0:Nx-1]
if (Nx, Ny) == (2, 2)
Vec2f[(0,1), (1,1), (1,0), (0,0)]
else
f = Vec2f(1 / Nx, 1 / Ny)
[f .* Vec2f(0.5 + i, 0.5 + j) for j in Ny-1:-1:0 for i in 0:Nx-1]
end
end)
normals = Buffer(lift(plot, ps, fs, plot.invert_normals) do ps, fs, invert
ns = Makie.nan_aware_normals(ps, fs)
Expand Down
File renamed without changes.
Binary file added docs/src/public/logo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
File renamed without changes
32 changes: 26 additions & 6 deletions metrics/ttfp/benchmark-ttfp.jl
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@ set_theme!(size=(800, 600))
create_time = @ctime fig = scatter(1:4; color=1:4, colormap=:turbo, markersize=20, visible=true)
display_time = @ctime colorbuffer(fig; px_per_unit=1)

using BenchmarkTools
using BenchmarkTools.JSON
using JSON
using Pkg
using Statistics: median

project_name = basename(dirname(Pkg.project().path))

Expand All @@ -31,13 +31,33 @@ old = isfile(result) ? JSON.parse(read(result, String)) : [[], [], [], [], []]
@show [t_using, create_time, display_time]
push!.(old[1:3], [t_using, create_time, display_time])

b1 = @benchmark fig = scatter(1:4; color=1:4, colormap=:turbo, markersize=20, visible=true)
b2 = @benchmark colorbuffer(fig; px_per_unit=1)
macro simple_median_time(expr)
time_expr = quote
local elapsedtime = time_ns()
$expr
elapsedtime = time_ns() - elapsedtime
Float64(elapsedtime)
end

quote
times = Float64[]
for i in 1:101
t = Core.eval(Main, $(QuoteNode(time_expr)))
if i > 1
push!(times, t)
end
end
median(times)
end
end
@time "creating figure" figure_time = @simple_median_time fig = scatter(1:4; color=1:4, colormap=:turbo, markersize=20, visible=true)
fig = scatter(1:4; color=1:4, colormap=:turbo, markersize=20, visible=true)
@time "colorbuffer" colorbuffer_time = @simple_median_time colorbuffer(fig; px_per_unit=1)

using Statistics

push!(old[4], mean(b1.times))
push!(old[5], mean(b2.times))
push!(old[4], figure_time)
push!(old[5], colorbuffer_time)

open(io-> JSON.print(io, old), result, "w")

Expand Down
17 changes: 12 additions & 5 deletions metrics/ttfp/run-benchmark.jl
Original file line number Diff line number Diff line change
Expand Up @@ -182,9 +182,10 @@ using Random

function run_benchmarks(projects; n=n_samples)
benchmark_file = joinpath(@__DIR__, "benchmark-ttfp.jl")
for project in shuffle!(repeat(projects; outer=n))
# go A, B, A, B, A, etc.
for project in repeat(projects, n)
println(basename(project))
run(`$(Base.julia_cmd()) --startup-file=no --project=$(project) $benchmark_file $Package`)
project_name = basename(project)
end
return
end
Expand Down Expand Up @@ -221,15 +222,14 @@ end
pkgs = NamedTuple[(; path="./MakieCore"), (; path="."), (; path="./$Package")]
# cd("dev/Makie")
Pkg.develop(pkgs)
Pkg.add([(; name="BenchmarkTools")])
pkg"add GeometryBasics#master MeshIO#ff/GeometryBasics_refactor ShaderAbstractions#ff/GeometryBasics_refactor"

Pkg.add([(; name="JSON")])

@time Pkg.precompile()

project2 = make_project_folder(base_branch)
Pkg.activate(project2)
pkgs = [(; rev=base_branch, name="MakieCore"), (; rev=base_branch, name="Makie"), (; rev=base_branch, name="$Package"), (;name="BenchmarkTools")]
pkgs = [(; rev=base_branch, name="MakieCore"), (; rev=base_branch, name="Makie"), (; rev=base_branch, name="$Package"), (;name="JSON")]
Package == "WGLMakie" && push!(pkgs, (; name="Electron"))
Pkg.add(pkgs)

Expand All @@ -252,3 +252,10 @@ else
@info("Not commenting, no PR found")
println(update_comment(COMMENT_TEMPLATE, Package, benchmark_rows))
end

mkdir("json")
for p in [project1, project2]
name = basename(p)
file = "$name-benchmark.json"
mv(file, joinpath("json", file))
end
43 changes: 28 additions & 15 deletions src/makielayout/blocks/axis3d.jl
Original file line number Diff line number Diff line change
Expand Up @@ -664,29 +664,42 @@ function add_panel!(scene, ax, dim1, dim2, dim3, limits, min3)
string((:x, :y, :z)[dim2]) * string(sym))
attr(sym) = getproperty(ax, dimsym(sym))

vertices = lift(limits, min3) do lims, mi3

rect = lift(limits) do lims
mi = minimum(lims)
ma = maximum(lims)
Polygon([
Point2(mi[dim1], mi[dim2]),
Point2(ma[dim1], mi[dim2]),
Point2(ma[dim1], ma[dim2]),
Point2(mi[dim1], ma[dim2])
])
end

v3 = if mi3
mi[dim3] + 0.005 * (mi[dim3] - ma[dim3])
else
ma[dim3] + 0.005 * (ma[dim3] - mi[dim3])
end
plane_offset = lift(limits, min3) do lims, mi3
mi = minimum(lims)
ma = maximum(lims)

p1 = dim3point(dim1, dim2, dim3, mi[dim1], mi[dim2], v3)
p2 = dim3point(dim1, dim2, dim3, mi[dim1], ma[dim2], v3)
p3 = dim3point(dim1, dim2, dim3, ma[dim1], ma[dim2], v3)
p4 = dim3point(dim1, dim2, dim3, ma[dim1], mi[dim2], v3)
[p1, p2, p3, p4]
mi3 ? mi[dim3] : ma[dim3]
end

faces = [1 2 3; 3 4 1]
plane = Symbol((:x, :y, :z)[dim1], (:x, :y, :z)[dim2])

panel = mesh!(scene, vertices, faces, shading = NoShading, inspectable = false,
panel = poly!(scene, rect, inspectable = false,
xautolimits = false, yautolimits = false, zautolimits = false,
color = attr(:panelcolor), visible = attr(:panelvisible))
color = attr(:panelcolor), visible = attr(:panelvisible),
strokecolor = :transparent, strokewidth = 0,
transformation = (plane, 0),
)

on(plane_offset) do offset
translate!(
panel,
dim3 == 1 ? offset : zero(offset),
dim3 == 2 ? offset : zero(offset),
dim3 == 3 ? offset : zero(offset),
)
end

return panel
end

Expand Down
20 changes: 11 additions & 9 deletions src/stats/boxplot.jl
Original file line number Diff line number Diff line change
Expand Up @@ -85,11 +85,10 @@ function Makie.plot!(plot::BoxPlot)
plot[:color],
args...,
) do x, y, color, weights, width, range, show_outliers, whiskerwidth, show_notch, orientation, gap, dodge, n_dodge, dodge_gap
x̂, boxwidth = compute_x_and_width(x, width, gap, dodge, n_dodge, dodge_gap)
x̂, widths = compute_x_and_width(x, width, gap, dodge, n_dodge, dodge_gap)
if !(whiskerwidth === :match || whiskerwidth >= 0)
error("whiskerwidth must be :match or a positive number. Found: $whiskerwidth")
end
ww = whiskerwidth === :match ? boxwidth : whiskerwidth * boxwidth
outlier_points = Point2f[]
centers = Float32[]
medians = Float32[]
Expand All @@ -99,8 +98,10 @@ function Makie.plot!(plot::BoxPlot)
notchmax = Float32[]
t_segments = Point2f[]
outlier_indices = Int[]
T = color isa AbstractVector ? eltype(color) : typeof(color)
boxcolor = T[]
CT = color isa AbstractVector ? eltype(color) : typeof(color)
boxcolor = CT[]
WT = widths isa AbstractVector ? eltype(widths) : typeof(widths)
boxwidth = WT[]
for (i, (center, idxs)) in enumerate(StructArrays.finduniquesorted(x̂))
values = view(y, idxs)

Expand All @@ -117,7 +118,7 @@ function Makie.plot!(plot::BoxPlot)
end

# outliers
if Float64(range) != 0.0 # if the range is 0.0, the whiskers will extend to the data
if !iszero(range) # if the range is 0, the whiskers will extend to the data
limit = range * (q4 - q2)
inside = Float64[]
for (value, idx) in zip(values,idxs)
Expand All @@ -134,18 +135,19 @@ function Makie.plot!(plot::BoxPlot)
# change q1 and q5 to show outliers
# using maximum and minimum values inside the limits
q1, q5 = extrema_nan(inside)
# register boxcolor
push!(boxcolor, getuniquevalue(color, idxs))
end

# whiskers
HW = 0.5 * _cycle(ww, i) # Whisker width
lw, rw = center - HW, center + HW
bw = getuniquevalue(widths, idxs) # Box width
ww = whiskerwidth === :match ? bw : whiskerwidth * bw # Whisker width
lw, rw = center - ww/2, center + ww/2
push!(t_segments, (center, q2), (center, q1), (lw, q1), (rw, q1)) # lower T
push!(t_segments, (center, q4), (center, q5), (rw, q5), (lw, q5)) # upper T

# box
push!(boxcolor, getuniquevalue(color, idxs))
push!(centers, center)
push!(boxwidth, bw)
push!(boxmin, q2)
push!(medians, q3)
push!(boxmax, q4)
Expand Down
6 changes: 5 additions & 1 deletion src/utilities/utilities.jl
Original file line number Diff line number Diff line change
Expand Up @@ -462,7 +462,11 @@ function matrix_grid(x::ClosedInterval, y::ClosedInterval, z::AbstractMatrix)
end

function matrix_grid(x::AbstractArray, y::AbstractArray, z::AbstractMatrix)
ps = [Point3(get_dim(x, i, 1, size(z)), get_dim(y, i, 2, size(z)), z[i]) for i in CartesianIndices(z)]
if size(z) == (2, 2) # untesselated Rect2 is defined in counter-clockwise fashion
ps = Point3.(x[[1,2,2,1]], y[[1,1,2,2]], z[[1,2,2,1], [1,1,2,2]])
else
ps = [Point3(get_dim(x, i, 1, size(z)), get_dim(y, i, 2, size(z)), z[i]) for i in CartesianIndices(z)]
end
return vec(ps)
end

Expand Down

0 comments on commit 4cad6ad

Please sign in to comment.