diff --git a/collects/plot/common/utils.rkt b/collects/plot/common/utils.rkt index 7decacee39..40d5a1838c 100644 --- a/collects/plot/common/utils.rkt +++ b/collects/plot/common/utils.rkt @@ -57,3 +57,11 @@ (cond [(andmap (λ (e2) (equiv? e e2)) (first res)) (cons (cons e (first res)) (rest res))] [else (list* (list e) res)]))])))) + +(define (parameterize-procedure t) + (define parameterization (current-parameterization)) + (make-keyword-procedure + (lambda (kws kw-args . rest) + (call-with-parameterization + parameterization + (λ () (keyword-apply t kws kw-args rest)))))) diff --git a/collects/plot/plot2d/plot.rkt b/collects/plot/plot2d/plot.rkt index f34c207465..607d574db6 100644 --- a/collects/plot/plot2d/plot.rkt +++ b/collects/plot/plot2d/plot.rkt @@ -18,6 +18,7 @@ "../common/parameters.rkt" "../common/deprecation-warning.rkt" "../common/renderer.rkt" + "../common/utils.rkt" "area.rkt") ;; Require lazily: without this, Racket complains while generating documentation: @@ -115,43 +116,11 @@ [#:y-label y-label (or/c string? #f) (plot-y-label)] [#:legend-anchor legend-anchor anchor/c (plot-legend-anchor)] ) pict? - (define foreground (plot-foreground)) - (define background (plot-background)) - (define foreground-alpha (plot-foreground-alpha)) - (define background-alpha (plot-background-alpha)) - (define font-size (plot-font-size)) - (define font-family (plot-font-family)) - (define line-width (plot-line-width)) - (define legend-box-alpha (plot-legend-box-alpha)) - (define tick-size (plot-tick-size)) - (define x-transform (plot-x-transform)) - (define y-transform (plot-y-transform)) - (define z-transform (plot-z-transform)) - (define x-ticks (plot-x-ticks)) - (define y-ticks (plot-y-ticks)) - (define z-ticks (plot-z-ticks)) - (define animating? (plot-animating?)) - - (dc (λ (dc x y) - (parameterize ([plot-foreground foreground] - [plot-background background] - [plot-foreground-alpha foreground-alpha] - [plot-background-alpha background-alpha] - [plot-font-size font-size] - [plot-font-family font-family] - [plot-line-width line-width] - [plot-legend-box-alpha legend-box-alpha] - [plot-tick-size tick-size] - [plot-x-transform x-transform] - [plot-y-transform y-transform] - [plot-z-transform z-transform] - [plot-x-ticks x-ticks] - [plot-y-ticks y-ticks] - [plot-z-ticks z-ticks] - [plot-animating? animating?]) - (plot/dc renderer-tree dc x y width height - #:x-min x-min #:x-max x-max #:y-min y-min #:y-max y-max - #:title title #:x-label x-label #:y-label y-label #:legend-anchor legend-anchor))) + (dc (parameterize-procedure + (λ (dc x y) + (plot/dc renderer-tree dc x y width height + #:x-min x-min #:x-max x-max #:y-min y-min #:y-max y-max + #:title title #:x-label x-label #:y-label y-label #:legend-anchor legend-anchor))) width height)) ;; Plot to a snip diff --git a/collects/plot/plot3d/plot.rkt b/collects/plot/plot3d/plot.rkt index 78327b6390..2a2c334064 100644 --- a/collects/plot/plot3d/plot.rkt +++ b/collects/plot/plot3d/plot.rkt @@ -12,6 +12,7 @@ "../common/parameters.rkt" "../common/deprecation-warning.rkt" "../common/renderer.rkt" + "../common/utils.rkt" "area.rkt") ;; Require lazily: without this, Racket complains while generating documentation: @@ -130,53 +131,12 @@ [#:z-label z-label (or/c string? #f) (plot-z-label)] [#:legend-anchor legend-anchor anchor/c (plot-legend-anchor)] ) pict? - (define foreground (plot-foreground)) - (define background (plot-background)) - (define foreground-alpha (plot-foreground-alpha)) - (define background-alpha (plot-background-alpha)) - (define font-size (plot-font-size)) - (define font-family (plot-font-family)) - (define line-width (plot-line-width)) - (define legend-box-alpha (plot-legend-box-alpha)) - (define tick-size (plot-tick-size)) - (define x-transform (plot-x-transform)) - (define y-transform (plot-y-transform)) - (define z-transform (plot-z-transform)) - (define x-ticks (plot-x-ticks)) - (define y-ticks (plot-y-ticks)) - (define z-ticks (plot-z-ticks)) - (define animating? (plot-animating?)) - (define samples (plot3d-samples)) - (define ambient-light (plot3d-ambient-light)) - (define diffuse-light? (plot3d-diffuse-light?)) - (define specular-light? (plot3d-specular-light?)) - - (dc (λ (dc x y) - (parameterize ([plot-foreground foreground] - [plot-background background] - [plot-foreground-alpha foreground-alpha] - [plot-background-alpha background-alpha] - [plot-font-size font-size] - [plot-font-family font-family] - [plot-line-width line-width] - [plot-legend-box-alpha legend-box-alpha] - [plot-tick-size tick-size] - [plot-x-transform x-transform] - [plot-y-transform y-transform] - [plot-z-transform z-transform] - [plot-x-ticks x-ticks] - [plot-y-ticks y-ticks] - [plot-z-ticks z-ticks] - [plot-animating? animating?] - [plot3d-samples samples] - [plot3d-ambient-light ambient-light] - [plot3d-diffuse-light? diffuse-light?] - [plot3d-specular-light? specular-light?]) - (plot3d/dc - renderer-tree dc x y width height - #:x-min x-min #:x-max x-max #:y-min y-min #:y-max y-max #:z-min z-min #:z-max z-max - #:angle angle #:altitude altitude #:title title #:x-label x-label #:y-label y-label - #:z-label z-label #:legend-anchor legend-anchor))) + (dc (parameterize-procedure + (λ (dc x y) + (plot3d/dc renderer-tree dc x y width height + #:x-min x-min #:x-max x-max #:y-min y-min #:y-max y-max #:z-min z-min + #:z-max z-max #:angle angle #:altitude altitude #:title title #:x-label x-label + #:y-label y-label #:z-label z-label #:legend-anchor legend-anchor))) width height)) ;; Plot to a snip diff --git a/collects/plot/tests/slideshow-test.rkt b/collects/plot/tests/slideshow-test.rkt index 6711554884..8d2ff3952a 100644 --- a/collects/plot/tests/slideshow-test.rkt +++ b/collects/plot/tests/slideshow-test.rkt @@ -22,6 +22,7 @@ (parameterize ([plot-background 1] [plot-background-alpha 1/2] [plot-foreground 1]) + ;; This parabola should be pink: (plot-pict (function sqr -1 1 #:label "y = x^2") #:legend-anchor 'center)))