Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 12 additions & 8 deletions plot-lib/plot/private/common/draw.rkt
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,10 @@
(define (margin-fixpoint x-min x-max y-min y-max
init-left init-right init-top init-bottom
get-vs)
(define x- (+ x-min init-left))
(define x+ (- x-max init-right 1))
(define y- (+ y-min init-top))
(define y+ (- y-max init-bottom 1))
(let/ec return : (Values Real Real Real Real)
(for/fold ([left : Real init-left]
[right : Real init-right]
Expand All @@ -250,15 +254,15 @@
([i (in-range 3)])
(match-define (list (vector #{xs : (Listof Real)} #{ys : (Listof Real)}) ...)
(get-vs left right top bottom))
(define param-x-min (apply min x-min xs))
(define param-x-max (apply max (sub1 x-max) xs))
(define param-y-min (apply min y-min ys))
(define param-y-max (apply max (sub1 y-max) ys))
(define param-x-min (apply min x- xs))
(define param-x-max (apply max x+ xs))
(define param-y-min (apply min y- ys))
(define param-y-max (apply max y+ ys))

(define new-left (round (+ left (- x-min param-x-min))))
(define new-right (round (- right (- (sub1 x-max) param-x-max))))
(define new-top (round (+ top (- y-min param-y-min))))
(define new-bottom (round (- bottom (- (sub1 y-max) param-y-max))))
(define new-left (round (+ left (- x- param-x-min))))
(define new-right (round (- right (- x+ param-x-max))))
(define new-top (round (+ top (- y- param-y-min))))
(define new-bottom (round (- bottom (- y+ param-y-max))))

;; Not enough space?
(define area-x-min (+ x-min new-left))
Expand Down
2 changes: 1 addition & 1 deletion plot-lib/plot/private/plot2d/plot-area.rkt
Original file line number Diff line number Diff line change
Expand Up @@ -552,7 +552,7 @@
(define: top : Real 0)
(define: bottom : Real 0)
(let-values ([(left-val right-val top-val bottom-val)
(margin-fixpoint 0 dc-x-size init-top-margin dc-y-size 0 0 init-top-margin 0
(margin-fixpoint 0 dc-x-size 0 dc-y-size 0 0 init-top-margin 0
(λ ([left : Real] [right : Real] [top : Real] [bottom : Real])
(get-param-vs/set-view->dc! left right top bottom)))])
(set! left left-val)
Expand Down
23 changes: 23 additions & 0 deletions plot-test/plot/tests/PRs/75.rkt
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#lang racket
(require rackunit
plot pict
racket/runtime-path
"../helpers.rkt")

;; Tests for: https://github.com/racket/plot/pull/75

(define (do-plot-margin-calc output-fn)
(output-fn (function values 0 1)
#:title (standard-fish 700 350)))

(define-runtime-path pr75-data "./test-data/pr75.dat")

(define pr75-test-suite
(test-suite
"PR#75: margin error"
(test-case "pr75-margin"
(check-draw-steps do-plot-margin-calc pr75-data))))

(module+ test
(require rackunit/text-ui)
(run-tests pr75-test-suite))
Binary file added plot-test/plot/tests/PRs/test-data/pr75.dat
Binary file not shown.
Binary file added plot-test/plot/tests/PRs/test-data/pr75.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified plot-test/plot/tests/test-data/p3d-14.dat
Binary file not shown.
Binary file modified plot-test/plot/tests/test-data/p3d-14.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.