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
8 changes: 7 additions & 1 deletion plot-doc/plot/scribblings/renderer2d.scrbl
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,7 @@ An example of automatic scaling:
[#:line-style line-style plot-pen-style/c (error-bar-line-style)]
[#:width width (>=/c 0) (error-bar-width)]
[#:alpha alpha (real-in 0 1) (error-bar-alpha)]
[#:invert? invert? boolean? #f]
) renderer2d?]{
Returns a renderer that draws error bars.
The first and second element in each vector in @(racket bars) comprise the coordinate; the third is the height.
Expand All @@ -158,7 +159,12 @@ The first and second element in each vector in @(racket bars) comprise the coord
(error-bars (list (vector 2 4 12)
(vector 4 16 20)
(vector 6 36 10)))))]
}

If @racket[invert?] is @racket[#t], the x and y coordinates are inverted, and the bars are drawn horizontally
rather than vertically. This is intended for use with the corresponding option of @racket[discrete-histogram]
and @racket[stacked-histogram].

@history[#:changed "1.1" @elem{Added the @racket[#:invert?] option.}]}

@defproc[(candlesticks
[candles (sequence/c (sequence/c #:min-count 5 real?))]
Expand Down
2 changes: 2 additions & 0 deletions plot-lib/info.rkt
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,5 @@
(define pkg-desc "Plot non-GUI interface")

(define pkg-authors '(ntoronto))

(define version "1.1")
35 changes: 23 additions & 12 deletions plot-lib/plot/private/plot2d/point.rkt
Original file line number Diff line number Diff line change
Expand Up @@ -188,21 +188,25 @@

(: error-bars-render-fun (-> (Listof Real) (Listof Real) (Listof Real)
Plot-Color Nonnegative-Real Plot-Pen-Style
Nonnegative-Real Nonnegative-Real
Nonnegative-Real Nonnegative-Real Boolean
2D-Render-Proc))
(define ((error-bars-render-fun xs ys hs color line-width line-style width alpha) area)
(define ((error-bars-render-fun xs ys hs color line-width line-style width alpha invert?) area)
(define clip-rect (send area get-clip-rect))
(define radius (* 1/2 width))
(define angle (if invert? (/ pi 2) 0))

(: maybe-invert (All (A) (-> A A (Vectorof A))))
(define maybe-invert (if invert? (λ (x y) (vector y x)) vector))

(send area put-alpha alpha)
(send area put-pen color line-width line-style)
(for ([x (in-list xs)] [y (in-list ys)] [h (in-list hs)])
(when (rect-contains? clip-rect (vector x y))
(define v1 (vector x (- y h)))
(define v2 (vector x (+ y h)))
(when (rect-contains? clip-rect (maybe-invert x y))
(define v1 (maybe-invert x (- y h)))
(define v2 (maybe-invert x (+ y h)))
(send area put-line v1 v2)
(send area put-tick v1 radius 0)
(send area put-tick v2 radius 0)))
(send area put-tick v1 radius angle)
(send area put-tick v2 radius angle)))

empty)

Expand All @@ -214,7 +218,8 @@
#:line-width Nonnegative-Real
#:line-style Plot-Pen-Style
#:width Nonnegative-Real
#:alpha Nonnegative-Real]
#:alpha Nonnegative-Real
#:invert? Boolean]
renderer2d))
(define (error-bars bars
#:x-min [x-min #f] #:x-max [x-max #f]
Expand All @@ -223,7 +228,8 @@
#:line-width [line-width (error-bar-line-width)]
#:line-style [line-style (error-bar-line-style)]
#:width [width (error-bar-width)]
#:alpha [alpha (error-bar-alpha)])
#:alpha [alpha (error-bar-alpha)]
#:invert? [invert? #f])
(define fail/kw (make-raise-keyword-error 'error-bars))
(cond
[(and x-min (not (rational? x-min))) (fail/kw "#f or rational" '#:x-min x-min)]
Expand All @@ -246,9 +252,14 @@
[x-max (if x-max x-max (apply max* xs))]
[y-min (if y-min y-min (apply min* (map - ys hs)))]
[y-max (if y-max y-max (apply max* (map + ys hs)))])
(renderer2d (vector (ivl x-min x-max) (ivl y-min y-max)) #f default-ticks-fun
(error-bars-render-fun xs ys hs
color line-width line-style width alpha)))]))]))
(: maybe-invert (All (A) (-> A A (Vectorof A))))
(define maybe-invert (if invert? (λ (x y) (vector y x)) vector))
(renderer2d
(maybe-invert (ivl x-min x-max) (ivl y-min y-max))
#f
default-ticks-fun
(error-bars-render-fun xs ys hs
color line-width line-style width alpha invert?)))]))]))

;; ===================================================================================================
;; Candlesticks
Expand Down