diff --git a/REQUIRE b/REQUIRE index b9cf9457..26a3ae70 100644 --- a/REQUIRE +++ b/REQUIRE @@ -1,4 +1,4 @@ -julia 0.7-alpha +julia 0.7 RecipesBase 0.2.3 PlotUtils 0.4.1 diff --git a/src/Plots.jl b/src/Plots.jl index d67a0381..854b13bf 100644 --- a/src/Plots.jl +++ b/src/Plots.jl @@ -1,5 +1,3 @@ -__precompile__(true) - module Plots using Reexport @@ -171,6 +169,7 @@ include("arg_desc.jl") include("plotattr.jl") include("backends.jl") include("output.jl") +include("init.jl") # --------------------------------------------------------- @@ -236,10 +235,10 @@ zlims!(zmin::Real, zmax::Real; kw...) = plot!(; zlims = (zmi "Set xticks for an existing plot" -xticks!(v::AVec{T}; kw...) where {T<:Real} = plot!(; xticks = v, kw...) +xticks!(v::TicksArgs; kw...) where {T<:Real} = plot!(; xticks = v, kw...) "Set yticks for an existing plot" -yticks!(v::AVec{T}; kw...) where {T<:Real} = plot!(; yticks = v, kw...) +yticks!(v::TicksArgs; kw...) where {T<:Real} = plot!(; yticks = v, kw...) xticks!( ticks::AVec{T}, labels::AVec{S}; kw...) where {T<:Real,S<:AbstractString} = plot!(; xticks = (ticks,labels), kw...) @@ -274,8 +273,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::AVec{T}; kw...) where {T<:Real} = plot!(plt; xticks = ticks, kw...) - global yticks!(plt::PlotOrSubplot, ticks::AVec{T}; kw...) where {T<:Real} = plot!(plt; yticks = ticks, 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::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/args.jl b/src/args.jl index 7930b775..a6310170 100644 --- a/src/args.jl +++ b/src/args.jl @@ -194,7 +194,7 @@ function hasgrid(arg::Symbol, letter) if arg in _allGridSyms arg in (:all, :both, :on) || occursin(string(letter), string(arg)) else - warn("Unknown grid argument $arg; $(Symbol(letter, :grid)) was set to `true` instead.") + @warn("Unknown grid argument $arg; $(Symbol(letter, :grid)) was set to `true` instead.") true end end @@ -212,7 +212,7 @@ function showaxis(arg::Symbol, letter) if arg in _allGridSyms arg in (:all, :both, :on, :yes) || occursin(string(letter), string(arg)) else - warn("Unknown showaxis argument $arg; $(Symbol(letter, :showaxis)) was set to `true` instead.") + @warn("Unknown showaxis argument $arg; $(Symbol(letter, :showaxis)) was set to `true` instead.") true end end @@ -704,7 +704,7 @@ function processLineArg(d::KW, arg) # color elseif !handleColors!(d, arg, :linecolor) - warn("Skipped line arg $arg.") + @warn("Skipped line arg $arg.") end end @@ -740,7 +740,7 @@ function processMarkerArg(d::KW, arg) # markercolor elseif !handleColors!(d, arg, :markercolor) - warn("Skipped marker arg $arg.") + @warn("Skipped marker arg $arg.") end end @@ -800,7 +800,7 @@ function processGridArg!(d::KW, arg, letter) # color elseif !handleColors!(d, arg, Symbol(letter, :foreground_color_grid)) - warn("Skipped grid arg $arg.") + @warn("Skipped grid arg $arg.") end end @@ -834,7 +834,7 @@ function processMinorGridArg!(d::KW, arg, letter) elseif handleColors!(d, arg, Symbol(letter, :foreground_color_minor_grid)) d[Symbol(letter, :minorgrid)] = true else - warn("Skipped grid arg $arg.") + @warn("Skipped grid arg $arg.") end end @@ -867,7 +867,7 @@ function processFontArg!(d::KW, fontname::Symbol, arg) elseif typeof(arg) <: Real d[Symbol(fontname, :rotation)] = convert(Float64, arg) else - warn("Skipped font arg: $arg ($(typeof(arg)))") + @warn("Skipped font arg: $arg ($(typeof(arg)))") end end @@ -1050,7 +1050,7 @@ function preprocessArgs!(d::KW) # warnings for moved recipes st = get(d, :seriestype, :path) if st in (:boxplot, :violin, :density) && !isdefined(Main, :StatPlots) - warn("seriestype $st has been moved to StatPlots. To use: \`Pkg.add(\"StatPlots\"); using StatPlots\`") + @warn("seriestype $st has been moved to StatPlots. To use: \`Pkg.add(\"StatPlots\"); using StatPlots\`") end return @@ -1070,7 +1070,7 @@ function extractGroupArgs(v::AVec, args...; legendEntry = string) groupLabels = sort(collect(unique(v))) n = length(groupLabels) if n > 100 - warn("You created n=$n groups... Is that intended?") + @warn("You created n=$n groups... Is that intended?") end groupIds = Vector{Int}[filter(i -> v[i] == glab, 1:length(v)) for glab in groupLabels] GroupBy(map(legendEntry, groupLabels), groupIds) @@ -1142,7 +1142,7 @@ function warnOnUnsupported_args(pkg::AbstractBackend, d::KW) if !isempty(_to_warn) for k in sort(collect(_to_warn)) push!(already_warned, k) - warn("Keyword argument $k not supported with $pkg. Choose from: $(supported_attrs(pkg))") + @warn("Keyword argument $k not supported with $pkg. Choose from: $(supported_attrs(pkg))") end end end @@ -1153,13 +1153,13 @@ end function warnOnUnsupported(pkg::AbstractBackend, d::KW) if !is_seriestype_supported(pkg, d[:seriestype]) - warn("seriestype $(d[:seriestype]) is unsupported with $pkg. Choose from: $(supported_seriestypes(pkg))") + @warn("seriestype $(d[:seriestype]) is unsupported with $pkg. Choose from: $(supported_seriestypes(pkg))") end if !is_style_supported(pkg, d[:linestyle]) - warn("linestyle $(d[:linestyle]) is unsupported with $pkg. Choose from: $(supported_styles(pkg))") + @warn("linestyle $(d[:linestyle]) is unsupported with $pkg. Choose from: $(supported_styles(pkg))") end if !is_marker_supported(pkg, d[:markershape]) - warn("markershape $(d[:markershape]) is unsupported with $pkg. Choose from: $(supported_markers(pkg))") + @warn("markershape $(d[:markershape]) is unsupported with $pkg. Choose from: $(supported_markers(pkg))") end end @@ -1168,7 +1168,7 @@ function warnOnUnsupported_scales(pkg::AbstractBackend, d::KW) if haskey(d, k) v = d[k] if !is_scale_supported(pkg, v) - warn("scale $v is unsupported with $pkg. Choose from: $(supported_scales(pkg))") + @warn("scale $v is unsupported with $pkg. Choose from: $(supported_scales(pkg))") end end end diff --git a/src/axes.jl b/src/axes.jl index 43bef9a0..094d4494 100644 --- a/src/axes.jl +++ b/src/axes.jl @@ -80,7 +80,7 @@ function process_axis_arg!(d::KW, arg, letter = "") d[Symbol(letter,:formatter)] = arg elseif !handleColors!(d, arg, Symbol(letter, :foreground_color_axis)) - warn("Skipped $(letter)axis arg $arg") + @warn("Skipped $(letter)axis arg $arg") end end diff --git a/src/backends.jl b/src/backends.jl index 3e1affce..ad1b92d2 100644 --- a/src/backends.jl +++ b/src/backends.jl @@ -6,6 +6,8 @@ const _backendType = Dict{Symbol, DataType}(:none => NoBackend) const _backendSymbol = Dict{DataType, Symbol}(NoBackend => :none) const _backends = Symbol[] const _initialized_backends = Set{Symbol}() +const _default_backends = (:none, :gr, :plotly) +const _backendPackage = Dict{Symbol, Symbol}() "Returns a list of supported backends" backends() = _backends @@ -13,9 +15,12 @@ backends() = _backends "Returns the name of the current backend" backend_name() = CURRENT_BACKEND.sym _backend_instance(sym::Symbol) = haskey(_backendType, sym) ? _backendType[sym]() : error("Unsupported backend $sym") +backend_package(pkg::Symbol) = pkg in _default_backends ? :Plots : Symbol("Plots", _backendPackage[pkg]) +backend_package_name(sym::Symbol) = sym in _default_backends ? :Plots : _backendPackage[sym] macro init_backend(s) - str = lowercase(string(s)) + package_str = string(s) + str = lowercase(package_str) sym = Symbol(str) T = Symbol(string(s) * "Backend") esc(quote @@ -23,14 +28,16 @@ macro init_backend(s) export $sym $sym(; kw...) = (default(; kw...); backend(Symbol($str))) backend_name(::$T) = Symbol($str) + backend_package_name(pkg::$T) = backend_package_name(Symbol($str)) push!(_backends, Symbol($str)) _backendType[Symbol($str)] = $T _backendSymbol[$T] = Symbol($str) - include("backends/" * $str * ".jl") + _backendPackage[Symbol($str)] = Symbol($package_str) + # include("backends/" * $str * ".jl") end) end -include("backends/web.jl") +# include("backends/web.jl") # include("backends/supported.jl") # --------------------------------------------------------- @@ -40,7 +47,6 @@ function add_backend(pkg::Symbol) println(add_backend_string(_backend_instance(pkg))) println() end -add_backend_string(b::AbstractBackend) = warn("No custom install defined for $(backend_name(b))") # don't do anything as a default _create_backend_figure(plt::Plot) = nothing @@ -135,30 +141,30 @@ CurrentBackend(sym::Symbol) = CurrentBackend(sym, _backend_instance(sym)) function pickDefaultBackend() env_default = get(ENV, "PLOTS_DEFAULT_BACKEND", "") if env_default != "" - if env_default in keys(Pkg.installed()) - sym = Symbol(lowercase(env_default)) - if haskey(_backendType, sym) + sym = Symbol(lowercase(env_default)) + if sym in _backends + if sym in _initialized_backends return backend(sym) else - warn("You have set PLOTS_DEFAULT_BACKEND=$env_default but it is not a valid backend package. Choose from:\n\t", - join(sort(_backends), "\n\t")) + @warn("You have set `PLOTS_DEFAULT_BACKEND=$env_default` but `$(backend_package_name(sym))` is not loaded.") end else - warn("You have set PLOTS_DEFAULT_BACKEND=$env_default but it is not installed.") + @warn("You have set PLOTS_DEFAULT_BACKEND=$env_default but it is not a valid backend package. Choose from:\n\t", + join(sort(_backends), "\n\t")) end end # the ordering/inclusion of this package list is my semi-arbitrary guess at # which one someone will want to use if they have the package installed...accounting for # features, speed, and robustness - for pkgstr in ("GR", "PyPlot", "PlotlyJS", "PGFPlots", "UnicodePlots", "InspectDR", "GLVisualize") - if pkgstr in keys(Pkg.installed()) - return backend(Symbol(lowercase(pkgstr))) - end - end + # for pkgstr in ("GR", "PyPlot", "PlotlyJS", "PGFPlots", "UnicodePlots", "InspectDR", "GLVisualize") + # if pkgstr in keys(Pkg.installed()) + # return backend(Symbol(lowercase(pkgstr))) + # end + # end # the default if nothing else is installed - backend(:plotly) + backend(:gr) end @@ -174,24 +180,6 @@ function backend() pickDefaultBackend() end - sym = CURRENT_BACKEND.sym - if !(sym in _initialized_backends) - - # # initialize - # println("[Plots.jl] Initializing backend: ", sym) - - inst = _backend_instance(sym) - try - _initialize_backend(inst) - catch err - warn("Couldn't initialize $sym. (might need to install it?)") - add_backend(sym) - rethrow(err) - end - - push!(_initialized_backends, sym) - - end CURRENT_BACKEND.pkg end @@ -199,16 +187,29 @@ end Set the plot backend. """ function backend(pkg::AbstractBackend) - CURRENT_BACKEND.sym = backend_name(pkg) - warn_on_deprecated_backend(CURRENT_BACKEND.sym) - CURRENT_BACKEND.pkg = pkg + sym = backend_name(pkg) + if sym in _initialized_backends + CURRENT_BACKEND.sym = backend_name(pkg) + CURRENT_BACKEND.pkg = pkg + else + # try + _initialize_backend(pkg) + push!(_initialized_backends, sym) + CURRENT_BACKEND.sym = backend_name(pkg) + CURRENT_BACKEND.pkg = pkg + # catch + # add_backend(sym) + # end + end backend() end -function backend(modname::Symbol) - warn_on_deprecated_backend(modname) - CURRENT_BACKEND.sym = modname - CURRENT_BACKEND.pkg = _backend_instance(modname) +function backend(sym::Symbol) + if sym in _backends + backend(_backend_instance(sym)) + else + @warn("`:$sym` is not a supported backend.") + end backend() end @@ -216,7 +217,7 @@ const _deprecated_backends = [:qwt, :winston, :bokeh, :gadfly, :immerse] function warn_on_deprecated_backend(bsym::Symbol) if bsym in _deprecated_backends - warn("Backend $bsym has been deprecated. It may not work as originally intended.") + @warn("Backend $bsym has been deprecated. It may not work as originally intended.") end end @@ -308,3 +309,109 @@ end # is_subplot_supported(::AbstractBackend) = false # is_subplot_supported() = is_subplot_supported(backend()) + + +################################################################################ +# initialize the backends + +function _initialize_backend(pkg::AbstractBackend) + sym = backend_package_name(pkg) + @eval Main begin + import $sym + export $sym + end +end + +function add_backend_string(pkg::AbstractBackend) + sym = backend_package_name(pkg) + """ + using Pkg + Pkg.add("$sym") + """ +end + +# ------------------------------------------------------------------------------ +# glvisualize + +function _initialize_backend(::GLVisualizeBackend; kw...) + @eval Main begin + import GLVisualize, GeometryTypes, Reactive, GLAbstraction, GLWindow, Contour + import GeometryTypes: Point2f0, Point3f0, Vec2f0, Vec3f0, GLNormalMesh, SimpleRectangle, Point, Vec + import FileIO, Images + export GLVisualize + import Reactive: Signal + import GLAbstraction: Style + import GLVisualize: visualize + import Plots.GL + import UnicodeFun + end +end + +# ------------------------------------------------------------------------------ +# hdf5 + +function _initialize_backend(::HDF5Backend) + @eval Main begin + import HDF5 + export HDF5 + end +end + +# ------------------------------------------------------------------------------ +# PGFPLOTS + +function add_backend_string(::PGFPlotsBackend) + """ + using Pkg + Pkg.add("PGFPlots") + Pkg.build("PGFPlots") + """ +end + +# ------------------------------------------------------------------------------ +# plotlyjs + +function add_backend_string(::PlotlyJSBackend) + """ + using Pkg + Pkg.add("PlotlyJS") + Pkg.add("Rsvg") + import Blink + Blink.AtomShell.install() + """ +end + +# ------------------------------------------------------------------------------ +# pyplot + +function _initialize_backend(::PyPlotBackend) + @eval Main begin + import PyPlot, PyCall + import LaTeXStrings: latexstring + + export PyPlot + + # we don't want every command to update the figure + PyPlot.ioff() + end +end + +function add_backend_string(::PyPlotBackend) + """ + using Pkg + Pkg.add("PyPlot") + withenv("PYTHON" => "") do + Pkg.build("PyPlot") + end + """ +end + +# ------------------------------------------------------------------------------ +# unicodeplots +function add_backend_string(::UnicodePlotsBackend) + """ + using Pkg + Pkg.add("UnicodePlots") + Pkg.build("UnicodePlots") + """ +end diff --git a/src/backends/glvisualize.jl b/src/backends/glvisualize.jl index 29880097..bf33704b 100644 --- a/src/backends/glvisualize.jl +++ b/src/backends/glvisualize.jl @@ -9,10 +9,6 @@ TODO * fix units in all visuals (e.g dotted lines, marker scale, surfaces) =# -@require Revise = "295af30f-e4ad-537b-8983-00126c2a3abe" begin - Revise.track(Plots, joinpath(Pkg.dir("Plots"), "src", "backends", "glvisualize.jl")) -end - const _glvisualize_attr = merge_with_base_supported([ :annotations, :background_color_legend, :background_color_inside, :background_color_outside, @@ -61,36 +57,11 @@ const _glvisualize_style = [:auto, :solid, :dash, :dot, :dashdot] const _glvisualize_marker = _allMarkers const _glvisualize_scale = [:identity, :ln, :log2, :log10] - - -# -------------------------------------------------------------------------------------- - -function _initialize_backend(::GLVisualizeBackend; kw...) - @eval begin - import GLVisualize, GeometryTypes, Reactive, GLAbstraction, GLWindow, Contour - import GeometryTypes: Point2f0, Point3f0, Vec2f0, Vec3f0, GLNormalMesh, SimpleRectangle, Point, Vec - import FileIO, Images - export GLVisualize - import Reactive: Signal - import GLAbstraction: Style - import GLVisualize: visualize - import Plots.GL - import UnicodeFun - Plots.slice_arg(img::Matrix{C}, idx::Int) where {C<:Colorant} = img - is_marker_supported(::GLVisualizeBackend, shape::GLVisualize.AllPrimitives) = true - is_marker_supported(::GLVisualizeBackend, shape::Union{Vector{Matrix{C}}, Matrix{C}}) where {C<:Colorant} = true - is_marker_supported(::GLVisualizeBackend, shape::Shape) = true - GL = Plots - end -end - -function add_backend_string(b::GLVisualizeBackend) - """ - if !Plots.is_installed("GLVisualize") - Pkg.add("GLVisualize") - end - """ -end +slice_arg(img::Matrix{C}, idx::Int) where {C<:Colorant} = img +is_marker_supported(::GLVisualizeBackend, shape::GLVisualize.AllPrimitives) = true +is_marker_supported(::GLVisualizeBackend, shape::Union{Vector{Matrix{C}}, Matrix{C}}) where {C<:Colorant} = true +is_marker_supported(::GLVisualizeBackend, shape::Shape) = true +GL = Plots # --------------------------------------------------------------------------- @@ -1329,7 +1300,7 @@ function gl_poly(points, kw_args) if !isempty(GeometryTypes.faces(mesh)) # check if polygonation has any faces push!(result, GLVisualize.visualize(mesh, Style(:default), kw_args)) else - warn("Couldn't draw the polygon: $points") + @warn("Couldn't draw the polygon: $points") end end result diff --git a/src/backends/gr.jl b/src/backends/gr.jl index 099378d7..0c2253fe 100644 --- a/src/backends/gr.jl +++ b/src/backends/gr.jl @@ -3,10 +3,6 @@ # significant contributions by @jheinen -@require Revise = "295af30f-e4ad-537b-8983-00126c2a3abe" begin - Revise.track(Plots, joinpath(Pkg.dir("Plots"), "src", "backends", "gr.jl")) -end - const _gr_attr = merge_with_base_supported([ :annotations, :background_color_legend, :background_color_inside, :background_color_outside, @@ -65,12 +61,8 @@ function add_backend_string(::GRBackend) """ end -function _initialize_backend(::GRBackend; kw...) - @eval begin - import GR - export GR - end -end +import GR +export GR # -------------------------------------------------------------------------------------- @@ -624,7 +616,7 @@ end function _update_min_padding!(sp::Subplot{GRBackend}) dpi = sp.plt[:thickness_scaling] if !haskey(ENV, "GKSwstype") - if isijulia() || (isdefined(Main, :Juno) && Juno.isactive()) + if isijulia() ENV["GKSwstype"] = "svg" end end diff --git a/src/backends/hdf5.jl b/src/backends/hdf5.jl index 0d8c1901..d8919942 100644 --- a/src/backends/hdf5.jl +++ b/src/backends/hdf5.jl @@ -28,10 +28,6 @@ Read from .hdf5 file using: - Should be reliable for archival purposes. ==# -@require Revise = "295af30f-e4ad-537b-8983-00126c2a3abe" begin - Revise.track(Plots, joinpath(Pkg.dir("Plots"), "src", "backends", "hdf5.jl")) -end - import FixedPointNumbers: N0f8 #In core Julia #Dispatch types: @@ -108,12 +104,35 @@ const _hdf5_marker = vcat(_allMarkers, :pixel) const _hdf5_scale = [:identity, :ln, :log2, :log10] is_marker_supported(::HDF5Backend, shape::Shape) = true -function add_backend_string(::HDF5Backend) - """ - if !Plots.is_installed("HDF5") - Pkg.add("HDF5") - end - """ +if length(HDF5PLOT_MAP_TELEM2STR) < 1 + #Possible element types of high-level data types: + telem2str = Dict{String, Type}( + "NATIVE" => HDF5PlotNative, + "VOID" => Nothing, + "BOOL" => Bool, + "SYMBOL" => Symbol, + "TUPLE" => Tuple, + "CTUPLE" => HDF5CTuple, #Tuple of complex structures + "RGBA" => ARGB{N0f8}, + "EXTREMA" => Extrema, + "LENGTH" => Length, + "ARRAY" => Array, #Dict won't allow Array to be key in HDF5PLOT_MAP_TELEM2STR + + #Sub-structure types: + "FONT" => Font, + "BOUNDINGBOX" => BoundingBox, + "GRIDLAYOUT" => GridLayout, + "ROOTLAYOUT" => RootLayout, + "SERIESANNOTATIONS" => SeriesAnnotations, +# "PLOTTEXT" => PlotText, + "COLORGRADIENT" => ColorGradient, + "AXIS" => Axis, + "SURFACE" => Surface, + "SUBPLOT" => Subplot, + "NULLABLE" => Nullable, + ) + merge!(HDF5PLOT_MAP_STR2TELEM, telem2str) + merge!(HDF5PLOT_MAP_TELEM2STR, Dict{Type, String}(v=>k for (k,v) in HDF5PLOT_MAP_STR2TELEM)) end @@ -140,44 +159,6 @@ end #== ===============================================================================# -function _initialize_backend(::HDF5Backend) - @eval begin - import HDF5 - export HDF5 - if length(HDF5PLOT_MAP_TELEM2STR) < 1 - #Possible element types of high-level data types: - telem2str = Dict{String, Type}( - "NATIVE" => HDF5PlotNative, - "VOID" => Nothing, - "BOOL" => Bool, - "SYMBOL" => Symbol, - "TUPLE" => Tuple, - "CTUPLE" => HDF5CTuple, #Tuple of complex structures - "RGBA" => ARGB{N0f8}, - "EXTREMA" => Extrema, - "LENGTH" => Length, - "ARRAY" => Array, #Dict won't allow Array to be key in HDF5PLOT_MAP_TELEM2STR - - #Sub-structure types: - "FONT" => Font, - "BOUNDINGBOX" => BoundingBox, - "GRIDLAYOUT" => GridLayout, - "ROOTLAYOUT" => RootLayout, - "SERIESANNOTATIONS" => SeriesAnnotations, -# "PLOTTEXT" => PlotText, - "COLORGRADIENT" => ColorGradient, - "AXIS" => Axis, - "SURFACE" => Surface, - "SUBPLOT" => Subplot, - "NULLABLE" => Nullable, - ) - merge!(HDF5PLOT_MAP_STR2TELEM, telem2str) - merge!(HDF5PLOT_MAP_TELEM2STR, Dict{Type, String}(v=>k for (k,v) in HDF5PLOT_MAP_STR2TELEM)) - end - end -end - -# --------------------------------------------------------------------------- # Create the window/figure for this backend. function _create_backend_figure(plt::Plot{HDF5Backend}) @@ -244,7 +225,7 @@ end function _display(plt::Plot{HDF5Backend}) msg = "HDF5 interface does not support `display()` function." msg *= "\nUse `Plots.hdf5plot_write(::String)` method to write to .HDF5 \"plot\" file instead." - warn(msg) + @warn(msg) return end @@ -312,7 +293,7 @@ end #= function _hdf5plot_gwrite(grp, k::String, v::Array{Any}) # @show grp, k - warn("Cannot write Array: $k=$v") + @warn("Cannot write Array: $k=$v") end =# function _hdf5plot_gwrite(grp, k::String, v::Nothing) @@ -342,7 +323,7 @@ function _hdf5plot_gwrite(grp, k::String, v::Tuple) #NOTE: _hdf5plot_overwritetype overwrites "Array" type with "Tuple". end function _hdf5plot_gwrite(grp, k::String, d::Dict) -# warn("Cannot write dict: $k=$d") +# @warn("Cannot write dict: $k=$d") end function _hdf5plot_gwrite(grp, k::String, v::AbstractRange) _hdf5plot_gwrite(grp, k, collect(v)) #For now @@ -605,7 +586,7 @@ function _hdf5plot_read(grp, d::Dict) catch e @show e @show grp - warn("Could not read field $k") + @warn("Could not read field $k") end end return diff --git a/src/backends/inspectdr.jl b/src/backends/inspectdr.jl index 3eb8e5fc..2a82f192 100644 --- a/src/backends/inspectdr.jl +++ b/src/backends/inspectdr.jl @@ -13,10 +13,6 @@ Add in functionality to Plots.jl: :aspect_ratio, =# -@require Revise = "295af30f-e4ad-537b-8983-00126c2a3abe" begin - Revise.track(Plots, joinpath(Pkg.dir("Plots"), "src", "backends", "inspectdr.jl")) -end - # --------------------------------------------------------------------------- #TODO: remove features const _inspectdr_attr = merge_with_base_supported([ @@ -152,37 +148,23 @@ end # --------------------------------------------------------------------------- -function add_backend_string(::InspectDRBackend) - """ - if !Plots.is_installed("InspectDR") - Pkg.add("InspectDR") - end - """ +#Glyph used when plotting "Shape"s: +INSPECTDR_GLYPH_SHAPE = InspectDR.GlyphPolyline( + 2*InspectDR.GLYPH_SQUARE.x, InspectDR.GLYPH_SQUARE.y +) + +mutable struct InspecDRPlotRef + mplot::Union{Nothing, InspectDR.Multiplot} + gui::Union{Nothing, InspectDR.GtkPlot} end -function _initialize_backend(::InspectDRBackend; kw...) - @eval begin - import InspectDR - export InspectDR +_inspectdr_getmplot(::Any) = nothing +_inspectdr_getmplot(r::InspecDRPlotRef) = r.mplot - #Glyph used when plotting "Shape"s: - INSPECTDR_GLYPH_SHAPE = InspectDR.GlyphPolyline( - 2*InspectDR.GLYPH_SQUARE.x, InspectDR.GLYPH_SQUARE.y - ) - - mutable struct InspecDRPlotRef - mplot::Union{Nothing, InspectDR.Multiplot} - gui::Union{Nothing, InspectDR.GtkPlot} - end - - _inspectdr_getmplot(::Any) = nothing - _inspectdr_getmplot(r::InspecDRPlotRef) = r.mplot - - _inspectdr_getgui(::Any) = nothing - _inspectdr_getgui(gplot::InspectDR.GtkPlot) = (gplot.destroyed ? nothing : gplot) - _inspectdr_getgui(r::InspecDRPlotRef) = _inspectdr_getgui(r.gui) - end -end +_inspectdr_getgui(::Any) = nothing +_inspectdr_getgui(gplot::InspectDR.GtkPlot) = (gplot.destroyed ? nothing : gplot) +_inspectdr_getgui(r::InspecDRPlotRef) = _inspectdr_getgui(r.gui) +push!(_initialized_backends, :inspectdr) # --------------------------------------------------------------------------- diff --git a/src/backends/pgfplots.jl b/src/backends/pgfplots.jl index ab5f8bee..153331d8 100644 --- a/src/backends/pgfplots.jl +++ b/src/backends/pgfplots.jl @@ -2,10 +2,6 @@ # significant contributions by: @pkofod -@require Revise = "295af30f-e4ad-537b-8983-00126c2a3abe" begin - Revise.track(Plots, joinpath(Pkg.dir("Plots"), "src", "backends", "pgfplots.jl")) -end - const _pgfplots_attr = merge_with_base_supported([ :annotations, :background_color_legend, @@ -47,23 +43,6 @@ const _pgfplots_marker = [:none, :auto, :circle, :rect, :diamond, :utriangle, :d const _pgfplots_scale = [:identity, :ln, :log2, :log10] -# -------------------------------------------------------------------------------------- - -function add_backend_string(::PGFPlotsBackend) - """ - Pkg.add("PGFPlots") - Pkg.build("PGFPlots") - """ -end - -function _initialize_backend(::PGFPlotsBackend; kw...) - @eval begin - import PGFPlots - export PGFPlots - end -end - - # -------------------------------------------------------------------------------------- const _pgfplots_linestyles = KW( @@ -124,7 +103,7 @@ function pgf_framestyle(style::Symbol) return style else default_style = get(_pgf_framestyle_defaults, style, :axes) - warn("Framestyle :$style is not (yet) supported by the PGFPlots backend. :$default_style was cosen instead.") + @warn("Framestyle :$style is not (yet) supported by the PGFPlots backend. :$default_style was cosen instead.") default_style end end diff --git a/src/backends/plotly.jl b/src/backends/plotly.jl index 0b4c44d4..51c24c85 100644 --- a/src/backends/plotly.jl +++ b/src/backends/plotly.jl @@ -1,10 +1,6 @@ # https://plot.ly/javascript/getting-started -@require Revise = "295af30f-e4ad-537b-8983-00126c2a3abe" begin - Revise.track(Plots, joinpath(Pkg.dir("Plots"), "src", "backends", "plotly.jl")) -end - const _plotly_attr = merge_with_base_supported([ :annotations, :background_color_legend, :background_color_inside, :background_color_outside, @@ -68,7 +64,7 @@ function _plotly_framestyle(style::Symbol) return style else default_style = get(_plotly_framestyle_defaults, style, :axes) - warn("Framestyle :$style is not supported by Plotly and PlotlyJS. :$default_style was cosen instead.") + @warn("Framestyle :$style is not supported by Plotly and PlotlyJS. :$default_style was cosen instead.") default_style end end @@ -76,46 +72,37 @@ end # -------------------------------------------------------------------------------------- -function add_backend_string(::PlotlyBackend) - """ - Pkg.build("Plots") - """ -end - const _plotly_js_path = joinpath(dirname(@__FILE__), "..", "..", "deps", "plotly-latest.min.js") const _plotly_js_path_remote = "https://cdn.plot.ly/plotly-latest.min.js" -function _initialize_backend(::PlotlyBackend; kw...) - @eval begin - _js_code = open(readstring, _plotly_js_path, "r") +_js_code = open(read, _plotly_js_path, "r") - # borrowed from https://github.com/plotly/plotly.py/blob/2594076e29584ede2d09f2aa40a8a195b3f3fc66/plotly/offline/offline.py#L64-L71 c/o @spencerlyon2 - _js_script = """ - - """ +# borrowed from https://github.com/plotly/plotly.py/blob/2594076e29584ede2d09f2aa40a8a195b3f3fc66/plotly/offline/offline.py#L64-L71 c/o @spencerlyon2 +_js_script = """ + +""" - # if we're in IJulia call setupnotebook to load js and css - if isijulia() - display("text/html", _js_script) - end - - # if isatom() - # import Atom - # Atom.@msg evaljs(_js_code) - # end - - end - # TODO: other initialization +# if we're in IJulia call setupnotebook to load js and css +if isijulia() + display("text/html", _js_script) end +# if isatom() +# import Atom +# Atom.@msg evaljs(_js_code) +# end +using UUIDs + +push!(_initialized_backends, :plotly) + # ---------------------------------------------------------------- @@ -631,7 +618,7 @@ function plotly_series(plt::Plot, series::Series) d_out[:hoverinfo] = "label+percent+name" else - warn("Plotly: seriestype $st isn't supported.") + @warn("Plotly: seriestype $st isn't supported.") return KW() end @@ -744,7 +731,7 @@ function plotly_series_segments(series::Series, d_base::KW, x, y, z) d_out[:fill] = "tonexty" d_out[:fillcolor] = rgba_string(plot_color(get_fillcolor(series, i), get_fillalpha(series, i))) elseif !(series[:fillrange] in (false, nothing)) - warn("fillrange ignored... plotly only supports filling to zero and to a vector of values. fillrange: $(series[:fillrange])") + @warn("fillrange ignored... plotly only supports filling to zero and to a vector of values. fillrange: $(series[:fillrange])") end d_out[:x], d_out[:y] = x[rng], y[rng] @@ -906,7 +893,7 @@ function html_body(plt::Plot{PlotlyBackend}, style = nothing) w, h = plt[:size] style = "width:$(w)px;height:$(h)px;" end - uuid = Base.Random.uuid4() + uuid = UUIDs.uuid4() html = """