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

factor backends into extensions #12

Draft
wants to merge 20 commits into
base: master
Choose a base branch
from
Draft

factor backends into extensions #12

wants to merge 20 commits into from

Conversation

BeastyBlacksmith
Copy link
Owner

Description

Attribution

Comment on lines 5 to 6
import Plots: Plots, Plot, Subplot, Axis, Series, Shape, Font, GRBackend, PlotText, Arrow, EachAnn
import Plots: _display, _show, closeall, get_size, _cycle, get_ticks, is_horizontal, tickfont, get_thickness_scaling, plot_color, colorbartitlefont, text, bbox, left, right, bottom, top, hascolorbar, plotarea, legendfont, series_list, should_add_to_legend, get_aspect_ratio, ispolar, is3d, axis_limits, needs_any_3d_axes, _logScales, axis_drawing_info, get_attr_symbol, coords, ok, axes_letters, reverse_if, _debug, get_colorgradient, handle_surface, series_annotations_shapes!, get_clims, series_segments, get_linecolor, get_linewidth, get_linestyle, get_linealpha, colorbar_style, _guess_best_legend_position, isortho, isautop, axis_drawing_info_3d, sort_3d_axes, _as_gradient, heatmap_edges, is_uniformly_spaced, cbar_gradient, get_fillalpha, _has_ticks, shape_data, get_fillcolor, get_fillstyle
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[JuliaFormatter] reported by reviewdog 🐶

Suggested change
import Plots: Plots, Plot, Subplot, Axis, Series, Shape, Font, GRBackend, PlotText, Arrow, EachAnn
import Plots: _display, _show, closeall, get_size, _cycle, get_ticks, is_horizontal, tickfont, get_thickness_scaling, plot_color, colorbartitlefont, text, bbox, left, right, bottom, top, hascolorbar, plotarea, legendfont, series_list, should_add_to_legend, get_aspect_ratio, ispolar, is3d, axis_limits, needs_any_3d_axes, _logScales, axis_drawing_info, get_attr_symbol, coords, ok, axes_letters, reverse_if, _debug, get_colorgradient, handle_surface, series_annotations_shapes!, get_clims, series_segments, get_linecolor, get_linewidth, get_linestyle, get_linealpha, colorbar_style, _guess_best_legend_position, isortho, isautop, axis_drawing_info_3d, sort_3d_axes, _as_gradient, heatmap_edges, is_uniformly_spaced, cbar_gradient, get_fillalpha, _has_ticks, shape_data, get_fillcolor, get_fillstyle
import Plots:
Plots, Plot, Subplot, Axis, Series, Shape, Font, GRBackend, PlotText, Arrow, EachAnn
import Plots:
_display,
_show,
closeall,
get_size,
_cycle,
get_ticks,
is_horizontal,
tickfont,
get_thickness_scaling,
plot_color,
colorbartitlefont,
text,
bbox,
left,
right,
bottom,
top,
hascolorbar,
plotarea,
legendfont,
series_list,
should_add_to_legend,
get_aspect_ratio,
ispolar,
is3d,
axis_limits,
needs_any_3d_axes,
_logScales,
axis_drawing_info,
get_attr_symbol,
coords,
ok,
axes_letters,
reverse_if,
_debug,
get_colorgradient,
handle_surface,
series_annotations_shapes!,
get_clims,
series_segments,
get_linecolor,
get_linewidth,
get_linestyle,
get_linealpha,
colorbar_style,
_guess_best_legend_position,
isortho,
isautop,
axis_drawing_info_3d,
sort_3d_axes,
_as_gradient,
heatmap_edges,
is_uniformly_spaced,
cbar_gradient,
get_fillalpha,
_has_ticks,
shape_data,
get_fillcolor,
get_fillstyle

using ..Plots.Shapes: Shape
using ..Plots: Series, Subplot, TimeType, Length

export EachAnn, series_annotations, series_annotations_shapes!, process_annotation, locate_annotation, annotations, assign_annotation_coord!
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[JuliaFormatter] reported by reviewdog 🐶

Suggested change
export EachAnn, series_annotations, series_annotations_shapes!, process_annotation, locate_annotation, annotations, assign_annotation_coord!
export EachAnn,
series_annotations,
series_annotations_shapes!,
process_annotation,
locate_annotation,
annotations,
assign_annotation_coord!

src/Commons.jl Outdated
Comment on lines 7 to 12
const AVec = AbstractVector
const AMat = AbstractMatrix
const KW = Dict{Symbol,Any}
const AKW = AbstractDict{Symbol,Any}
const TicksArgs =
Union{AVec{T},Tuple{AVec{T},AVec{S}},Symbol} where {T<:Real,S<:AbstractString}
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[JuliaFormatter] reported by reviewdog 🐶

