revisions for Julia 0.7

This commit is contained in:
Ralph A. Smith 2018-06-17 17:23:42 -04:00
parent 682fa6e9e6
commit f60ad6489c
24 changed files with 126 additions and 99 deletions

View File

@ -1,5 +1,5 @@
julia 0.7 julia 0.7
Compat 0.69
RecipesBase 0.2.3 RecipesBase 0.2.3
PlotUtils 0.4.1 PlotUtils 0.4.1
PlotThemes 0.1.3 PlotThemes 0.1.3
@ -7,7 +7,6 @@ Reexport
StaticArrays 0.5 StaticArrays 0.5
FixedPointNumbers 0.3 FixedPointNumbers 0.3
Measures Measures
Dates
Showoff Showoff
StatsBase 0.14.0 StatsBase 0.14.0
JSON JSON

View File

@ -12,8 +12,25 @@ import RecipesBase: plot, plot!, animate
using Base.Meta using Base.Meta
@reexport using PlotUtils @reexport using PlotUtils
@reexport using PlotThemes @reexport using PlotThemes
import Dates
import Dates.Date if VERSION >= v"0.7-"
import Dates
using Dates: Date, DateTime
using Printf: @printf, @sprintf
using REPL: REPLDisplay
using Base64: base64encode
using Base.Sys: isapple, islinux, iswindows, isbsd
import Pkg
const euler_e = Base.MathConstants.e
else
using Compat
using Compat.Sys: isapple, islinux, iswindows, isbsd
import Compat: maximum
maximum(arg::Tuple) = Base.maximum(arg)
using Base.REPL: REPLDisplay
const euler_e = Base.e
end
import Showoff import Showoff
import StatsBase import StatsBase
import JSON import JSON
@ -266,6 +283,8 @@ xgrid!(args...; kw...) = plot!(; xgrid = args
ygrid!(args...; kw...) = plot!(; ygrid = args, kw...) ygrid!(args...; kw...) = plot!(; ygrid = args, kw...)
let PlotOrSubplot = Union{Plot, Subplot} let PlotOrSubplot = Union{Plot, Subplot}
global title!, xlabel!, ylabel!, xlims!, ylims!, zlims!, xticks!, yticks!
global xgrid!, ygrid!, annotate!, xflip!, yflip!, xaxis!, yaxis!
title!(plt::PlotOrSubplot, s::AbstractString; kw...) = plot!(plt; title = s, kw...) title!(plt::PlotOrSubplot, s::AbstractString; kw...) = plot!(plt; title = s, kw...)
xlabel!(plt::PlotOrSubplot, s::AbstractString; kw...) = plot!(plt; xlabel = s, kw...) xlabel!(plt::PlotOrSubplot, s::AbstractString; kw...) = plot!(plt; xlabel = s, kw...)
ylabel!(plt::PlotOrSubplot, s::AbstractString; kw...) = plot!(plt; ylabel = s, kw...) ylabel!(plt::PlotOrSubplot, s::AbstractString; kw...) = plot!(plt; ylabel = s, kw...)

View File

@ -15,7 +15,7 @@ function add_non_underscore_aliases!(aliases::Dict{Symbol,Symbol})
for (k,v) in aliases for (k,v) in aliases
s = string(k) s = string(k)
if '_' in s if '_' in s
aliases[Symbol(replace(s, "_", ""))] = v aliases[Symbol(replace(s, "_" => ""))] = v
end end
end end
end end
@ -176,7 +176,11 @@ const _positionAliases = Dict{Symbol,Symbol}(
const _allScales = [:identity, :ln, :log2, :log10, :asinh, :sqrt] const _allScales = [:identity, :ln, :log2, :log10, :asinh, :sqrt]
const _logScales = [:ln, :log2, :log10] const _logScales = [:ln, :log2, :log10]
const _logScaleBases = Dict(:ln => e, :log2 => 2.0, :log10 => 10.0) const _logScaleBases = Dict(
:ln => euler_e,
:log2 => 2.0,
:log10 => 10.0
)
const _scaleAliases = Dict{Symbol,Symbol}( const _scaleAliases = Dict{Symbol,Symbol}(
:none => :identity, :none => :identity,
:log => :log10, :log => :log10,
@ -188,7 +192,7 @@ const _allGridSyms = [:x, :y, :z,
:all, :both, :on, :yes, :show, :all, :both, :on, :yes, :show,
:none, :off, :no, :hide] :none, :off, :no, :hide]
const _allGridArgs = [_allGridSyms; string.(_allGridSyms); nothing] const _allGridArgs = [_allGridSyms; string.(_allGridSyms); nothing]
hasgrid(arg::Void, letter) = false hasgrid(arg::Nothing, letter) = false
hasgrid(arg::Bool, letter) = arg hasgrid(arg::Bool, letter) = arg
function hasgrid(arg::Symbol, letter) function hasgrid(arg::Symbol, letter)
if arg in _allGridSyms if arg in _allGridSyms
@ -206,7 +210,7 @@ const _allShowaxisSyms = [:x, :y, :z,
:all, :both, :on, :yes, :show, :all, :both, :on, :yes, :show,
:off, :no, :hide] :off, :no, :hide]
const _allShowaxisArgs = [_allGridSyms; string.(_allGridSyms)] const _allShowaxisArgs = [_allGridSyms; string.(_allGridSyms)]
showaxis(arg::Void, letter) = false showaxis(arg::Nothing, letter) = false
showaxis(arg::Bool, letter) = arg showaxis(arg::Bool, letter) = arg
function showaxis(arg::Symbol, letter) function showaxis(arg::Symbol, letter)
if arg in _allGridSyms if arg in _allGridSyms
@ -654,6 +658,7 @@ function handleColors!(d::KW, arg, csym::Symbol)
d[csym] = c d[csym] = c
end end
return true return true
catch
end end
false false
end end
@ -1028,7 +1033,7 @@ function extractGroupArgs(vs::Tuple, args...)
end end
# allow passing NamedTuples for a named legend entry # allow passing NamedTuples for a named legend entry
@require NamedTuples begin @require NamedTuples="73a701b4-84e1-5df0-88ff-1968ee2ee8dc" begin
legendEntryFromTuple(ns::NamedTuples.NamedTuple) = legendEntryFromTuple(ns::NamedTuples.NamedTuple) =
join(["$k = $v" for (k, v) in zip(keys(ns), values(ns))], ", ") join(["$k = $v" for (k, v) in zip(keys(ns), values(ns))], ", ")
@ -1131,7 +1136,7 @@ function convertLegendValue(val::Symbol)
end end
end end
convertLegendValue(val::Bool) = val ? :best : :none convertLegendValue(val::Bool) = val ? :best : :none
convertLegendValue(val::Void) = :none convertLegendValue(val::Nothing) = :none
convertLegendValue(v::Tuple{S,T}) where {S<:Real, T<:Real} = v convertLegendValue(v::Tuple{S,T}) where {S<:Real, T<:Real} = v
convertLegendValue(v::AbstractArray) = map(convertLegendValue, v) convertLegendValue(v::AbstractArray) = map(convertLegendValue, v)

View File

@ -310,7 +310,7 @@ function expand_extrema!(axis::Axis, v::Number)
end end
# these shouldn't impact the extrema # these shouldn't impact the extrema
expand_extrema!(axis::Axis, ::Void) = axis[:extrema] expand_extrema!(axis::Axis, ::Nothing) = axis[:extrema]
expand_extrema!(axis::Axis, ::Bool) = axis[:extrema] expand_extrema!(axis::Axis, ::Bool) = axis[:extrema]

View File

@ -9,7 +9,7 @@ TODO
* fix units in all visuals (e.g dotted lines, marker scale, surfaces) * fix units in all visuals (e.g dotted lines, marker scale, surfaces)
=# =#
@require Revise begin @require Revise="295af30f-e4ad-537b-8983-00126c2a3abe" begin
Revise.track(Plots, joinpath(Pkg.dir("Plots"), "src", "backends", "glvisualize.jl")) Revise.track(Plots, joinpath(Pkg.dir("Plots"), "src", "backends", "glvisualize.jl"))
end end

View File

@ -3,7 +3,7 @@
# significant contributions by @jheinen # significant contributions by @jheinen
@require Revise begin @require Revise="295af30f-e4ad-537b-8983-00126c2a3abe" begin
Revise.track(Plots, joinpath(Pkg.dir("Plots"), "src", "backends", "gr.jl")) Revise.track(Plots, joinpath(Pkg.dir("Plots"), "src", "backends", "gr.jl"))
end end
@ -144,7 +144,7 @@ gr_set_fillcolor(c) = GR.setfillcolorind(gr_getcolorind(_cycle(c,1)))
gr_set_markercolor(c) = GR.setmarkercolorind(gr_getcolorind(_cycle(c,1))) gr_set_markercolor(c) = GR.setmarkercolorind(gr_getcolorind(_cycle(c,1)))
gr_set_textcolor(c) = GR.settextcolorind(gr_getcolorind(_cycle(c,1))) gr_set_textcolor(c) = GR.settextcolorind(gr_getcolorind(_cycle(c,1)))
gr_set_transparency(α::Real) = GR.settransparency(clamp(α, 0, 1)) gr_set_transparency(α::Real) = GR.settransparency(clamp(α, 0, 1))
function gr_set_transparency(::Void) end function gr_set_transparency(::Nothing) end
# -------------------------------------------------------------------------------------- # --------------------------------------------------------------------------------------
@ -196,7 +196,7 @@ gr_inqtext(x, y, s::Symbol) = gr_inqtext(x, y, string(s))
function gr_inqtext(x, y, s) function gr_inqtext(x, y, s)
if length(s) >= 2 && s[1] == '$' && s[end] == '$' if length(s) >= 2 && s[1] == '$' && s[end] == '$'
GR.inqtextext(x, y, s[2:end-1]) GR.inqtextext(x, y, s[2:end-1])
elseif search(s, '\\') != 0 || contains(s, "10^{") elseif something(findfirst(isequal('\\'), s), 0) != 0 || occursin("10^{", s)
GR.inqtextext(x, y, s) GR.inqtextext(x, y, s)
else else
GR.inqtext(x, y, s) GR.inqtext(x, y, s)
@ -208,7 +208,7 @@ gr_text(x, y, s::Symbol) = gr_text(x, y, string(s))
function gr_text(x, y, s) function gr_text(x, y, s)
if length(s) >= 2 && s[1] == '$' && s[end] == '$' if length(s) >= 2 && s[1] == '$' && s[end] == '$'
GR.mathtex(x, y, s[2:end-1]) GR.mathtex(x, y, s[2:end-1])
elseif search(s, '\\') != 0 || contains(s, "10^{") elseif something(findfirst(isequal('\\'), s), 0) != 0 || occursin("10^{", s)
GR.textext(x, y, s) GR.textext(x, y, s)
else else
GR.text(x, y, s) GR.text(x, y, s)
@ -502,16 +502,16 @@ function gr_legend_pos(s::Symbol,w,h)
if str == "best" if str == "best"
str = "topright" str = "topright"
end end
if contains(str,"right") if occursin("right",str)
xpos = viewport_plotarea[2] - 0.05 - w xpos = viewport_plotarea[2] - 0.05 - w
elseif contains(str,"left") elseif occursin("left",str)
xpos = viewport_plotarea[1] + 0.11 xpos = viewport_plotarea[1] + 0.11
else else
xpos = (viewport_plotarea[2]-viewport_plotarea[1])/2 - w/2 +.04 xpos = (viewport_plotarea[2]-viewport_plotarea[1])/2 - w/2 +.04
end end
if contains(str,"top") if occursin("top",str)
ypos = viewport_plotarea[4] - 0.06 ypos = viewport_plotarea[4] - 0.06
elseif contains(str,"bottom") elseif occursin("bottom",str)
ypos = viewport_plotarea[3] + h + 0.06 ypos = viewport_plotarea[3] + h + 0.06
else else
ypos = (viewport_plotarea[4]-viewport_plotarea[3])/2 + h/2 ypos = (viewport_plotarea[4]-viewport_plotarea[3])/2 + h/2
@ -1358,10 +1358,10 @@ const _gr_mimeformats = Dict(
"image/svg+xml" => "svg", "image/svg+xml" => "svg",
) )
const _gr_wstype_default = @static if is_linux() const _gr_wstype_default = @static if islinux()
"x11" "x11"
# "cairox11" # "cairox11"
elseif is_apple() elseif isapple()
"quartz" "quartz"
else else
"use_default" "use_default"

View File

@ -28,7 +28,7 @@ Read from .hdf5 file using:
- Should be reliable for archival purposes. - Should be reliable for archival purposes.
==# ==#
@require Revise begin @require Revise="295af30f-e4ad-537b-8983-00126c2a3abe" begin
Revise.track(Plots, joinpath(Pkg.dir("Plots"), "src", "backends", "hdf5.jl")) Revise.track(Plots, joinpath(Pkg.dir("Plots"), "src", "backends", "hdf5.jl"))
end end
@ -39,7 +39,7 @@ struct HDF5PlotNative; end #Indentifies a data element that can natively be hand
struct HDF5CTuple; end #Identifies a "complex" tuple structure struct HDF5CTuple; end #Identifies a "complex" tuple structure
mutable struct HDF5Plot_PlotRef mutable struct HDF5Plot_PlotRef
ref::Union{Plot, Void} ref::Union{Plot, Nothing}
end end
@ -148,7 +148,7 @@ function _initialize_backend(::HDF5Backend)
#Possible element types of high-level data types: #Possible element types of high-level data types:
const telem2str = Dict{String, Type}( const telem2str = Dict{String, Type}(
"NATIVE" => HDF5PlotNative, "NATIVE" => HDF5PlotNative,
"VOID" => Void, "VOID" => Nothing,
"BOOL" => Bool, "BOOL" => Bool,
"SYMBOL" => Symbol, "SYMBOL" => Symbol,
"TUPLE" => Tuple, "TUPLE" => Tuple,
@ -315,9 +315,9 @@ function _hdf5plot_gwrite(grp, k::String, v::Array{Any})
warn("Cannot write Array: $k=$v") warn("Cannot write Array: $k=$v")
end end
=# =#
function _hdf5plot_gwrite(grp, k::String, v::Void) function _hdf5plot_gwrite(grp, k::String, v::Nothing)
grp[k] = 0 grp[k] = 0
_hdf5plot_writetype(grp, k, Void) _hdf5plot_writetype(grp, k, Nothing)
end end
function _hdf5plot_gwrite(grp, k::String, v::Bool) function _hdf5plot_gwrite(grp, k::String, v::Bool)
grp[k] = Int(v) grp[k] = Int(v)
@ -344,7 +344,7 @@ end
function _hdf5plot_gwrite(grp, k::String, d::Dict) function _hdf5plot_gwrite(grp, k::String, d::Dict)
# warn("Cannot write dict: $k=$d") # warn("Cannot write dict: $k=$d")
end end
function _hdf5plot_gwrite(grp, k::String, v::Range) function _hdf5plot_gwrite(grp, k::String, v::AbstractRange)
_hdf5plot_gwrite(grp, k, collect(v)) #For now _hdf5plot_gwrite(grp, k, collect(v)) #For now
end end
function _hdf5plot_gwrite(grp, k::String, v::ARGB{N0f8}) function _hdf5plot_gwrite(grp, k::String, v::ARGB{N0f8})
@ -476,7 +476,7 @@ function _hdf5plot_readcount(grp) #Read directly from group
end end
_hdf5plot_convert(T::Type{HDF5PlotNative}, v) = v _hdf5plot_convert(T::Type{HDF5PlotNative}, v) = v
_hdf5plot_convert(T::Type{Void}, v) = nothing _hdf5plot_convert(T::Type{Nothing}, v) = nothing
_hdf5plot_convert(T::Type{Bool}, v) = (v!=0) _hdf5plot_convert(T::Type{Bool}, v) = (v!=0)
_hdf5plot_convert(T::Type{Symbol}, v) = Symbol(v) _hdf5plot_convert(T::Type{Symbol}, v) = Symbol(v)
_hdf5plot_convert(T::Type{Tuple}, v) = tuple(v...) #With Vector{T<:Number} _hdf5plot_convert(T::Type{Tuple}, v) = tuple(v...) #With Vector{T<:Number}

View File

@ -13,7 +13,7 @@ Add in functionality to Plots.jl:
:aspect_ratio, :aspect_ratio,
=# =#
@require Revise begin @require Revise="295af30f-e4ad-537b-8983-00126c2a3abe" begin
Revise.track(Plots, joinpath(Pkg.dir("Plots"), "src", "backends", "inspectdr.jl")) Revise.track(Plots, joinpath(Pkg.dir("Plots"), "src", "backends", "inspectdr.jl"))
end end
@ -166,13 +166,13 @@ function _initialize_backend(::InspectDRBackend; kw...)
export InspectDR export InspectDR
#Glyph used when plotting "Shape"s: #Glyph used when plotting "Shape"s:
const INSPECTDR_GLYPH_SHAPE = InspectDR.GlyphPolyline( INSPECTDR_GLYPH_SHAPE = InspectDR.GlyphPolyline(
2*InspectDR.GLYPH_SQUARE.x, InspectDR.GLYPH_SQUARE.y 2*InspectDR.GLYPH_SQUARE.x, InspectDR.GLYPH_SQUARE.y
) )
mutable struct InspecDRPlotRef mutable struct InspecDRPlotRef
mplot::Union{Void, InspectDR.Multiplot} mplot::Union{Nothing, InspectDR.Multiplot}
gui::Union{Void, InspectDR.GtkPlot} gui::Union{Nothing, InspectDR.GtkPlot}
end end
_inspectdr_getmplot(::Any) = nothing _inspectdr_getmplot(::Any) = nothing
@ -347,8 +347,8 @@ end
# --------------------------------------------------------------------------- # ---------------------------------------------------------------------------
function _inspectdr_setupsubplot(sp::Subplot{InspectDRBackend}) function _inspectdr_setupsubplot(sp::Subplot{InspectDRBackend})
const plot = sp.o plot = sp.o
const strip = plot.strips[1] #Only 1 strip supported with Plots.jl strip = plot.strips[1] #Only 1 strip supported with Plots.jl
xaxis = sp[:xaxis]; yaxis = sp[:yaxis] xaxis = sp[:xaxis]; yaxis = sp[:yaxis]
xgrid_show = xaxis[:grid] xgrid_show = xaxis[:grid]
@ -406,7 +406,7 @@ end
# called just before updating layout bounding boxes... in case you need to prep # called just before updating layout bounding boxes... in case you need to prep
# for the calcs # for the calcs
function _before_layout_calcs(plt::Plot{InspectDRBackend}) function _before_layout_calcs(plt::Plot{InspectDRBackend})
const mplot = _inspectdr_getmplot(plt.o) mplot = _inspectdr_getmplot(plt.o)
if nothing == mplot; return; end if nothing == mplot; return; end
mplot.title = plt[:plot_title] mplot.title = plt[:plot_title]
@ -506,7 +506,7 @@ const _inspectdr_mimeformats_nodpi = Dict(
# "application/postscript" => "ps", #TODO: support once Cairo supports PSSurface # "application/postscript" => "ps", #TODO: support once Cairo supports PSSurface
"application/pdf" => "pdf" "application/pdf" => "pdf"
) )
_inspectdr_show(io::IO, mime::MIME, ::Void, w, h) = _inspectdr_show(io::IO, mime::MIME, ::Nothing, w, h) =
throw(ErrorException("Cannot show(::IO, ...) plot - not yet generated")) throw(ErrorException("Cannot show(::IO, ...) plot - not yet generated"))
function _inspectdr_show(io::IO, mime::MIME, mplot, w, h) function _inspectdr_show(io::IO, mime::MIME, mplot, w, h)
InspectDR._show(io, mime, mplot, Float64(w), Float64(h)) InspectDR._show(io, mime, mplot, Float64(w), Float64(h))

View File

@ -2,7 +2,7 @@
# significant contributions by: @pkofod # significant contributions by: @pkofod
@require Revise begin @require Revise="295af30f-e4ad-537b-8983-00126c2a3abe" begin
Revise.track(Plots, joinpath(Pkg.dir("Plots"), "src", "backends", "pgfplots.jl")) Revise.track(Plots, joinpath(Pkg.dir("Plots"), "src", "backends", "pgfplots.jl"))
end end

View File

@ -1,7 +1,7 @@
# https://plot.ly/javascript/getting-started # https://plot.ly/javascript/getting-started
@require Revise begin @require Revise="295af30f-e4ad-537b-8983-00126c2a3abe" begin
Revise.track(Plots, joinpath(Pkg.dir("Plots"), "src", "backends", "plotly.jl")) Revise.track(Plots, joinpath(Pkg.dir("Plots"), "src", "backends", "plotly.jl"))
end end

View File

@ -1,4 +1,4 @@
@require Revise begin @require Revise="295af30f-e4ad-537b-8983-00126c2a3abe" begin
Revise.track(Plots, joinpath(Pkg.dir("Plots"), "src", "backends", "plotlyjs.jl")) Revise.track(Plots, joinpath(Pkg.dir("Plots"), "src", "backends", "plotlyjs.jl"))
end end

View File

@ -1,7 +1,7 @@
# https://github.com/stevengj/PyPlot.jl # https://github.com/stevengj/PyPlot.jl
@require Revise begin @require Revise="295af30f-e4ad-537b-8983-00126c2a3abe" begin
Revise.track(Plots, joinpath(Pkg.dir("Plots"), "src", "backends", "pyplot.jl")) Revise.track(Plots, joinpath(Pkg.dir("Plots"), "src", "backends", "pyplot.jl"))
end end
@ -683,8 +683,8 @@ function py_add_series(plt::Plot{PyPlotBackend}, series::Series)
if typeof(z) <: AbstractMatrix || typeof(z) <: Surface if typeof(z) <: AbstractMatrix || typeof(z) <: Surface
x, y, z = map(Array, (x,y,z)) x, y, z = map(Array, (x,y,z))
if !ismatrix(x) || !ismatrix(y) if !ismatrix(x) || !ismatrix(y)
x = repmat(x', length(y), 1) x = repeat(x', length(y), 1)
y = repmat(y, 1, length(series[:x])) y = repeat(y, 1, length(series[:x]))
end end
z = transpose_z(series, z) z = transpose_z(series, z)
if st == :surface if st == :surface
@ -923,7 +923,7 @@ function py_set_scale(ax, axis::Axis)
"linear" "linear"
else else
kw[Symbol(:base,letter)] = if scale == :ln kw[Symbol(:base,letter)] = if scale == :ln
e Base.MathConstants.e
elseif scale == :log2 elseif scale == :log2
2 2
elseif scale == :log10 elseif scale == :log10

View File

@ -1,7 +1,7 @@
# https://github.com/Evizero/UnicodePlots.jl # https://github.com/Evizero/UnicodePlots.jl
@require Revise begin @require Revise="295af30f-e4ad-537b-8983-00126c2a3abe" begin
Revise.track(Plots, joinpath(Pkg.dir("Plots"), "src", "backends", "unicodeplots.jl")) Revise.track(Plots, joinpath(Pkg.dir("Plots"), "src", "backends", "unicodeplots.jl"))
end end
@ -183,7 +183,7 @@ function png(plt::AbstractPlot{UnicodePlotsBackend}, fn::AbstractString)
gui(plt) gui(plt)
# @osx_only begin # @osx_only begin
@static if is_apple() @static if isapple()
# BEGIN HACK # BEGIN HACK
# wait while the plot gets drawn # wait while the plot gets drawn

View File

@ -2,7 +2,7 @@
# NOTE: backend should implement `html_body` and `html_head` # NOTE: backend should implement `html_body` and `html_head`
# CREDIT: parts of this implementation were inspired by @joshday's PlotlyLocal.jl # CREDIT: parts of this implementation were inspired by @joshday's PlotlyLocal.jl
@require Revise begin @require Revise="295af30f-e4ad-537b-8983-00126c2a3abe" begin
Revise.track(Plots, joinpath(Pkg.dir("Plots"), "src", "backends", "web.jl")) Revise.track(Plots, joinpath(Pkg.dir("Plots"), "src", "backends", "web.jl"))
end end
@ -23,13 +23,13 @@ function standalone_html(plt::AbstractPlot; title::AbstractString = get(plt.attr
end end
function open_browser_window(filename::AbstractString) function open_browser_window(filename::AbstractString)
@static if is_apple() @static if isapple()
return run(`open $(filename)`) return run(`open $(filename)`)
end end
@static if is_linux() || is_bsd() # is_bsd() addition is as yet untested, but based on suggestion in https://github.com/JuliaPlots/Plots.jl/issues/681 @static if islinux() || isbsd() # is_bsd() addition is as yet untested, but based on suggestion in https://github.com/JuliaPlots/Plots.jl/issues/681
return run(`xdg-open $(filename)`) return run(`xdg-open $(filename)`)
end end
@static if is_windows() @static if iswindows()
return run(`$(ENV["COMSPEC"]) /c start "" "$(filename)"`) return run(`$(ENV["COMSPEC"]) /c start "" "$(filename)"`)
end end
warn("Unknown OS... cannot open browser window.") warn("Unknown OS... cannot open browser window.")

View File

@ -58,7 +58,7 @@ end
"get an array of tuples of points on a circle with radius `r`" "get an array of tuples of points on a circle with radius `r`"
function partialcircle(start_θ, end_θ, n = 20, r=1) function partialcircle(start_θ, end_θ, n = 20, r=1)
Tuple{Float64,Float64}[(r*cos(u),r*sin(u)) for u in linspace(start_θ, end_θ, n)] Tuple{Float64,Float64}[(r*cos(u),r*sin(u)) for u in range(start_θ, stop=end_θ, length=n)]
end end
"interleave 2 vectors into each other (like a zipper's teeth)" "interleave 2 vectors into each other (like a zipper's teeth)"
@ -68,7 +68,8 @@ function weave(x,y; ordering = Vector[x,y])
while !done while !done
for o in ordering for o in ordering
try try
push!(ret, shift!(o)) push!(ret, popfirst!(o))
catch
end end
end end
done = isempty(x) && isempty(y) done = isempty(x) && isempty(y)
@ -388,6 +389,7 @@ function stroke(args...; alpha = nothing)
elseif T <: Symbol || T <: AbstractString elseif T <: Symbol || T <: AbstractString
try try
color = parse(Colorant, string(arg)) color = parse(Colorant, string(arg))
catch
end end
elseif allAlphas(arg) elseif allAlphas(arg)
alpha = arg alpha = arg
@ -420,6 +422,7 @@ function brush(args...; alpha = nothing)
elseif T <: Symbol || T <: AbstractString elseif T <: Symbol || T <: AbstractString
try try
color = parse(Colorant, string(arg)) color = parse(Colorant, string(arg))
catch
end end
elseif allAlphas(arg) elseif allAlphas(arg)
alpha = arg alpha = arg
@ -468,7 +471,7 @@ function series_annotations(strs::AbstractVector, args...)
SeriesAnnotations(strs, fnt, shp, scalefactor) SeriesAnnotations(strs, fnt, shp, scalefactor)
end end
series_annotations(anns::SeriesAnnotations) = anns series_annotations(anns::SeriesAnnotations) = anns
series_annotations(::Void) = nothing series_annotations(::Nothing) = nothing
function series_annotations_shapes!(series::Series, scaletype::Symbol = :pixels) function series_annotations_shapes!(series::Series, scaletype::Symbol = :pixels)
anns = series[:series_annotations] anns = series[:series_annotations]
@ -483,7 +486,7 @@ function series_annotations_shapes!(series::Series, scaletype::Symbol = :pixels)
# end # end
# @show msw msh # @show msw msh
if anns != nothing && !isnull(anns.baseshape) if anns != nothing && (anns.baseshape != nothing)
# we use baseshape to overwrite the markershape attribute # we use baseshape to overwrite the markershape attribute
# with a list of custom shapes for each # with a list of custom shapes for each
msw,msh = anns.scalefactor msw,msh = anns.scalefactor
@ -531,7 +534,7 @@ function Base.next(ea::EachAnn, i)
((_cycle(ea.x,i), _cycle(ea.y,i), str, fnt), i+1) ((_cycle(ea.x,i), _cycle(ea.y,i), str, fnt), i+1)
end end
annotations(::Void) = [] annotations(::Nothing) = []
annotations(anns::AVec) = anns annotations(anns::AVec) = anns
annotations(anns) = Any[anns] annotations(anns) = Any[anns]
annotations(sa::SeriesAnnotations) = sa annotations(sa::SeriesAnnotations) = sa
@ -747,7 +750,7 @@ end
@deprecate curve_points coords @deprecate curve_points coords
coords(curve::BezierCurve, n::Integer = 30; range = [0,1]) = map(curve, linspace(range..., n)) coords(curve::BezierCurve, n::Integer = 30; limits = [0,1]) = map(curve, range(limits[1],stop=limits[2], length=n))
# build a BezierCurve which leaves point p vertically upwards and arrives point q vertically upwards. # build a BezierCurve which leaves point p vertically upwards and arrives point q vertically upwards.
# may create a loop if necessary. Assumes the view is [0,1] # may create a loop if necessary. Assumes the view is [0,1]

View File

@ -8,7 +8,9 @@ mutable struct PlotExample
end end
# the _examples we'll run for each # the _examples we'll run for each
const _examples = PlotExample[ # FIXME: suppress explicit typing of array until parser is fixed
#const _examples = PlotExample[
const _examples = [
PlotExample("Lines", PlotExample("Lines",
"A simple line plot of the columns.", "A simple line plot of the columns.",
@ -157,7 +159,7 @@ PlotExample("Marker types",
markers = reshape(markers, 1, length(markers)) markers = reshape(markers, 1, length(markers))
n = length(markers) n = length(markers)
x = linspace(0,10,n+2)[2:end-1] x = linspace(0,10,n+2)[2:end-1]
y = repmat(reshape(reverse(x),1,:), n, 1) y = repeat(reshape(reverse(x),1,:), n, 1)
scatter(x, y, m=(8,:auto), lab=map(string,markers), bg=:linen, xlim=(0,10), ylim=(0,10)) scatter(x, y, m=(8,:auto), lab=map(string,markers), bg=:linen, xlim=(0,10), ylim=(0,10))
end)] end)]
), ),
@ -269,8 +271,8 @@ unfilled contour from a matrix.
x = 1:0.5:20 x = 1:0.5:20
y = 1:0.5:10 y = 1:0.5:10
f(x,y) = (3x+y^2)*abs(sin(x)+cos(y)) f(x,y) = (3x+y^2)*abs(sin(x)+cos(y))
X = repmat(reshape(x,1,:), length(y), 1) X = repeat(reshape(x,1,:), length(y), 1)
Y = repmat(y, 1, length(x)) Y = repeat(y, 1, length(x))
Z = map(f, X, Y) Z = map(f, X, Y)
p1 = contour(x, y, f, fill=true) p1 = contour(x, y, f, fill=true)
p2 = contour(x, y, Z) p2 = contour(x, y, Z)

View File

@ -268,7 +268,7 @@ function GridLayout(dims...;
widths = zeros(dims[2]), widths = zeros(dims[2]),
heights = zeros(dims[1]), heights = zeros(dims[1]),
kw...) kw...)
grid = Matrix{AbstractLayout}(dims...) grid = Matrix{AbstractLayout}(undef,dims...)
layout = GridLayout( layout = GridLayout(
parent, parent,
(20mm, 5mm, 2mm, 10mm), (20mm, 5mm, 2mm, 10mm),
@ -357,10 +357,10 @@ function update_child_bboxes!(layout::GridLayout, minimum_perimeter = [0mm,0mm,0
# get the max horizontal (left and right) padding over columns, # get the max horizontal (left and right) padding over columns,
# and max vertical (bottom and top) padding over rows # and max vertical (bottom and top) padding over rows
# TODO: add extra padding here # TODO: add extra padding here
pad_left = maximum(minpad_left, 1) pad_left = maximum(minpad_left, dims=1)
pad_top = maximum(minpad_top, 2) pad_top = maximum(minpad_top, dims=2)
pad_right = maximum(minpad_right, 1) pad_right = maximum(minpad_right, dims=1)
pad_bottom = maximum(minpad_bottom, 2) pad_bottom = maximum(minpad_bottom, dims=2)
# make sure the perimeter match the parent # make sure the perimeter match the parent
pad_left[1] = max(pad_left[1], minimum_perimeter[1]) pad_left[1] = max(pad_left[1], minimum_perimeter[1])

View File

@ -146,7 +146,7 @@ function Base.display(::PlotsDisplay, plt::Plot)
end end
# override the REPL display to open a gui window # override the REPL display to open a gui window
Base.display(::Base.REPL.REPLDisplay, ::MIME"text/plain", plt::Plot) = gui(plt) Base.display(::REPLDisplay, ::MIME"text/plain", plt::Plot) = gui(plt)
_do_plot_show(plt, showval::Bool) = showval && gui(plt) _do_plot_show(plt, showval::Bool) = showval && gui(plt)
@ -254,7 +254,7 @@ end
# IJulia # IJulia
# --------------------------------------------------------- # ---------------------------------------------------------
@require IJulia begin @require IJulia="7073ff75-c697-5162-941a-fcdaad2a7d2a" begin
if IJulia.inited if IJulia.inited
""" """
@ -310,7 +310,7 @@ end
# --------------------------------------------------------- # ---------------------------------------------------------
# Atom PlotPane # Atom PlotPane
# --------------------------------------------------------- # ---------------------------------------------------------
@require Juno begin @require Juno="e5e0dc1b-0480-54bc-9374-aad01c23163d" begin
import Hiccup, Media import Hiccup, Media
if Juno.isactive() if Juno.isactive()

View File

@ -70,7 +70,7 @@ function _process_userrecipes(plt::Plot, d::KW, args)
# grab the first in line to be processed and either add it to the kw_list or # grab the first in line to be processed and either add it to the kw_list or
# pass it through apply_recipe to generate a list of RecipeData objects (data + attributes) # pass it through apply_recipe to generate a list of RecipeData objects (data + attributes)
# for further processing. # for further processing.
next_series = shift!(still_to_process) next_series = popfirst!(still_to_process)
# recipedata should be of type RecipeData. if it's not then the inputs must not have been fully processed by recipes # recipedata should be of type RecipeData. if it's not then the inputs must not have been fully processed by recipes
if !(typeof(next_series) <: RecipeData) if !(typeof(next_series) <: RecipeData)
error("Inputs couldn't be processed... expected RecipeData but got: $next_series") error("Inputs couldn't be processed... expected RecipeData but got: $next_series")
@ -329,7 +329,7 @@ function _override_seriestype_check(d::KW, st::Symbol)
# do we want to override the series type? # do we want to override the series type?
if !is3d(st) && !(st in (:contour,:contour3d)) if !is3d(st) && !(st in (:contour,:contour3d))
z = d[:z] z = d[:z]
if !isa(z, Void) && (size(d[:x]) == size(d[:y]) == size(z)) if !isa(z, Nothing) && (size(d[:x]) == size(d[:y]) == size(z))
st = (st == :scatter ? :scatter3d : :path3d) st = (st == :scatter ? :scatter3d : :path3d)
d[:seriestype] = st d[:seriestype] = st
end end

View File

@ -46,9 +46,8 @@ When you pass in matrices, it splits by columns. To see the list of available at
function, where `attr` is the symbol `:Series:`, `:Subplot:`, `:Plot` or `:Axis`. Pass any attribute to `plotattr` function, where `attr` is the symbol `:Series:`, `:Subplot:`, `:Plot` or `:Axis`. Pass any attribute to `plotattr`
as a String to look up its docstring; e.g. `plotattr("seriestype")`. as a String to look up its docstring; e.g. `plotattr("seriestype")`.
""" """
# this creates a new plot with args/kw and sets it to be the current plot
function plot(args...; kw...) function plot(args...; kw...)
# this creates a new plot with args/kw and sets it to be the current plot
d = KW(kw) d = KW(kw)
preprocessArgs!(d) preprocessArgs!(d)
@ -193,7 +192,7 @@ function _plot!(plt::Plot, d::KW, args::Tuple)
still_to_process = kw_list still_to_process = kw_list
kw_list = KW[] kw_list = KW[]
while !isempty(still_to_process) while !isempty(still_to_process)
next_kw = shift!(still_to_process) next_kw = popfirst!(still_to_process)
_process_plotrecipe(plt, next_kw, kw_list, still_to_process) _process_plotrecipe(plt, next_kw, kw_list, still_to_process)
end end

View File

@ -80,7 +80,7 @@ end
@recipe function f(::Type{Val{:hline}}, x, y, z) @recipe function f(::Type{Val{:hline}}, x, y, z)
n = length(y) n = length(y)
newx = repmat(Float64[-1, 1, NaN], n) newx = repeat(Float64[-1, 1, NaN], n)
newy = vec(Float64[yi for i=1:3,yi=y]) newy = vec(Float64[yi for i=1:3,yi=y])
x := newx x := newx
y := newy y := newy
@ -92,7 +92,7 @@ end
@recipe function f(::Type{Val{:vline}}, x, y, z) @recipe function f(::Type{Val{:vline}}, x, y, z)
n = length(y) n = length(y)
newx = vec(Float64[yi for i=1:3,yi=y]) newx = vec(Float64[yi for i=1:3,yi=y])
newy = repmat(Float64[-1, 1, NaN], n) newy = repeat(Float64[-1, 1, NaN], n)
x := newx x := newx
y := newy y := newy
seriestype := :straightline seriestype := :straightline
@ -620,10 +620,10 @@ _hist_edge(vs::NTuple{N,AbstractVector}, dim::Integer, binning::Symbol) where {N
_hist_edge(vs::NTuple{N,AbstractVector}, dim::Integer, binning::AbstractVector) where {N} = binning _hist_edge(vs::NTuple{N,AbstractVector}, dim::Integer, binning::AbstractVector) where {N} = binning
_hist_edges(vs::NTuple{N,AbstractVector}, binning::NTuple{N}) where {N} = _hist_edges(vs::NTuple{N,AbstractVector}, binning::NTuple{N}) where {N} =
map(dim -> _hist_edge(vs, dim, binning[dim]), (1:N...)) map(dim -> _hist_edge(vs, dim, binning[dim]), (1:N...,))
_hist_edges(vs::NTuple{N,AbstractVector}, binning::Union{Integer, Symbol, AbstractVector}) where {N} = _hist_edges(vs::NTuple{N,AbstractVector}, binning::Union{Integer, Symbol, AbstractVector}) where {N} =
map(dim -> _hist_edge(vs, dim, binning), (1:N...)) map(dim -> _hist_edge(vs, dim, binning), (1:N...,))
_hist_norm_mode(mode::Symbol) = mode _hist_norm_mode(mode::Symbol) = mode
_hist_norm_mode(mode::Bool) = mode ? :pdf : :none _hist_norm_mode(mode::Bool) = mode ? :pdf : :none

View File

@ -14,7 +14,7 @@ all3D(d::KW) = trueOrAllTrue(st -> st in (:contour, :contourf, :heatmap, :surfac
convertToAnyVector(x, d::KW) = error("No user recipe defined for $(typeof(x))") convertToAnyVector(x, d::KW) = error("No user recipe defined for $(typeof(x))")
# missing # missing
convertToAnyVector(v::Void, d::KW) = Any[nothing], nothing convertToAnyVector(v::Nothing, d::KW) = Any[nothing], nothing
# fixed number of blank series # fixed number of blank series
convertToAnyVector(n::Integer, d::KW) = Any[zeros(0) for i in 1:n], nothing convertToAnyVector(n::Integer, d::KW) = Any[zeros(0) for i in 1:n], nothing
@ -46,7 +46,7 @@ convertToAnyVector(v::Volume, d::KW) = Any[v], nothing
# convertToAnyVector(v::AVec{OHLC}, d::KW) = Any[v], nothing # convertToAnyVector(v::AVec{OHLC}, d::KW) = Any[v], nothing
# # dates # # dates
convertToAnyVector{D<:Union{Date,DateTime}}(dts::AVec{D}, d::KW) = Any[dts], nothing convertToAnyVector(dts::AVec{D}, d::KW) where {D<:Union{Date,DateTime}} = Any[dts], nothing
# list of things (maybe other vectors, functions, or something else) # list of things (maybe other vectors, functions, or something else)
function convertToAnyVector(v::AVec, d::KW) function convertToAnyVector(v::AVec, d::KW)
@ -72,19 +72,19 @@ end
# TODO: can we avoid the copy here? one error that crops up is that mapping functions over the same array # TODO: can we avoid the copy here? one error that crops up is that mapping functions over the same array
# result in that array being shared. push!, etc will add too many items to that array # result in that array being shared. push!, etc will add too many items to that array
compute_x(x::Void, y::Void, z) = 1:size(z,1) compute_x(x::Nothing, y::Nothing, z) = 1:size(z,1)
compute_x(x::Void, y, z) = 1:size(y,1) compute_x(x::Nothing, y, z) = 1:size(y,1)
compute_x(x::Function, y, z) = map(x, y) compute_x(x::Function, y, z) = map(x, y)
compute_x(x, y, z) = copy(x) compute_x(x, y, z) = copy(x)
# compute_y(x::Void, y::Function, z) = error() # compute_y(x::Nothing, y::Function, z) = error()
compute_y(x::Void, y::Void, z) = 1:size(z,2) compute_y(x::Nothing, y::Nothing, z) = 1:size(z,2)
compute_y(x, y::Function, z) = map(y, x) compute_y(x, y::Function, z) = map(y, x)
compute_y(x, y, z) = copy(y) compute_y(x, y, z) = copy(y)
compute_z(x, y, z::Function) = map(z, x, y) compute_z(x, y, z::Function) = map(z, x, y)
compute_z(x, y, z::AbstractMatrix) = Surface(z) compute_z(x, y, z::AbstractMatrix) = Surface(z)
compute_z(x, y, z::Void) = nothing compute_z(x, y, z::Nothing) = nothing
compute_z(x, y, z) = copy(z) compute_z(x, y, z) = copy(z)
nobigs(v::AVec{BigFloat}) = map(Float64, v) nobigs(v::AVec{BigFloat}) = map(Float64, v)
@ -99,9 +99,9 @@ nobigs(v) = v
end end
# not allowed # not allowed
compute_xyz(x::Void, y::FuncOrFuncs{F}, z) where {F<:Function} = error("If you want to plot the function `$y`, you need to define the x values!") compute_xyz(x::Nothing, y::FuncOrFuncs{F}, z) where {F<:Function} = error("If you want to plot the function `$y`, you need to define the x values!")
compute_xyz(x::Void, y::Void, z::FuncOrFuncs{F}) where {F<:Function} = error("If you want to plot the function `$z`, you need to define x and y values!") compute_xyz(x::Nothing, y::Nothing, z::FuncOrFuncs{F}) where {F<:Function} = error("If you want to plot the function `$z`, you need to define x and y values!")
compute_xyz(x::Void, y::Void, z::Void) = error("x/y/z are all nothing!") compute_xyz(x::Nothing, y::Nothing, z::Nothing) = error("x/y/z are all nothing!")
# -------------------------------------------------------------------- # --------------------------------------------------------------------

View File

@ -6,7 +6,7 @@ const AVec = AbstractVector
const AMat = AbstractMatrix const AMat = AbstractMatrix
const KW = Dict{Symbol,Any} const KW = Dict{Symbol,Any}
struct PlotsDisplay <: Display end struct PlotsDisplay <: AbstractDisplay end
# ----------------------------------------------------------- # -----------------------------------------------------------

View File

@ -259,7 +259,7 @@ float_extended_type(x::AbstractArray{T}) where {T<:Real} = Float64
nop() = nothing nop() = nothing
notimpl() = error("This has not been implemented yet") notimpl() = error("This has not been implemented yet")
isnothing(x::Void) = true isnothing(x::Nothing) = true
isnothing(x) = false isnothing(x) = false
_cycle(wrapper::InputWrapper, idx::Int) = wrapper.obj _cycle(wrapper::InputWrapper, idx::Int) = wrapper.obj
@ -305,7 +305,7 @@ function _expand_limits(lims, x)
e1, e2 = ignorenan_extrema(x) e1, e2 = ignorenan_extrema(x)
lims[1] = NaNMath.min(lims[1], e1) lims[1] = NaNMath.min(lims[1], e1)
lims[2] = NaNMath.max(lims[2], e2) lims[2] = NaNMath.max(lims[2], e2)
# catch err catch err
# warn(err) # warn(err)
end end
nothing nothing
@ -343,7 +343,7 @@ function replaceAliases!(d::KW, aliases::Dict{Symbol,Symbol})
end end
end end
createSegments(z) = collect(repmat(reshape(z,1,:),2,1))[2:end] createSegments(z) = collect(repeat(reshape(z,1,:),2,1))[2:end]
Base.first(c::Colorant) = c Base.first(c::Colorant) = c
Base.first(x::Symbol) = x Base.first(x::Symbol) = x
@ -355,7 +355,7 @@ sortedkeys(d::Dict) = sort(collect(keys(d)))
const _scale_base = Dict{Symbol, Real}( const _scale_base = Dict{Symbol, Real}(
:log10 => 10, :log10 => 10,
:log2 => 2, :log2 => 2,
:ln => e, :ln => euler_e
) )
function _heatmap_edges(v::AVec) function _heatmap_edges(v::AVec)
@ -450,8 +450,8 @@ limsType(lims) = :invalid
# axis_Symbol(letter, postfix) = Symbol(letter * postfix) # axis_Symbol(letter, postfix) = Symbol(letter * postfix)
# axis_symbols(letter, postfix...) = map(s -> axis_Symbol(letter, s), postfix) # axis_symbols(letter, postfix...) = map(s -> axis_Symbol(letter, s), postfix)
Base.convert(::Type{Vector{T}}, rng::Range{T}) where {T<:Real} = T[x for x in rng] Base.convert(::Type{Vector{T}}, rng::AbstractRange{T}) where {T<:Real} = T[x for x in rng]
Base.convert(::Type{Vector{T}}, rng::Range{S}) where {T<:Real,S<: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))) Base.merge(a::AbstractVector, b::AbstractVector) = sort(unique(vcat(a,b)))
@ -846,8 +846,8 @@ end
extendSeriesByOne(v::UnitRange{Int}, n::Int = 1) = isempty(v) ? (1:n) : (minimum(v):maximum(v)+n) extendSeriesByOne(v::UnitRange{Int}, n::Int = 1) = isempty(v) ? (1:n) : (minimum(v):maximum(v)+n)
extendSeriesByOne(v::AVec, n::Integer = 1) = isempty(v) ? (1:n) : vcat(v, (1:n) + ignorenan_maximum(v)) extendSeriesByOne(v::AVec, n::Integer = 1) = isempty(v) ? (1:n) : vcat(v, (1:n) + ignorenan_maximum(v))
extendSeriesData(v::Range{T}, z::Real) where {T} = extendSeriesData(float(collect(v)), z) extendSeriesData(v::AbstractRange{T}, z::Real) where {T} = extendSeriesData(float(collect(v)), z)
extendSeriesData(v::Range{T}, z::AVec) where {T} = extendSeriesData(float(collect(v)), z) extendSeriesData(v::AbstractRange{T}, z::AVec) where {T} = extendSeriesData(float(collect(v)), z)
extendSeriesData(v::AVec{T}, z::Real) where {T} = (push!(v, convert(T, z)); v) extendSeriesData(v::AVec{T}, z::Real) where {T} = (push!(v, convert(T, z)); v)
extendSeriesData(v::AVec{T}, z::AVec) where {T} = (append!(v, convert(Vector{T}, z)); v) extendSeriesData(v::AVec{T}, z::AVec) where {T} = (append!(v, convert(Vector{T}, z)); v)
@ -856,7 +856,7 @@ extendSeriesData(v::AVec{T}, z::AVec) where {T} = (append!(v, convert(Ve
# NOTE: backends should implement the following methods to get/set the x/y/z data objects # NOTE: backends should implement the following methods to get/set the x/y/z data objects
tovec(v::AbstractVector) = v tovec(v::AbstractVector) = v
tovec(v::Void) = zeros(0) tovec(v::Nothing) = zeros(0)
function getxy(plt::Plot, i::Integer) function getxy(plt::Plot, i::Integer)
d = plt.series_list[i].d d = plt.series_list[i].d
@ -1138,9 +1138,9 @@ function convert_sci_unicode(label::AbstractString)
"×10" => "×10^{", "×10" => "×10^{",
) )
for key in keys(unicode_dict) for key in keys(unicode_dict)
label = replace(label, key, unicode_dict[key]) label = replace(label, key => unicode_dict[key])
end end
if contains(label, "10^{") if occursin("10^{", label)
label = string(label, "}") label = string(label, "}")
end end
label label