html_output_format

This commit is contained in:
Thomas Breloff 2016-05-26 20:57:51 -04:00
parent 77ec4adcad
commit f91c4d586c
2 changed files with 38 additions and 19 deletions

View File

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

View File

@ -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, "<img src=\"data:image/png;base64,", base64encode(writemime, MIME("image/png"), plt), "\" />")
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, "<img src=\"data:image/png;base64,", base64(writemime, MIME("image/png"), plt), "\" />")
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, "<img src=\"data:image/png;base64,", base64(writemime, MIME("image/png"), plt), "\" />")
# 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