|
188 | 188 |
|
189 | 189 | (: error-bars-render-fun (-> (Listof Real) (Listof Real) (Listof Real) |
190 | 190 | Plot-Color Nonnegative-Real Plot-Pen-Style |
191 | | - Nonnegative-Real Nonnegative-Real |
| 191 | + Nonnegative-Real Nonnegative-Real Boolean |
192 | 192 | 2D-Render-Proc)) |
193 | | -(define ((error-bars-render-fun xs ys hs color line-width line-style width alpha) area) |
| 193 | +(define ((error-bars-render-fun xs ys hs color line-width line-style width alpha invert?) area) |
194 | 194 | (define clip-rect (send area get-clip-rect)) |
195 | 195 | (define radius (* 1/2 width)) |
| 196 | + (define angle (if invert? (/ pi 2) 0)) |
| 197 | + |
| 198 | + (: maybe-invert (All (A) (-> A A (Vectorof A)))) |
| 199 | + (define maybe-invert (if invert? (λ (x y) (vector y x)) vector)) |
196 | 200 |
|
197 | 201 | (send area put-alpha alpha) |
198 | 202 | (send area put-pen color line-width line-style) |
199 | 203 | (for ([x (in-list xs)] [y (in-list ys)] [h (in-list hs)]) |
200 | | - (when (rect-contains? clip-rect (vector x y)) |
201 | | - (define v1 (vector x (- y h))) |
202 | | - (define v2 (vector x (+ y h))) |
| 204 | + (when (rect-contains? clip-rect (maybe-invert x y)) |
| 205 | + (define v1 (maybe-invert x (- y h))) |
| 206 | + (define v2 (maybe-invert x (+ y h))) |
203 | 207 | (send area put-line v1 v2) |
204 | | - (send area put-tick v1 radius 0) |
205 | | - (send area put-tick v2 radius 0))) |
| 208 | + (send area put-tick v1 radius angle) |
| 209 | + (send area put-tick v2 radius angle))) |
206 | 210 |
|
207 | 211 | empty) |
208 | 212 |
|
|
214 | 218 | #:line-width Nonnegative-Real |
215 | 219 | #:line-style Plot-Pen-Style |
216 | 220 | #:width Nonnegative-Real |
217 | | - #:alpha Nonnegative-Real] |
| 221 | + #:alpha Nonnegative-Real |
| 222 | + #:invert? Boolean] |
218 | 223 | renderer2d)) |
219 | 224 | (define (error-bars bars |
220 | 225 | #:x-min [x-min #f] #:x-max [x-max #f] |
|
223 | 228 | #:line-width [line-width (error-bar-line-width)] |
224 | 229 | #:line-style [line-style (error-bar-line-style)] |
225 | 230 | #:width [width (error-bar-width)] |
226 | | - #:alpha [alpha (error-bar-alpha)]) |
| 231 | + #:alpha [alpha (error-bar-alpha)] |
| 232 | + #:invert? [invert? #f]) |
227 | 233 | (define fail/kw (make-raise-keyword-error 'error-bars)) |
228 | 234 | (cond |
229 | 235 | [(and x-min (not (rational? x-min))) (fail/kw "#f or rational" '#:x-min x-min)] |
|
246 | 252 | [x-max (if x-max x-max (apply max* xs))] |
247 | 253 | [y-min (if y-min y-min (apply min* (map - ys hs)))] |
248 | 254 | [y-max (if y-max y-max (apply max* (map + ys hs)))]) |
249 | | - (renderer2d (vector (ivl x-min x-max) (ivl y-min y-max)) #f default-ticks-fun |
250 | | - (error-bars-render-fun xs ys hs |
251 | | - color line-width line-style width alpha)))]))])) |
| 255 | + (: maybe-invert (All (A) (-> A A (Vectorof A)))) |
| 256 | + (define maybe-invert (if invert? (λ (x y) (vector y x)) vector)) |
| 257 | + (renderer2d |
| 258 | + (maybe-invert (ivl x-min x-max) (ivl y-min y-max)) |
| 259 | + #f |
| 260 | + default-ticks-fun |
| 261 | + (error-bars-render-fun xs ys hs |
| 262 | + color line-width line-style width alpha invert?)))]))])) |
252 | 263 |
|
253 | 264 | ;; =================================================================================================== |
254 | 265 | ;; Candlesticks |
|
0 commit comments