Closed bennn closed 1 year ago
but I guess
""
is the right choice
Not if you don't want adjacent ticks collapsed! (make-string i)
is better.
I agree that the documentation for the ticks-format function is confusing, and I created pull request #114 to try to improve it. Here is some example code that will trigger the new error:
#lang racket
(require plot)
(plot-new-window? #t)
(define (pr113-ticks-layout low high)
(define n 10)
(define step (/ (- high low) n))
(for/list ([x (in-range n)])
(pre-tick (+ low (* x step)) #t)))
(define (pr113-ticks-format low high pre-ticks)
(define labels
(for/list ([t (in-list pre-ticks)])
(format "pr113 ~a" (pre-tick-value t))))
;; Skipping a label causes the ticks to fail, illustrating the new check in
;; `ticks-generate`
(cdr labels))
(define pr113-ticks (ticks pr113-ticks-layout pr113-ticks-format))
(parameterize ([plot-x-ticks pr113-ticks])
(plot (function sin -5 5)))
Unfortunately, I am not sure how to add a better contract for the length of the elements, so for now, I added a check to the ticks-generate
function and report an error. This has the problem that the error is reported in the ticks-generate
function, not in the user supplied function.
Unfortunately, the ticks-format/c
contract as defined below is only used in the scribble documentation, not in the actual code, so adding a #post
clause to the contract will have no effect, since this contract is not actually used:
The "contract" for the format function is actually the Ticks-Format
Typed Racket type defined below. Unfortunately, I don't know how to add a constraint to this type to specify that the length of the returned list has to be the same as the length of the input pre-tick
list. @samth do you have any ideas?
A check inside the function sounds good.
TR won't be able to check list length without enabling refinements.
ticks
has a pretty good contract. For one, it'll catch layout functions that return bad lists:But if the layout function returns a list of length
4
and the format function returns a list of length2
, there's an internal error:Improve the contract --- or add a check.
Improve the docs for
ticks-layout/c
too. I wanted to return no string for minor ticks, but I guess""
is the right choice.