From 863a46fe467d0dd4fe41aba854619ec0d89d8f97 Mon Sep 17 00:00:00 2001 From: Simon Date: Mon, 6 Jun 2022 16:01:57 +0200 Subject: [PATCH] Remove MakieLayout module (#2008) * remove MakieLayout module * revert change * use new clash free GridLayoutBase * fix tests * remove mentions of MakieLayout --- MakieRecipes/src/layout_integration.jl | 2 +- Project.toml | 2 +- docs/documentation/cameras.md | 2 +- docs/documentation/layouting.md | 2 +- docs/examples/blocks/axis.md | 12 ++-- docs/tutorials.md | 2 +- src/Makie.jl | 41 +++++++----- src/basic_recipes/axis.jl | 11 ++- src/basic_recipes/series.jl | 2 +- src/basic_recipes/text.jl | 14 ++-- src/figureplotting.jl | 4 +- src/makielayout/MakieLayout.jl | 48 +------------ src/makielayout/blocks.jl | 18 +++-- src/makielayout/blocks/axis3d.jl | 4 +- src/makielayout/lineaxis.jl | 2 +- src/makielayout/precompile.jl | 13 ---- src/precompiles.jl | 93 ++++++++++++++++++++++++-- src/utilities/utilities.jl | 6 -- test/makielayout.jl | 10 +-- 19 files changed, 159 insertions(+), 129 deletions(-) delete mode 100644 src/makielayout/precompile.jl diff --git a/MakieRecipes/src/layout_integration.jl b/MakieRecipes/src/layout_integration.jl index 14bb25fce7d..6cf6ad5206f 100644 --- a/MakieRecipes/src/layout_integration.jl +++ b/MakieRecipes/src/layout_integration.jl @@ -1,4 +1,4 @@ -function tomakie!(sc::AbstractScene, layout::MakieLayout.GridLayout, args...; attrs...) +function tomakie!(sc::AbstractScene, layout::Makie.GridLayout, args...; attrs...) # TODO create a finalizer for a Tuple{Scene, Layout, Vector{LAxis}} RecipesPipeline.recipe_pipeline!(sc, Dict{Symbol, Any}(attrs), args) end diff --git a/Project.toml b/Project.toml index cb5363c0f8d..16ba5f8c3fd 100644 --- a/Project.toml +++ b/Project.toml @@ -65,7 +65,7 @@ Formatting = "0.4" FreeType = "3.0, 4.0" FreeTypeAbstraction = "0.8, 0.9" GeometryBasics = "0.4.2" -GridLayoutBase = "0.7.1" +GridLayoutBase = "0.7.6" ImageIO = "0.2, 0.3, 0.4, 0.5, 0.6" IntervalSets = "0.3, 0.4, 0.5, 0.6, 0.7" Isoband = "0.1" diff --git a/docs/documentation/cameras.md b/docs/documentation/cameras.md index 2f3cc947700..f935c92c29c 100644 --- a/docs/documentation/cameras.md +++ b/docs/documentation/cameras.md @@ -24,7 +24,7 @@ The 2D camera (\apilink{cam2d!(scene)}) uses an orthographic projection with a f - `panbutton = Mouse.right` sets the mouse button that needs to be pressed to translate the view. - `selectionbutton = (Keyboard.space, Mouse.left)` sets a set of buttons that need to be pressed to perform rectangle zooms. -Note that this camera is not used by MakieLayout `Axis`. It is used, by default, for 2D `LScene`s and `Scene`s. +Note that this camera is not used by `Axis`. It is used, by default, for 2D `LScene`s and `Scene`s. ## 3D Camera diff --git a/docs/documentation/layouting.md b/docs/documentation/layouting.md index b5a5c904bb7..219877d34a3 100644 --- a/docs/documentation/layouting.md +++ b/docs/documentation/layouting.md @@ -1,6 +1,6 @@ # How layouts work -The goal of MakieLayout is that all elements placed in a scene fit into the +The goal is that all elements placed in a scene fit into the window, fill the available space, and are nicely aligned relative to each other. This works by using `GridLayout` objects that determine how wide their rows and columns should be given their content elements. diff --git a/docs/examples/blocks/axis.md b/docs/examples/blocks/axis.md index 272cc2f2571..bc7f1d5a005 100644 --- a/docs/examples/blocks/axis.md +++ b/docs/examples/blocks/axis.md @@ -216,9 +216,9 @@ To control ticks, you can set the axis attributes `xticks/yticks` and `xtickform You can overload one or more of these three functions to implement custom ticks: ```julia -tickvalues, ticklabels = MakieLayout.get_ticks(ticks, scale, formatter, vmin, vmax) -tickvalues = MakieLayout.get_tickvalues(ticks, vmin, vmax) -ticklabels = MakieLayout.get_ticklabels(formatter, tickvalues) +tickvalues, ticklabels = Makie.get_ticks(ticks, scale, formatter, vmin, vmax) +tickvalues = Makie.get_tickvalues(ticks, vmin, vmax) +ticklabels = Makie.get_ticklabels(formatter, tickvalues) ``` If you overload `get_ticks`, you have to compute both tickvalues and ticklabels directly as a vector of floats and strings, respectively. @@ -302,7 +302,7 @@ f You can show minor ticks and grids by setting `x/yminorticksvisible = true` and `x/yminorgridvisible = true` which are off by default. You can set size, color, width, align etc. like for the normal ticks, but there are no labels. The `x/yminorticks` attributes control how minor ticks are computed given major ticks and axis limits. -For that purpose you can create your own minortick type and overload `MakieLayout.get_minor_tickvalues(minorticks, tickvalues, vmin, vmax)`. +For that purpose you can create your own minortick type and overload `Makie.get_minor_tickvalues(minorticks, tickvalues, vmin, vmax)`. The default minor tick type is `IntervalsBetween(n, mirror = true)` where `n` gives the number of intervals each gap between major ticks is divided into with minor ticks, and `mirror` decides if outside of the major ticks there are more minor ticks with the same intervals as the adjacent gaps. @@ -794,7 +794,7 @@ mutable struct MyInteraction allow_right_click::Bool end -function MakieLayout.process_interaction(interaction::MyInteraction, event::MouseEvent, axis) +function Makie.process_interaction(interaction::MyInteraction, event::MouseEvent, axis) if interaction.use_left_click && event.type === MouseEventTypes.leftclick println("Left click in correct mode") end @@ -803,7 +803,7 @@ function MakieLayout.process_interaction(interaction::MyInteraction, event::Mous end end -function MakieLayout.process_interaction(interaction::MyInteraction, event::KeysEvent, axis) +function Makie.process_interaction(interaction::MyInteraction, event::KeysEvent, axis) interaction.allow_left_click = Keyboard.l in event.keys interaction.allow_right_click = Keyboard.r in event.keys end diff --git a/docs/tutorials.md b/docs/tutorials.md index 71d4751ff10..0387f66031e 100644 --- a/docs/tutorials.md +++ b/docs/tutorials.md @@ -65,7 +65,7 @@ @@box-container @@box ~~~~~~ - @@title MakieLayout Deep Dive @@ + @@title Makie Layouting Deep Dive @@ @@box-content @@description A tour of some of the more complex layout features of Makie. diff --git a/src/Makie.jl b/src/Makie.jl index 7c67099c04c..592416d817c 100644 --- a/src/Makie.jl +++ b/src/Makie.jl @@ -18,13 +18,11 @@ using Random using FFMPEG # get FFMPEG on any system! using Observables using GeometryBasics -using IntervalSets using PlotUtils using ColorBrewer using ColorTypes using Colors using ColorSchemes -using FixedPointNumbers using Packing using SignedDistanceFields using Markdown @@ -37,6 +35,8 @@ using FreeTypeAbstraction using UnicodeFun using LinearAlgebra using Statistics +using MakieCore +using OffsetArrays import RelocatableFolders import StatsBase @@ -48,10 +48,11 @@ import GridLayoutBase import ImageIO import FileIO import SparseArrays -using MakieCore -using OffsetArrays -using GeometryBasics: widths, positive_widths, VecTypes, AbstractPolygon, value, StaticVector +using IntervalSets: IntervalSets, (..), OpenInterval, ClosedInterval, AbstractInterval, Interval, endpoints +using FixedPointNumbers: N0f8 + +using GeometryBasics: width, widths, height, positive_widths, VecTypes, AbstractPolygon, value, StaticVector using Distributions: Distribution, VariateForm, Discrete, QQPair, pdf, quantile, qqbuild import FileIO: save @@ -276,6 +277,25 @@ function logo() end function __init__() + # Make GridLayoutBase default row and colgaps themeable when using Makie + # This mutates module-level state so it could mess up other libraries using + # GridLayoutBase at the same time as Makie, which is unlikely, though + GridLayoutBase.DEFAULT_COLGAP_GETTER[] = function() + ct = Makie.current_default_theme() + if haskey(ct, :colgap) + ct[:colgap][] + else + GridLayoutBase.DEFAULT_COLGAP[] + end + end + GridLayoutBase.DEFAULT_ROWGAP_GETTER[] = function() + ct = Makie.current_default_theme() + if haskey(ct, :rowgap) + ct[:rowgap][] + else + GridLayoutBase.DEFAULT_ROWGAP[] + end + end # fonts aren't cacheable by precompilation, so we need to empty it on load! empty!(FONT_CACHE) cfg_path = joinpath(homedir(), ".config", "makie", "theme.jl") @@ -290,12 +310,6 @@ export content export resize_to_layout! include("makielayout/MakieLayout.jl") -# re-export MakieLayout -for name in names(MakieLayout) - @eval import .MakieLayout: $(name) - @eval export $(name) -end - include("figureplotting.jl") include("basic_recipes/series.jl") include("basic_recipes/text.jl") @@ -307,9 +321,6 @@ export heatmap!, image!, lines!, linesegments!, mesh!, meshscatter!, scatter!, s export PointLight, EnvironmentLight, AmbientLight, SSAO -if Base.VERSION >= v"1.4.2" - include("precompiles.jl") - _precompile_() -end +include("precompiles.jl") end # module diff --git a/src/basic_recipes/axis.jl b/src/basic_recipes/axis.jl index 81a0ee1e793..373513a9216 100644 --- a/src/basic_recipes/axis.jl +++ b/src/basic_recipes/axis.jl @@ -20,6 +20,13 @@ module Formatters end using .Formatters + +to_3tuple(x) = ntuple(i -> x, Val(3)) +to_3tuple(x::NTuple{3,Any}) = x + +to_2tuple(x) = ntuple(i -> x, Val(2)) +to_2tuple(x::NTuple{2,Any}) = x + """ $(SIGNATURES) @@ -66,7 +73,7 @@ $(ATTRIBUTES) rotation = axisnames_rotation3d, textsize = (6.0, 6.0, 6.0), align = axisnames_align3d, - font = lift(dim3, theme(scene, :font)), + font = lift(to_3tuple, theme(scene, :font)), gap = 3 ), @@ -80,7 +87,7 @@ $(ATTRIBUTES) textsize = (tsize, tsize, tsize), align = tickalign3d, gap = 3, - font = lift(dim3, theme(scene, :font)), + font = lift(to_3tuple, theme(scene, :font)), ), frame = Attributes( diff --git a/src/basic_recipes/series.jl b/src/basic_recipes/series.jl index c1329f17363..c7bf498cb42 100644 --- a/src/basic_recipes/series.jl +++ b/src/basic_recipes/series.jl @@ -92,6 +92,6 @@ function plot!(plot::Series) end end -function MakieLayout.get_plots(plot::Series) +function Makie.get_plots(plot::Series) return plot.plots end diff --git a/src/basic_recipes/text.jl b/src/basic_recipes/text.jl index 750a56a8071..eb197e6bd3a 100644 --- a/src/basic_recipes/text.jl +++ b/src/basic_recipes/text.jl @@ -1,7 +1,7 @@ function plot!(plot::Text) # attach a function to any text that calculates the glyph layout and stores it glyphcollection = lift(plot[1], plot.textsize, plot.font, plot.align, - plot.rotation, plot.justification, plot.lineheight, plot.color, + plot.rotation, plot.justification, plot.lineheight, plot.color, plot.strokecolor, plot.strokewidth, plot.word_wrap_width) do str, ts, f, al, rot, jus, lh, col, scol, swi, www ts = to_textsize(ts) @@ -28,8 +28,8 @@ function plot!(plot::Text{<:Tuple{<:AbstractArray{<:AbstractString}}}) glyphcollections = Observable(GlyphCollection[]) rotation = Observable{Any}(nothing) - onany(plot[1], plot.textsize, plot.font, plot.align, - plot.rotation, plot.justification, plot.lineheight, plot.color, + onany(plot[1], plot.textsize, plot.font, plot.align, + plot.rotation, plot.justification, plot.lineheight, plot.color, plot.strokecolor, plot.strokewidth, plot.word_wrap_width) do str, ts, f, al, rot, jus, lh, col, scol, swi, wwws @@ -54,7 +54,7 @@ function plot!(plot::Text{<:Tuple{<:AbstractArray{<:AbstractString}}}) notify(plot[1]) text!(plot, glyphcollections; position = plot.position, rotation = rotation, - model = plot.model, offset = plot.offset, markerspace = plot.markerspace, + model = plot.model, offset = plot.offset, markerspace = plot.markerspace, visible=plot.visible, space = plot.space) plot @@ -90,7 +90,7 @@ function plot!(plot::Text{<:Tuple{<:Union{LaTeXString, AbstractVector{<:LaTeXStr # attach a function to any text that calculates the glyph layout and stores it lineels_glyphcollection_offset = lift(plot[1], plot.textsize, plot.align, plot.rotation, - plot.model, plot.color, plot.strokecolor, plot.strokewidth, + plot.model, plot.color, plot.strokecolor, plot.strokewidth, plot.word_wrap_width) do latexstring, ts, al, rot, mo, color, scolor, swidth, www ts = to_textsize(ts) @@ -182,7 +182,7 @@ function plot!(plot::Text{<:Tuple{<:Union{LaTeXString, AbstractVector{<:LaTeXStr text!(plot, glyphcollection; plot.attributes...) linesegments!( plot, linepairs, linewidth = linewidths, color = plot.color, - visible = plot.visible, inspectable = plot.inspectable, + visible = plot.visible, inspectable = plot.inspectable, transparent = plot.transparency, space = :pixel ) @@ -284,4 +284,4 @@ function texelems_and_glyph_collection(str::LaTeXString, fontscale_px, halign, v all_els, pre_align_gl, Point2f(xshift, yshift) end -MakieLayout.iswhitespace(l::LaTeXString) = MakieLayout.iswhitespace(replace(l.s, '$' => "")) \ No newline at end of file +iswhitespace(l::LaTeXString) = iswhitespace(replace(l.s, '$' => "")) diff --git a/src/figureplotting.jl b/src/figureplotting.jl index 05ab86684cd..bf21ff16d34 100644 --- a/src/figureplotting.jl +++ b/src/figureplotting.jl @@ -48,7 +48,7 @@ end function plot(P::PlotFunc, gp::GridPosition, args...; axis = NamedTuple(), kwargs...) - f = MakieLayout.get_top_parent(gp) + f = get_top_parent(gp) c = contents(gp, exact = true) if !isempty(c) @@ -108,7 +108,7 @@ function plot(P::PlotFunc, gsp::GridSubposition, args...; axis = NamedTuple(), k """) end - fig = MakieLayout.get_top_parent(gsp) + fig = get_top_parent(gsp) axis = Dict(pairs(axis)) diff --git a/src/makielayout/MakieLayout.jl b/src/makielayout/MakieLayout.jl index bd1172e24e8..83f7d061f2c 100644 --- a/src/makielayout/MakieLayout.jl +++ b/src/makielayout/MakieLayout.jl @@ -1,55 +1,14 @@ -module MakieLayout - -using ..Makie -using ..Makie: Rect2 -import ..Makie: Rect2i -import ..Makie: RGBColors -using ..Makie.Keyboard -using ..Makie.Mouse -using ..Makie: ispressed, is_mouseinside, get_scene, FigureLike -using ..Makie: Consume -using ..Makie: OpenInterval, Interval -using ..Makie: is_data_space -using MakieCore -using MakieCore: Automatic, automatic -using Observables: onany -import Observables import Formatting using Match import Animations -import PlotUtils using GridLayoutBase using GridLayoutBase: GridSubposition import Showoff -using Colors -import Markdown const FPS = Observable(30) const COLOR_ACCENT = Ref(RGBf(((79, 122, 214) ./ 255)...)) const COLOR_ACCENT_DIMMED = Ref(RGBf(((174, 192, 230) ./ 255)...)) -# Make GridLayoutBase default row and colgaps themeable when using MakieLayout -# This mutates module-level state so it could mess up other libraries using -# GridLayoutBase at the same time as MakieLayout, which is unlikely, though -function __init__() - GridLayoutBase.DEFAULT_COLGAP_GETTER[] = function() - ct = Makie.current_default_theme() - if haskey(ct, :colgap) - ct[:colgap][] - else - GridLayoutBase.DEFAULT_COLGAP[] - end - end - GridLayoutBase.DEFAULT_ROWGAP_GETTER[] = function() - ct = Makie.current_default_theme() - if haskey(ct, :rowgap) - ct[:rowgap][] - else - GridLayoutBase.DEFAULT_ROWGAP[] - end - end -end - include("blocks.jl") include("geometrybasics_extension.jl") include("mousestatemachine.jl") @@ -133,9 +92,4 @@ export swap! export ncols, nrows export contents, content -if Base.VERSION >= v"1.4.2" - include("precompile.jl") - _precompile_() -end - -end # module +Base.@deprecate_binding MakieLayout Makie true "The module `MakieLayout` has been removed and integrated into Makie, so simply replace all usage of `MakieLayout` with `Makie`." diff --git a/src/makielayout/blocks.jl b/src/makielayout/blocks.jl index 1a4d8a0acb7..f067b3cdf3b 100644 --- a/src/makielayout/blocks.jl +++ b/src/makielayout/blocks.jl @@ -14,9 +14,9 @@ macro Block(name::Symbol, body::Expr = Expr(:block)) end structdef = quote - mutable struct $name <: Makie.MakieLayout.Block + mutable struct $name <: Makie.Block parent::Union{Figure, Scene, Nothing} - layoutobservables::Makie.MakieLayout.LayoutObservables{GridLayout} + layoutobservables::Makie.LayoutObservables{GridLayout} blockscene::Scene end end @@ -63,18 +63,18 @@ macro Block(name::Symbol, body::Expr = Expr(:block)) export $name - function Makie.MakieLayout.is_attribute(::Type{$(name)}, sym::Symbol) + function Makie.is_attribute(::Type{$(name)}, sym::Symbol) sym in ($((attrs !== nothing ? [QuoteNode(a.symbol) for a in attrs] : [])...),) end - function Makie.MakieLayout.default_attribute_values(::Type{$(name)}, scene::Union{Scene, Nothing}) + function Makie.default_attribute_values(::Type{$(name)}, scene::Union{Scene, Nothing}) sceneattrs = scene === nothing ? Attributes() : theme(scene) curdeftheme = Makie.current_default_theme() $(make_attr_dict_expr(attrs, :sceneattrs, :curdeftheme)) end - function Makie.MakieLayout.attribute_default_expressions(::Type{$name}) + function Makie.attribute_default_expressions(::Type{$name}) $( if attrs === nothing Dict{Symbol, String}() @@ -84,7 +84,7 @@ macro Block(name::Symbol, body::Expr = Expr(:block)) ) end - function Makie.MakieLayout._attribute_docs(::Type{$(name)}) + function Makie._attribute_docs(::Type{$(name)}) Dict( $( (attrs !== nothing ? @@ -94,7 +94,7 @@ macro Block(name::Symbol, body::Expr = Expr(:block)) ) end - Makie.MakieLayout.has_forwarded_layout(::Type{$name}) = $has_forwarded_layout + Makie.has_forwarded_layout(::Type{$name}) = $has_forwarded_layout end esc(q) @@ -385,9 +385,7 @@ function _block(T::Type{<:Block}, fig_or_scene::Union{Figure, Scene}, empty!(b.layout.layoutobservables.computedbbox.listeners) # connect the block's layoutobservables.computedbbox to the align action that # usually the GridLayout executes itself - on(lobservables.computedbbox) do bb - GridLayoutBase.align_to_bbox!(b.layout, bb) - end + onany(GridLayoutBase.align_to_bbox!, b.layout, lobservables.computedbbox) end # in this function, the block specific setup logic is executed and the remaining diff --git a/src/makielayout/blocks/axis3d.jl b/src/makielayout/blocks/axis3d.jl index 8b2bf889c69..6b63ba16ef8 100644 --- a/src/makielayout/blocks/axis3d.jl +++ b/src/makielayout/blocks/axis3d.jl @@ -116,7 +116,7 @@ function initialize_block!(ax::Axis3) setfield!(ax, :scrollevents, scrollevents) keysevents = Observable(KeysEvent(Set())) setfield!(ax, :keysevents, keysevents) - + on(scene.events.scroll) do s if is_mouseinside(scene) ax.scrollevents[] = ScrollEvent(s[1], s[2]) @@ -546,7 +546,7 @@ function add_ticks_and_ticklabels!(topscene, scene, ax, dim::Int, limits, tickno label_align = Observable((:center, :top)) onany( - scene.px_area, scene.camera.projectionview, limits, miv, min1, min2, + scene.px_area, scene.camera.projectionview, limits, miv, min1, min2, attr(:labeloffset), attr(:labelrotation), attr(:labelalign) ) do pxa, pv, lims, miv, min1, min2, labeloffset, lrotation, lalign diff --git a/src/makielayout/lineaxis.jl b/src/makielayout/lineaxis.jl index 08c5d329885..da284cad5a3 100644 --- a/src/makielayout/lineaxis.jl +++ b/src/makielayout/lineaxis.jl @@ -653,7 +653,7 @@ get_ticklabels(formatstring::AbstractString, values) = [Formatting.format(format function get_ticks(m::MultiplesTicks, any_scale, ::Automatic, vmin, vmax) dvmin = vmin / m.multiple dvmax = vmax / m.multiple - multiples = MakieLayout.get_tickvalues(LinearTicks(m.n_ideal), dvmin, dvmax) + multiples = Makie.get_tickvalues(LinearTicks(m.n_ideal), dvmin, dvmax) multiples .* m.multiple, Showoff.showoff(multiples) .* m.suffix end diff --git a/src/makielayout/precompile.jl b/src/makielayout/precompile.jl deleted file mode 100644 index 1e29dc50ca4..00000000000 --- a/src/makielayout/precompile.jl +++ /dev/null @@ -1,13 +0,0 @@ -function _precompile_() - ccall(:jl_generating_output, Cint, ()) == 1 || return nothing - @assert precompile(Legend, (Scene, Observable{Vector{Tuple{Optional{String}, Vector{LegendEntry}}}})) - # @assert precompile(Legend, (Scene, AbstractArray, Vector{String})) - @assert precompile(Colorbar, (Scene,)) - # @assert precompile(Axis, (Scene,)) - # @assert precompile(Core.kwfunc(Type), (NamedTuple{(:title,), Tuple{String}}, Type{Axis}, Scene)) - @assert precompile(LineAxis, (Scene,)) - @assert precompile(Menu, (Scene,)) - @assert precompile(Button, (Scene,)) - @assert precompile(Slider, (Scene,)) - @assert precompile(Textbox, (Scene,)) -end diff --git a/src/precompiles.jl b/src/precompiles.jl index 2658634d48b..c46a263d9be 100644 --- a/src/precompiles.jl +++ b/src/precompiles.jl @@ -1,8 +1,87 @@ -function _precompile_() - ccall(:jl_generating_output, Cint, ()) == 1 || return nothing - f, ax1, pl = scatter(1:4) - f, ax2, pl = lines(1:4) - f = Figure() - Axis(f[1,1]) - return +function get_obs(x::Attributes, visited, obs=Set()) + if x in visited; return; else; push!(visited, x); end + union!(obs, values(x)) + return obs +end + +function get_obs(x::Union{AbstractVector, Tuple}, visited, obs=Set()) + if x in visited; return; else; push!(visited, x); end + isempty(x) && return + for e in x + get_obs(e, visited, obs) + end + return obs +end + +get_obs(::Nothing, visited, obs=Set()) = obs +get_obs(::DataType, visited, obs=Set()) = obs +get_obs(::Method, visited, obs=Set()) = obs + +function get_obs(x, visited, obs=Set()) + if x in visited; return; else; push!(visited, x); end + for f in fieldnames(typeof(x)) + if isdefined(x, f) + get_obs(getfield(x, f), visited, obs) + end + end +end + +function get_obs(x::Union{AbstractDict, NamedTuple}, visited, obs=Set()) + if x in visited; return; else; push!(visited, x); end + for (k, v) in pairs(x) + get_obs(v, visited, obs) + end + return obs +end + +function get_obs(x::Union{Observables.AbstractObservable, Observables.ObserverFunction}, visited, obs=Set()) + push!(obs, x) + return obs +end + +function get_obs(x::Axis, visited, obs=Set()) + if x in visited; return; else; push!(visited, x); end + + # get_obs(x.attributes, visited, obs) + get_obs(x.layoutobservables, visited, obs) + get_obs(x.scene, visited, obs) + get_obs(x.finallimits, visited, obs) + get_obs(x.scrollevents, visited, obs) + get_obs(x.keysevents, visited, obs) + get_obs(x.mouseeventhandle.obs, visited, obs) + return obs +end + +function precompile_obs(x) + obsies = get_obs(x, Base.IdSet()) + for obs in obsies + Base.precompile(obs) + end +end + +precompile(Makie.initialize_block!, (Axis,)) + +let + if ccall(:jl_generating_output, Cint, ()) == 1 + ax = Axis(Figure()[1,1]) + ax = _block(Axis, Figure()) + initialize_block!(ax) + LineAxis(Scene(); spinecolor=:red, labelfont="Deja vue", ticklabelfont="Deja Vue", spinevisible=false, endpoints=Observable([Point2f(0), Point2f(0, 1)]), minorticks = IntervalsBetween(5)) + cam = Camera(Observable(Recti(0, 0, 1, 1))) + f, ax1, pl = scatter(1:4) + f, ax2, pl = lines(1:4) + precompile_obs(ax1) + precompile_obs(ax2) + convert_arguments(Mesh{Tuple{Vector{Point{2, Float32}}, Matrix{Int64}}}, rand(Point2f, 10), [1 2 3; 4 3 2]) + @assert precompile(Legend, (Scene, Observable{Vector{Tuple{Optional{String}, Vector{LegendEntry}}}})) + # @assert precompile(Legend, (Scene, AbstractArray, Vector{String})) + @assert precompile(Colorbar, (Scene,)) + # @assert precompile(Axis, (Scene,)) + # @assert precompile(Core.kwfunc(Type), (NamedTuple{(:title,), Tuple{String}}, Type{Axis}, Scene)) + @assert precompile(LineAxis, (Scene,)) + @assert precompile(Menu, (Scene,)) + @assert precompile(Button, (Scene,)) + @assert precompile(Slider, (Scene,)) + @assert precompile(Textbox, (Scene,)) + end end diff --git a/src/utilities/utilities.jl b/src/utilities/utilities.jl index 204bea67548..cc1d2a3d4e0 100644 --- a/src/utilities/utilities.jl +++ b/src/utilities/utilities.jl @@ -231,12 +231,6 @@ function to_ndim(T::Type{<: VecTypes{N,ET}}, vec::VecTypes{N2}, fillval) where { end) end -dim3(x) = ntuple(i -> x, Val(3)) -dim3(x::NTuple{3,Any}) = x - -dim2(x) = ntuple(i -> x, Val(2)) -dim2(x::NTuple{2,Any}) = x - lerp(a::T, b::T, val::AbstractFloat) where {T} = (a .+ (val * (b .- a))) function merged_get!(defaults::Function, key, scene, input::Vector{Any}) diff --git a/test/makielayout.jl b/test/makielayout.jl index 6b1ea8a980f..7c30e92e4c5 100644 --- a/test/makielayout.jl +++ b/test/makielayout.jl @@ -1,9 +1,9 @@ -# Minimal sanity checks for MakieLayout +# Minimal sanity checks for Makie Layout @testset "Blocks constructors" begin fig = Figure() ax = Axis(fig[1, 1]) cb = Colorbar(fig[1, 2]) - gl2 = fig[2, :] = MakieLayout.GridLayout() + gl2 = fig[2, :] = Makie.GridLayout() bu = gl2[1, 1] = Button(fig) sl = gl2[1, 2] = Slider(fig) @@ -130,9 +130,9 @@ end automatic = Makie.automatic Automatic = Makie.Automatic - get_ticks = MakieLayout.get_ticks - get_tickvalues = MakieLayout.get_tickvalues - get_ticklabels = MakieLayout.get_ticklabels + get_ticks = Makie.get_ticks + get_tickvalues = Makie.get_tickvalues + get_ticklabels = Makie.get_ticklabels for func in [identity, log, log2, log10, Makie.logit] tup = ([1, 2, 3], ["a", "b", "c"])