-
Notifications
You must be signed in to change notification settings - Fork 0
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
base: master
Are you sure you want to change the base?
Conversation
ext/PlotsGRExt.jl
Outdated
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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[JuliaFormatter] reported by reviewdog 🐶
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 |
src/Annotations.jl
Outdated
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! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[JuliaFormatter] reported by reviewdog 🐶
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
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} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[JuliaFormatter] reported by reviewdog 🐶
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
const _haligns = :hcenter, :left, :right | ||
const _valigns = :vcenter, :top, :bottom |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[JuliaFormatter] reported by reviewdog 🐶
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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[JuliaFormatter] reported by reviewdog 🐶
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
|
||
# ----------------------------------------------------------------------- | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[JuliaFormatter] reported by reviewdog 🐶
@@ -0,0 +1,15 @@ | |||
module Surfaces | |||
|
|||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[JuliaFormatter] reported by reviewdog 🐶
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} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[JuliaFormatter] reported by reviewdog 🐶
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) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[JuliaFormatter] reported by reviewdog 🐶
src/Axes.jl
Outdated
attr!(Axis([sp], attr), args...; kw...) | ||
end | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[JuliaFormatter] reported by reviewdog 🐶
src/Axes.jl
Outdated
Base.setindex!(axis::Axis, v, k::Symbol) = (axis.plotattributes[k] = v) | ||
Base.get(axis::Axis, k::Symbol, v) = get(axis.plotattributes, k, v) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[JuliaFormatter] reported by reviewdog 🐶
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 | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[JuliaFormatter] reported by reviewdog 🐶
src/Axes.jl
Outdated
axis.plotattributes[:optimized_ticks] | ||
end | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[JuliaFormatter] reported by reviewdog 🐶
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} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[JuliaFormatter] reported by reviewdog 🐶
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) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[JuliaFormatter] reported by reviewdog 🐶
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 | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[JuliaFormatter] reported by reviewdog 🐶
src/args.jl
Outdated
|
||
# 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 | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[JuliaFormatter] reported by reviewdog 🐶
# 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) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[JuliaFormatter] reported by reviewdog 🐶
src/args.jl
Outdated
|
||
_replace_linewidth(plotattributes) | ||
plotattributes | ||
end | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[JuliaFormatter] reported by reviewdog 🐶
ext/PlotsGRExt.jl
Outdated
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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[JuliaFormatter] reported by reviewdog 🐶
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], | ||
) | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[JuliaFormatter] reported by reviewdog 🐶
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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[JuliaFormatter] reported by reviewdog 🐶
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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[JuliaFormatter] reported by reviewdog 🐶
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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[JuliaFormatter] reported by reviewdog 🐶
const MM_PER_PX = MM_PER_INCH / PX_PER_INCH | |
const MM_PER_PX = MM_PER_INCH / PX_PER_INCH |
src/PlotsPlots.jl
Outdated
module PlotsPlots | ||
|
||
export Plot, PlotOrSubplot, _update_plot_args, plottitlefont, ignorenan_extrema | ||
import Plots: Plots, AbstractPlot, AbstractBackend, DefaultsDict, Series, Axis, Subplot, AbstractLayout, RecipesPipeline, _subplot_defaults |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[JuliaFormatter] reported by reviewdog 🐶
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 |
src/PlotsPlots.jl
Outdated
|
||
# --------------------------------------------------------------- | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[JuliaFormatter] reported by reviewdog 🐶
src/args.jl
Outdated
function color_or_nothing!(plotattributes, k::Symbol) | ||
plotattributes[k] = (v = plotattributes[k]) === :match ? v : plot_color(v) | ||
nothing | ||
end | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[JuliaFormatter] reported by reviewdog 🐶
src/args.jl
Outdated
# 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 | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[JuliaFormatter] reported by reviewdog 🐶
# 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) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[JuliaFormatter] reported by reviewdog 🐶
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, | |
) |
src/PlotsPlots.jl
Outdated
|
||
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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[JuliaFormatter] reported by reviewdog 🐶
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...) | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[JuliaFormatter] reported by reviewdog 🐶
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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[JuliaFormatter] reported by reviewdog 🐶
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
data = plotattributes[ | ||
letter | ||
] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[JuliaFormatter] reported by reviewdog 🐶
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) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[JuliaFormatter] reported by reviewdog 🐶
src/args.jl
Outdated
end | ||
reset_axis_defaults_byletter!() | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[JuliaFormatter] reported by reviewdog 🐶
const _all_args = | ||
union(_lettered_all_axis_args, _all_subplot_args, _all_series_args, _all_plot_args) | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[JuliaFormatter] reported by reviewdog 🐶
src/args.jl
Outdated
|
||
_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 | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[JuliaFormatter] reported by reviewdog 🐶
_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
|
||
# ------------------------------------------------------- | ||
# operate on individual series | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[JuliaFormatter] reported by reviewdog 🐶
# ------------------------------------------------------- | |
# 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] | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[JuliaFormatter] reported by reviewdog 🐶
Description
Attribution