|
66 | 66 | #:title (U String pict #f) |
67 | 67 | #:x-label (U String pict #f) |
68 | 68 | #:y-label (U String pict #f) |
| 69 | + #:aspect-ratio (U Nonnegative-Real #f) |
69 | 70 | #:legend-anchor Legend-Anchor] |
70 | 71 | (Instance Snip%))) |
71 | 72 | (define (plot-snip renderer-tree |
|
76 | 77 | #:title [title (plot-title)] |
77 | 78 | #:x-label [x-label (plot-x-label)] |
78 | 79 | #:y-label [y-label (plot-y-label)] |
| 80 | + #:aspect-ratio [aspect-ratio (plot-aspect-ratio)] |
79 | 81 | #:legend-anchor [legend-anchor (plot-legend-anchor)]) |
80 | 82 | (define fail/kw (make-raise-keyword-error 'plot-snip)) |
81 | 83 | (cond |
|
89 | 91 | [(and title (not (or (string? title) (pict? title)))) (fail/kw "#f, string or pict" '#:title title)] |
90 | 92 | [(and x-label (not (or (string? x-label) (pict? x-label)))) (fail/kw "#f, string or pict" '#:x-label x-label)] |
91 | 93 | [(and y-label (not (or (string? y-label) (pict? y-label)))) (fail/kw "#f, string or pict" '#:y-label y-label)] |
| 94 | + [(and aspect-ratio (not (and (rational? aspect-ratio) (positive? aspect-ratio)))) |
| 95 | + (fail/kw "#f or positive real" '#:aspect-ratio aspect-ratio)] |
92 | 96 | [(not (legend-anchor/c legend-anchor)) (fail/kw "legend-anchor/c" '#:legend-anchor legend-anchor)]) |
93 | 97 |
|
94 | 98 | (parameterize ([plot-title title] |
|
116 | 120 | (define new-area |
117 | 121 | (make-object 2d-plot-area% |
118 | 122 | bounds-rect x-ticks x-far-ticks y-ticks y-far-ticks legend |
119 | | - dc 0 0 width height)) |
| 123 | + dc 0 0 width height aspect-ratio)) |
120 | 124 | (set! area new-area) |
121 | 125 | (plot-area new-area renderer-list)) |
122 | 126 | (values bm area)) |
|
137 | 141 | #:title (U String pict #f) |
138 | 142 | #:x-label (U String pict #f) |
139 | 143 | #:y-label (U String pict #f) |
| 144 | + #:aspect-ratio (U Nonnegative-Real #f) |
140 | 145 | #:legend-anchor Legend-Anchor] |
141 | 146 | (Instance Frame%))) |
142 | 147 | (define (plot-frame renderer-tree |
|
147 | 152 | #:title [title (plot-title)] |
148 | 153 | #:x-label [x-label (plot-x-label)] |
149 | 154 | #:y-label [y-label (plot-y-label)] |
| 155 | + #:aspect-ratio [aspect-ratio (plot-aspect-ratio)] |
150 | 156 | #:legend-anchor [legend-anchor (plot-legend-anchor)]) |
151 | 157 | (define fail/kw (make-raise-keyword-error 'plot-frame)) |
152 | 158 | (cond |
|
160 | 166 | [(and title (not (or (string? title) (pict? title)))) (fail/kw "#f, string or pict" '#:title title)] |
161 | 167 | [(and x-label (not (or (string? x-label) (pict? x-label)))) (fail/kw "#f, string or pict" '#:x-label x-label)] |
162 | 168 | [(and y-label (not (or (string? y-label) (pict? y-label)))) (fail/kw "#f, string or pict" '#:y-label y-label)] |
| 169 | + [(and aspect-ratio (not (and (rational? aspect-ratio) (positive? aspect-ratio)))) |
| 170 | + (fail/kw "#f or positive real" '#:aspect-ratio aspect-ratio)] |
163 | 171 | [(not (legend-anchor/c legend-anchor)) (fail/kw "legend-anchor/c" '#:legend-anchor legend-anchor)]) |
164 | 172 |
|
165 | 173 | ;; make-snip will be called in a separate thread, make sure the |
|
171 | 179 | (plot-snip |
172 | 180 | renderer-tree |
173 | 181 | #:x-min x-min #:x-max x-max #:y-min y-min #:y-max y-max #:width width #:height height |
174 | | - #:title title #:x-label x-label #:y-label y-label #:legend-anchor legend-anchor))) |
| 182 | + #:title title #:x-label x-label #:y-label y-label #:legend-anchor legend-anchor |
| 183 | + #:aspect-ratio aspect-ratio))) |
175 | 184 | (make-snip-frame make-snip width height (if title (format "Plot: ~a" title) "Plot"))) |
176 | 185 |
|
177 | 186 | ;; =================================================================================================== |
|
186 | 195 | #:title (U String pict #f) |
187 | 196 | #:x-label (U String pict #f) |
188 | 197 | #:y-label (U String pict #f) |
| 198 | + #:aspect-ratio (U Nonnegative-Real #f) |
189 | 199 | #:legend-anchor Legend-Anchor |
190 | 200 | #:out-file (U Path-String Output-Port #f) |
191 | 201 | #:out-kind (U 'auto Image-File-Format) |
|
201 | 211 | #:title [title (plot-title)] |
202 | 212 | #:x-label [x-label (plot-x-label)] |
203 | 213 | #:y-label [y-label (plot-y-label)] |
| 214 | + #:aspect-ratio [aspect-ratio (plot-aspect-ratio)] |
204 | 215 | #:legend-anchor [legend-anchor (plot-legend-anchor)] |
205 | 216 | #:out-file [out-file #f] |
206 | 217 | #:out-kind [out-kind 'auto] |
|
226 | 237 | [(and title (not (or (string? title) (pict? title)))) (fail/kw "#f, string or pict" '#:title title)] |
227 | 238 | [(and x-label (not (or (string? x-label) (pict? x-label)))) (fail/kw "#f, string or pict" '#:x-label x-label)] |
228 | 239 | [(and y-label (not (or (string? y-label) (pict? y-label)))) (fail/kw "#f, string or pict" '#:y-label y-label)] |
| 240 | + [(and aspect-ratio (not (and (rational? aspect-ratio) (positive? aspect-ratio)))) |
| 241 | + (fail/kw "#f or positive real" '#:aspect-ratio aspect-ratio)] |
229 | 242 | [(not (legend-anchor/c legend-anchor)) (fail/kw "legend-anchor/c" '#:legend-anchor legend-anchor)] |
230 | 243 | [(and out-kind (not (plot-file-format/c out-kind))) (fail/kw "plot-file-format/c" '#:out-kind out-kind)] |
231 | 244 | [(not (plot-file-format/c out-kind)) (fail/kw "plot-file-format/c" '#:out-kind out-kind)] |
|
241 | 254 | (plot-file |
242 | 255 | renderer-tree out-file out-kind |
243 | 256 | #:x-min x-min #:x-max x-max #:y-min y-min #:y-max y-max #:width width #:height height |
244 | | - #:title title #:x-label x-label #:y-label y-label #:legend-anchor legend-anchor)) |
| 257 | + #:title title #:x-label x-label #:y-label y-label #:legend-anchor legend-anchor |
| 258 | + #:aspect-ratio aspect-ratio)) |
245 | 259 |
|
246 | 260 | (cond [(plot-new-window?) |
247 | 261 | (define frame |
248 | 262 | (plot-frame |
249 | 263 | renderer-tree |
250 | 264 | #:x-min x-min #:x-max x-max #:y-min y-min #:y-max y-max #:width width #:height height |
251 | | - #:title title #:x-label x-label #:y-label y-label #:legend-anchor legend-anchor)) |
| 265 | + #:title title #:x-label x-label #:y-label y-label #:legend-anchor legend-anchor |
| 266 | + #:aspect-ratio aspect-ratio)) |
252 | 267 | (send frame show #t) |
253 | 268 | (void)] |
254 | 269 | [else |
255 | 270 | (plot-snip |
256 | 271 | renderer-tree |
257 | 272 | #:x-min x-min #:x-max x-max #:y-min y-min #:y-max y-max #:width width #:height height |
258 | | - #:title title #:x-label x-label #:y-label y-label #:legend-anchor legend-anchor)]))) |
| 273 | + #:title title #:x-label x-label #:y-label y-label #:legend-anchor legend-anchor |
| 274 | + #:aspect-ratio aspect-ratio)]))) |
0 commit comments