diff --git a/src/args.jl b/src/args.jl index 4c74b10a..49305e3b 100644 --- a/src/args.jl +++ b/src/args.jl @@ -186,6 +186,7 @@ const _plot_defaults = KW( :linky => false, :linkfunc => nothing, :overwrite_figure => true, + :html_output_format => :auto, ) @@ -408,6 +409,7 @@ add_aliases(:subplot, :sp, :subplt, :splt) add_aliases(:projection, :proj) add_aliases(:title_location, :title_loc, :titleloc, :title_position, :title_pos, :titlepos, :titleposition, :title_align, :title_alignment) add_aliases(:series_annotations, :series_ann, :seriesann, :series_anns, :seriesanns, :series_annotation) +add_aliases(:html_output_format, :format, :fmt, :html_format) # add all pluralized forms to the _keyAliases dict diff --git a/src/output.jl b/src/output.jl index 55443275..58a04683 100644 --- a/src/output.jl +++ b/src/output.jl @@ -122,11 +122,28 @@ const _mimeformats = Dict( "image/svg+xml" => "svg" ) -# # a backup for html... passes to svg -# function Base.writemime(io::IO, ::MIME"text/html", plt::Plot) -# writemime(io, MIME("image/svg+xml"), plt) -# end +const _best_html_output_type = KW( + :pyplot => :png, +) +# a backup for html... passes to svg or png depending on the html_output_format arg +function Base.writemime(io::IO, ::MIME"text/html", plt::Plot) + output_type = symbol(plt.attr[:html_output_format]) + if output_type == :auto + output_type = get(_best_html_output_type, backend_name(plt.backend), :svg) + end + if output_type == :png + # info("writing png to html output") + print(io, "") + elseif output_type == :svg + # info("writing svg to html output") + writemime(io, MIME("image/svg+xml"), plt) + else + error("only png or svg allowed. got: $output_type") + end +end + +# for writing to io streams... first prepare, then callback for mime in keys(_mimeformats) @eval function Base.writemime(io::IO, m::MIME{Symbol($mime)}, plt::Plot) prepare_output(plt) @@ -134,21 +151,21 @@ for mime in keys(_mimeformats) end end -function html_output_format(fmt) - if fmt == "png" - @eval function Base.writemime(io::IO, ::MIME"text/html", plt::Plot) - print(io, "") - end - elseif fmt == "svg" - @eval function Base.writemime(io::IO, ::MIME"text/html", plt::Plot) - writemime(io, MIME("image/svg+xml"), plt) - end - else - error("only png or svg allowed. got: $fmt") - end -end - -html_output_format("svg") +# function html_output_format(fmt) +# if fmt == "png" +# @eval function Base.writemime(io::IO, ::MIME"text/html", plt::Plot) +# print(io, "") +# end +# elseif fmt == "svg" +# @eval function Base.writemime(io::IO, ::MIME"text/html", plt::Plot) +# writemime(io, MIME("image/svg+xml"), plt) +# end +# else +# error("only png or svg allowed. got: $fmt") +# end +# end +# +# html_output_format("svg") # --------------------------------------------------------- # IJulia