Skip to content

Commit

Permalink
Merge branch 'master' into ff/fxaa
Browse files Browse the repository at this point in the history
  • Loading branch information
SimonDanisch authored Dec 1, 2023
2 parents 6c1b040 + c91752f commit bf4b0d2
Show file tree
Hide file tree
Showing 10 changed files with 98 additions and 23 deletions.
8 changes: 8 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,14 @@
## master

- Disable SDF based anti-aliasing in scatter, text and lines plots when `fxaa = true` in GLMakie. This allows removing outline artifacts at the cost of quality. [#3408](https://github.com/MakieOrg/Makie.jl/pull/3408)
- Fixed a bug with h/vlines and h/vspan not correctly resolving transformations [#3418](https://github.com/MakieOrg/Makie.jl/pull/3418)
- Fixed a bug with h/vlines and h/vspan returning the wrong limits, causing an error in Axis [#3427](https://github.com/MakieOrg/Makie.jl/pull/3427)

## 0.20.1

- Fixed bad rendering of `poly` in GLMakie by triangulating points after transformations [#3402](https://github.com/MakieOrg/Makie.jl/pull/3402).
- Fixed bug regarding inline display in VSCode Jupyter notebooks and other similar environments [#3403](https://github.com/MakieOrg/Makie.jl/pull/3403).
- Fixed issue with `plottype`, allowed `onany(...; update = true)` and fixed `Block` macro use outside Makie [#3401](https://github.com/MakieOrg/Makie.jl/pull/3401).

## 0.20

Expand Down
5 changes: 2 additions & 3 deletions docs/reference/blocks/polaraxis.md
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,7 @@ Not every plot type is compatible with the polar transform.
For example `image` is not as it expects to be drawn on a rectangle.
`heatmap` works to a degree in CairoMakie, but not GLMakie due to differences in the backend implementation.
`surface` can be used as a replacement for `image` as it generates a triangle mesh.
However it also has a component in z-direction which will affect drawing order.
You can use `translate!(plot, 0, 0, z_shift)` to work around that.
To avoid having the `surface` plot extend in z-direction and thus messing with render order it is recommended to pass the color-data through the `color` attribute and use a matrix of zeros for the z-data.
As a replacement for `heatmap` you can use `voronoiplot`, which generates cells of arbitrary shape around points given to it. Here you will generally need to set `rlims!(ax, rmax)` yourself.

\begin{examplefigure}{svg = false}
Expand All @@ -104,7 +103,7 @@ ax = PolarAxis(f[1, 1], title = "Surface")
rs = 0:10
phis = range(0, 2pi, 37)
cs = [r+cos(4phi) for phi in phis, r in rs]
p = surface!(ax, 0..2pi, 0..10, cs, shading = NoShading, colormap = :coolwarm)
p = surface!(ax, 0..2pi, 0..10, zeros(size(cs)), color = cs, shading = NoShading, colormap = :coolwarm)
ax.gridz[] = 100
tightlimits!(ax) # surface plots include padding by default
Colorbar(f[2, 1], p, vertical = false, flipaxis = false)
Expand Down
21 changes: 12 additions & 9 deletions src/basic_recipes/contours.jl
Original file line number Diff line number Diff line change
Expand Up @@ -22,26 +22,26 @@ To add contour labels, use `labels = true`, and pass additional label attributes
$(ATTRIBUTES)
"""
@recipe(Contour) do scene
default = default_theme(scene)
# pop!(default, :color)
Attributes(;
default...,
attr = Attributes(;
color = nothing,
colormap = theme(scene, :colormap),
colorscale = identity,
colorrange = Makie.automatic,
levels = 5,
linewidth = 1.0,
linestyle = nothing,
alpha = 1.0,
enable_depth = true,
transparency = false,
labels = false,

labelfont = theme(scene, :font),
labelcolor = nothing, # matches color by default
labelformatter = contour_label_formatter,
labelsize = 10, # arbitrary
)


MakieCore.colormap_attributes!(attr, theme(scene, :colormap))
MakieCore.generic_plot_attributes!(attr)

return attr
end

"""
Expand Down Expand Up @@ -146,11 +146,13 @@ function plot!(plot::Contour{<: Tuple{X, Y, Z, Vol}}) where {X, Y, Z, Vol}
end

attr = copy(Attributes(plot))

attr[:colorrange] = cliprange
attr[:colormap] = cmap
attr[:algorithm] = 7
pop!(attr, :levels)
pop!(attr, :alpha) # don't apply alpha 2 times

# unused attributes
pop!(attr, :labels)
pop!(attr, :labelfont)
Expand Down Expand Up @@ -320,7 +322,8 @@ function plot!(plot::T) where T <: Union{Contour, Contour3d}
linewidth = plot.linewidth,
inspectable = plot.inspectable,
transparency = plot.transparency,
linestyle = plot.linestyle
linestyle = plot.linestyle,
MakieCore.generic_plot_attributes(plot)...
)
plot
end
Expand Down
22 changes: 20 additions & 2 deletions src/basic_recipes/hvlines.jl
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,25 @@ function Makie.plot!(p::Union{HLines, VLines})
line_attributes = copy(p.attributes)
foreach(key-> delete!(line_attributes, key), [:ymin, :ymax, :xmin, :xmax, :xautolimits, :yautolimits])
# Drop transform_func because we handle it manually
T = Transformation(p, transform_func = identity)
linesegments!(p, line_attributes, points, transformation = T)
line_attributes[:transformation] = Transformation(p, transform_func = identity)
linesegments!(p, line_attributes, points)
p
end

function data_limits(p::HLines)
scene = parent_scene(p)
limits = projview_to_2d_limits(scene.camera.projectionview[])
itf = inverse_transform(p.transformation.transform_func[])
xmin, xmax = apply_transform.(itf[1], first.(extrema(limits)))
ymin, ymax = extrema(p[1][])
return Rect3f(Point3f(xmin, ymin, 0), Vec3f(xmax - xmin, ymax - ymin, 0))
end

function data_limits(p::VLines)
scene = parent_scene(p)
limits = projview_to_2d_limits(scene.camera.projectionview[])
itf = inverse_transform(p.transformation.transform_func[])
xmin, xmax = extrema(p[1][])
ymin, ymax = apply_transform.(itf[2], getindex.(extrema(limits), 2))
return Rect3f(Point3f(xmin, ymin, 0), Vec3f(xmax - xmin, ymax - ymin, 0))
end
25 changes: 23 additions & 2 deletions src/basic_recipes/hvspan.jl
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,8 @@ function Makie.plot!(p::Union{HSpan, VSpan})
foreach(x-> delete!(poly_attributes, x), [:ymin, :ymax, :xmin, :xmax, :xautolimits, :yautolimits])

# we handle transform_func manually
T = Transformation(p, transform_func = identity)
poly!(p, poly_attributes, rects; transformation = T)
poly_attributes[:transformation] = Transformation(p, transform_func = identity)
poly!(p, poly_attributes, rects)
p
end

Expand All @@ -88,3 +88,24 @@ _apply_x_transform(other, v) = error("x transform not defined for transform func
_apply_y_transform(t::Tuple, v) = apply_transform(t[2], v)
_apply_y_transform(other, v) = error("y transform not defined for transform function $(typeof(other))")
_apply_y_transform(::typeof(identity), v) = v


function data_limits(p::HSpan)
scene = parent_scene(p)
limits = projview_to_2d_limits(scene.camera.projectionview[])
itf = inverse_transform(p.transformation.transform_func[])
xmin, xmax = apply_transform.(itf[1], first.(extrema(limits)))
ymin = minimum(p[1][])
ymax = maximum(p[2][])
return Rect3f(Point3f(xmin, ymin, 0), Vec3f(xmax - xmin, ymax - ymin, 0))
end

function data_limits(p::VSpan)
scene = parent_scene(p)
limits = projview_to_2d_limits(scene.camera.projectionview[])
itf = inverse_transform(p.transformation.transform_func[])
xmin = minimum(p[1][])
xmax = maximum(p[2][])
ymin, ymax = apply_transform.(itf[2], getindex.(extrema(limits), 2))
return Rect3f(Point3f(xmin, ymin, 0), Vec3f(xmax - xmin, ymax - ymin, 0))
end
9 changes: 6 additions & 3 deletions src/figureplotting.jl
Original file line number Diff line number Diff line change
Expand Up @@ -269,9 +269,12 @@ end
# This enables convert_arguments(::Type{<:AbstractPlot}, ::X) -> FigureSpec
# Which skips axis creation
# TODO, what to return for the dynamically created axes?
figurelike_return(f::GridPosition, p::AbstractPlot) = p
figurelike_return(f::Figure, p::AbstractPlot) = FigureAxisPlot(f, nothing, p)
MakieCore.create_axis_like!(::AbstractPlot, attributes::Dict, fig::Figure) = fig
const PlotSpecPlot = Plot{plot, Tuple{<: GridLayoutSpec}}

figurelike_return(f::GridPosition, p::PlotSpecPlot) = p
figurelike_return(f::Figure, p::PlotSpecPlot) = FigureAxisPlot(f, nothing, p)
MakieCore.create_axis_like!(::PlotSpecPlot, attributes::Dict, fig::Figure) = fig
MakieCore.create_axis_like!(::AbstractPlot, attributes::Dict, fig::Figure) = nothing

# Axis interface

Expand Down
7 changes: 5 additions & 2 deletions src/stats/hist.jl
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,8 @@ function Makie.plot!(plot::StepHist)
pop!(attr, :normalization)
pop!(attr, :scale_to)
pop!(attr, :bins)
# plot the values, not the observables, to be in control of updating
stairs!(plot, points[]; attr..., color=color)
stairs!(plot, points; attr..., color=color)
plot
end

"""
Expand Down Expand Up @@ -187,5 +187,8 @@ function Makie.plot!(plot::Hist)
bp[1].val = points[]
bp.width = w
end
onany(plot, plot.normalization, plot.scale_to, plot.weights) do _, _, _
bp[1][] = points[]
end
plot
end
17 changes: 17 additions & 0 deletions test/boundingboxes.jl
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,23 @@ end

fig, ax, p = bracket(ps...)
@test data_limits(p) Rect3f(Point3f(0), Vec3f(1, 1, 0))

fig = Figure()
ax = Axis(fig[1, 1], yscale=log, xscale=log)
scatter!(ax, [0.5, 1, 2], [0.5, 1, 2])
p1 = vlines!(ax, [0.5])
p2 = hlines!(ax, [0.5])
p3 = vspan!(ax, [0.25], [0.75])
p4 = hspan!(ax, [0.25], [0.75])
Makie.reset_limits!(ax)

lims = ax.finallimits[]
x, y = minimum(lims); w, h = widths(lims)

@test data_limits(p1) Rect3f(Point3f(0.5, y, 0), Vec3f(0, h, 0))
@test data_limits(p2) Rect3f(Point3f(x, 0.5, 0), Vec3f(w, 0, 0))
@test data_limits(p3) Rect3f(Point3f(0.25, y, 0), Vec3f(0.5, h, 0))
@test data_limits(p4) Rect3f(Point3f(x, 0.25, 0), Vec3f(w, 0.5, 0))
end

@testset "boundingbox(plot)" begin
Expand Down
5 changes: 3 additions & 2 deletions test/figures.jl
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ end
current_axis!(ax2)
@test current_axis() === ax2
@test current_figure() === fig

end

@testset "Deleting from figures" begin
Expand Down Expand Up @@ -158,7 +159,7 @@ end
@test_throws ArgumentError lines(1:10, axis = (aspect = DataAspect()), figure = (size = (100, 100)))
@test_throws ArgumentError lines(1:10, figure = (size = (100, 100)))
@test_throws ArgumentError lines(1:10, axis = (aspect = DataAspect()))

# these just shouldn't error
lines(1:10, axis = (aspect = DataAspect(),))
lines(1:10, axis = Attributes(aspect = DataAspect()))
Expand All @@ -167,4 +168,4 @@ end
f = Figure()
@test_throws ArgumentError lines(f[1, 1], 1:10, axis = (aspect = DataAspect()))
@test_throws ArgumentError lines(f[1, 1][2, 2], 1:10, axis = (aspect = DataAspect()))
end
end
2 changes: 2 additions & 0 deletions test/pipeline.jl
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,8 @@ end
pl = meshscatter!(LScene(sub[1, 3]), rand(Point3f, 10))
@test pl isa AbstractPlot

f = Figure()
@test_throws ErrorException lines!(f, [1, 2])
end
end

Expand Down

0 comments on commit bf4b0d2

Please sign in to comment.