Suggested change
const AVec = AbstractVector
const AMat = AbstractMatrix
const KW = Dict{Symbol,Any}
const AKW = AbstractDict{Symbol,Any}
const TicksArgs =
Union{AVec{T},Tuple{AVec{T},AVec{S}},Symbol} where {T<:Real,S<:AbstractString}
const AVec = AbstractVector
const AMat = AbstractMatrix
const KW = Dict{Symbol,Any}
const AKW = AbstractDict{Symbol,Any}
const TicksArgs = Union{AVec{T},Tuple{AVec{T},AVec{S}},Symbol} where {T<:Real,S<:AbstractString}

src/Commons.jl Outdated
Comment on lines 18 to 19
const _haligns = :hcenter, :left, :right
const _valigns = :vcenter, :top, :bottom
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[JuliaFormatter] reported by reviewdog 🐶

Suggested change
const _haligns = :hcenter, :left, :right
const _valigns = :vcenter, :top, :bottom
const _haligns = :hcenter, :left, :right
const _valigns = :vcenter, :top, :bottom

src/Shapes.jl Outdated
using ..Plots.Commons
import ..RecipesPipeline

export shape, partialcircle, weave, makestar, makeshape, makecross, from_polar, makearrowhead, center, scale!, scale, translate, translate!, rotate, roatate!, shape_data
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[JuliaFormatter] reported by reviewdog 🐶

Suggested change
export shape, partialcircle, weave, makestar, makeshape, makecross, from_polar, makearrowhead, center, scale!, scale, translate, translate!, rotate, roatate!, shape_data
export shape,
partialcircle,
weave,
makestar,
makeshape,
makecross,
from_polar,
makearrowhead,
center,
scale!,
scale,
translate,
translate!,
rotate,
roatate!,
shape_data

src/Strokes.jl Outdated

# -----------------------------------------------------------------------


Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[JuliaFormatter] reported by reviewdog 🐶

Suggested change

@@ -0,0 +1,15 @@
module Surfaces


Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[JuliaFormatter] reported by reviewdog 🐶

Suggested change

src/types.jl Outdated
const KW = Dict{Symbol,Any}
const AKW = AbstractDict{Symbol,Any}
const TicksArgs =
Union{AVec{T},Tuple{AVec{T},AVec{S}},Symbol} where {T<:Real,S<:AbstractString}

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[JuliaFormatter] reported by reviewdog 🐶

Suggested change

src/utils.jl Outdated
inch2mm(inches::Real) = float(inches * MM_PER_INCH)
mm2inch(mm::Real) = float(mm / MM_PER_INCH)
px2mm(px::Real) = float(px * MM_PER_PX)
mm2px(mm::Real) = float(mm / MM_PER_PX)

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[JuliaFormatter] reported by reviewdog 🐶

Suggested change

src/Axes.jl Outdated
attr!(Axis([sp], attr), args...; kw...)
end


Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[JuliaFormatter] reported by reviewdog 🐶

Suggested change

src/Axes.jl Outdated
Comment on lines 41 to 42
Base.setindex!(axis::Axis, v, k::Symbol) = (axis.plotattributes[k] = v)
Base.get(axis::Axis, k::Symbol, v) = get(axis.plotattributes, k, v)
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[JuliaFormatter] reported by reviewdog 🐶

Suggested change
Base.setindex!(axis::Axis, v, k::Symbol) = (axis.plotattributes[k] = v)
Base.get(axis::Axis, k::Symbol, v) = get(axis.plotattributes, k, v)
Base.setindex!(axis::Axis, v, k::Symbol) = (axis.plotattributes[k] = v)
Base.get(axis::Axis, k::Symbol, v) = get(axis.plotattributes, k, v)

src/Axes.jl Outdated
nothing
end


Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[JuliaFormatter] reported by reviewdog 🐶

Suggested change

src/Axes.jl Outdated
axis.plotattributes[:optimized_ticks]
end


Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[JuliaFormatter] reported by reviewdog 🐶

Suggested change

src/Axes.jl Outdated
Plots.expand_extrema!(axis::Axis, ::Nothing) = axis[:extrema]
Plots.expand_extrema!(axis::Axis, ::Bool) = axis[:extrema]

function Plots.expand_extrema!(axis::Axis, v::Tuple{MIN,MAX}) where {MIN<:Number,MAX<:Number}
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[JuliaFormatter] reported by reviewdog 🐶

Suggested change
function Plots.expand_extrema!(axis::Axis, v::Tuple{MIN,MAX}) where {MIN<:Number,MAX<:Number}
function Plots.expand_extrema!(
axis::Axis,
v::Tuple{MIN,MAX},
) where {MIN<:Number,MAX<:Number}

src/args.jl Outdated
Base.get(plt::Plot, k::Symbol, v) = get(plt.attr, k, v)
Base.get(sp::Subplot, k::Symbol, v) = get(sp.attr, k, v)
Base.get(axis::Axis, k::Symbol, v) = get(axis.plotattributes, k, v)
Base.get(series::Series, k::Symbol, v) = get(series.plotattributes, k, v)

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[JuliaFormatter] reported by reviewdog 🐶

Suggested change

