From 0f11ad09f6287601f7d44d39baddd7068e872ad2 Mon Sep 17 00:00:00 2001 From: Adam Beckmeyer Date: Wed, 17 Apr 2019 22:42:00 -0400 Subject: [PATCH 1/3] Remove unnecessary splatting from internal interfaces This gives a marginal improvement on speed and memory use during first plot, but the biggest benefit is that it makes the code easier to read and the profiling significantly easier to grok. --- src/Gadfly.jl | 26 +++++++++++--------------- src/aesthetics.jl | 2 +- src/geom/subplot.jl | 8 ++++---- src/guide.jl | 2 +- src/scale.jl | 27 +++++++++++++++------------ 5 files changed, 32 insertions(+), 33 deletions(-) diff --git a/src/Gadfly.jl b/src/Gadfly.jl index b517bc2af..6803719d8 100755 --- a/src/Gadfly.jl +++ b/src/Gadfly.jl @@ -653,7 +653,7 @@ function render_prepare(plot::Plot) # I. Scales layer_aess = Scale.apply_scales(IterTools.distinct(values(scales)), - datas..., subplot_datas...) + vcat(datas, subplot_datas)) # set defaults for key titles keyvars = [:color, :shape] @@ -692,7 +692,7 @@ function render_prepare(plot::Plot) end # IIb. Plot-wise Statistics - plot_aes = concat(layer_aess...) + plot_aes = concat(layer_aess) statistics = collect(statistics) Stat.apply_statistics(statistics, scales, coord, plot_aes) @@ -809,28 +809,24 @@ function render_prepared(plot::Plot, # IV. Geometries themes = Theme[layer.theme === nothing ? plot.theme : layer.theme for layer in plot.layers] - zips = trim_zip(plot.layers, layer_aess, - layer_subplot_aess, - layer_subplot_datas, - themes) - - compose!(plot_context, - [compose(context(order=layer.order), render(layer.geom, theme, aes, - subplot_aes, subplot_data, - scales)) - for (layer, aes, subplot_aes, subplot_data, theme) in zips]...) + zips = trim_zip(plot.layers, layer_aess, layer_subplot_aess, + layer_subplot_datas, themes) + for (layer, aes, subplot_aes, subplot_data, theme) in zips + r = render(layer.geom, theme, aes, subplot_aes, subplot_data, scales) + compose!(plot_context, (context(order=layer.order), r)) + end#for # V. Guides - guide_contexts = Any[] + guide_contexts = Guide.PositionedGuide[] for guide in guides guide_context = render(guide, plot.theme, plot_aes, dynamic) - if guide_context != nothing + if !isnothing(guide_context) append!(guide_contexts, guide_context) end end tbl = Guide.layout_guides(plot_context, coord, - plot.theme, guide_contexts...) + plot.theme, guide_contexts) if table_only return tbl end diff --git a/src/aesthetics.jl b/src/aesthetics.jl index 0ac515231..5dcb69b98 100755 --- a/src/aesthetics.jl +++ b/src/aesthetics.jl @@ -226,7 +226,7 @@ json(a::Aesthetics) = join([string(a, ":", json(getfield(a, var))) for var in ae # Returns: # A new Aesthetics instance with vectors concatenated. # -function concat(aess::Aesthetics...) +function concat(aess) cataes = Aesthetics() for aes in aess for var in valid_aesthetics diff --git a/src/geom/subplot.jl b/src/geom/subplot.jl index 08bc4b113..bca1f4638 100644 --- a/src/geom/subplot.jl +++ b/src/geom/subplot.jl @@ -181,7 +181,7 @@ function render(geom::SubplotGrid, theme::Gadfly.Theme, Gadfly.Aesthetics[layer_aes_grid[k][i, j] for k in 1:length(geom.layers)], Gadfly.Data[layer_data_grid[k][i, j] - for k in 1:length(geom.layers)]...) + for k in 1:length(geom.layers)]) for (k, stats) in enumerate(layer_stats) Stat.apply_statistics(stats, scales, coord, layer_aes_grid[k][i, j]) @@ -190,7 +190,7 @@ function render(geom::SubplotGrid, theme::Gadfly.Theme, # apply geom-wide statistics geom_aes = Gadfly.concat([layer_aes_grid[k][i,j] - for i in 1:n, j in 1:m, k in 1:length(geom.layers)]...) + for i in 1:n, j in 1:m, k in 1:length(geom.layers)]) geom_stats = Gadfly.StatisticElement[] has_stat_xticks = false @@ -220,7 +220,7 @@ function render(geom::SubplotGrid, theme::Gadfly.Theme, if geom.free_x_axis for j in 1:m col_aes = Gadfly.concat([layer_aes_grid[k][i, j] - for i in 1:n, k in 1:length(geom.layers)]...) + for i in 1:n, k in 1:length(geom.layers)]) Gadfly.inherit!(col_aes, geom_aes) Stat.apply_statistic(Stat.xticks(), scales, coord, col_aes) @@ -231,7 +231,7 @@ function render(geom::SubplotGrid, theme::Gadfly.Theme, if geom.free_y_axis for i in 1:n row_aes = Gadfly.concat([layer_aes_grid[k][i, j] - for j in 1:m, k in 1:length(geom.layers)]...) + for j in 1:m, k in 1:length(geom.layers)]) Gadfly.inherit!(row_aes, geom_aes) Stat.apply_statistic(Stat.yticks(), scales, coord, row_aes) diff --git a/src/guide.jl b/src/guide.jl index 5e13b7c4c..400dca599 100644 --- a/src/guide.jl +++ b/src/guide.jl @@ -1129,7 +1129,7 @@ end function layout_guides(plot_context::Context, coord::Gadfly.CoordinateElement, theme::Gadfly.Theme, - positioned_guides::PositionedGuide...) + positioned_guides::Vector{PositionedGuide}) # Organize guides by position guides = DefaultDict(() -> (Tuple{Vector{Context}, Int})[]) for positioned_guide in positioned_guides diff --git a/src/scale.jl b/src/scale.jl index 6972591c4..be582ab93 100644 --- a/src/scale.jl +++ b/src/scale.jl @@ -19,9 +19,9 @@ include("color_misc.jl") iscategorical(scales::Dict{Symbol, Gadfly.ScaleElement}, var::Symbol) = haskey(scales, var) && isa(scales[var], DiscreteScale) -function apply_scales(scales, aess::Vector{Gadfly.Aesthetics}, datas::Gadfly.Data...) +function apply_scales(scales, aess::Vector{Gadfly.Aesthetics}, datas::Vector{Gadfly.Data}) for scale in scales - apply_scale(scale, aess, datas...) + apply_scale(scale, aess, datas) end for (aes, data) in zip(aess, datas) @@ -29,9 +29,9 @@ function apply_scales(scales, aess::Vector{Gadfly.Aesthetics}, datas::Gadfly.Dat end end -function apply_scales(scales, datas::Gadfly.Data...) +function apply_scales(scales, datas::Vector{Gadfly.Data}) aess = Gadfly.Aesthetics[Gadfly.Aesthetics() for _ in datas] - apply_scales(scales, aess, datas...) + apply_scales(scales, aess, datas) aess end @@ -178,9 +178,12 @@ alpha_continuous(; minvalue=0.0, maxvalue=1.0, labels=nothing, format=nothing, m ContinuousScale([:alpha], identity_transform, minvalue=minvalue, maxvalue=maxvalue, labels=labels, format=format, minticks=minticks, maxticks=maxticks, scalable=scalable) +# Need to wrap Gadfly.Data in array for apply_scale methods +apply_scale(scale::Gadfly.ScaleElement, aess::Vector{Gadfly.Aesthetics}, data::Gadfly.Data) = + apply_scale(scale, aess, Gadfly.Data[data]) function apply_scale(scale::ContinuousScale, - aess::Vector{Gadfly.Aesthetics}, datas::Gadfly.Data...) + aess::Vector{Gadfly.Aesthetics}, datas::Vector{Gadfly.Data}) for (aes, data) in zip(aess, datas) for var in scale.vars vals = getfield(data, var) @@ -363,7 +366,7 @@ alpha_discrete(; labels=nothing, levels=nothing, order=nothing) = DiscreteScale([:linestyle], labels=labels, levels=levels, order=order) -function apply_scale(scale::DiscreteScale, aess::Vector{Gadfly.Aesthetics}, datas::Gadfly.Data...) +function apply_scale(scale::DiscreteScale, aess::Vector{Gadfly.Aesthetics}, datas::Vector{Gadfly.Data}) for (aes, data) in zip(aess, datas) for var in scale.vars label_var = Symbol(var, "_label") @@ -412,7 +415,7 @@ const color_none = NoneColorScale element_aesthetics(scale::NoneColorScale) = [:color] function apply_scale(scale::NoneColorScale, - aess::Vector{Gadfly.Aesthetics}, datas::Gadfly.Data...) + aess::Vector{Gadfly.Aesthetics}, datas::Vector{Gadfly.Data}) for aes in aess aes.color = nothing end @@ -430,7 +433,7 @@ const color_identity = IdentityColorScale element_aesthetics(scale::IdentityColorScale) = [:color] function apply_scale(scale::IdentityColorScale, - aess::Vector{Gadfly.Aesthetics}, datas::Gadfly.Data...) + aess::Vector{Gadfly.Aesthetics}, datas::Vector{Gadfly.Data}) for (aes, data) in zip(aess, datas) data.color === nothing && continue aes.color = discretize_make_ia(data.color) @@ -513,7 +516,7 @@ end @deprecate discrete_color_manual(colors...; levels=nothing, order=nothing) color_discrete_manual(colors...; levels=levels, order=order) function apply_scale(scale::DiscreteColorScale, - aess::Vector{Gadfly.Aesthetics}, datas::Gadfly.Data...) + aess::Vector{Gadfly.Aesthetics}, datas::Vector{Gadfly.Data}) levelset = OrderedSet() for (aes, data) in zip(aess, datas) data.color === nothing && continue @@ -621,7 +624,7 @@ const color_continuous_gradient = color_continuous ### WHY HAVE THIS ALIAS? @deprecate continuous_color(;minvalue=nothing, maxvalue=nothing) color_continuous(;minvalue=nothing, maxvalue=nothing) function apply_scale(scale::ContinuousColorScale, - aess::Vector{Gadfly.Aesthetics}, datas::Gadfly.Data...) + aess::Vector{Gadfly.Aesthetics}, datas::Vector{Gadfly.Data}) cdata = skipmissing(Iterators.flatten(i.color for i in datas if i.color != nothing)) if !isempty(cdata) cmin, cmax = extrema(cdata) @@ -693,7 +696,7 @@ struct LabelScale <: Gadfly.ScaleElement end function apply_scale(scale::LabelScale, - aess::Vector{Gadfly.Aesthetics}, datas::Gadfly.Data...) + aess::Vector{Gadfly.Aesthetics}, datas::Vector{Gadfly.Data}) for (aes, data) in zip(aess, datas) data.label === nothing && continue aes.label = discretize(data.label) @@ -733,7 +736,7 @@ end element_aesthetics(scale::IdentityScale) = [scale.var] function apply_scale(scale::IdentityScale, - aess::Vector{Gadfly.Aesthetics}, datas::Gadfly.Data...) + aess::Vector{Gadfly.Aesthetics}, datas::Vector{Gadfly.Data}) for (aes, data) in zip(aess, datas) getfield(data, scale.var) === nothing && continue setfield!(aes, scale.var, getfield(data, scale.var)) From bf5bd2ec7b6615bf15bbf5e96abad1f7e3db9965 Mon Sep 17 00:00:00 2001 From: Adam Beckmeyer Date: Thu, 18 Apr 2019 21:33:15 -0400 Subject: [PATCH 2/3] Compare nothing by type rather than by value Comparing nothing by value (==, =!) rather than by identity (===, !==) or by type (isnothing) can have negative consequences on code speed. This commit changes all nothing comparisons to use the isnothing utility added in Julia 1.1 and Compat 2.1. --- Project.toml | 2 +- src/Gadfly.jl | 35 +++++----- src/aesthetics.jl | 55 +++++++-------- src/coord.jl | 48 +++++++------- src/data.jl | 4 +- src/dataframes.jl | 6 +- src/geom/bar.jl | 4 +- src/geom/boxplot.jl | 4 +- src/geom/errorbar.jl | 4 +- src/geom/hvabline.jl | 30 ++++----- src/geom/label.jl | 4 +- src/geom/point.jl | 2 +- src/geom/rectbin.jl | 4 +- src/geom/segment.jl | 2 +- src/geom/subplot.jl | 14 ++-- src/geometry.jl | 2 +- src/guide.jl | 66 +++++++++--------- src/guide/keys.jl | 10 +-- src/mapping.jl | 6 +- src/misc.jl | 5 +- src/scale.jl | 46 ++++++------- src/statistics.jl | 155 ++++++++++++++++++++++--------------------- src/ticks.jl | 4 +- src/varset.jl | 2 +- 24 files changed, 255 insertions(+), 259 deletions(-) diff --git a/Project.toml b/Project.toml index ce84fa85c..b7663da4d 100644 --- a/Project.toml +++ b/Project.toml @@ -34,7 +34,7 @@ StatsBase = "2913bbd2-ae8a-5f71-8c99-4fb6c76f3a91" [compat] CategoricalArrays = "0.5" Colors = "0.9" -Compat = "2" +Compat = "2.1" Compose = "0.7" Contour = "0.5" CoupledFields = "0.1" diff --git a/src/Gadfly.jl b/src/Gadfly.jl index 6803719d8..c935e13e4 100755 --- a/src/Gadfly.jl +++ b/src/Gadfly.jl @@ -388,14 +388,14 @@ function render_prepare(plot::Plot) # they are missing. datas = Array{Data}(undef, length(plot.layers)) for (i, layer) in enumerate(plot.layers) - if layer.data_source === nothing && isempty(layer.mapping) + if isnothing(layer.data_source) && isempty(layer.mapping) layer.data_source = plot.data_source layer.mapping = plot.mapping datas[i] = plot.data else datas[i] = Data() - if layer.data_source === nothing + if isnothing(layer.data_source) layer.data_source = plot.data_source end @@ -416,7 +416,7 @@ function render_prepare(plot::Plot) if isa(layer.geom, Geom.SubplotGeometry) for subplot_layer in layers(layer.geom) subplot_data = Data() - if subplot_layer.data_source === nothing + if isnothing(subplot_layer.data_source) subplot_layer.data_source = layer.data_source end @@ -434,7 +434,7 @@ function render_prepare(plot::Plot) coord = plot.coord for layer in plot.layers coord_type = element_coordinate_type(layer.geom) - if coord === nothing + if isnothing(coord) coord = coord_type() elseif typeof(coord) != coord_type error("Plot uses multiple coordinates: $(typeof(coord)) and $(coord_type)") @@ -503,7 +503,7 @@ function render_prepare(plot::Plot) unscaled_aesthetics = setdiff(used_aesthetics, scaled_aesthetics) - _theme(plt, lyr) = lyr.theme == nothing ? plt.theme : lyr.theme + _theme(plt, lyr) = isnothing(lyr.theme) ? plt.theme : lyr.theme # Add default scales for statistics. layer_stats_with_theme = map(plot.layers, layer_stats) do l, stats @@ -532,17 +532,17 @@ function render_prepare(plot::Plot) in(var, mapped_aesthetics) || continue var_data = getfield(plot.data, var) - if var_data == nothing + if isnothing(var_data) for data in datas var_layer_data = getfield(data, var) - if var_layer_data != nothing + if !isnothing(var_layer_data) var_data = var_layer_data break end end end - var_data == nothing && continue + isnothing(var_data) && continue t = classify_data(var_data) if scale_exists(t, var) @@ -560,7 +560,7 @@ function render_prepare(plot::Plot) t = :categorical for data in Iterators.flatten((datas, subplot_datas)) val = getfield(data, var) - if val != nothing && val != :categorical + if !isnothing(val) && val != :categorical t = classify_data(val) end end @@ -659,24 +659,27 @@ function render_prepare(plot::Plot) keyvars = [:color, :shape] for (i, layer) in enumerate(plot.layers) for kv in keyvars - fflag = (getfield(layer_aess[i], Symbol(kv,"_key_title")) == nothing) && haskey(layer.mapping, kv) && !isa(layer.mapping[kv], AbstractArray) + fflag = (isnothing(getfield(layer_aess[i], Symbol(kv,"_key_title")))) && + haskey(layer.mapping, kv) && + !isa(layer.mapping[kv], AbstractArray) fflag && setfield!(layer_aess[i], Symbol(kv,"_key_title"), string(layer.mapping[kv])) end end for kv in keyvars - fflag = (getfield(layer_aess[1], Symbol(kv,"_key_title")) == nothing) && haskey(plot.mapping, kv) && !isa(plot.mapping[kv], AbstractArray) + fflag = (isnothing(getfield(layer_aess[1], Symbol(kv,"_key_title")))) && + haskey(plot.mapping, kv) && !isa(plot.mapping[kv], AbstractArray) fflag && setfield!(layer_aess[1], Symbol(kv,"_key_title"), string(plot.mapping[kv])) end # Auto-update color scale if shape==color catdatas = vcat(datas, subplot_datas) shapev = getfield.(catdatas, :shape) - di = (shapev.!=nothing) .& (shapev.== getfield.(catdatas, :color)) + di = (!isnothing).(shapev) .& (shapev.== getfield.(catdatas, :color)) supress_colorkey = false for (aes, data) in zip(layer_aess[di], catdatas[di]) - aes.shape_key_title==nothing && (aes.shape_key_title=aes.color_key_title="Shape") + isnothing(aes.shape_key_title) && (aes.shape_key_title=aes.color_key_title="Shape") colorf = scales[:color].f scales[:color] = Scale.color_discrete(colorf, levels=scales[:shape].levels, order=scales[:shape].order) Scale.apply_scale(scales[:color], [aes], Gadfly.Data(color=getfield(data,:color)) ) @@ -713,7 +716,7 @@ function render_prepare(plot::Plot) if !supress_keys for (KT, kv) in zip(keytypes, keyvars) - fflag = !all([getfield(aes, kv)==nothing for aes in [plot_aes, layer_aess...]]) + fflag = !all([isnothing(getfield(aes, kv)) for aes in [plot_aes, layer_aess...]]) fflag && !in(KT, explicit_guide_types) && push!(guides, KT()) end end @@ -756,7 +759,7 @@ function render(plot::Plot) ctx = pad_inner(root_context, plot.theme.plot_padding...) - if plot.theme.background_color != nothing + if !isnothing(plot.theme.background_color) compose!(ctx, (context(order=-1000000), fill(plot.theme.background_color), stroke(nothing), rectangle())) @@ -807,7 +810,7 @@ function render_prepared(plot::Plot, layer_aess), scales) # IV. Geometries - themes = Theme[layer.theme === nothing ? plot.theme : layer.theme + themes = Theme[isnothing(layer.theme) ? plot.theme : layer.theme for layer in plot.layers] zips = trim_zip(plot.layers, layer_aess, layer_subplot_aess, layer_subplot_datas, themes) diff --git a/src/aesthetics.jl b/src/aesthetics.jl index 5dcb69b98..ba5532f7b 100755 --- a/src/aesthetics.jl +++ b/src/aesthetics.jl @@ -102,7 +102,7 @@ function show(io::IO, data::Aesthetics) print(io, "Aesthetics(") for name in valid_aesthetics val = getfield(data, name) - if !ismissing(val) && val != nothing + if !ismissing(val) && !isnothing(val) print(io, "\n ", string(name), "=") show(io, getfield(data, name)) end @@ -140,7 +140,7 @@ getindex(aes::Aesthetics, i::Integer, j::AbstractString) = getfield(aes, Symbol( function defined_aesthetics(aes::Aesthetics) vars = Set{Symbol}() for name in valid_aesthetics - getfield(aes, name) === nothing || push!(vars, name) + isnothing(getfield(aes, name)) || push!(vars, name) end vars end @@ -172,7 +172,7 @@ function assert_aesthetics_undefined(who::AbstractString, aes::Aesthetics, vars: end function assert_aesthetics_equal_length(who::AbstractString, aes::Aesthetics, vars::Symbol...) - defined_vars = Compat.Iterators.filter(var -> !(getfield(aes, var) === nothing), vars) + defined_vars = Compat.Iterators.filter(var -> !isnothing(getfield(aes, var)), vars) if !isempty(defined_vars) n = length(getfield(aes, first(defined_vars))) @@ -198,7 +198,7 @@ end # function update!(a::Aesthetics, b::Aesthetics) for name in valid_aesthetics - issomething(getfield(b, name)) && setfield(a, name, getfield(b, name)) + !isnothing(getfield(b, name)) && setfield(a, name, getfield(b, name)) end nothing end @@ -230,22 +230,17 @@ function concat(aess) cataes = Aesthetics() for aes in aess for var in valid_aesthetics - if var in [:xviewmin, :yviewmin] - mu, mv = getfield(cataes, var), getfield(aes, var) - setfield!(cataes, var, - mu === nothing ? mv : - mv == nothing ? mu : - min(mu, mv)) - elseif var in [:xviewmax, :yviewmax] - mu, mv = getfield(cataes, var), getfield(aes, var) - setfield!(cataes, var, - mu === nothing ? mv : - mv == nothing ? mu : - max(mu, mv)) + mu, mv = getfield(cataes, var), getfield(aes, var) + isviewmin = var in (:xviewmin, :yviewmin) + isviewmax = var in (:xviewmax, :yviewmax) + mumv = if isviewmin + isnothing(mu) ? mv : isnothing(mv) ? mu : min(mu, mv) + elseif isviewmax + isnothing(mu) ? mv : isnothing(mv) ? mu : max(mu, mv) else - setfield!(cataes, var, - cat_aes_var!(getfield(cataes, var), getfield(aes, var))) - end + cat_aes_var!(mu, mv) + end#if + setfield!(cataes, var, mumv) end end cataes @@ -313,13 +308,13 @@ end # function by_xy_group(aes::T, xgroup, ygroup, num_xgroups, num_ygroups) where T <: Union{Data, Aesthetics} - @assert xgroup === nothing || ygroup === nothing || length(xgroup) == length(ygroup) + @assert isnothing(xgroup) || isnothing(ygroup) || length(xgroup) == length(ygroup) n = num_ygroups m = num_xgroups - xrefs = xgroup === nothing ? [1] : xgroup - yrefs = ygroup === nothing ? [1] : ygroup + xrefs = isnothing(xgroup) ? [1] : xgroup + yrefs = isnothing(ygroup) ? [1] : ygroup aes_grid = Array{T}(undef, n, m) staging = Array{AbstractArray}(undef, n, m) @@ -327,7 +322,7 @@ function by_xy_group(aes::T, xgroup, ygroup, aes_grid[i, j] = T() end - xgroup === nothing && ygroup === nothing && return aes_grid + isnothing(xgroup) && isnothing(ygroup) && return aes_grid function make_pooled_array(::Type{IndirectArray{T,N,A,V}}, arr::AbstractArray) where {T,N,A,V} uarr = unique(arr) @@ -350,8 +345,8 @@ function by_xy_group(aes::T, xgroup, ygroup, vals = getfield(aes, var) if typeof(vals) <: AbstractArray - if xgroup !== nothing && length(vals) !== length(xgroup) || - ygroup !== nothing && length(vals) !== length(ygroup) + if !isnothing(xgroup) && length(vals) !== length(xgroup) || + !isnothing(ygroup) && length(vals) !== length(ygroup) continue end @@ -405,12 +400,12 @@ function inherit!(a::Aesthetics, b::Aesthetics; bval = getfield(b, field) if field in clobber_set setfield!(a, field, bval) - elseif aval === missing || aval === nothing || aval === string || aval == showoff + elseif aval === missing || isnothing(aval) || aval === string || aval === showoff setfield!(a, field, bval) - elseif field == :xviewmin || field == :yviewmin - bval != nothing && (aval == nothing || aval > bval) && setfield!(a, field, bval) - elseif field == :xviewmax || field == :yviewmax - bval != nothing && (aval == nothing || aval < bval) && setfield!(a, field, bval) + elseif field in (:xviewmin, :yviewmin) && !isnothing(bval) + (isnothing(aval) || aval > bval) && setfield!(a, field, bval) + elseif field in (:xviewmax, :yviewmax) && !isnothing(bval) + (isnothing(aval) || aval < bval) && setfield!(a, field, bval) elseif typeof(aval) <: Dict && typeof(bval) <: Dict merge!(aval, getfield(b, field)) end diff --git a/src/coord.jl b/src/coord.jl index 5358591a1..d70837ff1 100644 --- a/src/coord.jl +++ b/src/coord.jl @@ -67,7 +67,7 @@ function first_concrete_aesthetic_value(aess::Vector{Gadfly.Aesthetics}, vars::V for var in vars for aes in aess vals = getfield(aes, var) - vals === nothing && continue + Gadfly.isnothing(vals) && continue if !isa(vals, AbstractArray) vals = [vals] @@ -106,7 +106,7 @@ function aesthetics_type(aess::Vector{Gadfly.Aesthetics}, for var in vars for aes in aess vals = getfield(aes, var) - vals === nothing && continue + Gadfly.isnothing(vals) && continue if var == :outliers if !isempty(vals) @@ -153,11 +153,11 @@ function apply_coordinate(coord::Cartesian, aess::Vector{Gadfly.Aesthetics}, xmin = xmax = first_concrete_aesthetic_value(aess, coord.xvars) - if xmin != nothing + if !Gadfly.isnothing(xmin) for var in coord.xvars for aes in aess vals = getfield(aes, var) - vals === nothing && continue + Gadfly.isnothing(vals) && continue if !isa(vals, AbstractArray) vals = [vals] @@ -169,11 +169,11 @@ function apply_coordinate(coord::Cartesian, aess::Vector{Gadfly.Aesthetics}, end ymin = ymax = first_concrete_aesthetic_value(aess, coord.yvars) - if ymin != nothing + if !Gadfly.isnothing(ymin) for var in coord.yvars for aes in aess vals = getfield(aes, var) - vals === nothing && continue + Gadfly.isnothing(vals) && continue # Outliers is an odd aesthetic that needs special treatment. if var == :outliers @@ -196,40 +196,40 @@ function apply_coordinate(coord::Cartesian, aess::Vector{Gadfly.Aesthetics}, # viewmin/max that is set explicitly should override min/max for aes in aess - if aes.xviewmin != nothing - xviewmin = xviewmin === nothing ? aes.xviewmin : min(xviewmin, aes.xviewmin) + if !Gadfly.isnothing(aes.xviewmin) + xviewmin = Gadfly.isnothing(xviewmin) ? aes.xviewmin : min(xviewmin, aes.xviewmin) end - if aes.xviewmax != nothing - xviewmax = xviewmax === nothing ? aes.xviewmax : max(xviewmax, aes.xviewmax) + if !Gadfly.isnothing(aes.xviewmax) + xviewmax = Gadfly.isnothing(xviewmax) ? aes.xviewmax : max(xviewmax, aes.xviewmax) end - if aes.yviewmin != nothing - yviewmin = yviewmin === nothing ? aes.yviewmin : min(yviewmin, aes.yviewmin) + if !Gadfly.isnothing(aes.yviewmin) + yviewmin = Gadfly.isnothing(yviewmin) ? aes.yviewmin : min(yviewmin, aes.yviewmin) end - if aes.yviewmax != nothing - yviewmax = yviewmax === nothing ? aes.yviewmax : max(yviewmax, aes.yviewmax) + if !Gadfly.isnothing(aes.yviewmax) + yviewmax = Gadfly.isnothing(yviewmax) ? aes.yviewmax : max(yviewmax, aes.yviewmax) end end - xmax = xviewmax === nothing ? xmax : max(xmax, xviewmax) - xmin = xviewmin === nothing ? xmin : min(xmin, xviewmin) - ymax = yviewmax === nothing ? ymax : max(ymax, yviewmax) - ymin = yviewmin === nothing ? ymin : min(ymin, yviewmin) + xmax = Gadfly.isnothing(xviewmax) ? xmax : max(xmax, xviewmax) + xmin = Gadfly.isnothing(xviewmin) ? xmin : min(xmin, xviewmin) + ymax = Gadfly.isnothing(yviewmax) ? ymax : max(ymax, yviewmax) + ymin = Gadfly.isnothing(yviewmin) ? ymin : min(ymin, yviewmin) # Hard limits set in Coord should override everything else - xmin = coord.xmin === nothing ? xmin : coord.xmin - xmax = coord.xmax === nothing ? xmax : coord.xmax - ymin = coord.ymin === nothing ? ymin : coord.ymin - ymax = coord.ymax === nothing ? ymax : coord.ymax + xmin = Gadfly.isnothing(coord.xmin) ? xmin : coord.xmin + xmax = Gadfly.isnothing(coord.xmax) ? xmax : coord.xmax + ymin = Gadfly.isnothing(coord.ymin) ? ymin : coord.ymin + ymax = Gadfly.isnothing(coord.ymax) ? ymax : coord.ymax - if xmin === nothing || !isfinite(xmin) + if Gadfly.isnothing(xmin) || !isfinite(xmin) xmin = 0.0 xmax = 1.0 end - if ymin === nothing || !isfinite(ymin) + if Gadfly.isnothing(ymin) || !isfinite(ymin) ymin = 0.0 ymax = 1.0 end diff --git a/src/data.jl b/src/data.jl index d8334b016..21fa375c7 100644 --- a/src/data.jl +++ b/src/data.jl @@ -62,7 +62,7 @@ function chain(ds::Data...) chained_data = Data() for name in data_fields vs = Any[getfield(d, name) for d in ds] - vs = Any[v for v in filter(issomething, vs)] + vs = Any[v for v in filter(!isnothing, vs)] if isempty(vs) setfield!(chained_data, name, nothing) else @@ -78,7 +78,7 @@ function show(io::IO, data::Data) maxlen = 0 print(io, "Data(") for name in data_fields - if getfield(data, name) != nothing + if !isnothing(getfield(data, name)) print(io, "\n ", string(name), "=") show(io, getfield(data, name)) end diff --git a/src/dataframes.jl b/src/dataframes.jl index 622237fd4..2a7c6ddf3 100644 --- a/src/dataframes.jl +++ b/src/dataframes.jl @@ -11,7 +11,7 @@ function meltdata(U::AbstractDataFrame, colgroups_::Vector{Col.GroupedColumn}) vm = um grouped_columns = Set{Symbol}() for colgroup in colgroups - if colgroup.columns===nothing # null => group all columns + if isnothing(colgroup.columns) # null => group all columns vm *= un grouped_columns = copy(allcolumns) else @@ -34,7 +34,7 @@ function meltdata(U::AbstractDataFrame, colgroups_::Vector{Col.GroupedColumn}) # allocate vectors for grouped columns for (j, colgroup) in enumerate(colgroups) - cols = colgroup.columns===nothing ? allcolumns : colgroup.columns + cols = isnothing(colgroup.columns) ? allcolumns : colgroup.columns # figure the grouped common column type firstcol = U[first(cols)] @@ -64,7 +64,7 @@ function meltdata(U::AbstractDataFrame, colgroups_::Vector{Col.GroupedColumn}) col_indicators = Array{Symbol}(undef, vm, length(colgroups)) row_indicators = Array{Int}(undef, vm, length(colgroups)) - colidxs = [colgroup.columns===nothing ? collect(allcolumns) : colgroup.columns + colidxs = [isnothing(colgroup.columns) ? collect(allcolumns) : colgroup.columns for colgroup in colgroups] vi = 1 diff --git a/src/geom/bar.jl b/src/geom/bar.jl index 697de3061..6348072c2 100644 --- a/src/geom/bar.jl +++ b/src/geom/bar.jl @@ -74,7 +74,7 @@ function render_bar(geom::BarGeometry, svgclass("geometry")) end - cs = aes.color === nothing ? theme.default_color : aes.color + cs = isnothing(aes.color) ? theme.default_color : aes.color compose!(ctx, fill(cs), svgclass("geometry")) if isa(theme.bar_highlight, Function) compose!(ctx, stroke(theme.bar_highlight(theme.default_color))) @@ -272,7 +272,7 @@ function render(geom::BarGeometry, theme::Gadfly.Theme, aes::Gadfly.Aesthetics) error("Orientation must be :horizontal or :vertical") end - if aes.color === nothing + if isnothing(aes.color) ctx = render_bar(geom, theme, aes, geom.orientation) elseif geom.position == :stack if geom.orientation == :horizontal diff --git a/src/geom/boxplot.jl b/src/geom/boxplot.jl index 0fc6222f2..f47cb55eb 100644 --- a/src/geom/boxplot.jl +++ b/src/geom/boxplot.jl @@ -123,7 +123,7 @@ function render(geom::BoxplotGeometry, theme::Gadfly.Theme, aes::Gadfly.Aestheti svgclass("geometry")) # Outliers - if !geom.suppress_outliers && aes.outliers != nothing && !isempty(aes.outliers) + if !geom.suppress_outliers && !isnothing(aes.outliers) && !isempty(aes.outliers) xys = collect(Iterators.flatten(zip(cycle([x]), ys, cycle([c])) for (x, ys, c) in zip(xs, aes.outliers, cs))) compose!(ctx, (context(), @@ -133,7 +133,7 @@ function render(geom::BoxplotGeometry, theme::Gadfly.Theme, aes::Gadfly.Aestheti end # Middle - if aes.middle != nothing + if !isnothing(aes.middle) compose!(ctx, ( context(order=1), Compose.line([[(x - fw/2, mid), (x + fw/2, mid)] diff --git a/src/geom/errorbar.jl b/src/geom/errorbar.jl index 65dafa47b..67ce96d30 100644 --- a/src/geom/errorbar.jl +++ b/src/geom/errorbar.jl @@ -110,7 +110,7 @@ function render(geom::YErrorBarGeometry, theme::Gadfly.Theme, aes::Gadfly.Aesthe stroke([theme.stroke_color(c) for c in aes.color]), linewidth(theme.line_width)) - (aes.color_key_continuous == true || aes.color == nothing) || compose!(ctx, + (aes.color_key_continuous == true || isnothing(aes.color)) || compose!(ctx, svgclass([svg_color_class_from_label(aes.color_label([c])[1]) for c in aes.color])) return ctx @@ -148,7 +148,7 @@ function render(geom::XErrorBarGeometry, theme::Gadfly.Theme, aes::Gadfly.Aesthe stroke([theme.stroke_color(c) for c in aes.color]), linewidth(theme.line_width)) - (aes.color_key_continuous == true || aes.color == nothing) || compose!(ctx, + (aes.color_key_continuous == true || isnothing(aes.color)) || compose!(ctx, svgclass([svg_color_class_from_label(aes.color_label([c])[1]) for c in aes.color])) diff --git a/src/geom/hvabline.jl b/src/geom/hvabline.jl index 70f5248a1..69fa4968f 100755 --- a/src/geom/hvabline.jl +++ b/src/geom/hvabline.jl @@ -18,7 +18,7 @@ struct HLineGeometry <: Gadfly.GeometryElement tag::Symbol HLineGeometry(color, size, style, tag) = - new(color === nothing ? nothing : Gadfly.parse_colorant(color), size, style, tag) + new(isnothing(color) ? nothing : Gadfly.parse_colorant(color), size, style, tag) end HLineGeometry(; color=nothing, size=nothing, style=nothing, tag=empty_tag) = HLineGeometry(color, size, style, tag) @@ -36,9 +36,9 @@ element_aesthetics(::HLineGeometry) = [:yintercept] function render(geom::HLineGeometry, theme::Gadfly.Theme, aes::Gadfly.Aesthetics) Gadfly.assert_aesthetics_defined("Geom.hline", aes, :yintercept) - color = geom.color === nothing ? theme.default_color : geom.color - size = geom.size === nothing ? theme.line_width : geom.size - style = geom.style === nothing ? theme.line_style[1] : geom.style + color = isnothing(geom.color) ? theme.default_color : geom.color + size = isnothing(geom.size) ? theme.line_width : geom.size + style = isnothing(geom.style) ? theme.line_style[1] : geom.style color = check_arguments(color, length(aes.yintercept)) size = check_arguments(size, length(aes.yintercept)) @@ -65,7 +65,7 @@ struct VLineGeometry <: Gadfly.GeometryElement tag::Symbol VLineGeometry(color, size, style, tag) = - new(color === nothing ? nothing : Gadfly.parse_colorant(color), size, style, tag) + new(isnothing(color) ? nothing : Gadfly.parse_colorant(color), size, style, tag) end VLineGeometry(; color=nothing, size=nothing, style=nothing, tag=empty_tag) = VLineGeometry(color, size, style, tag) @@ -83,9 +83,9 @@ element_aesthetics(::VLineGeometry) = [:xintercept] function render(geom::VLineGeometry, theme::Gadfly.Theme, aes::Gadfly.Aesthetics) Gadfly.assert_aesthetics_defined("Geom.vline", aes, :xintercept) - color = geom.color === nothing ? theme.default_color : geom.color - size = geom.size === nothing ? theme.line_width : geom.size - style = geom.style === nothing ? theme.line_style[1] : geom.style + color = isnothing(geom.color) ? theme.default_color : geom.color + size = isnothing(geom.size) ? theme.line_width : geom.size + style = isnothing(geom.style) ? theme.line_style[1] : geom.style color = check_arguments(color, length(aes.xintercept)) size = check_arguments(size, length(aes.xintercept)) @@ -112,7 +112,7 @@ struct ABLineGeometry <: Gadfly.GeometryElement tag::Symbol ABLineGeometry(color, size, style, tag) = - new(color === nothing ? nothing : Gadfly.parse_colorant(color), size, style, tag) + new(isnothing(color) ? nothing : Gadfly.parse_colorant(color), size, style, tag) end ABLineGeometry(; color=nothing, size=nothing, style=nothing, tag::Symbol=empty_tag) = ABLineGeometry(color, size, style, tag) @@ -131,19 +131,19 @@ const abline = ABLineGeometry element_aesthetics(geom::ABLineGeometry) = [:intercept, :slope] function render(geom::ABLineGeometry, theme::Gadfly.Theme, aes::Gadfly.Aesthetics) - if aes.intercept == nothing && aes.slope == nothing + if isnothing(aes.intercept) && isnothing(aes.slope) aes.intercept = [0] aes.slope = [1] - elseif aes.intercept == nothing + elseif isnothing(aes.intercept) aes.intercept = fill(0,length(aes.slope)) - elseif aes.slope == nothing + elseif isnothing(aes.slope) aes.slope = fill(1,length(aes.intercept)) end Gadfly.assert_aesthetics_equal_length("Geom.line", aes, element_aesthetics(geom)...) - color = geom.color === nothing ? theme.default_color : geom.color - size = geom.size === nothing ? theme.line_width : geom.size - style = geom.style === nothing ? theme.line_style[1] : geom.style + color = isnothing(geom.color) ? theme.default_color : geom.color + size = isnothing(geom.size) ? theme.line_width : geom.size + style = isnothing(geom.style) ? theme.line_style[1] : geom.style color = check_arguments(color, length(aes.intercept)) size = check_arguments(size, length(aes.intercept)) diff --git a/src/geom/label.jl b/src/geom/label.jl index a26ee82e7..48fca4d70 100644 --- a/src/geom/label.jl +++ b/src/geom/label.jl @@ -50,7 +50,7 @@ function deferred_label_context(geom::LabelGeometry, num_labels = length(aes.label) - if aes.size == nothing + if isnothing(aes.size) padding = fill(theme.point_size, num_labels) .+ theme.label_padding else padding = aes.size .+ theme.label_padding @@ -279,7 +279,7 @@ function render(geom::LabelGeometry, theme::Gadfly.Theme, aes::Gadfly.Aesthetics end hpos, vpos, xoff, yoff = label_layouts[geom.position] - if aes.size == nothing + if isnothing(aes.size) offsets = [(xoff*(theme.point_size + theme.label_padding), yoff*(theme.point_size + theme.label_padding))] else diff --git a/src/geom/point.jl b/src/geom/point.jl index dd35ab2a0..beabffa94 100644 --- a/src/geom/point.jl +++ b/src/geom/point.jl @@ -67,7 +67,7 @@ function render(geom::PointGeometry, theme::Gadfly.Theme, aes::Gadfly.Aesthetics for (x, y, color, size, shape, alpha) in Compose.cyclezip(aes.x, aes.y, aes.color, aes.size, aes.shape, aes_alpha) shapefun = typeof(shape) <: Function ? shape : theme.point_shapes[shape] sizeval = typeof(size) <: Int ? interpolate_size(size) : size - strokecolor = aes.color_key_continuous != nothing && aes.color_key_continuous ? + strokecolor = !isnothing(aes.color_key_continuous) && aes.color_key_continuous ? theme.continuous_highlight_color(color) : theme.discrete_highlight_color(color) class = svg_color_class_from_label(aes.color_label([color])[1]) diff --git a/src/geom/rectbin.jl b/src/geom/rectbin.jl index 9b64363ff..b998fac0f 100644 --- a/src/geom/rectbin.jl +++ b/src/geom/rectbin.jl @@ -94,14 +94,14 @@ function render(geom::RectangularBinGeometry, theme::Gadfly.Theme, aes::Gadfly.A allvisible = true for c in cs - if c == nothing + if isnothing(c) allvisible = false break end end if !allvisible - visibility = cs .!= nothing + visibility = (!isnothing).(cs) cs = cs[visibility] xmin = xmin[visibility] xmax = xmax[visibility] diff --git a/src/geom/segment.jl b/src/geom/segment.jl index 499763686..a7fc70ae7 100755 --- a/src/geom/segment.jl +++ b/src/geom/segment.jl @@ -82,7 +82,7 @@ function render(geom::SegmentGeometry, theme::Gadfly.Theme, aes::Gadfly.Aestheti if geom.arrow check = [aes.xviewmin, aes.xviewmax, aes.yviewmin, aes.yviewmax ] - if any( map(x -> x === nothing, check) ) + if any(map(isnothing, check)) error("For Geom.vector, Scale minvalue and maxvalue must be manually provided for both axes") end xyrange = [aes.xviewmax-aes.xviewmin, aes.yviewmax-aes.yviewmin] diff --git a/src/geom/subplot.jl b/src/geom/subplot.jl index bca1f4638..a4c247780 100644 --- a/src/geom/subplot.jl +++ b/src/geom/subplot.jl @@ -136,7 +136,7 @@ function render(geom::SubplotGrid, theme::Gadfly.Theme, inherited_aes = element_aesthetics(layer.geom) push!(inherited_aes, :xgroup, :ygroup) for var in inherited_aes - if getfield(layer_aes, var) === nothing + if isnothing(getfield(layer_aes, var)) setfield!(layer_aes, var, getfield(superplot_aes, var)) end end @@ -144,17 +144,17 @@ function render(geom::SubplotGrid, theme::Gadfly.Theme, # z for (layer_data, layer_aes) in zip(subplot_layer_datas, subplot_layer_aess) z = getfield(layer_data, :z) - (z != nothing) && setfield!(layer_aes, :z, z) + (!isnothing(z)) && setfield!(layer_aes, :z, z) end # work out the grid size m = 1 n = 1 for layer_aes in subplot_layer_aess - if layer_aes.xgroup != nothing + if !isnothing(layer_aes.xgroup) m = max(m, maximum(layer_aes.xgroup)) end - if layer_aes.ygroup != nothing + if !isnothing(layer_aes.ygroup) n = max(n, maximum(layer_aes.ygroup)) end end @@ -315,7 +315,7 @@ function render(geom::SubplotGrid, theme::Gadfly.Theme, if i == n push!(guides, get(geom.guides, Guide.XTicks, Guide.xticks())) - if superplot_aes.xgroup !== nothing + if !isnothing(superplot_aes.xgroup) push!(guides, get(geom.guides, Guide.XLabel, Guide.xlabel(xlabels[j]))) end else @@ -326,7 +326,7 @@ function render(geom::SubplotGrid, theme::Gadfly.Theme, if j == 1 joff += 1 push!(guides, get(geom.guides, Guide.YTicks, Guide.yticks())) - if superplot_aes.ygroup !== nothing + if !isnothing(superplot_aes.ygroup) joff += 1 push!(guides, get(geom.guides, Guide.YLabel, Guide.ylabel(ylabels[i]))) end @@ -349,7 +349,7 @@ function render(geom::SubplotGrid, theme::Gadfly.Theme, # copy over the correct units, since we are reparenting the children for u in 1:size(subtbl, 1), v in 1:size(subtbl, 2) for child in subtbl[u, v] - if child.units===nothing + if isnothing(child.units) child.units = subtbl.units end end diff --git a/src/geometry.jl b/src/geometry.jl index 125410f34..377bf07b3 100644 --- a/src/geometry.jl +++ b/src/geometry.jl @@ -13,7 +13,7 @@ import Compose.combine # Prevent DataFrame.combine from taking over. import Gadfly: render, layers, element_aesthetics, inherit, escape_id, default_statistic, default_scales, element_coordinate_type, ScaleElement, svg_color_class_from_label, isconcrete, - concretize, discretize_make_ia + concretize, discretize_make_ia, isnothing import IterTools: distinct, takestrict import Compat.Iterators: cycle, product, repeated diff --git a/src/guide.jl b/src/guide.jl index 400dca599..32162cbca 100644 --- a/src/guide.jl +++ b/src/guide.jl @@ -9,7 +9,7 @@ using IterTools using JSON import Gadfly: render, escape_id, default_statistic, jsdata, jsplotdata, - svg_color_class_from_label + svg_color_class_from_label, isnothing # Where the guide should be placed in relation to the plot. @@ -35,7 +35,7 @@ const questionmark = QuestionMark function render(guide::QuestionMark, theme::Gadfly.Theme, aes::Gadfly.Aesthetics) - text_color = theme.background_color == nothing ? + text_color = isnothing(theme.background_color) ? colorant"black" : distinguishable_colors(2,theme.background_color)[2] text_box = compose!( context(), text(1w,0h+2px,"?",hright,vtop), @@ -64,7 +64,7 @@ const helpscreen = HelpScreen function render(guide::HelpScreen, theme::Gadfly.Theme, aes::Gadfly.Aesthetics) - box_color = theme.background_color == nothing ? + box_color = isnothing(theme.background_color) ? colorant"black" : distinguishable_colors(2,theme.background_color)[2] text_color = distinguishable_colors(2,box_color)[2] text_strings = ["h,j,k,l,arrows,drag to pan", @@ -104,7 +104,7 @@ const crosshair = CrossHair function render(guide::CrossHair, theme::Gadfly.Theme, aes::Gadfly.Aesthetics) - text_color = theme.background_color == nothing ? + text_color = isnothing(theme.background_color) ? colorant"black" : distinguishable_colors(2,theme.background_color)[2] text_box = compose!( context(), @@ -262,7 +262,7 @@ function render_discrete_color_key(colors::Vector{C}, fill(theme.key_label_color)) col = compose!(context(xpos, yoff), swatches, swatch_labels) - if aes_color_label != nothing + if !isnothing(aes_color_label) classes = [svg_color_class_from_label(aes_color_label([c])[1]) for c in cs] #class_jscalls = ["data(\"color_class\", \"$(c)\")" #for c in classes] @@ -395,7 +395,7 @@ function render(guide::ColorKey, theme::Gadfly.Theme, (theme.key_position == :none || isempty(aes.color_key_colors)) && return PositionedGuide[] gpos = guide.pos - (theme.key_position == :inside && gpos === nothing) && (gpos = [0.7w, 0.25h]) + (theme.key_position == :inside && isnothing(gpos)) && (gpos = [0.7w, 0.25h]) used_colors = Set{Color}() colors = Array{Color}(undef, 0) # to preserve ordering @@ -404,18 +404,18 @@ function render(guide::ColorKey, theme::Gadfly.Theme, continuous_guide = false guide_title = guide.title - if guide_title === nothing && aes.color_key_title !== nothing + if isnothing(guide_title) && !isnothing(aes.color_key_title) guide_title = aes.color_key_title end - if aes.color_key_colors != nothing && - aes.color_key_continuous != nothing && + if !isnothing(aes.color_key_colors) && + !isnothing(aes.color_key_continuous) && aes.color_key_continuous continuous_guide = true end color_key_labels = aes.color_label(keys(aes.color_key_colors)) - if !continuous_guide && (guide.labels != nothing) + if !continuous_guide && !isnothing(guide.labels) color_key_labels = guide.labels end @@ -430,7 +430,7 @@ function render(guide::ColorKey, theme::Gadfly.Theme, end end - if guide_title === nothing + if isnothing(guide_title) guide_title = "Color" end @@ -457,7 +457,7 @@ function render(guide::ColorKey, theme::Gadfly.Theme, title_width, theme) end - if aes.shape != nothing + if !isnothing(aes.shape) # TODO: Draw key for shapes. We need to think about how to make this # work. Do we need to optimize number of columns for shape and size # keys? I'm guessing it's not worth it. @@ -469,7 +469,7 @@ function render(guide::ColorKey, theme::Gadfly.Theme, end position = right_guide_position - if gpos != nothing + if !isnothing(gpos) position = over_guide_position ctxs = [compose(context(), (context(gpos[1],gpos[2]), ctxs[1]))] elseif theme.key_position == :left @@ -517,11 +517,11 @@ function render(guide::ManualColorKey, theme::Gadfly.Theme, guide_title = guide.title - if guide_title === nothing && aes.color_key_title !== nothing + if isnothing(guide_title) && !isnothing(aes.color_key_title) guide_title = aes.color_key_title end - if guide_title === nothing + if isnothing(guide_title) guide_title = "Color" end @@ -569,13 +569,13 @@ visibility. `ticks` can also be an array of locations, or `nothing`. const xticks = XTicks default_statistic(guide::XTicks) = - guide.ticks == nothing ? Stat.identity() : Stat.xticks(ticks=guide.ticks) + isnothing(guide.ticks) ? Stat.identity() : Stat.xticks(ticks=guide.ticks) function render(guide::XTicks, theme::Gadfly.Theme, aes::Gadfly.Aesthetics, dynamic::Bool=true) - guide.ticks == nothing && return PositionedGuide[] + isnothing(guide.ticks) && return PositionedGuide[] - if Gadfly.issomething(aes.xtick) + if !Gadfly.isnothing(aes.xtick) ticks = aes.xtick tickvisibility = aes.xtickvisible scale = aes.xtickscale @@ -592,7 +592,7 @@ function render(guide::XTicks, theme::Gadfly.Theme, scale = Any[] end - if Gadfly.issomething(aes.xgrid) + if !Gadfly.isnothing(aes.xgrid) grids = aes.xgrid gridvisibility = length(grids) < length(ticks) ? tickvisibility[2:end] : tickvisibility else @@ -740,7 +740,7 @@ visibility. `ticks` can also be an array of locations, or `nothing`. const yticks = YTicks function default_statistic(guide::YTicks) - if guide.ticks == nothing + if isnothing(guide.ticks) return Stat.identity() else return Stat.yticks(ticks=guide.ticks) @@ -749,11 +749,11 @@ end function render(guide::YTicks, theme::Gadfly.Theme, aes::Gadfly.Aesthetics, dynamic::Bool=true) - if guide.ticks == nothing + if isnothing(guide.ticks) return PositionedGuide[] end - if Gadfly.issomething(aes.ytick) + if !Gadfly.isnothing(aes.ytick) ticks = aes.ytick tickvisibility = aes.ytickvisible scale = aes.ytickscale @@ -769,7 +769,7 @@ function render(guide::YTicks, theme::Gadfly.Theme, scale = Any[] end - if Gadfly.issomething(aes.ygrid) + if !Gadfly.isnothing(aes.ygrid) grids = aes.ygrid if length(grids) < length(ticks) gridvisibility = tickvisibility[2:end] @@ -919,7 +919,7 @@ const xlabel = XLabel function render(guide::XLabel, theme::Gadfly.Theme, aes::Gadfly.Aesthetics) - if guide.label === nothing || isempty(guide.label) + if isnothing(guide.label) || isempty(guide.label) return nothing end @@ -986,7 +986,7 @@ const ylabel = YLabel function render(guide::YLabel, theme::Gadfly.Theme, aes::Gadfly.Aesthetics) - if guide.label === nothing || isempty(guide.label) + if isnothing(guide.label) || isempty(guide.label) return nothing end @@ -1044,7 +1044,7 @@ const title = Title function render(guide::Title, theme::Gadfly.Theme, aes::Gadfly.Aesthetics) - if guide.label === nothing || isempty(guide.label) + if isnothing(guide.label) || isempty(guide.label) return nothing end @@ -1160,9 +1160,9 @@ function layout_guides(plot_context::Context, aspect_ratio = nothing if isa(coord, Gadfly.Coord.cartesian) if coord.fixed - aspect_ratio = plot_context.units===nothing ? 1.0 : - abs(plot_context.units.width / plot_context.units.height) - elseif coord.aspect_ratio != nothing + aspect_ratio = isnothing(plot_context.units) ? 1.0 : + abs(plot_context.units.width / plot_context.units.height) + elseif !isnothing(coord.aspect_ratio) aspect_ratio = coord.aspect_ratio end end @@ -1172,7 +1172,7 @@ function layout_guides(plot_context::Context, i = 1 for (ctxs, order) in guides[top_guide_position] for ctx in ctxs - if ctx.units===nothing && plot_units!==nothing + if isnothing(ctx.units) && !isnothing(plot_units) ctx.units = UnitBox(plot_units, toppad=0mm, bottompad=0mm) end end @@ -1183,7 +1183,7 @@ function layout_guides(plot_context::Context, i += 1 for (ctxs, order) in guides[bottom_guide_position] for ctx in ctxs - if ctx.units===nothing && plot_units!==nothing + if isnothing(ctx.units) && !isnothing(plot_units) ctx.units = UnitBox(plot_units, toppad=0mm, bottompad=0mm) end end @@ -1195,7 +1195,7 @@ function layout_guides(plot_context::Context, j = 1 for (ctxs, order) in guides[left_guide_position] for ctx in ctxs - if ctx.units===nothing && plot_units!==nothing + if isnothing(ctx.units) && !isnothing(plot_units) ctx.units = UnitBox(plot_units, leftpad=0mm, rightpad=0mm) end end @@ -1206,7 +1206,7 @@ function layout_guides(plot_context::Context, j += 1 for (ctxs, order) in guides[right_guide_position] for ctx in ctxs - if ctx.units===nothing && plot_units!==nothing + if isnothing(ctx.units) && !isnothing(plot_units) ctx.units = UnitBox(plot_units, leftpad=0mm, rightpad=0mm) end end diff --git a/src/guide/keys.jl b/src/guide/keys.jl index ac3943033..d9d9d77b2 100644 --- a/src/guide/keys.jl +++ b/src/guide/keys.jl @@ -32,11 +32,11 @@ function Guide.render(guide::Guide.ShapeKey, theme::Gadfly.Theme, aes::Gadfly.Ae # Aesthetics for keys: shape_key_title, shape_label (Function), shape_key_shapes (AbstractDict) nshapes = length(unique(aes.shape)) - guide_title = (guide.title!="Shape" || aes.shape_key_title==nothing) ? guide.title : aes.shape_key_title + guide_title = (guide.title!="Shape" || isnothing(aes.shape_key_title)) ? guide.title : aes.shape_key_title shape_key_labels = !(guide.labels==[""]) ? guide.labels : aes.shape_label(1:nshapes) colors = [nothing] - if (aes.shape_key_title !=nothing) && (aes.color_key_title==aes.shape_key_title) + if !isnothing(aes.shape_key_title) && (aes.color_key_title==aes.shape_key_title) colors = collect(keys(aes.color_key_colors)) end @@ -70,8 +70,8 @@ function render_discrete_key(labels::Vector{String}, title_ctx::Context, title_w n = max(length(colors), length(shapes)) shape1 = shapes[1] - shapes = (shape1==nothing) ? fill(theme.key_swatch_shape, n) : theme.point_shapes[shapes] - (colors[1]==nothing) && (colors = fill((theme.key_swatch_color==nothing) ? theme.default_color : theme.key_swatch_color, n)) + shapes = isnothing(shape1) ? fill(theme.key_swatch_shape, n) : theme.point_shapes[shapes] + (isnothing(colors[1])) && (colors = fill((isnothing(theme.key_swatch_color)) ? theme.default_color : theme.key_swatch_color, n)) # only consider layouts with a reasonable number of columns maxcols = theme.key_max_columns < 1 ? 1 : theme.key_max_columns @@ -144,7 +144,7 @@ function render_discrete_key(labels::Vector{String}, title_ctx::Context, title_w fill(theme.key_label_color)) col = compose!(context(xpos, yoff), swatches, swatch_labels) - if aes_color_label != nothing + if !isnothing(aes_color_label) classes = [svg_color_class_from_label(aes_color_label([c])[1]) for c in clrs] #class_jscalls = ["data(\"color_class\", \"$(c)\")" for c in classes] compose!(col, diff --git a/src/mapping.jl b/src/mapping.jl index 12d625a58..9a7d9cc1b 100644 --- a/src/mapping.jl +++ b/src/mapping.jl @@ -87,7 +87,7 @@ end function meltdata(U::AbstractVector, colgroups_::Vector{Col.GroupedColumn}) colgroups = Set(colgroups_) - if length(colgroups) != 1 || first(colgroups).columns!==nothing + if length(colgroups) != 1 || !isnothing(first(colgroups).columns) # if every column is of the same length, treat it as a matrix if length(Set([length(u for u in U)])) == 1 return meltdata(cat(U..., dims=2), colgroups_) @@ -130,7 +130,7 @@ function meltdata(U::AbstractMatrix, colgroups_::Vector{Col.GroupedColumn}) vm = um grouped_columns = BitSet() for colgroup in colgroups - if colgroup.columns===nothing + if isnothing(colgroup.columns) vm *= un grouped_columns = copy(allcolumns) else @@ -149,7 +149,7 @@ function meltdata(U::AbstractMatrix, colgroups_::Vector{Col.GroupedColumn}) col_indicators = Array{Int}(undef, vm, length(colgroups)) row_indicators = Array{Int}(undef, vm, length(colgroups)) - colidxs = [colgroup.columns===nothing ? collect(allcolumns) : colgroup.columns + colidxs = [isnothing(colgroup.columns) ? collect(allcolumns) : colgroup.columns for colgroup in colgroups] vi = 1 diff --git a/src/misc.jl b/src/misc.jl index 4a3591600..5ddbcd80a 100644 --- a/src/misc.jl +++ b/src/misc.jl @@ -178,7 +178,7 @@ function inherit!(a::T, b::T) where T aval = getfield(a, field) bval = getfield(b, field) # TODO: this is a hack to let non-default labelers overide the defaults - if aval === nothing || aval === string || aval == showoff + if isnothing(aval) || aval === string || aval == showoff setfield!(a, field, bval) elseif typeof(aval) <: Dict && typeof(bval) <: Dict merge!(aval, getfield(b, field)) @@ -188,9 +188,6 @@ function inherit!(a::T, b::T) where T end -isnothing(u) = u === nothing -issomething(u) = !isnothing(u) - negate(f) = x -> !f(x) diff --git a/src/scale.jl b/src/scale.jl index be582ab93..a87692074 100644 --- a/src/scale.jl +++ b/src/scale.jl @@ -11,7 +11,7 @@ using CategoricalArrays using Printf import Gadfly: element_aesthetics, isconcrete, concrete_length, discretize_make_ia, - aes2str, valid_aesthetics + aes2str, valid_aesthetics, isnothing import Distributions: Distribution include("color_misc.jl") @@ -86,7 +86,7 @@ struct ContinuousScale <: Gadfly.ScaleElement function ContinuousScale(vars, trans, minvalue, maxvalue, minticks, maxticks, labels, format, scalable) - minvalue != nothing && maxvalue != nothing && minvalue > maxvalue && + !isnothing(minvalue) && !isnothing(maxvalue) && minvalue > maxvalue && error("Cannot construct a ContinuousScale with minvalue > maxvalue") new(vars, trans, minvalue, maxvalue, minticks, maxticks, labels, format, scalable) end @@ -100,9 +100,9 @@ function ContinuousScale(vars, trans; end function make_labeler(scale::ContinuousScale) - if scale.labels != nothing + if !isnothing(scale.labels) xs -> [scale.labels(x) for x in xs] - elseif scale.format == nothing + elseif isnothing(scale.format) scale.trans.label else xs -> scale.trans.label(xs, scale.format) @@ -190,7 +190,7 @@ function apply_scale(scale::ContinuousScale, if vals isa CategoricalArray throw(ArgumentError("continuous scale for $var aesthetic when stored as a CategoricalArray. Consider using a discrete scale or convert data to an Array.")) end - vals === nothing && continue + isnothing(vals) && continue # special case for function arrays bound to :y # pass the function values through and wait for the scale to @@ -245,7 +245,7 @@ function apply_scale(scale::ContinuousScale, end end - if scale.minvalue != nothing + if !isnothing(scale.minvalue) if scale.vars === x_vars aes.xviewmin = scale.trans.f(scale.minvalue) elseif scale.vars === y_vars @@ -253,7 +253,7 @@ function apply_scale(scale::ContinuousScale, end end - if scale.maxvalue != nothing + if !isnothing(scale.maxvalue) if scale.vars === x_vars aes.xviewmax = scale.trans.f(scale.maxvalue) elseif scale.vars === y_vars @@ -272,7 +272,7 @@ end function discretize(values, levels=nothing, order=nothing, preserve_order=true) - if levels == nothing + if isnothing(levels) if preserve_order levels = OrderedSet() for value in values @@ -286,7 +286,7 @@ function discretize(values, levels=nothing, order=nothing, preserve_order=true) da = discretize_make_ia(values, levels) end - if order != nothing + if !isnothing(order) return discretize_make_ia(da, da.values[order]) else return da @@ -370,13 +370,13 @@ function apply_scale(scale::DiscreteScale, aess::Vector{Gadfly.Aesthetics}, data for (aes, data) in zip(aess, datas) for var in scale.vars label_var = Symbol(var, "_label") - getfield(data, var) === nothing && continue + isnothing(getfield(data, var)) && continue disc_data = discretize(getfield(data, var), scale.levels, scale.order) setfield!(aes, var, discretize_make_ia(Int64.(disc_data.index))) # The leveler for discrete scales is a closure over the discretized data. - if scale.labels === nothing + if isnothing(scale.labels) function default_labeler(xs) lvls = filter(!ismissing, disc_data.values) vals = Any[1 <= x <= length(lvls) ? lvls[x] : "" for x in xs] @@ -435,7 +435,7 @@ element_aesthetics(scale::IdentityColorScale) = [:color] function apply_scale(scale::IdentityColorScale, aess::Vector{Gadfly.Aesthetics}, datas::Vector{Gadfly.Data}) for (aes, data) in zip(aess, datas) - data.color === nothing && continue + isnothing(data.color) && continue aes.color = discretize_make_ia(data.color) aes.color_key_colors = Dict() end @@ -519,7 +519,7 @@ function apply_scale(scale::DiscreteColorScale, aess::Vector{Gadfly.Aesthetics}, datas::Vector{Gadfly.Data}) levelset = OrderedSet() for (aes, data) in zip(aess, datas) - data.color === nothing && continue + isnothing(data.color) && continue for d in data.color # Remove missing values # FixMe! The handling of missing values shouldn't be this scattered across the source @@ -527,13 +527,13 @@ function apply_scale(scale::DiscreteColorScale, end end - if scale.levels == nothing + if isnothing(scale.levels) scale_levels = [levelset...] scale.preserve_order || sort!(scale_levels) else scale_levels = scale.levels end - scale.order == nothing || permute!(scale_levels, scale.order) + isnothing(scale.order) || permute!(scale_levels, scale.order) colors = convert(Vector{RGB{Float32}}, scale.f(length(scale_levels))) color_map = Dict([(color, string(label)) @@ -541,7 +541,7 @@ function apply_scale(scale::DiscreteColorScale, labeler(xs) = [color_map[x] for x in xs] for (aes, data) in zip(aess, datas) - data.color === nothing && continue + isnothing(data.color) && continue # Remove missing values # FixMe! The handling of missing values shouldn't be this scattered across the source ds = discretize([c for c in data.color if !ismissing(c)], scale_levels) @@ -625,7 +625,7 @@ const color_continuous_gradient = color_continuous ### WHY HAVE THIS ALIAS? function apply_scale(scale::ContinuousColorScale, aess::Vector{Gadfly.Aesthetics}, datas::Vector{Gadfly.Data}) - cdata = skipmissing(Iterators.flatten(i.color for i in datas if i.color != nothing)) + cdata = skipmissing(Iterators.flatten(i.color for i in datas if !isnothing(i.color))) if !isempty(cdata) cmin, cmax = extrema(cdata) else @@ -633,9 +633,9 @@ function apply_scale(scale::ContinuousColorScale, end strict_span = false - scale.minvalue != nothing && scale.maxvalue != nothing && (strict_span=true) - scale.minvalue != nothing && (cmin=scale.minvalue) - scale.maxvalue != nothing && (cmax=scale.maxvalue) + !isnothing(scale.minvalue) && !isnothing(scale.maxvalue) && (strict_span=true) + !isnothing(scale.minvalue) && (cmin=scale.minvalue) + !isnothing(scale.maxvalue) && (cmax=scale.maxvalue) cmin, cmax = promote(cmin, cmax) @@ -649,7 +649,7 @@ function apply_scale(scale::ContinuousColorScale, cspan = cmax != cmin ? cmax - cmin : 1.0 for (aes, data) in zip(aess, datas) - data.color === nothing && continue + isnothing(data.color) && continue aes.color = Array{RGB{Float32}}(undef, length(data.color)) apply_scale_typed!(aes.color, data.color, scale, cmin, cspan) @@ -698,7 +698,7 @@ end function apply_scale(scale::LabelScale, aess::Vector{Gadfly.Aesthetics}, datas::Vector{Gadfly.Data}) for (aes, data) in zip(aess, datas) - data.label === nothing && continue + isnothing(data.label) && continue aes.label = discretize(data.label) end end @@ -738,7 +738,7 @@ element_aesthetics(scale::IdentityScale) = [scale.var] function apply_scale(scale::IdentityScale, aess::Vector{Gadfly.Aesthetics}, datas::Vector{Gadfly.Data}) for (aes, data) in zip(aess, datas) - getfield(data, scale.var) === nothing && continue + isnothing(getfield(data, scale.var)) && continue setfield!(aes, scale.var, getfield(data, scale.var)) end end diff --git a/src/statistics.jl b/src/statistics.jl index a55415ea5..6a2769d35 100644 --- a/src/statistics.jl +++ b/src/statistics.jl @@ -17,7 +17,8 @@ using LinearAlgebra using Random import Gadfly: Scale, Coord, input_aesthetics, output_aesthetics, - default_scales, isconcrete, setfield!, discretize_make_ia, aes2str + default_scales, isconcrete, setfield!, discretize_make_ia, aes2str, + isnothing import KernelDensity # import Distributions: Uniform, Distribution, qqbuild import IterTools: distinct @@ -186,7 +187,7 @@ function apply_statistic(stat::BarStatistic, iscontinuous = haskey(scales, var) && isa(scales[var], Scale.ContinuousScale) - if getfield(aes, minvar) == nothing || getfield(aes, maxvar) == nothing + if isnothing(getfield(aes, minvar)) || isnothing(getfield(aes, maxvar)) minvals, maxvals = barminmax(vals, iscontinuous) setfield!(aes, minvar, minvals) @@ -194,13 +195,13 @@ function apply_statistic(stat::BarStatistic, end z = zero(eltype(getfield(aes, othervar))) - if getfield(aes, viewminvar) == nothing && z < minimum(getfield(aes, othervar)) + if isnothing(getfield(aes, viewminvar)) && z < minimum(getfield(aes, othervar)) setfield!(aes, viewminvar, z) - elseif getfield(aes, viewmaxvar) == nothing && z > maximum(getfield(aes, othervar)) + elseif isnothing(getfield(aes, viewmaxvar)) && z > maximum(getfield(aes, othervar)) setfield!(aes, viewmaxvar, z) end - if stat.position == :stack && aes.color !== nothing + if stat.position == :stack && !isnothing(aes.color) groups = Dict{Any,Float64}() for (x, y) in zip(getfield(aes, othervar), vals) Gadfly.isconcrete(x) || continue @@ -214,11 +215,11 @@ function apply_statistic(stat::BarStatistic, viewmin, viewmax = extrema(values(groups)) aes_viewminvar = getfield(aes, viewminvar) - if aes_viewminvar === nothing || aes_viewminvar > viewmin + if isnothing(aes_viewminvar) || aes_viewminvar > viewmin setfield!(aes, viewminvar, viewmin) end aes_viewmaxvar = getfield(aes, viewmaxvar) - if aes_viewmaxvar === nothing || aes_viewmaxvar < viewmax + if isnothing(aes_viewmaxvar) || aes_viewmaxvar < viewmax setfield!(aes, viewmaxvar, viewmax) end end @@ -249,7 +250,7 @@ function HistogramStatistic(; bincount=nothing, orientation=:vertical, density=false, limits=NamedTuple()) - if bincount != nothing + if !isnothing(bincount) HistogramStatistic(bincount, bincount, position, orientation, density, limits) else HistogramStatistic(minbincount, maxbincount, position, orientation, density, limits) @@ -340,7 +341,7 @@ function apply_statistic(stat::HistogramStatistic, stat.density && (bincounts = bincounts ./ (sum(bincounts) * binwidth)) - if aes.color === nothing + if isnothing(aes.color) T = typeof(x_min + 1*binwidth) setfield!(aes, othervar, Array{Float64}(undef, d)) setfield!(aes, minvar, Array{T}(undef, d)) @@ -398,7 +399,7 @@ function apply_statistic(stat::HistogramStatistic, if stat.position == :stack viewmax = Float64(maximum(stack_height)) aes_viewmax = getfield(aes, viewmaxvar) - if aes_viewmax === nothing || aes_viewmax < viewmax + if isnothing(aes_viewmax) || aes_viewmax < viewmax setfield!(aes, viewmaxvar, viewmax) end end @@ -406,7 +407,7 @@ function apply_statistic(stat::HistogramStatistic, aes.color = discretize_make_ia(colors) end - getfield(aes, viewminvar) === nothing && setfield!(aes, viewminvar, 0.0) + isnothing(getfield(aes, viewminvar)) && setfield!(aes, viewminvar, 0.0) if haskey(scales, othervar) data = Gadfly.Data() @@ -417,7 +418,7 @@ function apply_statistic(stat::HistogramStatistic, # See issue #560. Stacked histograms on a non-linear y scale are a strange # thing. After some discussion, the least confusing thing is to make the stack # partitioned linearly. Here we make that adjustment. - if stat.position == :stack && aes.color != nothing + if stat.position == :stack && !isnothing(aes.color) # A little trickery to figure out the scale stack height. data = Gadfly.Data() setfield!(data, othervar, stack_height) @@ -511,7 +512,7 @@ function apply_statistic(stat::DensityStatistic, aes::Gadfly.Aesthetics) Gadfly.assert_aesthetics_defined("DensityStatistic", aes, :x) - if aes.color === nothing + if isnothing(aes.color) isa(aes.x[1], Real) || error("Kernel density estimation only works on Real types.") x_f64 = collect(Float64, aes.x) @@ -561,12 +562,12 @@ function Histogram2DStatistic(; xbincount=nothing, ybincount=nothing, yminbincount=3, ymaxbincount=150) - if xbincount != nothing + if !isnothing(xbincount) xminbincount = xbincount xmaxbincount = xbincount end - if ybincount != nothing + if !isnothing(ybincount) yminbincount = ybincount ymaxbincount = ybincount end @@ -770,7 +771,7 @@ function apply_statistic(stat::TickStatistic, error("TickStatistic cannot be applied to subplot coordinates.") # don't clobber existing ticks - getfield(aes, Symbol(stat.axis, "tick")) == nothing || return + isnothing(getfield(aes, Symbol(stat.axis, "tick"))) || return in_group_var = Symbol(stat.axis, "group") minval, maxval = nothing, nothing @@ -781,11 +782,11 @@ function apply_statistic(stat::TickStatistic, for var in in_vars categorical && !in(var,[:x,:y]) && continue vals = getfield(aes, var) - if vals != nothing && eltype(vals) != Function - if minval == nothing + if !isnothing(vals) && eltype(vals) != Function + if isnothing(minval) minval = first(vals) end - if maxval == nothing + if isnothing(maxval) maxval = first(vals) end T = promote_type(typeof(minval), typeof(maxval)) @@ -794,14 +795,14 @@ function apply_statistic(stat::TickStatistic, maxval = convert(T, maxval) if stat.axis == "x" - dsize = aes.xsize === nothing ? [nothing] : aes.xsize + dsize = isnothing(aes.xsize) ? [nothing] : aes.xsize elseif stat.axis == "y" - dsize = aes.ysize === nothing ? [nothing] : aes.ysize + dsize = isnothing(aes.ysize) ? [nothing] : aes.ysize else dsize = [nothing] end - size = aes.size === nothing ? [nothing] : aes.size + size = isnothing(aes.size) ? [nothing] : aes.size minval, maxval = apply_statistic_typed(minval, maxval, vals, size, dsize) push!(in_vals, vals) @@ -824,17 +825,17 @@ function apply_statistic(stat::TickStatistic, # check the x/yviewmin/max pesudo-aesthetics if stat.axis == "x" - if aes.xviewmin != nothing + if !isnothing(aes.xviewmin) minval = min(minval, aes.xviewmin) end - if aes.xviewmax != nothing + if !isnothing(aes.xviewmax) maxval = max(maxval, aes.xviewmax) end elseif stat.axis == "y" - if aes.yviewmin != nothing + if !isnothing(aes.yviewmin) minval = min(minval, aes.yviewmin) end - if aes.yviewmax != nothing + if !isnothing(aes.yviewmax) maxval = max(maxval, aes.yviewmax) end end @@ -843,20 +844,20 @@ function apply_statistic(stat::TickStatistic, strict_span = false if typeof(coord) == Coord.Cartesian if stat.axis == "x" - if coord.xmin !== nothing + if !isnothing(coord.xmin) minval = coord.xmin strict_span = true end - if coord.xmax !== nothing + if !isnothing(coord.xmax) maxval = coord.xmax strict_span = true end elseif stat.axis == "y" - if coord.ymin !== nothing + if !isnothing(coord.ymin) minval = coord.ymin strict_span = true end - if coord.ymax !== nothing + if !isnothing(coord.ymax) maxval = coord.ymax strict_span = true end @@ -923,12 +924,12 @@ function apply_statistic(stat::TickStatistic, setfield!(aes, Symbol(stat.axis, "tickscale"), tickscale) viewmin_var = Symbol(stat.axis, "viewmin") - if getfield(aes, viewmin_var) === nothing || getfield(aes, viewmin_var) > viewmin + if isnothing(getfield(aes, viewmin_var)) || getfield(aes, viewmin_var) > viewmin setfield!(aes, viewmin_var, viewmin) end viewmax_var = Symbol(stat.axis, "viewmax") - if getfield(aes, viewmax_var) === nothing || getfield(aes, viewmax_var) < viewmax + if isnothing(getfield(aes, viewmax_var)) || getfield(aes, viewmax_var) < viewmax setfield!(aes, viewmax_var, viewmax) end @@ -959,12 +960,12 @@ function minvalmaxval(minval::T, maxval::T, val, s, ds) where T maxval = val end - if s != nothing && typeof(s) <: AbstractFloat + if !isnothing(s) && typeof(s) <: AbstractFloat minval = min(minval, val - s)::T maxval = max(maxval, val + s)::T end - if ds != nothing + if !isnothing(ds) minval = min(minval, val - ds)::T maxval = max(maxval, val + ds)::T end @@ -999,7 +1000,7 @@ function apply_statistic(stat::BoxplotStatistic, coord::Gadfly.CoordinateElement, aes::Gadfly.Aesthetics) - xflag = aes.x != nothing + xflag = !isnothing(aes.x) aes_x = (xflag ? eltype(aes.x) : Int)[] if xflag aes_x = aes.x @@ -1007,26 +1008,26 @@ function apply_statistic(stat::BoxplotStatistic, aes_x = ones(Int, length(aes.y)) aes.x_label = x -> fill("", length(x)) end - colorflag = aes.color != nothing + colorflag = !isnothing(aes.color) aes_color = colorflag ? aes.color : fill(nothing, length(aes_x)) - if aes.y == nothing + if isnothing(aes.y) groups = Any[] for (x, c) in zip(aes.x, cycle(aes_color)) push!(groups, (x, c)) end yviewmin, yviewmax = minimum(aes.lower_fence), maximum(aes.upper_fence) - if aes.outliers !== nothing + if !isnothing(aes.outliers) yviewmin = minimum(yviewmin, aes.outliers) yviewmax = maximum(yviewmax, aes.outliers) end - if aes.yviewmin === nothing || aes.yviewmin > yviewmin + if isnothing(aes.yviewmin) || aes.yviewmin > yviewmin aes.yviewmin = yviewmin end - if aes.yviewmax === nothing || aes.yviewmax < yviewmax + if isnothing(aes.yviewmax) || aes.yviewmax < yviewmax aes.yviewmax = yviewmax end else @@ -1082,11 +1083,11 @@ function apply_statistic(stat::BoxplotStatistic, xviewmin = xmin - minspan / 2 xviewmax = xmax + minspan / 2 - if aes.xviewmin === nothing || aes.xviewmin > xviewmin + if isnothing(aes.xviewmin) || aes.xviewmin > xviewmin aes.xviewmin = xviewmin end - if aes.xviewmax === nothing || aes.xviewmax < xviewmax + if isnothing(aes.xviewmax) || aes.xviewmax < xviewmax aes.xviewmax = xviewmax end end @@ -1150,7 +1151,7 @@ function Stat.apply_statistic(stat::SmoothStatistic, error("Stat.loess and Stat.lm require that x and y be bound to arrays of plain numbers.") end - colorflag = aes.color != nothing + colorflag = !isnothing(aes.color) aes_color = colorflag ? aes.color : fill(nothing, length(aes.x)) uc = unique(aes_color) @@ -1308,18 +1309,18 @@ function apply_statistic(stat::StepStatistic, p = sortperm(aes.x, alg=MergeSort) permute!(aes.x, p) permute!(aes.y, p) - aes.group != nothing && permute!(aes.group, p) - aes.color != nothing && permute!(aes.color, p) + !isnothing(aes.group) && permute!(aes.group, p) + !isnothing(aes.color) && permute!(aes.color, p) - if aes.group != nothing + if !isnothing(aes.group) Gadfly.assert_aesthetics_equal_length("StepStatistic", aes, :x, :group) permute!(aes.x, p) permute!(aes.y, p) permute!(aes.group, p) - aes.color != nothing && permute!(aes.color, p) + !isnothing(aes.color) && permute!(aes.color, p) end - if aes.color != nothing + if !isnothing(aes.color) Gadfly.assert_aesthetics_equal_length("StepStatistic", aes, :x, :color) # TODO: use this when we switch to 0.4 # sortperm!(p, aes.color, alg=MergeSort, lt=Gadfly.color_isless) @@ -1327,13 +1328,13 @@ function apply_statistic(stat::StepStatistic, permute!(aes.x, p) permute!(aes.y, p) permute!(aes.color, p) - aes.group != nothing && permute!(aes.group, p) + !isnothing(aes.group) && permute!(aes.group, p) end x_step = Array{eltype(aes.x)}(undef, 0) y_step = Array{eltype(aes.y)}(undef, 0) - color_step = aes.color == nothing ? nothing : Array{eltype(aes.color)}(undef, 0) - group_step = aes.group == nothing ? nothing : Array{eltype(aes.group)}(undef, 0) + color_step = isnothing(aes.color) ? nothing : Array{eltype(aes.color)}(undef, 0) + group_step = isnothing(aes.group) ? nothing : Array{eltype(aes.group)}(undef, 0) i = 1 i_offset = 1 @@ -1343,17 +1344,17 @@ function apply_statistic(stat::StepStatistic, (u > length(aes.x) || v > length(aes.y)) && break - if (aes.color != nothing && + if (!isnothing(aes.color) && (aes.color[u] != aes.color[i_offset] || aes.color[v] != aes.color[i_offset])) || - (aes.group != nothing && + (!isnothing(aes.group) && (aes.group[u] != aes.color[i_offset] || aes.color[v] != aes.group[i_offset])) i_offset = max(u, v) i = 1 else push!(x_step, aes.x[u]) push!(y_step, aes.y[v]) - aes.color != nothing && push!(color_step, aes.color[i_offset]) - aes.group != nothing && push!(group_step, aes.group[i_offset]) + !isnothing(aes.color) && push!(color_step, aes.color[i_offset]) + !isnothing(aes.group) && push!(group_step, aes.group[i_offset]) i += 1 end end @@ -1405,7 +1406,7 @@ function apply_statistic(stat::FunctionStatistic, end # color was bound explicitly - if aes.color != nothing + if !isnothing(aes.color) func_color = aes.color aes.color = Array{eltype(aes.color)}(undef, length(aes.y) * stat.num_samples) groups = Array{Int}(undef, length(aes.y) * stat.num_samples) @@ -1465,15 +1466,15 @@ function apply_statistic(stat::ContourStatistic, scales::Dict{Symbol, Gadfly.ScaleElement}, coord::Gadfly.CoordinateElement, aes::Gadfly.Aesthetics) - xs = aes.x === nothing ? nothing : convert(Vector{Float64}, aes.x) - ys = aes.y === nothing ? nothing : convert(Vector{Float64}, aes.y) + xs = isnothing(aes.x) ? nothing : convert(Vector{Float64}, aes.x) + ys = isnothing(aes.y) ? nothing : convert(Vector{Float64}, aes.y) if typeof(aes.z) <: Function - if xs == nothing && aes.xmin != nothing && aes.xmax != nothing + if isnothing(xs) && !isnothing(aes.xmin) && !isnothing(aes.xmax) xs = range(aes.xmin[1], stop=aes.xmax[1], length=stat.samples) end - if ys == nothing && aes.ymin != nothing && aes.ymax != nothing + if isnothing(ys) && !isnothing(aes.ymin) && !isnothing(aes.ymax) ys = range(aes.ymin[1], stop=aes.ymax[1], length=stat.samples) end @@ -1482,10 +1483,10 @@ function apply_statistic(stat::ContourStatistic, elseif typeof(aes.z) <: Matrix zs = convert(Matrix{Float64}, aes.z) - if xs == nothing + if isnothing(xs) xs = collect(Float64, 1:size(zs)[1]) end - if ys == nothing + if isnothing(ys) ys = collect(Float64, 1:size(zs)[2]) end size(zs) != (length(xs), length(ys)) && @@ -1634,7 +1635,7 @@ function apply_statistic(stat::ViolinStatistic, grouped_color = Dict{Int, Gadfly.ColorOrNothing}(1=>nothing) ux = unique(aes.x) uxflag = length(ux) < length(aes.x) - colorflag = aes.color != nothing + colorflag = !isnothing(aes.color) uxflag && (grouped_y = Dict(x=>aes.y[aes.x.==x] for x in ux)) @@ -1701,7 +1702,7 @@ function minimum_span(vars::Vector{Symbol}, aes::Gadfly.Aesthetics) end end - if span == nothing || (dataspan != nothing && dataspan < span) + if isnothing(span) || (!isnothing(dataspan) && dataspan < span) span = dataspan end end @@ -1714,7 +1715,7 @@ function apply_statistic(stat::JitterStatistic, coord::Gadfly.CoordinateElement, aes::Gadfly.Aesthetics) span = minimum_span(stat.vars, aes) - span == nothing && return + isnothing(span) && return rng = MersenneTwister(stat.seed) for var in stat.vars @@ -1755,7 +1756,7 @@ function apply_statistic(stat::BinMeanStatistic, Tx = eltype(aes.x) Ty = eltype(aes.y) - if aes.color === nothing + if isnothing(aes.color) (aes.x, aes.y) = mean_by_group(aes.x, aes.y, breaks) else groups = Dict() @@ -1827,8 +1828,8 @@ function apply_statistic(stat::EnumerateStatistic, scales::Dict{Symbol, Gadfly.ScaleElement}, coord::Gadfly.CoordinateElement, aes::Gadfly.Aesthetics) - has_x = aes.x != nothing - has_y = aes.y != nothing + has_x = !isnothing(aes.x) + has_y = !isnothing(aes.y) if stat.var == :x && !has_x && has_y aes.x = collect(1:length(aes.y)) @@ -1869,14 +1870,14 @@ function apply_statistic(stat::VecFieldStatistic, scales::Dict{Symbol, Gadfly.ScaleElement}, coord::Gadfly.CoordinateElement, aes::Gadfly.Aesthetics) - xs = aes.x === nothing ? nothing : Float64.(aes.x) - ys = aes.y === nothing ? nothing : Float64.(aes.y) + xs = isnothing(aes.x) ? nothing : Float64.(aes.x) + ys = isnothing(aes.y) ? nothing : Float64.(aes.y) if isa(aes.z, Function) - if xs == nothing && aes.xmin != nothing && aes.xmax != nothing + if isnothing(xs) && !isnothing(aes.xmin) && !isnothing(aes.xmax) xs = range(aes.xmin[1], stop=aes.xmax[1], length=stat.samples) end - if ys == nothing && aes.ymin != nothing && aes.ymax != nothing + if isnothing(ys) && !isnothing(aes.ymin) && !isnothing(aes.ymax) ys = range(aes.ymin[1], stop=aes.ymax[1], length=stat.samples) end @@ -1885,10 +1886,10 @@ function apply_statistic(stat::VecFieldStatistic, elseif isa(aes.z, Matrix) zs = Float64.(aes.z) - if xs == nothing + if isnothing(xs) xs = collect(Float64, 1:size(zs)[1]) end - if ys == nothing + if isnothing(ys) ys = collect(Float64, 1:size(zs)[2]) end if size(zs) != (length(xs), length(ys)) @@ -1981,8 +1982,8 @@ function apply_statistic(stat::EllipseStatistic, aes::Gadfly.Aesthetics) Dat = [aes.x aes.y] - colorflag = aes.color != nothing - groupflag = aes.group != nothing + colorflag = !isnothing(aes.color) + groupflag = !isnothing(aes.group) aes_color = colorflag ? aes.color : fill(nothing, length(aes.x)) aes_group = groupflag ? aes.group : fill(nothing, length(aes.x)) CT, GT = eltype(aes_color), eltype(aes_group) @@ -2053,7 +2054,7 @@ function apply_statistic(stat::DodgeStatistic, coord::Gadfly.CoordinateElement, aes::Gadfly.Aesthetics) - aes.color==nothing && return + isnothing(aes.color) && return nbars = length(unique(aes.color)) othervar = (stat.axis == :x) ? :y : :x vals = getfield(aes, stat.axis) diff --git a/src/ticks.jl b/src/ticks.jl index aae6954d5..2e4c5710d 100644 --- a/src/ticks.jl +++ b/src/ticks.jl @@ -214,7 +214,7 @@ function optimize_ticks(x_min::DateTime, x_max::DateTime; extend_ticks::Bool=fal # TODO: manually setting scale with :day, :minute, etc end - if scale === nothing + if isnothing(scale) for proposed_scale in [Day(1), Hour(1), Minute(1), Second(1), Millisecond(100), Millisecond(10), Millisecond(1)] @@ -225,7 +225,7 @@ function optimize_ticks(x_min::DateTime, x_max::DateTime; extend_ticks::Bool=fal end end - if scale === nothing + if isnothing(scale) scale = Millisecond(1) end diff --git a/src/varset.jl b/src/varset.jl index 7773a18ce..9c3f31e42 100644 --- a/src/varset.jl +++ b/src/varset.jl @@ -45,7 +45,7 @@ macro varset(name::Symbol, table) push!(parameters, Expr(:kw, var, default)) push!(inherit_parameters, Expr(:kw, var, :(b.$var))) if typ==:ColorOrNothing - push!(parsed_vars, :($(var)==nothing ? nothing : parse_colorant($(var)))) + push!(parsed_vars, :(isnothing($(var)) ? nothing : parse_colorant($(var)))) else push!(parsed_vars, :($(var))) end From 80ae3df9c90ae8a241cb91f6f6e4b9322b0b1741 Mon Sep 17 00:00:00 2001 From: Adam Beckmeyer Date: Wed, 8 May 2019 15:43:00 -0400 Subject: [PATCH 3/3] Compare nothing values with === Per comment from @ararslan, the Julia compiler may prefer === versus isnothing; improvements to be confirmed with benchmarking. --- src/Gadfly.jl | 34 +++++----- src/aesthetics.jl | 34 +++++----- src/coord.jl | 48 +++++++------- src/data.jl | 2 +- src/dataframes.jl | 6 +- src/geom/bar.jl | 4 +- src/geom/boxplot.jl | 4 +- src/geom/errorbar.jl | 4 +- src/geom/hvabline.jl | 30 ++++----- src/geom/label.jl | 4 +- src/geom/point.jl | 2 +- src/geom/rectbin.jl | 2 +- src/geom/subplot.jl | 14 ++-- src/geometry.jl | 2 +- src/guide.jl | 64 +++++++++--------- src/guide/keys.jl | 10 +-- src/mapping.jl | 6 +- src/misc.jl | 2 +- src/scale.jl | 46 ++++++------- src/statistics.jl | 155 +++++++++++++++++++++---------------------- src/ticks.jl | 4 +- src/varset.jl | 2 +- 22 files changed, 239 insertions(+), 240 deletions(-) diff --git a/src/Gadfly.jl b/src/Gadfly.jl index c935e13e4..06edc7630 100755 --- a/src/Gadfly.jl +++ b/src/Gadfly.jl @@ -388,14 +388,14 @@ function render_prepare(plot::Plot) # they are missing. datas = Array{Data}(undef, length(plot.layers)) for (i, layer) in enumerate(plot.layers) - if isnothing(layer.data_source) && isempty(layer.mapping) + if layer.data_source === nothing && isempty(layer.mapping) layer.data_source = plot.data_source layer.mapping = plot.mapping datas[i] = plot.data else datas[i] = Data() - if isnothing(layer.data_source) + if layer.data_source === nothing layer.data_source = plot.data_source end @@ -416,7 +416,7 @@ function render_prepare(plot::Plot) if isa(layer.geom, Geom.SubplotGeometry) for subplot_layer in layers(layer.geom) subplot_data = Data() - if isnothing(subplot_layer.data_source) + if subplot_layer.data_source === nothing subplot_layer.data_source = layer.data_source end @@ -434,7 +434,7 @@ function render_prepare(plot::Plot) coord = plot.coord for layer in plot.layers coord_type = element_coordinate_type(layer.geom) - if isnothing(coord) + if coord === nothing coord = coord_type() elseif typeof(coord) != coord_type error("Plot uses multiple coordinates: $(typeof(coord)) and $(coord_type)") @@ -503,7 +503,7 @@ function render_prepare(plot::Plot) unscaled_aesthetics = setdiff(used_aesthetics, scaled_aesthetics) - _theme(plt, lyr) = isnothing(lyr.theme) ? plt.theme : lyr.theme + _theme(plt, lyr) = lyr.theme === nothing ? plt.theme : lyr.theme # Add default scales for statistics. layer_stats_with_theme = map(plot.layers, layer_stats) do l, stats @@ -532,17 +532,17 @@ function render_prepare(plot::Plot) in(var, mapped_aesthetics) || continue var_data = getfield(plot.data, var) - if isnothing(var_data) + if var_data === nothing for data in datas var_layer_data = getfield(data, var) - if !isnothing(var_layer_data) + if var_layer_data !== nothing var_data = var_layer_data break end end end - isnothing(var_data) && continue + var_data === nothing && continue t = classify_data(var_data) if scale_exists(t, var) @@ -560,7 +560,7 @@ function render_prepare(plot::Plot) t = :categorical for data in Iterators.flatten((datas, subplot_datas)) val = getfield(data, var) - if !isnothing(val) && val != :categorical + if val !== nothing && val != :categorical t = classify_data(val) end end @@ -659,7 +659,7 @@ function render_prepare(plot::Plot) keyvars = [:color, :shape] for (i, layer) in enumerate(plot.layers) for kv in keyvars - fflag = (isnothing(getfield(layer_aess[i], Symbol(kv,"_key_title")))) && + fflag = (getfield(layer_aess[i], Symbol(kv,"_key_title")) === nothing) && haskey(layer.mapping, kv) && !isa(layer.mapping[kv], AbstractArray) fflag && setfield!(layer_aess[i], Symbol(kv,"_key_title"), string(layer.mapping[kv])) @@ -667,7 +667,7 @@ function render_prepare(plot::Plot) end for kv in keyvars - fflag = (isnothing(getfield(layer_aess[1], Symbol(kv,"_key_title")))) && + fflag = (getfield(layer_aess[1], Symbol(kv,"_key_title")) === nothing) && haskey(plot.mapping, kv) && !isa(plot.mapping[kv], AbstractArray) fflag && setfield!(layer_aess[1], Symbol(kv,"_key_title"), string(plot.mapping[kv])) end @@ -675,11 +675,11 @@ function render_prepare(plot::Plot) # Auto-update color scale if shape==color catdatas = vcat(datas, subplot_datas) shapev = getfield.(catdatas, :shape) - di = (!isnothing).(shapev) .& (shapev.== getfield.(catdatas, :color)) + di = @. (shapev !== nothing) & (shapev == getfield(catdatas, :color)) supress_colorkey = false for (aes, data) in zip(layer_aess[di], catdatas[di]) - isnothing(aes.shape_key_title) && (aes.shape_key_title=aes.color_key_title="Shape") + aes.shape_key_title === nothing && (aes.shape_key_title=aes.color_key_title="Shape") colorf = scales[:color].f scales[:color] = Scale.color_discrete(colorf, levels=scales[:shape].levels, order=scales[:shape].order) Scale.apply_scale(scales[:color], [aes], Gadfly.Data(color=getfield(data,:color)) ) @@ -716,7 +716,7 @@ function render_prepare(plot::Plot) if !supress_keys for (KT, kv) in zip(keytypes, keyvars) - fflag = !all([isnothing(getfield(aes, kv)) for aes in [plot_aes, layer_aess...]]) + fflag = !all([getfield(aes, kv) === nothing for aes in [plot_aes, layer_aess...]]) fflag && !in(KT, explicit_guide_types) && push!(guides, KT()) end end @@ -759,7 +759,7 @@ function render(plot::Plot) ctx = pad_inner(root_context, plot.theme.plot_padding...) - if !isnothing(plot.theme.background_color) + if plot.theme.background_color !== nothing compose!(ctx, (context(order=-1000000), fill(plot.theme.background_color), stroke(nothing), rectangle())) @@ -810,7 +810,7 @@ function render_prepared(plot::Plot, layer_aess), scales) # IV. Geometries - themes = Theme[isnothing(layer.theme) ? plot.theme : layer.theme + themes = Theme[layer.theme === nothing ? plot.theme : layer.theme for layer in plot.layers] zips = trim_zip(plot.layers, layer_aess, layer_subplot_aess, layer_subplot_datas, themes) @@ -823,7 +823,7 @@ function render_prepared(plot::Plot, guide_contexts = Guide.PositionedGuide[] for guide in guides guide_context = render(guide, plot.theme, plot_aes, dynamic) - if !isnothing(guide_context) + if guide_context !== nothing append!(guide_contexts, guide_context) end end diff --git a/src/aesthetics.jl b/src/aesthetics.jl index ba5532f7b..2617831a1 100755 --- a/src/aesthetics.jl +++ b/src/aesthetics.jl @@ -102,7 +102,7 @@ function show(io::IO, data::Aesthetics) print(io, "Aesthetics(") for name in valid_aesthetics val = getfield(data, name) - if !ismissing(val) && !isnothing(val) + if !ismissing(val) && val !== nothing print(io, "\n ", string(name), "=") show(io, getfield(data, name)) end @@ -140,7 +140,7 @@ getindex(aes::Aesthetics, i::Integer, j::AbstractString) = getfield(aes, Symbol( function defined_aesthetics(aes::Aesthetics) vars = Set{Symbol}() for name in valid_aesthetics - isnothing(getfield(aes, name)) || push!(vars, name) + getfield(aes, name) === nothing || push!(vars, name) end vars end @@ -172,7 +172,7 @@ function assert_aesthetics_undefined(who::AbstractString, aes::Aesthetics, vars: end function assert_aesthetics_equal_length(who::AbstractString, aes::Aesthetics, vars::Symbol...) - defined_vars = Compat.Iterators.filter(var -> !isnothing(getfield(aes, var)), vars) + defined_vars = Compat.Iterators.filter(var -> getfield(aes, var) !== nothing, vars) if !isempty(defined_vars) n = length(getfield(aes, first(defined_vars))) @@ -198,7 +198,7 @@ end # function update!(a::Aesthetics, b::Aesthetics) for name in valid_aesthetics - !isnothing(getfield(b, name)) && setfield(a, name, getfield(b, name)) + getfield(b, name) !== nothing && setfield(a, name, getfield(b, name)) end nothing end @@ -234,9 +234,9 @@ function concat(aess) isviewmin = var in (:xviewmin, :yviewmin) isviewmax = var in (:xviewmax, :yviewmax) mumv = if isviewmin - isnothing(mu) ? mv : isnothing(mv) ? mu : min(mu, mv) + mu === nothing ? mv : mv === nothing ? mu : min(mu, mv) elseif isviewmax - isnothing(mu) ? mv : isnothing(mv) ? mu : max(mu, mv) + mu === nothing ? mv : mv === nothing ? mu : max(mu, mv) else cat_aes_var!(mu, mv) end#if @@ -308,13 +308,13 @@ end # function by_xy_group(aes::T, xgroup, ygroup, num_xgroups, num_ygroups) where T <: Union{Data, Aesthetics} - @assert isnothing(xgroup) || isnothing(ygroup) || length(xgroup) == length(ygroup) + @assert xgroup === nothing || ygroup === nothing || length(xgroup) == length(ygroup) n = num_ygroups m = num_xgroups - xrefs = isnothing(xgroup) ? [1] : xgroup - yrefs = isnothing(ygroup) ? [1] : ygroup + xrefs = xgroup === nothing ? [1] : xgroup + yrefs = ygroup === nothing ? [1] : ygroup aes_grid = Array{T}(undef, n, m) staging = Array{AbstractArray}(undef, n, m) @@ -322,7 +322,7 @@ function by_xy_group(aes::T, xgroup, ygroup, aes_grid[i, j] = T() end - isnothing(xgroup) && isnothing(ygroup) && return aes_grid + xgroup === nothing && ygroup === nothing && return aes_grid function make_pooled_array(::Type{IndirectArray{T,N,A,V}}, arr::AbstractArray) where {T,N,A,V} uarr = unique(arr) @@ -345,8 +345,8 @@ function by_xy_group(aes::T, xgroup, ygroup, vals = getfield(aes, var) if typeof(vals) <: AbstractArray - if !isnothing(xgroup) && length(vals) !== length(xgroup) || - !isnothing(ygroup) && length(vals) !== length(ygroup) + if xgroup !== nothing && length(vals) !== length(xgroup) || + ygroup !== nothing && length(vals) !== length(ygroup) continue end @@ -400,12 +400,12 @@ function inherit!(a::Aesthetics, b::Aesthetics; bval = getfield(b, field) if field in clobber_set setfield!(a, field, bval) - elseif aval === missing || isnothing(aval) || aval === string || aval === showoff + elseif aval === missing || aval === nothing || aval === string || aval === showoff setfield!(a, field, bval) - elseif field in (:xviewmin, :yviewmin) && !isnothing(bval) - (isnothing(aval) || aval > bval) && setfield!(a, field, bval) - elseif field in (:xviewmax, :yviewmax) && !isnothing(bval) - (isnothing(aval) || aval < bval) && setfield!(a, field, bval) + elseif field in (:xviewmin, :yviewmin) && bval !== nothing + (aval === nothing || aval > bval) && setfield!(a, field, bval) + elseif field in (:xviewmax, :yviewmax) && bval !== nothing + (aval === nothing || aval < bval) && setfield!(a, field, bval) elseif typeof(aval) <: Dict && typeof(bval) <: Dict merge!(aval, getfield(b, field)) end diff --git a/src/coord.jl b/src/coord.jl index d70837ff1..9d3c1784a 100644 --- a/src/coord.jl +++ b/src/coord.jl @@ -67,7 +67,7 @@ function first_concrete_aesthetic_value(aess::Vector{Gadfly.Aesthetics}, vars::V for var in vars for aes in aess vals = getfield(aes, var) - Gadfly.isnothing(vals) && continue + vals === nothing && continue if !isa(vals, AbstractArray) vals = [vals] @@ -106,7 +106,7 @@ function aesthetics_type(aess::Vector{Gadfly.Aesthetics}, for var in vars for aes in aess vals = getfield(aes, var) - Gadfly.isnothing(vals) && continue + vals === nothing && continue if var == :outliers if !isempty(vals) @@ -153,11 +153,11 @@ function apply_coordinate(coord::Cartesian, aess::Vector{Gadfly.Aesthetics}, xmin = xmax = first_concrete_aesthetic_value(aess, coord.xvars) - if !Gadfly.isnothing(xmin) + if xmin !== nothing for var in coord.xvars for aes in aess vals = getfield(aes, var) - Gadfly.isnothing(vals) && continue + vals === nothing && continue if !isa(vals, AbstractArray) vals = [vals] @@ -169,11 +169,11 @@ function apply_coordinate(coord::Cartesian, aess::Vector{Gadfly.Aesthetics}, end ymin = ymax = first_concrete_aesthetic_value(aess, coord.yvars) - if !Gadfly.isnothing(ymin) + if ymin !== nothing for var in coord.yvars for aes in aess vals = getfield(aes, var) - Gadfly.isnothing(vals) && continue + vals === nothing && continue # Outliers is an odd aesthetic that needs special treatment. if var == :outliers @@ -196,40 +196,40 @@ function apply_coordinate(coord::Cartesian, aess::Vector{Gadfly.Aesthetics}, # viewmin/max that is set explicitly should override min/max for aes in aess - if !Gadfly.isnothing(aes.xviewmin) - xviewmin = Gadfly.isnothing(xviewmin) ? aes.xviewmin : min(xviewmin, aes.xviewmin) + if aes.xviewmin !== nothing + xviewmin = xviewmin === nothing ? aes.xviewmin : min(xviewmin, aes.xviewmin) end - if !Gadfly.isnothing(aes.xviewmax) - xviewmax = Gadfly.isnothing(xviewmax) ? aes.xviewmax : max(xviewmax, aes.xviewmax) + if aes.xviewmax !== nothing + xviewmax = xviewmax === nothing ? aes.xviewmax : max(xviewmax, aes.xviewmax) end - if !Gadfly.isnothing(aes.yviewmin) - yviewmin = Gadfly.isnothing(yviewmin) ? aes.yviewmin : min(yviewmin, aes.yviewmin) + if aes.yviewmin !== nothing + yviewmin = yviewmin === nothing ? aes.yviewmin : min(yviewmin, aes.yviewmin) end - if !Gadfly.isnothing(aes.yviewmax) - yviewmax = Gadfly.isnothing(yviewmax) ? aes.yviewmax : max(yviewmax, aes.yviewmax) + if aes.yviewmax !== nothing + yviewmax = yviewmax === nothing ? aes.yviewmax : max(yviewmax, aes.yviewmax) end end - xmax = Gadfly.isnothing(xviewmax) ? xmax : max(xmax, xviewmax) - xmin = Gadfly.isnothing(xviewmin) ? xmin : min(xmin, xviewmin) - ymax = Gadfly.isnothing(yviewmax) ? ymax : max(ymax, yviewmax) - ymin = Gadfly.isnothing(yviewmin) ? ymin : min(ymin, yviewmin) + xmax = xviewmax === nothing ? xmax : max(xmax, xviewmax) + xmin = xviewmin === nothing ? xmin : min(xmin, xviewmin) + ymax = yviewmax === nothing ? ymax : max(ymax, yviewmax) + ymin = yviewmin === nothing ? ymin : min(ymin, yviewmin) # Hard limits set in Coord should override everything else - xmin = Gadfly.isnothing(coord.xmin) ? xmin : coord.xmin - xmax = Gadfly.isnothing(coord.xmax) ? xmax : coord.xmax - ymin = Gadfly.isnothing(coord.ymin) ? ymin : coord.ymin - ymax = Gadfly.isnothing(coord.ymax) ? ymax : coord.ymax + xmin = coord.xmin === nothing ? xmin : coord.xmin + xmax = coord.xmax === nothing ? xmax : coord.xmax + ymin = coord.ymin === nothing ? ymin : coord.ymin + ymax = coord.ymax === nothing ? ymax : coord.ymax - if Gadfly.isnothing(xmin) || !isfinite(xmin) + if xmin === nothing || !isfinite(xmin) xmin = 0.0 xmax = 1.0 end - if Gadfly.isnothing(ymin) || !isfinite(ymin) + if ymin === nothing || !isfinite(ymin) ymin = 0.0 ymax = 1.0 end diff --git a/src/data.jl b/src/data.jl index 21fa375c7..4c63cae71 100644 --- a/src/data.jl +++ b/src/data.jl @@ -78,7 +78,7 @@ function show(io::IO, data::Data) maxlen = 0 print(io, "Data(") for name in data_fields - if !isnothing(getfield(data, name)) + if getfield(data, name) !== nothing print(io, "\n ", string(name), "=") show(io, getfield(data, name)) end diff --git a/src/dataframes.jl b/src/dataframes.jl index 2a7c6ddf3..eeb4e76ba 100644 --- a/src/dataframes.jl +++ b/src/dataframes.jl @@ -11,7 +11,7 @@ function meltdata(U::AbstractDataFrame, colgroups_::Vector{Col.GroupedColumn}) vm = um grouped_columns = Set{Symbol}() for colgroup in colgroups - if isnothing(colgroup.columns) # null => group all columns + if colgroup.columns === nothing # null => group all columns vm *= un grouped_columns = copy(allcolumns) else @@ -34,7 +34,7 @@ function meltdata(U::AbstractDataFrame, colgroups_::Vector{Col.GroupedColumn}) # allocate vectors for grouped columns for (j, colgroup) in enumerate(colgroups) - cols = isnothing(colgroup.columns) ? allcolumns : colgroup.columns + cols = colgroup.columns === nothing ? allcolumns : colgroup.columns # figure the grouped common column type firstcol = U[first(cols)] @@ -64,7 +64,7 @@ function meltdata(U::AbstractDataFrame, colgroups_::Vector{Col.GroupedColumn}) col_indicators = Array{Symbol}(undef, vm, length(colgroups)) row_indicators = Array{Int}(undef, vm, length(colgroups)) - colidxs = [isnothing(colgroup.columns) ? collect(allcolumns) : colgroup.columns + colidxs = [colgroup.columns === nothing ? collect(allcolumns) : colgroup.columns for colgroup in colgroups] vi = 1 diff --git a/src/geom/bar.jl b/src/geom/bar.jl index 6348072c2..697de3061 100644 --- a/src/geom/bar.jl +++ b/src/geom/bar.jl @@ -74,7 +74,7 @@ function render_bar(geom::BarGeometry, svgclass("geometry")) end - cs = isnothing(aes.color) ? theme.default_color : aes.color + cs = aes.color === nothing ? theme.default_color : aes.color compose!(ctx, fill(cs), svgclass("geometry")) if isa(theme.bar_highlight, Function) compose!(ctx, stroke(theme.bar_highlight(theme.default_color))) @@ -272,7 +272,7 @@ function render(geom::BarGeometry, theme::Gadfly.Theme, aes::Gadfly.Aesthetics) error("Orientation must be :horizontal or :vertical") end - if isnothing(aes.color) + if aes.color === nothing ctx = render_bar(geom, theme, aes, geom.orientation) elseif geom.position == :stack if geom.orientation == :horizontal diff --git a/src/geom/boxplot.jl b/src/geom/boxplot.jl index f47cb55eb..c56a8bcb4 100644 --- a/src/geom/boxplot.jl +++ b/src/geom/boxplot.jl @@ -123,7 +123,7 @@ function render(geom::BoxplotGeometry, theme::Gadfly.Theme, aes::Gadfly.Aestheti svgclass("geometry")) # Outliers - if !geom.suppress_outliers && !isnothing(aes.outliers) && !isempty(aes.outliers) + if !geom.suppress_outliers && aes.outliers !== nothing && !isempty(aes.outliers) xys = collect(Iterators.flatten(zip(cycle([x]), ys, cycle([c])) for (x, ys, c) in zip(xs, aes.outliers, cs))) compose!(ctx, (context(), @@ -133,7 +133,7 @@ function render(geom::BoxplotGeometry, theme::Gadfly.Theme, aes::Gadfly.Aestheti end # Middle - if !isnothing(aes.middle) + if aes.middle !== nothing compose!(ctx, ( context(order=1), Compose.line([[(x - fw/2, mid), (x + fw/2, mid)] diff --git a/src/geom/errorbar.jl b/src/geom/errorbar.jl index 67ce96d30..2e5bfb4a0 100644 --- a/src/geom/errorbar.jl +++ b/src/geom/errorbar.jl @@ -110,7 +110,7 @@ function render(geom::YErrorBarGeometry, theme::Gadfly.Theme, aes::Gadfly.Aesthe stroke([theme.stroke_color(c) for c in aes.color]), linewidth(theme.line_width)) - (aes.color_key_continuous == true || isnothing(aes.color)) || compose!(ctx, + (aes.color_key_continuous == true || aes.color === nothing) || compose!(ctx, svgclass([svg_color_class_from_label(aes.color_label([c])[1]) for c in aes.color])) return ctx @@ -148,7 +148,7 @@ function render(geom::XErrorBarGeometry, theme::Gadfly.Theme, aes::Gadfly.Aesthe stroke([theme.stroke_color(c) for c in aes.color]), linewidth(theme.line_width)) - (aes.color_key_continuous == true || isnothing(aes.color)) || compose!(ctx, + (aes.color_key_continuous == true || aes.color === nothing) || compose!(ctx, svgclass([svg_color_class_from_label(aes.color_label([c])[1]) for c in aes.color])) diff --git a/src/geom/hvabline.jl b/src/geom/hvabline.jl index 69fa4968f..ca8e86000 100755 --- a/src/geom/hvabline.jl +++ b/src/geom/hvabline.jl @@ -18,7 +18,7 @@ struct HLineGeometry <: Gadfly.GeometryElement tag::Symbol HLineGeometry(color, size, style, tag) = - new(isnothing(color) ? nothing : Gadfly.parse_colorant(color), size, style, tag) + new(color === nothing ? nothing : Gadfly.parse_colorant(color), size, style, tag) end HLineGeometry(; color=nothing, size=nothing, style=nothing, tag=empty_tag) = HLineGeometry(color, size, style, tag) @@ -36,9 +36,9 @@ element_aesthetics(::HLineGeometry) = [:yintercept] function render(geom::HLineGeometry, theme::Gadfly.Theme, aes::Gadfly.Aesthetics) Gadfly.assert_aesthetics_defined("Geom.hline", aes, :yintercept) - color = isnothing(geom.color) ? theme.default_color : geom.color - size = isnothing(geom.size) ? theme.line_width : geom.size - style = isnothing(geom.style) ? theme.line_style[1] : geom.style + color = geom.color === nothing ? theme.default_color : geom.color + size = geom.size === nothing ? theme.line_width : geom.size + style = geom.style === nothing ? theme.line_style[1] : geom.style color = check_arguments(color, length(aes.yintercept)) size = check_arguments(size, length(aes.yintercept)) @@ -65,7 +65,7 @@ struct VLineGeometry <: Gadfly.GeometryElement tag::Symbol VLineGeometry(color, size, style, tag) = - new(isnothing(color) ? nothing : Gadfly.parse_colorant(color), size, style, tag) + new(color === nothing ? nothing : Gadfly.parse_colorant(color), size, style, tag) end VLineGeometry(; color=nothing, size=nothing, style=nothing, tag=empty_tag) = VLineGeometry(color, size, style, tag) @@ -83,9 +83,9 @@ element_aesthetics(::VLineGeometry) = [:xintercept] function render(geom::VLineGeometry, theme::Gadfly.Theme, aes::Gadfly.Aesthetics) Gadfly.assert_aesthetics_defined("Geom.vline", aes, :xintercept) - color = isnothing(geom.color) ? theme.default_color : geom.color - size = isnothing(geom.size) ? theme.line_width : geom.size - style = isnothing(geom.style) ? theme.line_style[1] : geom.style + color = geom.color === nothing ? theme.default_color : geom.color + size = geom.size === nothing ? theme.line_width : geom.size + style = geom.style === nothing ? theme.line_style[1] : geom.style color = check_arguments(color, length(aes.xintercept)) size = check_arguments(size, length(aes.xintercept)) @@ -112,7 +112,7 @@ struct ABLineGeometry <: Gadfly.GeometryElement tag::Symbol ABLineGeometry(color, size, style, tag) = - new(isnothing(color) ? nothing : Gadfly.parse_colorant(color), size, style, tag) + new(color === nothing ? nothing : Gadfly.parse_colorant(color), size, style, tag) end ABLineGeometry(; color=nothing, size=nothing, style=nothing, tag::Symbol=empty_tag) = ABLineGeometry(color, size, style, tag) @@ -131,19 +131,19 @@ const abline = ABLineGeometry element_aesthetics(geom::ABLineGeometry) = [:intercept, :slope] function render(geom::ABLineGeometry, theme::Gadfly.Theme, aes::Gadfly.Aesthetics) - if isnothing(aes.intercept) && isnothing(aes.slope) + if aes.intercept === nothing && aes.slope === nothing aes.intercept = [0] aes.slope = [1] - elseif isnothing(aes.intercept) + elseif aes.intercept === nothing aes.intercept = fill(0,length(aes.slope)) - elseif isnothing(aes.slope) + elseif aes.slope === nothing aes.slope = fill(1,length(aes.intercept)) end Gadfly.assert_aesthetics_equal_length("Geom.line", aes, element_aesthetics(geom)...) - color = isnothing(geom.color) ? theme.default_color : geom.color - size = isnothing(geom.size) ? theme.line_width : geom.size - style = isnothing(geom.style) ? theme.line_style[1] : geom.style + color = geom.color === nothing ? theme.default_color : geom.color + size = geom.size === nothing ? theme.line_width : geom.size + style = geom.style === nothing ? theme.line_style[1] : geom.style color = check_arguments(color, length(aes.intercept)) size = check_arguments(size, length(aes.intercept)) diff --git a/src/geom/label.jl b/src/geom/label.jl index 48fca4d70..94a277c60 100644 --- a/src/geom/label.jl +++ b/src/geom/label.jl @@ -50,7 +50,7 @@ function deferred_label_context(geom::LabelGeometry, num_labels = length(aes.label) - if isnothing(aes.size) + if aes.size === nothing padding = fill(theme.point_size, num_labels) .+ theme.label_padding else padding = aes.size .+ theme.label_padding @@ -279,7 +279,7 @@ function render(geom::LabelGeometry, theme::Gadfly.Theme, aes::Gadfly.Aesthetics end hpos, vpos, xoff, yoff = label_layouts[geom.position] - if isnothing(aes.size) + if aes.size === nothing offsets = [(xoff*(theme.point_size + theme.label_padding), yoff*(theme.point_size + theme.label_padding))] else diff --git a/src/geom/point.jl b/src/geom/point.jl index beabffa94..a98e4fc95 100644 --- a/src/geom/point.jl +++ b/src/geom/point.jl @@ -67,7 +67,7 @@ function render(geom::PointGeometry, theme::Gadfly.Theme, aes::Gadfly.Aesthetics for (x, y, color, size, shape, alpha) in Compose.cyclezip(aes.x, aes.y, aes.color, aes.size, aes.shape, aes_alpha) shapefun = typeof(shape) <: Function ? shape : theme.point_shapes[shape] sizeval = typeof(size) <: Int ? interpolate_size(size) : size - strokecolor = !isnothing(aes.color_key_continuous) && aes.color_key_continuous ? + strokecolor = aes.color_key_continuous !== nothing && aes.color_key_continuous ? theme.continuous_highlight_color(color) : theme.discrete_highlight_color(color) class = svg_color_class_from_label(aes.color_label([color])[1]) diff --git a/src/geom/rectbin.jl b/src/geom/rectbin.jl index b998fac0f..8a2ae0c81 100644 --- a/src/geom/rectbin.jl +++ b/src/geom/rectbin.jl @@ -94,7 +94,7 @@ function render(geom::RectangularBinGeometry, theme::Gadfly.Theme, aes::Gadfly.A allvisible = true for c in cs - if isnothing(c) + if c === nothing allvisible = false break end diff --git a/src/geom/subplot.jl b/src/geom/subplot.jl index a4c247780..abd4955f7 100644 --- a/src/geom/subplot.jl +++ b/src/geom/subplot.jl @@ -136,7 +136,7 @@ function render(geom::SubplotGrid, theme::Gadfly.Theme, inherited_aes = element_aesthetics(layer.geom) push!(inherited_aes, :xgroup, :ygroup) for var in inherited_aes - if isnothing(getfield(layer_aes, var)) + if getfield(layer_aes, var) === nothing setfield!(layer_aes, var, getfield(superplot_aes, var)) end end @@ -144,17 +144,17 @@ function render(geom::SubplotGrid, theme::Gadfly.Theme, # z for (layer_data, layer_aes) in zip(subplot_layer_datas, subplot_layer_aess) z = getfield(layer_data, :z) - (!isnothing(z)) && setfield!(layer_aes, :z, z) + (z !== nothing) && setfield!(layer_aes, :z, z) end # work out the grid size m = 1 n = 1 for layer_aes in subplot_layer_aess - if !isnothing(layer_aes.xgroup) + if layer_aes.xgroup !== nothing m = max(m, maximum(layer_aes.xgroup)) end - if !isnothing(layer_aes.ygroup) + if layer_aes.ygroup !== nothing n = max(n, maximum(layer_aes.ygroup)) end end @@ -315,7 +315,7 @@ function render(geom::SubplotGrid, theme::Gadfly.Theme, if i == n push!(guides, get(geom.guides, Guide.XTicks, Guide.xticks())) - if !isnothing(superplot_aes.xgroup) + if superplot_aes.xgroup !== nothing push!(guides, get(geom.guides, Guide.XLabel, Guide.xlabel(xlabels[j]))) end else @@ -326,7 +326,7 @@ function render(geom::SubplotGrid, theme::Gadfly.Theme, if j == 1 joff += 1 push!(guides, get(geom.guides, Guide.YTicks, Guide.yticks())) - if !isnothing(superplot_aes.ygroup) + if superplot_aes.ygroup !== nothing joff += 1 push!(guides, get(geom.guides, Guide.YLabel, Guide.ylabel(ylabels[i]))) end @@ -349,7 +349,7 @@ function render(geom::SubplotGrid, theme::Gadfly.Theme, # copy over the correct units, since we are reparenting the children for u in 1:size(subtbl, 1), v in 1:size(subtbl, 2) for child in subtbl[u, v] - if isnothing(child.units) + if child.units === nothing child.units = subtbl.units end end diff --git a/src/geometry.jl b/src/geometry.jl index 377bf07b3..125410f34 100644 --- a/src/geometry.jl +++ b/src/geometry.jl @@ -13,7 +13,7 @@ import Compose.combine # Prevent DataFrame.combine from taking over. import Gadfly: render, layers, element_aesthetics, inherit, escape_id, default_statistic, default_scales, element_coordinate_type, ScaleElement, svg_color_class_from_label, isconcrete, - concretize, discretize_make_ia, isnothing + concretize, discretize_make_ia import IterTools: distinct, takestrict import Compat.Iterators: cycle, product, repeated diff --git a/src/guide.jl b/src/guide.jl index 32162cbca..ab64e060f 100644 --- a/src/guide.jl +++ b/src/guide.jl @@ -9,7 +9,7 @@ using IterTools using JSON import Gadfly: render, escape_id, default_statistic, jsdata, jsplotdata, - svg_color_class_from_label, isnothing + svg_color_class_from_label # Where the guide should be placed in relation to the plot. @@ -35,7 +35,7 @@ const questionmark = QuestionMark function render(guide::QuestionMark, theme::Gadfly.Theme, aes::Gadfly.Aesthetics) - text_color = isnothing(theme.background_color) ? + text_color = theme.background_color === nothing ? colorant"black" : distinguishable_colors(2,theme.background_color)[2] text_box = compose!( context(), text(1w,0h+2px,"?",hright,vtop), @@ -64,7 +64,7 @@ const helpscreen = HelpScreen function render(guide::HelpScreen, theme::Gadfly.Theme, aes::Gadfly.Aesthetics) - box_color = isnothing(theme.background_color) ? + box_color = theme.background_color === nothing ? colorant"black" : distinguishable_colors(2,theme.background_color)[2] text_color = distinguishable_colors(2,box_color)[2] text_strings = ["h,j,k,l,arrows,drag to pan", @@ -104,7 +104,7 @@ const crosshair = CrossHair function render(guide::CrossHair, theme::Gadfly.Theme, aes::Gadfly.Aesthetics) - text_color = isnothing(theme.background_color) ? + text_color = theme.background_color === nothing ? colorant"black" : distinguishable_colors(2,theme.background_color)[2] text_box = compose!( context(), @@ -262,7 +262,7 @@ function render_discrete_color_key(colors::Vector{C}, fill(theme.key_label_color)) col = compose!(context(xpos, yoff), swatches, swatch_labels) - if !isnothing(aes_color_label) + if aes_color_label !== nothing classes = [svg_color_class_from_label(aes_color_label([c])[1]) for c in cs] #class_jscalls = ["data(\"color_class\", \"$(c)\")" #for c in classes] @@ -395,7 +395,7 @@ function render(guide::ColorKey, theme::Gadfly.Theme, (theme.key_position == :none || isempty(aes.color_key_colors)) && return PositionedGuide[] gpos = guide.pos - (theme.key_position == :inside && isnothing(gpos)) && (gpos = [0.7w, 0.25h]) + (theme.key_position == :inside && gpos === nothing) && (gpos = [0.7w, 0.25h]) used_colors = Set{Color}() colors = Array{Color}(undef, 0) # to preserve ordering @@ -404,18 +404,18 @@ function render(guide::ColorKey, theme::Gadfly.Theme, continuous_guide = false guide_title = guide.title - if isnothing(guide_title) && !isnothing(aes.color_key_title) + if guide_title === nothing && aes.color_key_title !== nothing guide_title = aes.color_key_title end - if !isnothing(aes.color_key_colors) && - !isnothing(aes.color_key_continuous) && + if aes.color_key_colors !== nothing && + aes.color_key_continuous !== nothing && aes.color_key_continuous continuous_guide = true end color_key_labels = aes.color_label(keys(aes.color_key_colors)) - if !continuous_guide && !isnothing(guide.labels) + if !continuous_guide && guide.labels !== nothing color_key_labels = guide.labels end @@ -430,7 +430,7 @@ function render(guide::ColorKey, theme::Gadfly.Theme, end end - if isnothing(guide_title) + if guide_title === nothing guide_title = "Color" end @@ -457,7 +457,7 @@ function render(guide::ColorKey, theme::Gadfly.Theme, title_width, theme) end - if !isnothing(aes.shape) + if aes.shape !== nothing # TODO: Draw key for shapes. We need to think about how to make this # work. Do we need to optimize number of columns for shape and size # keys? I'm guessing it's not worth it. @@ -469,7 +469,7 @@ function render(guide::ColorKey, theme::Gadfly.Theme, end position = right_guide_position - if !isnothing(gpos) + if gpos !== nothing position = over_guide_position ctxs = [compose(context(), (context(gpos[1],gpos[2]), ctxs[1]))] elseif theme.key_position == :left @@ -517,11 +517,11 @@ function render(guide::ManualColorKey, theme::Gadfly.Theme, guide_title = guide.title - if isnothing(guide_title) && !isnothing(aes.color_key_title) + if guide_title === nothing && aes.color_key_title !== nothing guide_title = aes.color_key_title end - if isnothing(guide_title) + if guide_title === nothing guide_title = "Color" end @@ -569,13 +569,13 @@ visibility. `ticks` can also be an array of locations, or `nothing`. const xticks = XTicks default_statistic(guide::XTicks) = - isnothing(guide.ticks) ? Stat.identity() : Stat.xticks(ticks=guide.ticks) + guide.ticks === nothing ? Stat.identity() : Stat.xticks(ticks=guide.ticks) function render(guide::XTicks, theme::Gadfly.Theme, aes::Gadfly.Aesthetics, dynamic::Bool=true) - isnothing(guide.ticks) && return PositionedGuide[] + guide.ticks === nothing && return PositionedGuide[] - if !Gadfly.isnothing(aes.xtick) + if aes.xtick !== nothing ticks = aes.xtick tickvisibility = aes.xtickvisible scale = aes.xtickscale @@ -592,7 +592,7 @@ function render(guide::XTicks, theme::Gadfly.Theme, scale = Any[] end - if !Gadfly.isnothing(aes.xgrid) + if aes.xgrid !== nothing grids = aes.xgrid gridvisibility = length(grids) < length(ticks) ? tickvisibility[2:end] : tickvisibility else @@ -740,7 +740,7 @@ visibility. `ticks` can also be an array of locations, or `nothing`. const yticks = YTicks function default_statistic(guide::YTicks) - if isnothing(guide.ticks) + if guide.ticks === nothing return Stat.identity() else return Stat.yticks(ticks=guide.ticks) @@ -749,11 +749,11 @@ end function render(guide::YTicks, theme::Gadfly.Theme, aes::Gadfly.Aesthetics, dynamic::Bool=true) - if isnothing(guide.ticks) + if guide.ticks === nothing return PositionedGuide[] end - if !Gadfly.isnothing(aes.ytick) + if aes.ytick !== nothing ticks = aes.ytick tickvisibility = aes.ytickvisible scale = aes.ytickscale @@ -769,7 +769,7 @@ function render(guide::YTicks, theme::Gadfly.Theme, scale = Any[] end - if !Gadfly.isnothing(aes.ygrid) + if aes.ygrid !== nothing grids = aes.ygrid if length(grids) < length(ticks) gridvisibility = tickvisibility[2:end] @@ -919,7 +919,7 @@ const xlabel = XLabel function render(guide::XLabel, theme::Gadfly.Theme, aes::Gadfly.Aesthetics) - if isnothing(guide.label) || isempty(guide.label) + if guide.label === nothing || isempty(guide.label) return nothing end @@ -986,7 +986,7 @@ const ylabel = YLabel function render(guide::YLabel, theme::Gadfly.Theme, aes::Gadfly.Aesthetics) - if isnothing(guide.label) || isempty(guide.label) + if guide.label === nothing || isempty(guide.label) return nothing end @@ -1044,7 +1044,7 @@ const title = Title function render(guide::Title, theme::Gadfly.Theme, aes::Gadfly.Aesthetics) - if isnothing(guide.label) || isempty(guide.label) + if guide.label === nothing || isempty(guide.label) return nothing end @@ -1160,9 +1160,9 @@ function layout_guides(plot_context::Context, aspect_ratio = nothing if isa(coord, Gadfly.Coord.cartesian) if coord.fixed - aspect_ratio = isnothing(plot_context.units) ? 1.0 : + aspect_ratio = (plot_context.units === nothing) ? 1.0 : abs(plot_context.units.width / plot_context.units.height) - elseif !isnothing(coord.aspect_ratio) + elseif coord.aspect_ratio !== nothing aspect_ratio = coord.aspect_ratio end end @@ -1172,7 +1172,7 @@ function layout_guides(plot_context::Context, i = 1 for (ctxs, order) in guides[top_guide_position] for ctx in ctxs - if isnothing(ctx.units) && !isnothing(plot_units) + if ctx.units === nothing && plot_units !== nothing ctx.units = UnitBox(plot_units, toppad=0mm, bottompad=0mm) end end @@ -1183,7 +1183,7 @@ function layout_guides(plot_context::Context, i += 1 for (ctxs, order) in guides[bottom_guide_position] for ctx in ctxs - if isnothing(ctx.units) && !isnothing(plot_units) + if ctx.units === nothing && plot_units !== nothing ctx.units = UnitBox(plot_units, toppad=0mm, bottompad=0mm) end end @@ -1195,7 +1195,7 @@ function layout_guides(plot_context::Context, j = 1 for (ctxs, order) in guides[left_guide_position] for ctx in ctxs - if isnothing(ctx.units) && !isnothing(plot_units) + if ctx.units === nothing && plot_units !== nothing ctx.units = UnitBox(plot_units, leftpad=0mm, rightpad=0mm) end end @@ -1206,7 +1206,7 @@ function layout_guides(plot_context::Context, j += 1 for (ctxs, order) in guides[right_guide_position] for ctx in ctxs - if isnothing(ctx.units) && !isnothing(plot_units) + if ctx.units === nothing && plot_units !== nothing ctx.units = UnitBox(plot_units, leftpad=0mm, rightpad=0mm) end end diff --git a/src/guide/keys.jl b/src/guide/keys.jl index d9d9d77b2..f62568d00 100644 --- a/src/guide/keys.jl +++ b/src/guide/keys.jl @@ -32,11 +32,11 @@ function Guide.render(guide::Guide.ShapeKey, theme::Gadfly.Theme, aes::Gadfly.Ae # Aesthetics for keys: shape_key_title, shape_label (Function), shape_key_shapes (AbstractDict) nshapes = length(unique(aes.shape)) - guide_title = (guide.title!="Shape" || isnothing(aes.shape_key_title)) ? guide.title : aes.shape_key_title + guide_title = (guide.title!="Shape" || aes.shape_key_title === nothing) ? guide.title : aes.shape_key_title shape_key_labels = !(guide.labels==[""]) ? guide.labels : aes.shape_label(1:nshapes) colors = [nothing] - if !isnothing(aes.shape_key_title) && (aes.color_key_title==aes.shape_key_title) + if aes.shape_key_title !== nothing && (aes.color_key_title==aes.shape_key_title) colors = collect(keys(aes.color_key_colors)) end @@ -70,8 +70,8 @@ function render_discrete_key(labels::Vector{String}, title_ctx::Context, title_w n = max(length(colors), length(shapes)) shape1 = shapes[1] - shapes = isnothing(shape1) ? fill(theme.key_swatch_shape, n) : theme.point_shapes[shapes] - (isnothing(colors[1])) && (colors = fill((isnothing(theme.key_swatch_color)) ? theme.default_color : theme.key_swatch_color, n)) + shapes = shape1 === nothing ? fill(theme.key_swatch_shape, n) : theme.point_shapes[shapes] + (colors[1] === nothing) && (colors = fill((theme.key_swatch_color === nothing) ? theme.default_color : theme.key_swatch_color, n)) # only consider layouts with a reasonable number of columns maxcols = theme.key_max_columns < 1 ? 1 : theme.key_max_columns @@ -144,7 +144,7 @@ function render_discrete_key(labels::Vector{String}, title_ctx::Context, title_w fill(theme.key_label_color)) col = compose!(context(xpos, yoff), swatches, swatch_labels) - if !isnothing(aes_color_label) + if aes_color_label !== nothing classes = [svg_color_class_from_label(aes_color_label([c])[1]) for c in clrs] #class_jscalls = ["data(\"color_class\", \"$(c)\")" for c in classes] compose!(col, diff --git a/src/mapping.jl b/src/mapping.jl index 9a7d9cc1b..072f76696 100644 --- a/src/mapping.jl +++ b/src/mapping.jl @@ -87,7 +87,7 @@ end function meltdata(U::AbstractVector, colgroups_::Vector{Col.GroupedColumn}) colgroups = Set(colgroups_) - if length(colgroups) != 1 || !isnothing(first(colgroups).columns) + if length(colgroups) != 1 || first(colgroups).columns !== nothing # if every column is of the same length, treat it as a matrix if length(Set([length(u for u in U)])) == 1 return meltdata(cat(U..., dims=2), colgroups_) @@ -130,7 +130,7 @@ function meltdata(U::AbstractMatrix, colgroups_::Vector{Col.GroupedColumn}) vm = um grouped_columns = BitSet() for colgroup in colgroups - if isnothing(colgroup.columns) + if colgroup.columns === nothing vm *= un grouped_columns = copy(allcolumns) else @@ -149,7 +149,7 @@ function meltdata(U::AbstractMatrix, colgroups_::Vector{Col.GroupedColumn}) col_indicators = Array{Int}(undef, vm, length(colgroups)) row_indicators = Array{Int}(undef, vm, length(colgroups)) - colidxs = [isnothing(colgroup.columns) ? collect(allcolumns) : colgroup.columns + colidxs = [colgroup.columns === nothing ? collect(allcolumns) : colgroup.columns for colgroup in colgroups] vi = 1 diff --git a/src/misc.jl b/src/misc.jl index 5ddbcd80a..b1583a9f8 100644 --- a/src/misc.jl +++ b/src/misc.jl @@ -178,7 +178,7 @@ function inherit!(a::T, b::T) where T aval = getfield(a, field) bval = getfield(b, field) # TODO: this is a hack to let non-default labelers overide the defaults - if isnothing(aval) || aval === string || aval == showoff + if aval === nothing || aval === string || aval == showoff setfield!(a, field, bval) elseif typeof(aval) <: Dict && typeof(bval) <: Dict merge!(aval, getfield(b, field)) diff --git a/src/scale.jl b/src/scale.jl index a87692074..555806bc6 100644 --- a/src/scale.jl +++ b/src/scale.jl @@ -11,7 +11,7 @@ using CategoricalArrays using Printf import Gadfly: element_aesthetics, isconcrete, concrete_length, discretize_make_ia, - aes2str, valid_aesthetics, isnothing + aes2str, valid_aesthetics import Distributions: Distribution include("color_misc.jl") @@ -86,7 +86,7 @@ struct ContinuousScale <: Gadfly.ScaleElement function ContinuousScale(vars, trans, minvalue, maxvalue, minticks, maxticks, labels, format, scalable) - !isnothing(minvalue) && !isnothing(maxvalue) && minvalue > maxvalue && + minvalue !== nothing && maxvalue !== nothing && minvalue > maxvalue && error("Cannot construct a ContinuousScale with minvalue > maxvalue") new(vars, trans, minvalue, maxvalue, minticks, maxticks, labels, format, scalable) end @@ -100,9 +100,9 @@ function ContinuousScale(vars, trans; end function make_labeler(scale::ContinuousScale) - if !isnothing(scale.labels) + if scale.labels !== nothing xs -> [scale.labels(x) for x in xs] - elseif isnothing(scale.format) + elseif scale.format === nothing scale.trans.label else xs -> scale.trans.label(xs, scale.format) @@ -190,7 +190,7 @@ function apply_scale(scale::ContinuousScale, if vals isa CategoricalArray throw(ArgumentError("continuous scale for $var aesthetic when stored as a CategoricalArray. Consider using a discrete scale or convert data to an Array.")) end - isnothing(vals) && continue + vals === nothing && continue # special case for function arrays bound to :y # pass the function values through and wait for the scale to @@ -245,7 +245,7 @@ function apply_scale(scale::ContinuousScale, end end - if !isnothing(scale.minvalue) + if scale.minvalue !== nothing if scale.vars === x_vars aes.xviewmin = scale.trans.f(scale.minvalue) elseif scale.vars === y_vars @@ -253,7 +253,7 @@ function apply_scale(scale::ContinuousScale, end end - if !isnothing(scale.maxvalue) + if scale.maxvalue !== nothing if scale.vars === x_vars aes.xviewmax = scale.trans.f(scale.maxvalue) elseif scale.vars === y_vars @@ -272,7 +272,7 @@ end function discretize(values, levels=nothing, order=nothing, preserve_order=true) - if isnothing(levels) + if levels === nothing if preserve_order levels = OrderedSet() for value in values @@ -286,7 +286,7 @@ function discretize(values, levels=nothing, order=nothing, preserve_order=true) da = discretize_make_ia(values, levels) end - if !isnothing(order) + if order !== nothing return discretize_make_ia(da, da.values[order]) else return da @@ -370,13 +370,13 @@ function apply_scale(scale::DiscreteScale, aess::Vector{Gadfly.Aesthetics}, data for (aes, data) in zip(aess, datas) for var in scale.vars label_var = Symbol(var, "_label") - isnothing(getfield(data, var)) && continue + getfield(data, var) === nothing && continue disc_data = discretize(getfield(data, var), scale.levels, scale.order) setfield!(aes, var, discretize_make_ia(Int64.(disc_data.index))) # The leveler for discrete scales is a closure over the discretized data. - if isnothing(scale.labels) + if scale.labels === nothing function default_labeler(xs) lvls = filter(!ismissing, disc_data.values) vals = Any[1 <= x <= length(lvls) ? lvls[x] : "" for x in xs] @@ -435,7 +435,7 @@ element_aesthetics(scale::IdentityColorScale) = [:color] function apply_scale(scale::IdentityColorScale, aess::Vector{Gadfly.Aesthetics}, datas::Vector{Gadfly.Data}) for (aes, data) in zip(aess, datas) - isnothing(data.color) && continue + data.color === nothing && continue aes.color = discretize_make_ia(data.color) aes.color_key_colors = Dict() end @@ -519,7 +519,7 @@ function apply_scale(scale::DiscreteColorScale, aess::Vector{Gadfly.Aesthetics}, datas::Vector{Gadfly.Data}) levelset = OrderedSet() for (aes, data) in zip(aess, datas) - isnothing(data.color) && continue + data.color === nothing && continue for d in data.color # Remove missing values # FixMe! The handling of missing values shouldn't be this scattered across the source @@ -527,13 +527,13 @@ function apply_scale(scale::DiscreteColorScale, end end - if isnothing(scale.levels) + if scale.levels === nothing scale_levels = [levelset...] scale.preserve_order || sort!(scale_levels) else scale_levels = scale.levels end - isnothing(scale.order) || permute!(scale_levels, scale.order) + scale.order === nothing || permute!(scale_levels, scale.order) colors = convert(Vector{RGB{Float32}}, scale.f(length(scale_levels))) color_map = Dict([(color, string(label)) @@ -541,7 +541,7 @@ function apply_scale(scale::DiscreteColorScale, labeler(xs) = [color_map[x] for x in xs] for (aes, data) in zip(aess, datas) - isnothing(data.color) && continue + data.color === nothing && continue # Remove missing values # FixMe! The handling of missing values shouldn't be this scattered across the source ds = discretize([c for c in data.color if !ismissing(c)], scale_levels) @@ -625,7 +625,7 @@ const color_continuous_gradient = color_continuous ### WHY HAVE THIS ALIAS? function apply_scale(scale::ContinuousColorScale, aess::Vector{Gadfly.Aesthetics}, datas::Vector{Gadfly.Data}) - cdata = skipmissing(Iterators.flatten(i.color for i in datas if !isnothing(i.color))) + cdata = skipmissing(Iterators.flatten(i.color for i in datas if i.color !== nothing)) if !isempty(cdata) cmin, cmax = extrema(cdata) else @@ -633,9 +633,9 @@ function apply_scale(scale::ContinuousColorScale, end strict_span = false - !isnothing(scale.minvalue) && !isnothing(scale.maxvalue) && (strict_span=true) - !isnothing(scale.minvalue) && (cmin=scale.minvalue) - !isnothing(scale.maxvalue) && (cmax=scale.maxvalue) + scale.minvalue !== nothing && scale.maxvalue !== nothing && (strict_span=true) + scale.minvalue !== nothing && (cmin=scale.minvalue) + scale.maxvalue !== nothing && (cmax=scale.maxvalue) cmin, cmax = promote(cmin, cmax) @@ -649,7 +649,7 @@ function apply_scale(scale::ContinuousColorScale, cspan = cmax != cmin ? cmax - cmin : 1.0 for (aes, data) in zip(aess, datas) - isnothing(data.color) && continue + data.color === nothing && continue aes.color = Array{RGB{Float32}}(undef, length(data.color)) apply_scale_typed!(aes.color, data.color, scale, cmin, cspan) @@ -698,7 +698,7 @@ end function apply_scale(scale::LabelScale, aess::Vector{Gadfly.Aesthetics}, datas::Vector{Gadfly.Data}) for (aes, data) in zip(aess, datas) - isnothing(data.label) && continue + data.label === nothing && continue aes.label = discretize(data.label) end end @@ -738,7 +738,7 @@ element_aesthetics(scale::IdentityScale) = [scale.var] function apply_scale(scale::IdentityScale, aess::Vector{Gadfly.Aesthetics}, datas::Vector{Gadfly.Data}) for (aes, data) in zip(aess, datas) - isnothing(getfield(data, scale.var)) && continue + getfield(data, scale.var) === nothing && continue setfield!(aes, scale.var, getfield(data, scale.var)) end end diff --git a/src/statistics.jl b/src/statistics.jl index 6a2769d35..49ad28a88 100644 --- a/src/statistics.jl +++ b/src/statistics.jl @@ -17,8 +17,7 @@ using LinearAlgebra using Random import Gadfly: Scale, Coord, input_aesthetics, output_aesthetics, - default_scales, isconcrete, setfield!, discretize_make_ia, aes2str, - isnothing + default_scales, isconcrete, setfield!, discretize_make_ia, aes2str import KernelDensity # import Distributions: Uniform, Distribution, qqbuild import IterTools: distinct @@ -187,7 +186,7 @@ function apply_statistic(stat::BarStatistic, iscontinuous = haskey(scales, var) && isa(scales[var], Scale.ContinuousScale) - if isnothing(getfield(aes, minvar)) || isnothing(getfield(aes, maxvar)) + if getfield(aes, minvar) === nothing || getfield(aes, maxvar) === nothing minvals, maxvals = barminmax(vals, iscontinuous) setfield!(aes, minvar, minvals) @@ -195,13 +194,13 @@ function apply_statistic(stat::BarStatistic, end z = zero(eltype(getfield(aes, othervar))) - if isnothing(getfield(aes, viewminvar)) && z < minimum(getfield(aes, othervar)) + if getfield(aes, viewminvar) === nothing && z < minimum(getfield(aes, othervar)) setfield!(aes, viewminvar, z) - elseif isnothing(getfield(aes, viewmaxvar)) && z > maximum(getfield(aes, othervar)) + elseif getfield(aes, viewmaxvar) === nothing && z > maximum(getfield(aes, othervar)) setfield!(aes, viewmaxvar, z) end - if stat.position == :stack && !isnothing(aes.color) + if stat.position == :stack && aes.color !== nothing groups = Dict{Any,Float64}() for (x, y) in zip(getfield(aes, othervar), vals) Gadfly.isconcrete(x) || continue @@ -215,11 +214,11 @@ function apply_statistic(stat::BarStatistic, viewmin, viewmax = extrema(values(groups)) aes_viewminvar = getfield(aes, viewminvar) - if isnothing(aes_viewminvar) || aes_viewminvar > viewmin + if aes_viewminvar === nothing || aes_viewminvar > viewmin setfield!(aes, viewminvar, viewmin) end aes_viewmaxvar = getfield(aes, viewmaxvar) - if isnothing(aes_viewmaxvar) || aes_viewmaxvar < viewmax + if aes_viewmaxvar === nothing || aes_viewmaxvar < viewmax setfield!(aes, viewmaxvar, viewmax) end end @@ -250,7 +249,7 @@ function HistogramStatistic(; bincount=nothing, orientation=:vertical, density=false, limits=NamedTuple()) - if !isnothing(bincount) + if bincount !== nothing HistogramStatistic(bincount, bincount, position, orientation, density, limits) else HistogramStatistic(minbincount, maxbincount, position, orientation, density, limits) @@ -341,7 +340,7 @@ function apply_statistic(stat::HistogramStatistic, stat.density && (bincounts = bincounts ./ (sum(bincounts) * binwidth)) - if isnothing(aes.color) + if aes.color === nothing T = typeof(x_min + 1*binwidth) setfield!(aes, othervar, Array{Float64}(undef, d)) setfield!(aes, minvar, Array{T}(undef, d)) @@ -399,7 +398,7 @@ function apply_statistic(stat::HistogramStatistic, if stat.position == :stack viewmax = Float64(maximum(stack_height)) aes_viewmax = getfield(aes, viewmaxvar) - if isnothing(aes_viewmax) || aes_viewmax < viewmax + if aes_viewmax === nothing || aes_viewmax < viewmax setfield!(aes, viewmaxvar, viewmax) end end @@ -407,7 +406,7 @@ function apply_statistic(stat::HistogramStatistic, aes.color = discretize_make_ia(colors) end - isnothing(getfield(aes, viewminvar)) && setfield!(aes, viewminvar, 0.0) + getfield(aes, viewminvar) === nothing && setfield!(aes, viewminvar, 0.0) if haskey(scales, othervar) data = Gadfly.Data() @@ -418,7 +417,7 @@ function apply_statistic(stat::HistogramStatistic, # See issue #560. Stacked histograms on a non-linear y scale are a strange # thing. After some discussion, the least confusing thing is to make the stack # partitioned linearly. Here we make that adjustment. - if stat.position == :stack && !isnothing(aes.color) + if stat.position == :stack && aes.color !== nothing # A little trickery to figure out the scale stack height. data = Gadfly.Data() setfield!(data, othervar, stack_height) @@ -512,7 +511,7 @@ function apply_statistic(stat::DensityStatistic, aes::Gadfly.Aesthetics) Gadfly.assert_aesthetics_defined("DensityStatistic", aes, :x) - if isnothing(aes.color) + if aes.color === nothing isa(aes.x[1], Real) || error("Kernel density estimation only works on Real types.") x_f64 = collect(Float64, aes.x) @@ -562,12 +561,12 @@ function Histogram2DStatistic(; xbincount=nothing, ybincount=nothing, yminbincount=3, ymaxbincount=150) - if !isnothing(xbincount) + if xbincount !== nothing xminbincount = xbincount xmaxbincount = xbincount end - if !isnothing(ybincount) + if ybincount !== nothing yminbincount = ybincount ymaxbincount = ybincount end @@ -771,7 +770,7 @@ function apply_statistic(stat::TickStatistic, error("TickStatistic cannot be applied to subplot coordinates.") # don't clobber existing ticks - isnothing(getfield(aes, Symbol(stat.axis, "tick"))) || return + getfield(aes, Symbol(stat.axis, "tick")) === nothing || return in_group_var = Symbol(stat.axis, "group") minval, maxval = nothing, nothing @@ -782,11 +781,11 @@ function apply_statistic(stat::TickStatistic, for var in in_vars categorical && !in(var,[:x,:y]) && continue vals = getfield(aes, var) - if !isnothing(vals) && eltype(vals) != Function - if isnothing(minval) + if vals !== nothing && eltype(vals) != Function + if minval === nothing minval = first(vals) end - if isnothing(maxval) + if maxval === nothing maxval = first(vals) end T = promote_type(typeof(minval), typeof(maxval)) @@ -795,14 +794,14 @@ function apply_statistic(stat::TickStatistic, maxval = convert(T, maxval) if stat.axis == "x" - dsize = isnothing(aes.xsize) ? [nothing] : aes.xsize + dsize = aes.xsize === nothing ? [nothing] : aes.xsize elseif stat.axis == "y" - dsize = isnothing(aes.ysize) ? [nothing] : aes.ysize + dsize = aes.ysize === nothing ? [nothing] : aes.ysize else dsize = [nothing] end - size = isnothing(aes.size) ? [nothing] : aes.size + size = aes.size === nothing ? [nothing] : aes.size minval, maxval = apply_statistic_typed(minval, maxval, vals, size, dsize) push!(in_vals, vals) @@ -825,17 +824,17 @@ function apply_statistic(stat::TickStatistic, # check the x/yviewmin/max pesudo-aesthetics if stat.axis == "x" - if !isnothing(aes.xviewmin) + if aes.xviewmin !== nothing minval = min(minval, aes.xviewmin) end - if !isnothing(aes.xviewmax) + if aes.xviewmax !== nothing maxval = max(maxval, aes.xviewmax) end elseif stat.axis == "y" - if !isnothing(aes.yviewmin) + if aes.yviewmin !== nothing minval = min(minval, aes.yviewmin) end - if !isnothing(aes.yviewmax) + if aes.yviewmax !== nothing maxval = max(maxval, aes.yviewmax) end end @@ -844,20 +843,20 @@ function apply_statistic(stat::TickStatistic, strict_span = false if typeof(coord) == Coord.Cartesian if stat.axis == "x" - if !isnothing(coord.xmin) + if coord.xmin !== nothing minval = coord.xmin strict_span = true end - if !isnothing(coord.xmax) + if coord.xmax !== nothing maxval = coord.xmax strict_span = true end elseif stat.axis == "y" - if !isnothing(coord.ymin) + if coord.ymin !== nothing minval = coord.ymin strict_span = true end - if !isnothing(coord.ymax) + if coord.ymax !== nothing maxval = coord.ymax strict_span = true end @@ -924,12 +923,12 @@ function apply_statistic(stat::TickStatistic, setfield!(aes, Symbol(stat.axis, "tickscale"), tickscale) viewmin_var = Symbol(stat.axis, "viewmin") - if isnothing(getfield(aes, viewmin_var)) || getfield(aes, viewmin_var) > viewmin + if getfield(aes, viewmin_var) === nothing || getfield(aes, viewmin_var) > viewmin setfield!(aes, viewmin_var, viewmin) end viewmax_var = Symbol(stat.axis, "viewmax") - if isnothing(getfield(aes, viewmax_var)) || getfield(aes, viewmax_var) < viewmax + if getfield(aes, viewmax_var) === nothing || getfield(aes, viewmax_var) < viewmax setfield!(aes, viewmax_var, viewmax) end @@ -960,12 +959,12 @@ function minvalmaxval(minval::T, maxval::T, val, s, ds) where T maxval = val end - if !isnothing(s) && typeof(s) <: AbstractFloat + if s !== nothing && typeof(s) <: AbstractFloat minval = min(minval, val - s)::T maxval = max(maxval, val + s)::T end - if !isnothing(ds) + if ds !== nothing minval = min(minval, val - ds)::T maxval = max(maxval, val + ds)::T end @@ -1000,7 +999,7 @@ function apply_statistic(stat::BoxplotStatistic, coord::Gadfly.CoordinateElement, aes::Gadfly.Aesthetics) - xflag = !isnothing(aes.x) + xflag = aes.x !== nothing aes_x = (xflag ? eltype(aes.x) : Int)[] if xflag aes_x = aes.x @@ -1008,26 +1007,26 @@ function apply_statistic(stat::BoxplotStatistic, aes_x = ones(Int, length(aes.y)) aes.x_label = x -> fill("", length(x)) end - colorflag = !isnothing(aes.color) + colorflag = aes.color !== nothing aes_color = colorflag ? aes.color : fill(nothing, length(aes_x)) - if isnothing(aes.y) + if aes.y === nothing groups = Any[] for (x, c) in zip(aes.x, cycle(aes_color)) push!(groups, (x, c)) end yviewmin, yviewmax = minimum(aes.lower_fence), maximum(aes.upper_fence) - if !isnothing(aes.outliers) + if aes.outliers !== nothing yviewmin = minimum(yviewmin, aes.outliers) yviewmax = maximum(yviewmax, aes.outliers) end - if isnothing(aes.yviewmin) || aes.yviewmin > yviewmin + if aes.yviewmin === nothing || aes.yviewmin > yviewmin aes.yviewmin = yviewmin end - if isnothing(aes.yviewmax) || aes.yviewmax < yviewmax + if aes.yviewmax === nothing || aes.yviewmax < yviewmax aes.yviewmax = yviewmax end else @@ -1083,11 +1082,11 @@ function apply_statistic(stat::BoxplotStatistic, xviewmin = xmin - minspan / 2 xviewmax = xmax + minspan / 2 - if isnothing(aes.xviewmin) || aes.xviewmin > xviewmin + if aes.xviewmin === nothing || aes.xviewmin > xviewmin aes.xviewmin = xviewmin end - if isnothing(aes.xviewmax) || aes.xviewmax < xviewmax + if aes.xviewmax === nothing || aes.xviewmax < xviewmax aes.xviewmax = xviewmax end end @@ -1151,7 +1150,7 @@ function Stat.apply_statistic(stat::SmoothStatistic, error("Stat.loess and Stat.lm require that x and y be bound to arrays of plain numbers.") end - colorflag = !isnothing(aes.color) + colorflag = aes.color !== nothing aes_color = colorflag ? aes.color : fill(nothing, length(aes.x)) uc = unique(aes_color) @@ -1309,18 +1308,18 @@ function apply_statistic(stat::StepStatistic, p = sortperm(aes.x, alg=MergeSort) permute!(aes.x, p) permute!(aes.y, p) - !isnothing(aes.group) && permute!(aes.group, p) - !isnothing(aes.color) && permute!(aes.color, p) + aes.group !== nothing && permute!(aes.group, p) + aes.color !== nothing && permute!(aes.color, p) - if !isnothing(aes.group) + if aes.group !== nothing Gadfly.assert_aesthetics_equal_length("StepStatistic", aes, :x, :group) permute!(aes.x, p) permute!(aes.y, p) permute!(aes.group, p) - !isnothing(aes.color) && permute!(aes.color, p) + aes.color !== nothing && permute!(aes.color, p) end - if !isnothing(aes.color) + if aes.color !== nothing Gadfly.assert_aesthetics_equal_length("StepStatistic", aes, :x, :color) # TODO: use this when we switch to 0.4 # sortperm!(p, aes.color, alg=MergeSort, lt=Gadfly.color_isless) @@ -1328,13 +1327,13 @@ function apply_statistic(stat::StepStatistic, permute!(aes.x, p) permute!(aes.y, p) permute!(aes.color, p) - !isnothing(aes.group) && permute!(aes.group, p) + aes.group !== nothing && permute!(aes.group, p) end x_step = Array{eltype(aes.x)}(undef, 0) y_step = Array{eltype(aes.y)}(undef, 0) - color_step = isnothing(aes.color) ? nothing : Array{eltype(aes.color)}(undef, 0) - group_step = isnothing(aes.group) ? nothing : Array{eltype(aes.group)}(undef, 0) + color_step = aes.color === nothing ? nothing : Array{eltype(aes.color)}(undef, 0) + group_step = aes.group === nothing ? nothing : Array{eltype(aes.group)}(undef, 0) i = 1 i_offset = 1 @@ -1344,17 +1343,17 @@ function apply_statistic(stat::StepStatistic, (u > length(aes.x) || v > length(aes.y)) && break - if (!isnothing(aes.color) && + if (aes.color !== nothing && (aes.color[u] != aes.color[i_offset] || aes.color[v] != aes.color[i_offset])) || - (!isnothing(aes.group) && + (aes.group !== nothing && (aes.group[u] != aes.color[i_offset] || aes.color[v] != aes.group[i_offset])) i_offset = max(u, v) i = 1 else push!(x_step, aes.x[u]) push!(y_step, aes.y[v]) - !isnothing(aes.color) && push!(color_step, aes.color[i_offset]) - !isnothing(aes.group) && push!(group_step, aes.group[i_offset]) + aes.color !== nothing && push!(color_step, aes.color[i_offset]) + aes.group !== nothing && push!(group_step, aes.group[i_offset]) i += 1 end end @@ -1406,7 +1405,7 @@ function apply_statistic(stat::FunctionStatistic, end # color was bound explicitly - if !isnothing(aes.color) + if aes.color !== nothing func_color = aes.color aes.color = Array{eltype(aes.color)}(undef, length(aes.y) * stat.num_samples) groups = Array{Int}(undef, length(aes.y) * stat.num_samples) @@ -1466,15 +1465,15 @@ function apply_statistic(stat::ContourStatistic, scales::Dict{Symbol, Gadfly.ScaleElement}, coord::Gadfly.CoordinateElement, aes::Gadfly.Aesthetics) - xs = isnothing(aes.x) ? nothing : convert(Vector{Float64}, aes.x) - ys = isnothing(aes.y) ? nothing : convert(Vector{Float64}, aes.y) + xs = aes.x === nothing ? nothing : convert(Vector{Float64}, aes.x) + ys = aes.y === nothing ? nothing : convert(Vector{Float64}, aes.y) if typeof(aes.z) <: Function - if isnothing(xs) && !isnothing(aes.xmin) && !isnothing(aes.xmax) + if xs === nothing && aes.xmin !== nothing && aes.xmax !== nothing xs = range(aes.xmin[1], stop=aes.xmax[1], length=stat.samples) end - if isnothing(ys) && !isnothing(aes.ymin) && !isnothing(aes.ymax) + if ys === nothing && aes.ymin !== nothing && aes.ymax !== nothing ys = range(aes.ymin[1], stop=aes.ymax[1], length=stat.samples) end @@ -1483,10 +1482,10 @@ function apply_statistic(stat::ContourStatistic, elseif typeof(aes.z) <: Matrix zs = convert(Matrix{Float64}, aes.z) - if isnothing(xs) + if xs === nothing xs = collect(Float64, 1:size(zs)[1]) end - if isnothing(ys) + if ys === nothing ys = collect(Float64, 1:size(zs)[2]) end size(zs) != (length(xs), length(ys)) && @@ -1635,7 +1634,7 @@ function apply_statistic(stat::ViolinStatistic, grouped_color = Dict{Int, Gadfly.ColorOrNothing}(1=>nothing) ux = unique(aes.x) uxflag = length(ux) < length(aes.x) - colorflag = !isnothing(aes.color) + colorflag = aes.color !== nothing uxflag && (grouped_y = Dict(x=>aes.y[aes.x.==x] for x in ux)) @@ -1702,7 +1701,7 @@ function minimum_span(vars::Vector{Symbol}, aes::Gadfly.Aesthetics) end end - if isnothing(span) || (!isnothing(dataspan) && dataspan < span) + if span === nothing || (dataspan !== nothing && dataspan < span) span = dataspan end end @@ -1715,7 +1714,7 @@ function apply_statistic(stat::JitterStatistic, coord::Gadfly.CoordinateElement, aes::Gadfly.Aesthetics) span = minimum_span(stat.vars, aes) - isnothing(span) && return + span === nothing && return rng = MersenneTwister(stat.seed) for var in stat.vars @@ -1756,7 +1755,7 @@ function apply_statistic(stat::BinMeanStatistic, Tx = eltype(aes.x) Ty = eltype(aes.y) - if isnothing(aes.color) + if aes.color === nothing (aes.x, aes.y) = mean_by_group(aes.x, aes.y, breaks) else groups = Dict() @@ -1828,8 +1827,8 @@ function apply_statistic(stat::EnumerateStatistic, scales::Dict{Symbol, Gadfly.ScaleElement}, coord::Gadfly.CoordinateElement, aes::Gadfly.Aesthetics) - has_x = !isnothing(aes.x) - has_y = !isnothing(aes.y) + has_x = aes.x !== nothing + has_y = aes.y !== nothing if stat.var == :x && !has_x && has_y aes.x = collect(1:length(aes.y)) @@ -1870,14 +1869,14 @@ function apply_statistic(stat::VecFieldStatistic, scales::Dict{Symbol, Gadfly.ScaleElement}, coord::Gadfly.CoordinateElement, aes::Gadfly.Aesthetics) - xs = isnothing(aes.x) ? nothing : Float64.(aes.x) - ys = isnothing(aes.y) ? nothing : Float64.(aes.y) + xs = aes.x === nothing ? nothing : Float64.(aes.x) + ys = aes.y === nothing ? nothing : Float64.(aes.y) if isa(aes.z, Function) - if isnothing(xs) && !isnothing(aes.xmin) && !isnothing(aes.xmax) + if xs === nothing && aes.xmin !== nothing && aes.xmax !== nothing xs = range(aes.xmin[1], stop=aes.xmax[1], length=stat.samples) end - if isnothing(ys) && !isnothing(aes.ymin) && !isnothing(aes.ymax) + if ys === nothing && aes.ymin !== nothing && aes.ymax !== nothing ys = range(aes.ymin[1], stop=aes.ymax[1], length=stat.samples) end @@ -1886,10 +1885,10 @@ function apply_statistic(stat::VecFieldStatistic, elseif isa(aes.z, Matrix) zs = Float64.(aes.z) - if isnothing(xs) + if xs === nothing xs = collect(Float64, 1:size(zs)[1]) end - if isnothing(ys) + if ys === nothing ys = collect(Float64, 1:size(zs)[2]) end if size(zs) != (length(xs), length(ys)) @@ -1982,8 +1981,8 @@ function apply_statistic(stat::EllipseStatistic, aes::Gadfly.Aesthetics) Dat = [aes.x aes.y] - colorflag = !isnothing(aes.color) - groupflag = !isnothing(aes.group) + colorflag = aes.color !== nothing + groupflag = aes.group !== nothing aes_color = colorflag ? aes.color : fill(nothing, length(aes.x)) aes_group = groupflag ? aes.group : fill(nothing, length(aes.x)) CT, GT = eltype(aes_color), eltype(aes_group) @@ -2054,7 +2053,7 @@ function apply_statistic(stat::DodgeStatistic, coord::Gadfly.CoordinateElement, aes::Gadfly.Aesthetics) - isnothing(aes.color) && return + aes.color === nothing && return nbars = length(unique(aes.color)) othervar = (stat.axis == :x) ? :y : :x vals = getfield(aes, stat.axis) diff --git a/src/ticks.jl b/src/ticks.jl index 2e4c5710d..aae6954d5 100644 --- a/src/ticks.jl +++ b/src/ticks.jl @@ -214,7 +214,7 @@ function optimize_ticks(x_min::DateTime, x_max::DateTime; extend_ticks::Bool=fal # TODO: manually setting scale with :day, :minute, etc end - if isnothing(scale) + if scale === nothing for proposed_scale in [Day(1), Hour(1), Minute(1), Second(1), Millisecond(100), Millisecond(10), Millisecond(1)] @@ -225,7 +225,7 @@ function optimize_ticks(x_min::DateTime, x_max::DateTime; extend_ticks::Bool=fal end end - if isnothing(scale) + if scale === nothing scale = Millisecond(1) end diff --git a/src/varset.jl b/src/varset.jl index 9c3f31e42..ce909e502 100644 --- a/src/varset.jl +++ b/src/varset.jl @@ -45,7 +45,7 @@ macro varset(name::Symbol, table) push!(parameters, Expr(:kw, var, default)) push!(inherit_parameters, Expr(:kw, var, :(b.$var))) if typ==:ColorOrNothing - push!(parsed_vars, :(isnothing($(var)) ? nothing : parse_colorant($(var)))) + push!(parsed_vars, :($(var) === nothing ? nothing : parse_colorant($(var)))) else push!(parsed_vars, :($(var))) end