working on layout

This commit is contained in:
Thomas Breloff 2016-05-16 17:12:45 -04:00
parent 35ff449dc3
commit 61107b8577
5 changed files with 25 additions and 15 deletions

View File

@ -199,7 +199,7 @@ _plotDefaults[:size] = (600,400)
_plotDefaults[:pos] = (0,0)
_plotDefaults[:windowtitle] = "Plots.jl"
_plotDefaults[:show] = false
_plotDefaults[:layout] = nothing
_plotDefaults[:layout] = :auto
_plotDefaults[:n] = -1
_plotDefaults[:nr] = -1
_plotDefaults[:nc] = -1

View File

@ -35,6 +35,7 @@ supportedArgs(::PyPlotBackend) = [
:polar,
:normalize, :weights, :contours, :aspect_ratio,
:match_dimensions,
:subplot,
]
supportedAxes(::PyPlotBackend) = _allAxes
supportedTypes(::PyPlotBackend) = [
@ -333,7 +334,8 @@ end
# each backend should set up the subplot here
function _initialize_subplot(plt::Plot{PyPlotBackend}, sp::Subplot{PyPlotBackend})
fig = plt.o
ax = fig[:add_axes]([0,0,1,1])
# add a new axis, and force it to create a new one by setting a distinct label
ax = fig[:add_axes]([0,0,1,1], label = string(gensym()))
for axis in (:xaxis, :yaxis)
ax[axis][:_autolabelpos] = false
end

View File

@ -60,7 +60,9 @@ function plot(args...; kw...)
plt.layout, plt.subplots, plt.spmap = build_layout(pop!(d, :layout, :auto))
for sp in plt.subplots
@show sp.o
_initialize_subplot(plt, sp)
@show sp.o
end
# now update the plot
@ -275,12 +277,12 @@ function _plot!(plt::Plot, d::KW, args...)
# merge plot args... this is where we combine all the plot args from the user and
# from the recipes... axis info, colors, etc
# TODO: why do i need to check for the subplot key?
if !haskey(d, :subplot)
# if !haskey(d, :subplot)
for kw in vcat(kw_list, d)
_add_plotargs!(plt, kw)
end
handlePlotColors(plt.backend, plt.plotargs)
end
# end
# for kw in kw_list
# @show typeof((kw[:x], kw[:y], kw[:z]))
@ -334,10 +336,10 @@ function _plot!(plt::Plot, d::KW, args...)
# add title, axis labels, ticks, etc
# TODO: do we really need this subplot check?
if !haskey(d, :subplot)
# if !haskey(d, :subplot)
# merge!(plt.plotargs, d) # this shouldn't be needed since we merged the keys earlier
_update_plot(plt, plt.plotargs)
end
# end
current(plt)

View File

@ -14,9 +14,9 @@ function _add_defaults!(d::KW, plt::Plot, commandIndex::Int)
setDictValue(d, d, k, commandIndex, _seriesDefaults)
end
if d[:subplot_index] == :auto
if d[:subplot] == :auto
# TODO: something useful
d[:subplot_index] = 1
d[:subplot] = 1
end
aliasesAndAutopick(d, :axis, _axesAliases, supportedAxes(pkg), plotIndex)
@ -66,7 +66,7 @@ function _add_defaults!(d::KW, plt::Plot, commandIndex::Int)
label = string(label, " (R)")
end
d[:label] = label
d
end

View File

@ -149,16 +149,22 @@ function update_bboxes!(layout::GridLayout) #, parent_bbox::BoundingBox = Boundi
# TODO: this should really track used/free space for each row/column so that we can align plot areas properly
l, b = 0.0, 0.0
# l, b = 0.0, 0.0
rights = zeros(nc)
tops = zeros(nr)
for r=1:nr, c=1:nc
# compute the child's bounding box relative to the parent
child = layout[r,c]
usedw, usedh = used_size(child)
child_bbox = BoundingBox(
l, b,
l + usedw + freew * layout.widths[c],
b + usedh + freeh * layout.heights[r]
)
left = (c == 1 ? 0 : rights[c-1])
bottom = (r == 1 ? 0 : tops[r-1])
right = left + usedw + freew * layout.widths[c]
top = bottom + usedh + freeh * layout.heights[r]
child_bbox = BoundingBox(left, bottom, right, top)
rights[c] = right
tops[r] = top
# then compute the bounding box relative to the canvas, and cache it in the child object
bbox!(child, crop(bbox(layout), child_bbox))