Skip to content
This repository has been archived by the owner on Jul 13, 2021. It is now read-only.

Commit

Permalink
Merge pull request #664 from JuliaPlots/sd/fileio-ambig
Browse files Browse the repository at this point in the history
fix fileio ambig MakieOrg/Makie.jl#894
  • Loading branch information
SimonDanisch authored Mar 19, 2021
2 parents ccf70c3 + 87e8eec commit 06ef92d
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions src/display.jl
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,7 @@ format2mime(::Type{FileIO.format"HTML"}) = MIME("text/html")
filetype(::FileIO.File{F}) where F = F
# Allow format to be overridden with first argument


"""
FileIO.save(filename, scene; resolution = size(scene), pt_per_unit = 1.0, px_per_unit = 1.0)
Expand All @@ -225,21 +226,28 @@ Save a `Scene` with the specified filename and format.
- `px_per_unit`: The size of one scene unit in `px` when exporting to a bitmap format. This provides a mechanism to export the same scene with higher or lower resolution.
"""
function FileIO.save(
filename, fig::FigureLike;
filename::String, fig::FigureLike; args...
)
FileIO.save(FileIO.query(filename), fig; args...)
end

function FileIO.save(
file::FileIO.Formatted, fig::FigureLike;
resolution = size(get_scene(fig)),
pt_per_unit = 1.0,
px_per_unit = 1.0,
)
scene = get_scene(fig)
resolution != size(scene) && resize!(scene, resolution)
filename = FileIO.filename(file)
# Delete previous file if it exists and query only the file string for type.
# We overwrite existing files anyway, so this doesn't change the behavior.
# But otherwise we could get a filetype :UNKNOWN from a corrupt existing file
# (from an error during save, e.g.), therefore we don't want to rely on the
# type readout from an existing file.
isfile(filename) && rm(filename)
# query the filetype only from the file extension
F = filetype(FileIO.query(filename))
F = filetype(file)

open(filename, "w") do s
iocontext = IOContext(s,
Expand Down

0 comments on commit 06ef92d

Please sign in to comment.