src/args.jl Outdated
plt[:background_color] = plot_color(plt.attr[:background_color])
plt[:foreground_color] = fg_color(plt.attr)
color_or_nothing!(plt.attr, :background_color_outside)
end

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[JuliaFormatter] reported by reviewdog 🐶

Suggested change

src/args.jl Outdated
Comment on lines 1751 to 1752

# then get those args that were passed with a leading letter: `xlabel = "X"`
lk = get_attr_symbol(letter, k)

if haskey(plotattributes_in, lk)
kw[k] = slice_arg(plotattributes_in[lk], subplot_index)
end
end

# update the axis
attr!(axis; kw...)
nothing
end

function _update_axis_colors(axis::Axis)
# # update the axis colors
color_or_nothing!(axis.plotattributes, :foreground_color_axis)
color_or_nothing!(axis.plotattributes, :foreground_color_border)
color_or_nothing!(axis.plotattributes, :foreground_color_guide)
color_or_nothing!(axis.plotattributes, :foreground_color_text)
color_or_nothing!(axis.plotattributes, :foreground_color_grid)
color_or_nothing!(axis.plotattributes, :foreground_color_minor_grid)
nothing
end

function _update_axis_links(plt::Plot, axis::Axis, letter::Symbol)
# handle linking here. if we're passed a list of
# other subplots to link to, link them together
(link = axis[:link]) |> isempty && return
for other_sp in link
link_axes!(axis, get_axis(get_subplot(plt, other_sp), letter))
end
axis.plotattributes[:link] = []
nothing
end

# update a subplots args and axes
function _update_subplot_args(
plt::Plot,
sp::Subplot,
plotattributes_in,
subplot_index::Int,
remove_pair::Bool,
)
anns = RecipesPipeline.pop_kw!(sp.attr, :annotations)

# grab those args which apply to this subplot
for k in keys(_subplot_defaults)
slice_arg!(plotattributes_in, sp.attr, k, subplot_index, remove_pair)
end

_update_subplot_colors(sp)
_update_margins(sp)
colorbar_update_keys =
(:clims, :colorbar, :seriestype, :marker_z, :line_z, :fill_z, :colorbar_entry)
if any(haskey.(Ref(plotattributes_in), colorbar_update_keys))
_update_subplot_colorbars(sp)
end

lims_warned = false
for letter in (:x, :y, :z)
_update_axis(plt, sp, plotattributes_in, letter, subplot_index)
lk = get_attr_symbol(letter, :lims)

# warn against using `Range` in x,y,z lims
if !lims_warned &&
haskey(plotattributes_in, lk) &&
plotattributes_in[lk] isa AbstractRange
@warn "lims should be a Tuple, not $(typeof(plotattributes_in[lk]))."
lims_warned = true
end
end

_update_subplot_periphery(sp, anns)
end

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[JuliaFormatter] reported by reviewdog 🐶

Suggested change
# then get those args that were passed with a leading letter: `xlabel = "X"`
lk = get_attr_symbol(letter, k)
if haskey(plotattributes_in, lk)
kw[k] = slice_arg(plotattributes_in[lk], subplot_index)
end
end
# update the axis
attr!(axis; kw...)
nothing
end
function _update_axis_colors(axis::Axis)
# # update the axis colors
color_or_nothing!(axis.plotattributes, :foreground_color_axis)
color_or_nothing!(axis.plotattributes, :foreground_color_border)
color_or_nothing!(axis.plotattributes, :foreground_color_guide)
color_or_nothing!(axis.plotattributes, :foreground_color_text)
color_or_nothing!(axis.plotattributes, :foreground_color_grid)
color_or_nothing!(axis.plotattributes, :foreground_color_minor_grid)
nothing
end
function _update_axis_links(plt::Plot, axis::Axis, letter::Symbol)
# handle linking here. if we're passed a list of
# other subplots to link to, link them together
(link = axis[:link]) |> isempty && return
for other_sp in link
link_axes!(axis, get_axis(get_subplot(plt, other_sp), letter))
end
axis.plotattributes[:link] = []
nothing
end
# update a subplots args and axes
function _update_subplot_args(
plt::Plot,
sp::Subplot,
plotattributes_in,
subplot_index::Int,
remove_pair::Bool,
)
anns = RecipesPipeline.pop_kw!(sp.attr, :annotations)
# grab those args which apply to this subplot
for k in keys(_subplot_defaults)
slice_arg!(plotattributes_in, sp.attr, k, subplot_index, remove_pair)
end
_update_subplot_colors(sp)
_update_margins(sp)
colorbar_update_keys =
(:clims, :colorbar, :seriestype, :marker_z, :line_z, :fill_z, :colorbar_entry)
if any(haskey.(Ref(plotattributes_in), colorbar_update_keys))
_update_subplot_colorbars(sp)
end
lims_warned = false
for letter in (:x, :y, :z)
_update_axis(plt, sp, plotattributes_in, letter, subplot_index)
lk = get_attr_symbol(letter, :lims)
# warn against using `Range` in x,y,z lims
if !lims_warned &&
haskey(plotattributes_in, lk) &&
plotattributes_in[lk] isa AbstractRange
@warn "lims should be a Tuple, not $(typeof(plotattributes_in[lk]))."
lims_warned = true
end
end
_update_subplot_periphery(sp, anns)
end

