don't error on savefig without an ext, use default; closes #32

This commit is contained in:
Thomas Breloff 2015-09-30 09:55:07 -04:00
parent 69d574c587
commit 1f58ef5140
4 changed files with 48 additions and 29 deletions

View File

@ -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

View File

@ -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)

View File

@ -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

View File

@ -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