Skip to content

Commit

Permalink
Merge branch 'master' into revimg
Browse files Browse the repository at this point in the history
  • Loading branch information
ffreyer authored Jul 29, 2024
2 parents 3f3ea48 + 4c4eaa1 commit 26648f6
Show file tree
Hide file tree
Showing 19 changed files with 339 additions and 84 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,12 @@
## [Unreleased]

- Support images with reversed axes [#3989](https://github.com/MakieOrg/Makie.jl/pull/3989)
- Introduce stroke_depth_shift + forward normal depth_shift for Poly [#4058](https://github.com/MakieOrg/Makie.jl/pull/4058).
- Use linestyle for Poly and Density legend elements [#4000](https://github.com/MakieOrg/Makie.jl/pull/4000).
- Bring back interpolation attribute for surface [#4056](https://github.com/MakieOrg/Makie.jl/pull/4056).
- Improved accuracy of framerate settings in GLMakie [#3954](https://github.com/MakieOrg/Makie.jl/pull/3954)
- Fix label_formatter being called twice in barplot [#4046](https://github.com/MakieOrg/Makie.jl/pull/4046).
- Fix error with automatic `highclip` or `lowclip` and scalar colors [#4048](https://github.com/MakieOrg/Makie.jl/pull/4048).
- Correct a bug in the `project` function when projecting using a `Scene`. [#3909](https://github.com/MakieOrg/Makie.jl/pull/3909).
- Correct a method ambiguity in `insert!` which was causing `PlotList` to fail on CairoMakie. [#4038](https://github.com/MakieOrg/Makie.jl/pull/4038)

Expand Down
1 change: 1 addition & 0 deletions GLMakie/src/GLMakie.jl
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ using Makie: @get_attribute, to_value, to_colormap, extrema_nan
using Makie: ClosedInterval, (..)
using Makie: to_native
using Makie: spaces, is_data_space, is_pixel_space, is_relative_space, is_clip_space
using Makie: BudgetedTimer, reset!
import Makie: to_font, el32convert, Shape, CIRCLE, RECTANGLE, ROUNDED_RECTANGLE, DISTANCEFIELD, TRIANGLE
import Makie: RelocatableFolders

Expand Down
51 changes: 25 additions & 26 deletions GLMakie/src/screen.jl
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,7 @@ mutable struct Screen{GLWindow} <: MakieScreen
config::Union{Nothing, ScreenConfig}
stop_renderloop::Bool
rendertask::Union{Task, Nothing}
timer::BudgetedTimer
px_per_unit::Observable{Float32}

screen2scene::Dict{WeakRef, ScreenID}
Expand Down Expand Up @@ -202,7 +203,7 @@ mutable struct Screen{GLWindow} <: MakieScreen
s = size(framebuffer)
screen = new{GLWindow}(
glscreen, shader_cache, framebuffer,
config, stop_renderloop, rendertask,
config, stop_renderloop, rendertask, BudgetedTimer(1.0 / 30.0),
Observable(0f0), screen2scene,
screens, renderlist, postprocessors, cache, cache2plot,
Matrix{RGB{N0f8}}(undef, s), Observable(nothing),
Expand Down Expand Up @@ -898,29 +899,25 @@ function vsynced_renderloop(screen)
end
pollevents(screen) # GLFW poll
render_frame(screen)
GLFW.SwapBuffers(to_native(screen))
yield()
GC.safepoint()
GLFW.SwapBuffers(to_native(screen))
end
end

function fps_renderloop(screen::Screen)
reset!(screen.timer, 1.0 / screen.config.framerate)
while isopen(screen) && !screen.stop_renderloop
if screen.config.pause_renderloop
pollevents(screen); sleep(0.1)
continue
end
time_per_frame = 1.0 / screen.config.framerate
t = time_ns()
pollevents(screen) # GLFW poll
render_frame(screen)
GLFW.SwapBuffers(to_native(screen))
t_elapsed = (time_ns() - t) / 1e9
diff = time_per_frame - t_elapsed
if diff > 0.001 # can't sleep less than 0.001
sleep(diff)
else # if we don't sleep, we still need to yield explicitely to other tasks
yield()
pollevents(screen)

if !screen.config.pause_renderloop
pollevents(screen) # GLFW poll
render_frame(screen)
GLFW.SwapBuffers(to_native(screen))
end

GC.safepoint()
sleep(screen.timer)
end
end

Expand All @@ -933,24 +930,26 @@ function requires_update(screen::Screen)
return false
end


# const time_record = sizehint!(Float64[], 100_000)

function on_demand_renderloop(screen::Screen)
# last_time = time_ns()
reset!(screen.timer, 1.0 / screen.config.framerate)
while isopen(screen) && !screen.stop_renderloop
t = time_ns()
time_per_frame = 1.0 / screen.config.framerate
pollevents(screen) # GLFW poll

if !screen.config.pause_renderloop && requires_update(screen)
render_frame(screen)
GLFW.SwapBuffers(to_native(screen))
end

t_elapsed = (time_ns() - t) / 1e9
diff = time_per_frame - t_elapsed
if diff > 0.001 # can't sleep less than 0.001
sleep(diff)
else # if we don't sleep, we still need to yield explicitely to other tasks
yield()
end
GC.safepoint()
sleep(screen.timer)

# t = time_ns()
# push!(time_record, 1e-9 * (t - last_time))
# last_time = t
end
cause = screen.stop_renderloop ? "stopped renderloop" : "closing window"
@debug("Leaving renderloop, cause: $(cause)")
Expand Down
13 changes: 9 additions & 4 deletions MakieCore/src/basic_plots.jl
Original file line number Diff line number Diff line change
Expand Up @@ -298,6 +298,8 @@ Plots a surface, where `(x, y)` define a grid whose heights are the entries in `
color = nothing
"Inverts the normals generated for the surface. This can be useful to illuminate the other side of the surface."
invert_normals = false
"[(W)GLMakie only] Specifies whether the surface matrix gets sampled with interpolation."
interpolate = true
mixin_generic_plot_attributes()...
mixin_shading_attributes()...
mixin_colormap_attributes()...
Expand All @@ -321,7 +323,7 @@ Creates a connected line plot for each element in `(x, y, z)`, `(x, y)` or `posi
Sets the dash pattern of the line. Options are `:solid` (equivalent to `nothing`), `:dot`, `:dash`, `:dashdot` and `:dashdotdot`.
These can also be given in a tuple with a gap style modifier, either `:normal`, `:dense` or `:loose`.
For example, `(:dot, :loose)` or `(:dashdot, :dense)`.
For custom patterns have a look at [`Makie.Linestyle`](@ref).
"""
linestyle = nothing
Expand Down Expand Up @@ -362,7 +364,7 @@ Plots a line for each pair of points in `(x, y, z)`, `(x, y)`, or `positions`.
Sets the dash pattern of the line. Options are `:solid` (equivalent to `nothing`), `:dot`, `:dash`, `:dashdot` and `:dashdotdot`.
These can also be given in a tuple with a gap style modifier, either `:normal`, `:dense` or `:loose`.
For example, `(:dot, :loose)` or `(:dashdot, :dense)`.
For custom patterns have a look at [`Makie.Linestyle`](@ref).
"""
linestyle = nothing
Expand Down Expand Up @@ -617,7 +619,7 @@ Plots polygons, which are defined by
Sets the dash pattern of the line. Options are `:solid` (equivalent to `nothing`), `:dot`, `:dash`, `:dashdot` and `:dashdotdot`.
These can also be given in a tuple with a gap style modifier, either `:normal`, `:dense` or `:loose`.
For example, `(:dot, :loose)` or `(:dashdot, :dense)`.
For custom patterns have a look at [`Makie.Linestyle`](@ref).
"""
linestyle = nothing
Expand All @@ -628,7 +630,10 @@ Plots polygons, which are defined by
shading = NoShading

cycle = [:color => :patchcolor]

"""
Depth shift of stroke plot. This is useful to avoid z-fighting between the stroke and the fill.
"""
stroke_depth_shift = -1.0f-5
mixin_generic_plot_attributes()...
mixin_colormap_attributes()...
end
Expand Down
17 changes: 10 additions & 7 deletions ReferenceTests/src/tests/examples2d.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1132,13 +1132,16 @@ end
hidespines!(ax)
colormap = :tab10
colorrange = (1, 10)
for i in 1:10
color = i
lines!(ax, i .* [10, 10], [10, 590]; color, colormap, colorrange, linewidth = 5)
scatter!(ax, fill(10 * i + 130, 50), range(10, 590, length = 50); color, colormap, colorrange)
poly!(ax, Ref(Point2f(260, i * 50)) .+ Point2f[(0, 0), (50, 0), (25, 40)]; color, colormap, colorrange)
text!(ax, 360, i * 50, text = "$i"; color, colormap, colorrange, fontsize = 40)
poly!(ax, [Ref(Point2f(430 + 20 * j, 20 * j + i * 50)) .+ Point2f[(0, 0), (30, 0), (15, 22)] for j in 1:3]; color, colormap, colorrange)
nan_color = :cyan
for i in -1:13
color = i == 13 ? NaN : i
lowclip = i == 0 ? Makie.automatic : :bisque
highclip = i == 11 ? Makie.automatic : :black
lines!(ax, i .* [8, 8], [10, 590]; color, colormap, colorrange, lowclip, highclip, nan_color, linewidth = 5)
scatter!(ax, fill(8 * i + 130, 50), range(10, 590, length = 50); color, colormap, colorrange, lowclip, highclip, nan_color)
poly!(ax, Ref(Point2f(260, i * 50)) .+ Point2f[(0, 0), (50, 0), (25, 40)]; color, colormap, colorrange, lowclip, highclip, nan_color)
text!(ax, 360, i * 50, text = "$i"; color, colormap, colorrange, lowclip, highclip, nan_color, fontsize = 40)
poly!(ax, [Ref(Point2f(430 + 20 * j, 20 * j + i * 50)) .+ Point2f[(0, 0), (30, 0), (15, 22)] for j in 1:3]; color, colormap, colorrange, lowclip, highclip, nan_color)
end
f
end
Expand Down
6 changes: 6 additions & 0 deletions ReferenceTests/src/tests/examples3d.jl
Original file line number Diff line number Diff line change
Expand Up @@ -623,3 +623,9 @@ end
@reference_test "Heatmap 3D" begin
heatmap(-2..2, -1..1, RNG.rand(100, 100); axis = (; type = LScene))
end

@reference_test "Surface interpolate attribute" begin
f, ls1, pl = surface(Makie.peaks(20); interpolate=true, axis=(; show_axis=false))
ls2, pl = surface(f[1, 2], Makie.peaks(20); interpolate=false, axis=(; show_axis=false))
f
end
4 changes: 3 additions & 1 deletion docs/src/.vitepress/config.mts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,9 @@ export default defineConfig({
head: [
['link', { rel: 'icon', href: 'REPLACE_ME_DOCUMENTER_VITEPRESS_FAVICON' }],
['script', {src: '/versions.js'}],
['script', {src: `${baseTemp.base}siteinfo.js`}]
['script', {src: `${baseTemp.base}siteinfo.js`}],
['script', {async:'', defer:'', src:'https://api.makie.org/latest.js'}],
['noscript', {}, '<img alt="" referrerpolicy="no-referrer-when-downgrade" src="https://api.makie.org/noscript.gif"/>'],
],
ignoreDeadLinks: true,

Expand Down
3 changes: 0 additions & 3 deletions docs/src/.vitepress/theme/SimpleAnalytics.vue

This file was deleted.

2 changes: 0 additions & 2 deletions docs/src/.vitepress/theme/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
import { h, watch } from "vue";
import type { Theme } from "vitepress";
import DefaultTheme from "vitepress/theme";
import SimpleAnalytics from "./SimpleAnalytics.vue"
import VersionPicker from "./VersionPicker.vue"

import { enhanceAppWithTabs } from "vitepress-plugin-tabs/client";
Expand All @@ -13,7 +12,6 @@ export default {
Layout() {
return h(DefaultTheme.Layout, null, {
// https://vitepress.dev/guide/extending-default-theme#layout-slots
'layout-bottom': () => h(SimpleAnalytics)
});
},
async enhanceApp({ app, router, siteData }) {
Expand Down
13 changes: 7 additions & 6 deletions docs/src/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ layout: home
hero:
name: Makie
text:
tagline: Interactive data visualizations and plotting in Julia
text:
tagline: Interactive data visualizations and plotting in Julia
image:
src: logo.svg
alt: Makie
Expand Down Expand Up @@ -65,8 +65,8 @@ colors = Observable(Int[])
set_theme!(theme_black())
fig, ax, l = lines(points, color = colors,
colormap = :inferno, transparency = true,
axis = (; type = Axis3, protrusions = (0, 0, 0, 0),
colormap = :inferno, transparency = true,
axis = (; type = Axis3, protrusions = (0, 0, 0, 0),
viewmode = :fit, limits = (-30, 30, -30, 30, 0, 50)))
record(fig, "lorenz.mp4", 1:120) do frame
Expand All @@ -89,11 +89,12 @@ set_theme!() # hide

## Installation

First, choose one (or more) of the four backend packages (more info under [What is a backend](@ref)):
Makie offers four different backends (more info under [What is a backend](@ref)).
We suggest GLMakie for GPU-accelerated, interactive plots, and CairoMakie for static vector graphics.

- [GLMakie](@ref) (OpenGL based, interactive)
- [CairoMakie](@ref) (Cairo based, static vector graphics)
- [WGLMakie](@ref) (WebGL based, runs in the browser)
- [WGLMakie](@ref) (WebGL based, displays plots in the browser)
- [RPRMakie](@ref) (Experimental ray-tracing using RadeonProRender)

Then install it using Julia's package manager `Pkg`:
Expand Down
1 change: 1 addition & 0 deletions src/Makie.jl
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ include("utilities/quaternions.jl")
include("utilities/stable-hashing.jl")
include("bezier.jl")
include("types.jl")
include("utilities/timing.jl")
include("utilities/texture_atlas.jl")
include("interaction/observables.jl")
include("interaction/liftmacro.jl")
Expand Down
4 changes: 2 additions & 2 deletions src/basic_recipes/barplot.jl
Original file line number Diff line number Diff line change
Expand Up @@ -214,9 +214,9 @@ function barplot_labels(xpositions, ypositions, offset, bar_labels, in_y_directi
if bar_labels isa Symbol && bar_labels in (:x, :y)
bar_labels = map(xpositions, ypositions) do x, y
if bar_labels === :x
label_formatter.(x)
x
else
label_formatter.(y)
y
end
end
end
Expand Down
21 changes: 12 additions & 9 deletions src/basic_recipes/poly.jl
Original file line number Diff line number Diff line change
Expand Up @@ -44,15 +44,16 @@ function plot!(plot::Poly{<: Tuple{Union{GeometryBasics.Mesh, GeometryPrimitive}
overdraw = plot.overdraw,
inspectable = plot.inspectable,
transparency = plot.transparency,
space = plot.space
space = plot.space,
depth_shift = plot.depth_shift
)
wireframe!(
plot, plot[1],
color = plot[:strokecolor], linestyle = plot[:linestyle], space = plot[:space],
linewidth = plot[:strokewidth], linecap = plot[:linecap],
visible = plot[:visible], overdraw = plot[:overdraw],
inspectable = plot[:inspectable], transparency = plot[:transparency],
colormap = plot[:strokecolormap]
color = plot.strokecolor, linestyle = plot.linestyle, space = plot.space,
linewidth = plot.strokewidth, linecap = plot.linecap,
visible = plot.visible, overdraw = plot.overdraw,
inspectable = plot.inspectable, transparency = plot.transparency,
colormap = plot.strokecolormap, depth_shift=plot.stroke_depth_shift
)
end

Expand Down Expand Up @@ -161,6 +162,7 @@ function plot!(plot::Poly{<: Tuple{<: Union{Polygon, AbstractVector{<: PolyEleme
transparency = plot.transparency,
inspectable = plot.inspectable,
space = plot.space,
depth_shift = plot.depth_shift
)

outline = lift(to_lines, plot, geometries)
Expand All @@ -185,7 +187,7 @@ function plot!(plot::Poly{<: Tuple{<: Union{Polygon, AbstractVector{<: PolyEleme
joinstyle = plot.joinstyle, miter_limit = plot.miter_limit,
space = plot.space,
overdraw = plot.overdraw, transparency = plot.transparency,
inspectable = plot.inspectable, depth_shift = -1f-5
inspectable = plot.inspectable, depth_shift = plot.stroke_depth_shift
)
end

Expand All @@ -195,13 +197,14 @@ function plot!(plot::Mesh{<: Tuple{<: AbstractVector{P}}}) where P <: Union{Abst
visible = plot.visible, shading = plot.shading, fxaa = plot.fxaa,
inspectable = plot.inspectable, transparency = plot.transparency,
space = plot.space, ssao = plot.ssao,
alpha=plot.alpha,
alpha = plot.alpha,
lowclip = get(plot, :lowclip, automatic),
highclip = get(plot, :highclip, automatic),
nan_color = get(plot, :nan_color, :transparent),
colormap = get(plot, :colormap, nothing),
colorscale = get(plot, :colorscale, identity),
colorrange = get(plot, :colorrange, automatic)
colorrange = get(plot, :colorrange, automatic),
depth_shift = plot.depth_shift
)

num_meshes = lift(plot, meshes; ignore_equal_values=true) do meshes
Expand Down
5 changes: 2 additions & 3 deletions src/colorsampler.jl
Original file line number Diff line number Diff line change
Expand Up @@ -164,9 +164,9 @@ function numbers_to_colors(numbers::Union{AbstractArray{<:Number, N},Number},
scaled_number = apply_scale(colorscale, Float64(number)) # ints don't work in interpolated_getindex
if isnan(scaled_number)
return nan_color
elseif !isnothing(lowclip) && scaled_number < scaled_cmin
elseif lowclip !== automatic && scaled_number < scaled_cmin
return lowclip
elseif !isnothing(highclip) && scaled_number > scaled_cmax
elseif highclip !== automatic && scaled_number > scaled_cmax
return highclip
end
return interpolated_getindex(
Expand Down Expand Up @@ -363,7 +363,6 @@ end

function assemble_colors(::Number, color, plot)
plot.colorrange[] isa Automatic && error("Cannot determine a colorrange automatically for single number color value. Pass an explicit colorrange.")

cm = assemble_colors([color[]], lift(x -> [x], color), plot)
return lift((args...)-> numbers_to_colors(args...)[1], cm.color_scaled, cm.colormap, identity, cm.colorrange_scaled, cm.lowclip, cm.highclip,
cm.nan_color)
Expand Down
Loading

0 comments on commit 26648f6

Please sign in to comment.