diff --git a/src/Plots.jl b/src/Plots.jl index 29b8574e..66d0d779 100644 --- a/src/Plots.jl +++ b/src/Plots.jl @@ -125,12 +125,28 @@ annotate!(plt::Plot, anns) = plot!(plt; annotation = # --------------------------------------------------------- + +defaultOutputFormat(plt::PlottingObject) = "png" + +function png(plt::PlottingObject, fn::AbstractString) + fn = addExtension(fn, "png") + io = open(fn, "w") + writemime(io, MIME("image/png"), plt) + close(io) +end +png(fn::AbstractString) = png(current(), fn) + + +const _savemap = Dict( + "png" => png, + ) + function getExtension(fn::AbstractString) pieces = split(fn, ".") - if length(pieces) < 2 - error("Can't extract file extension: ", fn) - end - pieces[end] + length(pieces) > 1 || error("Can't extract file extension: ", fn) + ext = pieces[end] + haskey(_savemap, ext) || error("Invalid file extension: ", fn) + ext end function addExtension(fn::AbstractString, ext::AbstractString) @@ -146,22 +162,19 @@ function addExtension(fn::AbstractString, ext::AbstractString) end end - -function png(plt::PlottingObject, fn::AbstractString) - fn = addExtension(fn, "png") - io = open(fn, "w") - writemime(io, MIME("image/png"), plt) - close(io) -end -png(fn::AbstractString) = png(current(), fn) - - -const _savemap = Dict( - "png" => png, - ) - function savefig(plt::PlottingObject, fn::AbstractString) - ext = getExtension(fn) + + # get the extension + local ext + try + ext = getExtension(fn) + catch + # if we couldn't extract the extension, add the default + ext = defaultOutputFormat(plt) + fn = addExtension(fn, ext) + end + + # save it func = get(_savemap, ext) do error("Unsupported extension $ext with filename ", fn) end diff --git a/src/args.jl b/src/args.jl index c92af45f..b982ce5d 100644 --- a/src/args.jl +++ b/src/args.jl @@ -351,6 +351,12 @@ function getPlotArgs(pkg::PlottingPackage, kw, idx::Int) d[k] = _plotDefaults[k] end end + + for k in (:xscale, :yscale) + if haskey(_scaleAliases, d[k]) + d[k] = _scaleAliases[d[k]] + end + end # convert color handlePlotColors(pkg, d) @@ -386,12 +392,6 @@ function getSeriesArgs(pkg::PlottingPackage, initargs::Dict, kw, commandIndex::I d[:linetype] = _typeAliases[d[:linetype]] end - for k in (:xscale, :yscale) - if haskey(_scaleAliases, d[k]) - d[k] = _scaleAliases[d[k]] - end - end - aliasesAndAutopick(d, :axis, _axesAliases, supportedAxes(pkg), plotIndex) aliasesAndAutopick(d, :linestyle, _styleAliases, supportedStyles(pkg), plotIndex) aliasesAndAutopick(d, :marker, _markerAliases, supportedMarkers(pkg), plotIndex) diff --git a/src/backends/gadfly.jl b/src/backends/gadfly.jl index 28d38d1b..d2e3837b 100644 --- a/src/backends/gadfly.jl +++ b/src/backends/gadfly.jl @@ -355,7 +355,7 @@ function addGadflyLimitsScale(gplt, d::Dict, isx::Bool) # get the correct scale function gfunc, hasScaleKey = getGadflyScaleFunction(d, isx) - @show d gfunc hasScaleKey + # @show d gfunc hasScaleKey # do we want to add min/max limits for the axis? limsym = isx ? :xlims : :ylims @@ -375,14 +375,14 @@ function addGadflyLimitsScale(gplt, d::Dict, isx::Bool) error("Invalid input for $(isx ? "xlims" : "ylims"): ", lims) end end - @show limargs + # @show limargs # replace any current scales with this one if hasScaleKey || !isempty(limargs) filterGadflyScale(gplt, isx) push!(gplt.scales, gfunc(; limargs...)) end - @show gplt.scales + # @show gplt.scales return end diff --git a/src/plot.jl b/src/plot.jl index a4c3c063..34f574aa 100644 --- a/src/plot.jl +++ b/src/plot.jl @@ -60,8 +60,14 @@ end -# this adds to the current plot +# this adds to the current plot, or creates a new plot if none are current function plot!(args...; kw...) + local plt + try + plt = current() + catch + return plot(args...; kw...) + end plot!(current(), args...; kw...) end