default minpad fix; html_output_format

This commit is contained in:
Thomas Breloff 2016-05-26 17:04:28 -04:00
parent b5a8186d99
commit 77ec4adcad
2 changed files with 26 additions and 9 deletions

View File

@ -60,11 +60,12 @@ guide_padding(axis::Axis) = axis[:guide] == "" ? 0mm : axis[:guidefont].pointsiz
# Set the (left, top, right, bottom) minimum padding around the plot area
# to fit ticks, tick labels, guides, colorbars, etc.
function _update_min_padding!(sp::Subplot)
toppad = 2mm + title_padding(sp)
bottompad = 5mm + guide_padding(sp.attr[:xaxis])
leftpad = 10mm + guide_padding(sp.attr[:yaxis])
@show (leftpad, toppad, 3mm, bottompad)
sp.minpad = (leftpad, toppad, 3mm, bottompad)
leftpad = 10mm + sp.attr[:left_margin] + guide_padding(sp.attr[:yaxis])
toppad = 2mm + sp.attr[:top_margin] + title_padding(sp)
rightpad = 3mm + sp.attr[:right_margin]
bottompad = 5mm + sp.attr[:bottom_margin] + guide_padding(sp.attr[:xaxis])
@show (leftpad, toppad, rightpad, bottompad)
sp.minpad = (leftpad, toppad, rightpad, bottompad)
end
_update_plot_object(plt::Plot) = nothing

View File

@ -122,10 +122,10 @@ 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
# # 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
for mime in keys(_mimeformats)
@eval function Base.writemime(io::IO, m::MIME{Symbol($mime)}, plt::Plot)
@ -134,6 +134,22 @@ 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")
# ---------------------------------------------------------
# IJulia
# ---------------------------------------------------------