Skip to content

Commit 840d7ef

Browse files
committed
GraphLayout should adjust its title location if the plot size changes
1 parent 8bb2c56 commit 840d7ef

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

Sources/SwiftPlot/GraphLayout.swift

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,8 +170,16 @@ public struct GraphLayout {
170170
/// Makes adjustments to the layout as requested by the plot.
171171
private func adjustPlotSize(info: AdjustsPlotSize, results: inout Results) {
172172
if info.desiredPlotSize != .zero {
173+
let topDifference = results.plotBorderRect.height - info.desiredPlotSize.height
173174
results.plotBorderRect.size = info.desiredPlotSize
175+
// Adjust the title location for the change in height.
176+
if var oldTitleLocation = results.titleLocation {
177+
oldTitleLocation.y -= topDifference/2
178+
results.titleLocation = oldTitleLocation
179+
}
180+
// FIXME: Adjust Y2 label and anything else on the right side.
174181
}
182+
175183
}
176184

177185
/// Rounds the given markers to integer pixel locations, for sharper gridlines.

0 commit comments

Comments
 (0)