Skip to content

Commit c7a9e02

Browse files
committed
Don't cull error bars based on plot area (#108)
... this allows the plot to show partial error bars if the plot area is not set up to show them entirely. The previous code would remove error bars whose center was not inside the plot area, we could have fixed the algorithm to consider a full line-rectangle intersection, however that code would probably would have run slower than just letting racket/draw do the clipping. A test was added to ensure the expected behavior is not reverted by accident in the future.
1 parent 6e20be1 commit c7a9e02

File tree

5 files changed

+40
-9
lines changed

5 files changed

+40
-9
lines changed

.github/workflows/ci.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,11 @@ jobs:
99
# the failure is specific to a Racket version.
1010
fail-fast: false
1111
matrix:
12-
racket-version: ["current"]
12+
racket-version: ["8.4", "current"]
1313
racket-variant: ["BC", "CS"]
1414
steps:
1515
- uses: actions/checkout@v2
16-
- uses: Bogdanp/setup-racket@v1.6
16+
- uses: Bogdanp/setup-racket@v1.7
1717
with:
1818
architecture: x64
1919
distribution: minimal

plot-lib/plot/private/plot2d/point.rkt

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,6 @@
190190
Nonnegative-Real Nonnegative-Real Boolean
191191
2D-Render-Proc))
192192
(define ((error-bars-render-fun xs ys hs color line-width line-style width alpha invert?) area)
193-
(define clip-rect (send area get-clip-rect))
194193
(define radius (* 1/2 width))
195194
(define angle (if invert? (/ pi 2) 0))
196195

@@ -200,12 +199,11 @@
200199
(send area put-alpha alpha)
201200
(send area put-pen color line-width line-style)
202201
(for ([x (in-list xs)] [y (in-list ys)] [h (in-list hs)])
203-
(when (rect-contains? clip-rect (maybe-invert x y))
204-
(define v1 (maybe-invert x (- y h)))
205-
(define v2 (maybe-invert x (+ y h)))
206-
(send area put-line v1 v2)
207-
(send area put-tick v1 radius angle)
208-
(send area put-tick v2 radius angle))))
202+
(define v1 (maybe-invert x (- y h)))
203+
(define v2 (maybe-invert x (+ y h)))
204+
(send area put-line v1 v2)
205+
(send area put-tick v1 radius angle)
206+
(send area put-tick v2 radius angle)))
209207

210208
(:: error-bars
211209
(->* [(Sequenceof (Sequenceof Real))]

plot-test/plot/tests/PRs/108.rkt

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
#lang racket
2+
3+
(require rackunit
4+
plot racket/runtime-path
5+
"../helpers.rkt")
6+
7+
;; Tests for https://github.com/racket/plot/issues/108, error bars are not
8+
;; culled out based on their center location, and partial error bars should be
9+
;; visible when the plot area does not include the entire error bar
10+
11+
(define-runtime-path pr108-data "./test-data/pr108.dat")
12+
13+
;; This plot is set up to have the area such that the center and edges of
14+
;; error bars are not in the plot, it should still draw a line from the
15+
;; partial error bar at 4.
16+
(define (do-plot-pr108 output-fn)
17+
(output-fn
18+
(list (function sqr 1 7)
19+
(error-bars (list (vector 2 4 12)
20+
(vector 4 16 20)
21+
(vector 6 36 10))))
22+
#:x-min 3.5 #:x-max 4.5
23+
#:y-min 20 #:y-max 30))
24+
25+
(define pr108-test-suite
26+
(test-suite
27+
"PR#108: Zoom in for error-bars (plot package) not working properly."
28+
(test-case "pr108"
29+
(check-draw-steps do-plot-pr108 pr108-data))))
30+
31+
(module+ test
32+
(require rackunit/text-ui)
33+
(run-tests pr108-test-suite))
1.65 KB
Binary file not shown.
11 KB
Loading

0 commit comments

Comments
 (0)