src/args.jl Outdated
end |> plot_color

get_series_color(c::AbstractArray, sp::Subplot, n::Int, seriestype) =
map(x -> get_series_color(x, sp, n, seriestype), c)

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[JuliaFormatter] reported by reviewdog 🐶

Suggested change

src/args.jl Outdated

_replace_linewidth(plotattributes)
plotattributes
end

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[JuliaFormatter] reported by reviewdog 🐶

Suggested change

import GR
import Plots: DEFAULT_LINEWIDTH
import Plots: Plots, Shape, Font, GRBackend, PlotText, Arrow, EachAnn
import Plots: _display, _show, closeall, get_size, _cycle, get_ticks, is_horizontal, get_thickness_scaling, plot_color, text, bbox, left, right, bottom, top, hascolorbar, plotarea, series_list, should_add_to_legend, get_aspect_ratio, ispolar, is3d, axis_limits, needs_any_3d_axes, _logScales, axis_drawing_info, get_attr_symbol, coords, ok, axes_letters, reverse_if, _debug, get_colorgradient, handle_surface, series_annotations_shapes!, get_clims, series_segments, get_linecolor, get_linewidth, get_linestyle, get_linealpha, colorbar_style, _guess_best_legend_position, isortho, isautop, axis_drawing_info_3d, sort_3d_axes, _as_gradient, heatmap_edges, is_uniformly_spaced, cbar_gradient, get_fillalpha, _has_ticks, shape_data, get_fillcolor, get_fillstyle
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[JuliaFormatter] reported by reviewdog 🐶

Suggested change
import Plots: _display, _show, closeall, get_size, _cycle, get_ticks, is_horizontal, get_thickness_scaling, plot_color, text, bbox, left, right, bottom, top, hascolorbar, plotarea, series_list, should_add_to_legend, get_aspect_ratio, ispolar, is3d, axis_limits, needs_any_3d_axes, _logScales, axis_drawing_info, get_attr_symbol, coords, ok, axes_letters, reverse_if, _debug, get_colorgradient, handle_surface, series_annotations_shapes!, get_clims, series_segments, get_linecolor, get_linewidth, get_linestyle, get_linealpha, colorbar_style, _guess_best_legend_position, isortho, isautop, axis_drawing_info_3d, sort_3d_axes, _as_gradient, heatmap_edges, is_uniformly_spaced, cbar_gradient, get_fillalpha, _has_ticks, shape_data, get_fillcolor, get_fillstyle
import Plots:
_display,
_show,
closeall,
get_size,
_cycle,
get_ticks,
is_horizontal,
get_thickness_scaling,
plot_color,
text,
bbox,
left,
right,
bottom,
top,
hascolorbar,
plotarea,
series_list,
should_add_to_legend,
get_aspect_ratio,
ispolar,
is3d,
axis_limits,
needs_any_3d_axes,
_logScales,
axis_drawing_info,
get_attr_symbol,
coords,
ok,
axes_letters,
reverse_if,
_debug,
get_colorgradient,
handle_surface,
series_annotations_shapes!,
get_clims,
series_segments,
get_linecolor,
get_linewidth,
get_linestyle,
get_linealpha,
colorbar_style,
_guess_best_legend_position,
isortho,
isautop,
axis_drawing_info_3d,
sort_3d_axes,
_as_gradient,
heatmap_edges,
is_uniformly_spaced,
cbar_gradient,
get_fillalpha,
_has_ticks,
shape_data,
get_fillcolor,
get_fillstyle

src/Axes.jl Outdated
color = ax[:guidefontcolor],
)


Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[JuliaFormatter] reported by reviewdog 🐶

Suggested change

src/Commons.jl Outdated
const AKW = AbstractDict{Symbol,Any}
const TicksArgs =
Union{AVec{T},Tuple{AVec{T},AVec{S}},Symbol} where {T<:Real,S<:AbstractString}
const PLOTS_SEED = 1234
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[JuliaFormatter] reported by reviewdog 🐶

Suggested change
const PLOTS_SEED = 1234
const PLOTS_SEED = 1234

src/Commons.jl Outdated
Union{AVec{T},Tuple{AVec{T},AVec{S}},Symbol} where {T<:Real,S<:AbstractString}
const PLOTS_SEED = 1234
const PX_PER_INCH = 100
const DPI = PX_PER_INCH
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[JuliaFormatter] reported by reviewdog 🐶

Suggested change
const DPI = PX_PER_INCH
const DPI = PX_PER_INCH

