working on layout
This commit is contained in:
parent
ae1f5b8b06
commit
35ff449dc3
@ -156,7 +156,7 @@ _seriesDefaults[:weights] = nothing # optional weights for histograms
|
|||||||
_seriesDefaults[:contours] = false # add contours to 3d surface and wireframe plots
|
_seriesDefaults[:contours] = false # add contours to 3d surface and wireframe plots
|
||||||
_seriesDefaults[:match_dimensions] = false # do rows match x (true) or y (false) for heatmap/image/spy? see issue 196
|
_seriesDefaults[:match_dimensions] = false # do rows match x (true) or y (false) for heatmap/image/spy? see issue 196
|
||||||
# this ONLY effects whether or not the z-matrix is transposed for a heatmap display!
|
# this ONLY effects whether or not the z-matrix is transposed for a heatmap display!
|
||||||
_seriesDefaults[:subplot_index] = :auto
|
_seriesDefaults[:subplot] = :auto
|
||||||
|
|
||||||
|
|
||||||
const _plotDefaults = KW()
|
const _plotDefaults = KW()
|
||||||
@ -721,7 +721,7 @@ end
|
|||||||
function warnOnUnsupportedArgs(pkg::AbstractBackend, d::KW)
|
function warnOnUnsupportedArgs(pkg::AbstractBackend, d::KW)
|
||||||
for k in sortedkeys(d)
|
for k in sortedkeys(d)
|
||||||
if (!(k in supportedArgs(pkg))
|
if (!(k in supportedArgs(pkg))
|
||||||
&& k != :subplot
|
# && k != :subplot
|
||||||
&& d[k] != default(k))
|
&& d[k] != default(k))
|
||||||
warn("Keyword argument $k not supported with $pkg. Choose from: $(supportedArgs(pkg))")
|
warn("Keyword argument $k not supported with $pkg. Choose from: $(supportedArgs(pkg))")
|
||||||
end
|
end
|
||||||
|
|||||||
@ -234,13 +234,13 @@ renderer(fig) = canvas(fig)[:get_renderer]()
|
|||||||
drawfig(fig) = fig[:draw](renderer(fig))
|
drawfig(fig) = fig[:draw](renderer(fig))
|
||||||
drawax(ax) = ax[:draw](renderer(ax[:get_figure]()))
|
drawax(ax) = ax[:draw](renderer(ax[:get_figure]()))
|
||||||
|
|
||||||
bbox(obj) = obj[:get_window_extent](renderer(obj[:get_figure]()))
|
# bbox(obj) = obj[:get_window_extent](renderer(obj[:get_figure]()))
|
||||||
pos(obj) = obj[:get_position]()
|
# pos(obj) = obj[:get_position]()
|
||||||
|
|
||||||
# merge a list of bounding boxes together to become the area that surrounds them all
|
# # merge a list of bounding boxes together to become the area that surrounds them all
|
||||||
bbox_union(bboxes) = pytransforms.Bbox[:union](bboxes)
|
# bbox_union(bboxes) = pytransforms.Bbox[:union](bboxes)
|
||||||
|
|
||||||
function bbox_pct(obj)
|
function py_bbox_pct(obj)
|
||||||
pybbox_pixels = obj[:get_window_extent]()
|
pybbox_pixels = obj[:get_window_extent]()
|
||||||
fig = obj[:get_figure]()
|
fig = obj[:get_figure]()
|
||||||
pybbox_pct = pybbox_pixels[:inverse_transformed](fig[:transFigure])
|
pybbox_pct = pybbox_pixels[:inverse_transformed](fig[:transFigure])
|
||||||
@ -250,7 +250,7 @@ end
|
|||||||
|
|
||||||
# bbox_from_pyplot(obj) =
|
# bbox_from_pyplot(obj) =
|
||||||
|
|
||||||
function bbox_ticks(ax, letter)
|
function py_bbox_ticks(ax, letter)
|
||||||
# fig = ax[:get_figure]()
|
# fig = ax[:get_figure]()
|
||||||
# @show fig
|
# @show fig
|
||||||
labels = ax[symbol("get_"*letter*"ticklabels")]()
|
labels = ax[symbol("get_"*letter*"ticklabels")]()
|
||||||
@ -259,42 +259,63 @@ function bbox_ticks(ax, letter)
|
|||||||
bbox_union = BoundingBox()
|
bbox_union = BoundingBox()
|
||||||
for lab in labels
|
for lab in labels
|
||||||
# @show lab,lab[:get_text]()
|
# @show lab,lab[:get_text]()
|
||||||
bbox = bbox_pct(lab)
|
bbox = py_bbox_pct(lab)
|
||||||
bbox_union = bbox_union + bbox
|
bbox_union = bbox_union + bbox
|
||||||
# @show bbox_union
|
# @show bbox_union
|
||||||
end
|
end
|
||||||
bbox_union
|
bbox_union
|
||||||
end
|
end
|
||||||
|
|
||||||
function bbox_axislabel(ax, letter)
|
function py_bbox_axislabel(ax, letter)
|
||||||
pyaxis_label = ax[symbol("get_"*letter*"axis")]()
|
pyaxis_label = ax[symbol("get_"*letter*"axis")]()[:label]
|
||||||
bbox_pct(pyaxis_label)
|
py_bbox_pct(pyaxis_label)
|
||||||
end
|
end
|
||||||
|
|
||||||
# get a bounding box for the whole axis
|
# get a bounding box for the whole axis
|
||||||
function bbox_axis(ax, letter)
|
function py_bbox_axis(ax, letter)
|
||||||
bbox_ticks(ax, letter) + bbox_axislabel(ax, letter)
|
py_bbox_ticks(ax, letter) + py_bbox_axislabel(ax, letter)
|
||||||
end
|
end
|
||||||
|
|
||||||
# get a bounding box for the title area
|
# get a bounding box for the title area
|
||||||
function bbox_title(ax)
|
function py_bbox_title(ax)
|
||||||
bbox_pct(ax[:title])
|
py_bbox_pct(ax[:title])
|
||||||
end
|
end
|
||||||
|
|
||||||
xaxis_height(sp::Subplot{PyPlotBackend}) = height(bbox_axis(sp.o,"x"))
|
xaxis_height(sp::Subplot{PyPlotBackend}) = height(py_bbox_axis(sp.o,"x"))
|
||||||
yaxis_width(sp::Subplot{PyPlotBackend}) = width(bbox_axis(sp.o,"y"))
|
yaxis_width(sp::Subplot{PyPlotBackend}) = width(py_bbox_axis(sp.o,"y"))
|
||||||
title_height(sp::Subplot{PyPlotBackend}) = height(bbox_title(sp.o))
|
title_height(sp::Subplot{PyPlotBackend}) = height(py_bbox_title(sp.o))
|
||||||
|
|
||||||
|
# note: this overrides the default version to allow for labels that stick out the sides
|
||||||
|
# bounding box (relative to canvas) for plot area
|
||||||
|
# note: we assume the x axis is on the left, and y axis is on the bottom
|
||||||
|
# TODO: really the padding below should be part of the freespace calc, and we should probably
|
||||||
|
# cache the plotarea bbox while we're doing that (need to add plotarea field to Subplot)
|
||||||
|
function plotarea_bbox(sp::Subplot{PyPlotBackend})
|
||||||
|
ax = sp.o
|
||||||
|
plot_bb = py_bbox_pct(ax)
|
||||||
|
xbb = py_bbox_axis(ax, "x")
|
||||||
|
ybb = py_bbox_axis(ax, "y")
|
||||||
|
titbb = py_bbox_title(ax)
|
||||||
|
items = [xbb, ybb, titbb]
|
||||||
|
# TODO: add in margin/padding from sp.attr
|
||||||
|
leftpad = max(0, left(plot_bb) - minimum(map(left, items)))
|
||||||
|
bottompad = max(0, bottom(plot_bb) - minimum(map(bottom, items)))
|
||||||
|
rightpad = max(0, maximum(map(right, items)) - right(plot_bb))
|
||||||
|
toppad = max(0, maximum(map(top, items)) - top(plot_bb))
|
||||||
|
# crop(bbox(sp), BoundingBox(yaxis_width(sp), xaxis_height(sp), 1, 1 - title_height(sp)))
|
||||||
|
crop(bbox(sp), BoundingBox(leftpad, bottompad, 1 - rightpad, 1 - toppad))
|
||||||
|
end
|
||||||
|
|
||||||
# ---------------------------------------------------------------------------
|
# ---------------------------------------------------------------------------
|
||||||
|
|
||||||
# function used_width(sp::Subplot{PyPlotBackend})
|
# function used_width(sp::Subplot{PyPlotBackend})
|
||||||
# ax = sp.o
|
# ax = sp.o
|
||||||
# width(bbox_axis(ax,"y"))
|
# width(py_bbox_axis(ax,"y"))
|
||||||
# end
|
# end
|
||||||
#
|
#
|
||||||
# function used_height(sp::Subplot{PyPlotBackend})
|
# function used_height(sp::Subplot{PyPlotBackend})
|
||||||
# ax = sp.o
|
# ax = sp.o
|
||||||
# height(bbox_axis(ax,"x")) + height(bbox_title(ax))
|
# height(py_bbox_axis(ax,"x")) + height(py_bbox_title(ax))
|
||||||
# end
|
# end
|
||||||
|
|
||||||
|
|
||||||
@ -309,28 +330,29 @@ function update_position!(sp::Subplot{PyPlotBackend})
|
|||||||
ax[:set_position]([f(bb) for f in (left, bottom, width, height)])
|
ax[:set_position]([f(bb) for f in (left, bottom, width, height)])
|
||||||
end
|
end
|
||||||
|
|
||||||
# ---------------------------------------------------------------------------
|
# each backend should set up the subplot here
|
||||||
|
function _initialize_subplot(plt::Plot{PyPlotBackend}, sp::Subplot{PyPlotBackend})
|
||||||
function getAxis(plt::Plot{PyPlotBackend}, subplot::Subplot = plt.subplots[1])
|
|
||||||
if subplot.o == nothing
|
|
||||||
@show subplot
|
|
||||||
fig = plt.o
|
fig = plt.o
|
||||||
@show fig
|
|
||||||
# if fig == nothing
|
|
||||||
# fig =
|
|
||||||
# TODO: actual coords?
|
|
||||||
# NOTE: might want to use ax[:get_tightbbox](ax[:get_renderer_cache]()) to calc size of guides?
|
|
||||||
# NOTE: can set subplot location later with ax[:set_position]([left, bottom, width, height])
|
|
||||||
# left, bottom, width, height = 0.3, 0.3, 0.5, 0.5
|
|
||||||
|
|
||||||
# init to the full canvas, then we can set_position later
|
|
||||||
ax = fig[:add_axes]([0,0,1,1])
|
ax = fig[:add_axes]([0,0,1,1])
|
||||||
subplot.o = ax
|
for axis in (:xaxis, :yaxis)
|
||||||
|
ax[axis][:_autolabelpos] = false
|
||||||
end
|
end
|
||||||
subplot.o
|
sp.o = ax
|
||||||
end
|
end
|
||||||
|
|
||||||
getLeftAxis(plt::Plot{PyPlotBackend}, subplot::Subplot = plt.subplots[1]) = getAxis(plt, subplot)
|
# ---------------------------------------------------------------------------
|
||||||
|
|
||||||
|
# these can probably be removed eventually... right now they're just keeping things working before cleanup
|
||||||
|
# getAxis(plt::Plot{PyPlotBackend}, subplot::Subplot = plt.subplots[1]) = subplot.o
|
||||||
|
|
||||||
|
getAxis(sp::Subplot) = sp.o
|
||||||
|
|
||||||
|
function getAxis(plt::Plot{PyPlotBackend}, series::Series)
|
||||||
|
sp = get_subplot(plt, get(series.d, :subplot, 1))
|
||||||
|
getAxis(sp)
|
||||||
|
end
|
||||||
|
|
||||||
|
# getLeftAxis(plt::Plot{PyPlotBackend}, subplot::Subplot = plt.subplots[1]) = getAxis(plt, subplot)
|
||||||
getfig(o) = o
|
getfig(o) = o
|
||||||
|
|
||||||
# ---------------------------------------------------------------------------
|
# ---------------------------------------------------------------------------
|
||||||
@ -501,7 +523,7 @@ function _add_series(plt::Plot{PyPlotBackend}, series::Series)
|
|||||||
fix_xy_lengths!(plt, d)
|
fix_xy_lengths!(plt, d)
|
||||||
|
|
||||||
# ax = getAxis(plt, d[:axis])
|
# ax = getAxis(plt, d[:axis])
|
||||||
ax = getAxis(plt, get(d, :subplot, plt.subplots[1]))
|
ax = getAxis(plt, series)
|
||||||
x, y, z = d[:x], d[:y], d[:z]
|
x, y, z = d[:x], d[:y], d[:z]
|
||||||
@show typeof((x,y,z))
|
@show typeof((x,y,z))
|
||||||
xyargs = (st in _3dTypes ? (x,y,z) : (x,y))
|
xyargs = (st in _3dTypes ? (x,y,z) : (x,y))
|
||||||
@ -889,42 +911,43 @@ end
|
|||||||
# -----------------------------------------------------------------
|
# -----------------------------------------------------------------
|
||||||
|
|
||||||
|
|
||||||
# given a dimension (:x, :y, or :z), loop over the seriesargs KWs to find the min/max of the underlying data
|
# # given a dimension (:x, :y, or :z), loop over the seriesargs KWs to find the min/max of the underlying data
|
||||||
function minmaxseries(series_list, dimension, axis)
|
# function minmaxseries(series_list, dimension, axis)
|
||||||
lo, hi = Inf, -Inf
|
# lo, hi = Inf, -Inf
|
||||||
for series in series_list
|
# for series in series_list
|
||||||
series.d[:axis] == axis || continue
|
# series.d[:axis] == axis || continue
|
||||||
v = series.d[dimension]
|
# v = series.d[dimension]
|
||||||
if length(v) > 0
|
# if length(v) > 0
|
||||||
vlo, vhi = extrema(v)
|
# vlo, vhi = extrema(v)
|
||||||
lo = min(lo, vlo)
|
# lo = min(lo, vlo)
|
||||||
hi = max(hi, vhi)
|
# hi = max(hi, vhi)
|
||||||
end
|
# end
|
||||||
end
|
# end
|
||||||
if lo == hi
|
# if lo == hi
|
||||||
hi = if lo == 0
|
# hi = if lo == 0
|
||||||
1e-6
|
# 1e-6
|
||||||
else
|
# else
|
||||||
hi + min(abs(1e-2hi), 1e-6)
|
# hi + min(abs(1e-2hi), 1e-6)
|
||||||
end
|
# end
|
||||||
end
|
# end
|
||||||
lo, hi
|
# lo, hi
|
||||||
end
|
# end
|
||||||
|
#
|
||||||
# TODO: this needs to handle one-sided fixed limits
|
# # TODO: this needs to handle one-sided fixed limits
|
||||||
function set_lims!(plt::Plot{PyPlotBackend}, axis::Symbol)
|
# # TODO: this should be handled within the Axis type
|
||||||
ax = getAxis(plt, axis)
|
# function set_lims!(plt::Plot{PyPlotBackend}, axis::Symbol)
|
||||||
pargs = plt.plotargs
|
# ax = getAxis(plt, axis)
|
||||||
if pargs[:xlims] == :auto
|
# pargs = plt.plotargs
|
||||||
ax[pargs[:polar] ? :set_tlim : :set_xlim](minmaxseries(plt.series_list, :x, axis)...)
|
# if pargs[:xlims] == :auto
|
||||||
end
|
# ax[pargs[:polar] ? :set_tlim : :set_xlim](minmaxseries(plt.series_list, :x, axis)...)
|
||||||
if pargs[:ylims] == :auto
|
# end
|
||||||
ax[pargs[:polar] ? :set_rlim : :set_ylim](minmaxseries(plt.series_list, :y, axis)...)
|
# if pargs[:ylims] == :auto
|
||||||
end
|
# ax[pargs[:polar] ? :set_rlim : :set_ylim](minmaxseries(plt.series_list, :y, axis)...)
|
||||||
if pargs[:zlims] == :auto && haskey(ax, :set_zlim)
|
# end
|
||||||
ax[:set_zlim](minmaxseries(plt.series_list, :z, axis)...)
|
# if pargs[:zlims] == :auto && haskey(ax, :set_zlim)
|
||||||
end
|
# ax[:set_zlim](minmaxseries(plt.series_list, :z, axis)...)
|
||||||
end
|
# end
|
||||||
|
# end
|
||||||
|
|
||||||
# --------------------------------------------------------------------------
|
# --------------------------------------------------------------------------
|
||||||
|
|
||||||
@ -941,7 +964,7 @@ function setxy!{X,Y}(plt::Plot{PyPlotBackend}, xy::Tuple{X,Y}, i::Integer)
|
|||||||
handle[:set_offsets](hcat(xy...))
|
handle[:set_offsets](hcat(xy...))
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
set_lims!(plt, d[:axis])
|
# set_lims!(plt, plt.series_list[i])
|
||||||
plt
|
plt
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -953,7 +976,7 @@ function setxyz!{X,Y,Z}(plt::Plot{PyPlotBackend}, xyz::Tuple{X,Y,Z}, i::Integer)
|
|||||||
handle[:set_data](d[:x], d[:y])
|
handle[:set_data](d[:x], d[:y])
|
||||||
handle[:set_3d_properties](d[:z])
|
handle[:set_3d_properties](d[:z])
|
||||||
end
|
end
|
||||||
set_lims!(plt, d[:axis])
|
# set_lims!(plt, plt.series_list[i])
|
||||||
plt
|
plt
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -1032,9 +1055,10 @@ end
|
|||||||
|
|
||||||
function _update_plot(plt::Plot{PyPlotBackend}, d::KW)
|
function _update_plot(plt::Plot{PyPlotBackend}, d::KW)
|
||||||
# @show d
|
# @show d
|
||||||
figorax = plt.o
|
# figorax = plt.o
|
||||||
# ax = getLeftAxis(figorax)
|
# ax = getLeftAxis(figorax)
|
||||||
ax = getAxis(plt, plt.subplots[1])
|
for sp in plt.subplots
|
||||||
|
ax = getAxis(sp)
|
||||||
# ticksz = get(d, :tickfont, plt.plotargs[:tickfont]).pointsize
|
# ticksz = get(d, :tickfont, plt.plotargs[:tickfont]).pointsize
|
||||||
guidesz = get(d, :guidefont, plt.plotargs[:guidefont]).pointsize
|
guidesz = get(d, :guidefont, plt.plotargs[:guidefont]).pointsize
|
||||||
|
|
||||||
@ -1042,7 +1066,7 @@ function _update_plot(plt::Plot{PyPlotBackend}, d::KW)
|
|||||||
haskey(d, :title) && ax[:set_title](d[:title])
|
haskey(d, :title) && ax[:set_title](d[:title])
|
||||||
ax[:title][:set_fontsize](guidesz)
|
ax[:title][:set_fontsize](guidesz)
|
||||||
|
|
||||||
axes = [ax]
|
# axes = [ax]
|
||||||
# # handle right y axis
|
# # handle right y axis
|
||||||
# axes = [getLeftAxis(figorax)]
|
# axes = [getLeftAxis(figorax)]
|
||||||
# if usingRightAxis(plt)
|
# if usingRightAxis(plt)
|
||||||
@ -1065,7 +1089,8 @@ function _update_plot(plt::Plot{PyPlotBackend}, d::KW)
|
|||||||
if get(axis.d, :flip, false)
|
if get(axis.d, :flip, false)
|
||||||
ax[symbol("invert_", letter, "axis")]()
|
ax[symbol("invert_", letter, "axis")]()
|
||||||
end
|
end
|
||||||
for tmpax in axes
|
# for tmpax in axes
|
||||||
|
tmpax = ax
|
||||||
tmpax[axissym][:label][:set_fontsize](axis[:guidefont].pointsize)
|
tmpax[axissym][:label][:set_fontsize](axis[:guidefont].pointsize)
|
||||||
for lab in tmpax[symbol("get_", letter, "ticklabels")]()
|
for lab in tmpax[symbol("get_", letter, "ticklabels")]()
|
||||||
lab[:set_fontsize](axis[:tickfont].pointsize)
|
lab[:set_fontsize](axis[:tickfont].pointsize)
|
||||||
@ -1076,7 +1101,7 @@ function _update_plot(plt::Plot{PyPlotBackend}, d::KW)
|
|||||||
tmpax[axissym][:grid](true, color = fgcolor)
|
tmpax[axissym][:grid](true, color = fgcolor)
|
||||||
tmpax[:set_axisbelow](true)
|
tmpax[:set_axisbelow](true)
|
||||||
end
|
end
|
||||||
end
|
# end
|
||||||
# @show ""
|
# @show ""
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -1112,35 +1137,38 @@ function _update_plot(plt::Plot{PyPlotBackend}, d::KW)
|
|||||||
if aratio != :none
|
if aratio != :none
|
||||||
ax[:set_aspect](isa(aratio, Symbol) ? string(aratio) : aratio, anchor = "C")
|
ax[:set_aspect](isa(aratio, Symbol) ? string(aratio) : aratio, anchor = "C")
|
||||||
end
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
# -----------------------------------------------------------------
|
# -----------------------------------------------------------------
|
||||||
|
|
||||||
function createPyPlotAnnotationObject(plt::Plot{PyPlotBackend}, x, y, val::@compat(AbstractString))
|
# TODO: these should apply to a Subplot, NOT a Plot
|
||||||
ax = getLeftAxis(plt)
|
|
||||||
ax[:annotate](val, xy = (x,y))
|
|
||||||
end
|
|
||||||
|
|
||||||
|
# function createPyPlotAnnotationObject(plt::Plot{PyPlotBackend}, x, y, val::@compat(AbstractString))
|
||||||
function createPyPlotAnnotationObject(plt::Plot{PyPlotBackend}, x, y, val::PlotText)
|
# ax = getLeftAxis(plt)
|
||||||
ax = getLeftAxis(plt)
|
# ax[:annotate](val, xy = (x,y))
|
||||||
ax[:annotate](val.str,
|
# end
|
||||||
xy = (x,y),
|
#
|
||||||
family = val.font.family,
|
#
|
||||||
color = getPyPlotColor(val.font.color),
|
# function createPyPlotAnnotationObject(plt::Plot{PyPlotBackend}, x, y, val::PlotText)
|
||||||
horizontalalignment = val.font.halign == :hcenter ? "center" : string(val.font.halign),
|
# ax = getLeftAxis(plt)
|
||||||
verticalalignment = val.font.valign == :vcenter ? "center" : string(val.font.valign),
|
# ax[:annotate](val.str,
|
||||||
rotation = val.font.rotation * 180 / π,
|
# xy = (x,y),
|
||||||
size = val.font.pointsize
|
# family = val.font.family,
|
||||||
)
|
# color = getPyPlotColor(val.font.color),
|
||||||
end
|
# horizontalalignment = val.font.halign == :hcenter ? "center" : string(val.font.halign),
|
||||||
|
# verticalalignment = val.font.valign == :vcenter ? "center" : string(val.font.valign),
|
||||||
function _add_annotations{X,Y,V}(plt::Plot{PyPlotBackend}, anns::AVec{@compat(Tuple{X,Y,V})})
|
# rotation = val.font.rotation * 180 / π,
|
||||||
for ann in anns
|
# size = val.font.pointsize
|
||||||
createPyPlotAnnotationObject(plt, ann...)
|
# )
|
||||||
end
|
# end
|
||||||
end
|
#
|
||||||
|
# function _add_annotations{X,Y,V}(plt::Plot{PyPlotBackend}, anns::AVec{@compat(Tuple{X,Y,V})})
|
||||||
|
# for ann in anns
|
||||||
|
# createPyPlotAnnotationObject(plt, ann...)
|
||||||
|
# end
|
||||||
|
# end
|
||||||
|
|
||||||
# -----------------------------------------------------------------
|
# -----------------------------------------------------------------
|
||||||
|
|
||||||
@ -1271,9 +1299,12 @@ end
|
|||||||
# -----------------------------------------------------------------
|
# -----------------------------------------------------------------
|
||||||
|
|
||||||
function finalizePlot(plt::Plot{PyPlotBackend})
|
function finalizePlot(plt::Plot{PyPlotBackend})
|
||||||
ax = getLeftAxis(plt)
|
for sp in plt.subplots
|
||||||
|
# ax = getLeftAxis(plt)
|
||||||
|
ax = getAxis(sp)
|
||||||
addPyPlotLegend(plt, ax)
|
addPyPlotLegend(plt, ax)
|
||||||
updateAxisColors(ax, plt.plotargs)
|
updateAxisColors(ax, plt.plotargs)
|
||||||
|
end
|
||||||
drawfig(plt.o)
|
drawfig(plt.o)
|
||||||
update_bboxes!(plt.layout)
|
update_bboxes!(plt.layout)
|
||||||
update_position!(plt.layout)
|
update_position!(plt.layout)
|
||||||
|
|||||||
@ -47,7 +47,6 @@ function plot(args...; kw...)
|
|||||||
d = KW(kw)
|
d = KW(kw)
|
||||||
preprocessArgs!(d)
|
preprocessArgs!(d)
|
||||||
|
|
||||||
layout, subplots, spmap = build_layout(pop!(d, :layout, :auto))
|
|
||||||
# subplots = Subplot[layout] # TODO: build full list
|
# subplots = Subplot[layout] # TODO: build full list
|
||||||
# smap = SubplotMap(1 => layout) # TODO: actually build a map
|
# smap = SubplotMap(1 => layout) # TODO: actually build a map
|
||||||
|
|
||||||
@ -55,9 +54,15 @@ function plot(args...; kw...)
|
|||||||
plotargs = merge(d, getPlotArgs(pkg, d, 1))
|
plotargs = merge(d, getPlotArgs(pkg, d, 1))
|
||||||
# plt = _create_plot(pkg, plotargs) # create a new, blank plot
|
# plt = _create_plot(pkg, plotargs) # create a new, blank plot
|
||||||
|
|
||||||
plt = Plot(nothing, pkg, 0, plotargs, Series[], subplots, spmap, layout)
|
# plt = Plot(nothing, pkg, 0, plotargs, Series[]) #, subplots, spmap, layout)
|
||||||
|
plt = Plot(plotargs)
|
||||||
plt.o = _create_backend_figure(plt)
|
plt.o = _create_backend_figure(plt)
|
||||||
|
|
||||||
|
plt.layout, plt.subplots, plt.spmap = build_layout(pop!(d, :layout, :auto))
|
||||||
|
for sp in plt.subplots
|
||||||
|
_initialize_subplot(plt, sp)
|
||||||
|
end
|
||||||
|
|
||||||
# now update the plot
|
# now update the plot
|
||||||
_plot!(plt, d, args...)
|
_plot!(plt, d, args...)
|
||||||
end
|
end
|
||||||
|
|||||||
@ -58,6 +58,9 @@ used_size(layout::AbstractLayout) = (used_width(layout), used_height(layout))
|
|||||||
#
|
#
|
||||||
# end
|
# end
|
||||||
|
|
||||||
|
update_position!(layout::AbstractLayout) = nothing
|
||||||
|
update_bboxes!(layout::AbstractLayout) = nothing
|
||||||
|
|
||||||
# ----------------------------------------------------------------------
|
# ----------------------------------------------------------------------
|
||||||
|
|
||||||
Base.size(layout::EmptyLayout) = (0,0)
|
Base.size(layout::EmptyLayout) = (0,0)
|
||||||
@ -67,7 +70,6 @@ Base.getindex(layout::EmptyLayout, r::Int, c::Int) = nothing
|
|||||||
used_width(layout::EmptyLayout) = 0.0
|
used_width(layout::EmptyLayout) = 0.0
|
||||||
used_height(layout::EmptyLayout) = 0.0
|
used_height(layout::EmptyLayout) = 0.0
|
||||||
|
|
||||||
update_position!(layout::EmptyLayout) = nothing
|
|
||||||
|
|
||||||
# ----------------------------------------------------------------------
|
# ----------------------------------------------------------------------
|
||||||
|
|
||||||
@ -118,7 +120,7 @@ function used_width(layout::GridLayout)
|
|||||||
w = 0.0
|
w = 0.0
|
||||||
nr,nc = size(layout)
|
nr,nc = size(layout)
|
||||||
for c=1:nc
|
for c=1:nc
|
||||||
w += maximum([used_width(layout(r,c)) for r=1:nr])
|
w += maximum([used_width(layout[r,c]) for r=1:nr])
|
||||||
end
|
end
|
||||||
w
|
w
|
||||||
end
|
end
|
||||||
@ -127,7 +129,7 @@ function used_height(layout::GridLayout)
|
|||||||
h = 0.0
|
h = 0.0
|
||||||
nr,nc = size(layout)
|
nr,nc = size(layout)
|
||||||
for r=1:nr
|
for r=1:nr
|
||||||
h += maximum([used_height(layout(r,c)) for c=1:nc])
|
h += maximum([used_height(layout[r,c]) for c=1:nc])
|
||||||
end
|
end
|
||||||
h
|
h
|
||||||
end
|
end
|
||||||
@ -142,8 +144,8 @@ function update_bboxes!(layout::GridLayout) #, parent_bbox::BoundingBox = Boundi
|
|||||||
# initialize the free space (per child!)
|
# initialize the free space (per child!)
|
||||||
nr, nc = size(layout)
|
nr, nc = size(layout)
|
||||||
freew, freeh = free_size(layout)
|
freew, freeh = free_size(layout)
|
||||||
freew /= nc
|
freew /= sum(layout.widths)
|
||||||
freeh /= nr
|
freeh /= sum(layout.heights)
|
||||||
|
|
||||||
# TODO: this should really track used/free space for each row/column so that we can align plot areas properly
|
# TODO: this should really track used/free space for each row/column so that we can align plot areas properly
|
||||||
|
|
||||||
@ -152,7 +154,11 @@ function update_bboxes!(layout::GridLayout) #, parent_bbox::BoundingBox = Boundi
|
|||||||
# compute the child's bounding box relative to the parent
|
# compute the child's bounding box relative to the parent
|
||||||
child = layout[r,c]
|
child = layout[r,c]
|
||||||
usedw, usedh = used_size(child)
|
usedw, usedh = used_size(child)
|
||||||
child_bbox = BoundingBox(l, b, l + usedw + freew, b + usedh + freeh)
|
child_bbox = BoundingBox(
|
||||||
|
l, b,
|
||||||
|
l + usedw + freew * layout.widths[c],
|
||||||
|
b + usedh + freeh * layout.heights[r]
|
||||||
|
)
|
||||||
|
|
||||||
# then compute the bounding box relative to the canvas, and cache it in the child object
|
# then compute the bounding box relative to the canvas, and cache it in the child object
|
||||||
bbox!(child, crop(bbox(layout), child_bbox))
|
bbox!(child, crop(bbox(layout), child_bbox))
|
||||||
@ -167,7 +173,7 @@ end
|
|||||||
# return the top-level layout, a list of subplots, and a SubplotMap
|
# return the top-level layout, a list of subplots, and a SubplotMap
|
||||||
function build_layout(s::Symbol)
|
function build_layout(s::Symbol)
|
||||||
s == :auto || error() # TODO: handle anything else
|
s == :auto || error() # TODO: handle anything else
|
||||||
layout = GridLayout(1, 2)
|
layout = GridLayout(1, 2) #TODO this need to go
|
||||||
nr, nc = size(layout)
|
nr, nc = size(layout)
|
||||||
subplots = Subplot[]
|
subplots = Subplot[]
|
||||||
spmap = SubplotMap()
|
spmap = SubplotMap()
|
||||||
@ -181,6 +187,11 @@ function build_layout(s::Symbol)
|
|||||||
end
|
end
|
||||||
|
|
||||||
# ----------------------------------------------------------------------
|
# ----------------------------------------------------------------------
|
||||||
|
|
||||||
|
get_subplot(plt::Plot, sp::Subplot) = sp
|
||||||
|
get_subplot(plt::Plot, i::Integer) = plt.subplots[i]
|
||||||
|
get_subplot(plt::Plot, k) = plt.spmap[k]
|
||||||
|
|
||||||
# ----------------------------------------------------------------------
|
# ----------------------------------------------------------------------
|
||||||
# ----------------------------------------------------------------------
|
# ----------------------------------------------------------------------
|
||||||
|
|
||||||
|
|||||||
11
src/types.jl
11
src/types.jl
@ -56,7 +56,7 @@ type EmptyLayout <: AbstractLayout
|
|||||||
parent::AbstractLayout
|
parent::AbstractLayout
|
||||||
bbox::BoundingBox
|
bbox::BoundingBox
|
||||||
end
|
end
|
||||||
EmptyLayout(parent) = EmptyLayout(parent, BoundingBox(0,0,1,1))
|
EmptyLayout(parent = RootLayout()) = EmptyLayout(parent, BoundingBox(0,0,1,1))
|
||||||
|
|
||||||
# this is the parent of the top-level layout
|
# this is the parent of the top-level layout
|
||||||
immutable RootLayout <: AbstractLayout
|
immutable RootLayout <: AbstractLayout
|
||||||
@ -123,17 +123,20 @@ type Series
|
|||||||
end
|
end
|
||||||
|
|
||||||
type Plot{T<:AbstractBackend} <: AbstractPlot{T}
|
type Plot{T<:AbstractBackend} <: AbstractPlot{T}
|
||||||
o # the backend's plot object
|
|
||||||
backend::T # the backend type
|
backend::T # the backend type
|
||||||
n::Int # number of series
|
n::Int # number of series
|
||||||
plotargs::KW # arguments for the whole plot
|
plotargs::KW # arguments for the whole plot
|
||||||
# seriesargs::Vector{KW} # arguments for each series
|
|
||||||
series_list::Vector{Series} # arguments for each series
|
series_list::Vector{Series} # arguments for each series
|
||||||
|
o # the backend's plot object
|
||||||
subplots::Vector{Subplot}
|
subplots::Vector{Subplot}
|
||||||
subplot_map::SubplotMap # provide any label as a map to a subplot
|
spmap::SubplotMap # provide any label as a map to a subplot
|
||||||
layout::AbstractLayout
|
layout::AbstractLayout
|
||||||
end
|
end
|
||||||
|
|
||||||
|
function Plot(plotargs::KW)
|
||||||
|
Plot(backend(), 0, plotargs, Series[], nothing, Subplot[], SubplotMap(), EmptyLayout())
|
||||||
|
end
|
||||||
|
|
||||||
# -----------------------------------------------------------
|
# -----------------------------------------------------------
|
||||||
# Subplot
|
# Subplot
|
||||||
# -----------------------------------------------------------
|
# -----------------------------------------------------------
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user