Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove MakieLayout module #2008

Merged
merged 10 commits into from Jun 6, 2022
2 changes: 1 addition & 1 deletion Project.toml
Expand Up @@ -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"
Expand Down
41 changes: 26 additions & 15 deletions src/Makie.jl
Expand Up @@ -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
Expand All @@ -37,6 +35,8 @@ using FreeTypeAbstraction
using UnicodeFun
using LinearAlgebra
using Statistics
using MakieCore
using OffsetArrays

import RelocatableFolders
import StatsBase
Expand All @@ -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
Expand Down Expand Up @@ -272,6 +273,25 @@ function logo()
end

function __init__()
# 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
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")
Expand All @@ -286,12 +306,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")
Expand All @@ -303,9 +317,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
11 changes: 9 additions & 2 deletions src/basic_recipes/axis.jl
Expand Up @@ -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)

Expand Down Expand Up @@ -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
),

Expand All @@ -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(
Expand Down
2 changes: 1 addition & 1 deletion src/basic_recipes/series.jl
Expand Up @@ -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
14 changes: 7 additions & 7 deletions 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)
Expand All @@ -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

Expand All @@ -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
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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
)

Expand Down Expand Up @@ -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, '$' => ""))
iswhitespace(l::LaTeXString) = iswhitespace(replace(l.s, '$' => ""))
4 changes: 2 additions & 2 deletions src/figureplotting.jl
Expand Up @@ -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)
Expand Down Expand Up @@ -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))

Expand Down
48 changes: 1 addition & 47 deletions 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")
Expand Down Expand Up @@ -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`."
18 changes: 8 additions & 10 deletions src/makielayout/blocks.jl
Expand Up @@ -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
Expand Down Expand Up @@ -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}()
Expand All @@ -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 ?
Expand All @@ -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)
Expand Down Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions src/makielayout/blocks/axis3d.jl
Expand Up @@ -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])
Expand Down Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion src/makielayout/lineaxis.jl
Expand Up @@ -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
Expand Down
13 changes: 0 additions & 13 deletions src/makielayout/precompile.jl

This file was deleted.