src/Commons.jl Outdated
const PX_PER_INCH = 100
const DPI = PX_PER_INCH
const MM_PER_INCH = 25.4
const MM_PER_PX = MM_PER_INCH / PX_PER_INCH
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[JuliaFormatter] reported by reviewdog 🐶

Suggested change
const MM_PER_PX = MM_PER_INCH / PX_PER_INCH
const MM_PER_PX = MM_PER_INCH / PX_PER_INCH

module PlotsPlots

export Plot, PlotOrSubplot, _update_plot_args, plottitlefont, ignorenan_extrema
import Plots: Plots, AbstractPlot, AbstractBackend, DefaultsDict, Series, Axis, Subplot, AbstractLayout, RecipesPipeline, _subplot_defaults
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[JuliaFormatter] reported by reviewdog 🐶

Suggested change
import Plots: Plots, AbstractPlot, AbstractBackend, DefaultsDict, Series, Axis, Subplot, AbstractLayout, RecipesPipeline, _subplot_defaults
import Plots:
Plots,
AbstractPlot,
AbstractBackend,
DefaultsDict,
Series,
Axis,
Subplot,
AbstractLayout,
RecipesPipeline,
_subplot_defaults


# ---------------------------------------------------------------


Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[JuliaFormatter] reported by reviewdog 🐶

Suggested change

src/args.jl Outdated
function color_or_nothing!(plotattributes, k::Symbol)
plotattributes[k] = (v = plotattributes[k]) === :match ? v : plot_color(v)
nothing
end

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[JuliaFormatter] reported by reviewdog 🐶

Suggested change

src/args.jl Outdated
Comment on lines 1737 to 1738
# convert a bool into auto or nothing
if isa(axis[:ticks], Bool)
axis[:ticks] = axis[:ticks] ? :auto : nothing
end

_update_axis_colors(axis)
_update_axis_links(plt, axis, letter)
nothing
end

function _update_axis(
axis::Axis,
plotattributes_in::AKW,
letter::Symbol,
subplot_index::Int,
)
# build the KW of arguments from the letter version (i.e. xticks --> ticks)
kw = KW()
for k in _all_axis_args
# first get the args without the letter: `tickfont = font(10)`
# note: we don't pop because we want this to apply to all axes! (delete after all have finished)
if haskey(plotattributes_in, k)
kw[k] = slice_arg(plotattributes_in[k], subplot_index)
end

# then get those args that were passed with a leading letter: `xlabel = "X"`
lk = get_attr_symbol(letter, k)

if haskey(plotattributes_in, lk)
kw[k] = slice_arg(plotattributes_in[lk], subplot_index)
end
end

# update the axis
attr!(axis; kw...)
nothing
end

function _update_axis_colors(axis::Axis)
# # update the axis colors
color_or_nothing!(axis.plotattributes, :foreground_color_axis)
color_or_nothing!(axis.plotattributes, :foreground_color_border)
color_or_nothing!(axis.plotattributes, :foreground_color_guide)
color_or_nothing!(axis.plotattributes, :foreground_color_text)
color_or_nothing!(axis.plotattributes, :foreground_color_grid)
color_or_nothing!(axis.plotattributes, :foreground_color_minor_grid)
nothing
end

function _update_axis_links(plt::Plot, axis::Axis, letter::Symbol)
# handle linking here. if we're passed a list of
# other subplots to link to, link them together
(link = axis[:link]) |> isempty && return
for other_sp in link
link_axes!(axis, get_axis(get_subplot(plt, other_sp), letter))
end
axis.plotattributes[:link] = []
nothing
end

# update a subplots args and axes
function _update_subplot_args(
plt::Plot,
sp::Subplot,
plotattributes_in,
subplot_index::Int,
remove_pair::Bool,
)
anns = RecipesPipeline.pop_kw!(sp.attr, :annotations)

# grab those args which apply to this subplot
for k in keys(_subplot_defaults)
slice_arg!(plotattributes_in, sp.attr, k, subplot_index, remove_pair)
end

_update_subplot_colors(sp)
_update_margins(sp)
colorbar_update_keys =
(:clims, :colorbar, :seriestype, :marker_z, :line_z, :fill_z, :colorbar_entry)
if any(haskey.(Ref(plotattributes_in), colorbar_update_keys))
_update_subplot_colorbars(sp)
end

lims_warned = false
for letter in (:x, :y, :z)
_update_axis(plt, sp, plotattributes_in, letter, subplot_index)
lk = get_attr_symbol(letter, :lims)

# warn against using `Range` in x,y,z lims
if !lims_warned &&
haskey(plotattributes_in, lk) &&
plotattributes_in[lk] isa AbstractRange
@warn "lims should be a Tuple, not $(typeof(plotattributes_in[lk]))."
lims_warned = true
end
end

_update_subplot_periphery(sp, anns)
end

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[JuliaFormatter] reported by reviewdog 🐶

