Better error message when plot can't determine sensible bounds
This commit is contained in:
parent
cf75609d82
commit
8f914f653f
|
@ -83,6 +83,9 @@
|
|||
(defproc (real->plot-label [x real?] [digits exact-integer?] [scientific? boolean? #t]) any
|
||||
(cond
|
||||
[(zero? x) "0"]
|
||||
[(eqv? x +nan.0) "+nan.0"]
|
||||
[(eqv? x +inf.0) "+inf.0"]
|
||||
[(eqv? x -inf.0) "-inf.0"]
|
||||
[else
|
||||
(define front-sign (if (x . < . 0) "-" ""))
|
||||
(define mid-sign (if (x . < . 0) "-" "+"))
|
||||
|
@ -133,6 +136,26 @@
|
|||
[frac-zero? (format "~a~a" front-sign int-str)]
|
||||
[else (format "~a~a.~a" front-sign int-str frac-str)])]))]))
|
||||
|
||||
(define (format-special x)
|
||||
(case x
|
||||
[(#f) "#f"]
|
||||
[(+nan.0) "+nan.0"]
|
||||
[(+inf.0) "+inf.0"]
|
||||
[(-inf.0) "-inf.0"]
|
||||
[else "<unknown>"]))
|
||||
|
||||
(defproc (ivl->string [i ivl?] [extra-digits exact-integer? 3]) string?
|
||||
(match-define (ivl a b) i)
|
||||
(cond [(and (not (regular-real? a)) (not (regular-real? b)))
|
||||
(format "[~a,~a]" (format-special a) (format-special b))]
|
||||
[(not (regular-real? a)) (format "[~a,~a]" (format-special a) (real->plot-label b 15))]
|
||||
[(not (regular-real? b)) (format "[~a,~a]" (real->plot-label a 15) (format-special b))]
|
||||
[else
|
||||
(define digits (digits-for-range a b extra-digits))
|
||||
(format "[~a,~a]"
|
||||
(real->plot-label a digits)
|
||||
(real->plot-label b digits))]))
|
||||
|
||||
(defproc (->plot-label [a any/c] [digits exact-integer? 7]) string?
|
||||
(let loop ([a a])
|
||||
(cond [(string? a) a]
|
||||
|
|
|
@ -7,5 +7,5 @@
|
|||
integer->superscript
|
||||
digits-for-range
|
||||
real->decimal-string* real->string/trunc
|
||||
real->plot-label ->plot-label
|
||||
real->plot-label ivl->string ->plot-label
|
||||
parse-format-string apply-formatter))
|
||||
|
|
|
@ -14,6 +14,7 @@
|
|||
"../common/file-type.rkt"
|
||||
"../common/deprecation-warning.rkt"
|
||||
"../common/contract-doc.rkt"
|
||||
"../common/format.rkt"
|
||||
"plot-area.rkt")
|
||||
|
||||
;; Require lazily: without this, Racket complains while generating documentation:
|
||||
|
@ -37,9 +38,9 @@
|
|||
(define plot-bounds-rect (bounds-fixpoint renderer-list given-bounds-rect))
|
||||
(when (or (not (rect-regular? plot-bounds-rect))
|
||||
(rect-zero-area? plot-bounds-rect))
|
||||
(match-define (vector (ivl x-min x-max) (ivl y-min y-max)) plot-bounds-rect)
|
||||
(error 'plot "could not determine sensible plot bounds; got x ∈ [~a,~a], y ∈ [~a,~a]"
|
||||
x-min x-max y-min y-max))
|
||||
(match-define (vector x-ivl y-ivl) plot-bounds-rect)
|
||||
(error 'plot "could not determine sensible plot bounds; got x ∈ ~a, y ∈ ~a"
|
||||
(ivl->string x-ivl) (ivl->string y-ivl)))
|
||||
plot-bounds-rect)
|
||||
|
||||
(define (get-ticks renderer-list bounds-rect)
|
||||
|
|
|
@ -14,6 +14,7 @@
|
|||
"../common/file-type.rkt"
|
||||
"../common/deprecation-warning.rkt"
|
||||
"../common/contract-doc.rkt"
|
||||
"../common/format.rkt"
|
||||
"plot-area.rkt")
|
||||
|
||||
;; Require lazily: without this, Racket complains while generating documentation:
|
||||
|
@ -38,9 +39,9 @@
|
|||
(define plot-bounds-rect (bounds-fixpoint renderer-list given-bounds-rect))
|
||||
(when (or (not (rect-regular? plot-bounds-rect))
|
||||
(rect-zero-area? plot-bounds-rect))
|
||||
(match-define (vector (ivl x-min x-max) (ivl y-min y-max) (ivl z-min z-max)) plot-bounds-rect)
|
||||
(error 'plot "could not determine sensible plot bounds; got x ∈ [~a,~a], y ∈ [~a,~a], z ∈ [~a,~a]"
|
||||
x-min x-max y-min y-max z-min z-max))
|
||||
(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"
|
||||
(ivl->string x-ivl) (ivl->string y-ivl) (ivl->string z-ivl)))
|
||||
plot-bounds-rect)
|
||||
|
||||
(define (get-ticks renderer-list bounds-rect)
|
||||
|
|
Loading…
Reference in New Issue
Block a user