From da4414ce18a86b3de33bca32bd30e4b2a3f317c1 Mon Sep 17 00:00:00 2001 From: Simon Date: Fri, 21 Jul 2023 15:44:36 +0200 Subject: [PATCH 1/7] better colorbuffer, fix record + window hiding when using save (#3078) * fix issues with saving + record * add colorbuffer for axis + subscenes * fixes + tests * add news entry --- GLMakie/src/screen.jl | 9 +++++++-- NEWS.md | 7 ++++--- ReferenceTests/src/tests/short_tests.jl | 25 +++++++++++++++++++++++ src/Makie.jl | 2 +- src/display.jl | 25 ++++++++++++++++++----- src/makielayout/blocks/axis.jl | 27 +++++++++++++++++++++++++ 6 files changed, 84 insertions(+), 11 deletions(-) diff --git a/GLMakie/src/screen.jl b/GLMakie/src/screen.jl index 0bf5028cb50..24432b071c6 100644 --- a/GLMakie/src/screen.jl +++ b/GLMakie/src/screen.jl @@ -342,7 +342,6 @@ function apply_config!(screen::Screen, config::ScreenConfig; start_renderloop::B replace_processor!(config.fxaa ? fxaa_postprocessor : empty_postprocessor, 3) # Set the config screen.config = config - if start_renderloop start_renderloop!(screen) else @@ -688,7 +687,13 @@ function Makie.colorbuffer(screen::Screen, format::Makie.ImageStorageFormat = Ma # GLFW.PollEvents() # keep current buffer size to allows larger-than-window renders render_frame(screen, resize_buffers=false) # let it render - glFinish() # block until opengl is done rendering + if screen.config.visible + GLFW.SwapBuffers(to_native(screen)) + else + # SwapBuffers blocks as well, but if we don't call that + # We need to call glFinish to wait for all OpenGL changes to finish + glFinish() + end if size(ctex) != size(screen.framecache) screen.framecache = Matrix{RGB{N0f8}}(undef, size(ctex)) end diff --git a/NEWS.md b/NEWS.md index ea97f41d58b..dba0dff7c55 100644 --- a/NEWS.md +++ b/NEWS.md @@ -2,14 +2,15 @@ ## master +- Exported colorbuffer, and added `colorbuffer(axis::Axis; include_decorations=false, colorbuffer_kws...)`, to get an image of an axis with or without decorations [#3078](https://github.com/MakieOrg/Makie.jl/pull/3078). - Fixed an issue where the `linestyle` of some polys was not applied to the stroke in CairoMakie. [#2604](https://github.com/MakieOrg/Makie.jl/pull/2604) - Add `colorscale = identity` to any plotting function using a colormap. This works with any scaling function like `log10`, `sqrt` etc. Consequently, `scale` for `hexbin` is replaced with `colorscale` [#2900](https://github.com/MakieOrg/Makie.jl/pull/2900). - Add `alpha=1.0` argument to all basic plots, which supports independently adding an alpha component to colormaps and colors. Multiple alphas like in `plot(alpha=0.2, color=RGBAf(1, 0, 0, 0.5))`, will get multiplied [#2900](https://github.com/MakieOrg/Makie.jl/pull/2900). - `hexbin` now supports any per-observation weights which StatsBase respects - `<: StatsBase.AbstractWeights`, `Vector{Real}`, or `nothing` (the default). [#2804](https://github.com/MakieOrg/Makie.jl/pulls/2804) -- Added a new Axis type, `PolarAxis`, which is an axis with a polar projection. Input is in `(r, theta)` coordinates and is transformed to `(x, y)` coordinates using the standard polar-to-cartesian transformation. - Generally, its attributes are very similar to the usual `Axis` attributes, but `x` is replaced by `r` and `y` by `θ`. +- Added a new Axis type, `PolarAxis`, which is an axis with a polar projection. Input is in `(r, theta)` coordinates and is transformed to `(x, y)` coordinates using the standard polar-to-cartesian transformation. + Generally, its attributes are very similar to the usual `Axis` attributes, but `x` is replaced by `r` and `y` by `θ`. It also inherits from the theme of `Axis` in this manner, so should work seamlessly with Makie themes [#2990](https://github.com/MakieOrg/Makie.jl/pull/2990). -- `inherit` now has a new signature `inherit(scene, attrs::NTuple{N, Symbol}, default_value)`, allowing recipe authors to access nested attributes when trying to inherit from the parent Scene. +- `inherit` now has a new signature `inherit(scene, attrs::NTuple{N, Symbol}, default_value)`, allowing recipe authors to access nested attributes when trying to inherit from the parent Scene. For example, one could inherit from `scene.Axis.yticks` by `inherit(scene, (:Axis, :yticks), $default_value)` [#2990](https://github.com/MakieOrg/Makie.jl/pull/2990). - Fixed incorrect rendering of 3D heatmaps [#2959](https://github.com/MakieOrg/Makie.jl/pull/2959) - Deprecated `flatten_plots` in favor of `collect_atomic_plots`. Using the new `collect_atomic_plots` fixed a bug in CairoMakie where the z-level of plots within recipes was not respected. [#2793](https://github.com/MakieOrg/Makie.jl/pull/2793) diff --git a/ReferenceTests/src/tests/short_tests.jl b/ReferenceTests/src/tests/short_tests.jl index 57baa421b1e..c939fc60626 100644 --- a/ReferenceTests/src/tests/short_tests.jl +++ b/ReferenceTests/src/tests/short_tests.jl @@ -257,6 +257,31 @@ end f end +@reference_test "colorbuffer for axis" begin + fig = Figure() + ax1 = Axis(fig[1, 1]) + ax2 = Axis(fig[1, 2]) + ax3 = Axis(fig[2, 2]) + ax4 = Axis(fig[2, 1]) + scatter!(ax1, 1:10, 1:10; markersize=50, color=1:10) + scatter!(ax2, 1:10, 1:10; markersize=50, color=:red) + heatmap!(ax3, -8:0.1:8, 8:0.1:8, (x, y) -> sin(x) + cos(y)) + meshscatter!(ax4, 1:10, 1:10; markersize=1, color=:red) + img1 = colorbuffer(ax1; include_decorations=true) + img2 = colorbuffer(ax2; include_decorations=false) + img3 = colorbuffer(ax3; include_decorations=true) + img4 = colorbuffer(ax4; include_decorations=false) + f, ax5, pl = image(rotr90(img1); axis=(; aspect=DataAspect())) + ax6, pl = image(f[1, 2], rotr90(img2); axis=(; aspect=DataAspect())) + ax7, pl = image(f[2, 2], rotr90(img3); axis=(; aspect=DataAspect())) + ax8, pl = image(f[2, 1], rotr90(img4); axis=(; aspect=DataAspect())) + hidedecorations!(ax5) + hidedecorations!(ax6) + hidedecorations!(ax7) + hidedecorations!(ax8) + f +end + # Needs a way to disable autolimits on show # @reference_test "interactions after close" begin diff --git a/src/Makie.jl b/src/Makie.jl index ff0cc254311..2fc66e042f0 100644 --- a/src/Makie.jl +++ b/src/Makie.jl @@ -276,7 +276,7 @@ export abline! # until deprecation removal export Stepper, replay_events, record_events, RecordEvents, record, VideoStream export VideoStream, recordframe!, record, Record -export save +export save, colorbuffer # colormap stuff from PlotUtils, and showgradients export cgrad, available_gradients, showgradients diff --git a/src/display.jl b/src/display.jl index b06739085c0..30b7c10ef74 100644 --- a/src/display.jl +++ b/src/display.jl @@ -320,7 +320,8 @@ function FileIO.save( # If the scene already got displayed, we get the current screen its displayed on # Else, we create a new scene and update the state of the fig update && update_state_before_display!(fig) - screen = getscreen(backend, scene, io, mime; visible=false, screen_config...) + visible = !isnothing(getscreen(scene)) # if already has a screen, don't hide it! + screen = getscreen(backend, scene, io, mime; visible=visible, screen_config...) backend_show(screen, io, mime, scene) end catch e @@ -408,9 +409,16 @@ function getscreen(backend::Union{Missing, Module}, scene::Scene, args...; scree end end +function get_sub_picture(image, format::ImageStorageFormat, rect) + xmin, ymin = minimum(rect) .- (1, 0) + xmax, ymax = maximum(rect) + start = size(image, 1) - ymax + stop = size(image, 1) - ymin + return image[start:stop, xmin:xmax] +end + """ - colorbuffer(scene, format::ImageStorageFormat = JuliaNative; backend=current_backend(), screen_config...) - colorbuffer(screen, format::ImageStorageFormat = JuliaNative) + colorbuffer(scene, format::ImageStorageFormat = JuliaNative; update=true, backend=current_backend(), screen_config...) Returns the content of the given scene or screen rasterised to a Matrix of Colors. The return type is backend-dependent, but will be some form of RGB @@ -421,12 +429,19 @@ or RGBA. - `format = GLNative` : Returns a more efficient format buffer for GLMakie which can be directly used in FFMPEG without conversion - `screen_config`: Backend dependend, look up via `?Backend.Screen`/`Base.doc(Backend.Screen)` +- `update=true`: resets/updates limits. Set to false, if you want to preserver camera movements. """ function colorbuffer(fig::FigureLike, format::ImageStorageFormat = JuliaNative; update=true, backend = current_backend(), screen_config...) scene = get_scene(fig) update && update_state_before_display!(fig) - screen = getscreen(backend, scene, format; start_renderloop=false, visible=false, screen_config...) - return colorbuffer(screen, format) + visible = !isnothing(getscreen(scene)) # if already has a screen, don't hide it! + screen = getscreen(backend, scene; start_renderloop=false, visible=visible, screen_config...) + img = colorbuffer(screen, format) + if !isroot(scene) + return get_sub_picture(img, format, pixelarea(scene)[]) + else + return img + end end # Fallback for any backend that will just use colorbuffer to write out an image diff --git a/src/makielayout/blocks/axis.jl b/src/makielayout/blocks/axis.jl index 4151a899207..8656998749a 100644 --- a/src/makielayout/blocks/axis.jl +++ b/src/makielayout/blocks/axis.jl @@ -1785,3 +1785,30 @@ function attribute_examples(::Type{Axis}) ], ) end + +function axis_bounds_with_decoration(axis::Axis) + # Filter out the zoomrect + background plot + lims = Makie.data_limits(axis.blockscene.plots, p -> p isa Mesh || p isa Poly) + return Makie.parent_transform(axis.blockscene) * lims +end + +""" + colorbuffer(ax::Axis; include_decorations=true, colorbuffer_kws...) + +Gets the colorbuffer of the `Axis` in `JuliaNative` image format. +If `include_decorations=false`, only the inside of the axis is fetched. +""" +function colorbuffer(ax::Axis; include_decorations=true, update=true, colorbuffer_kws...) + if update + update_state_before_display!(ax) + end + bb = if include_decorations + bb = axis_bounds_with_decoration(ax) + Rect2{Int}(round.(Int, minimum(bb)) .+ 1, round.(Int, widths(bb))) + else + pixelarea(ax.scene)[] + end + + img = colorbuffer(root(ax.scene); update=false, colorbuffer_kws...) + return get_sub_picture(img, JuliaNative, bb) +end From e3835c192da3b6a04274ebcb39997767a2e8d0db Mon Sep 17 00:00:00 2001 From: Florian Date: Fri, 21 Jul 2023 15:46:44 +0200 Subject: [PATCH 2/7] Hook up ticksize attribute for Axis3 (#2354) * hook up ticksize attribute for Axis3 * project tick segments positions to pixel space * remove useless statement * remove :pixel arg --------- Co-authored-by: Anshul Singhvi Co-authored-by: Simon --- src/makielayout/blocks/axis3d.jl | 38 ++++++++++++++++++-------------- src/makielayout/types.jl | 6 +++++ 2 files changed, 27 insertions(+), 17 deletions(-) diff --git a/src/makielayout/blocks/axis3d.jl b/src/makielayout/blocks/axis3d.jl index 2fc0fa72e62..b9483559f67 100644 --- a/src/makielayout/blocks/axis3d.jl +++ b/src/makielayout/blocks/axis3d.jl @@ -477,10 +477,11 @@ function add_ticks_and_ticklabels!(topscene, scene, ax, dim::Int, limits, tickno map!(ticklabels, ticknode) do (values, labels) labels end + ticksize = attr(:ticksize) tick_segments = lift(topscene, limits, tickvalues, miv, min1, min2, - scene.camera.projectionview, scene.px_area) do lims, ticks, miv, min1, min2, - pview, pxa + scene.camera.projectionview, scene.px_area, ticksize) do lims, ticks, miv, min1, min2, + pview, pxa, tsize f1 = !min1 ? minimum(lims)[d1] : maximum(lims)[d1] f2 = min2 ? minimum(lims)[d2] : maximum(lims)[d2] @@ -490,23 +491,28 @@ function add_ticks_and_ticklabels!(topscene, scene, ax, dim::Int, limits, tickno diff_f1 = f1 - f1_oppo diff_f2 = f2 - f2_oppo - map(ticks) do t + o = pxa.origin + + return map(ticks) do t p1 = dpoint(t, f1, f2) p2 = if dim == 3 # special case the z axis, here it depends on azimuth in which direction the ticks go if 45 <= mod1(rad2deg(azimuth[]), 180) <= 135 - dpoint(t, f1 + 0.03 * diff_f1, f2) + dpoint(t, f1 + diff_f1, f2) else - dpoint(t, f1, f2 + 0.03 * diff_f2) + dpoint(t, f1, f2 + diff_f2) end else - dpoint(t, f1 + 0.03 * diff_f1, f2) + dpoint(t, f1 + diff_f1, f2) end - (p1, p2) - end - end + pp1 = Point2f(o + Makie.project(scene, p1)) + pp2 = Point2f(o + Makie.project(scene, p2)) + diff_pp = Makie.GeometryBasics.normalize(Point2f(pp2 - pp1)) + return (pp1, pp1 .+ Float32(tsize) .* diff_pp) + end + end # we are going to transform the 3d tick segments into 2d of the topscene # because otherwise they # be cut when they extend beyond the scene boundary @@ -516,10 +522,13 @@ function add_ticks_and_ticklabels!(topscene, scene, ax, dim::Int, limits, tickno end end - ticks = linesegments!(topscene, tick_segments_2dz, + ticks = linesegments!(topscene, tick_segments, xautolimits = false, yautolimits = false, zautolimits = false, transparency = true, inspectable = false, color = attr(:tickcolor), linewidth = attr(:tickwidth), visible = attr(:ticksvisible)) + # -10000 is an arbitrary weird constant that in preliminary testing didn't seem + # to clip into plot objects anymore + translate!(ticks, 0, 0, -10000) labels_positions = Observable{Any}() map!(topscene, labels_positions, scene.px_area, scene.camera.projectionview, @@ -528,12 +537,8 @@ function add_ticks_and_ticklabels!(topscene, scene, ax, dim::Int, limits, tickno o = pxa.origin points = map(ticksegs) do (tstart, tend) - tstartp = Point2f(o + Makie.project(scene, tstart)) - tendp = Point2f(o + Makie.project(scene, tend)) - - offset = pad * Makie.GeometryBasics.normalize( - Point2f(tendp - tstartp)) - tendp + offset + offset = pad * Makie.GeometryBasics.normalize(Point2f(tend - tstart)) + tend + offset end N = min(length(ticklabs), length(points)) @@ -609,7 +614,6 @@ function add_ticks_and_ticklabels!(topscene, scene, ax, dim::Int, limits, tickno if slight_flip offset_ang_90deg_alwaysup += pi end - offset_ang_90deg_alwaysup labelrotation = if lrotation == Makie.automatic offset_ang_90deg_alwaysup diff --git a/src/makielayout/types.jl b/src/makielayout/types.jl index 5fa462f2644..2216c311bac 100644 --- a/src/makielayout/types.jl +++ b/src/makielayout/types.jl @@ -1505,6 +1505,12 @@ end ytickwidth = 1 "The z tick width" ztickwidth = 1 + "The size of the xtick marks." + xticksize::Float64 = 12f0 + "The size of the ytick marks." + yticksize::Float64 = 12f0 + "The size of the ztick marks." + zticksize::Float64 = 12f0 "The color of x spine 1 where the ticks are displayed" xspinecolor_1 = :black "The color of y spine 1 where the ticks are displayed" From 1734cf87821a2605537e7eec3a65f1e2f925b5bc Mon Sep 17 00:00:00 2001 From: Simon Date: Sat, 22 Jul 2023 09:23:28 +0200 Subject: [PATCH 3/7] Allow arrows to take a Function to produce the vector (#3080) * Allow arrows to take a Function to produce the vector * Update NEWS.md * Update docs with an example * Update docstring * Fix typo * Update docs/examples/plotting_functions/arrows.md * Fix function name clash with figure * change function name to not conflict with other functions * Update conversions.jl --------- Co-authored-by: Anshul Singhvi --- NEWS.md | 1 + docs/examples/plotting_functions/arrows.md | 26 ++++++++++++++++++++++ src/basic_recipes/arrows.jl | 5 +++++ src/conversions.jl | 19 ++++++++++++++++ 4 files changed, 51 insertions(+) diff --git a/NEWS.md b/NEWS.md index dba0dff7c55..756ef79aac6 100644 --- a/NEWS.md +++ b/NEWS.md @@ -2,6 +2,7 @@ ## master +- `arrows` can now take input of the form `x::AbstractVector, y::AbstractVector, [z::AbstractVector,] f::Function`, where `f` must return a `VecTypes` of the appropriate dimension [#2597](https://github.com/MakieOrg/Makie.jl/pull/2597). - Exported colorbuffer, and added `colorbuffer(axis::Axis; include_decorations=false, colorbuffer_kws...)`, to get an image of an axis with or without decorations [#3078](https://github.com/MakieOrg/Makie.jl/pull/3078). - Fixed an issue where the `linestyle` of some polys was not applied to the stroke in CairoMakie. [#2604](https://github.com/MakieOrg/Makie.jl/pull/2604) - Add `colorscale = identity` to any plotting function using a colormap. This works with any scaling function like `log10`, `sqrt` etc. Consequently, `scale` for `hexbin` is replaced with `colorscale` [#2900](https://github.com/MakieOrg/Makie.jl/pull/2900). diff --git a/docs/examples/plotting_functions/arrows.md b/docs/examples/plotting_functions/arrows.md index 07e0f621e85..041dceaa2e6 100644 --- a/docs/examples/plotting_functions/arrows.md +++ b/docs/examples/plotting_functions/arrows.md @@ -93,3 +93,29 @@ arrows( ) ``` \end{examplefigure} + +`arrows` can also take a function `f(x::Point{N})::Point{N}` which returns the arrow vector when given the arrow's origin. + + +\begin{examplefigure}{} +```julia +using CairoMakie +CairoMakie.activate!() # hide + + +fig = Figure(resolution = (800, 800)) +ax = Axis(fig[1, 1], backgroundcolor = "black") +xs = LinRange(0, 2pi, 20) +ys = LinRange(0, 3pi, 20) +# explicit method +us = [sin(x) * cos(y) for x in xs, y in ys] +vs = [-cos(x) * sin(y) for x in xs, y in ys] +strength = vec(sqrt.(us .^ 2 .+ vs .^ 2)) +# function method +arrow_fun(x) = Point2f(sin(x[1])*cos(x[2]), -cos(x[1])*sin(x[2])) +arrows!(ax, xs, ys, arrow_fun, arrowsize = 10, lengthscale = 0.3, + arrowcolor = strength, linecolor = strength) +fig +``` +\end{examplefigure} + diff --git a/src/basic_recipes/arrows.jl b/src/basic_recipes/arrows.jl index d7bfe3b2d0b..27fa6bfd7c3 100644 --- a/src/basic_recipes/arrows.jl +++ b/src/basic_recipes/arrows.jl @@ -3,6 +3,7 @@ arrows(x, y, u, v) arrows(x::AbstractVector, y::AbstractVector, u::AbstractMatrix, v::AbstractMatrix) arrows(x, y, z, u, v, w) + arrows(x, y, [z], f::Function) Plots arrows at the specified points with the specified components. `u` and `v` are interpreted as vector components (`u` being the x @@ -18,6 +19,10 @@ grid. `arrows` can also work in three dimensions. +If a `Function` is provided in place of `u, v, [w]`, then it must accept +a `Point` as input, and return an appropriately dimensioned `Point`, `Vec`, +or other array-like output. + ## Attributes $(ATTRIBUTES) """ diff --git a/src/conversions.jl b/src/conversions.jl index 296ce5251c5..b0b2009bc86 100644 --- a/src/conversions.jl +++ b/src/conversions.jl @@ -607,6 +607,25 @@ function convert_arguments( m = normal_mesh(to_vertices(vertices), to_triangles(indices)) (m,) end + +################################################################################ +# <:Arrows # +################################################################################ + +# Allow the user to pass a function to `arrows` which determines the direction +# and magnitude of the arrows. The function must accept `Point2f` as input. +# and return Point2f or Vec2f or some array like structure as output. +function convert_arguments(::Type{<: Arrows}, x::AbstractVector, y::AbstractVector, f::Function) + points = Point2f.(x, y') + f_out = Vec2f.(f.(points)) + return (vec(points), vec(f_out)) +end + +function convert_arguments(::Type{<: Arrows}, x::AbstractVector, y::AbstractVector, z::AbstractVector, f::Function) + points = [Point3f(x, y, z) for x in x, y in y, z in z] + f_out = Vec3f.(f.(points)) + return (vec(points), vec(f_out)) +end ################################################################################ # Function Conversions # From acf64cf5b11e67e7462712e4db3acb52564552c8 Mon Sep 17 00:00:00 2001 From: Fabian Greimel Date: Sat, 22 Jul 2023 10:46:43 +0200 Subject: [PATCH 4/7] Improve `bar_labels`: `LaTeXString`s and `fontsize` (#2501) * Improve `bar_labels`: `LaTeXString`s and `fontsize` alignment use `align` keyword again use `get_xshift` once more fix * add test --------- Co-authored-by: Simon --- ReferenceTests/src/tests/primitives.jl | 12 +++++ src/basic_recipes/barplot.jl | 4 +- src/basic_recipes/text.jl | 74 +++++++++----------------- 3 files changed, 38 insertions(+), 52 deletions(-) diff --git a/ReferenceTests/src/tests/primitives.jl b/ReferenceTests/src/tests/primitives.jl index ee037943133..150aab8a35d 100644 --- a/ReferenceTests/src/tests/primitives.jl +++ b/ReferenceTests/src/tests/primitives.jl @@ -445,3 +445,15 @@ end scene end + +@reference_test "barplot with TeX-ed labels" begin + fig = Figure(resolution = (800, 800)) + lab1 = L"\int f(x) dx" + lab2 = lab1 + # lab2 = L"\frac{a}{b} - \sqrt{b}" # this will not work until #2667 is fixed + + barplot(fig[1,1], [1, 2], [0.5, 0.2], bar_labels = [lab1, lab2], flip_labels_at = 0.3, direction=:x) + barplot(fig[1,2], [1, 2], [0.5, 0.2], bar_labels = [lab1, lab2], flip_labels_at = 0.3) + + fig +end \ No newline at end of file diff --git a/src/basic_recipes/barplot.jl b/src/basic_recipes/barplot.jl index 164630cdb48..e86d10960de 100644 --- a/src/basic_recipes/barplot.jl +++ b/src/basic_recipes/barplot.jl @@ -78,7 +78,7 @@ $(ATTRIBUTES) color_over_bar = automatic, label_offset = 5, label_font = theme(scene, :font), - label_size = 20, + label_size = theme(scene, :fontsize), label_formatter = bar_label_formatter, transparency = false ) @@ -220,7 +220,7 @@ end function Makie.plot!(p::BarPlot) - labels = Observable(Tuple{String, Point2f}[]) + labels = Observable(Tuple{Union{String,LaTeXStrings.LaTeXString}, Point2f}[]) label_aligns = Observable(Vec2f[]) label_offsets = Observable(Vec2f[]) label_colors = Observable(RGBAf[]) diff --git a/src/basic_recipes/text.jl b/src/basic_recipes/text.jl index 8581cd4fca1..aee85ac7d5e 100644 --- a/src/basic_recipes/text.jl +++ b/src/basic_recipes/text.jl @@ -231,21 +231,8 @@ function texelems_and_glyph_collection(str::LaTeXString, fontscale_px, halign, v end end - xshift = if halign === :center - width(bb) ./ 2 - elseif halign === :left - minimum(bb)[1] - elseif halign === :right - maximum(bb)[1] - end - - yshift = if valign === :center - maximum(bb)[2] - (height(bb) / 2) - elseif valign === :top - maximum(bb)[2] - else - minimum(bb)[2] - end + xshift = get_xshift(minimum(bb)[1], maximum(bb)[1], halign) + yshift = get_yshift(minimum(bb)[2], maximum(bb)[2], valign, default=0f0) shift = Vec3f(xshift, yshift, 0) positions = basepositions .- Ref(shift) @@ -395,25 +382,8 @@ function apply_alignment_and_justification!(lines, ju, al) top_y = max_y_ascender(lines[1]) bottom_y = min_y_descender(lines[end]) - al_offset_x = if al[1] === :center - max_x / 2 - elseif al[1] === :left - 0f0 - elseif al[1] === :right - max_x - else - 0f0 - end - - al_offset_y = if al[2] === :center - 0.5 * (top_y + bottom_y) - elseif al[2] === :bottom - bottom_y - elseif al[2] === :top - top_y - else - 0f0 - end + al_offset_x = get_xshift(0f0, max_x, al[1]; default=0f0) + al_offset_y = get_yshift(bottom_y, top_y, al[2]; default=0f0) fju = float_justification(ju, al) @@ -431,23 +401,9 @@ end function float_justification(ju, al)::Float32 halign = al[1] float_justification = if ju === automatic - if halign === :left || halign == 0 - 0.0f0 - elseif halign === :right || halign == 1 - 1.0f0 - elseif halign === :center || halign == 0.5 - 0.5f0 - else - 0.5f0 - end - elseif ju === :left - 0.0f0 - elseif ju === :right - 1.0f0 - elseif ju === :center - 0.5f0 + get_xshift(0f0, 1f0, halign) else - Float32(ju) + get_xshift(0f0, 1f0, ju; default=ju) # errors if wrong symbol is used end end @@ -546,3 +502,21 @@ function new_glyphstate(gs::GlyphState, rt::RichText, val::Val{:sub}, fonts) end iswhitespace(r::RichText) = iswhitespace(String(r)) + +function get_xshift(lb, ub, align; default=0.5f0) + if align isa Symbol + align = align === :left ? 0.0f0 : + align === :center ? 0.5f0 : + align === :right ? 1.0f0 : default + end + lb * (1-align) + ub * align |> Float32 +end + +function get_yshift(lb, ub, align; default=0.5f0) + if align isa Symbol + align = align === :bottom ? 0.0f0 : + align === :center ? 0.5f0 : + align === :top ? 1.0f0 : default + end + lb * (1-align) + ub * align |> Float32 +end From aab593f73b6a4235c246fe8565b96f744bf91c7c Mon Sep 17 00:00:00 2001 From: Anshul Singhvi Date: Sat, 22 Jul 2023 05:29:51 -0400 Subject: [PATCH 5/7] Arbitrary coloring functions for `streamplot` (#2002) * Allow the coloring function to be changed by `color_func`. Not sure if this should be an option for `color` or a separate kwarg. @lazarusA any thoughts? * color_func -> color, document * Change `color` to `color_func` This is because `color` is overridden by the palette, and it's generally more obvious this way in any case. * Update NEWS.md * Update streamplot.jl --------- Co-authored-by: Simon --- MakieCore/src/basic_plots.jl | 37 ++++++++ NEWS.md | 1 + .../examples/plotting_functions/streamplot.md | 5 +- src/basic_recipes/streamplot.jl | 88 +++++++++++-------- 4 files changed, 92 insertions(+), 39 deletions(-) diff --git a/MakieCore/src/basic_plots.jl b/MakieCore/src/basic_plots.jl index b8743289161..b1db6a60b18 100644 --- a/MakieCore/src/basic_plots.jl +++ b/MakieCore/src/basic_plots.jl @@ -26,6 +26,20 @@ function default_theme!(attr) return attr end +function default_attributes(attr) + return ( + transformation = attr[:transformation], + model = attr[:model], + visible = attr[:visible], + transparency = attr[:transparency], + overdraw = attr[:overdraw], + ssao = attr[:ssao], + inspectable = attr[:inspectable], + depth_shift = attr[:depth_shift], + space = attr[:space] + ) +end + """ ### Color attributes @@ -50,6 +64,18 @@ function colormap_args!(attr, colormap) return attr end +function colormap_attributes(attr) + return ( + colormap = attr[:colormap], + colorscale = attr[:colorscale], + colorrange = attr[:colorrange], + lowclip = attr[:lowclip], + highclip = attr[:highclip], + nan_color = attr[:nan_color], + alpha = attr[:alpha] + ) +end + """ ### 3D shading attributes @@ -68,6 +94,17 @@ function shading_attributes!(attr) attr[:ssao] = false end +function shading_attributes(attr) + return ( + shading = attr[:shading], + diffuse = attr[:diffuse], + specular = attr[:specular], + shininess = attr[:shininess], + backlight = attr[:backlight], + ssao = attr[:ssao] + ) +end + """ `calculated_attributes!(trait::Type{<: AbstractPlot}, plot)` trait version of calculated_attributes diff --git a/NEWS.md b/NEWS.md index 756ef79aac6..4f309f7f721 100644 --- a/NEWS.md +++ b/NEWS.md @@ -2,6 +2,7 @@ ## master +- Allow arbitrary functions to color `streamplot` lines by passing a `Function` to `color`. This must accept `Point` of the appropriate dimension and return a `Point`, `Vec`, or other arraylike object [#2002](https://github.com/MakieOrg/Makie.jl/pull/2002). - `arrows` can now take input of the form `x::AbstractVector, y::AbstractVector, [z::AbstractVector,] f::Function`, where `f` must return a `VecTypes` of the appropriate dimension [#2597](https://github.com/MakieOrg/Makie.jl/pull/2597). - Exported colorbuffer, and added `colorbuffer(axis::Axis; include_decorations=false, colorbuffer_kws...)`, to get an image of an axis with or without decorations [#3078](https://github.com/MakieOrg/Makie.jl/pull/3078). - Fixed an issue where the `linestyle` of some polys was not applied to the stroke in CairoMakie. [#2604](https://github.com/MakieOrg/Makie.jl/pull/2604) diff --git a/docs/examples/plotting_functions/streamplot.md b/docs/examples/plotting_functions/streamplot.md index 3bd5a8734d9..c76490bbd54 100644 --- a/docs/examples/plotting_functions/streamplot.md +++ b/docs/examples/plotting_functions/streamplot.md @@ -26,6 +26,9 @@ f(x, P::FitzhughNagumo) = Point2f( f(x) = f(x, P) -streamplot(f, -1.5..1.5, -1.5..1.5, colormap = :magma) +fig, ax, pl = streamplot(f, -1.5..1.5, -1.5..1.5, colormap = :magma) +# you can also pass a function to `color`, to either return a number or color value +streamplot(fig[1,2], f, -1.5 .. 1.5, -1.5 .. 1.5, color=(p)-> RGBAf(p..., 0.0, 1)) +fig ``` \end{examplefigure} diff --git a/src/basic_recipes/streamplot.jl b/src/basic_recipes/streamplot.jl index a5d7b65b825..f892860627f 100644 --- a/src/basic_recipes/streamplot.jl +++ b/src/basic_recipes/streamplot.jl @@ -1,6 +1,6 @@ """ - streamplot(f::function, xinterval, yinterval; kwargs...) + streamplot(f::function, xinterval, yinterval; color = norm, kwargs...) f must either accept `f(::Point)` or `f(x::Number, y::Number)`. f must return a Point2. @@ -10,6 +10,11 @@ Example: v(x::Point2{T}) where T = Point2f(x[2], 4*x[1]) streamplot(v, -2..2, -2..2) ``` + +One can choose the color of the lines by passing a function `color_func(dx::Point)` to the `color` attribute. +By default this is set to `norm`, but can be set to any function or composition of functions. +The `dx` which is passed to `color_func` is the output of `f` at the point being colored. + ## Attributes $(ATTRIBUTES) @@ -17,21 +22,23 @@ $(ATTRIBUTES) See the function `Makie.streamplot_impl` for implementation details. """ @recipe(StreamPlot, f, limits) do scene - merge( - Attributes( - stepsize = 0.01, - gridsize = (32, 32, 32), - maxsteps = 500, - colormap = theme(scene, :colormap), - colorscale = identity, - colorrange = Makie.automatic, - arrow_size = 15, - arrow_head = automatic, - density = 1.0, - quality = 16 - ), - default_theme(scene, Lines) # so that we can theme the lines as needed. + attr = Attributes( + stepsize = 0.01, + gridsize = (32, 32, 32), + maxsteps = 500, + color = norm, + + arrow_size = 15, + arrow_head = automatic, + density = 1.0, + quality = 16, + + linewidth = theme(scene, :linewidth), + linestyle = nothing, ) + MakieCore.colormap_args!(attr, theme(scene, :colormap)) + MakieCore.default_theme!(attr) + return attr end function convert_arguments(::Type{<: StreamPlot}, f::Function, xrange, yrange) @@ -74,24 +81,23 @@ Links: [Quasirandom sequences](http://extremelearning.com.au/unreasonable-effectiveness-of-quasirandom-sequences/) """ -function streamplot_impl(CallType, f, limits::Rect{N, T}, resolutionND, stepsize, maxsteps=500, dens=1.0) where {N, T} +function streamplot_impl(CallType, f, limits::Rect{N, T}, resolutionND, stepsize, maxsteps=500, dens=1.0, color_func = norm) where {N, T} resolution = to_ndim(Vec{N, Int}, resolutionND, last(resolutionND)) mask = trues(resolution...) # unvisited squares arrow_pos = Point{N, Float32}[] arrow_dir = Vec{N, Float32}[] line_points = Point{N, Float32}[] - colors = Float64[] - line_colors = Float64[] + _cfunc = x-> to_color(color_func(x)) + ColorType = typeof(_cfunc(Point{N,Float32}(0.0))) + line_colors = ColorType[] + colors = ColorType[] dt = Point{N, Float32}(stepsize) mini, maxi = minimum(limits), maximum(limits) r = ntuple(N) do i LinRange(mini[i], maxi[i], resolution[i] + 1) end - apply_f(x0, P) = if P <: Point - f(x0) - else - f(x0...) - end + apply_f(x0, P) = P <: Point ? f(x0) : f(x0...) + # see http://extremelearning.com.au/unreasonable-effectiveness-of-quasirandom-sequences/ ϕ = (MathConstants.φ, 1.324717957244746, 1.2207440846057596)[N] acoeff = ϕ.^(-(1:N)) @@ -113,9 +119,10 @@ function streamplot_impl(CallType, f, limits::Rect{N, T}, resolutionND, stepsize error("Function passed to streamplot must return Point2 or Point3") end pnorm = norm(point) + color = _cfunc(point) push!(arrow_pos, x0) push!(arrow_dir, point ./ pnorm) - push!(colors, pnorm) + push!(colors, color) mask[c] = false n_points += 1 for d in (-1, 1) @@ -123,7 +130,7 @@ function streamplot_impl(CallType, f, limits::Rect{N, T}, resolutionND, stepsize x = x0 ccur = c push!(line_points, Point{N, Float32}(NaN), x) - push!(line_colors, 0.0, pnorm) + push!(line_colors, color, color) while x in limits && n_linepoints < maxsteps point = apply_f(x, CallType) pnorm = norm(point) @@ -143,7 +150,7 @@ function streamplot_impl(CallType, f, limits::Rect{N, T}, resolutionND, stepsize ccur = idx end push!(line_points, x) - push!(line_colors, pnorm) + push!(line_colors, _cfunc(point)) n_linepoints += 1 end end @@ -160,23 +167,27 @@ function streamplot_impl(CallType, f, limits::Rect{N, T}, resolutionND, stepsize end function plot!(p::StreamPlot) - data = lift(p, p.f, p.limits, p.gridsize, p.stepsize, p.maxsteps, p.density) do f, limits, resolution, stepsize, maxsteps, density + data = lift(p, p.f, p.limits, p.gridsize, p.stepsize, p.maxsteps, p.density, p.color) do f, limits, resolution, stepsize, maxsteps, density, color_func P = if applicable(f, Point2f(0)) || applicable(f, Point3f(0)) Point else Number end - streamplot_impl(P, f, limits, resolution, stepsize, maxsteps, density) + streamplot_impl(P, f, limits, resolution, stepsize, maxsteps, density, color_func) end + colormap_args = MakieCore.colormap_attributes(p) + default_attributes = MakieCore.default_attributes(p) + lines!( p, - lift(x->x[3], p, data), color = lift(last, p, data), - colormap = p.colormap, colorscale = p.colorscale, colorrange = p.colorrange, + lift(x->x[3], p, data), + color = lift(last, p, data), linestyle = p.linestyle, - linewidth = p.linewidth, - inspectable = p.inspectable, - transparency = p.transparency + linewidth = p.linewidth; + colormap_args..., + default_attributes... ) + N = ndims(p.limits[]) if N == 2 # && scatterplot.markerspace[] == Pixel (default) @@ -204,10 +215,11 @@ function plot!(p::StreamPlot) scatterfun(N)( p, - lift(first, p, data), markersize = p.arrow_size, - marker=lift((ah, q) -> arrow_head(N, ah, q), p, p.arrow_head, p.quality), - color = lift(x-> x[4], p, data), rotations = rotations, - colormap = p.colormap, colorscale = p.colorscale, colorrange = p.colorrange, - inspectable = p.inspectable, transparency = p.transparency + lift(first, p, data); + markersize=p.arrow_size, rotations=rotations, + color=lift(x -> x[4], p, data), + marker = lift((ah, q) -> arrow_head(N, ah, q), p, p.arrow_head, p.quality), + colormap_args..., + default_attributes... ) end From ecbb0edefb7085d6954f9dd6aeca65b9325d3a24 Mon Sep 17 00:00:00 2001 From: Simon Date: Sat, 22 Jul 2023 13:49:00 +0200 Subject: [PATCH 6/7] prepare 0.19.7 release (#3079) * prepare 0.19.7 release * try non breaking version for MakieCore * rename plot attribute functions --- CairoMakie/Project.toml | 4 +- GLMakie/Project.toml | 4 +- MakieCore/Project.toml | 2 +- MakieCore/src/basic_plots.jl | 96 ++++++++++++++-------------- NEWS.md | 3 +- Project.toml | 4 +- RPRMakie/Project.toml | 4 +- WGLMakie/Project.toml | 4 +- src/basic_recipes/streamplot.jl | 10 +-- src/makielayout/defaultattributes.jl | 2 +- src/makielayout/lineaxis.jl | 2 +- 11 files changed, 68 insertions(+), 67 deletions(-) diff --git a/CairoMakie/Project.toml b/CairoMakie/Project.toml index 7cda71a68ec..7ce30776da2 100644 --- a/CairoMakie/Project.toml +++ b/CairoMakie/Project.toml @@ -1,7 +1,7 @@ name = "CairoMakie" uuid = "13f3f980-e62b-5c42-98c6-ff1f3baf88f0" author = ["Simon Danisch "] -version = "0.10.6" +version = "0.10.7" [deps] Base64 = "2a0f44e3-6c83-55bd-87e4-b1978d98bd5f" @@ -23,7 +23,7 @@ FFTW = "1" FileIO = "1.1" FreeType = "3, 4.0" GeometryBasics = "0.4.1" -Makie = "=0.19.6" +Makie = "=0.19.7" PrecompileTools = "1.0" julia = "1.3" diff --git a/GLMakie/Project.toml b/GLMakie/Project.toml index ad8027ba3a2..52af9bc22e1 100644 --- a/GLMakie/Project.toml +++ b/GLMakie/Project.toml @@ -1,6 +1,6 @@ name = "GLMakie" uuid = "e9467ef8-e4e7-5192-8a1a-b1aee30e663a" -version = "0.8.6" +version = "0.8.7" [deps] ColorTypes = "3da002f7-5984-5a60-b8a6-cbb66c0b333f" @@ -29,7 +29,7 @@ FixedPointNumbers = "0.7, 0.8" FreeTypeAbstraction = "0.10" GLFW = "3" GeometryBasics = "0.4.1" -Makie = "=0.19.6" +Makie = "=0.19.7" MeshIO = "0.4" ModernGL = "1" Observables = "0.5.1" diff --git a/MakieCore/Project.toml b/MakieCore/Project.toml index 729ca0b07e5..8f276dee845 100644 --- a/MakieCore/Project.toml +++ b/MakieCore/Project.toml @@ -1,7 +1,7 @@ authors = ["Simon Danisch"] name = "MakieCore" uuid = "20f20a25-4f0e-4fdf-b5d1-57303727442b" -version = "0.6.3" +version = "0.6.4" [deps] Observables = "510215fc-4207-5dde-b226-833fc4488ee2" diff --git a/MakieCore/src/basic_plots.jl b/MakieCore/src/basic_plots.jl index b1db6a60b18..897216bdd31 100644 --- a/MakieCore/src/basic_plots.jl +++ b/MakieCore/src/basic_plots.jl @@ -1,4 +1,4 @@ -default_theme(scene) = default_theme!(Attributes()) +default_theme(scene) = generic_plot_attributes!(Attributes()) """ @@ -13,7 +13,7 @@ default_theme(scene) = default_theme!(Attributes()) - `model::Makie.Mat4f` sets a model matrix for the plot. This replaces adjustments made with `translate!`, `rotate!` and `scale!`. - `space::Symbol = :data` sets the transformation space for box encompassing the volume plot. See `Makie.spaces()` for possible inputs. """ -function default_theme!(attr) +function generic_plot_attributes!(attr) attr[:transformation] = automatic attr[:model] = automatic attr[:visible] = true @@ -26,7 +26,7 @@ function default_theme!(attr) return attr end -function default_attributes(attr) +function generic_plot_attributes(attr) return ( transformation = attr[:transformation], model = attr[:model], @@ -53,7 +53,7 @@ end - `highclip::Union{Nothing, Symbol, <:Colorant} = nothing` sets a color for any value above the colorrange. - `alpha = 1.0` sets the alpha value of the colormap or color attribute. Multiple alphas like in `plot(alpha=0.2, color=(:red, 0.5)`, will get multiplied. """ -function colormap_args!(attr, colormap) +function colormap_attributes!(attr, colormap) attr[:colormap] = colormap attr[:colorscale] = identity attr[:colorrange] = automatic @@ -129,17 +129,17 @@ Plots an image on range `x, y` (defaults to dimensions). - `interpolate::Bool = true` sets whether colors should be interpolated. -$(Base.Docs.doc(colormap_args!)) +$(Base.Docs.doc(colormap_attributes!)) -$(Base.Docs.doc(MakieCore.default_theme!)) +$(Base.Docs.doc(MakieCore.generic_plot_attributes!)) """ @recipe(Image, x, y, image) do scene attr = Attributes(; interpolate = true, fxaa = false, ) - default_theme!(attr) - return colormap_args!(attr, [:black, :white]) + generic_plot_attributes!(attr) + return colormap_attributes!(attr, [:black, :white]) end """ @@ -154,9 +154,9 @@ Plots a heatmap as an image on `x, y` (defaults to interpretation as dimensions) - `interpolate::Bool = false` sets whether colors should be interpolated. -$(Base.Docs.doc(colormap_args!)) +$(Base.Docs.doc(colormap_attributes!)) -$(Base.Docs.doc(MakieCore.default_theme!)) +$(Base.Docs.doc(MakieCore.generic_plot_attributes!)) """ @recipe(Heatmap, x, y, values) do scene attr = Attributes(; @@ -166,8 +166,8 @@ $(Base.Docs.doc(MakieCore.default_theme!)) linewidth = 0.0, fxaa = true, ) - default_theme!(attr) - return colormap_args!(attr, theme(scene, :colormap)) + generic_plot_attributes!(attr) + return colormap_attributes!(attr, theme(scene, :colormap)) end """ @@ -193,9 +193,9 @@ Available algorithms are: $(Base.Docs.doc(shading_attributes!)) -$(Base.Docs.doc(colormap_args!)) +$(Base.Docs.doc(colormap_attributes!)) -$(Base.Docs.doc(MakieCore.default_theme!)) +$(Base.Docs.doc(MakieCore.generic_plot_attributes!)) """ @recipe(Volume, x, y, z, volume) do scene attr = Attributes(; @@ -206,9 +206,9 @@ $(Base.Docs.doc(MakieCore.default_theme!)) fxaa = true, ) - default_theme!(attr) + generic_plot_attributes!(attr) shading_attributes!(attr) - return colormap_args!(attr, theme(scene, :colormap)) + return colormap_attributes!(attr, theme(scene, :colormap)) end """ @@ -229,9 +229,9 @@ Plots a surface, where `(x, y)` define a grid whose heights are the entries in $(Base.Docs.doc(shading_attributes!)) -$(Base.Docs.doc(colormap_args!)) +$(Base.Docs.doc(colormap_attributes!)) -$(Base.Docs.doc(MakieCore.default_theme!)) +$(Base.Docs.doc(MakieCore.generic_plot_attributes!)) """ @recipe(Surface, x, y, z) do scene attr = Attributes(; @@ -241,8 +241,8 @@ $(Base.Docs.doc(MakieCore.default_theme!)) fxaa = true, ) shading_attributes!(attr) - default_theme!(attr) - return colormap_args!(attr, theme(scene, :colormap)) + generic_plot_attributes!(attr) + return colormap_attributes!(attr, theme(scene, :colormap)) end """ @@ -264,9 +264,9 @@ Creates a connected line plot for each element in `(x, y, z)`, `(x, y)` or `posi - `linestyle::Union{Nothing, Symbol, Vector} = nothing` sets the pattern of the line (e.g. `:solid`, `:dot`, `:dashdot`) - `linewidth::Union{Real, Vector} = 1.5` sets the width of the line in pixel units. -$(Base.Docs.doc(colormap_args!)) +$(Base.Docs.doc(colormap_attributes!)) -$(Base.Docs.doc(MakieCore.default_theme!)) +$(Base.Docs.doc(MakieCore.generic_plot_attributes!)) """ @recipe(Lines, positions) do scene attr = Attributes(; @@ -278,8 +278,8 @@ $(Base.Docs.doc(MakieCore.default_theme!)) fxaa = false, cycle = [:color], ) - default_theme!(attr, ) - return colormap_args!(attr, theme(scene, :colormap)) + generic_plot_attributes!(attr, ) + return colormap_attributes!(attr, theme(scene, :colormap)) end """ @@ -300,9 +300,9 @@ Plots a line for each pair of points in `(x, y, z)`, `(x, y)`, or `positions`. - `linestyle::Union{Nothing, Symbol, Vector} = nothing` sets the pattern of the line (e.g. `:solid`, `:dot`, `:dashdot`) - `linewidth::Union{Real, Vector} = 1.5` sets the width of the line in pixel units. -$(Base.Docs.doc(colormap_args!)) +$(Base.Docs.doc(colormap_attributes!)) -$(Base.Docs.doc(MakieCore.default_theme!)) +$(Base.Docs.doc(MakieCore.generic_plot_attributes!)) """ @recipe(LineSegments, positions) do scene default_theme(scene, Lines) @@ -328,9 +328,9 @@ Plots a 3D or 2D mesh. Supported `mesh_object`s include `Mesh` types from [Geome $(Base.Docs.doc(shading_attributes!)) -$(Base.Docs.doc(colormap_args!)) +$(Base.Docs.doc(colormap_attributes!)) -$(Base.Docs.doc(MakieCore.default_theme!)) +$(Base.Docs.doc(MakieCore.generic_plot_attributes!)) """ @recipe(Mesh, mesh) do scene attr = Attributes(; @@ -341,8 +341,8 @@ $(Base.Docs.doc(MakieCore.default_theme!)) cycle = [:color => :patchcolor], ) shading_attributes!(attr) - default_theme!(attr) - return colormap_args!(attr, theme(scene, :colormap)) + generic_plot_attributes!(attr) + return colormap_attributes!(attr, theme(scene, :colormap)) end """ @@ -369,9 +369,9 @@ Plots a marker for each element in `(x, y, z)`, `(x, y)`, or `positions`. - `rotations::Union{Real, Billboard, Quaternion} = Billboard(0f0)` sets the rotation of the marker. A `Billboard` rotation is always around the depth axis. - `transform_marker::Bool = false` controls whether the model matrix (without translation) applies to the marker itself, rather than just the positions. (If this is true, `scale!` and `rotate!` will affect the marker.) -$(Base.Docs.doc(colormap_args!)) +$(Base.Docs.doc(colormap_attributes!)) -$(Base.Docs.doc(MakieCore.default_theme!)) +$(Base.Docs.doc(MakieCore.generic_plot_attributes!)) """ @recipe(Scatter, positions) do scene attr = Attributes(; @@ -396,8 +396,8 @@ $(Base.Docs.doc(MakieCore.default_theme!)) fxaa = false, cycle = [:color], ) - default_theme!(attr) - return colormap_args!(attr, theme(scene, :colormap)) + generic_plot_attributes!(attr) + return colormap_attributes!(attr, theme(scene, :colormap)) end """ @@ -421,9 +421,9 @@ Plots a mesh for each element in `(x, y, z)`, `(x, y)`, or `positions` (similar $(Base.Docs.doc(shading_attributes!)) -$(Base.Docs.doc(colormap_args!)) +$(Base.Docs.doc(colormap_attributes!)) -$(Base.Docs.doc(MakieCore.default_theme!)) +$(Base.Docs.doc(MakieCore.generic_plot_attributes!)) """ @recipe(MeshScatter, positions) do scene attr = Attributes(; @@ -438,8 +438,8 @@ $(Base.Docs.doc(MakieCore.default_theme!)) cycle = [:color], ) shading_attributes!(attr) - default_theme!(attr) - return colormap_args!(attr, theme(scene, :colormap)) + generic_plot_attributes!(attr) + return colormap_attributes!(attr, theme(scene, :colormap)) end """ @@ -468,9 +468,9 @@ Plots one or multiple texts passed via the `text` keyword. - `glowcolor::Union{Symbol, <:Colorant} = (:black, 0)` sets the color of the glow effect. - `word_wrap_with::Real = -1` specifies a linewidth limit for text. If a word overflows this limit, a newline is inserted before it. Negative numbers disable word wrapping. -$(Base.Docs.doc(colormap_args!)) +$(Base.Docs.doc(colormap_attributes!)) -$(Base.Docs.doc(MakieCore.default_theme!)) +$(Base.Docs.doc(MakieCore.generic_plot_attributes!)) """ @recipe(Text, positions) do scene attr = Attributes(; @@ -492,8 +492,8 @@ $(Base.Docs.doc(MakieCore.default_theme!)) offset = (0.0, 0.0), word_wrap_width = -1, ) - default_theme!(attr) - return colormap_args!(attr, theme(scene, :colormap)) + generic_plot_attributes!(attr) + return colormap_attributes!(attr, theme(scene, :colormap)) end """ @@ -524,9 +524,9 @@ Plots polygons, which are defined by - `strokewidth::Real = 0` sets the width of the outline around a marker. - `linestyle::Union{Nothing, Symbol, Vector} = nothing` sets the pattern of the line (e.g. `:solid`, `:dot`, `:dashdot`) -$(Base.Docs.doc(colormap_args!)) +$(Base.Docs.doc(colormap_attributes!)) -$(Base.Docs.doc(MakieCore.default_theme!)) +$(Base.Docs.doc(MakieCore.generic_plot_attributes!)) """ @recipe(Poly) do scene attr = Attributes(; @@ -541,8 +541,8 @@ $(Base.Docs.doc(MakieCore.default_theme!)) cycle = [:color => :patchcolor], ) - default_theme!(attr) - return colormap_args!(attr, theme(scene, :colormap)) + generic_plot_attributes!(attr) + return colormap_attributes!(attr, theme(scene, :colormap)) end @recipe(Wireframe) do scene @@ -579,8 +579,8 @@ end ssao = false ) - default_theme!(attr) - colormap_args!(attr, theme(scene, :colormap)) + generic_plot_attributes!(attr) + colormap_attributes!(attr, theme(scene, :colormap)) attr[:fxaa] = automatic attr[:linewidth] = automatic diff --git a/NEWS.md b/NEWS.md index 4f309f7f721..5e752ac134b 100644 --- a/NEWS.md +++ b/NEWS.md @@ -2,6 +2,8 @@ ## master +## v0.19.7 + - Allow arbitrary functions to color `streamplot` lines by passing a `Function` to `color`. This must accept `Point` of the appropriate dimension and return a `Point`, `Vec`, or other arraylike object [#2002](https://github.com/MakieOrg/Makie.jl/pull/2002). - `arrows` can now take input of the form `x::AbstractVector, y::AbstractVector, [z::AbstractVector,] f::Function`, where `f` must return a `VecTypes` of the appropriate dimension [#2597](https://github.com/MakieOrg/Makie.jl/pull/2597). - Exported colorbuffer, and added `colorbuffer(axis::Axis; include_decorations=false, colorbuffer_kws...)`, to get an image of an axis with or without decorations [#3078](https://github.com/MakieOrg/Makie.jl/pull/3078). @@ -26,7 +28,6 @@ - Adjusted scaling of scatter/text stroke, glow and anti-aliasing width under non-uniform 2D scaling (Vec2f markersize/fontsize) in GLMakie [#2950](https://github.com/MakieOrg/Makie.jl/pull/2950). - Scaled `errorbar` whiskers and `bracket` correctly with transformations [#3012](https://github.com/MakieOrg/Makie.jl/pull/3012). - Updated `bracket` when the screen is resized or transformations change [#3012](https://github.com/MakieOrg/Makie.jl/pull/3012). -- Added auto-resizing functionality to WGLMakie plot figures [#3042](https://github.com/MakieOrg/Makie.jl/pull/3042) ## v0.19.6 diff --git a/Project.toml b/Project.toml index e6d2419da51..36b12693102 100644 --- a/Project.toml +++ b/Project.toml @@ -1,7 +1,7 @@ name = "Makie" uuid = "ee78f7c6-11fb-53f2-987a-cfe4a2b5a57a" authors = ["Simon Danisch", "Julius Krumbiegel"] -version = "0.19.6" +version = "0.19.7" [deps] Animations = "27a7e980-b3e6-11e9-2bcd-0b925532e340" @@ -82,7 +82,7 @@ Isoband = "0.1" KernelDensity = "0.5, 0.6" LaTeXStrings = "1.2" MacroTools = "0.5" -MakieCore = "=0.6.3" +MakieCore = "=0.6.4" Match = "1.1" MathTeXEngine = "0.5" Observables = "0.5.3" diff --git a/RPRMakie/Project.toml b/RPRMakie/Project.toml index e0aea02aeb2..564a226a6f8 100644 --- a/RPRMakie/Project.toml +++ b/RPRMakie/Project.toml @@ -1,7 +1,7 @@ name = "RPRMakie" uuid = "22d9f318-5e34-4b44-b769-6e3734a732a6" authors = ["Simon Danisch"] -version = "0.5.6" +version = "0.5.7" [deps] Colors = "5ae59095-9a9b-59fe-a467-6f913c188581" @@ -17,7 +17,7 @@ julia = "1.3" Colors = "0.9, 0.10, 0.11, 0.12" FileIO = "1.6" GeometryBasics = "0.4.1" -Makie = "=0.19.6" +Makie = "=0.19.7" RadeonProRender = "0.3.0" [extras] diff --git a/WGLMakie/Project.toml b/WGLMakie/Project.toml index 09053cbf7bb..0def8bf49bf 100644 --- a/WGLMakie/Project.toml +++ b/WGLMakie/Project.toml @@ -1,7 +1,7 @@ name = "WGLMakie" uuid = "276b4fcb-3e11-5398-bf8b-a0c2d153d008" authors = ["SimonDanisch "] -version = "0.8.10" +version = "0.8.11" [deps] Colors = "5ae59095-9a9b-59fe-a467-6f913c188581" @@ -26,7 +26,7 @@ FreeTypeAbstraction = "0.10" GeometryBasics = "0.4.1" Hyperscript = "0.0.3, 0.0.4" JSServe = "2.2" -Makie = "=0.19.6" +Makie = "=0.19.7" Observables = "0.5.1" RelocatableFolders = "0.1, 0.2, 0.3, 1.0" ShaderAbstractions = "0.3" diff --git a/src/basic_recipes/streamplot.jl b/src/basic_recipes/streamplot.jl index f892860627f..9a999d27300 100644 --- a/src/basic_recipes/streamplot.jl +++ b/src/basic_recipes/streamplot.jl @@ -36,8 +36,8 @@ See the function `Makie.streamplot_impl` for implementation details. linewidth = theme(scene, :linewidth), linestyle = nothing, ) - MakieCore.colormap_args!(attr, theme(scene, :colormap)) - MakieCore.default_theme!(attr) + MakieCore.colormap_attributes!(attr, theme(scene, :colormap)) + MakieCore.generic_plot_attributes!(attr) return attr end @@ -176,7 +176,7 @@ function plot!(p::StreamPlot) streamplot_impl(P, f, limits, resolution, stepsize, maxsteps, density, color_func) end colormap_args = MakieCore.colormap_attributes(p) - default_attributes = MakieCore.default_attributes(p) + generic_plot_attributes = MakieCore.generic_plot_attributes(p) lines!( p, @@ -185,7 +185,7 @@ function plot!(p::StreamPlot) linestyle = p.linestyle, linewidth = p.linewidth; colormap_args..., - default_attributes... + generic_plot_attributes... ) N = ndims(p.limits[]) @@ -220,6 +220,6 @@ function plot!(p::StreamPlot) color=lift(x -> x[4], p, data), marker = lift((ah, q) -> arrow_head(N, ah, q), p, p.arrow_head, p.quality), colormap_args..., - default_attributes... + generic_plot_attributes... ) end diff --git a/src/makielayout/defaultattributes.jl b/src/makielayout/defaultattributes.jl index da2aaec776a..12603db1821 100644 --- a/src/makielayout/defaultattributes.jl +++ b/src/makielayout/defaultattributes.jl @@ -34,7 +34,7 @@ function inherit(::Nothing, attr::NTuple{N, Symbol}, default_value::T) where {N, default_value end -function default_attributes(::Type{LineAxis}) +function generic_plot_attributes(::Type{LineAxis}) Attributes( endpoints = (Point2f(0, 0), Point2f(100, 0)), trimspine = false, diff --git a/src/makielayout/lineaxis.jl b/src/makielayout/lineaxis.jl index 2f345b736b4..d8dbcd3b6a9 100644 --- a/src/makielayout/lineaxis.jl +++ b/src/makielayout/lineaxis.jl @@ -1,5 +1,5 @@ function LineAxis(parent::Scene; @nospecialize(kwargs...)) - attrs = merge!(Attributes(kwargs), default_attributes(LineAxis)) + attrs = merge!(Attributes(kwargs), generic_plot_attributes(LineAxis)) return LineAxis(parent, attrs) end From 8a0bc1500daf984bec0ed6d3071e0f948b0d6ec3 Mon Sep 17 00:00:00 2001 From: Simon Date: Sat, 22 Jul 2023 13:50:17 +0200 Subject: [PATCH 7/7] Update Project.toml --- Project.toml | 1 + 1 file changed, 1 insertion(+) diff --git a/Project.toml b/Project.toml index 36b12693102..95b654d9bf1 100644 --- a/Project.toml +++ b/Project.toml @@ -93,6 +93,7 @@ PolygonOps = "0.1.1" PrecompileTools = "1.0" RelocatableFolders = "0.1, 0.2, 0.3, 1.0" Setfield = "1" +ShaderAbstractions = "0.3" Showoff = "0.3, 1.0.2" SignedDistanceFields = "0.4" StableHashTraits = "0.3"