Suggested change
# handle legend/colorbar
sp.attr[:legend_position] = convertLegendValue(sp.attr[:legend_position])
sp.attr[:colorbar] = convertLegendValue(sp.attr[:colorbar])
if sp.attr[:colorbar] === :legend
sp.attr[:colorbar] = sp.attr[:legend_position]
end
nothing
end
function _update_subplot_colors(sp::Subplot)
# background colors
color_or_nothing!(sp.attr, :background_color_subplot)
sp.attr[:color_palette] = get_color_palette(sp.attr[:color_palette], 30)
color_or_nothing!(sp.attr, :legend_background_color)
color_or_nothing!(sp.attr, :background_color_inside)
# foreground colors
color_or_nothing!(sp.attr, :foreground_color_subplot)
color_or_nothing!(sp.attr, :legend_foreground_color)
color_or_nothing!(sp.attr, :foreground_color_title)
nothing
end
_update_margins(sp::Subplot) =
for sym in (:margin, :left_margin, :top_margin, :right_margin, :bottom_margin)
if (margin = get(sp.attr, sym, nothing)) isa Tuple
# transform e.g. (1, :mm) => 1 * Plots.mm
sp.attr[sym] = margin[1] * getfield(@__MODULE__, margin[2])
end
end
function _update_axis(
plt::Plot,
sp::Subplot,
plotattributes_in::AKW,
letter::Symbol,
subplot_index::Int,
)
# get (maybe initialize) the axis
axis = get_axis(sp, letter)
_update_axis(axis, plotattributes_in, letter, subplot_index)
# convert a bool into auto or nothing
if isa(axis[:ticks], Bool)
axis[:ticks] = axis[:ticks] ? :auto : nothing
end
_update_axis_colors(axis)
_update_axis_links(plt, axis, letter)
nothing
end
function _update_axis(
axis::Axis,
plotattributes_in::AKW,
letter::Symbol,
subplot_index::Int,
)
# build the KW of arguments from the letter version (i.e. xticks --> ticks)
kw = KW()
for k in _all_axis_args
# first get the args without the letter: `tickfont = font(10)`
# note: we don't pop because we want this to apply to all axes! (delete after all have finished)
if haskey(plotattributes_in, k)
kw[k] = slice_arg(plotattributes_in[k], subplot_index)
end
# then get those args that were passed with a leading letter: `xlabel = "X"`
lk = get_attr_symbol(letter, k)
if haskey(plotattributes_in, lk)
kw[k] = slice_arg(plotattributes_in[lk], subplot_index)
end
end
# update the axis
attr!(axis; kw...)
nothing
end
function _update_axis_colors(axis::Axis)
# # update the axis colors
color_or_nothing!(axis.plotattributes, :foreground_color_axis)
color_or_nothing!(axis.plotattributes, :foreground_color_border)
color_or_nothing!(axis.plotattributes, :foreground_color_guide)
color_or_nothing!(axis.plotattributes, :foreground_color_text)
color_or_nothing!(axis.plotattributes, :foreground_color_grid)
color_or_nothing!(axis.plotattributes, :foreground_color_minor_grid)
nothing
end
function _update_axis_links(plt::Plot, axis::Axis, letter::Symbol)
# handle linking here. if we're passed a list of
# other subplots to link to, link them together
(link = axis[:link]) |> isempty && return
for other_sp in link
link_axes!(axis, get_axis(get_subplot(plt, other_sp), letter))
end
axis.plotattributes[:link] = []
nothing
end
# update a subplots args and axes
function _update_subplot_args(
plt::Plot,
sp::Subplot,
plotattributes_in,
subplot_index::Int,
remove_pair::Bool,
)
anns = RecipesPipeline.pop_kw!(sp.attr, :annotations)
# grab those args which apply to this subplot
for k in keys(_subplot_defaults)
slice_arg!(plotattributes_in, sp.attr, k, subplot_index, remove_pair)
end
_update_subplot_colors(sp)
_update_margins(sp)
colorbar_update_keys =
(:clims, :colorbar, :seriestype, :marker_z, :line_z, :fill_z, :colorbar_entry)
if any(haskey.(Ref(plotattributes_in), colorbar_update_keys))
_update_subplot_colorbars(sp)
end
lims_warned = false
for letter in (:x, :y, :z)
_update_axis(plt, sp, plotattributes_in, letter, subplot_index)
lk = get_attr_symbol(letter, :lims)
# warn against using `Range` in x,y,z lims
if !lims_warned &&
haskey(plotattributes_in, lk) &&
plotattributes_in[lk] isa AbstractRange
@warn "lims should be a Tuple, not $(typeof(plotattributes_in[lk]))."
lims_warned = true
end
end
_update_subplot_periphery(sp, anns)
end

