resolve relative coords for inset subplots
This commit is contained in:
parent
9fd09924eb
commit
0e598cc51d
@ -124,9 +124,9 @@ export
|
|||||||
# ---------------------------------------------------------
|
# ---------------------------------------------------------
|
||||||
|
|
||||||
import Measures
|
import Measures
|
||||||
import Measures: Length, AbsoluteLength, Measure, BoundingBox, mm, cm, inch, pt, width, height
|
import Measures: Length, AbsoluteLength, Measure, BoundingBox, mm, cm, inch, pt, width, height, w, h
|
||||||
typealias BBox Measures.Absolute2DBox
|
typealias BBox Measures.Absolute2DBox
|
||||||
export BBox, BoundingBox, mm, cm, inch, pt, px, pct
|
export BBox, BoundingBox, mm, cm, inch, pt, px, pct, w, h
|
||||||
|
|
||||||
# ---------------------------------------------------------
|
# ---------------------------------------------------------
|
||||||
|
|
||||||
|
|||||||
@ -23,6 +23,8 @@ convertColor(c::Symbol) = parse(Colorant, string(c))
|
|||||||
convertColor(c::Colorant) = c
|
convertColor(c::Colorant) = c
|
||||||
convertColor(cvec::AbstractVector) = map(convertColor, cvec)
|
convertColor(cvec::AbstractVector) = map(convertColor, cvec)
|
||||||
convertColor(c::ColorScheme) = c
|
convertColor(c::ColorScheme) = c
|
||||||
|
convertColor(v::Void) = RGBA(0,0,0,0)
|
||||||
|
convertColor(b::Bool) = b ? RGBA(0,0,0,1) : RGBA(0,0,0,0)
|
||||||
|
|
||||||
function convertColor(c, α::Real)
|
function convertColor(c, α::Real)
|
||||||
c = convertColor(c)
|
c = convertColor(c)
|
||||||
|
|||||||
@ -138,8 +138,9 @@ bottom(layout::AbstractLayout) = bottom(bbox(layout))
|
|||||||
width(layout::AbstractLayout) = width(bbox(layout))
|
width(layout::AbstractLayout) = width(bbox(layout))
|
||||||
height(layout::AbstractLayout) = height(bbox(layout))
|
height(layout::AbstractLayout) = height(bbox(layout))
|
||||||
|
|
||||||
plotarea(layout::AbstractLayout) = defaultbox
|
# pass these through to the bbox methods if there's no plotarea
|
||||||
plotarea!(layout::AbstractLayout, bbox::BoundingBox) = nothing
|
plotarea(layout::AbstractLayout) = bbox(layout)
|
||||||
|
plotarea!(layout::AbstractLayout, bb::BoundingBox) = bbox!(layout, bb)
|
||||||
|
|
||||||
attr(layout::AbstractLayout, k::Symbol) = layout.attr[k]
|
attr(layout::AbstractLayout, k::Symbol) = layout.attr[k]
|
||||||
attr(layout::AbstractLayout, k::Symbol, v) = get(layout.attr, k, v)
|
attr(layout::AbstractLayout, k::Symbol, v) = get(layout.attr, k, v)
|
||||||
@ -354,23 +355,19 @@ function update_child_bboxes!(layout::GridLayout, minimum_perimeter = [0mm,0mm,0
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# for each inset (floating) subplot, resolve the relative position
|
||||||
|
# to absolute canvas coordinates, relative to the parent's plotarea
|
||||||
function update_inset_bboxes!(plt::Plot)
|
function update_inset_bboxes!(plt::Plot)
|
||||||
for sp in plt.inset_subplots
|
for sp in plt.inset_subplots
|
||||||
relative_bbox = sp[:relative_bbox]
|
p_area = Measures.resolve(plotarea(sp.parent), sp[:relative_bbox])
|
||||||
# TODO: need to handle percentages... right now only AbsoluteLength works
|
# @show bbox(sp.parent) sp[:relative_bbox] p_area
|
||||||
|
plotarea!(sp, p_area)
|
||||||
|
|
||||||
bb = bbox!(sp, bbox(
|
bbox!(sp, bbox(
|
||||||
left(sp.parent) + left(relative_bbox),
|
left(p_area) - leftpad(sp),
|
||||||
top(sp.parent) + top(relative_bbox),
|
top(p_area) - toppad(sp),
|
||||||
width(relative_bbox),
|
width(p_area) + leftpad(sp) + rightpad(sp),
|
||||||
height(relative_bbox)
|
height(p_area) + toppad(sp) + bottompad(sp)
|
||||||
))
|
|
||||||
|
|
||||||
plotarea!(sp, bbox(
|
|
||||||
left(bb) + leftpad(sp),
|
|
||||||
top(bb) + toppad(sp),
|
|
||||||
width(bb) - leftpad(sp) - rightpad(sp),
|
|
||||||
height(bb) - toppad(sp) - bottompad(sp)
|
|
||||||
))
|
))
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
10
src/plot.jl
10
src/plot.jl
@ -353,10 +353,15 @@ function _plot!(plt::Plot, d::KW, args...)
|
|||||||
sp.attr[:subplot_index] = idx
|
sp.attr[:subplot_index] = idx
|
||||||
end
|
end
|
||||||
|
|
||||||
|
plt.init = true
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
# handle inset subplots
|
# handle inset subplots
|
||||||
insets = plt[:inset_subplots]
|
insets = plt[:inset_subplots]
|
||||||
if insets != nothing
|
if insets != nothing
|
||||||
for (parent, bb) in insets
|
for inset in insets
|
||||||
|
parent, bb = is_2tuple(inset) ? inset : (nothing, inset)
|
||||||
P = typeof(parent)
|
P = typeof(parent)
|
||||||
if P <: Integer
|
if P <: Integer
|
||||||
parent = plt.subplots[parent]
|
parent = plt.subplots[parent]
|
||||||
@ -374,9 +379,6 @@ function _plot!(plt::Plot, d::KW, args...)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
plt.init = true
|
|
||||||
end
|
|
||||||
|
|
||||||
# just in case the backend needs to set up the plot (make it current or something)
|
# just in case the backend needs to set up the plot (make it current or something)
|
||||||
_prepare_plot_object(plt)
|
_prepare_plot_object(plt)
|
||||||
|
|
||||||
|
|||||||
@ -281,6 +281,8 @@ ismatrix(::Any) = false
|
|||||||
isscalar(::Real) = true
|
isscalar(::Real) = true
|
||||||
isscalar(::Any) = false
|
isscalar(::Any) = false
|
||||||
|
|
||||||
|
is_2tuple(v) = typeof(v) <: Tuple && length(v) == 2
|
||||||
|
|
||||||
|
|
||||||
isvertical(d::KW) = get(d, :orientation, :vertical) in (:vertical, :v, :vert)
|
isvertical(d::KW) = get(d, :orientation, :vertical) in (:vertical, :v, :vert)
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user