From 98d95b8db230548be8cefcb519ac1f14fcfec913 Mon Sep 17 00:00:00 2001 From: Zhanibek Date: Thu, 18 Jul 2024 16:35:14 +0900 Subject: [PATCH 1/3] fix up --- PlotsBase/src/Commons/attrs.jl | 5 +++++ PlotsBase/src/arg_desc.jl | 1 + PlotsBase/src/output.jl | 5 ++++- 3 files changed, 10 insertions(+), 1 deletion(-) diff --git a/PlotsBase/src/Commons/attrs.jl b/PlotsBase/src/Commons/attrs.jl index 48da09c12..4c6532736 100644 --- a/PlotsBase/src/Commons/attrs.jl +++ b/PlotsBase/src/Commons/attrs.jl @@ -410,6 +410,7 @@ const _plot_defaults = KW( :thickness_scaling => 1, :display_type => :auto, :warn_on_unsupported => true, + :safe_saving => true, :extra_plot_kwargs => Dict(), :extra_kwargs => :series, # directs collection of extra_kwargs ) @@ -1156,7 +1157,11 @@ label_to_string(label::Nothing, series_plotindex) = "" label_to_string(label::Missing, series_plotindex) = "" label_to_string(label::Symbol, series_plotindex) = if label ≡ :auto +<<<<<<< HEAD string("y", series_plotindex) +======= + return label_auto(series_plotindex) +>>>>>>> d6b3aaf8 (safe-saving arg) elseif label ≡ :none "" else diff --git a/PlotsBase/src/arg_desc.jl b/PlotsBase/src/arg_desc.jl index f448804cb..d83fa3d45 100644 --- a/PlotsBase/src/arg_desc.jl +++ b/PlotsBase/src/arg_desc.jl @@ -83,6 +83,7 @@ const _arg_desc = KW( Example: `pgfplotsx(); scatter(1:5, extra_kwargs=Dict(:subplot=>Dict("axis line shift" => "10pt"))`."""), :fontfamily => (Union{AStr,Symbol}, "Default font family for title, legend entries, tick labels and guides."), :warn_on_unsupported => (Bool, "Warn on unsupported attributes, series types and marker shapes."), + :safe_saving => (Bool, "Do not override existing files when saving to disk. Choose from (true, false)"), # subplot args :title => (AStr, "Subplot title."), diff --git a/PlotsBase/src/output.jl b/PlotsBase/src/output.jl index 68464aee3..df21e2610 100644 --- a/PlotsBase/src/output.jl +++ b/PlotsBase/src/output.jl @@ -138,7 +138,10 @@ file types, some also support svg, ps, eps, html and tex. """ function savefig(plt::Plot, fn) # fn might be an `AbstractString` or an `AbstractPath` from `FilePaths.jl` fn = abspath(expanduser(fn)) - + if isfile(fn) + @warn "Filename $fn already exist, defaulting to omit overriding. To disable this behavior, provide `:safe_saving=false` kwarg." + return + end # get the extension _, ext = splitext(fn) ext = chop(ext, head = 1, tail = 0) From e0f0abd6a1d258a33ae9ace88d43357ab8fbcd03 Mon Sep 17 00:00:00 2001 From: Zhanibek Date: Thu, 18 Jul 2024 16:27:14 +0900 Subject: [PATCH 2/3] fixup --- PlotsBase/src/arg_desc.jl | 2 +- PlotsBase/src/output.jl | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/PlotsBase/src/arg_desc.jl b/PlotsBase/src/arg_desc.jl index d83fa3d45..1599be5fe 100644 --- a/PlotsBase/src/arg_desc.jl +++ b/PlotsBase/src/arg_desc.jl @@ -83,7 +83,7 @@ const _arg_desc = KW( Example: `pgfplotsx(); scatter(1:5, extra_kwargs=Dict(:subplot=>Dict("axis line shift" => "10pt"))`."""), :fontfamily => (Union{AStr,Symbol}, "Default font family for title, legend entries, tick labels and guides."), :warn_on_unsupported => (Bool, "Warn on unsupported attributes, series types and marker shapes."), - :safe_saving => (Bool, "Do not override existing files when saving to disk. Choose from (true, false)"), + :safe_saving => (Bool, "Do not override existing files when saving to disk. Choose from (true, false), i.e. `plot(rand(10), safe_saving=false)` for enable file overriding"), # subplot args :title => (AStr, "Subplot title."), diff --git a/PlotsBase/src/output.jl b/PlotsBase/src/output.jl index df21e2610..90ba74c80 100644 --- a/PlotsBase/src/output.jl +++ b/PlotsBase/src/output.jl @@ -138,8 +138,8 @@ file types, some also support svg, ps, eps, html and tex. """ function savefig(plt::Plot, fn) # fn might be an `AbstractString` or an `AbstractPath` from `FilePaths.jl` fn = abspath(expanduser(fn)) - if isfile(fn) - @warn "Filename $fn already exist, defaulting to omit overriding. To disable this behavior, provide `:safe_saving=false` kwarg." + if isfile(fn) && plt[:safe_saving] + @warn "Filename $fn already exists, defaulting to prevent overriding. To disable this behavior, provide `:safe_saving=false` kwarg, i.e. `plot(rand(10), safe_saving=false)`" return end # get the extension From 88628e4c99a9804a7443a9a7d3c4c6557d00d809 Mon Sep 17 00:00:00 2001 From: Zhanibek Date: Thu, 18 Jul 2024 16:36:59 +0900 Subject: [PATCH 3/3] fix --- PlotsBase/src/Commons/attrs.jl | 4 ---- 1 file changed, 4 deletions(-) diff --git a/PlotsBase/src/Commons/attrs.jl b/PlotsBase/src/Commons/attrs.jl index 4c6532736..2d46a7b17 100644 --- a/PlotsBase/src/Commons/attrs.jl +++ b/PlotsBase/src/Commons/attrs.jl @@ -1157,11 +1157,7 @@ label_to_string(label::Nothing, series_plotindex) = "" label_to_string(label::Missing, series_plotindex) = "" label_to_string(label::Symbol, series_plotindex) = if label ≡ :auto -<<<<<<< HEAD string("y", series_plotindex) -======= - return label_auto(series_plotindex) ->>>>>>> d6b3aaf8 (safe-saving arg) elseif label ≡ :none "" else