src/plot.jl Outdated
@@ -181,7 +182,7 @@ function plot!(

# first apply any args for the subplots
for (idx, sp) in enumerate(plt.subplots)
_update_subplot_args(plt, sp, idx == ttl_idx ? KW() : plotattributes, idx, false)
PlotsPlots._update_subplot_args(plt, sp, idx == ttl_idx ? KW() : plotattributes, idx, false)
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[JuliaFormatter] reported by reviewdog 🐶

Suggested change
PlotsPlots._update_subplot_args(plt, sp, idx == ttl_idx ? KW() : plotattributes, idx, false)
PlotsPlots._update_subplot_args(
plt,
sp,
idx == ttl_idx ? KW() : plotattributes,
idx,
false,
)


export Plot, PlotOrSubplot, _update_plot_args, plottitlefont, ignorenan_extrema
import Plots.Axes: _update_axis
using Plots: Plots, AbstractPlot, AbstractBackend, DefaultsDict, Series, Axis, Subplot, AbstractLayout, RecipesPipeline, _subplot_defaults
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[JuliaFormatter] reported by reviewdog 🐶

Suggested change
using Plots: Plots, AbstractPlot, AbstractBackend, DefaultsDict, Series, Axis, Subplot, AbstractLayout, RecipesPipeline, _subplot_defaults
using Plots:
Plots,
AbstractPlot,
AbstractBackend,
DefaultsDict,
Series,
Axis,
Subplot,
AbstractLayout,
RecipesPipeline,
_subplot_defaults

src/Series.jl Outdated
Base.push!(series::Series, args...) = extend_series!(series, args...)
Base.append!(series::Series, args...) = extend_series!(series, args...)


Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[JuliaFormatter] reported by reviewdog 🐶

Suggested change

src/Subplots.jl Outdated
module Subplots

export Subplot, colorbartitlefont, legendfont, legendtitlefont, titlefont
using Plots: Plots, Series, AbstractBackend, AbstractLayout, BoundingBox, DefaultsDict, _subplot_defaults, convert_legend_value
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[JuliaFormatter] reported by reviewdog 🐶

Suggested change
using Plots: Plots, Series, AbstractBackend, AbstractLayout, BoundingBox, DefaultsDict, _subplot_defaults, convert_legend_value
using Plots:
Plots,
Series,
AbstractBackend,
AbstractLayout,
BoundingBox,
DefaultsDict,
_subplot_defaults,
convert_legend_value

src/Subplots.jl Outdated
Comment on lines 182 to 184
data = plotattributes[
letter
]
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[JuliaFormatter] reported by reviewdog 🐶

Suggested change
data = plotattributes[
letter
]
data = plotattributes[letter]

src/args.jl Outdated
const _allScales = [:identity, :ln, :log2, :log10, :asinh, :sqrt]
const _logScales = [:ln, :log2, :log10]
const _logScaleBases = Dict(:ln => ℯ, :log2 => 2.0, :log10 => 10.0)
const _scaleAliases = Dict{Symbol,Symbol}(:none => :identity, :log => :log10)

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[JuliaFormatter] reported by reviewdog 🐶

Suggested change

src/args.jl Outdated
end
reset_axis_defaults_byletter!()


Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[JuliaFormatter] reported by reviewdog 🐶

Suggested change

const _all_args =
union(_lettered_all_axis_args, _all_subplot_args, _all_series_args, _all_plot_args)


Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[JuliaFormatter] reported by reviewdog 🐶

Suggested change

src/args.jl Outdated
Comment on lines 1742 to 1743

_update_axis_colors(axis)
_update_axis_links(plt, axis, letter)
nothing
end

function _update_axis(
axis::Axis,
plotattributes_in::AKW,
letter::Symbol,
subplot_index::Int,
)
# build the KW of arguments from the letter version (i.e. xticks --> ticks)
kw = KW()
for k in _all_axis_args
# first get the args without the letter: `tickfont = font(10)`
# note: we don't pop because we want this to apply to all axes! (delete after all have finished)
if haskey(plotattributes_in, k)
kw[k] = slice_arg(plotattributes_in[k], subplot_index)
end

# then get those args that were passed with a leading letter: `xlabel = "X"`
lk = get_attr_symbol(letter, k)

if haskey(plotattributes_in, lk)
kw[k] = slice_arg(plotattributes_in[lk], subplot_index)
end
end

# update the axis
attr!(axis; kw...)
nothing
end

function _update_axis_colors(axis::Axis)
# # update the axis colors
color_or_nothing!(axis.plotattributes, :foreground_color_axis)
color_or_nothing!(axis.plotattributes, :foreground_color_border)
color_or_nothing!(axis.plotattributes, :foreground_color_guide)
color_or_nothing!(axis.plotattributes, :foreground_color_text)
color_or_nothing!(axis.plotattributes, :foreground_color_grid)
color_or_nothing!(axis.plotattributes, :foreground_color_minor_grid)
nothing
end

function _update_axis_links(plt::Plot, axis::Axis, letter::Symbol)
# handle linking here. if we're passed a list of
# other subplots to link to, link them together
(link = axis[:link]) |> isempty && return
for other_sp in link
link_axes!(axis, get_axis(get_subplot(plt, other_sp), letter))
end
axis.plotattributes[:link] = []
nothing
end

# update a subplots args and axes
function _update_subplot_args(
plt::Plot,
sp::Subplot,
plotattributes_in,
subplot_index::Int,
remove_pair::Bool,
)
anns = RecipesPipeline.pop_kw!(sp.attr, :annotations)

# grab those args which apply to this subplot
for k in keys(_subplot_defaults)
slice_arg!(plotattributes_in, sp.attr, k, subplot_index, remove_pair)
end

_update_subplot_colors(sp)
_update_margins(sp)
colorbar_update_keys =
(:clims, :colorbar, :seriestype, :marker_z, :line_z, :fill_z, :colorbar_entry)
if any(haskey.(Ref(plotattributes_in), colorbar_update_keys))
_update_subplot_colorbars(sp)
end

lims_warned = false
for letter in (:x, :y, :z)
_update_axis(plt, sp, plotattributes_in, letter, subplot_index)
lk = get_attr_symbol(letter, :lims)

# warn against using `Range` in x,y,z lims
if !lims_warned &&
haskey(plotattributes_in, lk) &&
plotattributes_in[lk] isa AbstractRange
@warn "lims should be a Tuple, not $(typeof(plotattributes_in[lk]))."
lims_warned = true
end
end

_update_subplot_periphery(sp, anns)
end

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[JuliaFormatter] reported by reviewdog 🐶

Suggested change
_update_axis_colors(axis)
_update_axis_links(plt, axis, letter)
nothing
end
function _update_axis(
axis::Axis,
plotattributes_in::AKW,
letter::Symbol,
subplot_index::Int,
)
# build the KW of arguments from the letter version (i.e. xticks --> ticks)
kw = KW()
for k in _all_axis_args
# first get the args without the letter: `tickfont = font(10)`
# note: we don't pop because we want this to apply to all axes! (delete after all have finished)
if haskey(plotattributes_in, k)
kw[k] = slice_arg(plotattributes_in[k], subplot_index)
end
# then get those args that were passed with a leading letter: `xlabel = "X"`
lk = get_attr_symbol(letter, k)
if haskey(plotattributes_in, lk)
kw[k] = slice_arg(plotattributes_in[lk], subplot_index)
end
end
# update the axis
attr!(axis; kw...)
nothing
end
function _update_axis_colors(axis::Axis)
# # update the axis colors
color_or_nothing!(axis.plotattributes, :foreground_color_axis)
color_or_nothing!(axis.plotattributes, :foreground_color_border)
color_or_nothing!(axis.plotattributes, :foreground_color_guide)
color_or_nothing!(axis.plotattributes, :foreground_color_text)
color_or_nothing!(axis.plotattributes, :foreground_color_grid)
color_or_nothing!(axis.plotattributes, :foreground_color_minor_grid)
nothing
end
function _update_axis_links(plt::Plot, axis::Axis, letter::Symbol)
# handle linking here. if we're passed a list of
# other subplots to link to, link them together
(link = axis[:link]) |> isempty && return
for other_sp in link
link_axes!(axis, get_axis(get_subplot(plt, other_sp), letter))
end
axis.plotattributes[:link] = []
nothing
end
# update a subplots args and axes
function _update_subplot_args(
plt::Plot,
sp::Subplot,
plotattributes_in,
subplot_index::Int,
remove_pair::Bool,
)
anns = RecipesPipeline.pop_kw!(sp.attr, :annotations)
# grab those args which apply to this subplot
for k in keys(_subplot_defaults)
slice_arg!(plotattributes_in, sp.attr, k, subplot_index, remove_pair)
end
_update_subplot_colors(sp)
_update_margins(sp)
colorbar_update_keys =
(:clims, :colorbar, :seriestype, :marker_z, :line_z, :fill_z, :colorbar_entry)
if any(haskey.(Ref(plotattributes_in), colorbar_update_keys))
_update_subplot_colorbars(sp)
end
lims_warned = false
for letter in (:x, :y, :z)
_update_axis(plt, sp, plotattributes_in, letter, subplot_index)
lk = get_attr_symbol(letter, :lims)
# warn against using `Range` in x,y,z lims
if !lims_warned &&
haskey(plotattributes_in, lk) &&
plotattributes_in[lk] isa AbstractRange
@warn "lims should be a Tuple, not $(typeof(plotattributes_in[lk]))."
lims_warned = true
end
end
_update_subplot_periphery(sp, anns)
end

src/utils.jl Outdated
Comment on lines 771 to 772

# -------------------------------------------------------
# operate on individual series

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[JuliaFormatter] reported by reviewdog 🐶

Suggested change
# -------------------------------------------------------
# operate on individual series

src/utils.jl Outdated
const _attrsymbolcache = Dict{Symbol,Dict{Symbol,Symbol}}()

get_attr_symbol(letter::Symbol, keyword::String) = get_attr_symbol(letter, Symbol(keyword))
get_attr_symbol(letter::Symbol, keyword::Symbol) = _attrsymbolcache[letter][keyword]

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[JuliaFormatter] reported by reviewdog 🐶

Suggested change

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant