Allow plots with 0-length axes

Closes PR 14053
This commit is contained in:
Neil Toronto 2014-04-05 20:04:29 -06:00
parent c8f3974a20
commit cd293eb379
4 changed files with 32 additions and 19 deletions

View File

@ -79,7 +79,7 @@
(format "~a.~a×10~a" fst rst (integer->superscript (- (add1 i))))])]))) (format "~a.~a×10~a" fst rst (integer->superscript (- (add1 i))))])])))
(define (zero-string n) (define (zero-string n)
(list->string (build-list n (λ _ #\0)))) (make-string n #\0))
(defproc (real->plot-label [x real?] [digits exact-integer?] [scientific? boolean? #t]) any (defproc (real->plot-label [x real?] [digits exact-integer?] [scientific? boolean? #t]) any
(cond (cond

View File

@ -16,13 +16,20 @@
(define (get-bounds-rect renderer-list x-min x-max y-min y-max) (define (get-bounds-rect renderer-list x-min x-max y-min y-max)
(define given-bounds-rect (vector (ivl x-min x-max) (ivl y-min y-max))) (define given-bounds-rect (vector (ivl x-min x-max) (ivl y-min y-max)))
(define plot-bounds-rect (bounds-fixpoint renderer-list given-bounds-rect)) (let* ([plot-bounds-rect (bounds-fixpoint renderer-list given-bounds-rect)]
(when (or (not (rect-rational? plot-bounds-rect)) [plot-bounds-rect
(rect-zero-area? plot-bounds-rect)) (cond [(not (rect-rational? plot-bounds-rect))
(match-define (vector x-ivl y-ivl) plot-bounds-rect) (match-define (vector x-ivl y-ivl) plot-bounds-rect)
(error 'plot "could not determine sensible plot bounds; got x ∈ ~a, y ∈ ~a" (error 'plot "could not determine sensible plot bounds; got x ∈ ~a, y ∈ ~a"
(ivl->plot-label x-ivl) (ivl->plot-label y-ivl))) (ivl->plot-label x-ivl) (ivl->plot-label y-ivl))]
(rect-inexact->exact plot-bounds-rect)) [(rect-zero-area? plot-bounds-rect)
(for/vector ([i (in-vector plot-bounds-rect)])
(match-define (ivl a b) i)
(cond [(= a b) (if (zero? a) (ivl -1 1) (ivl (* a (- 1 1e-2)) (* b (+ 1 1e-2))))]
[else i]))]
[else
plot-bounds-rect])])
(rect-inexact->exact plot-bounds-rect)))
(define (get-ticks renderer-list bounds-rect) (define (get-ticks renderer-list bounds-rect)
(define-values (all-x-ticks all-x-far-ticks all-y-ticks all-y-far-ticks) (define-values (all-x-ticks all-x-far-ticks all-y-ticks all-y-far-ticks)

View File

@ -16,13 +16,20 @@
(define (get-bounds-rect renderer-list x-min x-max y-min y-max z-min z-max) (define (get-bounds-rect renderer-list x-min x-max y-min y-max z-min z-max)
(define given-bounds-rect (vector (ivl x-min x-max) (ivl y-min y-max) (ivl z-min z-max))) (define given-bounds-rect (vector (ivl x-min x-max) (ivl y-min y-max) (ivl z-min z-max)))
(define plot-bounds-rect (bounds-fixpoint renderer-list given-bounds-rect)) (let* ([plot-bounds-rect (bounds-fixpoint renderer-list given-bounds-rect)]
(when (or (not (rect-rational? plot-bounds-rect)) [plot-bounds-rect
(rect-zero-area? plot-bounds-rect)) (cond [(not (rect-rational? plot-bounds-rect))
(match-define (vector x-ivl y-ivl z-ivl) plot-bounds-rect) (match-define (vector x-ivl y-ivl z-ivl) plot-bounds-rect)
(error 'plot "could not determine sensible plot bounds; got x ∈ ~a, y ∈ ~a, z ∈ ~a" (error 'plot "could not determine sensible plot bounds; got x ∈ ~a, y ∈ ~a, z ∈ ~a"
(ivl->plot-label x-ivl) (ivl->plot-label y-ivl) (ivl->plot-label z-ivl))) (ivl->plot-label x-ivl) (ivl->plot-label y-ivl) (ivl->plot-label z-ivl))]
(rect-inexact->exact plot-bounds-rect)) [(rect-zero-area? plot-bounds-rect)
(for/vector ([i (in-vector plot-bounds-rect)])
(match-define (ivl a b) i)
(cond [(= a b) (if (zero? a) (ivl -1 1) (ivl (* a (- 1 1e-2)) (* b (+ 1 1e-2))))]
[else i]))]
[else
plot-bounds-rect])])
(rect-inexact->exact plot-bounds-rect)))
(define (get-ticks renderer-list bounds-rect) (define (get-ticks renderer-list bounds-rect)
(define-values (all-x-ticks all-x-far-ticks all-y-ticks all-y-far-ticks all-z-ticks all-z-far-ticks) (define-values (all-x-ticks all-x-far-ticks all-y-ticks all-y-far-ticks all-z-ticks all-z-far-ticks)

View File

@ -156,10 +156,9 @@
#:color "blue") #:color "blue")
(axes 1 0 #:y-ticks? #f))) (axes 1 0 #:y-ticks? #f)))
;; error: could not determine x bounds (printf "Plot should be empty:~n")
(check-exn exn:fail? (plot (list (function sqr #f -1)
(λ () (plot (list (function sqr #f -1) (function sqr 1 #f)))
(function sqr 1 #f)))))
; draws both functions with x in [-1,2] (meaning nothing is drawn) ; draws both functions with x in [-1,2] (meaning nothing is drawn)
(printf "Plot should be empty:~n") (printf "Plot should be empty:~n")