fixes; basic layout works
This commit is contained in:
parent
33d9664df5
commit
df7fc0c4df
@ -260,7 +260,9 @@ py_bbox_fig(plt::Plot) = py_bbox_fig(plt.o)
|
|||||||
# compute a bounding box (with origin top-left), however pyplot gives coords with origin bottom-left
|
# compute a bounding box (with origin top-left), however pyplot gives coords with origin bottom-left
|
||||||
function py_bbox(obj)
|
function py_bbox(obj)
|
||||||
fl, fr, fb, ft = get_extents(obj[:get_figure]())
|
fl, fr, fb, ft = get_extents(obj[:get_figure]())
|
||||||
|
# @show fl, fr, fb, ft
|
||||||
l, r, b, t = get_extents(obj)
|
l, r, b, t = get_extents(obj)
|
||||||
|
# @show l, r, b, t, obj
|
||||||
BoundingBox(l*px, (ft-t)*px, (r-l)*px, (t-b)*px)
|
BoundingBox(l*px, (ft-t)*px, (r-l)*px, (t-b)*px)
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -276,6 +278,7 @@ function py_bbox_ticks(ax, letter)
|
|||||||
# @show lab,lab[:get_text]()
|
# @show lab,lab[:get_text]()
|
||||||
bbox = py_bbox(lab)
|
bbox = py_bbox(lab)
|
||||||
bbox_union = bbox_union + bbox
|
bbox_union = bbox_union + bbox
|
||||||
|
# @show letter,bbox bbox_union
|
||||||
# @show bbox_union
|
# @show bbox_union
|
||||||
end
|
end
|
||||||
bbox_union
|
bbox_union
|
||||||
@ -288,7 +291,10 @@ end
|
|||||||
|
|
||||||
# get a bounding box for the whole axis
|
# get a bounding box for the whole axis
|
||||||
function py_bbox_axis(ax, letter)
|
function py_bbox_axis(ax, letter)
|
||||||
py_bbox_ticks(ax, letter) + py_bbox_axislabel(ax, letter)
|
ticks = py_bbox_ticks(ax, letter)
|
||||||
|
labels = py_bbox_axislabel(ax, letter)
|
||||||
|
# @show ticks labels ticks+labels
|
||||||
|
ticks + labels
|
||||||
end
|
end
|
||||||
|
|
||||||
# get a bounding box for the title area
|
# get a bounding box for the title area
|
||||||
@ -301,9 +307,9 @@ end
|
|||||||
# and aggregation (minimum or maximum) into a method to do this.
|
# and aggregation (minimum or maximum) into a method to do this.
|
||||||
|
|
||||||
min_padding_left(layout::Subplot{PyPlotBackend}) = compute_min_padding(layout, left, 1)
|
min_padding_left(layout::Subplot{PyPlotBackend}) = compute_min_padding(layout, left, 1)
|
||||||
min_padding_top(layout::Subplot{PyPlotBackend}) = compute_min_padding(layout, top, -1)
|
min_padding_top(layout::Subplot{PyPlotBackend}) = compute_min_padding(layout, top, 1)
|
||||||
min_padding_right(layout::Subplot{PyPlotBackend}) = compute_min_padding(layout, right, -1)
|
min_padding_right(layout::Subplot{PyPlotBackend}) = compute_min_padding(layout, right, -1)
|
||||||
min_padding_bottom(layout::Subplot{PyPlotBackend}) = compute_min_padding(layout, bottom, 1)
|
min_padding_bottom(layout::Subplot{PyPlotBackend}) = compute_min_padding(layout, bottom,-1)
|
||||||
|
|
||||||
# loop over the guides and axes and compute how far they "stick out" from the plot area,
|
# loop over the guides and axes and compute how far they "stick out" from the plot area,
|
||||||
# so that we know the minimum padding we need to avoid cropping and overlapping text.
|
# so that we know the minimum padding we need to avoid cropping and overlapping text.
|
||||||
@ -311,12 +317,17 @@ min_padding_bottom(layout::Subplot{PyPlotBackend}) = compute_min_padding(layout,
|
|||||||
function compute_min_padding(sp::Subplot{PyPlotBackend}, func::Function, mult::Number)
|
function compute_min_padding(sp::Subplot{PyPlotBackend}, func::Function, mult::Number)
|
||||||
ax = sp.o
|
ax = sp.o
|
||||||
plotbb = py_bbox(ax)
|
plotbb = py_bbox(ax)
|
||||||
|
# @show func, mult plotbb
|
||||||
padding = 0mm
|
padding = 0mm
|
||||||
for bb in (py_bbox_axis(ax, "x"),
|
for bb in (py_bbox_axis(ax, "x"),
|
||||||
py_bbox_axis(ax, "y"),
|
py_bbox_axis(ax, "y"),
|
||||||
py_bbox_title(ax))
|
py_bbox_title(ax))
|
||||||
diff = func(plotbb) - func(bb)
|
diff = func(plotbb) - func(bb)
|
||||||
padding = max(padding, mult * diff)
|
# @show diff,bb
|
||||||
|
if ispositive(width(bb)) && ispositive(height(bb))
|
||||||
|
padding = max(padding, mult * diff)
|
||||||
|
end
|
||||||
|
# @show padding
|
||||||
end
|
end
|
||||||
padding
|
padding
|
||||||
end
|
end
|
||||||
@ -355,14 +366,16 @@ function update_position!(sp::Subplot{PyPlotBackend})
|
|||||||
|
|
||||||
# plot_bb = plotarea_bbox(sp)
|
# plot_bb = plotarea_bbox(sp)
|
||||||
plot_bb = sp.plotarea
|
plot_bb = sp.plotarea
|
||||||
@show sp.bbox plot_bb
|
# @show sp.bbox plot_bb
|
||||||
# l = float(left(plot_bb) / px) / figw
|
# l = float(left(plot_bb) / px) / figw
|
||||||
# b = float(bottom(plot_bb) / px) / figh
|
# b = float(bottom(plot_bb) / px) / figh
|
||||||
# w = float(width(plot_bb) / px) / figw
|
# w = float(width(plot_bb) / px) / figw
|
||||||
mms = Float64[f(plot_bb).value for f in (left, bottom, width, height)]
|
mms = Float64[f(plot_bb).value for f in (left, bottom, width, height)]
|
||||||
@show mms
|
|
||||||
|
mms[2] = figh.value - mms[2]
|
||||||
|
# @show mms
|
||||||
pcts = mms ./ Float64[figw.value, figh.value, figw.value, figh.value]
|
pcts = mms ./ Float64[figw.value, figh.value, figw.value, figh.value]
|
||||||
@show pcts
|
# @show pcts
|
||||||
ax[:set_position](pcts)
|
ax[:set_position](pcts)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@ -127,7 +127,7 @@ function update_child_bboxes!(layout::GridLayout)
|
|||||||
minpad_top = map(min_padding_top, layout.grid)
|
minpad_top = map(min_padding_top, layout.grid)
|
||||||
minpad_right = map(min_padding_right, layout.grid)
|
minpad_right = map(min_padding_right, layout.grid)
|
||||||
minpad_bottom = map(min_padding_bottom, layout.grid)
|
minpad_bottom = map(min_padding_bottom, layout.grid)
|
||||||
@show minpad_left minpad_top minpad_right minpad_bottom
|
# @show minpad_left minpad_top minpad_right minpad_bottom
|
||||||
|
|
||||||
# get the max horizontal (left and right) padding over columns,
|
# get the max horizontal (left and right) padding over columns,
|
||||||
# and max vertical (bottom and top) padding over rows
|
# and max vertical (bottom and top) padding over rows
|
||||||
@ -136,22 +136,22 @@ function update_child_bboxes!(layout::GridLayout)
|
|||||||
pad_top = maximum(minpad_top, 2)
|
pad_top = maximum(minpad_top, 2)
|
||||||
pad_right = maximum(minpad_right, 1)
|
pad_right = maximum(minpad_right, 1)
|
||||||
pad_bottom = maximum(minpad_bottom, 2)
|
pad_bottom = maximum(minpad_bottom, 2)
|
||||||
@show pad_left pad_top pad_right pad_bottom
|
# @show pad_left pad_top pad_right pad_bottom
|
||||||
|
|
||||||
# scale this up to the total padding in each direction
|
# scale this up to the total padding in each direction
|
||||||
total_pad_horizontal = (pad_left + pad_right) .* nc
|
total_pad_horizontal = (pad_left + pad_right) .* nc
|
||||||
total_pad_vertical = (pad_top + pad_bottom) .* nr
|
total_pad_vertical = (pad_top + pad_bottom) .* nr
|
||||||
@show total_pad_horizontal total_pad_vertical
|
# @show total_pad_horizontal total_pad_vertical
|
||||||
|
|
||||||
# now we can compute the total plot area in each direction
|
# now we can compute the total plot area in each direction
|
||||||
total_plotarea_horizontal = width(layout) - total_pad_horizontal
|
total_plotarea_horizontal = width(layout) - total_pad_horizontal
|
||||||
total_plotarea_vertical = height(layout) - total_pad_vertical
|
total_plotarea_vertical = height(layout) - total_pad_vertical
|
||||||
@show total_plotarea_horizontal total_plotarea_vertical
|
# @show total_plotarea_horizontal total_plotarea_vertical
|
||||||
|
|
||||||
# normalize widths/heights so they sum to 1
|
# normalize widths/heights so they sum to 1
|
||||||
denom_w = sum(layout.widths)
|
denom_w = sum(layout.widths)
|
||||||
denom_h = sum(layout.heights)
|
denom_h = sum(layout.heights)
|
||||||
@show denom_w, denom_h
|
# @show denom_w, denom_h
|
||||||
|
|
||||||
# we have all the data we need... lets compute the plot areas
|
# we have all the data we need... lets compute the plot areas
|
||||||
for r=1:nr, c=1:nc
|
for r=1:nr, c=1:nc
|
||||||
@ -159,7 +159,7 @@ function update_child_bboxes!(layout::GridLayout)
|
|||||||
|
|
||||||
# get the top-left corner of this child
|
# get the top-left corner of this child
|
||||||
child_left = (c == 1 ? 0mm : right(layout[r, c-1].bbox))
|
child_left = (c == 1 ? 0mm : right(layout[r, c-1].bbox))
|
||||||
child_top = (r == 1 ? 0mm : top(layout[r-1, c].bbox))
|
child_top = (r == 1 ? 0mm : bottom(layout[r-1, c].bbox))
|
||||||
|
|
||||||
# compute plot area
|
# compute plot area
|
||||||
plotarea_left = child_left + pad_left[c]
|
plotarea_left = child_left + pad_left[c]
|
||||||
@ -172,12 +172,12 @@ function update_child_bboxes!(layout::GridLayout)
|
|||||||
child_width = pad_left[c] + plotarea_width + pad_right[c]
|
child_width = pad_left[c] + plotarea_width + pad_right[c]
|
||||||
child_height = pad_top[r] + plotarea_height + pad_bottom[r]
|
child_height = pad_top[r] + plotarea_height + pad_bottom[r]
|
||||||
child_bbox = BoundingBox(child_left, child_top, child_width, child_height)
|
child_bbox = BoundingBox(child_left, child_top, child_width, child_height)
|
||||||
@show (r,c) child_plotarea child_bbox
|
# @show (r,c) child_plotarea child_bbox
|
||||||
|
|
||||||
# the bounding boxes are currently relative to the parent, but we need them relative to the canvas
|
# the bounding boxes are currently relative to the parent, but we need them relative to the canvas
|
||||||
plotarea!(child, crop(layout.bbox, child_plotarea))
|
plotarea!(child, crop(layout.bbox, child_plotarea))
|
||||||
bbox!(child, crop(layout.bbox, child_bbox))
|
bbox!(child, crop(layout.bbox, child_bbox))
|
||||||
@show child_plotarea child_bbox
|
# @show child_plotarea child_bbox
|
||||||
|
|
||||||
# recursively update the child's children
|
# recursively update the child's children
|
||||||
update_child_bboxes!(child)
|
update_child_bboxes!(child)
|
||||||
|
|||||||
@ -105,10 +105,10 @@ function Base.(:+)(bb1::BoundingBox, bb2::BoundingBox)
|
|||||||
# return bb1
|
# return bb1
|
||||||
# end
|
# end
|
||||||
l = min(left(bb1), left(bb2))
|
l = min(left(bb1), left(bb2))
|
||||||
b = min(bottom(bb1), bottom(bb2))
|
t = min(top(bb1), top(bb2))
|
||||||
r = max(right(bb1), right(bb2))
|
r = max(right(bb1), right(bb2))
|
||||||
t = max(top(bb1), top(bb2))
|
b = max(bottom(bb1), bottom(bb2))
|
||||||
BoundingBox(l, t, r-l, t-b)
|
BoundingBox(l, t, r-l, b-t)
|
||||||
end
|
end
|
||||||
|
|
||||||
# this creates a bounding box in the parent's scope, where the child bounding box
|
# this creates a bounding box in the parent's scope, where the child bounding box
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user