From bd46b51b944e43960c2654d678dcd389963ad9b7 Mon Sep 17 00:00:00 2001 From: Daniel Schwabeneder Date: Sun, 4 Oct 2020 18:10:52 +0200 Subject: [PATCH] remove some more type piracies and use `===` when comparing to `nothing` --- src/Plots.jl | 6 +++--- src/init.jl | 2 +- src/pipeline.jl | 2 +- src/recipes.jl | 6 +++--- src/shorthands.jl | 4 ++-- src/utils.jl | 10 ---------- 6 files changed, 10 insertions(+), 20 deletions(-) diff --git a/src/Plots.jl b/src/Plots.jl index a7c114b7..41381146 100644 --- a/src/Plots.jl +++ b/src/Plots.jl @@ -10,7 +10,7 @@ using Reexport import GeometryTypes, GeometryBasics using Dates, Printf, Statistics, Base64, LinearAlgebra, Random -import SparseArrays: AbstractSparseMatrix, findnz +using SparseArrays using FFMPEG @@ -224,8 +224,8 @@ let PlotOrSubplot = Union{Plot, Subplot} global xlims!(plt::PlotOrSubplot, xmin::Real, xmax::Real; kw...) = plot!(plt; xlims = (xmin,xmax), kw...) global ylims!(plt::PlotOrSubplot, ymin::Real, ymax::Real; kw...) = plot!(plt; ylims = (ymin,ymax), kw...) global zlims!(plt::PlotOrSubplot, zmin::Real, zmax::Real; kw...) = plot!(plt; zlims = (zmin,zmax), kw...) - global xticks!(plt::PlotOrSubplot, ticks::TicksArgs; kw...) where {T<:Real} = plot!(plt; xticks = ticks, kw...) - global yticks!(plt::PlotOrSubplot, ticks::TicksArgs; kw...) where {T<:Real} = plot!(plt; yticks = ticks, kw...) + global xticks!(plt::PlotOrSubplot, ticks::TicksArgs; kw...) = plot!(plt; xticks = ticks, kw...) + global yticks!(plt::PlotOrSubplot, ticks::TicksArgs; kw...) = plot!(plt; yticks = ticks, kw...) global xticks!(plt::PlotOrSubplot, ticks::AVec{T}, labels::AVec{S}; kw...) where {T<:Real,S<:AbstractString} = plot!(plt; xticks = (ticks,labels), kw...) global yticks!(plt::PlotOrSubplot, diff --git a/src/init.jl b/src/init.jl index 54bac3b2..0c431963 100644 --- a/src/init.jl +++ b/src/init.jl @@ -80,7 +80,7 @@ function __init__() artifact_toml = joinpath(@__DIR__, "Artifacts.toml") plotly_sha = artifact_hash("plotly", artifact_toml) - if plotly_sha == nothing || !artifact_exists(plotly_sha) + if plotly_sha === nothing || !artifact_exists(plotly_sha) plotly_sha = create_artifact() do artifact_dir download("https://cdn.plot.ly/plotly-1.54.2.min.js", joinpath(artifact_dir, "plotly-1.54.2.min.js")) end diff --git a/src/pipeline.jl b/src/pipeline.jl index 0177e9ec..e02b3478 100644 --- a/src/pipeline.jl +++ b/src/pipeline.jl @@ -49,7 +49,7 @@ RecipesPipeline.splittable_attribute(plt::Plot, key, val::SeriesAnnotations, len RecipesPipeline.splittable_attribute(plt, key, val.strs, len) function RecipesPipeline.split_attribute(plt::Plot, key, val::SeriesAnnotations, indices) - split_strs = RecipesPipeline.split_attribute(key, val.strs, indices) + split_strs = RecipesPipeline.split_attribute(plt, key, val.strs, indices) return SeriesAnnotations(split_strs, val.font, val.baseshape, val.scalefactor) end diff --git a/src/recipes.jl b/src/recipes.jl index 4083289a..7ccaf9c8 100644 --- a/src/recipes.jl +++ b/src/recipes.jl @@ -280,7 +280,7 @@ end end fillrange := nothing seriestype := :path - if plotattributes[:linecolor] == :auto && plotattributes[:marker_z] !== nothing && plotattributes[:line_z] == nothing + if plotattributes[:linecolor] == :auto && plotattributes[:marker_z] !== nothing && plotattributes[:line_z] === nothing line_z := plotattributes[:marker_z] end @@ -933,7 +933,7 @@ end @recipe function f(::Type{Val{:mesh3d}}, x, y, z) # As long as no i,j,k are supplied this should work with PyPlot and GR seriestype := :surface - if plotattributes[:connections] != nothing + if plotattributes[:connections] !== nothing throw(ArgumentError("Giving triangles using the connections argument is only supported on Plotly backend.")) end () @@ -1496,7 +1496,7 @@ end end -Plots.findnz(A::AbstractSparseMatrix) = findnz(A) +Plots.findnz(A::AbstractSparseMatrix) = SparseArrays.findnz(A) # fallback function for finding non-zero elements of non-sparse matrices function Plots.findnz(A::AbstractMatrix) diff --git a/src/shorthands.jl b/src/shorthands.jl index 89ac4e80..2931162c 100644 --- a/src/shorthands.jl +++ b/src/shorthands.jl @@ -432,10 +432,10 @@ zlims!(zmin::Real, zmax::Real; kw...) = plot!(; zlims = (zmi "Set xticks for an existing plot" -xticks!(v::TicksArgs; kw...) where {T<:Real} = plot!(; xticks = v, kw...) +xticks!(v::TicksArgs; kw...) = plot!(; xticks = v, kw...) "Set yticks for an existing plot" -yticks!(v::TicksArgs; kw...) where {T<:Real} = plot!(; yticks = v, kw...) +yticks!(v::TicksArgs; kw...) = plot!(; yticks = v, kw...) xticks!( ticks::AVec{T}, labels::AVec{S}; kw...) where {T<:Real,S<:AbstractString} = plot!(; xticks = (ticks,labels), kw...) diff --git a/src/utils.jl b/src/utils.jl index 1a1f81a1..af4bcaa0 100644 --- a/src/utils.jl +++ b/src/utils.jl @@ -207,9 +207,6 @@ end createSegments(z) = collect(repeat(reshape(z,1,:),2,1))[2:end] -Base.first(c::Colorant) = c -Base.first(x::Symbol) = x - sortedkeys(plotattributes::Dict) = sort(collect(keys(plotattributes))) @@ -295,13 +292,6 @@ limsType(lims::Tuple{T,S}) where {T<:Real,S<:Real} = :limits limsType(lims::Symbol) = lims == :auto ? :auto : :invalid limsType(lims) = :invalid -# axis_Symbol(letter, postfix) = Symbol(letter * postfix) -# axis_symbols(letter, postfix...) = map(s -> axis_Symbol(letter, s), postfix) - -Base.convert(::Type{Vector{T}}, rng::AbstractRange{T}) where {T<:Real} = T[x for x in rng] -Base.convert(::Type{Vector{T}}, rng::AbstractRange{S}) where {T<:Real,S<:Real} = T[x for x in rng] - -Base.merge(a::AbstractVector, b::AbstractVector) = sort(unique(vcat(a,b))) # recursively merge kw-dicts, e.g. for merging extra_kwargs / extra_plot_kwargs in plotly) recursive_merge(x::AbstractDict...) = merge(recursive_merge, x...)