From f6a48813475f81336bcf2bab658c23e14b73e976 Mon Sep 17 00:00:00 2001 From: Neil Toronto Date: Wed, 9 Oct 2013 15:19:34 -0600 Subject: [PATCH] Plot source reorg before separating "plot" into multiple packages Also added plot/pict and plot/bitmap (and typed versions) --- pkgs/plot/bitmap.rkt | 8 + pkgs/plot/compat.rkt | 199 +--------- pkgs/plot/main.rkt | 92 +---- pkgs/plot/no-gui.rkt | 87 +++++ pkgs/plot/pict.rkt | 8 + pkgs/plot/plot2d/plot.rkt | 307 --------------- pkgs/plot/plot3d/plot.rkt | 352 ------------------ .../{ => private}/common/axis-transform.rkt | 0 pkgs/plot/{ => private}/common/contract.rkt | 0 pkgs/plot/{ => private}/common/currency.rkt | 0 pkgs/plot/{ => private}/common/date-time.rkt | 0 .../common/deprecation-warning.rkt | 0 pkgs/plot/{ => private}/common/draw.rkt | 0 pkgs/plot/{ => private}/common/file-type.rkt | 0 pkgs/plot/{ => private}/common/format.rkt | 0 pkgs/plot/{ => private}/common/kde.rkt | 0 pkgs/plot/{ => private}/common/legend.rkt | 0 .../{ => private}/common/marching-cubes.rkt | 0 .../{ => private}/common/marching-squares.rkt | 0 .../{ => private}/common/marching-utils.rkt | 0 pkgs/plot/{ => private}/common/math.rkt | 0 .../plot/{ => private}/common/nonrenderer.rkt | 0 pkgs/plot/{ => private}/common/parameters.rkt | 0 .../plot/{ => private}/common/plot-device.rkt | 0 .../{ => private}/common/plot-element.rkt | 0 pkgs/plot/{ => private}/common/sample.rkt | 0 pkgs/plot/{ => private}/common/samplers.rkt | 0 pkgs/plot/{ => private}/common/ticks.rkt | 0 pkgs/plot/{ => private}/common/utils.rkt | 0 .../{ => private}/common/worker-thread.rkt | 0 pkgs/plot/private/compat.rkt | 199 ++++++++++ .../contracted/axis-transform.rkt | 0 .../{ => private}/contracted/date-time.rkt | 0 pkgs/plot/{ => private}/contracted/draw.rkt | 0 pkgs/plot/{ => private}/contracted/format.rkt | 0 pkgs/plot/{ => private}/contracted/kde.rkt | 0 pkgs/plot/{ => private}/contracted/legend.rkt | 0 pkgs/plot/{ => private}/contracted/math.rkt | 0 .../{ => private}/contracted/parameters.rkt | 0 .../{ => private}/contracted/plot-element.rkt | 0 pkgs/plot/{ => private}/contracted/sample.rkt | 0 .../{ => private}/contracted/samplers.rkt | 0 pkgs/plot/{ => private}/contracted/ticks.rkt | 0 .../{ => private}/deprecated/deprecated.rkt | 0 pkgs/plot/{ => private}/deprecated/math.rkt | 0 .../{ => private}/deprecated/renderers.rkt | 0 pkgs/plot/{ => private}/doc.rkt | 12 +- pkgs/plot/{common => private/gui}/gui.rkt | 0 pkgs/plot/private/gui/plot2d.rkt | 134 +++++++ pkgs/plot/private/gui/plot3d.rkt | 166 +++++++++ pkgs/plot/{common => private/gui}/snip.rkt | 8 +- .../snip.rkt => private/gui/snip2d.rkt} | 2 +- .../snip.rkt => private/gui/snip3d.rkt} | 2 +- pkgs/plot/private/no-gui/plot-bitmap.rkt | 63 ++++ pkgs/plot/private/no-gui/plot-pict.rkt | 62 +++ pkgs/plot/private/no-gui/plot2d-utils.rkt | 56 +++ pkgs/plot/private/no-gui/plot2d.rkt | 132 +++++++ pkgs/plot/private/no-gui/plot3d-utils.rkt | 61 +++ pkgs/plot/private/no-gui/plot3d.rkt | 150 ++++++++ pkgs/plot/{ => private}/plot2d/clip.rkt | 0 pkgs/plot/{ => private}/plot2d/contour.rkt | 0 pkgs/plot/{ => private}/plot2d/decoration.rkt | 0 pkgs/plot/{ => private}/plot2d/interval.rkt | 0 pkgs/plot/{ => private}/plot2d/line.rkt | 0 pkgs/plot/{ => private}/plot2d/plot-area.rkt | 0 pkgs/plot/{ => private}/plot2d/point.rkt | 0 pkgs/plot/{ => private}/plot2d/rectangle.rkt | 0 pkgs/plot/{ => private}/plot3d/clip.rkt | 0 pkgs/plot/{ => private}/plot3d/contour.rkt | 0 pkgs/plot/{ => private}/plot3d/decoration.rkt | 0 pkgs/plot/{ => private}/plot3d/isosurface.rkt | 0 pkgs/plot/{ => private}/plot3d/line.rkt | 0 pkgs/plot/{ => private}/plot3d/matrix.rkt | 0 pkgs/plot/{ => private}/plot3d/plot-area.rkt | 0 pkgs/plot/{ => private}/plot3d/point.rkt | 0 pkgs/plot/{ => private}/plot3d/rectangle.rkt | 0 pkgs/plot/{ => private}/plot3d/shape.rkt | 0 pkgs/plot/{ => private}/plot3d/surface.rkt | 0 pkgs/plot/scribblings/common.rkt | 10 +- pkgs/plot/scribblings/compat.scrbl | 5 +- pkgs/plot/scribblings/contracts.scrbl | 5 +- pkgs/plot/scribblings/custom.scrbl | 3 +- pkgs/plot/scribblings/intro.scrbl | 10 +- pkgs/plot/scribblings/nonrenderer.scrbl | 1 + pkgs/plot/scribblings/params.scrbl | 9 +- pkgs/plot/scribblings/plot.scrbl | 11 +- pkgs/plot/scribblings/plot2d.scrbl | 96 ----- pkgs/plot/scribblings/plot3d.scrbl | 64 ---- pkgs/plot/scribblings/plotting.scrbl | 221 +++++++++++ pkgs/plot/scribblings/porting.scrbl | 21 +- pkgs/plot/scribblings/renderer2d.scrbl | 5 +- pkgs/plot/scribblings/renderer3d.scrbl | 5 +- pkgs/plot/scribblings/ticks.scrbl | 9 +- pkgs/plot/scribblings/utils.scrbl | 13 +- pkgs/plot/tests/doc-tests.rkt | 2 +- pkgs/plot/tests/low-level-tests.rkt | 10 +- pkgs/plot/tests/plot-bitmap.rkt | 17 + pkgs/plot/tests/plot-no-gui.rkt | 20 + pkgs/plot/tests/plot-pict.rkt | 16 + pkgs/plot/tests/subdivision-tests.rkt | 4 +- .../parameter-regression-tests.rkt} | 0 pkgs/plot/tests/typed/plot-bitmap.rkt | 11 + pkgs/plot/tests/typed/plot-no-gui.rkt | 20 + pkgs/plot/tests/typed/plot-pict.rkt | 16 + .../plot-tests.rkt} | 0 pkgs/plot/typed/bitmap.rkt | 8 + pkgs/plot/typed/main.rkt | 85 +---- pkgs/plot/typed/no-gui.rkt | 79 ++++ pkgs/plot/typed/pict.rkt | 8 + .../{ => private}/common/nonrenderers.rkt | 0 .../plot/typed/{ => private}/common/types.rkt | 37 +- .../contracted/axis-transform.rkt | 2 +- .../{ => private}/contracted/date-time.rkt | 2 +- .../typed/{ => private}/contracted/draw.rkt | 2 +- .../typed/{ => private}/contracted/format.rkt | 2 +- .../typed/{ => private}/contracted/kde.rkt | 2 +- .../typed/{ => private}/contracted/math.rkt | 8 +- .../{ => private}/contracted/parameters.rkt | 2 +- .../typed/{ => private}/contracted/sample.rkt | 2 +- .../typed/{ => private}/contracted/ticks.rkt | 2 +- pkgs/plot/typed/private/gui/plot2d.rkt | 54 +++ pkgs/plot/typed/private/gui/plot3d.rkt | 69 ++++ .../plot/typed/private/no-gui/plot-bitmap.rkt | 46 +++ pkgs/plot/typed/private/no-gui/plot-pict.rkt | 46 +++ .../plot.rkt => private/no-gui/plot2d.rkt} | 129 +++---- .../plot.rkt => private/no-gui/plot3d.rkt} | 174 +++------ .../typed/{ => private}/plot2d/contour.rkt | 0 .../typed/{ => private}/plot2d/decoration.rkt | 0 .../typed/{ => private}/plot2d/interval.rkt | 0 pkgs/plot/typed/{ => private}/plot2d/line.rkt | 0 .../plot/typed/{ => private}/plot2d/point.rkt | 0 .../typed/{ => private}/plot2d/rectangle.rkt | 0 .../typed/{ => private}/plot3d/contour.rkt | 0 .../typed/{ => private}/plot3d/decoration.rkt | 0 .../typed/{ => private}/plot3d/isosurface.rkt | 0 pkgs/plot/typed/{ => private}/plot3d/line.rkt | 0 .../plot/typed/{ => private}/plot3d/point.rkt | 0 .../typed/{ => private}/plot3d/rectangle.rkt | 0 .../typed/{ => private}/plot3d/surface.rkt | 0 pkgs/plot/typed/{ => private}/syntax.rkt | 0 pkgs/plot/typed/utils.rkt | 62 +-- pkgs/plot/utils.rkt | 60 +-- 142 files changed, 2046 insertions(+), 1539 deletions(-) create mode 100644 pkgs/plot/bitmap.rkt create mode 100644 pkgs/plot/no-gui.rkt create mode 100644 pkgs/plot/pict.rkt delete mode 100644 pkgs/plot/plot2d/plot.rkt delete mode 100644 pkgs/plot/plot3d/plot.rkt rename pkgs/plot/{ => private}/common/axis-transform.rkt (100%) rename pkgs/plot/{ => private}/common/contract.rkt (100%) rename pkgs/plot/{ => private}/common/currency.rkt (100%) rename pkgs/plot/{ => private}/common/date-time.rkt (100%) rename pkgs/plot/{ => private}/common/deprecation-warning.rkt (100%) rename pkgs/plot/{ => private}/common/draw.rkt (100%) rename pkgs/plot/{ => private}/common/file-type.rkt (100%) rename pkgs/plot/{ => private}/common/format.rkt (100%) rename pkgs/plot/{ => private}/common/kde.rkt (100%) rename pkgs/plot/{ => private}/common/legend.rkt (100%) rename pkgs/plot/{ => private}/common/marching-cubes.rkt (100%) rename pkgs/plot/{ => private}/common/marching-squares.rkt (100%) rename pkgs/plot/{ => private}/common/marching-utils.rkt (100%) rename pkgs/plot/{ => private}/common/math.rkt (100%) rename pkgs/plot/{ => private}/common/nonrenderer.rkt (100%) rename pkgs/plot/{ => private}/common/parameters.rkt (100%) rename pkgs/plot/{ => private}/common/plot-device.rkt (100%) rename pkgs/plot/{ => private}/common/plot-element.rkt (100%) rename pkgs/plot/{ => private}/common/sample.rkt (100%) rename pkgs/plot/{ => private}/common/samplers.rkt (100%) rename pkgs/plot/{ => private}/common/ticks.rkt (100%) rename pkgs/plot/{ => private}/common/utils.rkt (100%) rename pkgs/plot/{ => private}/common/worker-thread.rkt (100%) create mode 100644 pkgs/plot/private/compat.rkt rename pkgs/plot/{ => private}/contracted/axis-transform.rkt (100%) rename pkgs/plot/{ => private}/contracted/date-time.rkt (100%) rename pkgs/plot/{ => private}/contracted/draw.rkt (100%) rename pkgs/plot/{ => private}/contracted/format.rkt (100%) rename pkgs/plot/{ => private}/contracted/kde.rkt (100%) rename pkgs/plot/{ => private}/contracted/legend.rkt (100%) rename pkgs/plot/{ => private}/contracted/math.rkt (100%) rename pkgs/plot/{ => private}/contracted/parameters.rkt (100%) rename pkgs/plot/{ => private}/contracted/plot-element.rkt (100%) rename pkgs/plot/{ => private}/contracted/sample.rkt (100%) rename pkgs/plot/{ => private}/contracted/samplers.rkt (100%) rename pkgs/plot/{ => private}/contracted/ticks.rkt (100%) rename pkgs/plot/{ => private}/deprecated/deprecated.rkt (100%) rename pkgs/plot/{ => private}/deprecated/math.rkt (100%) rename pkgs/plot/{ => private}/deprecated/renderers.rkt (100%) rename pkgs/plot/{ => private}/doc.rkt (90%) rename pkgs/plot/{common => private/gui}/gui.rkt (100%) create mode 100644 pkgs/plot/private/gui/plot2d.rkt create mode 100644 pkgs/plot/private/gui/plot3d.rkt rename pkgs/plot/{common => private/gui}/snip.rkt (98%) rename pkgs/plot/{plot2d/snip.rkt => private/gui/snip2d.rkt} (99%) rename pkgs/plot/{plot3d/snip.rkt => private/gui/snip3d.rkt} (99%) create mode 100644 pkgs/plot/private/no-gui/plot-bitmap.rkt create mode 100644 pkgs/plot/private/no-gui/plot-pict.rkt create mode 100644 pkgs/plot/private/no-gui/plot2d-utils.rkt create mode 100644 pkgs/plot/private/no-gui/plot2d.rkt create mode 100644 pkgs/plot/private/no-gui/plot3d-utils.rkt create mode 100644 pkgs/plot/private/no-gui/plot3d.rkt rename pkgs/plot/{ => private}/plot2d/clip.rkt (100%) rename pkgs/plot/{ => private}/plot2d/contour.rkt (100%) rename pkgs/plot/{ => private}/plot2d/decoration.rkt (100%) rename pkgs/plot/{ => private}/plot2d/interval.rkt (100%) rename pkgs/plot/{ => private}/plot2d/line.rkt (100%) rename pkgs/plot/{ => private}/plot2d/plot-area.rkt (100%) rename pkgs/plot/{ => private}/plot2d/point.rkt (100%) rename pkgs/plot/{ => private}/plot2d/rectangle.rkt (100%) rename pkgs/plot/{ => private}/plot3d/clip.rkt (100%) rename pkgs/plot/{ => private}/plot3d/contour.rkt (100%) rename pkgs/plot/{ => private}/plot3d/decoration.rkt (100%) rename pkgs/plot/{ => private}/plot3d/isosurface.rkt (100%) rename pkgs/plot/{ => private}/plot3d/line.rkt (100%) rename pkgs/plot/{ => private}/plot3d/matrix.rkt (100%) rename pkgs/plot/{ => private}/plot3d/plot-area.rkt (100%) rename pkgs/plot/{ => private}/plot3d/point.rkt (100%) rename pkgs/plot/{ => private}/plot3d/rectangle.rkt (100%) rename pkgs/plot/{ => private}/plot3d/shape.rkt (100%) rename pkgs/plot/{ => private}/plot3d/surface.rkt (100%) delete mode 100644 pkgs/plot/scribblings/plot2d.scrbl delete mode 100644 pkgs/plot/scribblings/plot3d.scrbl create mode 100644 pkgs/plot/scribblings/plotting.scrbl create mode 100644 pkgs/plot/tests/plot-bitmap.rkt create mode 100644 pkgs/plot/tests/plot-no-gui.rkt create mode 100644 pkgs/plot/tests/plot-pict.rkt rename pkgs/plot/tests/{typed-parameter-regression-tests.rkt => typed/parameter-regression-tests.rkt} (100%) create mode 100644 pkgs/plot/tests/typed/plot-bitmap.rkt create mode 100644 pkgs/plot/tests/typed/plot-no-gui.rkt create mode 100644 pkgs/plot/tests/typed/plot-pict.rkt rename pkgs/plot/tests/{typed-plot-tests.rkt => typed/plot-tests.rkt} (100%) create mode 100644 pkgs/plot/typed/bitmap.rkt create mode 100644 pkgs/plot/typed/no-gui.rkt create mode 100644 pkgs/plot/typed/pict.rkt rename pkgs/plot/typed/{ => private}/common/nonrenderers.rkt (100%) rename pkgs/plot/typed/{ => private}/common/types.rkt (86%) rename pkgs/plot/typed/{ => private}/contracted/axis-transform.rkt (95%) rename pkgs/plot/typed/{ => private}/contracted/date-time.rkt (90%) rename pkgs/plot/typed/{ => private}/contracted/draw.rkt (95%) rename pkgs/plot/typed/{ => private}/contracted/format.rkt (96%) rename pkgs/plot/typed/{ => private}/contracted/kde.rkt (85%) rename pkgs/plot/typed/{ => private}/contracted/math.rkt (95%) rename pkgs/plot/typed/{ => private}/contracted/parameters.rkt (99%) rename pkgs/plot/typed/{ => private}/contracted/sample.rkt (94%) rename pkgs/plot/typed/{ => private}/contracted/ticks.rkt (98%) create mode 100644 pkgs/plot/typed/private/gui/plot2d.rkt create mode 100644 pkgs/plot/typed/private/gui/plot3d.rkt create mode 100644 pkgs/plot/typed/private/no-gui/plot-bitmap.rkt create mode 100644 pkgs/plot/typed/private/no-gui/plot-pict.rkt rename pkgs/plot/typed/{plot2d/plot.rkt => private/no-gui/plot2d.rkt} (53%) rename pkgs/plot/typed/{plot3d/plot.rkt => private/no-gui/plot3d.rkt} (55%) rename pkgs/plot/typed/{ => private}/plot2d/contour.rkt (100%) rename pkgs/plot/typed/{ => private}/plot2d/decoration.rkt (100%) rename pkgs/plot/typed/{ => private}/plot2d/interval.rkt (100%) rename pkgs/plot/typed/{ => private}/plot2d/line.rkt (100%) rename pkgs/plot/typed/{ => private}/plot2d/point.rkt (100%) rename pkgs/plot/typed/{ => private}/plot2d/rectangle.rkt (100%) rename pkgs/plot/typed/{ => private}/plot3d/contour.rkt (100%) rename pkgs/plot/typed/{ => private}/plot3d/decoration.rkt (100%) rename pkgs/plot/typed/{ => private}/plot3d/isosurface.rkt (100%) rename pkgs/plot/typed/{ => private}/plot3d/line.rkt (100%) rename pkgs/plot/typed/{ => private}/plot3d/point.rkt (100%) rename pkgs/plot/typed/{ => private}/plot3d/rectangle.rkt (100%) rename pkgs/plot/typed/{ => private}/plot3d/surface.rkt (100%) rename pkgs/plot/typed/{ => private}/syntax.rkt (100%) diff --git a/pkgs/plot/bitmap.rkt b/pkgs/plot/bitmap.rkt new file mode 100644 index 0000000000..d31ac1339b --- /dev/null +++ b/pkgs/plot/bitmap.rkt @@ -0,0 +1,8 @@ +#lang racket/base + +(require unstable/latent-contract + "no-gui.rkt" + "private/no-gui/plot-bitmap.rkt") + +(provide (all-from-out "no-gui.rkt") + (activate-contract-out plot plot3d)) diff --git a/pkgs/plot/compat.rkt b/pkgs/plot/compat.rkt index e3d6c006b2..130aaaac70 100644 --- a/pkgs/plot/compat.rkt +++ b/pkgs/plot/compat.rkt @@ -1,199 +1,4 @@ #lang racket/base -;; A compatibility module for the old 'plot'. - -(require racket/contract racket/class racket/snip racket/draw racket/vector - unstable/latent-contract unstable/latent-contract/defthing - ;; Plotting - "common/math.rkt" - "common/contract.rkt" - "common/plot-element.rkt" - "plot2d/plot-area.rkt" - "plot3d/plot-area.rkt" - (prefix-in new. (only-in "main.rkt" - x-axis y-axis - plot-x-ticks plot-y-ticks plot-z-ticks - points error-bars vector-field - plot-title plot-x-label plot-y-label plot-z-label - plot-foreground plot-background - plot3d-angle plot3d-altitude)) - "deprecated/renderers.rkt" - ;; Miscellaneous - "deprecated/math.rkt") - -(provide mix - (activate-contract-out plot-color? - plot plot3d - points vector-field error-bars - line - contour shade - surface) - (only-doc-out (all-defined-out)) - ;; Miscellaneous - make-vec derivative gradient) - -(define (mix . data) - (for/fold ([f (λ (area) (void))]) ([d (in-list data)]) - (λ (area) - (f area) - (d area) - (void)))) - -(defproc (plot-color? [v any/c]) boolean? - (and (member v '(white black yellow green aqua pink wheat gray brown blue violet cyan - turquoise magenta salmon red)) - #t)) - -(define ((renderer2d->plot-data r) area) - ((renderer2d-render-proc r) area) - (void)) - -(define ((renderer3d->plot-data r) area) - ((renderer3d-render-proc r) area) - (void)) - -;; =================================================================================================== -;; Plotting - -(define x-axis-data (renderer2d->plot-data (new.x-axis))) -(define y-axis-data (renderer2d->plot-data (new.y-axis))) - -(defproc (plot [data ((is-a?/c 2d-plot-area%) . -> . void?)] - [#:width width real? 400] [#:height height real? 400] - [#:x-min x-min real? -5] [#:x-max x-max real? 5] - [#:y-min y-min real? -5] [#:y-max y-max real? 5] - [#:x-label x-label string? "X axis"] [#:y-label y-label string? "Y axis"] - [#:title title string? ""] - [#:fgcolor fgcolor (list/c byte? byte? byte?) '(0 0 0)] - [#:bgcolor bgcolor (list/c byte? byte? byte?) '(255 255 255)] - [#:lncolor lncolor (list/c byte? byte? byte?) '(255 0 0)] - [#:out-file out-file (or/c path-string? output-port? #f) #f] - ) (is-a?/c image-snip%) - (define x-ticks ((new.plot-x-ticks) x-min x-max)) - (define y-ticks ((new.plot-y-ticks) y-min y-max)) - (define bounds-rect (vector (ivl x-min x-max) (ivl y-min y-max))) - - (parameterize ([new.plot-title title] - [new.plot-x-label x-label] - [new.plot-y-label y-label] - [new.plot-foreground fgcolor] - [new.plot-background bgcolor]) - (define bm (make-bitmap (ceiling width) (ceiling height))) - (define dc (make-object bitmap-dc% bm)) - (define area (make-object 2d-plot-area% - bounds-rect x-ticks x-ticks y-ticks y-ticks dc 0 0 width height)) - - (define data+axes (mix x-axis-data y-axis-data data)) - - (send area start-plot) - (send area start-renderer bounds-rect) - (data+axes area) - (send area end-renderers) - (send area end-plot) - - (when out-file (send bm save-file out-file 'png)) - - (make-object image-snip% bm))) - -(defproc (plot3d [data ((is-a?/c 3d-plot-area%) . -> . void?)] - [#:width width real? 400] [#:height height real? 400] - [#:x-min x-min real? -5] [#:x-max x-max real? 5] - [#:y-min y-min real? -5] [#:y-max y-max real? 5] - [#:z-min z-min real? -5] [#:z-max z-max real? 5] - [#:alt alt real? 30] - [#:az az real? 45] - [#:x-label x-label string? "X axis"] - [#:y-label y-label string? "Y axis"] - [#:z-label z-label string? "Z axis"] - [#:title title string? ""] - [#:fgcolor fgcolor (list/c byte? byte? byte?) '(0 0 0)] - [#:bgcolor bgcolor (list/c byte? byte? byte?) '(255 255 255)] - [#:lncolor lncolor (list/c byte? byte? byte?) '(255 0 0)] - [#:out-file out-file (or/c path-string? output-port? #f) #f] - ) (is-a?/c image-snip%) - (define x-ticks ((new.plot-x-ticks) x-min x-max)) - (define y-ticks ((new.plot-y-ticks) y-min y-max)) - (define z-ticks ((new.plot-z-ticks) z-min z-max)) - (define bounds-rect (vector (ivl x-min x-max) (ivl y-min y-max) (ivl z-min z-max))) - - (parameterize ([new.plot-title title] - [new.plot-x-label x-label] - [new.plot-y-label y-label] - [new.plot-z-label z-label] - [new.plot-foreground fgcolor] - [new.plot-background bgcolor] - [new.plot3d-angle az] - [new.plot3d-altitude alt]) - (define bm (make-bitmap (ceiling width) (ceiling height))) - (define dc (make-object bitmap-dc% bm)) - (define area (make-object 3d-plot-area% - bounds-rect x-ticks x-ticks y-ticks y-ticks z-ticks z-ticks dc 0 0 width height)) - - (send area start-plot) - (send area start-renderer bounds-rect) - (data area) - (send area end-renderers) - (send area end-plot) - - (when out-file (send bm save-file out-file 'png)) - - (make-object image-snip% bm))) - -;; =================================================================================================== -;; Functions that generate "plot data" - -(defproc (points [vecs (listof (vectorof real?))] - [#:sym sym (or/c char? string? exact-integer? symbol?) 'square] - [#:color color plot-color? 'black] - ) ((is-a?/c 2d-plot-area%) . -> . void?) - (renderer2d->plot-data (new.points (map (λ (v) (vector-take v 2)) vecs) - #:sym sym #:size 6 #:color color))) - -(defproc (vector-field [f ((vector/c real? real?) . -> . (vector/c real? real?))] - [#:samples samples (and/c exact-integer? (>=/c 2)) 20] - [#:width width exact-positive-integer? 1] - [#:color color plot-color? 'red] - [#:style style (one-of/c 'scaled 'normalized 'real) 'scaled] - ) ((is-a?/c 2d-plot-area%) . -> . void?) - (define scale (case style - [(scaled) 'auto] - [(normalized) 'normalized] - [(real) 1.0])) - (renderer2d->plot-data - (new.vector-field f #:samples samples #:line-width width #:color color #:scale scale))) - -(defproc (error-bars [vecs (listof (vector/c real? real? real?))] - [#:color color plot-color? 'black] - ) ((is-a?/c 2d-plot-area%) . -> . void?) - (renderer2d->plot-data (new.error-bars vecs #:color color #:alpha 1 #:width 4))) - -(defproc (line [f (real? . -> . (or/c real? (vector/c real? real?)))] - [#:samples samples (and/c exact-integer? (>=/c 2)) 150] - [#:width width (>=/c 0) 1] - [#:color color plot-color/c 'red] - [#:mode mode (one-of/c 'standard 'parametric) 'standard] - [#:mapping mapping (one-of/c 'cartesian 'polar) 'cartesian] - [#:t-min t-min real? -5] [#:t-max t-max real? 5] - ) ((is-a?/c 2d-plot-area%) . -> . void?) - (renderer2d->plot-data (line-renderer f samples width color mode mapping t-min t-max))) - -(defproc (contour [f (real? real? . -> . real?)] - [#:samples samples exact-nonnegative-integer? 50] - [#:width width (>=/c 0) 1] - [#:color color plot-color/c 'black] - [#:levels levels (or/c (and/c exact-integer? (>=/c 2)) (listof real?)) 10] - ) ((is-a?/c 2d-plot-area%) . -> . void?) - (renderer2d->plot-data (contour-renderer f samples width color levels))) - -(defproc (shade [f (real? real? . -> . real?)] - [#:samples samples (and/c exact-integer? (>=/c 2)) 50] - [#:levels levels (or/c (and/c exact-integer? (>=/c 2)) (listof real?)) 10] - ) ((is-a?/c 2d-plot-area%) . -> . void?) - (renderer2d->plot-data (shade-renderer f samples levels))) - -(defproc (surface [f (real? real? . -> . real?)] - [#:samples samples (and/c exact-integer? (>=/c 2)) 50] - [#:width width (>=/c 0) 1] - [#:color color plot-color/c 'black] - ) ((is-a?/c 3d-plot-area%) . -> . void?) - (renderer3d->plot-data (surface-renderer f samples width color))) +(require "private/compat.rkt") +(provide (all-from-out "private/compat.rkt")) diff --git a/pkgs/plot/main.rkt b/pkgs/plot/main.rkt index 745804f132..58289d59e5 100644 --- a/pkgs/plot/main.rkt +++ b/pkgs/plot/main.rkt @@ -1,88 +1,10 @@ #lang racket/base -(require racket/contract unstable/latent-contract) +(require unstable/latent-contract + "no-gui.rkt" + "private/gui/plot2d.rkt" + "private/gui/plot3d.rkt") -;; =================================================================================================== -;; General exports - -(require "contracted/parameters.rkt") -(provide (all-from-out "contracted/parameters.rkt")) - -(require "contracted/math.rkt") -(provide (struct-out ivl)) - -(require "contracted/axis-transform.rkt") -(provide (all-from-out "contracted/axis-transform.rkt")) - -(require "contracted/ticks.rkt") -(provide (all-from-out "contracted/ticks.rkt")) - -(require "contracted/date-time.rkt") -(provide (struct-out plot-time) - plot-time->seconds seconds->plot-time - datetime->real) - -(require "common/nonrenderer.rkt") -(provide (activate-contract-out x-ticks y-ticks z-ticks invisible-rect invisible-rect3d)) - -;; =================================================================================================== -;; 2D exports - -(require "plot2d/plot.rkt") -(provide (activate-contract-out plot/dc plot plot-bitmap plot-pict plot-snip plot-frame plot-file)) - -(require "plot2d/point.rkt") -(provide (activate-contract-out points vector-field error-bars)) - -(require "plot2d/line.rkt") -(provide (activate-contract-out lines parametric polar function inverse density)) - -(require "plot2d/interval.rkt") -(provide (activate-contract-out - lines-interval parametric-interval polar-interval function-interval inverse-interval)) - -(require "plot2d/contour.rkt") -(provide (activate-contract-out isoline contours contour-intervals)) - -(require "plot2d/rectangle.rkt") -(provide (activate-contract-out rectangles area-histogram discrete-histogram stacked-histogram)) - -(require "plot2d/decoration.rkt") -(provide (activate-contract-out - x-axis y-axis axes polar-axes - x-tick-lines y-tick-lines tick-grid - point-label parametric-label polar-label function-label inverse-label)) - -;; =================================================================================================== -;; 3D exports - -(require "plot3d/plot.rkt") -(provide (activate-contract-out - plot3d/dc plot3d plot3d-bitmap plot3d-pict plot3d-snip plot3d-frame plot3d-file)) - -(require "plot3d/surface.rkt") -(provide (activate-contract-out surface3d)) - -(require "plot3d/contour.rkt") -(provide (activate-contract-out isoline3d contours3d contour-intervals3d)) - -(require "plot3d/line.rkt") -(provide (activate-contract-out lines3d parametric3d)) - -(require "plot3d/point.rkt") -(provide (activate-contract-out points3d vector-field3d)) - -(require "plot3d/isosurface.rkt") -(provide (activate-contract-out isosurface3d isosurfaces3d polar3d)) - -(require "plot3d/rectangle.rkt") -(provide (activate-contract-out rectangles3d discrete-histogram3d stacked-histogram3d)) - -(require "plot3d/decoration.rkt") -(provide (activate-contract-out point-label3d)) - -;; =================================================================================================== -;; Deprecated functions - -(require "deprecated/deprecated.rkt") -(provide mix (activate-contract-out line contour shade surface)) +(provide (all-from-out "no-gui.rkt") + (activate-contract-out plot-snip plot-frame plot) + (activate-contract-out plot3d-snip plot3d-frame plot3d)) diff --git a/pkgs/plot/no-gui.rkt b/pkgs/plot/no-gui.rkt new file mode 100644 index 0000000000..2a17aba884 --- /dev/null +++ b/pkgs/plot/no-gui.rkt @@ -0,0 +1,87 @@ +#lang racket/base + +(require racket/contract unstable/latent-contract) + +;; =================================================================================================== +;; General exports + +(require "private/contracted/parameters.rkt") +(provide (all-from-out "private/contracted/parameters.rkt")) + +(require "private/contracted/math.rkt") +(provide (struct-out ivl)) + +(require "private/contracted/axis-transform.rkt") +(provide (all-from-out "private/contracted/axis-transform.rkt")) + +(require "private/contracted/ticks.rkt") +(provide (all-from-out "private/contracted/ticks.rkt")) + +(require "private/contracted/date-time.rkt") +(provide (struct-out plot-time) + plot-time->seconds seconds->plot-time + datetime->real) + +(require "private/common/nonrenderer.rkt") +(provide (activate-contract-out x-ticks y-ticks z-ticks invisible-rect invisible-rect3d)) + +;; =================================================================================================== +;; 2D exports + +(require "private/no-gui/plot2d.rkt") +(provide (activate-contract-out plot/dc plot-bitmap plot-pict plot-file)) + +(require "private/plot2d/point.rkt") +(provide (activate-contract-out points vector-field error-bars)) + +(require "private/plot2d/line.rkt") +(provide (activate-contract-out lines parametric polar function inverse density)) + +(require "private/plot2d/interval.rkt") +(provide (activate-contract-out + lines-interval parametric-interval polar-interval function-interval inverse-interval)) + +(require "private/plot2d/contour.rkt") +(provide (activate-contract-out isoline contours contour-intervals)) + +(require "private/plot2d/rectangle.rkt") +(provide (activate-contract-out rectangles area-histogram discrete-histogram stacked-histogram)) + +(require "private/plot2d/decoration.rkt") +(provide (activate-contract-out + x-axis y-axis axes polar-axes + x-tick-lines y-tick-lines tick-grid + point-label parametric-label polar-label function-label inverse-label)) + +;; =================================================================================================== +;; 3D exports + +(require "private/no-gui/plot3d.rkt") +(provide (activate-contract-out plot3d/dc plot3d-bitmap plot3d-pict plot3d-file)) + +(require "private/plot3d/surface.rkt") +(provide (activate-contract-out surface3d)) + +(require "private/plot3d/contour.rkt") +(provide (activate-contract-out isoline3d contours3d contour-intervals3d)) + +(require "private/plot3d/line.rkt") +(provide (activate-contract-out lines3d parametric3d)) + +(require "private/plot3d/point.rkt") +(provide (activate-contract-out points3d vector-field3d)) + +(require "private/plot3d/isosurface.rkt") +(provide (activate-contract-out isosurface3d isosurfaces3d polar3d)) + +(require "private/plot3d/rectangle.rkt") +(provide (activate-contract-out rectangles3d discrete-histogram3d stacked-histogram3d)) + +(require "private/plot3d/decoration.rkt") +(provide (activate-contract-out point-label3d)) + +;; =================================================================================================== +;; Deprecated functions + +(require "private/deprecated/deprecated.rkt") +(provide mix (activate-contract-out line contour shade surface)) diff --git a/pkgs/plot/pict.rkt b/pkgs/plot/pict.rkt new file mode 100644 index 0000000000..c4c1c4aef3 --- /dev/null +++ b/pkgs/plot/pict.rkt @@ -0,0 +1,8 @@ +#lang racket/base + +(require unstable/latent-contract + "no-gui.rkt" + "private/no-gui/plot-pict.rkt") + +(provide (all-from-out "no-gui.rkt") + (activate-contract-out plot plot3d)) diff --git a/pkgs/plot/plot2d/plot.rkt b/pkgs/plot/plot2d/plot.rkt deleted file mode 100644 index 1eac6f1ae5..0000000000 --- a/pkgs/plot/plot2d/plot.rkt +++ /dev/null @@ -1,307 +0,0 @@ -#lang racket/base - -;; Procedures that plot 2D renderers. - -(require racket/draw racket/snip racket/contract racket/list racket/class racket/match - unstable/contract - pict - unstable/parameter-group - racket/lazy-require - unstable/latent-contract/defthing - "../common/contract.rkt" - "../common/math.rkt" - "../common/draw.rkt" - "../common/parameters.rkt" - "../common/plot-element.rkt" - "../common/file-type.rkt" - "../common/deprecation-warning.rkt" - "../common/format.rkt" - "plot-area.rkt") - -;; Require lazily: without this, Racket complains while generating documentation: -;; cannot instantiate `racket/gui/base' a second time in the same process -(lazy-require ["snip.rkt" (make-2d-plot-snip)] - ["../common/gui.rkt" (make-snip-frame with-new-eventspace)]) - -(provide (except-out (all-defined-out) get-renderer-list get-bounds-rect get-ticks plot-dc)) - -;; =================================================================================================== -;; Plot to a given device context - -(define (get-renderer-list renderer-tree) - (for/list ([r (flatten (list renderer-tree))]) - (match r - [(nonrenderer bounds-rect bounds-fun ticks-fun) - (renderer2d bounds-rect bounds-fun ticks-fun #f)] - [_ r]))) - -(define (get-bounds-rect renderer-list x-min x-max y-min y-max) - (define given-bounds-rect (vector (ivl x-min x-max) (ivl y-min y-max))) - (define plot-bounds-rect (bounds-fixpoint renderer-list given-bounds-rect)) - (when (or (not (rect-rational? plot-bounds-rect)) - (rect-zero-area? plot-bounds-rect)) - (match-define (vector x-ivl y-ivl) plot-bounds-rect) - (error 'plot "could not determine sensible plot bounds; got x ∈ ~a, y ∈ ~a" - (ivl->plot-label x-ivl) (ivl->plot-label y-ivl))) - (rect-inexact->exact plot-bounds-rect)) - -(define (get-ticks renderer-list bounds-rect) - (define-values (all-x-ticks all-x-far-ticks all-y-ticks all-y-far-ticks) - (for/lists (all-x-ticks all-x-far-ticks all-y-ticks all-y-far-ticks - ) ([r (in-list renderer-list)]) - (define ticks-fun (plot-element-ticks-fun r)) - (cond [ticks-fun (ticks-fun bounds-rect)] - [else (values empty empty empty empty)]))) - (values (remove-duplicates (append* all-x-ticks)) - (remove-duplicates (append* all-x-far-ticks)) - (remove-duplicates (append* all-y-ticks)) - (remove-duplicates (append* all-y-far-ticks)))) - -(define (plot-dc renderer-list bounds-rect x-ticks x-far-ticks y-ticks y-far-ticks - dc x y width height) - (define area (make-object 2d-plot-area% - bounds-rect x-ticks x-far-ticks y-ticks y-far-ticks dc x y width height)) - (send area start-plot) - - (define legend-entries - (flatten (for/list ([rend (in-list renderer-list)]) - (match-define (renderer2d rend-bounds-rect _bf _tf render-proc) rend) - (send area start-renderer (if rend-bounds-rect - (rect-inexact->exact rend-bounds-rect) - (unknown-rect 2))) - (if render-proc (render-proc area) empty)))) - - (send area end-renderers) - - (when (not (empty? legend-entries)) - (send area draw-legend legend-entries)) - - (send area end-plot)) - -(defproc (plot/dc [renderer-tree (treeof (or/c renderer2d? nonrenderer?))] - [dc (is-a?/c dc<%>)] - [x real?] [y real?] [width (>=/c 0)] [height (>=/c 0)] - [#:x-min x-min (or/c rational? #f) #f] [#:x-max x-max (or/c rational? #f) #f] - [#:y-min y-min (or/c rational? #f) #f] [#:y-max y-max (or/c rational? #f) #f] - [#:title title (or/c string? #f) (plot-title)] - [#:x-label x-label (or/c string? #f) (plot-x-label)] - [#:y-label y-label (or/c string? #f) (plot-y-label)] - [#:legend-anchor legend-anchor anchor/c (plot-legend-anchor)]) void? - (define renderer-list (get-renderer-list renderer-tree)) - (define bounds-rect (get-bounds-rect renderer-list x-min x-max y-min y-max)) - (define-values (x-ticks x-far-ticks y-ticks y-far-ticks) - (get-ticks renderer-list bounds-rect)) - - (parameterize ([plot-title title] - [plot-x-label x-label] - [plot-y-label y-label] - [plot-legend-anchor legend-anchor]) - (plot-dc renderer-list bounds-rect x-ticks x-far-ticks y-ticks y-far-ticks - dc x y width height))) - -;; =================================================================================================== -;; Plot to various other backends - -;; Plot to a bitmap -(defproc (plot-bitmap [renderer-tree (treeof (or/c renderer2d? nonrenderer?))] - [#:x-min x-min (or/c rational? #f) #f] [#:x-max x-max (or/c rational? #f) #f] - [#:y-min y-min (or/c rational? #f) #f] [#:y-max y-max (or/c rational? #f) #f] - [#:width width exact-positive-integer? (plot-width)] - [#:height height exact-positive-integer? (plot-height)] - [#:title title (or/c string? #f) (plot-title)] - [#:x-label x-label (or/c string? #f) (plot-x-label)] - [#:y-label y-label (or/c string? #f) (plot-y-label)] - [#:legend-anchor legend-anchor anchor/c (plot-legend-anchor)] - ) (is-a?/c bitmap%) - (define renderer-list (get-renderer-list renderer-tree)) - (define bounds-rect (get-bounds-rect renderer-list x-min x-max y-min y-max)) - (define-values (x-ticks x-far-ticks y-ticks y-far-ticks) - (get-ticks renderer-list bounds-rect)) - ((if (plot-animating?) draw-bitmap draw-bitmap/supersampling) - (λ (dc) - (plot/dc renderer-tree dc 0 0 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)) - -(defproc (plot-pict [renderer-tree (treeof (or/c renderer2d? nonrenderer?))] - [#:x-min x-min (or/c rational? #f) #f] [#:x-max x-max (or/c rational? #f) #f] - [#:y-min y-min (or/c rational? #f) #f] [#:y-max y-max (or/c rational? #f) #f] - [#:width width exact-positive-integer? (plot-width)] - [#:height height exact-positive-integer? (plot-height)] - [#:title title (or/c string? #f) (plot-title)] - [#:x-label x-label (or/c string? #f) (plot-x-label)] - [#:y-label y-label (or/c string? #f) (plot-y-label)] - [#:legend-anchor legend-anchor anchor/c (plot-legend-anchor)] - ) pict? - (define saved-values (plot-parameters)) - (dc (λ (dc x y) - (parameterize/group - ([plot-parameters saved-values]) - (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 -(defproc (plot-snip [renderer-tree (treeof (or/c renderer2d? nonrenderer?))] - [#:x-min x-min (or/c rational? #f) #f] [#:x-max x-max (or/c rational? #f) #f] - [#:y-min y-min (or/c rational? #f) #f] [#:y-max y-max (or/c rational? #f) #f] - [#:width width exact-positive-integer? (plot-width)] - [#:height height exact-positive-integer? (plot-height)] - [#:title title (or/c string? #f) (plot-title)] - [#:x-label x-label (or/c string? #f) (plot-x-label)] - [#:y-label y-label (or/c string? #f) (plot-y-label)] - [#:legend-anchor legend-anchor anchor/c (plot-legend-anchor)] - ) (is-a?/c image-snip%) - (parameterize ([plot-title title] - [plot-x-label x-label] - [plot-y-label y-label] - [plot-legend-anchor legend-anchor]) - (define saved-plot-parameters (plot-parameters)) - (define renderer-list (get-renderer-list renderer-tree)) - (define bounds-rect (get-bounds-rect renderer-list x-min x-max y-min y-max)) - - (define (make-bm anim? bounds-rect width height) - (define area #f) - (define bm - (parameterize/group ([plot-parameters saved-plot-parameters] - [plot-animating? (if anim? #t (plot-animating?))]) - ((if (plot-animating?) draw-bitmap draw-bitmap/supersampling) - (λ (dc) - (define-values (x-ticks x-far-ticks y-ticks y-far-ticks) - (get-ticks renderer-list bounds-rect)) - (set! area (make-object 2d-plot-area% - bounds-rect x-ticks x-far-ticks y-ticks y-far-ticks - dc 0 0 width height)) - - (send area start-plot) - - (define legend-entries - (flatten (for/list ([rend (in-list renderer-list)]) - (match-define (renderer2d rend-bounds-rect _bf _tf render-proc) rend) - (send area start-renderer (if rend-bounds-rect - (rect-inexact->exact rend-bounds-rect) - (unknown-rect 2))) - (if render-proc (render-proc area) empty)))) - - (send area end-renderers) - - (when (not (empty? legend-entries)) - (send area draw-legend legend-entries)) - - (send area end-plot)) - width height))) - - (define (area-bounds->plot-bounds rect) - (match-define (vector (ivl area-x-min area-x-max) (ivl area-y-min area-y-max)) rect) - (match-define (vector x-min y-min) (send area dc->plot (vector area-x-min area-y-min))) - (match-define (vector x-max y-max) (send area dc->plot (vector area-x-max area-y-max))) - (vector (ivl x-min x-max) (ivl y-min y-max))) - - (values bm (send area get-area-bounds-rect) area-bounds->plot-bounds)) - - (define-values (bm area-bounds-rect area-bounds->plot-bounds) - (make-bm #f bounds-rect width height)) - - (make-2d-plot-snip - bm saved-plot-parameters - make-bm bounds-rect area-bounds-rect area-bounds->plot-bounds width height))) - -;; Plot to a frame -(defproc (plot-frame [renderer-tree (treeof (or/c renderer2d? nonrenderer?))] - [#:x-min x-min (or/c rational? #f) #f] [#:x-max x-max (or/c rational? #f) #f] - [#:y-min y-min (or/c rational? #f) #f] [#:y-max y-max (or/c rational? #f) #f] - [#:width width exact-positive-integer? (plot-width)] - [#:height height exact-positive-integer? (plot-height)] - [#:title title (or/c string? #f) (plot-title)] - [#:x-label x-label (or/c string? #f) (plot-x-label)] - [#:y-label y-label (or/c string? #f) (plot-y-label)] - [#:legend-anchor legend-anchor anchor/c (plot-legend-anchor)] - ) (is-a?/c object%) - (define snip - (plot-snip - renderer-tree - #:x-min x-min #:x-max x-max #:y-min y-min #:y-max y-max #:width width #:height height - #:title title #:x-label x-label #:y-label y-label #:legend-anchor legend-anchor)) - (make-snip-frame snip width height (if title (format "Plot: ~a" title) "Plot"))) - -;; Plot to a file -(defproc (plot-file [renderer-tree (treeof (or/c renderer2d? nonrenderer?))] - [output (or/c path-string? output-port?)] - [kind (one-of/c 'auto 'png 'jpeg 'xmb 'xpm 'bmp 'ps 'pdf 'svg) 'auto] - [#:x-min x-min (or/c rational? #f) #f] [#:x-max x-max (or/c rational? #f) #f] - [#:y-min y-min (or/c rational? #f) #f] [#:y-max y-max (or/c rational? #f) #f] - [#:width width exact-positive-integer? (plot-width)] - [#:height height exact-positive-integer? (plot-height)] - [#:title title (or/c string? #f) (plot-title)] - [#:x-label x-label (or/c string? #f) (plot-x-label)] - [#:y-label y-label (or/c string? #f) (plot-y-label)] - [#:legend-anchor legend-anchor anchor/c (plot-legend-anchor)]) void? - (define real-kind (if (eq? kind 'auto) (detect-image-file-type output) kind)) - (case real-kind - [(png jpeg xbm xpm bmp) - (define bm - (plot-bitmap - renderer-tree - #:x-min x-min #:x-max x-max #:y-min y-min #:y-max y-max #:width width #:height height - #:title title #:x-label x-label #:y-label y-label #:legend-anchor legend-anchor)) - (send bm save-file output real-kind (plot-jpeg-quality))] - [(ps pdf svg) - (define dc - (case real-kind - [(ps) (new post-script-dc% - [interactive (plot-ps/pdf-interactive?)] [parent #f] [use-paper-bbox #f] - [as-eps #t] [width width] [height height] [output output])] - [(pdf) (new pdf-dc% - [interactive (plot-ps/pdf-interactive?)] [parent #f] [use-paper-bbox #f] - [width width] [height height] [output output])] - [(svg) (new svg-dc% - [width width] [height height] [output output] [exists 'truncate/replace])])) - (define-values (x-scale y-scale) (send dc get-device-scale)) - (send dc start-doc "Rendering plot") - (send dc start-page) - (plot/dc renderer-tree dc 0 0 - (inexact->exact (/ width x-scale)) (inexact->exact (/ height y-scale)) - #: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) - (send dc end-page) - (send dc end-doc)]) - (void)) - -;; Plot to a frame or a snip, depending on (plot-new-window?) -(defproc (plot [renderer-tree (treeof (or/c renderer2d? nonrenderer?))] - [#:x-min x-min (or/c rational? #f) #f] [#:x-max x-max (or/c rational? #f) #f] - [#:y-min y-min (or/c rational? #f) #f] [#:y-max y-max (or/c rational? #f) #f] - [#:width width exact-positive-integer? (plot-width)] - [#:height height exact-positive-integer? (plot-height)] - [#:title title (or/c string? #f) (plot-title)] - [#:x-label x-label (or/c string? #f) (plot-x-label)] - [#:y-label y-label (or/c string? #f) (plot-y-label)] - [#:legend-anchor legend-anchor anchor/c (plot-legend-anchor)] - [#:out-file out-file (or/c path-string? output-port? #f) #f] - [#:out-kind out-kind (one-of/c 'auto 'png 'jpeg 'xmb 'xpm 'bmp 'ps 'pdf 'svg) 'auto] - [#:fgcolor fgcolor plot-color/c #f] [#:bgcolor bgcolor plot-color/c #f] - [#:lncolor lncolor plot-color/c #f] ; unused - ) (or/c (is-a?/c snip%) void?) - (when fgcolor - (deprecation-warning "the plot #:fgcolor keyword argument" "plot-foreground")) - (when bgcolor - (deprecation-warning "the plot #:bgcolor keyword argument" "plot-background")) - (when lncolor - (deprecation-warning "the plot #:lncolor keyword argument")) - - (define (call f . args) - (apply f renderer-tree args - #:x-min x-min #:x-max x-max #:y-min y-min #:y-max y-max #:width width #:height height - #:title title #:x-label x-label #:y-label y-label #:legend-anchor legend-anchor)) - - (parameterize ([plot-foreground (if fgcolor fgcolor (plot-foreground))] - [plot-background (if bgcolor bgcolor (plot-background))]) - (when out-file - (call plot-file out-file out-kind)) - - (cond [(plot-new-window?) (define frame (with-new-eventspace (λ () (call plot-frame)))) - (send frame show #t) - (void)] - [else (call plot-snip)]))) diff --git a/pkgs/plot/plot3d/plot.rkt b/pkgs/plot/plot3d/plot.rkt deleted file mode 100644 index 1db0d9d0e1..0000000000 --- a/pkgs/plot/plot3d/plot.rkt +++ /dev/null @@ -1,352 +0,0 @@ -#lang racket/base - -;; Procedures that plot 3D renderers. - -(require racket/draw racket/snip racket/match racket/list racket/class racket/contract - unstable/contract - pict - unstable/parameter-group - racket/lazy-require - unstable/latent-contract/defthing - "../common/contract.rkt" - "../common/math.rkt" - "../common/draw.rkt" - "../common/parameters.rkt" - "../common/plot-element.rkt" - "../common/file-type.rkt" - "../common/deprecation-warning.rkt" - "../common/format.rkt" - "plot-area.rkt") - -;; Require lazily: without this, Racket complains while generating documentation: -;; cannot instantiate `racket/gui/base' a second time in the same process -(lazy-require ["snip.rkt" (make-3d-plot-snip)] - ["../common/gui.rkt" (make-snip-frame with-new-eventspace)]) - -(provide (except-out (all-defined-out) get-renderer-list get-bounds-rect get-ticks plot3d-dc)) - -;; =================================================================================================== -;; Plot to a given device context - -(define (get-renderer-list renderer-tree) - (for/list ([r (flatten (list renderer-tree))]) - (match r - [(nonrenderer bounds-rect bounds-fun ticks-fun) - (renderer3d bounds-rect bounds-fun ticks-fun #f)] - [_ r]))) - -(define (get-bounds-rect renderer-list x-min x-max y-min y-max z-min z-max) - (define given-bounds-rect (vector (ivl x-min x-max) (ivl y-min y-max) (ivl z-min z-max))) - (define plot-bounds-rect (bounds-fixpoint renderer-list given-bounds-rect)) - (when (or (not (rect-rational? plot-bounds-rect)) - (rect-zero-area? plot-bounds-rect)) - (match-define (vector x-ivl y-ivl z-ivl) plot-bounds-rect) - (error 'plot "could not determine sensible plot bounds; got x ∈ ~a, y ∈ ~a, z ∈ ~a" - (ivl->plot-label x-ivl) (ivl->plot-label y-ivl) (ivl->plot-label z-ivl))) - (rect-inexact->exact plot-bounds-rect)) - -(define (get-ticks renderer-list bounds-rect) - (define-values (all-x-ticks all-x-far-ticks all-y-ticks all-y-far-ticks all-z-ticks all-z-far-ticks) - (for/lists (all-x-ticks - all-x-far-ticks - all-y-ticks - all-y-far-ticks - all-z-ticks - all-z-far-ticks) ([r (in-list renderer-list)]) - (define ticks-fun (plot-element-ticks-fun r)) - (cond [ticks-fun (ticks-fun bounds-rect)] - [else (values empty empty empty empty empty empty)]))) - (values (remove-duplicates (append* all-x-ticks)) - (remove-duplicates (append* all-x-far-ticks)) - (remove-duplicates (append* all-y-ticks)) - (remove-duplicates (append* all-y-far-ticks)) - (remove-duplicates (append* all-z-ticks)) - (remove-duplicates (append* all-z-far-ticks)))) - -(define (plot3d-dc renderer-list bounds-rect - x-ticks x-far-ticks y-ticks y-far-ticks z-ticks z-far-ticks - dc x y width height) - (define area (make-object 3d-plot-area% - bounds-rect x-ticks x-far-ticks y-ticks y-far-ticks z-ticks z-far-ticks - dc x y width height)) - (send area start-plot) - - (define legend-entries - (flatten (for/list ([rend (in-list renderer-list)]) - (match-define (renderer3d rend-bounds-rect _bf _tf render-proc) rend) - (send area start-renderer (if rend-bounds-rect - (rect-inexact->exact rend-bounds-rect) - (unknown-rect 3))) - (if render-proc (render-proc area) empty)))) - - (send area end-renderers) - - (when (not (empty? legend-entries)) - (send area draw-legend legend-entries)) - - (send area end-plot)) - - -(defproc (plot3d/dc [renderer-tree (treeof (or/c renderer3d? nonrenderer?))] - [dc (is-a?/c dc<%>)] - [x real?] [y real?] [width (>=/c 0)] [height (>=/c 0)] - [#:x-min x-min (or/c rational? #f) #f] [#:x-max x-max (or/c rational? #f) #f] - [#:y-min y-min (or/c rational? #f) #f] [#:y-max y-max (or/c rational? #f) #f] - [#:z-min z-min (or/c rational? #f) #f] [#:z-max z-max (or/c rational? #f) #f] - [#:angle angle real? (plot3d-angle)] [#:altitude altitude real? (plot3d-altitude)] - [#:title title (or/c string? #f) (plot-title)] - [#:x-label x-label (or/c string? #f) (plot-x-label)] - [#:y-label y-label (or/c string? #f) (plot-y-label)] - [#:z-label z-label (or/c string? #f) (plot-z-label)] - [#:legend-anchor legend-anchor anchor/c (plot-legend-anchor)]) void? - (define renderer-list (get-renderer-list renderer-tree)) - (define bounds-rect (get-bounds-rect renderer-list x-min x-max y-min y-max z-min z-max)) - (define-values (x-ticks x-far-ticks y-ticks y-far-ticks z-ticks z-far-ticks) - (get-ticks renderer-list bounds-rect)) - - (parameterize ([plot3d-angle angle] - [plot3d-altitude altitude] - [plot-title title] - [plot-x-label x-label] - [plot-y-label y-label] - [plot-z-label z-label] - [plot-legend-anchor legend-anchor]) - (plot3d-dc renderer-list bounds-rect - x-ticks x-far-ticks y-ticks y-far-ticks z-ticks z-far-ticks - dc x y width height))) - -;; =================================================================================================== -;; Plot to various other backends - -;; Plot to a bitmap -(defproc (plot3d-bitmap [renderer-tree (treeof (or/c renderer3d? nonrenderer?))] - [#:x-min x-min (or/c rational? #f) #f] [#:x-max x-max (or/c rational? #f) #f] - [#:y-min y-min (or/c rational? #f) #f] [#:y-max y-max (or/c rational? #f) #f] - [#:z-min z-min (or/c rational? #f) #f] [#:z-max z-max (or/c rational? #f) #f] - [#:width width exact-positive-integer? (plot-width)] - [#:height height exact-positive-integer? (plot-height)] - [#:angle angle real? (plot3d-angle)] - [#:altitude altitude real? (plot3d-altitude)] - [#:title title (or/c string? #f) (plot-title)] - [#:x-label x-label (or/c string? #f) (plot-x-label)] - [#:y-label y-label (or/c string? #f) (plot-y-label)] - [#:z-label z-label (or/c string? #f) (plot-z-label)] - [#:legend-anchor legend-anchor anchor/c (plot-legend-anchor)] - ) (is-a?/c bitmap%) - ((if (plot-animating?) draw-bitmap draw-bitmap/supersampling) - (λ (dc) - (plot3d/dc renderer-tree dc 0 0 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)) - -(defproc (plot3d-pict [renderer-tree (treeof (or/c renderer3d? nonrenderer?))] - [#:x-min x-min (or/c rational? #f) #f] [#:x-max x-max (or/c rational? #f) #f] - [#:y-min y-min (or/c rational? #f) #f] [#:y-max y-max (or/c rational? #f) #f] - [#:z-min z-min (or/c rational? #f) #f] [#:z-max z-max (or/c rational? #f) #f] - [#:width width exact-positive-integer? (plot-width)] - [#:height height exact-positive-integer? (plot-height)] - [#:angle angle real? (plot3d-angle)] - [#:altitude altitude real? (plot3d-altitude)] - [#:title title (or/c string? #f) (plot-title)] - [#:x-label x-label (or/c string? #f) (plot-x-label)] - [#:y-label y-label (or/c string? #f) (plot-y-label)] - [#:z-label z-label (or/c string? #f) (plot-z-label)] - [#:legend-anchor legend-anchor anchor/c (plot-legend-anchor)] - ) pict? - (define saved-plot-parameters (plot-parameters)) - (dc (λ (dc x y) - (parameterize/group ([plot-parameters saved-plot-parameters]) - (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 -(defproc (plot3d-snip [renderer-tree (treeof (or/c renderer3d? nonrenderer?))] - [#:x-min x-min (or/c rational? #f) #f] [#:x-max x-max (or/c rational? #f) #f] - [#:y-min y-min (or/c rational? #f) #f] [#:y-max y-max (or/c rational? #f) #f] - [#:z-min z-min (or/c rational? #f) #f] [#:z-max z-max (or/c rational? #f) #f] - [#:width width exact-positive-integer? (plot-width)] - [#:height height exact-positive-integer? (plot-height)] - [#:angle angle real? (plot3d-angle)] - [#:altitude altitude real? (plot3d-altitude)] - [#:title title (or/c string? #f) (plot-title)] - [#:x-label x-label (or/c string? #f) (plot-x-label)] - [#:y-label y-label (or/c string? #f) (plot-y-label)] - [#:z-label z-label (or/c string? #f) (plot-z-label)] - [#:legend-anchor legend-anchor anchor/c (plot-legend-anchor)] - ) (is-a?/c image-snip%) - (parameterize ([plot-title title] - [plot-x-label x-label] - [plot-y-label y-label] - [plot-z-label z-label] - [plot-legend-anchor legend-anchor]) - (define saved-plot-parameters (plot-parameters)) - (define renderer-list (get-renderer-list renderer-tree)) - (define bounds-rect (get-bounds-rect renderer-list x-min x-max y-min y-max z-min z-max)) - (define-values (x-ticks x-far-ticks y-ticks y-far-ticks z-ticks z-far-ticks) - (get-ticks renderer-list bounds-rect)) - - (define render-list-hash (make-hash)) - (define legend-entries-hash (make-hash)) - - (define (make-bm anim? angle altitude width height) - (parameterize/group ([plot-parameters saved-plot-parameters] - [plot-animating? (if anim? #t (plot-animating?))] - [plot3d-angle angle] - [plot3d-altitude altitude]) - ((if (plot-animating?) draw-bitmap draw-bitmap/supersampling) - (λ (dc) - (define area (make-object 3d-plot-area% - bounds-rect x-ticks x-far-ticks y-ticks y-far-ticks z-ticks z-far-ticks - dc 0 0 width height)) - (send area start-plot) - - (cond [(not (hash-ref render-list-hash (plot-animating?) #f)) - (hash-set! - legend-entries-hash (plot-animating?) - (flatten (for/list ([rend (in-list renderer-list)]) - (match-define (renderer3d rend-bounds-rect _bf _tf render-proc) rend) - (send area start-renderer (if rend-bounds-rect - (rect-inexact->exact rend-bounds-rect) - (unknown-rect 3))) - (if render-proc (render-proc area) empty)))) - - (hash-set! render-list-hash (plot-animating?) (send area get-render-list))] - [else - (send area put-render-list (hash-ref render-list-hash (plot-animating?)))]) - - (send area end-renderers) - - (define legend-entries (hash-ref legend-entries-hash (plot-animating?) #f)) - (when (not (empty? legend-entries)) - (send area draw-legend legend-entries)) - - (send area end-plot)) - width height))) - - (make-3d-plot-snip - (make-bm #f angle altitude width height) saved-plot-parameters - make-bm angle altitude width height))) - -;; Plot to a frame -(defproc (plot3d-frame [renderer-tree (treeof (or/c renderer3d? nonrenderer?))] - [#:x-min x-min (or/c rational? #f) #f] [#:x-max x-max (or/c rational? #f) #f] - [#:y-min y-min (or/c rational? #f) #f] [#:y-max y-max (or/c rational? #f) #f] - [#:z-min z-min (or/c rational? #f) #f] [#:z-max z-max (or/c rational? #f) #f] - [#:width width exact-positive-integer? (plot-width)] - [#:height height exact-positive-integer? (plot-height)] - [#:angle angle real? (plot3d-angle)] - [#:altitude altitude real? (plot3d-altitude)] - [#:title title (or/c string? #f) (plot-title)] - [#:x-label x-label (or/c string? #f) (plot-x-label)] - [#:y-label y-label (or/c string? #f) (plot-y-label)] - [#:z-label z-label (or/c string? #f) (plot-z-label)] - [#:legend-anchor legend-anchor anchor/c (plot-legend-anchor)] - ) (is-a?/c object%) - (define snip - (plot3d-snip - renderer-tree - #:x-min x-min #:x-max x-max #:y-min y-min #:y-max y-max #:z-min z-min #:z-max z-max - #:width width #:height height #:angle angle #:altitude altitude #:title title - #:x-label x-label #:y-label y-label #:z-label z-label #:legend-anchor legend-anchor)) - (make-snip-frame snip width height (if title (format "Plot: ~a" title) "Plot"))) - -;; Plot to any supported kind of file -(defproc (plot3d-file [renderer-tree (treeof (or/c renderer3d? nonrenderer?))] - [output (or/c path-string? output-port?)] - [kind (one-of/c 'auto 'png 'jpeg 'xmb 'xpm 'bmp 'ps 'pdf 'svg) 'auto] - [#:x-min x-min (or/c rational? #f) #f] [#:x-max x-max (or/c rational? #f) #f] - [#:y-min y-min (or/c rational? #f) #f] [#:y-max y-max (or/c rational? #f) #f] - [#:z-min z-min (or/c rational? #f) #f] [#:z-max z-max (or/c rational? #f) #f] - [#:width width exact-positive-integer? (plot-width)] - [#:height height exact-positive-integer? (plot-height)] - [#:angle angle real? (plot3d-angle)] - [#:altitude altitude real? (plot3d-altitude)] - [#:title title (or/c string? #f) (plot-title)] - [#:x-label x-label (or/c string? #f) (plot-x-label)] - [#:y-label y-label (or/c string? #f) (plot-y-label)] - [#:z-label z-label (or/c string? #f) (plot-z-label)] - [#:legend-anchor legend-anchor anchor/c (plot-legend-anchor)]) void? - (define real-kind (if (eq? kind 'auto) (detect-image-file-type output) kind)) - (case real-kind - [(png jpeg xbm xpm bmp) - (define bm - (plot3d-bitmap - renderer-tree - #:x-min x-min #:x-max x-max #:y-min y-min #:y-max y-max #:z-min z-min #:z-max z-max - #:width width #:height height #:angle angle #:altitude altitude #:title title - #:x-label x-label #:y-label y-label #:z-label z-label #:legend-anchor legend-anchor)) - (send bm save-file output real-kind (plot-jpeg-quality))] - [(ps pdf svg) - (define dc - (case real-kind - [(ps) (new post-script-dc% - [interactive (plot-ps/pdf-interactive?)] [parent #f] [use-paper-bbox #f] - [as-eps #t] [width width] [height height] [output output])] - [(pdf) (new pdf-dc% - [interactive (plot-ps/pdf-interactive?)] [parent #f] [use-paper-bbox #f] - [width width] [height height] [output output])] - [(svg) (new svg-dc% - [width width] [height height] [output output] [exists 'truncate/replace])])) - (define-values (x-scale y-scale) (send dc get-device-scale)) - (send dc start-doc "Rendering plot") - (send dc start-page) - (plot3d/dc renderer-tree dc 0 0 - (inexact->exact (/ width x-scale)) (inexact->exact (/ height y-scale)) - #: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) - (send dc end-page) - (send dc end-doc)]) - (void)) - -;; Plot to a frame or a snip, depending on the value of plot-new-window? -(defproc (plot3d [renderer-tree (treeof (or/c renderer3d? nonrenderer?))] - [#:x-min x-min (or/c rational? #f) #f] [#:x-max x-max (or/c rational? #f) #f] - [#:y-min y-min (or/c rational? #f) #f] [#:y-max y-max (or/c rational? #f) #f] - [#:z-min z-min (or/c rational? #f) #f] [#:z-max z-max (or/c rational? #f) #f] - [#:width width exact-positive-integer? (plot-width)] - [#:height height exact-positive-integer? (plot-height)] - [#:angle angle real? #f] [#:altitude altitude real? #f] - [#:az az real? #f] [#:alt alt real? #f] ; backward-compatible aliases - [#:title title (or/c string? #f) (plot-title)] - [#:x-label x-label (or/c string? #f) (plot-x-label)] - [#:y-label y-label (or/c string? #f) (plot-y-label)] - [#:z-label z-label (or/c string? #f) (plot-z-label)] - [#:legend-anchor legend-anchor anchor/c (plot-legend-anchor)] - [#:out-file out-file (or/c path-string? output-port? #f) #f] - [#:out-kind out-kind (one-of/c 'auto 'png 'jpeg 'xmb 'xpm 'bmp 'ps 'pdf 'svg) 'auto] - [#:fgcolor fgcolor plot-color/c #f] [#:bgcolor bgcolor plot-color/c #f] - [#:lncolor lncolor plot-color/c #f] ; unused - ) (or/c (is-a?/c snip%) void?) - (when fgcolor - (deprecation-warning "the plot3d #:fgcolor keyword argument" "plot-foreground")) - (when bgcolor - (deprecation-warning "the plot3d #:bgcolor keyword argument" "plot-background")) - (when lncolor - (deprecation-warning "the plot3d #:lncolor keyword argument")) - (when az - (deprecation-warning "the plot3d #:az keyword argument" "#:angle")) - (when alt - (deprecation-warning "the plot3d #:alt keyword argument" "#:altitude")) - - (define (call f . args) - (apply f renderer-tree args - #:x-min x-min #:x-max x-max #:y-min y-min #:y-max y-max #:z-min z-min #:z-max z-max - #:width width #:height height #:title title - #:angle (or angle az (plot3d-angle)) #:altitude (or altitude alt (plot3d-altitude)) - #:x-label x-label #:y-label y-label #:z-label z-label #:legend-anchor legend-anchor)) - - (parameterize ([plot-foreground (if fgcolor fgcolor (plot-foreground))] - [plot-background (if bgcolor bgcolor (plot-background))]) - (when out-file - (call plot3d-file out-file out-kind)) - - (cond [(plot-new-window?) (define frame (with-new-eventspace (λ () (call plot3d-frame)))) - (send frame show #t) - (void)] - [else (call plot3d-snip)]))) diff --git a/pkgs/plot/common/axis-transform.rkt b/pkgs/plot/private/common/axis-transform.rkt similarity index 100% rename from pkgs/plot/common/axis-transform.rkt rename to pkgs/plot/private/common/axis-transform.rkt diff --git a/pkgs/plot/common/contract.rkt b/pkgs/plot/private/common/contract.rkt similarity index 100% rename from pkgs/plot/common/contract.rkt rename to pkgs/plot/private/common/contract.rkt diff --git a/pkgs/plot/common/currency.rkt b/pkgs/plot/private/common/currency.rkt similarity index 100% rename from pkgs/plot/common/currency.rkt rename to pkgs/plot/private/common/currency.rkt diff --git a/pkgs/plot/common/date-time.rkt b/pkgs/plot/private/common/date-time.rkt similarity index 100% rename from pkgs/plot/common/date-time.rkt rename to pkgs/plot/private/common/date-time.rkt diff --git a/pkgs/plot/common/deprecation-warning.rkt b/pkgs/plot/private/common/deprecation-warning.rkt similarity index 100% rename from pkgs/plot/common/deprecation-warning.rkt rename to pkgs/plot/private/common/deprecation-warning.rkt diff --git a/pkgs/plot/common/draw.rkt b/pkgs/plot/private/common/draw.rkt similarity index 100% rename from pkgs/plot/common/draw.rkt rename to pkgs/plot/private/common/draw.rkt diff --git a/pkgs/plot/common/file-type.rkt b/pkgs/plot/private/common/file-type.rkt similarity index 100% rename from pkgs/plot/common/file-type.rkt rename to pkgs/plot/private/common/file-type.rkt diff --git a/pkgs/plot/common/format.rkt b/pkgs/plot/private/common/format.rkt similarity index 100% rename from pkgs/plot/common/format.rkt rename to pkgs/plot/private/common/format.rkt diff --git a/pkgs/plot/common/kde.rkt b/pkgs/plot/private/common/kde.rkt similarity index 100% rename from pkgs/plot/common/kde.rkt rename to pkgs/plot/private/common/kde.rkt diff --git a/pkgs/plot/common/legend.rkt b/pkgs/plot/private/common/legend.rkt similarity index 100% rename from pkgs/plot/common/legend.rkt rename to pkgs/plot/private/common/legend.rkt diff --git a/pkgs/plot/common/marching-cubes.rkt b/pkgs/plot/private/common/marching-cubes.rkt similarity index 100% rename from pkgs/plot/common/marching-cubes.rkt rename to pkgs/plot/private/common/marching-cubes.rkt diff --git a/pkgs/plot/common/marching-squares.rkt b/pkgs/plot/private/common/marching-squares.rkt similarity index 100% rename from pkgs/plot/common/marching-squares.rkt rename to pkgs/plot/private/common/marching-squares.rkt diff --git a/pkgs/plot/common/marching-utils.rkt b/pkgs/plot/private/common/marching-utils.rkt similarity index 100% rename from pkgs/plot/common/marching-utils.rkt rename to pkgs/plot/private/common/marching-utils.rkt diff --git a/pkgs/plot/common/math.rkt b/pkgs/plot/private/common/math.rkt similarity index 100% rename from pkgs/plot/common/math.rkt rename to pkgs/plot/private/common/math.rkt diff --git a/pkgs/plot/common/nonrenderer.rkt b/pkgs/plot/private/common/nonrenderer.rkt similarity index 100% rename from pkgs/plot/common/nonrenderer.rkt rename to pkgs/plot/private/common/nonrenderer.rkt diff --git a/pkgs/plot/common/parameters.rkt b/pkgs/plot/private/common/parameters.rkt similarity index 100% rename from pkgs/plot/common/parameters.rkt rename to pkgs/plot/private/common/parameters.rkt diff --git a/pkgs/plot/common/plot-device.rkt b/pkgs/plot/private/common/plot-device.rkt similarity index 100% rename from pkgs/plot/common/plot-device.rkt rename to pkgs/plot/private/common/plot-device.rkt diff --git a/pkgs/plot/common/plot-element.rkt b/pkgs/plot/private/common/plot-element.rkt similarity index 100% rename from pkgs/plot/common/plot-element.rkt rename to pkgs/plot/private/common/plot-element.rkt diff --git a/pkgs/plot/common/sample.rkt b/pkgs/plot/private/common/sample.rkt similarity index 100% rename from pkgs/plot/common/sample.rkt rename to pkgs/plot/private/common/sample.rkt diff --git a/pkgs/plot/common/samplers.rkt b/pkgs/plot/private/common/samplers.rkt similarity index 100% rename from pkgs/plot/common/samplers.rkt rename to pkgs/plot/private/common/samplers.rkt diff --git a/pkgs/plot/common/ticks.rkt b/pkgs/plot/private/common/ticks.rkt similarity index 100% rename from pkgs/plot/common/ticks.rkt rename to pkgs/plot/private/common/ticks.rkt diff --git a/pkgs/plot/common/utils.rkt b/pkgs/plot/private/common/utils.rkt similarity index 100% rename from pkgs/plot/common/utils.rkt rename to pkgs/plot/private/common/utils.rkt diff --git a/pkgs/plot/common/worker-thread.rkt b/pkgs/plot/private/common/worker-thread.rkt similarity index 100% rename from pkgs/plot/common/worker-thread.rkt rename to pkgs/plot/private/common/worker-thread.rkt diff --git a/pkgs/plot/private/compat.rkt b/pkgs/plot/private/compat.rkt new file mode 100644 index 0000000000..63766d7e6f --- /dev/null +++ b/pkgs/plot/private/compat.rkt @@ -0,0 +1,199 @@ +#lang racket/base + +;; A compatibility module for the old 'plot'. + +(require racket/contract racket/class racket/snip racket/draw racket/vector + unstable/latent-contract unstable/latent-contract/defthing + ;; Plotting + "common/math.rkt" + "common/contract.rkt" + "common/plot-element.rkt" + "plot2d/plot-area.rkt" + "plot3d/plot-area.rkt" + (prefix-in new. (only-in plot + x-axis y-axis + plot-x-ticks plot-y-ticks plot-z-ticks + points error-bars vector-field + plot-title plot-x-label plot-y-label plot-z-label + plot-foreground plot-background + plot3d-angle plot3d-altitude)) + "deprecated/renderers.rkt" + ;; Miscellaneous + "deprecated/math.rkt") + +(provide mix + (activate-contract-out plot-color? + plot plot3d + points vector-field error-bars + line + contour shade + surface) + (only-doc-out (all-defined-out)) + ;; Miscellaneous + make-vec derivative gradient) + +(define (mix . data) + (for/fold ([f (λ (area) (void))]) ([d (in-list data)]) + (λ (area) + (f area) + (d area) + (void)))) + +(defproc (plot-color? [v any/c]) boolean? + (and (member v '(white black yellow green aqua pink wheat gray brown blue violet cyan + turquoise magenta salmon red)) + #t)) + +(define ((renderer2d->plot-data r) area) + ((renderer2d-render-proc r) area) + (void)) + +(define ((renderer3d->plot-data r) area) + ((renderer3d-render-proc r) area) + (void)) + +;; =================================================================================================== +;; Plotting + +(define x-axis-data (renderer2d->plot-data (new.x-axis))) +(define y-axis-data (renderer2d->plot-data (new.y-axis))) + +(defproc (plot [data ((is-a?/c 2d-plot-area%) . -> . void?)] + [#:width width real? 400] [#:height height real? 400] + [#:x-min x-min real? -5] [#:x-max x-max real? 5] + [#:y-min y-min real? -5] [#:y-max y-max real? 5] + [#:x-label x-label string? "X axis"] [#:y-label y-label string? "Y axis"] + [#:title title string? ""] + [#:fgcolor fgcolor (list/c byte? byte? byte?) '(0 0 0)] + [#:bgcolor bgcolor (list/c byte? byte? byte?) '(255 255 255)] + [#:lncolor lncolor (list/c byte? byte? byte?) '(255 0 0)] + [#:out-file out-file (or/c path-string? output-port? #f) #f] + ) (is-a?/c image-snip%) + (define x-ticks ((new.plot-x-ticks) x-min x-max)) + (define y-ticks ((new.plot-y-ticks) y-min y-max)) + (define bounds-rect (vector (ivl x-min x-max) (ivl y-min y-max))) + + (parameterize ([new.plot-title title] + [new.plot-x-label x-label] + [new.plot-y-label y-label] + [new.plot-foreground fgcolor] + [new.plot-background bgcolor]) + (define bm (make-bitmap (ceiling width) (ceiling height))) + (define dc (make-object bitmap-dc% bm)) + (define area (make-object 2d-plot-area% + bounds-rect x-ticks x-ticks y-ticks y-ticks dc 0 0 width height)) + + (define data+axes (mix x-axis-data y-axis-data data)) + + (send area start-plot) + (send area start-renderer bounds-rect) + (data+axes area) + (send area end-renderers) + (send area end-plot) + + (when out-file (send bm save-file out-file 'png)) + + (make-object image-snip% bm))) + +(defproc (plot3d [data ((is-a?/c 3d-plot-area%) . -> . void?)] + [#:width width real? 400] [#:height height real? 400] + [#:x-min x-min real? -5] [#:x-max x-max real? 5] + [#:y-min y-min real? -5] [#:y-max y-max real? 5] + [#:z-min z-min real? -5] [#:z-max z-max real? 5] + [#:alt alt real? 30] + [#:az az real? 45] + [#:x-label x-label string? "X axis"] + [#:y-label y-label string? "Y axis"] + [#:z-label z-label string? "Z axis"] + [#:title title string? ""] + [#:fgcolor fgcolor (list/c byte? byte? byte?) '(0 0 0)] + [#:bgcolor bgcolor (list/c byte? byte? byte?) '(255 255 255)] + [#:lncolor lncolor (list/c byte? byte? byte?) '(255 0 0)] + [#:out-file out-file (or/c path-string? output-port? #f) #f] + ) (is-a?/c image-snip%) + (define x-ticks ((new.plot-x-ticks) x-min x-max)) + (define y-ticks ((new.plot-y-ticks) y-min y-max)) + (define z-ticks ((new.plot-z-ticks) z-min z-max)) + (define bounds-rect (vector (ivl x-min x-max) (ivl y-min y-max) (ivl z-min z-max))) + + (parameterize ([new.plot-title title] + [new.plot-x-label x-label] + [new.plot-y-label y-label] + [new.plot-z-label z-label] + [new.plot-foreground fgcolor] + [new.plot-background bgcolor] + [new.plot3d-angle az] + [new.plot3d-altitude alt]) + (define bm (make-bitmap (ceiling width) (ceiling height))) + (define dc (make-object bitmap-dc% bm)) + (define area (make-object 3d-plot-area% + bounds-rect x-ticks x-ticks y-ticks y-ticks z-ticks z-ticks dc 0 0 width height)) + + (send area start-plot) + (send area start-renderer bounds-rect) + (data area) + (send area end-renderers) + (send area end-plot) + + (when out-file (send bm save-file out-file 'png)) + + (make-object image-snip% bm))) + +;; =================================================================================================== +;; Functions that generate "plot data" + +(defproc (points [vecs (listof (vectorof real?))] + [#:sym sym (or/c char? string? exact-integer? symbol?) 'square] + [#:color color plot-color? 'black] + ) ((is-a?/c 2d-plot-area%) . -> . void?) + (renderer2d->plot-data (new.points (map (λ (v) (vector-take v 2)) vecs) + #:sym sym #:size 6 #:color color))) + +(defproc (vector-field [f ((vector/c real? real?) . -> . (vector/c real? real?))] + [#:samples samples (and/c exact-integer? (>=/c 2)) 20] + [#:width width exact-positive-integer? 1] + [#:color color plot-color? 'red] + [#:style style (one-of/c 'scaled 'normalized 'real) 'scaled] + ) ((is-a?/c 2d-plot-area%) . -> . void?) + (define scale (case style + [(scaled) 'auto] + [(normalized) 'normalized] + [(real) 1.0])) + (renderer2d->plot-data + (new.vector-field f #:samples samples #:line-width width #:color color #:scale scale))) + +(defproc (error-bars [vecs (listof (vector/c real? real? real?))] + [#:color color plot-color? 'black] + ) ((is-a?/c 2d-plot-area%) . -> . void?) + (renderer2d->plot-data (new.error-bars vecs #:color color #:alpha 1 #:width 4))) + +(defproc (line [f (real? . -> . (or/c real? (vector/c real? real?)))] + [#:samples samples (and/c exact-integer? (>=/c 2)) 150] + [#:width width (>=/c 0) 1] + [#:color color plot-color/c 'red] + [#:mode mode (one-of/c 'standard 'parametric) 'standard] + [#:mapping mapping (one-of/c 'cartesian 'polar) 'cartesian] + [#:t-min t-min real? -5] [#:t-max t-max real? 5] + ) ((is-a?/c 2d-plot-area%) . -> . void?) + (renderer2d->plot-data (line-renderer f samples width color mode mapping t-min t-max))) + +(defproc (contour [f (real? real? . -> . real?)] + [#:samples samples exact-nonnegative-integer? 50] + [#:width width (>=/c 0) 1] + [#:color color plot-color/c 'black] + [#:levels levels (or/c (and/c exact-integer? (>=/c 2)) (listof real?)) 10] + ) ((is-a?/c 2d-plot-area%) . -> . void?) + (renderer2d->plot-data (contour-renderer f samples width color levels))) + +(defproc (shade [f (real? real? . -> . real?)] + [#:samples samples (and/c exact-integer? (>=/c 2)) 50] + [#:levels levels (or/c (and/c exact-integer? (>=/c 2)) (listof real?)) 10] + ) ((is-a?/c 2d-plot-area%) . -> . void?) + (renderer2d->plot-data (shade-renderer f samples levels))) + +(defproc (surface [f (real? real? . -> . real?)] + [#:samples samples (and/c exact-integer? (>=/c 2)) 50] + [#:width width (>=/c 0) 1] + [#:color color plot-color/c 'black] + ) ((is-a?/c 3d-plot-area%) . -> . void?) + (renderer3d->plot-data (surface-renderer f samples width color))) diff --git a/pkgs/plot/contracted/axis-transform.rkt b/pkgs/plot/private/contracted/axis-transform.rkt similarity index 100% rename from pkgs/plot/contracted/axis-transform.rkt rename to pkgs/plot/private/contracted/axis-transform.rkt diff --git a/pkgs/plot/contracted/date-time.rkt b/pkgs/plot/private/contracted/date-time.rkt similarity index 100% rename from pkgs/plot/contracted/date-time.rkt rename to pkgs/plot/private/contracted/date-time.rkt diff --git a/pkgs/plot/contracted/draw.rkt b/pkgs/plot/private/contracted/draw.rkt similarity index 100% rename from pkgs/plot/contracted/draw.rkt rename to pkgs/plot/private/contracted/draw.rkt diff --git a/pkgs/plot/contracted/format.rkt b/pkgs/plot/private/contracted/format.rkt similarity index 100% rename from pkgs/plot/contracted/format.rkt rename to pkgs/plot/private/contracted/format.rkt diff --git a/pkgs/plot/contracted/kde.rkt b/pkgs/plot/private/contracted/kde.rkt similarity index 100% rename from pkgs/plot/contracted/kde.rkt rename to pkgs/plot/private/contracted/kde.rkt diff --git a/pkgs/plot/contracted/legend.rkt b/pkgs/plot/private/contracted/legend.rkt similarity index 100% rename from pkgs/plot/contracted/legend.rkt rename to pkgs/plot/private/contracted/legend.rkt diff --git a/pkgs/plot/contracted/math.rkt b/pkgs/plot/private/contracted/math.rkt similarity index 100% rename from pkgs/plot/contracted/math.rkt rename to pkgs/plot/private/contracted/math.rkt diff --git a/pkgs/plot/contracted/parameters.rkt b/pkgs/plot/private/contracted/parameters.rkt similarity index 100% rename from pkgs/plot/contracted/parameters.rkt rename to pkgs/plot/private/contracted/parameters.rkt diff --git a/pkgs/plot/contracted/plot-element.rkt b/pkgs/plot/private/contracted/plot-element.rkt similarity index 100% rename from pkgs/plot/contracted/plot-element.rkt rename to pkgs/plot/private/contracted/plot-element.rkt diff --git a/pkgs/plot/contracted/sample.rkt b/pkgs/plot/private/contracted/sample.rkt similarity index 100% rename from pkgs/plot/contracted/sample.rkt rename to pkgs/plot/private/contracted/sample.rkt diff --git a/pkgs/plot/contracted/samplers.rkt b/pkgs/plot/private/contracted/samplers.rkt similarity index 100% rename from pkgs/plot/contracted/samplers.rkt rename to pkgs/plot/private/contracted/samplers.rkt diff --git a/pkgs/plot/contracted/ticks.rkt b/pkgs/plot/private/contracted/ticks.rkt similarity index 100% rename from pkgs/plot/contracted/ticks.rkt rename to pkgs/plot/private/contracted/ticks.rkt diff --git a/pkgs/plot/deprecated/deprecated.rkt b/pkgs/plot/private/deprecated/deprecated.rkt similarity index 100% rename from pkgs/plot/deprecated/deprecated.rkt rename to pkgs/plot/private/deprecated/deprecated.rkt diff --git a/pkgs/plot/deprecated/math.rkt b/pkgs/plot/private/deprecated/math.rkt similarity index 100% rename from pkgs/plot/deprecated/math.rkt rename to pkgs/plot/private/deprecated/math.rkt diff --git a/pkgs/plot/deprecated/renderers.rkt b/pkgs/plot/private/deprecated/renderers.rkt similarity index 100% rename from pkgs/plot/deprecated/renderers.rkt rename to pkgs/plot/private/deprecated/renderers.rkt diff --git a/pkgs/plot/doc.rkt b/pkgs/plot/private/doc.rkt similarity index 90% rename from pkgs/plot/doc.rkt rename to pkgs/plot/private/doc.rkt index 1a46dca6c2..cfbdebc49e 100644 --- a/pkgs/plot/doc.rkt +++ b/pkgs/plot/private/doc.rkt @@ -41,7 +41,8 @@ ;; =================================================================================================== ;; 2D exports -(require "plot2d/plot.rkt" +(require "no-gui/plot2d.rkt" + "gui/plot2d.rkt" "plot2d/point.rkt" "plot2d/line.rkt" "plot2d/interval.rkt" @@ -50,7 +51,8 @@ "plot2d/decoration.rkt") (provide (only-doc-out - (combine-out (all-from-out "plot2d/plot.rkt") + (combine-out (all-from-out "no-gui/plot2d.rkt") + (all-from-out "gui/plot2d.rkt") (all-from-out "plot2d/point.rkt") (all-from-out "plot2d/line.rkt") (all-from-out "plot2d/interval.rkt") @@ -61,7 +63,8 @@ ;; =================================================================================================== ;; 3D exports -(require "plot3d/plot.rkt" +(require "no-gui/plot3d.rkt" + "gui/plot3d.rkt" "plot3d/surface.rkt" "plot3d/contour.rkt" "plot3d/line.rkt" @@ -71,7 +74,8 @@ "plot3d/decoration.rkt") (provide (only-doc-out - (combine-out (all-from-out "plot3d/plot.rkt") + (combine-out (all-from-out "no-gui/plot3d.rkt") + (all-from-out "gui/plot3d.rkt") (all-from-out "plot3d/surface.rkt") (all-from-out "plot3d/contour.rkt") (all-from-out "plot3d/line.rkt") diff --git a/pkgs/plot/common/gui.rkt b/pkgs/plot/private/gui/gui.rkt similarity index 100% rename from pkgs/plot/common/gui.rkt rename to pkgs/plot/private/gui/gui.rkt diff --git a/pkgs/plot/private/gui/plot2d.rkt b/pkgs/plot/private/gui/plot2d.rkt new file mode 100644 index 0000000000..16a58d75c1 --- /dev/null +++ b/pkgs/plot/private/gui/plot2d.rkt @@ -0,0 +1,134 @@ +#lang racket/base + +(require racket/snip racket/contract racket/class racket/match + unstable/contract + unstable/parameter-group + racket/lazy-require + unstable/latent-contract/defthing + "../common/contract.rkt" + "../common/math.rkt" + "../common/draw.rkt" + "../common/parameters.rkt" + "../common/plot-element.rkt" + "../common/deprecation-warning.rkt" + "../plot2d/plot-area.rkt" + "../no-gui/plot2d.rkt" + "../no-gui/plot2d-utils.rkt") + +;; Require lazily, in case someone wants to just (require plot) in a headless setup +(lazy-require ["snip2d.rkt" (make-2d-plot-snip)] + ["gui.rkt" (make-snip-frame with-new-eventspace)]) + +(provide plot-snip plot-frame plot) + +;; =================================================================================================== +;; Plot to a snip + +(defproc (plot-snip [renderer-tree (treeof (or/c renderer2d? nonrenderer?))] + [#:x-min x-min (or/c rational? #f) #f] [#:x-max x-max (or/c rational? #f) #f] + [#:y-min y-min (or/c rational? #f) #f] [#:y-max y-max (or/c rational? #f) #f] + [#:width width exact-positive-integer? (plot-width)] + [#:height height exact-positive-integer? (plot-height)] + [#:title title (or/c string? #f) (plot-title)] + [#:x-label x-label (or/c string? #f) (plot-x-label)] + [#:y-label y-label (or/c string? #f) (plot-y-label)] + [#:legend-anchor legend-anchor anchor/c (plot-legend-anchor)] + ) (is-a?/c image-snip%) + (parameterize ([plot-title title] + [plot-x-label x-label] + [plot-y-label y-label] + [plot-legend-anchor legend-anchor]) + (define saved-plot-parameters (plot-parameters)) + (define renderer-list (get-renderer-list renderer-tree)) + (define bounds-rect (get-bounds-rect renderer-list x-min x-max y-min y-max)) + + (define (make-bm anim? bounds-rect width height) + (define area #f) + (define bm + (parameterize/group ([plot-parameters saved-plot-parameters] + [plot-animating? (if anim? #t (plot-animating?))]) + ((if (plot-animating?) draw-bitmap draw-bitmap/supersampling) + (λ (dc) + (define-values (x-ticks x-far-ticks y-ticks y-far-ticks) + (get-ticks renderer-list bounds-rect)) + + (set! area (make-object 2d-plot-area% + bounds-rect x-ticks x-far-ticks y-ticks y-far-ticks + dc 0 0 width height)) + + (plot-area area renderer-list)) + width height))) + + (define (area-bounds->plot-bounds rect) + (match-define (vector (ivl area-x-min area-x-max) (ivl area-y-min area-y-max)) rect) + (match-define (vector x-min y-min) (send area dc->plot (vector area-x-min area-y-min))) + (match-define (vector x-max y-max) (send area dc->plot (vector area-x-max area-y-max))) + (vector (ivl x-min x-max) (ivl y-min y-max))) + + (values bm (send area get-area-bounds-rect) area-bounds->plot-bounds)) + + (define-values (bm area-bounds-rect area-bounds->plot-bounds) + (make-bm #f bounds-rect width height)) + + (make-2d-plot-snip + bm saved-plot-parameters + make-bm bounds-rect area-bounds-rect area-bounds->plot-bounds width height))) + +;; =================================================================================================== +;; Plot to a frame + +(defproc (plot-frame [renderer-tree (treeof (or/c renderer2d? nonrenderer?))] + [#:x-min x-min (or/c rational? #f) #f] [#:x-max x-max (or/c rational? #f) #f] + [#:y-min y-min (or/c rational? #f) #f] [#:y-max y-max (or/c rational? #f) #f] + [#:width width exact-positive-integer? (plot-width)] + [#:height height exact-positive-integer? (plot-height)] + [#:title title (or/c string? #f) (plot-title)] + [#:x-label x-label (or/c string? #f) (plot-x-label)] + [#:y-label y-label (or/c string? #f) (plot-y-label)] + [#:legend-anchor legend-anchor anchor/c (plot-legend-anchor)] + ) (is-a?/c object%) + (define snip + (plot-snip + renderer-tree + #:x-min x-min #:x-max x-max #:y-min y-min #:y-max y-max #:width width #:height height + #:title title #:x-label x-label #:y-label y-label #:legend-anchor legend-anchor)) + (make-snip-frame snip width height (if title (format "Plot: ~a" title) "Plot"))) + +;; =================================================================================================== +;; Plot to a frame or a snip, depending on (plot-new-window?) + +(defproc (plot [renderer-tree (treeof (or/c renderer2d? nonrenderer?))] + [#:x-min x-min (or/c rational? #f) #f] [#:x-max x-max (or/c rational? #f) #f] + [#:y-min y-min (or/c rational? #f) #f] [#:y-max y-max (or/c rational? #f) #f] + [#:width width exact-positive-integer? (plot-width)] + [#:height height exact-positive-integer? (plot-height)] + [#:title title (or/c string? #f) (plot-title)] + [#:x-label x-label (or/c string? #f) (plot-x-label)] + [#:y-label y-label (or/c string? #f) (plot-y-label)] + [#:legend-anchor legend-anchor anchor/c (plot-legend-anchor)] + [#:out-file out-file (or/c path-string? output-port? #f) #f] + [#:out-kind out-kind (one-of/c 'auto 'png 'jpeg 'xmb 'xpm 'bmp 'ps 'pdf 'svg) 'auto] + [#:fgcolor fgcolor plot-color/c #f] [#:bgcolor bgcolor plot-color/c #f] + [#:lncolor lncolor plot-color/c #f] ; unused + ) (or/c (is-a?/c snip%) void?) + (when fgcolor + (deprecation-warning "the plot #:fgcolor keyword argument" "plot-foreground")) + (when bgcolor + (deprecation-warning "the plot #:bgcolor keyword argument" "plot-background")) + (when lncolor + (deprecation-warning "the plot #:lncolor keyword argument")) + + (define (call f . args) + (apply f renderer-tree args + #:x-min x-min #:x-max x-max #:y-min y-min #:y-max y-max #:width width #:height height + #:title title #:x-label x-label #:y-label y-label #:legend-anchor legend-anchor)) + + (parameterize ([plot-foreground (if fgcolor fgcolor (plot-foreground))] + [plot-background (if bgcolor bgcolor (plot-background))]) + (when out-file + (call plot-file out-file out-kind)) + + (cond [(plot-new-window?) (define frame (with-new-eventspace (λ () (call plot-frame)))) + (send frame show #t) + (void)] + [else (call plot-snip)]))) diff --git a/pkgs/plot/private/gui/plot3d.rkt b/pkgs/plot/private/gui/plot3d.rkt new file mode 100644 index 0000000000..69f0e90720 --- /dev/null +++ b/pkgs/plot/private/gui/plot3d.rkt @@ -0,0 +1,166 @@ +#lang racket/base + +(require racket/snip racket/match racket/list racket/class racket/contract + unstable/contract + unstable/parameter-group + racket/lazy-require + unstable/latent-contract/defthing + "../common/contract.rkt" + "../common/math.rkt" + "../common/draw.rkt" + "../common/parameters.rkt" + "../common/plot-element.rkt" + "../common/deprecation-warning.rkt" + "../plot3d/plot-area.rkt" + "../no-gui/plot3d.rkt" + "../no-gui/plot3d-utils.rkt") + +;; Require lazily, in case someone wants to just (require plot) in a headless setup +(lazy-require ["snip3d.rkt" (make-3d-plot-snip)] + ["gui.rkt" (make-snip-frame with-new-eventspace)]) + +(provide plot3d-snip plot3d-frame plot3d) + +;; =================================================================================================== +;; Plot to a snip + +(defproc (plot3d-snip [renderer-tree (treeof (or/c renderer3d? nonrenderer?))] + [#:x-min x-min (or/c rational? #f) #f] [#:x-max x-max (or/c rational? #f) #f] + [#:y-min y-min (or/c rational? #f) #f] [#:y-max y-max (or/c rational? #f) #f] + [#:z-min z-min (or/c rational? #f) #f] [#:z-max z-max (or/c rational? #f) #f] + [#:width width exact-positive-integer? (plot-width)] + [#:height height exact-positive-integer? (plot-height)] + [#:angle angle real? (plot3d-angle)] + [#:altitude altitude real? (plot3d-altitude)] + [#:title title (or/c string? #f) (plot-title)] + [#:x-label x-label (or/c string? #f) (plot-x-label)] + [#:y-label y-label (or/c string? #f) (plot-y-label)] + [#:z-label z-label (or/c string? #f) (plot-z-label)] + [#:legend-anchor legend-anchor anchor/c (plot-legend-anchor)] + ) (is-a?/c image-snip%) + (parameterize ([plot-title title] + [plot-x-label x-label] + [plot-y-label y-label] + [plot-z-label z-label] + [plot-legend-anchor legend-anchor]) + (define saved-plot-parameters (plot-parameters)) + (define renderer-list (get-renderer-list renderer-tree)) + (define bounds-rect (get-bounds-rect renderer-list x-min x-max y-min y-max z-min z-max)) + (define-values (x-ticks x-far-ticks y-ticks y-far-ticks z-ticks z-far-ticks) + (get-ticks renderer-list bounds-rect)) + + (define render-list-hash (make-hash)) + (define legend-entries-hash (make-hash)) + + (define (make-bm anim? angle altitude width height) + (parameterize/group ([plot-parameters saved-plot-parameters] + [plot-animating? (if anim? #t (plot-animating?))] + [plot3d-angle angle] + [plot3d-altitude altitude]) + ((if (plot-animating?) draw-bitmap draw-bitmap/supersampling) + (λ (dc) + (define area (make-object 3d-plot-area% + bounds-rect x-ticks x-far-ticks y-ticks y-far-ticks z-ticks z-far-ticks + dc 0 0 width height)) + (send area start-plot) + + (cond [(not (hash-ref render-list-hash (plot-animating?) #f)) + (hash-set! + legend-entries-hash (plot-animating?) + (flatten (for/list ([rend (in-list renderer-list)]) + (match-define (renderer3d rend-bounds-rect _bf _tf render-proc) rend) + (send area start-renderer (if rend-bounds-rect + (rect-inexact->exact rend-bounds-rect) + (unknown-rect 3))) + (if render-proc (render-proc area) empty)))) + + (hash-set! render-list-hash (plot-animating?) (send area get-render-list))] + [else + (send area put-render-list (hash-ref render-list-hash (plot-animating?)))]) + + (send area end-renderers) + + (define legend-entries (hash-ref legend-entries-hash (plot-animating?) #f)) + (when (not (empty? legend-entries)) + (send area draw-legend legend-entries)) + + (send area end-plot)) + width height))) + + (make-3d-plot-snip + (make-bm #f angle altitude width height) saved-plot-parameters + make-bm angle altitude width height))) + +;; =================================================================================================== +;; Plot to a frame + +(defproc (plot3d-frame [renderer-tree (treeof (or/c renderer3d? nonrenderer?))] + [#:x-min x-min (or/c rational? #f) #f] [#:x-max x-max (or/c rational? #f) #f] + [#:y-min y-min (or/c rational? #f) #f] [#:y-max y-max (or/c rational? #f) #f] + [#:z-min z-min (or/c rational? #f) #f] [#:z-max z-max (or/c rational? #f) #f] + [#:width width exact-positive-integer? (plot-width)] + [#:height height exact-positive-integer? (plot-height)] + [#:angle angle real? (plot3d-angle)] + [#:altitude altitude real? (plot3d-altitude)] + [#:title title (or/c string? #f) (plot-title)] + [#:x-label x-label (or/c string? #f) (plot-x-label)] + [#:y-label y-label (or/c string? #f) (plot-y-label)] + [#:z-label z-label (or/c string? #f) (plot-z-label)] + [#:legend-anchor legend-anchor anchor/c (plot-legend-anchor)] + ) (is-a?/c object%) + (define snip + (plot3d-snip + renderer-tree + #:x-min x-min #:x-max x-max #:y-min y-min #:y-max y-max #:z-min z-min #:z-max z-max + #:width width #:height height #:angle angle #:altitude altitude #:title title + #:x-label x-label #:y-label y-label #:z-label z-label #:legend-anchor legend-anchor)) + (make-snip-frame snip width height (if title (format "Plot: ~a" title) "Plot"))) + +;; =================================================================================================== +;; Plot to a frame or a snip, depending on the value of plot-new-window? + +(defproc (plot3d [renderer-tree (treeof (or/c renderer3d? nonrenderer?))] + [#:x-min x-min (or/c rational? #f) #f] [#:x-max x-max (or/c rational? #f) #f] + [#:y-min y-min (or/c rational? #f) #f] [#:y-max y-max (or/c rational? #f) #f] + [#:z-min z-min (or/c rational? #f) #f] [#:z-max z-max (or/c rational? #f) #f] + [#:width width exact-positive-integer? (plot-width)] + [#:height height exact-positive-integer? (plot-height)] + [#:angle angle real? #f] [#:altitude altitude real? #f] + [#:az az real? #f] [#:alt alt real? #f] ; backward-compatible aliases + [#:title title (or/c string? #f) (plot-title)] + [#:x-label x-label (or/c string? #f) (plot-x-label)] + [#:y-label y-label (or/c string? #f) (plot-y-label)] + [#:z-label z-label (or/c string? #f) (plot-z-label)] + [#:legend-anchor legend-anchor anchor/c (plot-legend-anchor)] + [#:out-file out-file (or/c path-string? output-port? #f) #f] + [#:out-kind out-kind (one-of/c 'auto 'png 'jpeg 'xmb 'xpm 'bmp 'ps 'pdf 'svg) 'auto] + [#:fgcolor fgcolor plot-color/c #f] [#:bgcolor bgcolor plot-color/c #f] + [#:lncolor lncolor plot-color/c #f] ; unused + ) (or/c (is-a?/c snip%) void?) + (when fgcolor + (deprecation-warning "the plot3d #:fgcolor keyword argument" "plot-foreground")) + (when bgcolor + (deprecation-warning "the plot3d #:bgcolor keyword argument" "plot-background")) + (when lncolor + (deprecation-warning "the plot3d #:lncolor keyword argument")) + (when az + (deprecation-warning "the plot3d #:az keyword argument" "#:angle")) + (when alt + (deprecation-warning "the plot3d #:alt keyword argument" "#:altitude")) + + (define (call f . args) + (apply f renderer-tree args + #:x-min x-min #:x-max x-max #:y-min y-min #:y-max y-max #:z-min z-min #:z-max z-max + #:width width #:height height #:title title + #:angle (or angle az (plot3d-angle)) #:altitude (or altitude alt (plot3d-altitude)) + #:x-label x-label #:y-label y-label #:z-label z-label #:legend-anchor legend-anchor)) + + (parameterize ([plot-foreground (if fgcolor fgcolor (plot-foreground))] + [plot-background (if bgcolor bgcolor (plot-background))]) + (when out-file + (call plot3d-file out-file out-kind)) + + (cond [(plot-new-window?) (define frame (with-new-eventspace (λ () (call plot3d-frame)))) + (send frame show #t) + (void)] + [else (call plot3d-snip)]))) diff --git a/pkgs/plot/common/snip.rkt b/pkgs/plot/private/gui/snip.rkt similarity index 98% rename from pkgs/plot/common/snip.rkt rename to pkgs/plot/private/gui/snip.rkt index 7ddef5f322..562e29c25b 100644 --- a/pkgs/plot/common/snip.rkt +++ b/pkgs/plot/private/gui/snip.rkt @@ -1,10 +1,10 @@ #lang racket/base (require racket/gui/base racket/class racket/list unstable/parameter-group - "math.rkt" - "parameters.rkt" - "plot-device.rkt" - "worker-thread.rkt") + "../common/math.rkt" + "../common/parameters.rkt" + "../common/plot-device.rkt" + "../common/worker-thread.rkt") (provide plot-snip%) diff --git a/pkgs/plot/plot2d/snip.rkt b/pkgs/plot/private/gui/snip2d.rkt similarity index 99% rename from pkgs/plot/plot2d/snip.rkt rename to pkgs/plot/private/gui/snip2d.rkt index 20bac385f1..f39e417898 100644 --- a/pkgs/plot/plot2d/snip.rkt +++ b/pkgs/plot/private/gui/snip2d.rkt @@ -1,7 +1,7 @@ #lang racket/base (require racket/gui/base racket/class racket/match racket/list racket/math unstable/parameter-group - "../common/snip.rkt" + "snip.rkt" "../common/plot-device.rkt" "../common/math.rkt" "../common/format.rkt" diff --git a/pkgs/plot/plot3d/snip.rkt b/pkgs/plot/private/gui/snip3d.rkt similarity index 99% rename from pkgs/plot/plot3d/snip.rkt rename to pkgs/plot/private/gui/snip3d.rkt index 102c08bcb1..9177600743 100644 --- a/pkgs/plot/plot3d/snip.rkt +++ b/pkgs/plot/private/gui/snip3d.rkt @@ -1,7 +1,7 @@ #lang racket/base (require racket/gui/base racket/class racket/match unstable/parameter-group - "../common/snip.rkt" + "snip.rkt" "../common/math.rkt" "../common/worker-thread.rkt" "../common/parameters.rkt") diff --git a/pkgs/plot/private/no-gui/plot-bitmap.rkt b/pkgs/plot/private/no-gui/plot-bitmap.rkt new file mode 100644 index 0000000000..c66558d672 --- /dev/null +++ b/pkgs/plot/private/no-gui/plot-bitmap.rkt @@ -0,0 +1,63 @@ +#lang racket/base + +(require racket/contract + racket/class + unstable/latent-contract/defthing + unstable/contract + racket/draw + "../common/contract.rkt" + "../common/parameters.rkt" + "../common/plot-element.rkt" + "plot2d.rkt" + "plot3d.rkt") + +(provide (all-defined-out)) + +(defproc (plot [renderer-tree (treeof (or/c renderer2d? nonrenderer?))] + [#:x-min x-min (or/c rational? #f) #f] [#:x-max x-max (or/c rational? #f) #f] + [#:y-min y-min (or/c rational? #f) #f] [#:y-max y-max (or/c rational? #f) #f] + [#:width width exact-positive-integer? (plot-width)] + [#:height height exact-positive-integer? (plot-height)] + [#:title title (or/c string? #f) (plot-title)] + [#:x-label x-label (or/c string? #f) (plot-x-label)] + [#:y-label y-label (or/c string? #f) (plot-y-label)] + [#:legend-anchor legend-anchor anchor/c (plot-legend-anchor)] + [#:out-file out-file (or/c path-string? output-port? #f) #f] + [#:out-kind out-kind (one-of/c 'auto 'png 'jpeg 'xmb 'xpm 'bmp 'ps 'pdf 'svg) 'auto] + ) (is-a?/c bitmap%) + (define (call f . args) + (apply f renderer-tree args + #:x-min x-min #:x-max x-max #:y-min y-min #:y-max y-max #:width width #:height height + #:title title #:x-label x-label #:y-label y-label #:legend-anchor legend-anchor)) + + (when out-file + (call plot-file out-file out-kind)) + + (call plot-bitmap)) + +(defproc (plot3d [renderer-tree (treeof (or/c renderer3d? nonrenderer?))] + [#:x-min x-min (or/c rational? #f) #f] [#:x-max x-max (or/c rational? #f) #f] + [#:y-min y-min (or/c rational? #f) #f] [#:y-max y-max (or/c rational? #f) #f] + [#:z-min z-min (or/c rational? #f) #f] [#:z-max z-max (or/c rational? #f) #f] + [#:width width exact-positive-integer? (plot-width)] + [#:height height exact-positive-integer? (plot-height)] + [#:angle angle real? #f] [#:altitude altitude real? #f] + [#:title title (or/c string? #f) (plot-title)] + [#:x-label x-label (or/c string? #f) (plot-x-label)] + [#:y-label y-label (or/c string? #f) (plot-y-label)] + [#:z-label z-label (or/c string? #f) (plot-z-label)] + [#:legend-anchor legend-anchor anchor/c (plot-legend-anchor)] + [#:out-file out-file (or/c path-string? output-port? #f) #f] + [#:out-kind out-kind (one-of/c 'auto 'png 'jpeg 'xmb 'xpm 'bmp 'ps 'pdf 'svg) 'auto] + ) (is-a?/c bitmap%) + (define (call f . args) + (apply f renderer-tree args + #:x-min x-min #:x-max x-max #:y-min y-min #:y-max y-max #:z-min z-min #:z-max z-max + #:width width #:height height #:title title + #:angle (or angle (plot3d-angle)) #:altitude (or altitude (plot3d-altitude)) + #:x-label x-label #:y-label y-label #:z-label z-label #:legend-anchor legend-anchor)) + + (when out-file + (call plot3d-file out-file out-kind)) + + (call plot3d-bitmap)) diff --git a/pkgs/plot/private/no-gui/plot-pict.rkt b/pkgs/plot/private/no-gui/plot-pict.rkt new file mode 100644 index 0000000000..d66394f8b9 --- /dev/null +++ b/pkgs/plot/private/no-gui/plot-pict.rkt @@ -0,0 +1,62 @@ +#lang racket/base + +(require racket/contract + unstable/latent-contract/defthing + unstable/contract + pict + "../common/contract.rkt" + "../common/parameters.rkt" + "../common/plot-element.rkt" + "plot2d.rkt" + "plot3d.rkt") + +(provide (all-defined-out)) + +(defproc (plot [renderer-tree (treeof (or/c renderer2d? nonrenderer?))] + [#:x-min x-min (or/c rational? #f) #f] [#:x-max x-max (or/c rational? #f) #f] + [#:y-min y-min (or/c rational? #f) #f] [#:y-max y-max (or/c rational? #f) #f] + [#:width width exact-positive-integer? (plot-width)] + [#:height height exact-positive-integer? (plot-height)] + [#:title title (or/c string? #f) (plot-title)] + [#:x-label x-label (or/c string? #f) (plot-x-label)] + [#:y-label y-label (or/c string? #f) (plot-y-label)] + [#:legend-anchor legend-anchor anchor/c (plot-legend-anchor)] + [#:out-file out-file (or/c path-string? output-port? #f) #f] + [#:out-kind out-kind (one-of/c 'auto 'png 'jpeg 'xmb 'xpm 'bmp 'ps 'pdf 'svg) 'auto] + ) pict? + (define (call f . args) + (apply f renderer-tree args + #:x-min x-min #:x-max x-max #:y-min y-min #:y-max y-max #:width width #:height height + #:title title #:x-label x-label #:y-label y-label #:legend-anchor legend-anchor)) + + (when out-file + (call plot-file out-file out-kind)) + + (call plot-pict)) + +(defproc (plot3d [renderer-tree (treeof (or/c renderer3d? nonrenderer?))] + [#:x-min x-min (or/c rational? #f) #f] [#:x-max x-max (or/c rational? #f) #f] + [#:y-min y-min (or/c rational? #f) #f] [#:y-max y-max (or/c rational? #f) #f] + [#:z-min z-min (or/c rational? #f) #f] [#:z-max z-max (or/c rational? #f) #f] + [#:width width exact-positive-integer? (plot-width)] + [#:height height exact-positive-integer? (plot-height)] + [#:angle angle real? #f] [#:altitude altitude real? #f] + [#:title title (or/c string? #f) (plot-title)] + [#:x-label x-label (or/c string? #f) (plot-x-label)] + [#:y-label y-label (or/c string? #f) (plot-y-label)] + [#:z-label z-label (or/c string? #f) (plot-z-label)] + [#:legend-anchor legend-anchor anchor/c (plot-legend-anchor)] + [#:out-file out-file (or/c path-string? output-port? #f) #f] + [#:out-kind out-kind (one-of/c 'auto 'png 'jpeg 'xmb 'xpm 'bmp 'ps 'pdf 'svg) 'auto] + ) pict? + (define (call f . args) + (apply f renderer-tree args + #:x-min x-min #:x-max x-max #:y-min y-min #:y-max y-max #:z-min z-min #:z-max z-max + #:width width #:height height #:title title + #:angle (or angle (plot3d-angle)) #:altitude (or altitude (plot3d-altitude)) + #:x-label x-label #:y-label y-label #:z-label z-label #:legend-anchor legend-anchor)) + + (when out-file + (call plot3d-file out-file out-kind)) + + (call plot3d-pict)) diff --git a/pkgs/plot/private/no-gui/plot2d-utils.rkt b/pkgs/plot/private/no-gui/plot2d-utils.rkt new file mode 100644 index 0000000000..e0935693ef --- /dev/null +++ b/pkgs/plot/private/no-gui/plot2d-utils.rkt @@ -0,0 +1,56 @@ +#lang racket/base + +(require racket/list racket/class racket/match + "../common/math.rkt" + "../common/plot-element.rkt" + "../common/format.rkt") + +(provide (all-defined-out)) + +(define (get-renderer-list renderer-tree) + (for/list ([r (flatten (list renderer-tree))]) + (match r + [(nonrenderer bounds-rect bounds-fun ticks-fun) + (renderer2d bounds-rect bounds-fun ticks-fun #f)] + [_ r]))) + +(define (get-bounds-rect renderer-list x-min x-max y-min y-max) + (define given-bounds-rect (vector (ivl x-min x-max) (ivl y-min y-max))) + (define plot-bounds-rect (bounds-fixpoint renderer-list given-bounds-rect)) + (when (or (not (rect-rational? plot-bounds-rect)) + (rect-zero-area? plot-bounds-rect)) + (match-define (vector x-ivl y-ivl) plot-bounds-rect) + (error 'plot "could not determine sensible plot bounds; got x ∈ ~a, y ∈ ~a" + (ivl->plot-label x-ivl) (ivl->plot-label y-ivl))) + (rect-inexact->exact plot-bounds-rect)) + +(define (get-ticks renderer-list bounds-rect) + (define-values (all-x-ticks all-x-far-ticks all-y-ticks all-y-far-ticks) + (for/lists (all-x-ticks all-x-far-ticks all-y-ticks all-y-far-ticks + ) ([r (in-list renderer-list)]) + (define ticks-fun (plot-element-ticks-fun r)) + (cond [ticks-fun (ticks-fun bounds-rect)] + [else (values empty empty empty empty)]))) + (values (remove-duplicates (append* all-x-ticks)) + (remove-duplicates (append* all-x-far-ticks)) + (remove-duplicates (append* all-y-ticks)) + (remove-duplicates (append* all-y-far-ticks)))) + +(define (plot-area area renderer-list) + (send area start-plot) + + (define legend-entries + (flatten (for/list ([rend (in-list renderer-list)]) + (match-define (renderer2d rend-bounds-rect _bf _tf render-proc) rend) + (send area start-renderer (if rend-bounds-rect + (rect-inexact->exact rend-bounds-rect) + (unknown-rect 2))) + (if render-proc (render-proc area) empty)))) + + (send area end-renderers) + + (when (not (empty? legend-entries)) + (send area draw-legend legend-entries)) + + (send area end-plot)) + diff --git a/pkgs/plot/private/no-gui/plot2d.rkt b/pkgs/plot/private/no-gui/plot2d.rkt new file mode 100644 index 0000000000..2ddfda2592 --- /dev/null +++ b/pkgs/plot/private/no-gui/plot2d.rkt @@ -0,0 +1,132 @@ +#lang racket/base + +(require racket/draw racket/contract racket/class + unstable/contract + pict + unstable/parameter-group + unstable/latent-contract/defthing + "../common/contract.rkt" + "../common/draw.rkt" + "../common/parameters.rkt" + "../common/plot-element.rkt" + "../common/file-type.rkt" + "../plot2d/plot-area.rkt" + "plot2d-utils.rkt") + +(provide (all-defined-out)) + +;; =================================================================================================== +;; Plot to a given device context + +(defproc (plot/dc [renderer-tree (treeof (or/c renderer2d? nonrenderer?))] + [dc (is-a?/c dc<%>)] + [x real?] [y real?] [width (>=/c 0)] [height (>=/c 0)] + [#:x-min x-min (or/c rational? #f) #f] [#:x-max x-max (or/c rational? #f) #f] + [#:y-min y-min (or/c rational? #f) #f] [#:y-max y-max (or/c rational? #f) #f] + [#:title title (or/c string? #f) (plot-title)] + [#:x-label x-label (or/c string? #f) (plot-x-label)] + [#:y-label y-label (or/c string? #f) (plot-y-label)] + [#:legend-anchor legend-anchor anchor/c (plot-legend-anchor)]) void? + (define renderer-list (get-renderer-list renderer-tree)) + (define bounds-rect (get-bounds-rect renderer-list x-min x-max y-min y-max)) + (define-values (x-ticks x-far-ticks y-ticks y-far-ticks) + (get-ticks renderer-list bounds-rect)) + + (parameterize ([plot-title title] + [plot-x-label x-label] + [plot-y-label y-label] + [plot-legend-anchor legend-anchor]) + (define area (make-object 2d-plot-area% + bounds-rect x-ticks x-far-ticks y-ticks y-far-ticks dc x y width height)) + (plot-area area renderer-list))) + +;; =================================================================================================== +;; Plot to a bitmap + +(defproc (plot-bitmap [renderer-tree (treeof (or/c renderer2d? nonrenderer?))] + [#:x-min x-min (or/c rational? #f) #f] [#:x-max x-max (or/c rational? #f) #f] + [#:y-min y-min (or/c rational? #f) #f] [#:y-max y-max (or/c rational? #f) #f] + [#:width width exact-positive-integer? (plot-width)] + [#:height height exact-positive-integer? (plot-height)] + [#:title title (or/c string? #f) (plot-title)] + [#:x-label x-label (or/c string? #f) (plot-x-label)] + [#:y-label y-label (or/c string? #f) (plot-y-label)] + [#:legend-anchor legend-anchor anchor/c (plot-legend-anchor)] + ) (is-a?/c bitmap%) + (define renderer-list (get-renderer-list renderer-tree)) + (define bounds-rect (get-bounds-rect renderer-list x-min x-max y-min y-max)) + (define-values (x-ticks x-far-ticks y-ticks y-far-ticks) + (get-ticks renderer-list bounds-rect)) + ((if (plot-animating?) draw-bitmap draw-bitmap/supersampling) + (λ (dc) + (plot/dc renderer-tree dc 0 0 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 pict + +(defproc (plot-pict [renderer-tree (treeof (or/c renderer2d? nonrenderer?))] + [#:x-min x-min (or/c rational? #f) #f] [#:x-max x-max (or/c rational? #f) #f] + [#:y-min y-min (or/c rational? #f) #f] [#:y-max y-max (or/c rational? #f) #f] + [#:width width exact-positive-integer? (plot-width)] + [#:height height exact-positive-integer? (plot-height)] + [#:title title (or/c string? #f) (plot-title)] + [#:x-label x-label (or/c string? #f) (plot-x-label)] + [#:y-label y-label (or/c string? #f) (plot-y-label)] + [#:legend-anchor legend-anchor anchor/c (plot-legend-anchor)] + ) pict? + (define saved-values (plot-parameters)) + (dc (λ (dc x y) + (parameterize/group + ([plot-parameters saved-values]) + (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 file + +(defproc (plot-file [renderer-tree (treeof (or/c renderer2d? nonrenderer?))] + [output (or/c path-string? output-port?)] + [kind (one-of/c 'auto 'png 'jpeg 'xmb 'xpm 'bmp 'ps 'pdf 'svg) 'auto] + [#:x-min x-min (or/c rational? #f) #f] [#:x-max x-max (or/c rational? #f) #f] + [#:y-min y-min (or/c rational? #f) #f] [#:y-max y-max (or/c rational? #f) #f] + [#:width width exact-positive-integer? (plot-width)] + [#:height height exact-positive-integer? (plot-height)] + [#:title title (or/c string? #f) (plot-title)] + [#:x-label x-label (or/c string? #f) (plot-x-label)] + [#:y-label y-label (or/c string? #f) (plot-y-label)] + [#:legend-anchor legend-anchor anchor/c (plot-legend-anchor)]) void? + (define real-kind (if (eq? kind 'auto) (detect-image-file-type output) kind)) + (case real-kind + [(png jpeg xbm xpm bmp) + (define bm + (plot-bitmap + renderer-tree + #:x-min x-min #:x-max x-max #:y-min y-min #:y-max y-max #:width width #:height height + #:title title #:x-label x-label #:y-label y-label #:legend-anchor legend-anchor)) + (send bm save-file output real-kind (plot-jpeg-quality))] + [(ps pdf svg) + (define dc + (case real-kind + [(ps) (new post-script-dc% + [interactive (plot-ps/pdf-interactive?)] [parent #f] [use-paper-bbox #f] + [as-eps #t] [width width] [height height] [output output])] + [(pdf) (new pdf-dc% + [interactive (plot-ps/pdf-interactive?)] [parent #f] [use-paper-bbox #f] + [width width] [height height] [output output])] + [(svg) (new svg-dc% + [width width] [height height] [output output] [exists 'truncate/replace])])) + (define-values (x-scale y-scale) (send dc get-device-scale)) + (send dc start-doc "Rendering plot") + (send dc start-page) + (plot/dc renderer-tree dc 0 0 + (inexact->exact (/ width x-scale)) (inexact->exact (/ height y-scale)) + #: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) + (send dc end-page) + (send dc end-doc)]) + (void)) diff --git a/pkgs/plot/private/no-gui/plot3d-utils.rkt b/pkgs/plot/private/no-gui/plot3d-utils.rkt new file mode 100644 index 0000000000..585ea9459f --- /dev/null +++ b/pkgs/plot/private/no-gui/plot3d-utils.rkt @@ -0,0 +1,61 @@ +#lang racket/base + +(require racket/match racket/list racket/class + "../common/math.rkt" + "../common/plot-element.rkt" + "../common/format.rkt") + +(provide (all-defined-out)) + +(define (get-renderer-list renderer-tree) + (for/list ([r (flatten (list renderer-tree))]) + (match r + [(nonrenderer bounds-rect bounds-fun ticks-fun) + (renderer3d bounds-rect bounds-fun ticks-fun #f)] + [_ r]))) + +(define (get-bounds-rect renderer-list x-min x-max y-min y-max z-min z-max) + (define given-bounds-rect (vector (ivl x-min x-max) (ivl y-min y-max) (ivl z-min z-max))) + (define plot-bounds-rect (bounds-fixpoint renderer-list given-bounds-rect)) + (when (or (not (rect-rational? plot-bounds-rect)) + (rect-zero-area? plot-bounds-rect)) + (match-define (vector x-ivl y-ivl z-ivl) plot-bounds-rect) + (error 'plot "could not determine sensible plot bounds; got x ∈ ~a, y ∈ ~a, z ∈ ~a" + (ivl->plot-label x-ivl) (ivl->plot-label y-ivl) (ivl->plot-label z-ivl))) + (rect-inexact->exact plot-bounds-rect)) + +(define (get-ticks renderer-list bounds-rect) + (define-values (all-x-ticks all-x-far-ticks all-y-ticks all-y-far-ticks all-z-ticks all-z-far-ticks) + (for/lists (all-x-ticks + all-x-far-ticks + all-y-ticks + all-y-far-ticks + all-z-ticks + all-z-far-ticks) ([r (in-list renderer-list)]) + (define ticks-fun (plot-element-ticks-fun r)) + (cond [ticks-fun (ticks-fun bounds-rect)] + [else (values empty empty empty empty empty empty)]))) + (values (remove-duplicates (append* all-x-ticks)) + (remove-duplicates (append* all-x-far-ticks)) + (remove-duplicates (append* all-y-ticks)) + (remove-duplicates (append* all-y-far-ticks)) + (remove-duplicates (append* all-z-ticks)) + (remove-duplicates (append* all-z-far-ticks)))) + +(define (plot-area area renderer-list) + (send area start-plot) + + (define legend-entries + (flatten (for/list ([rend (in-list renderer-list)]) + (match-define (renderer3d rend-bounds-rect _bf _tf render-proc) rend) + (send area start-renderer (if rend-bounds-rect + (rect-inexact->exact rend-bounds-rect) + (unknown-rect 3))) + (if render-proc (render-proc area) empty)))) + + (send area end-renderers) + + (when (not (empty? legend-entries)) + (send area draw-legend legend-entries)) + + (send area end-plot)) diff --git a/pkgs/plot/private/no-gui/plot3d.rkt b/pkgs/plot/private/no-gui/plot3d.rkt new file mode 100644 index 0000000000..e29ea97514 --- /dev/null +++ b/pkgs/plot/private/no-gui/plot3d.rkt @@ -0,0 +1,150 @@ +#lang racket/base + +(require racket/draw racket/class racket/contract + unstable/contract + pict + unstable/parameter-group + unstable/latent-contract/defthing + "../common/contract.rkt" + "../common/draw.rkt" + "../common/parameters.rkt" + "../common/plot-element.rkt" + "../common/file-type.rkt" + "../plot3d/plot-area.rkt" + "plot3d-utils.rkt") + +(provide (all-defined-out)) + +;; =================================================================================================== +;; Plot to a given device context + +(defproc (plot3d/dc [renderer-tree (treeof (or/c renderer3d? nonrenderer?))] + [dc (is-a?/c dc<%>)] + [x real?] [y real?] [width (>=/c 0)] [height (>=/c 0)] + [#:x-min x-min (or/c rational? #f) #f] [#:x-max x-max (or/c rational? #f) #f] + [#:y-min y-min (or/c rational? #f) #f] [#:y-max y-max (or/c rational? #f) #f] + [#:z-min z-min (or/c rational? #f) #f] [#:z-max z-max (or/c rational? #f) #f] + [#:angle angle real? (plot3d-angle)] [#:altitude altitude real? (plot3d-altitude)] + [#:title title (or/c string? #f) (plot-title)] + [#:x-label x-label (or/c string? #f) (plot-x-label)] + [#:y-label y-label (or/c string? #f) (plot-y-label)] + [#:z-label z-label (or/c string? #f) (plot-z-label)] + [#:legend-anchor legend-anchor anchor/c (plot-legend-anchor)]) void? + (define renderer-list (get-renderer-list renderer-tree)) + (define bounds-rect (get-bounds-rect renderer-list x-min x-max y-min y-max z-min z-max)) + (define-values (x-ticks x-far-ticks y-ticks y-far-ticks z-ticks z-far-ticks) + (get-ticks renderer-list bounds-rect)) + + (parameterize ([plot3d-angle angle] + [plot3d-altitude altitude] + [plot-title title] + [plot-x-label x-label] + [plot-y-label y-label] + [plot-z-label z-label] + [plot-legend-anchor legend-anchor]) + (define area (make-object 3d-plot-area% + bounds-rect x-ticks x-far-ticks y-ticks y-far-ticks z-ticks z-far-ticks + dc x y width height)) + (plot-area area renderer-list))) + +;; =================================================================================================== +;; Plot to a bitmap + +(defproc (plot3d-bitmap [renderer-tree (treeof (or/c renderer3d? nonrenderer?))] + [#:x-min x-min (or/c rational? #f) #f] [#:x-max x-max (or/c rational? #f) #f] + [#:y-min y-min (or/c rational? #f) #f] [#:y-max y-max (or/c rational? #f) #f] + [#:z-min z-min (or/c rational? #f) #f] [#:z-max z-max (or/c rational? #f) #f] + [#:width width exact-positive-integer? (plot-width)] + [#:height height exact-positive-integer? (plot-height)] + [#:angle angle real? (plot3d-angle)] + [#:altitude altitude real? (plot3d-altitude)] + [#:title title (or/c string? #f) (plot-title)] + [#:x-label x-label (or/c string? #f) (plot-x-label)] + [#:y-label y-label (or/c string? #f) (plot-y-label)] + [#:z-label z-label (or/c string? #f) (plot-z-label)] + [#:legend-anchor legend-anchor anchor/c (plot-legend-anchor)] + ) (is-a?/c bitmap%) + ((if (plot-animating?) draw-bitmap draw-bitmap/supersampling) + (λ (dc) + (plot3d/dc renderer-tree dc 0 0 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 pict + +(defproc (plot3d-pict [renderer-tree (treeof (or/c renderer3d? nonrenderer?))] + [#:x-min x-min (or/c rational? #f) #f] [#:x-max x-max (or/c rational? #f) #f] + [#:y-min y-min (or/c rational? #f) #f] [#:y-max y-max (or/c rational? #f) #f] + [#:z-min z-min (or/c rational? #f) #f] [#:z-max z-max (or/c rational? #f) #f] + [#:width width exact-positive-integer? (plot-width)] + [#:height height exact-positive-integer? (plot-height)] + [#:angle angle real? (plot3d-angle)] + [#:altitude altitude real? (plot3d-altitude)] + [#:title title (or/c string? #f) (plot-title)] + [#:x-label x-label (or/c string? #f) (plot-x-label)] + [#:y-label y-label (or/c string? #f) (plot-y-label)] + [#:z-label z-label (or/c string? #f) (plot-z-label)] + [#:legend-anchor legend-anchor anchor/c (plot-legend-anchor)] + ) pict? + (define saved-plot-parameters (plot-parameters)) + (dc (λ (dc x y) + (parameterize/group ([plot-parameters saved-plot-parameters]) + (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 any supported kind of file + +(defproc (plot3d-file [renderer-tree (treeof (or/c renderer3d? nonrenderer?))] + [output (or/c path-string? output-port?)] + [kind (one-of/c 'auto 'png 'jpeg 'xmb 'xpm 'bmp 'ps 'pdf 'svg) 'auto] + [#:x-min x-min (or/c rational? #f) #f] [#:x-max x-max (or/c rational? #f) #f] + [#:y-min y-min (or/c rational? #f) #f] [#:y-max y-max (or/c rational? #f) #f] + [#:z-min z-min (or/c rational? #f) #f] [#:z-max z-max (or/c rational? #f) #f] + [#:width width exact-positive-integer? (plot-width)] + [#:height height exact-positive-integer? (plot-height)] + [#:angle angle real? (plot3d-angle)] + [#:altitude altitude real? (plot3d-altitude)] + [#:title title (or/c string? #f) (plot-title)] + [#:x-label x-label (or/c string? #f) (plot-x-label)] + [#:y-label y-label (or/c string? #f) (plot-y-label)] + [#:z-label z-label (or/c string? #f) (plot-z-label)] + [#:legend-anchor legend-anchor anchor/c (plot-legend-anchor)]) void? + (define real-kind (if (eq? kind 'auto) (detect-image-file-type output) kind)) + (case real-kind + [(png jpeg xbm xpm bmp) + (define bm + (plot3d-bitmap + renderer-tree + #:x-min x-min #:x-max x-max #:y-min y-min #:y-max y-max #:z-min z-min #:z-max z-max + #:width width #:height height #:angle angle #:altitude altitude #:title title + #:x-label x-label #:y-label y-label #:z-label z-label #:legend-anchor legend-anchor)) + (send bm save-file output real-kind (plot-jpeg-quality))] + [(ps pdf svg) + (define dc + (case real-kind + [(ps) (new post-script-dc% + [interactive (plot-ps/pdf-interactive?)] [parent #f] [use-paper-bbox #f] + [as-eps #t] [width width] [height height] [output output])] + [(pdf) (new pdf-dc% + [interactive (plot-ps/pdf-interactive?)] [parent #f] [use-paper-bbox #f] + [width width] [height height] [output output])] + [(svg) (new svg-dc% + [width width] [height height] [output output] [exists 'truncate/replace])])) + (define-values (x-scale y-scale) (send dc get-device-scale)) + (send dc start-doc "Rendering plot") + (send dc start-page) + (plot3d/dc renderer-tree dc 0 0 + (inexact->exact (/ width x-scale)) (inexact->exact (/ height y-scale)) + #: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) + (send dc end-page) + (send dc end-doc)]) + (void)) diff --git a/pkgs/plot/plot2d/clip.rkt b/pkgs/plot/private/plot2d/clip.rkt similarity index 100% rename from pkgs/plot/plot2d/clip.rkt rename to pkgs/plot/private/plot2d/clip.rkt diff --git a/pkgs/plot/plot2d/contour.rkt b/pkgs/plot/private/plot2d/contour.rkt similarity index 100% rename from pkgs/plot/plot2d/contour.rkt rename to pkgs/plot/private/plot2d/contour.rkt diff --git a/pkgs/plot/plot2d/decoration.rkt b/pkgs/plot/private/plot2d/decoration.rkt similarity index 100% rename from pkgs/plot/plot2d/decoration.rkt rename to pkgs/plot/private/plot2d/decoration.rkt diff --git a/pkgs/plot/plot2d/interval.rkt b/pkgs/plot/private/plot2d/interval.rkt similarity index 100% rename from pkgs/plot/plot2d/interval.rkt rename to pkgs/plot/private/plot2d/interval.rkt diff --git a/pkgs/plot/plot2d/line.rkt b/pkgs/plot/private/plot2d/line.rkt similarity index 100% rename from pkgs/plot/plot2d/line.rkt rename to pkgs/plot/private/plot2d/line.rkt diff --git a/pkgs/plot/plot2d/plot-area.rkt b/pkgs/plot/private/plot2d/plot-area.rkt similarity index 100% rename from pkgs/plot/plot2d/plot-area.rkt rename to pkgs/plot/private/plot2d/plot-area.rkt diff --git a/pkgs/plot/plot2d/point.rkt b/pkgs/plot/private/plot2d/point.rkt similarity index 100% rename from pkgs/plot/plot2d/point.rkt rename to pkgs/plot/private/plot2d/point.rkt diff --git a/pkgs/plot/plot2d/rectangle.rkt b/pkgs/plot/private/plot2d/rectangle.rkt similarity index 100% rename from pkgs/plot/plot2d/rectangle.rkt rename to pkgs/plot/private/plot2d/rectangle.rkt diff --git a/pkgs/plot/plot3d/clip.rkt b/pkgs/plot/private/plot3d/clip.rkt similarity index 100% rename from pkgs/plot/plot3d/clip.rkt rename to pkgs/plot/private/plot3d/clip.rkt diff --git a/pkgs/plot/plot3d/contour.rkt b/pkgs/plot/private/plot3d/contour.rkt similarity index 100% rename from pkgs/plot/plot3d/contour.rkt rename to pkgs/plot/private/plot3d/contour.rkt diff --git a/pkgs/plot/plot3d/decoration.rkt b/pkgs/plot/private/plot3d/decoration.rkt similarity index 100% rename from pkgs/plot/plot3d/decoration.rkt rename to pkgs/plot/private/plot3d/decoration.rkt diff --git a/pkgs/plot/plot3d/isosurface.rkt b/pkgs/plot/private/plot3d/isosurface.rkt similarity index 100% rename from pkgs/plot/plot3d/isosurface.rkt rename to pkgs/plot/private/plot3d/isosurface.rkt diff --git a/pkgs/plot/plot3d/line.rkt b/pkgs/plot/private/plot3d/line.rkt similarity index 100% rename from pkgs/plot/plot3d/line.rkt rename to pkgs/plot/private/plot3d/line.rkt diff --git a/pkgs/plot/plot3d/matrix.rkt b/pkgs/plot/private/plot3d/matrix.rkt similarity index 100% rename from pkgs/plot/plot3d/matrix.rkt rename to pkgs/plot/private/plot3d/matrix.rkt diff --git a/pkgs/plot/plot3d/plot-area.rkt b/pkgs/plot/private/plot3d/plot-area.rkt similarity index 100% rename from pkgs/plot/plot3d/plot-area.rkt rename to pkgs/plot/private/plot3d/plot-area.rkt diff --git a/pkgs/plot/plot3d/point.rkt b/pkgs/plot/private/plot3d/point.rkt similarity index 100% rename from pkgs/plot/plot3d/point.rkt rename to pkgs/plot/private/plot3d/point.rkt diff --git a/pkgs/plot/plot3d/rectangle.rkt b/pkgs/plot/private/plot3d/rectangle.rkt similarity index 100% rename from pkgs/plot/plot3d/rectangle.rkt rename to pkgs/plot/private/plot3d/rectangle.rkt diff --git a/pkgs/plot/plot3d/shape.rkt b/pkgs/plot/private/plot3d/shape.rkt similarity index 100% rename from pkgs/plot/plot3d/shape.rkt rename to pkgs/plot/private/plot3d/shape.rkt diff --git a/pkgs/plot/plot3d/surface.rkt b/pkgs/plot/private/plot3d/surface.rkt similarity index 100% rename from pkgs/plot/plot3d/surface.rkt rename to pkgs/plot/private/plot3d/surface.rkt diff --git a/pkgs/plot/scribblings/common.rkt b/pkgs/plot/scribblings/common.rkt index f11c568114..478403c3df 100644 --- a/pkgs/plot/scribblings/common.rkt +++ b/pkgs/plot/scribblings/common.rkt @@ -10,7 +10,7 @@ unstable/contract) plot plot/utils - plot/doc + plot/private/doc unstable/latent-contract/defthing) (provide (all-defined-out) @@ -23,19 +23,17 @@ plot/utils unstable/contract)) (all-from-out plot) - (all-from-out plot/doc) + (all-from-out plot/private/doc) (all-from-out plot/utils) doc-apply) -(define (plot-name) "PLoT") +(define (plot-name) "Plot") (define plot-eval (let ([eval (make-base-eval)]) (eval '(begin (require racket/math racket/match racket/list racket/draw racket/class - (rename-in (except-in plot plot plot3d) - [plot-pict plot] - [plot3d-pict plot3d]) + plot/pict plot/utils))) eval)) diff --git a/pkgs/plot/scribblings/compat.scrbl b/pkgs/plot/scribblings/compat.scrbl index 295f160751..d2b8f0af80 100644 --- a/pkgs/plot/scribblings/compat.scrbl +++ b/pkgs/plot/scribblings/compat.scrbl @@ -4,7 +4,8 @@ plot/compat) plot/compat (only-in unstable/latent-contract/defthing - doc-apply)) + doc-apply) + (only-in "common.rkt" plot-name)) @title[#:tag "compat"]{Compatibility Module} @@ -12,7 +13,7 @@ @defmodule[plot/compat] -This module provides an interface compatible with PLoT 5.1.3 and earlier. +This module provides an interface compatible with @(plot-name) 5.1.3 and earlier. @bold{Do not use both @racketmodname[plot] and @racketmodname[plot/compat] in the same module.} It is tempting to try it, to get both the new features and comprehensive backward compatibility. diff --git a/pkgs/plot/scribblings/contracts.scrbl b/pkgs/plot/scribblings/contracts.scrbl index de2027c5c5..3f1d53b5e2 100644 --- a/pkgs/plot/scribblings/contracts.scrbl +++ b/pkgs/plot/scribblings/contracts.scrbl @@ -3,10 +3,11 @@ @(require "common.rkt" (for-label (rename-in racket/draw [font-family/c ff/c]))) -@declare-exporting[plot/utils] - @title[#:tag "contracts"]{Plot Contracts} +@declare-exporting[plot/utils] +@defmodule*/no-declare[(plot/utils) #:link-target? #f] + @section{Plot Element Contracts} @defproc[(renderer2d? [value any/c]) boolean?]{ diff --git a/pkgs/plot/scribblings/custom.scrbl b/pkgs/plot/scribblings/custom.scrbl index aaeae695a4..c0bcf1b5af 100644 --- a/pkgs/plot/scribblings/custom.scrbl +++ b/pkgs/plot/scribblings/custom.scrbl @@ -5,8 +5,7 @@ @title[#:tag "custom"]{Custom Plot Elements} @declare-exporting[plot/utils] - -The following API is provided by @racketmodname[plot/utils]. +@defmodule*/no-declare[(plot/utils plot/typed/utils) #:link-target? #f] @section{Plot Elements} diff --git a/pkgs/plot/scribblings/intro.scrbl b/pkgs/plot/scribblings/intro.scrbl index eec524cb97..09e552d04c 100644 --- a/pkgs/plot/scribblings/intro.scrbl +++ b/pkgs/plot/scribblings/intro.scrbl @@ -4,6 +4,8 @@ @title[#:tag "intro"]{Introduction} +@defmodule*/no-declare[(plot plot/typed) #:link-target? #f] + @section{Plotting 2D Graphs} To plot a one-input, real-valued function, do something like @@ -11,12 +13,12 @@ To plot a one-input, real-valued function, do something like @racketinput[(require plot)] @interaction[#:eval plot-eval (plot (function sin (- pi) pi #:label "y = sin(x)"))] -(If you're not using DrRacket, start with +The first argument to @(racket function) is the function to be plotted, and the @(racket #:label) argument becomes the name of the function in the legend. + +If you're not using DrRacket, start with @racketblock[(require plot) (plot-new-window? #t)] -to open each plot in a new window.) - -The first argument to @(racket function) is the function to be plotted, and the @(racket #:label) argument becomes the name of the function in the legend. +to open each plot in a new window. @section{Terminology} diff --git a/pkgs/plot/scribblings/nonrenderer.scrbl b/pkgs/plot/scribblings/nonrenderer.scrbl index 0a83a54892..28b27f2a72 100644 --- a/pkgs/plot/scribblings/nonrenderer.scrbl +++ b/pkgs/plot/scribblings/nonrenderer.scrbl @@ -3,6 +3,7 @@ @(require "common.rkt") @declare-exporting[plot] +@defmodule*/no-declare[(plot plot/typed) #:link-target? #f] @title[#:tag "nonrenderer"]{Nonrenderers} diff --git a/pkgs/plot/scribblings/params.scrbl b/pkgs/plot/scribblings/params.scrbl index 99609d179b..e7a3a5b40c 100644 --- a/pkgs/plot/scribblings/params.scrbl +++ b/pkgs/plot/scribblings/params.scrbl @@ -2,10 +2,11 @@ @(require "common.rkt") -@declare-exporting[plot] - @title[#:tag "params"]{Plot and Renderer Parameters} +@declare-exporting[plot] +@defmodule*/no-declare[(plot plot/typed) #:link-target? #f] + @section{Compatibility} @doc-apply[plot-deprecation-warnings?]{ @@ -37,7 +38,7 @@ If @(racket #t), @(racket plot-file) and @(racket plot3d-file) open a dialog whe @doc-apply[plot-background]{ The plot foreground and background color. That both are @(racket 0) by default is not a mistake: for foreground colors, @(racket 0) is interpreted as black; for background colors, @(racket 0) is interpreted as white. -See @(racket ->pen-color) and @(racket ->brush-color) for details on how PLoT interprets integer colors.} +See @(racket ->pen-color) and @(racket ->brush-color) for details on how @(plot-name) interprets integer colors.} @doc-apply[plot-foreground-alpha] @doc-apply[plot-background-alpha]{The opacity of the background and foreground colors.} @doc-apply[plot-font-size]{The font size of the title, axis labels, tick labels, and other labels, in drawing units.} @@ -93,7 +94,7 @@ Use these along with @racket[x-axis] and @racket[y-axis] if you want axes that i } @doc-apply[plot-animating?]{ -When @(racket #t), certain renderers draw simplified plots to speed up drawing. PLoT sets it to @(racket #t), for example, when a user is clicking and dragging a 3D plot to rotate it. +When @(racket #t), certain renderers draw simplified plots to speed up drawing. @(plot-name) sets it to @(racket #t), for example, when a user is clicking and dragging a 3D plot to rotate it. } @doc-apply[animated-samples]{ diff --git a/pkgs/plot/scribblings/plot.scrbl b/pkgs/plot/scribblings/plot.scrbl index 8bc61c2608..8ff0249516 100644 --- a/pkgs/plot/scribblings/plot.scrbl +++ b/pkgs/plot/scribblings/plot.scrbl @@ -17,22 +17,23 @@ Typed Racket users should use It includes many common kinds already, such as scatter plots, line plots, contour plots, histograms, and 3D surfaces and isosurfaces. Thanks to Racket's excellent multiple-backend drawing library, @(plot-name) can render plots as manipulatable images in DrRacket, as bitmaps in slideshows, as PNG, PDF, PS and SVG files, or on any device context. +For non-GUI uses, see @racketmodname[plot/no-gui]. +For REPL-like environments outside of DrRacket (including Scribble manuals) in particular, see @racketmodname[plot/pict] and @racketmodname[plot/bitmap]. + @bold{A note on backward compatibility.} @(plot-name) has undergone a major rewrite between versions 5.1.3 and 5.2. -Many programs written using PLoT 5.1.3 and earlier will still compile, run and generate plots. +Many programs written using @(plot-name) 5.1.3 and earlier will still compile, run and generate plots. Some programs will not. Most programs use deprecated functions such as @(racket mix), @(racket line) and @(racket surface). These functions still exist for backward compatibility, but are deprecated and may be removed in the future. -If you have code written for PLoT 5.1.3 or earlier, please see @secref["porting"] (and possibly @secref["compat"]). +If you have code written for @(plot-name) 5.1.3 or earlier, please see @secref["porting"] (and possibly @secref["compat"]). @table-of-contents[] @include-section["intro.scrbl"] -@include-section["plot2d.scrbl"] +@include-section["plotting.scrbl"] @include-section["renderer2d.scrbl"] -@include-section["plot3d.scrbl"] - @include-section["renderer3d.scrbl"] @include-section["nonrenderer.scrbl"] diff --git a/pkgs/plot/scribblings/plot2d.scrbl b/pkgs/plot/scribblings/plot2d.scrbl deleted file mode 100644 index e72ec8095e..0000000000 --- a/pkgs/plot/scribblings/plot2d.scrbl +++ /dev/null @@ -1,96 +0,0 @@ -#lang scribble/manual - -@(require (for-label slideshow) - "common.rkt") - -@declare-exporting[plot] - -@title[#:tag "plot2d"]{2D Plot Procedures} - -@defproc[(plot [renderer-tree (treeof (or/c renderer2d? nonrenderer?))] - [#:x-min x-min (or/c rational? #f) #f] [#:x-max x-max (or/c rational? #f) #f] - [#:y-min y-min (or/c rational? #f) #f] [#:y-max y-max (or/c rational? #f) #f] - [#:width width exact-positive-integer? (plot-width)] - [#:height height exact-positive-integer? (plot-height)] - [#:title title (or/c string? #f) (plot-title)] - [#:x-label x-label (or/c string? #f) (plot-x-label)] - [#:y-label y-label (or/c string? #f) (plot-y-label)] - [#:legend-anchor legend-anchor anchor/c (plot-legend-anchor)] - [#:out-file out-file (or/c path-string? output-port? #f) #f] - [#:out-kind out-kind (one-of/c 'auto 'png 'jpeg 'xmb 'xpm 'bmp 'ps 'pdf 'svg) 'auto] - ) (or/c (is-a?/c image-snip%) void?)]{ -Plots a 2D renderer or list of renderers (or more generally, a tree of renderers), as returned by @(racket points), @(racket function), @(racket contours), @(racket discrete-histogram), and others. - -By default, @(racket plot) produces a Racket value that is displayed as an image and can be manipulated like any other value. -For example, they may be put in lists: - -@interaction[#:eval plot-eval - (parameterize ([plot-width 150] - [plot-height 150] - [plot-x-label #f] - [plot-y-label #f]) - (list (plot (function sin (- pi) pi)) - (plot (function sqr -2 2))))] - -When the parameter @(racket plot-new-window?) is @(racket #t), @(racket plot) opens a new window to display the plot and returns @(racket (void)). - -When @(racket #:out-file) is given, @(racket plot) writes the plot to a file using @(racket plot-file) as well as returning an @(racket image-snip%) or opening a new window. - -When given, the @(racket x-min), @(racket x-max), @(racket y-min) and @(racket y-max) arguments determine the bounds of the plot, but not the bounds of the renderers. For example, - -@interaction[#:eval plot-eval -(plot (function (λ (x) (sin (* 4 x))) -1 1) - #:x-min -1.5 #:x-max 1.5 #:y-min -1.5 #:y-max 1.5)] - -Here, the renderer draws in [-1,1] × [-1,1], but the plot area is [-1.5,1.5] × [-1.5,1.5]. - -@bold{Deprecated keywords.} The @(racket #:fgcolor) and @(racket #:bgcolor) keyword arguments are currently supported for backward compatibility, but may not be in the future. -Please set the @(racket plot-foreground) and @(racket plot-background) parameters instead of using these keyword arguments. -The @(racket #:lncolor) keyword argument is also accepted for backward compatibility but deprecated. It does nothing. -} - -@deftogether[ -(@defproc[(plot-file [renderer-tree (treeof (or/c renderer2d? nonrenderer?))] - [output (or/c path-string? output-port?)] - [kind (one-of/c 'auto 'png 'jpeg 'xmb 'xpm 'bmp 'ps 'pdf 'svg) 'auto] - [#: ] ...) void?] - @defproc[(plot-pict [renderer-tree (treeof (or/c renderer2d? nonrenderer?))] ...) pict?] - @defproc[(plot-bitmap [renderer-tree (treeof (or/c renderer2d? nonrenderer?))] ...) (is-a?/c bitmap%)] - @defproc[(plot-snip [renderer-tree (treeof (or/c renderer2d? nonrenderer?))] ...) (is-a?/c image-snip%)] - @defproc[(plot-frame [renderer-tree (treeof (or/c renderer2d? nonrenderer?))] ...) (is-a?/c frame%)])]{ -Plot to different backends. Each of these procedures has the same keyword arguments as @(racket plot), except for deprecated keywords. - -Use @(racket plot-file) to save a plot to a file. -When creating a JPEG file, the parameter @(racket plot-jpeg-quality) determines its quality. -When creating a PostScript or PDF file, the parameter @(racket plot-ps/pdf-interactive?) determines whether the user is given a dialog for setting printing parameters. -(See @(racket post-script-dc%) and @(racket pdf-dc%).) -When @(racket kind) is @(racket 'auto), @(racket plot-file) tries to determine the kind of file to write from the file name extension. - -Use @(racket plot-pict) to plot to a slideshow @(racket pict). For example, -@racketmod[slideshow -(require plot) - -(plot-font-size (current-font-size)) -(plot-width (current-para-width)) -(plot-height 600) -(plot-background-alpha 1/2) - -(slide - #:title "A 2D Parabola" - (plot-pict (function sqr -1 1 #:label "y = x^2")))] -creates a slide containing a 2D plot of a parabola. - -Use @(racket plot-bitmap) to create a @(racket bitmap%). - -Use @(racket plot-frame) to create a @(racket frame%) regardless of the value of @(racket plot-new-window?). The frame is initially hidden. - -Use @(racket plot-snip) to create an interactive @(racket image-snip%) regardless of the value of @(racket plot-new-window?). -} - -@doc-apply[plot/dc]{ -Plots to an arbitrary device context, in the rectangle with width @(racket width), height @(racket height), and upper-left corner @(racket x),@(racket y). - -Every @secref{plot2d} procedure is defined in terms of @(racket plot/dc). - -Use this if you need to continually update a plot on a @(racket canvas%), or to create other @(racket plot)-like functions with different backends. -} diff --git a/pkgs/plot/scribblings/plot3d.scrbl b/pkgs/plot/scribblings/plot3d.scrbl deleted file mode 100644 index b2aa932c36..0000000000 --- a/pkgs/plot/scribblings/plot3d.scrbl +++ /dev/null @@ -1,64 +0,0 @@ -#lang scribble/manual - -@(require "common.rkt") - -@declare-exporting[plot] - -@title[#:tag "plot3d"]{3D Plot Procedures} - -Each 3D plot procedure corresponds with a @(secref "plot2d") procedure. Each behaves the same way as its corresponding 2D procedure, but takes the additional keyword arguments @(racket #:z-min), @(racket #:z-max), @(racket #:angle), @(racket #:altitude) and @(racket #:z-label). - -@defproc[(plot3d [renderer-tree (treeof (or/c renderer3d? nonrenderer?))] - [#:x-min x-min (or/c rational? #f) #f] [#:x-max x-max (or/c rational? #f) #f] - [#:y-min y-min (or/c rational? #f) #f] [#:y-max y-max (or/c rational? #f) #f] - [#:z-min z-min (or/c rational? #f) #f] [#:z-max z-max (or/c rational? #f) #f] - [#:width width exact-positive-integer? (plot-width)] - [#:height height exact-positive-integer? (plot-height)] - [#:angle angle real? (plot3d-angle)] - [#:altitude altitude real? (plot3d-altitude)] - [#:title title (or/c string? #f) (plot-title)] - [#:x-label x-label (or/c string? #f) (plot-x-label)] - [#:y-label y-label (or/c string? #f) (plot-y-label)] - [#:z-label z-label (or/c string? #f) (plot-z-label)] - [#:legend-anchor legend-anchor anchor/c (plot-legend-anchor)] - [#:out-file out-file (or/c path-string? output-port? #f) #f] - [#:out-kind out-kind (one-of/c 'auto 'png 'jpeg 'xmb 'xpm 'bmp 'ps 'pdf 'svg) 'auto] - ) (or/c (is-a?/c image-snip%) void?)]{ -This procedure corresponds with @(racket plot). It plots a 3D renderer or list of renderers (or more generally, a tree of renderers), as returned by @(racket points3d), @(racket parametric3d), @(racket surface3d), @(racket isosurface3d), and others. - -When the parameter @(racket plot-new-window?) is @(racket #t), @(racket plot3d) opens a new window to display the plot and returns @(racket (void)). - -When @(racket #:out-file) is given, @(racket plot3d) writes the plot to a file using @(racket plot3d-file) as well as returning a @(racket image-snip%) or opening a new window. - -When given, the @(racket x-min), @(racket x-max), @(racket y-min), @(racket y-max), @(racket z-min) and @(racket z-max) arguments determine the bounds of the plot, but not the bounds of the renderers. - -@bold{Deprecated keywords.} The @(racket #:fgcolor) and @(racket #:bgcolor) keyword arguments are currently supported for backward compatibility, but may not be in the future. -Please set the @(racket plot-foreground) and @(racket plot-background) parameters instead of using these keyword arguments. -The @(racket #:lncolor) keyword argument is also accepted for backward compatibility but deprecated. It does nothing. - -The @(racket #:az) and @(racket #:alt) keyword arguments are backward-compatible, deprecated aliases for @(racket #:angle) and @(racket #:altitude), respectively. -} - -@deftogether[ -(@defproc[(plot3d-file [renderer-tree (treeof (or/c renderer3d? nonrenderer?))] - [output (or/c path-string? output-port?)] - [kind (one-of/c 'auto 'png 'jpeg 'xmb 'xpm 'bmp 'ps 'pdf 'svg) 'auto] - [#: ] ...) void?] - @defproc[(plot3d-pict [renderer-tree (treeof (or/c renderer3d? nonrenderer?))] ...) pict?] - @defproc[(plot3d-bitmap [renderer-tree (treeof (or/c renderer3d? nonrenderer?))] ...) (is-a?/c bitmap%)] - @defproc[(plot3d-snip [renderer-tree (treeof (or/c renderer3d? nonrenderer?))] ...) (is-a?/c image-snip%)] - @defproc[(plot3d-frame [renderer-tree (treeof (or/c renderer3d? nonrenderer?))] ...) (is-a?/c frame%)])]{ -Plot to different backends. Each of these procedures has the same keyword arguments as @(racket plot3d), except for deprecated keywords. - -These procedures correspond with @(racket plot-file), @(racket plot-pict), @(racket plot-bitmap), @(racket plot-snip) and @(racket plot-frame). -} - -@doc-apply[plot3d/dc]{ -Plots to an arbitrary device context, in the rectangle with width @(racket width), height @(racket height), and upper-left corner @(racket x),@(racket y). - -Every @secref{plot3d} procedure is defined in terms of @(racket plot3d/dc). - -Use this if you need to continually update a plot on a @(racket canvas%), or to create other @(racket plot3d)-like functions with different backends. - -This procedure corresponds with @(racket plot/dc). -} diff --git a/pkgs/plot/scribblings/plotting.scrbl b/pkgs/plot/scribblings/plotting.scrbl new file mode 100644 index 0000000000..a63b51d66c --- /dev/null +++ b/pkgs/plot/scribblings/plotting.scrbl @@ -0,0 +1,221 @@ +#lang scribble/manual + +@(require (for-label slideshow + racket/gui/dynamic) + "common.rkt") + +@declare-exporting[plot] + +@title[#:tag "plotting"]{2D and 3D Plotting Procedures} + +The plotting procedures exported by @racketmodname[plot/no-gui] produce @racket[bitmap%] and @racket[pict] instances, and write to files. +They do not require @racketmodname[racket/gui], so they work in headless environments; for example, a Linux terminal with @tt{DISPLAY} unset. + +The @racketmodname[plot] module re-exports everything exported by @racketmodname[plot/no-gui], as well as @racket[plot], @racket[plot3d], and other procedures that create interactive plots and plot frames. +Interactive plotting procedures can always be imported, but fail when called if there is no working display or @racketmodname[racket/gui] is not present. + +Each 3D plotting procedure behaves the same way as its corresponding 2D procedure, but takes the additional keyword arguments @(racket #:z-min), @(racket #:z-max), @(racket #:angle), @(racket #:altitude) and @(racket #:z-label). + +@section{GUI Plotting Procedures} + +@defmodule*/no-declare[(plot plot/typed) #:link-target? #f] + +@defproc[(plot [renderer-tree (treeof (or/c renderer2d? nonrenderer?))] + [#:x-min x-min (or/c rational? #f) #f] [#:x-max x-max (or/c rational? #f) #f] + [#:y-min y-min (or/c rational? #f) #f] [#:y-max y-max (or/c rational? #f) #f] + [#:width width exact-positive-integer? (plot-width)] + [#:height height exact-positive-integer? (plot-height)] + [#:title title (or/c string? #f) (plot-title)] + [#:x-label x-label (or/c string? #f) (plot-x-label)] + [#:y-label y-label (or/c string? #f) (plot-y-label)] + [#:legend-anchor legend-anchor anchor/c (plot-legend-anchor)] + [#:out-file out-file (or/c path-string? output-port? #f) #f] + [#:out-kind out-kind (one-of/c 'auto 'png 'jpeg 'xmb 'xpm 'bmp 'ps 'pdf 'svg) 'auto] + ) (or/c (is-a?/c image-snip%) void?)]{ +Plots a 2D renderer or list of renderers (or more generally, a tree of renderers), as returned by @(racket points), @(racket function), @(racket contours), @(racket discrete-histogram), and others. + +By default, @(racket plot) produces a Racket value that is displayed as an image and can be manipulated like any other value. +For example, they may be put in lists: + +@interaction[#:eval plot-eval + (parameterize ([plot-width 150] + [plot-height 150] + [plot-x-label #f] + [plot-y-label #f]) + (list (plot (function sin (- pi) pi)) + (plot (function sqr -2 2))))] + +When the parameter @(racket plot-new-window?) is @(racket #t), @(racket plot) opens a new window to display the plot and returns @(racket (void)). + +When @(racket #:out-file) is given, @(racket plot) writes the plot to a file using @(racket plot-file) as well as returning an @(racket image-snip%) or opening a new window. + +When given, the @(racket x-min), @(racket x-max), @(racket y-min) and @(racket y-max) arguments determine the bounds of the plot, but not the bounds of the renderers. For example, + +@interaction[#:eval plot-eval +(plot (function (λ (x) (sin (* 4 x))) -1 1) + #:x-min -1.5 #:x-max 1.5 #:y-min -1.5 #:y-max 1.5)] + +Here, the renderer draws in [-1,1] × [-1,1], but the plot area is [-1.5,1.5] × [-1.5,1.5]. + +@bold{Deprecated keywords.} The @(racket #:fgcolor) and @(racket #:bgcolor) keyword arguments are currently supported for backward compatibility, but may not be in the future. +Please set the @(racket plot-foreground) and @(racket plot-background) parameters instead of using these keyword arguments. +The @(racket #:lncolor) keyword argument is also accepted for backward compatibility but deprecated. It does nothing. +} + +@defproc[(plot3d [renderer-tree (treeof (or/c renderer3d? nonrenderer?))] + [#:x-min x-min (or/c rational? #f) #f] [#:x-max x-max (or/c rational? #f) #f] + [#:y-min y-min (or/c rational? #f) #f] [#:y-max y-max (or/c rational? #f) #f] + [#:z-min z-min (or/c rational? #f) #f] [#:z-max z-max (or/c rational? #f) #f] + [#:width width exact-positive-integer? (plot-width)] + [#:height height exact-positive-integer? (plot-height)] + [#:angle angle real? (plot3d-angle)] + [#:altitude altitude real? (plot3d-altitude)] + [#:title title (or/c string? #f) (plot-title)] + [#:x-label x-label (or/c string? #f) (plot-x-label)] + [#:y-label y-label (or/c string? #f) (plot-y-label)] + [#:z-label z-label (or/c string? #f) (plot-z-label)] + [#:legend-anchor legend-anchor anchor/c (plot-legend-anchor)] + [#:out-file out-file (or/c path-string? output-port? #f) #f] + [#:out-kind out-kind (one-of/c 'auto 'png 'jpeg 'xmb 'xpm 'bmp 'ps 'pdf 'svg) 'auto] + ) (or/c (is-a?/c image-snip%) void?)]{ +Plots a 3D renderer or list of renderers (or more generally, a tree of renderers), as returned by @(racket points3d), @(racket parametric3d), @(racket surface3d), @(racket isosurface3d), and others. + +When the parameter @(racket plot-new-window?) is @(racket #t), @(racket plot3d) opens a new window to display the plot and returns @(racket (void)). + +When @(racket #:out-file) is given, @(racket plot3d) writes the plot to a file using @(racket plot3d-file) as well as returning a @(racket image-snip%) or opening a new window. + +When given, the @(racket x-min), @(racket x-max), @(racket y-min), @(racket y-max), @(racket z-min) and @(racket z-max) arguments determine the bounds of the plot, but not the bounds of the renderers. + +@bold{Deprecated keywords.} The @(racket #:fgcolor) and @(racket #:bgcolor) keyword arguments are currently supported for backward compatibility, but may not be in the future. +Please set the @(racket plot-foreground) and @(racket plot-background) parameters instead of using these keyword arguments. +The @(racket #:lncolor) keyword argument is also accepted for backward compatibility but deprecated. It does nothing. + +The @(racket #:az) and @(racket #:alt) keyword arguments are backward-compatible, deprecated aliases for @(racket #:angle) and @(racket #:altitude), respectively. +} + +@defproc[(plot-snip [ ] ...) + (is-a?/c image-snip%)] +@defproc[(plot3d-snip [ ] ...) + (is-a?/c image-snip%)] +@defproc[(plot-frame [ ] ...) + (is-a?/c frame%)] +@defproc[(plot3d-frame [ ] ...) + (is-a?/c frame%)]{ +Plot to different GUI backends. +These procedures accept the same arguments as @(racket plot) and @(racket plot3d), except deprecated keywords, and @racket[#:out-file] and @racket[#:out-kind]. + +Use @(racket plot-frame) and @(racket plot3d-frame) to create a @(racket frame%) regardless of the value of @(racket plot-new-window?). The frame is initially hidden. + +Use @(racket plot-snip) and @(racket plot3d-snip) to create an interactive @(racket image-snip%) regardless of the value of @(racket plot-new-window?). +} + +@section{Non-GUI Plotting Procedures} + +@defmodule*/no-declare[(plot/no-gui plot/typed/no-gui)] + +@defproc[(plot-file [renderer-tree (treeof (or/c renderer2d? nonrenderer?))] + [output (or/c path-string? output-port?)] + [kind (one-of/c 'auto 'png 'jpeg 'xmb 'xpm 'bmp 'ps 'pdf 'svg) 'auto] + [#: ] ...) + void?] +@defproc[(plot3d-file [renderer-tree (treeof (or/c renderer3d? nonrenderer?))] + [output (or/c path-string? output-port?)] + [kind (one-of/c 'auto 'png 'jpeg 'xmb 'xpm 'bmp 'ps 'pdf 'svg) 'auto] + [#: ] ...) + void?] +@defproc[(plot-pict [ ] ...) + pict?] +@defproc[(plot3d-pict [ ] ...) + pict?] +@defproc[(plot-bitmap [ ] ...) + (is-a?/c bitmap%)] +@defproc[(plot3d-bitmap [ ] ...) + (is-a?/c bitmap%)]{ +Plot to different non-GUI backends. +These procedures accept the same arguments as @(racket plot) and @(racket plot3d), except deprecated keywords, and @racket[#:out-file] and @racket[#:out-kind]. + +Use @(racket plot-file) or @(racket plot3d-file) to save a plot to a file. +When creating a JPEG file, the parameter @(racket plot-jpeg-quality) determines its quality. +When creating a PostScript or PDF file, the parameter @(racket plot-ps/pdf-interactive?) determines whether the user is given a dialog to set printing parameters. +(See @(racket post-script-dc%) and @(racket pdf-dc%).) +When @(racket kind) is @(racket 'auto), @(racket plot-file) and @(racket plot3d-file) try to determine from the file name extension the kind of file to write. + +Use @(racket plot-pict) or @(racket plot3d-pict) to create a @(racket pict). +For example, this program creates a slide containing a 2D plot of a parabola: +@racketmod[slideshow +(require plot) + +(plot-font-size (current-font-size)) +(plot-width (current-para-width)) +(plot-height 600) +(plot-background-alpha 1/2) + +(slide + #:title "A 2D Parabola" + (plot-pict (function sqr -1 1 #:label "y = x^2")))] + +Use @(racket plot-bitmap) or @(racket plot3d-bitmap) to create a @(racket bitmap%). +} + +@defproc[(plot/dc [renderer-tree (treeof (or/c renderer2d? nonrenderer?))] + [dc (is-a?/c dc<%>)] + [x real?] + [y real?] + [width (>=/c 0)] + [height (>=/c 0)] + [#: ] ...) + void?] +@defproc[(plot3d/dc [renderer-tree (treeof (or/c renderer3d? nonrenderer?))] + [dc (is-a?/c dc<%>)] + [x real?] + [y real?] + [width (>=/c 0)] + [height (>=/c 0)] + [#: ] ...) + void?]{ +Plot to an arbitrary device context, in the rectangle with width @(racket width), height @(racket height), and upper-left corner @(racket x),@(racket y). +These procedures accept the same arguments as @(racket plot) and @(racket plot3d), except deprecated keywords, and @racket[#:out-file] and @racket[#:out-kind]. + +Use these if you need to continually update a plot on a @(racket canvas%), or to create other @(racket plot)-like functions with different backends. +} + +@section{Pict-Plotting Work-a-Likes} + +@declare-exporting[plot/pict] +@defmodule*/no-declare[(plot/pict plot/typed/pict)] + +When setting up an evaluator for a Scribble manual, require @racketmodname[plot/pict] instead of @racketmodname[plot]. +Evaluation will produce picts instead of snips, which scale nicely in PDF-rendered documentation. + +For example, this is how the evaluator for the @(plot-name) documentation is defined: +@racketblock[ +(define plot-eval + (let ([eval (make-base-eval)]) + (eval '(begin + (require racket/math + racket/match + racket/list + racket/draw + racket/class + plot/pict + plot/utils))) + eval))] + +If you use @racket[(require (for-label plot))], links in example code should resolve to documentation for the functions exported by @racketmodname[plot]. + +@defproc[(plot [ ] ...) pict?] +@defproc[(plot3d [ ] ...) pict?]{ +Like the functions of the same name exported from @racketmodname[plot], but these produce @racket[pict] instances instead of interactive snips. +} + +@section{Bitmap-Plotting Work-a-Likes} + +@declare-exporting[plot/bitmap] +@defmodule*/no-declare[(plot/bitmap plot/typed/bitmap)] + +When plotting in an environment where @racket[bitmap%] instances can be shown but @racket[snip%] instances cannot (for example, on a web page that evaluates Racket code), require @racketmodname[plot/bitmap] instead of @racketmodname[plot]. + +@defproc[(plot [ ] ...) (is-a?/c bitmap%)] +@defproc[(plot3d [ ] ...) (is-a?/c bitmap%)]{ +Like the functions of the same name exported from @racketmodname[plot], but these produce @racket[bitmap%] instances instead of interactive snips. +} diff --git a/pkgs/plot/scribblings/porting.scrbl b/pkgs/plot/scribblings/porting.scrbl index 8457dcff0b..b851900b01 100644 --- a/pkgs/plot/scribblings/porting.scrbl +++ b/pkgs/plot/scribblings/porting.scrbl @@ -2,27 +2,25 @@ @(require "common.rkt") -@declare-exporting[plot] - -@title[#:tag "porting"]{Porting From PLoT <= 5.1.3} +@title[#:tag "porting"]{Porting From @(plot-name) <= 5.1.3} If it seems porting will take too long, you can get your old code running more quickly using the @secref["compat"]. -The update from PLoT version 5.1.3 to 5.2 introduces a few incompatibilities: +The update from @(plot-name) version 5.1.3 to 5.2 introduces a few incompatibilities: @itemlist[ - @item{PLoT now allows plot elements to request plot area bounds, and finds bounds large enough to fit all plot elements. + @item{@(plot-name) now allows plot elements to request plot area bounds, and finds bounds large enough to fit all plot elements. The old default plot area bounds of [-5,5] × [-5,5] cannot be made consistent with the improved behavior; the default bounds are now "no bounds". This causes code such as @(racket (plot (line sin))), which does not state bounds, to fail.} @item{The @(racket #:width) and @(racket #:style) keyword arguments to @(racket vector-field) have been replaced by @(racket #:line-width) and @(racket #:scale) to be consistent with other functions.} @item{The @(racket plot) function no longer takes a @(racket ((is-a?/c 2d-view%) . -> . void?)) as an argument, but a @(racket (treeof renderer2d?)). The argument change in @(racket plot3d) is similar. - This should not affect most code because PLoT encourages regarding these data types as black boxes.} + This should not affect most code because @(plot-name) encourages regarding these data types as black boxes.} @item{The @(racket plot-extend) module no longer exists.} @item{The @racket[fit] function and @racket[fit-result] struct type have been removed.} ] -This section of the PLoT manual will help you port code written for PLoT 5.1.3 and earlier to the most recent PLoT. +This section of the @(plot-name) manual will help you port code written for @(plot-name) 5.1.3 and earlier to the most recent @(plot-name). There are four main tasks: @itemlist[ @item{Replace deprecated functions.} @@ -50,7 +48,7 @@ The number of contour levels is therefore some number between @(racket 4) and @( The safest way to ensure that @(racket plot) can determine bounds for the plot area is to add @(racket #:x-min -5 #:x-max 5 #:y-min -5 #:y-max 5) to every call to @(racket plot). Similarly, add @(racket #:x-min -5 #:x-max 5 #:y-min -5 #:y-max 5 #:z-min -5 #:z-max 5) to every call to @(racket plot3d). -Because PLoT is now smarter about choosing bounds, there are better ways. For example, suppose you have +Because @(plot-name) is now smarter about choosing bounds, there are better ways. For example, suppose you have @interaction[#:eval plot-eval (eval:alts @@ -106,13 +104,16 @@ For example, if @(racket vs) is the list of vectors, send @(racket (map (λ (v) Chances are, if you used @(racket plot-extend), you no longer need it. The canonical @(racket plot-extend) example used to be a version of @(racket line) that drew dashed lines. -Every line-drawing function in PLoT now has a @(racket #:style) or @(racket #:line-style) keyword argument. +Every line-drawing function in @(plot-name) now has a @(racket #:style) or @(racket #:line-style) keyword argument. -The rewritten PLoT will eventually have a similar extension mechanism. +The rewritten @(plot-name) will eventually have a similar extension mechanism. @section{Deprecated Functions} +@declare-exporting[plot] +@defmodule*/no-declare[(plot) #:link-target? #f] + The following functions exist for backward compatibility, but may be removed in the future. Set @(racket (plot-deprecation-warnings? #t)) to be alerted the first time each is used. diff --git a/pkgs/plot/scribblings/renderer2d.scrbl b/pkgs/plot/scribblings/renderer2d.scrbl index 96c8acf966..1eb31c6162 100644 --- a/pkgs/plot/scribblings/renderer2d.scrbl +++ b/pkgs/plot/scribblings/renderer2d.scrbl @@ -2,10 +2,11 @@ @(require "common.rkt") -@declare-exporting[plot] - @title[#:tag "renderer2d"]{2D Renderers} +@declare-exporting[plot] +@defmodule*/no-declare[(plot plot/typed) #:link-target? #f] + @section[#:tag "renderer2d-function-arguments"]{2D Renderer Function Arguments} Functions that return 2D renderers always have these kinds of arguments: diff --git a/pkgs/plot/scribblings/renderer3d.scrbl b/pkgs/plot/scribblings/renderer3d.scrbl index e704069e3e..43fb7d49ec 100644 --- a/pkgs/plot/scribblings/renderer3d.scrbl +++ b/pkgs/plot/scribblings/renderer3d.scrbl @@ -2,10 +2,11 @@ @(require "common.rkt") -@declare-exporting[plot] - @title[#:tag "renderer3d"]{3D Renderers} +@declare-exporting[plot] +@defmodule*/no-declare[(plot plot/typed) #:link-target? #f] + @section{3D Renderer Function Arguments} As with functions that return 2D renderers, functions that return 3D renderers always have these kinds of arguments: diff --git a/pkgs/plot/scribblings/ticks.scrbl b/pkgs/plot/scribblings/ticks.scrbl index 0f10faf661..334b51cbe7 100644 --- a/pkgs/plot/scribblings/ticks.scrbl +++ b/pkgs/plot/scribblings/ticks.scrbl @@ -2,10 +2,11 @@ @(require "common.rkt" (for-label racket/date db)) -@declare-exporting[plot] - @title[#:tag "ticks and transforms"]{Axis Transforms and Ticks} +@declare-exporting[plot] +@defmodule*/no-declare[(plot plot/typed) #:link-target? #f] + @section[#:tag "transforms"]{Axis Transforms} The @italic{x}, @italic{y} and @italic{z} axes for any plot can be independently transformed by parameterizing the plot on different @racket[plot-x-transform], @racket[plot-y-transform] and @racket[plot-z-transform] values. @@ -38,7 +39,7 @@ Here, the renderer returned by @racket[surface3d] does not have to bend the poly @doc-apply[plot-x-transform] @doc-apply[plot-y-transform] @doc-apply[plot-z-transform]{ -Independent, per-axis, monotone, nonlinear transforms. PLoT comes with some typical (and some atypical) axis transforms, documented immediately below. +Independent, per-axis, monotone, nonlinear transforms. @(plot-name) comes with some typical (and some atypical) axis transforms, documented immediately below. } @doc-apply[id-transform]{ @@ -358,7 +359,7 @@ The @racket[#:formats] keyword argument is a list of three format strings, repre @doc-apply[currency-ticks-formats]{ The default currency scales and formats. -For example, a PLoT user in France would probably begin programs with +For example, a @(plot-name) user in France would probably begin programs with @racketblock[(require plot) (currency-ticks-scales eu-currency-scales) (currency-ticks-formats eu-currency-formats)] diff --git a/pkgs/plot/scribblings/utils.scrbl b/pkgs/plot/scribblings/utils.scrbl index 98a2217a7e..fdb35f1d21 100644 --- a/pkgs/plot/scribblings/utils.scrbl +++ b/pkgs/plot/scribblings/utils.scrbl @@ -4,11 +4,8 @@ @title[#:tag "utils"]{Plot Utilities} -@defmodule[plot/utils] - -Typed Racket users should use - -@defmodule*/no-declare[(plot/typed/utils)] +@declare-exporting[plot/utils] +@defmodule*/no-declare[(plot/utils plot/typed/utils)] @;==================================================================================================== @section{Formatting} @@ -66,7 +63,7 @@ Converts an integer into a string of superscript Unicode characters. @examples[#:eval plot-eval (integer->superscript -1234567890)] Systems running some out-of-date versions of Windows XP have difficulty with Unicode superscripts for 4 and up. -Because @racket[integer->superscript] is used by every number formatting function to format exponents, if you have such a system, PLoT will apparently not format all numbers with exponents correctly (until you update it). +Because @racket[integer->superscript] is used by every number formatting function to format exponents, if you have such a system, @(plot-name) will apparently not format all numbers with exponents correctly (until you update it). } @;{ @@ -453,7 +450,7 @@ Use this to construct inputs for @(racket rectangles) and @(racket rectangles3d) @subsection[#:tag "math.rectangles"]{Rectangles and Rectangle Functions} @margin-note*{The @racket[rect-meet] and @racket[rect-join] functions define a @link["http://en.wikipedia.org/wiki/Lattice_%28order%29"]{pointed lattice} over rectangles. - This fact may seem esoteric, but it allows PLoT to combine multiple renderers with different rectangular bounds in a way that is intuitive and mathematically sound.} + This fact may seem esoteric, but it allows @(plot-name) to combine multiple renderers with different rectangular bounds in a way that is intuitive and mathematically sound.} @defproc[(rect-meet [i (vectorof ivl?)] ...) (vectorof ivl?)]{ } @@ -505,7 +502,7 @@ To keep time zone offsets from influencing the plot, set them to @racket[0] firs [day exact-integer?])]{ A time representation that accounts for days, negative times (using negative days), and fractional seconds. -PLoT (specifically @racket[time-ticks]) uses @racket[plot-time] internally to format times, but because renderer-producing functions require only real values, +@(plot-name) (specifically @racket[time-ticks]) uses @racket[plot-time] internally to format times, but because renderer-producing functions require only real values, user code should not need it. It is provided just in case. } diff --git a/pkgs/plot/tests/doc-tests.rkt b/pkgs/plot/tests/doc-tests.rkt index aaa4ff358d..4b99bdbe4a 100644 --- a/pkgs/plot/tests/doc-tests.rkt +++ b/pkgs/plot/tests/doc-tests.rkt @@ -1,6 +1,6 @@ #lang racket -(require plot/doc +(require plot/private/doc scribble/manual scribble/render scribble/text-render diff --git a/pkgs/plot/tests/low-level-tests.rkt b/pkgs/plot/tests/low-level-tests.rkt index 2e19a05b6a..b8c0c775cf 100644 --- a/pkgs/plot/tests/low-level-tests.rkt +++ b/pkgs/plot/tests/low-level-tests.rkt @@ -2,20 +2,20 @@ (require rackunit racket/date plot plot/utils - plot/common/utils - (only-in plot/common/math + plot/private/common/utils + (only-in plot/private/common/math vector-andmap vector-ormap) - (only-in plot/common/date-time + (only-in plot/private/common/date-time utc-seconds-round-year utc-seconds-round-month seconds-per-minute seconds-per-hour seconds-per-day seconds-per-week) - (only-in plot/common/format + (only-in plot/private/common/format int-str->e-str frac-str->e-str) - plot/common/worker-thread) + plot/private/common/worker-thread) (check-equal? (linear-seq 1 1 2) '(1 1)) (check-equal? (linear-seq 0 1 2 #:start? #t #:end? #t) '(0 1)) diff --git a/pkgs/plot/tests/plot-bitmap.rkt b/pkgs/plot/tests/plot-bitmap.rkt new file mode 100644 index 0000000000..6ebc9ef892 --- /dev/null +++ b/pkgs/plot/tests/plot-bitmap.rkt @@ -0,0 +1,17 @@ +#lang racket + +(require rackunit + plot/bitmap + racket/draw) + +(check-true (is-a? (plot (function sin -4 4) + #:out-file "sin.png") + bitmap%)) +(check-true (is-a? (read-bitmap "sin.png") bitmap%)) +(delete-file "sin.png") + +(check-true (is-a? (plot3d (contour-intervals3d * -4 4 -4 4) + #:out-file "times.png") + bitmap%)) +(check-true (is-a? (read-bitmap "times.png") bitmap%)) +(delete-file "times.png") diff --git a/pkgs/plot/tests/plot-no-gui.rkt b/pkgs/plot/tests/plot-no-gui.rkt new file mode 100644 index 0000000000..a11d9b19c2 --- /dev/null +++ b/pkgs/plot/tests/plot-no-gui.rkt @@ -0,0 +1,20 @@ +#lang racket + +(require rackunit + plot/no-gui + pict + racket/draw) + +(check-true (pict? (plot-pict (function sin -4 4)))) +(check-true (pict? (plot3d-pict (contour-intervals3d * -4 4 -4 4)))) + +(check-true (is-a? (plot-bitmap (function sin -4 4)) bitmap%)) +(check-true (is-a? (plot3d-bitmap (contour-intervals3d * -4 4 -4 4)) bitmap%)) + +(check-true (void? (plot-file (function sin -4 4) "sin.png"))) +(check-true (is-a? (read-bitmap "sin.png") bitmap%)) +(delete-file "sin.png") + +(check-true (void? (plot3d-file (contour-intervals3d * -4 4 -4 4) "times.png"))) +(check-true (is-a? (read-bitmap "times.png") bitmap%)) +(delete-file "times.png") diff --git a/pkgs/plot/tests/plot-pict.rkt b/pkgs/plot/tests/plot-pict.rkt new file mode 100644 index 0000000000..d0f7209468 --- /dev/null +++ b/pkgs/plot/tests/plot-pict.rkt @@ -0,0 +1,16 @@ +#lang racket + +(require rackunit + plot/pict + pict + racket/draw) + +(check-true (pict? (plot (function sin -4 4) + #:out-file "sin.png"))) +(check-true (is-a? (read-bitmap "sin.png") bitmap%)) +(delete-file "sin.png") + +(check-true (pict? (plot3d (contour-intervals3d * -4 4 -4 4) + #:out-file "times.png"))) +(check-true (is-a? (read-bitmap "times.png") bitmap%)) +(delete-file "times.png") diff --git a/pkgs/plot/tests/subdivision-tests.rkt b/pkgs/plot/tests/subdivision-tests.rkt index bdaf8cffcf..5bf63e2cf5 100644 --- a/pkgs/plot/tests/subdivision-tests.rkt +++ b/pkgs/plot/tests/subdivision-tests.rkt @@ -1,6 +1,8 @@ #lang racket -(require plot plot/plot2d/plot-area plot/plot3d/plot-area) +(require plot + plot/private/plot2d/plot-area + plot/private/plot3d/plot-area) (parameterize ([plot-x-transform log-transform] [plot-x-ticks (log-ticks)]) diff --git a/pkgs/plot/tests/typed-parameter-regression-tests.rkt b/pkgs/plot/tests/typed/parameter-regression-tests.rkt similarity index 100% rename from pkgs/plot/tests/typed-parameter-regression-tests.rkt rename to pkgs/plot/tests/typed/parameter-regression-tests.rkt diff --git a/pkgs/plot/tests/typed/plot-bitmap.rkt b/pkgs/plot/tests/typed/plot-bitmap.rkt new file mode 100644 index 0000000000..4d1f660b26 --- /dev/null +++ b/pkgs/plot/tests/typed/plot-bitmap.rkt @@ -0,0 +1,11 @@ +#lang typed/racket + +(require plot/typed/bitmap) + +(plot (function sin -4 4) + #:out-file "sin.png") +(delete-file "sin.png") + +(plot3d (contour-intervals3d * -4 4 -4 4) + #:out-file "times.png") +(delete-file "times.png") diff --git a/pkgs/plot/tests/typed/plot-no-gui.rkt b/pkgs/plot/tests/typed/plot-no-gui.rkt new file mode 100644 index 0000000000..813dc516d7 --- /dev/null +++ b/pkgs/plot/tests/typed/plot-no-gui.rkt @@ -0,0 +1,20 @@ +#lang typed/racket + +(require typed/rackunit + plot/typed/no-gui) + +(require/typed + pict + [#:opaque Pict pict?]) + +(check-true (pict? (plot-pict (function sin -4 4)))) +(check-true (pict? (plot3d-pict (contour-intervals3d * -4 4 -4 4)))) + +(plot-bitmap (function sin -4 4)) +(plot3d-bitmap (contour-intervals3d * -4 4 -4 4)) + +(check-true (void? (plot-file (function sin -4 4) "sin.png"))) +(delete-file "sin.png") + +(check-true (void? (plot3d-file (contour-intervals3d * -4 4 -4 4) "times.png"))) +(delete-file "times.png") diff --git a/pkgs/plot/tests/typed/plot-pict.rkt b/pkgs/plot/tests/typed/plot-pict.rkt new file mode 100644 index 0000000000..178e688b69 --- /dev/null +++ b/pkgs/plot/tests/typed/plot-pict.rkt @@ -0,0 +1,16 @@ +#lang typed/racket + +(require typed/rackunit + plot/typed/pict) + +(require/typed + pict + [#:opaque Pict pict?]) + +(check-true (pict? (plot (function sin -4 4) + #:out-file "sin.png"))) +(delete-file "sin.png") + +(check-true (pict? (plot3d (contour-intervals3d * -4 4 -4 4) + #:out-file "times.png"))) +(delete-file "times.png") diff --git a/pkgs/plot/tests/typed-plot-tests.rkt b/pkgs/plot/tests/typed/plot-tests.rkt similarity index 100% rename from pkgs/plot/tests/typed-plot-tests.rkt rename to pkgs/plot/tests/typed/plot-tests.rkt diff --git a/pkgs/plot/typed/bitmap.rkt b/pkgs/plot/typed/bitmap.rkt new file mode 100644 index 0000000000..72088844ed --- /dev/null +++ b/pkgs/plot/typed/bitmap.rkt @@ -0,0 +1,8 @@ +#lang racket/base + +(require "no-gui.rkt" + "private/no-gui/plot-bitmap.rkt") + +(provide (all-from-out + "no-gui.rkt" + "private/no-gui/plot-bitmap.rkt")) diff --git a/pkgs/plot/typed/main.rkt b/pkgs/plot/typed/main.rkt index b35d56bf4b..867e72b44a 100644 --- a/pkgs/plot/typed/main.rkt +++ b/pkgs/plot/typed/main.rkt @@ -1,79 +1,10 @@ -#lang typed/racket/base +#lang racket/base -;; Every require/provide pair in this file corresponds with a require/provide pair in plot/main +(require "no-gui.rkt" + "private/gui/plot2d.rkt" + "private/gui/plot3d.rkt") -;; =================================================================================================== -;; General exports - -(require "common/types.rkt") -(provide (all-from-out "common/types.rkt")) - -(require "contracted/parameters.rkt") -(provide (all-from-out "contracted/parameters.rkt")) - -;; Not necessary because re-exporting "types.rkt" exports the `ivl' struct -;(require "contracted/math.rkt") -;(provide (struct-out ivl)) - -(require "contracted/axis-transform.rkt") -(provide (all-from-out "contracted/axis-transform.rkt")) - -(require "contracted/ticks.rkt") -(provide (all-from-out "contracted/ticks.rkt")) - -(require "contracted/date-time.rkt") -(provide plot-time->seconds seconds->plot-time datetime->real) - -(require "common/nonrenderers.rkt") -(provide (all-from-out "common/nonrenderers.rkt")) - -;; =================================================================================================== -;; 2D exports - -(require "plot2d/plot.rkt") -(provide (all-from-out "plot2d/plot.rkt")) - -(require "plot2d/point.rkt") -(provide (all-from-out "plot2d/point.rkt")) - -(require "plot2d/line.rkt") -(provide (all-from-out "plot2d/line.rkt")) - -(require "plot2d/interval.rkt") -(provide (all-from-out "plot2d/interval.rkt")) - -(require "plot2d/contour.rkt") -(provide (all-from-out "plot2d/contour.rkt")) - -(require "plot2d/rectangle.rkt") -(provide (all-from-out "plot2d/rectangle.rkt")) - -(require "plot2d/decoration.rkt") -(provide (all-from-out "plot2d/decoration.rkt")) - -;; =================================================================================================== -;; 3D exports - -(require "plot3d/plot.rkt") -(provide (all-from-out "plot3d/plot.rkt")) - -(require "plot3d/surface.rkt") -(provide (all-from-out "plot3d/surface.rkt")) - -(require "plot3d/contour.rkt") -(provide (all-from-out "plot3d/contour.rkt")) - -(require "plot3d/line.rkt") -(provide (all-from-out "plot3d/line.rkt")) - -(require "plot3d/point.rkt") -(provide (all-from-out "plot3d/point.rkt")) - -(require "plot3d/isosurface.rkt") -(provide (all-from-out "plot3d/isosurface.rkt")) - -(require "plot3d/rectangle.rkt") -(provide (all-from-out "plot3d/rectangle.rkt")) - -(require "plot3d/decoration.rkt") -(provide (all-from-out "plot3d/decoration.rkt")) +(provide (all-from-out + "no-gui.rkt" + "private/gui/plot2d.rkt" + "private/gui/plot3d.rkt")) diff --git a/pkgs/plot/typed/no-gui.rkt b/pkgs/plot/typed/no-gui.rkt new file mode 100644 index 0000000000..21774e0cf1 --- /dev/null +++ b/pkgs/plot/typed/no-gui.rkt @@ -0,0 +1,79 @@ +#lang racket/base + +;; Every require/provide pair in this file corresponds with a require/provide pair in plot/no-gui + +;; =================================================================================================== +;; General exports + +(require (except-in "private/common/types.rkt" Pict)) +(provide (all-from-out "private/common/types.rkt")) + +(require "private/contracted/parameters.rkt") +(provide (all-from-out "private/contracted/parameters.rkt")) + +;; Not necessary because re-exporting "types.rkt" exports the `ivl' struct +;(require "private/contracted/math.rkt") +;(provide (struct-out ivl)) + +(require "private/contracted/axis-transform.rkt") +(provide (all-from-out "private/contracted/axis-transform.rkt")) + +(require "private/contracted/ticks.rkt") +(provide (all-from-out "private/contracted/ticks.rkt")) + +(require "private/contracted/date-time.rkt") +(provide plot-time->seconds seconds->plot-time datetime->real) + +(require "private/common/nonrenderers.rkt") +(provide (all-from-out "private/common/nonrenderers.rkt")) + +;; =================================================================================================== +;; 2D exports + +(require "private/no-gui/plot2d.rkt") +(provide (all-from-out "private/no-gui/plot2d.rkt")) + +(require "private/plot2d/point.rkt") +(provide (all-from-out "private/plot2d/point.rkt")) + +(require "private/plot2d/line.rkt") +(provide (all-from-out "private/plot2d/line.rkt")) + +(require "private/plot2d/interval.rkt") +(provide (all-from-out "private/plot2d/interval.rkt")) + +(require "private/plot2d/contour.rkt") +(provide (all-from-out "private/plot2d/contour.rkt")) + +(require "private/plot2d/rectangle.rkt") +(provide (all-from-out "private/plot2d/rectangle.rkt")) + +(require "private/plot2d/decoration.rkt") +(provide (all-from-out "private/plot2d/decoration.rkt")) + +;; =================================================================================================== +;; 3D exports + +(require "private/no-gui/plot3d.rkt") +(provide (all-from-out "private/no-gui/plot3d.rkt")) + +(require "private/plot3d/surface.rkt") +(provide (all-from-out "private/plot3d/surface.rkt")) + +(require "private/plot3d/contour.rkt") +(provide (all-from-out "private/plot3d/contour.rkt")) + +(require "private/plot3d/line.rkt") +(provide (all-from-out "private/plot3d/line.rkt")) + +(require "private/plot3d/point.rkt") +(provide (all-from-out "private/plot3d/point.rkt")) + +(require "private/plot3d/isosurface.rkt") +(provide (all-from-out "private/plot3d/isosurface.rkt")) + +(require "private/plot3d/rectangle.rkt") +(provide (all-from-out "private/plot3d/rectangle.rkt")) + +(require "private/plot3d/decoration.rkt") +(provide (all-from-out "private/plot3d/decoration.rkt")) diff --git a/pkgs/plot/typed/pict.rkt b/pkgs/plot/typed/pict.rkt new file mode 100644 index 0000000000..8fc83def04 --- /dev/null +++ b/pkgs/plot/typed/pict.rkt @@ -0,0 +1,8 @@ +#lang racket/base + +(require "no-gui.rkt" + "private/no-gui/plot-pict.rkt") + +(provide (all-from-out + "no-gui.rkt" + "private/no-gui/plot-pict.rkt")) diff --git a/pkgs/plot/typed/common/nonrenderers.rkt b/pkgs/plot/typed/private/common/nonrenderers.rkt similarity index 100% rename from pkgs/plot/typed/common/nonrenderers.rkt rename to pkgs/plot/typed/private/common/nonrenderers.rkt diff --git a/pkgs/plot/typed/common/types.rkt b/pkgs/plot/typed/private/common/types.rkt similarity index 86% rename from pkgs/plot/typed/common/types.rkt rename to pkgs/plot/typed/private/common/types.rkt index e385bceeb0..7505e6ea43 100644 --- a/pkgs/plot/typed/common/types.rkt +++ b/pkgs/plot/typed/private/common/types.rkt @@ -3,7 +3,12 @@ (require (for-syntax racket/base) (only-in typed/mred/mred Color%)) -(provide (all-defined-out)) +(require/typed + pict + [#:opaque Pict pict?]) + +(provide (all-defined-out) + Pict) (define-type (Treeof A) (Rec T (U A (Listof T)))) @@ -15,15 +20,15 @@ ;; Struct types (require/typed/provide - plot/common/plot-device + plot/private/common/plot-device [plot-device% Plot-Device%]) (require/typed/provide - plot/plot2d/plot-area + plot/private/plot2d/plot-area [2d-plot-area% 2D-Plot-Area%]) (require/typed/provide - plot/plot3d/plot-area + plot/private/plot3d/plot-area [3d-plot-area% 3D-Plot-Area%]) (require-typed-struct/provide @@ -35,7 +40,7 @@ (require-typed-struct/provide ivl ([min : (Option Real)] [max : (Option Real)]) - plot/common/math) + plot/private/common/math) (require-typed-struct/provide plot-time @@ -43,22 +48,22 @@ [minute : Nonnegative-Integer] [hour : Nonnegative-Integer] [day : Integer]) - plot/common/date-time) + plot/private/common/date-time) (require-typed-struct/provide invertible-function ([f : (Real -> Real)] [g : (Real -> Real)]) - plot/common/axis-transform) + plot/private/common/axis-transform) (require-typed-struct/provide pre-tick ([value : Real] [major? : Boolean]) - plot/common/ticks) + plot/private/common/ticks) (require-typed-struct/provide (tick pre-tick) ([label : String]) - plot/common/ticks) + plot/private/common/ticks) (define-type Ticks-Layout (Real Real -> (Listof pre-tick))) (define-type Ticks-Format (Real Real (Listof pre-tick) -> (Listof String))) @@ -67,13 +72,13 @@ ticks ([layout : Ticks-Layout] [format : Ticks-Format]) - plot/common/ticks) + plot/private/common/ticks) (require-typed-struct/provide legend-entry ([label : String] [draw : ((Instance Plot-Device%) Real Real -> Void)]) - plot/common/legend) + plot/private/common/legend) (define-type Bounds-Fun ((Vectorof ivl) -> (Vectorof ivl))) (define-type Ticks-Fun ((Vectorof ivl) -> Any)) @@ -83,27 +88,27 @@ ([bounds-rect : (Option (Vectorof ivl))] [bounds-fun : (Option Bounds-Fun)] [ticks-fun : (Option Ticks-Fun)]) - plot/common/plot-element) + plot/private/common/plot-element) (require-typed-struct/provide (nonrenderer plot-element) () - plot/common/plot-element) + plot/private/common/plot-element) (require-typed-struct/provide (renderer2d plot-element) ([render-proc : (Option ((Instance 2D-Plot-Area%) -> (Treeof legend-entry)))]) - plot/common/plot-element) + plot/private/common/plot-element) (require-typed-struct/provide (renderer3d plot-element) ([render-proc : (Option ((Instance 3D-Plot-Area%) -> (Treeof legend-entry)))]) - plot/common/plot-element) + plot/private/common/plot-element) ;; =================================================================================================== ;; Styles and colors -(require (for-syntax (only-in plot/common/contract known-point-symbols))) +(require (for-syntax (only-in plot/private/common/contract known-point-symbols))) (define-syntax (define-point-sym-type stx) (syntax-case stx () diff --git a/pkgs/plot/typed/contracted/axis-transform.rkt b/pkgs/plot/typed/private/contracted/axis-transform.rkt similarity index 95% rename from pkgs/plot/typed/contracted/axis-transform.rkt rename to pkgs/plot/typed/private/contracted/axis-transform.rkt index 7c303bc13d..699180055b 100644 --- a/pkgs/plot/typed/contracted/axis-transform.rkt +++ b/pkgs/plot/typed/private/contracted/axis-transform.rkt @@ -3,7 +3,7 @@ (require "../common/types.rkt") (require/typed/provide - plot/contracted/axis-transform + plot/private/contracted/axis-transform [id-function invertible-function] [invertible-compose (invertible-function invertible-function -> invertible-function)] diff --git a/pkgs/plot/typed/contracted/date-time.rkt b/pkgs/plot/typed/private/contracted/date-time.rkt similarity index 90% rename from pkgs/plot/typed/contracted/date-time.rkt rename to pkgs/plot/typed/private/contracted/date-time.rkt index d10da881dd..b5a7bee03c 100644 --- a/pkgs/plot/typed/contracted/date-time.rkt +++ b/pkgs/plot/typed/private/contracted/date-time.rkt @@ -3,7 +3,7 @@ (require "../common/types.rkt") (require/typed/provide - plot/contracted/date-time + plot/private/contracted/date-time #; [datetime->real ((U plot-time Date Date* SQL-Date SQL-Time SQL-Timestamp) -> Real)] diff --git a/pkgs/plot/typed/contracted/draw.rkt b/pkgs/plot/typed/private/contracted/draw.rkt similarity index 95% rename from pkgs/plot/typed/contracted/draw.rkt rename to pkgs/plot/typed/private/contracted/draw.rkt index 4d9f0d026e..42da125f1f 100644 --- a/pkgs/plot/typed/contracted/draw.rkt +++ b/pkgs/plot/typed/private/contracted/draw.rkt @@ -3,7 +3,7 @@ (require "../common/types.rkt") (require/typed/provide - plot/contracted/draw + plot/private/contracted/draw [->color (Color -> (List Real Real Real))] [->pen-color (Plot-Color -> (List Real Real Real))] [->brush-color (Plot-Color -> (List Real Real Real))] diff --git a/pkgs/plot/typed/contracted/format.rkt b/pkgs/plot/typed/private/contracted/format.rkt similarity index 96% rename from pkgs/plot/typed/contracted/format.rkt rename to pkgs/plot/typed/private/contracted/format.rkt index feccbda126..fa2ec8a80c 100644 --- a/pkgs/plot/typed/contracted/format.rkt +++ b/pkgs/plot/typed/private/contracted/format.rkt @@ -3,7 +3,7 @@ (require "../common/types.rkt") (require/typed/provide - plot/contracted/format + plot/private/contracted/format [integer->superscript (Integer -> String)] diff --git a/pkgs/plot/typed/contracted/kde.rkt b/pkgs/plot/typed/private/contracted/kde.rkt similarity index 85% rename from pkgs/plot/typed/contracted/kde.rkt rename to pkgs/plot/typed/private/contracted/kde.rkt index 2e136c1d82..3dadcf0f36 100644 --- a/pkgs/plot/typed/contracted/kde.rkt +++ b/pkgs/plot/typed/private/contracted/kde.rkt @@ -3,6 +3,6 @@ (require "../common/types.rkt") (require/typed/provide - plot/contracted/kde + plot/private/contracted/kde [kde ((Listof Real) Real -> (Values mapped-function (Option Real) (Option Real)))] ) diff --git a/pkgs/plot/typed/contracted/math.rkt b/pkgs/plot/typed/private/contracted/math.rkt similarity index 95% rename from pkgs/plot/typed/contracted/math.rkt rename to pkgs/plot/typed/private/contracted/math.rkt index dd2b4b2b88..f80012b182 100644 --- a/pkgs/plot/typed/contracted/math.rkt +++ b/pkgs/plot/typed/private/contracted/math.rkt @@ -4,7 +4,7 @@ ;; Misc (require/typed/provide - plot/common/math + plot/private/common/math [polar->cartesian (Real Real -> (Vector Real Real))] [3d-polar->3d-cartesian (Real Real Real -> (Vector Real Real Real))] [ceiling-log/base (Integer Real -> Integer)] @@ -14,7 +14,7 @@ ;; Vectors (require/typed/provide - plot/common/math + plot/private/common/math [v+ ((Vectorof Real) (Vectorof Real) -> (Vectorof Real))] [v- ((Vectorof Real) (Vectorof Real) -> (Vectorof Real))] [vneg ((Vectorof Real) -> (Vectorof Real))] @@ -33,7 +33,7 @@ ;; Intervals (require/typed/provide - plot/common/math + plot/private/common/math [empty-ivl ivl] [unknown-ivl ivl] [rational-ivl? (Any -> Boolean)] @@ -58,7 +58,7 @@ ;; Rectangles (require/typed/provide - plot/common/math + plot/private/common/math [empty-rect (Natural -> Rect)] [unknown-rect (Natural -> Rect)] [bounding-rect ((Listof Rect) -> Rect)] diff --git a/pkgs/plot/typed/contracted/parameters.rkt b/pkgs/plot/typed/private/contracted/parameters.rkt similarity index 99% rename from pkgs/plot/typed/contracted/parameters.rkt rename to pkgs/plot/typed/private/contracted/parameters.rkt index de87be0582..b9deff45a2 100644 --- a/pkgs/plot/typed/contracted/parameters.rkt +++ b/pkgs/plot/typed/private/contracted/parameters.rkt @@ -3,7 +3,7 @@ (require "../common/types.rkt") (require/typed/provide - plot/contracted/parameters + plot/private/contracted/parameters ;; 9.1 Compatibility [plot-deprecation-warnings? (Parameterof Boolean)] diff --git a/pkgs/plot/typed/contracted/sample.rkt b/pkgs/plot/typed/private/contracted/sample.rkt similarity index 94% rename from pkgs/plot/typed/contracted/sample.rkt rename to pkgs/plot/typed/private/contracted/sample.rkt index bb8687fc2e..50a4acbb83 100644 --- a/pkgs/plot/typed/contracted/sample.rkt +++ b/pkgs/plot/typed/private/contracted/sample.rkt @@ -6,7 +6,7 @@ (require "../common/types.rkt") (require/typed/provide - plot/contracted/sample + plot/private/contracted/sample [linear-seq (Real Real Integer [#:start? Boolean] [#:end? Boolean] -> (Listof Real))] [linear-seq* ((Listof Real) Integer [#:start? Boolean] [#:end? Boolean] -> (Listof Real))] diff --git a/pkgs/plot/typed/contracted/ticks.rkt b/pkgs/plot/typed/private/contracted/ticks.rkt similarity index 98% rename from pkgs/plot/typed/contracted/ticks.rkt rename to pkgs/plot/typed/private/contracted/ticks.rkt index efcc971063..1d2b246200 100644 --- a/pkgs/plot/typed/contracted/ticks.rkt +++ b/pkgs/plot/typed/private/contracted/ticks.rkt @@ -3,7 +3,7 @@ (require "../common/types.rkt") (require/typed/provide - plot/contracted/ticks + plot/private/contracted/ticks [24h-descending-date-ticks-formats (Listof String)] [12h-descending-date-ticks-formats (Listof String)] [24h-descending-time-ticks-formats (Listof String)] diff --git a/pkgs/plot/typed/private/gui/plot2d.rkt b/pkgs/plot/typed/private/gui/plot2d.rkt new file mode 100644 index 0000000000..3be9cd3da6 --- /dev/null +++ b/pkgs/plot/typed/private/gui/plot2d.rkt @@ -0,0 +1,54 @@ +#lang typed/racket/base + +(require (only-in typed/mred/mred Snip% Frame%) + "../common/types.rkt" + "../syntax.rkt") + +(provide plot-snip + plot-frame + plot) + +(require/typed* + plot + + [plot-snip ((Treeof (U renderer2d nonrenderer)) + [#:x-min (Option Real)] + [#:x-max (Option Real)] + [#:y-min (Option Real)] + [#:y-max (Option Real)] + [#:width Integer] + [#:height Integer] + [#:title (Option String)] + [#:x-label (Option String)] + [#:y-label (Option String)] + [#:legend-anchor Anchor] + -> (Instance Snip%))] + + [plot-frame ((Treeof (U renderer2d nonrenderer)) + [#:x-min (Option Real)] + [#:x-max (Option Real)] + [#:y-min (Option Real)] + [#:y-max (Option Real)] + [#:width Integer] + [#:height Integer] + [#:title (Option String)] + [#:x-label (Option String)] + [#:y-label (Option String)] + [#:legend-anchor Anchor] + -> (Instance Frame%))] + + [plot ((Treeof (U renderer2d nonrenderer)) + [#:x-min (Option Real)] + [#:x-max (Option Real)] + [#:y-min (Option Real)] + [#:y-max (Option Real)] + [#:width Integer] + [#:height Integer] + [#:title (Option String)] + [#:x-label (Option String)] + [#:y-label (Option String)] + [#:legend-anchor Anchor] + [#:out-file (Option (U Path-String Output-Port))] + [#:out-kind (U 'auto Image-File-Format)] + -> (U (Instance Snip%) Void))] + ) diff --git a/pkgs/plot/typed/private/gui/plot3d.rkt b/pkgs/plot/typed/private/gui/plot3d.rkt new file mode 100644 index 0000000000..378b69c177 --- /dev/null +++ b/pkgs/plot/typed/private/gui/plot3d.rkt @@ -0,0 +1,69 @@ +#lang typed/racket/base + +(require (only-in typed/mred/mred Snip% Frame%) + "../common/types.rkt" + "../syntax.rkt") + +(provide plot3d-snip + plot3d-frame + plot3d) + +(require/typed* + plot + + [plot3d-snip ((Treeof (U renderer3d nonrenderer)) + [#:x-min (Option Real)] + [#:x-max (Option Real)] + [#:y-min (Option Real)] + [#:y-max (Option Real)] + [#:z-min (Option Real)] + [#:z-max (Option Real)] + [#:width Integer] + [#:height Integer] + [#:angle Real] + [#:altitude Real] + [#:title (Option String)] + [#:x-label (Option String)] + [#:y-label (Option String)] + [#:z-label (Option String)] + [#:legend-anchor Anchor] + -> (Instance Snip%))] + + [plot3d-frame ((Treeof (U renderer3d nonrenderer)) + [#:x-min (Option Real)] + [#:x-max (Option Real)] + [#:y-min (Option Real)] + [#:y-max (Option Real)] + [#:z-min (Option Real)] + [#:z-max (Option Real)] + [#:width Integer] + [#:height Integer] + [#:angle Real] + [#:altitude Real] + [#:title (Option String)] + [#:x-label (Option String)] + [#:y-label (Option String)] + [#:z-label (Option String)] + [#:legend-anchor Anchor] + -> (Instance Frame%))] + + [plot3d ((Treeof (U renderer3d nonrenderer)) + [#:x-min (Option Real)] + [#:x-max (Option Real)] + [#:y-min (Option Real)] + [#:y-max (Option Real)] + [#:z-min (Option Real)] + [#:z-max (Option Real)] + [#:width Integer] + [#:height Integer] + [#:angle Real] + [#:altitude Real] + [#:title (Option String)] + [#:x-label (Option String)] + [#:y-label (Option String)] + [#:z-label (Option String)] + [#:legend-anchor Anchor] + [#:out-file (Option (U Path-String Output-Port))] + [#:out-kind (U 'auto Image-File-Format)] + -> (U (Instance Snip%) Void))] + ) diff --git a/pkgs/plot/typed/private/no-gui/plot-bitmap.rkt b/pkgs/plot/typed/private/no-gui/plot-bitmap.rkt new file mode 100644 index 0000000000..d2c676afa9 --- /dev/null +++ b/pkgs/plot/typed/private/no-gui/plot-bitmap.rkt @@ -0,0 +1,46 @@ +#lang typed/racket/base + +(require (only-in typed/mred/mred Bitmap%) + "../common/types.rkt" + "../syntax.rkt") + +(provide plot plot3d) + +(require/typed* + plot/bitmap + + [plot ((Treeof (U renderer2d nonrenderer)) + [#:x-min (Option Real)] + [#:x-max (Option Real)] + [#:y-min (Option Real)] + [#:y-max (Option Real)] + [#:width Integer] + [#:height Integer] + [#:title (Option String)] + [#:x-label (Option String)] + [#:y-label (Option String)] + [#:legend-anchor Anchor] + [#:out-file (Option (U Path-String Output-Port))] + [#:out-kind (U 'auto Image-File-Format)] + -> (Instance Bitmap%))] + + [plot3d ((Treeof (U renderer3d nonrenderer)) + [#:x-min (Option Real)] + [#:x-max (Option Real)] + [#:y-min (Option Real)] + [#:y-max (Option Real)] + [#:z-min (Option Real)] + [#:z-max (Option Real)] + [#:width Integer] + [#:height Integer] + [#:angle Real] + [#:altitude Real] + [#:title (Option String)] + [#:x-label (Option String)] + [#:y-label (Option String)] + [#:z-label (Option String)] + [#:legend-anchor Anchor] + [#:out-file (Option (U Path-String Output-Port))] + [#:out-kind (U 'auto Image-File-Format)] + -> (Instance Bitmap%))] + ) diff --git a/pkgs/plot/typed/private/no-gui/plot-pict.rkt b/pkgs/plot/typed/private/no-gui/plot-pict.rkt new file mode 100644 index 0000000000..1da4e4510c --- /dev/null +++ b/pkgs/plot/typed/private/no-gui/plot-pict.rkt @@ -0,0 +1,46 @@ +#lang typed/racket/base + +(require (only-in typed/mred/mred Bitmap%) + "../common/types.rkt" + "../syntax.rkt") + +(provide plot plot3d) + +(require/typed* + plot/pict + + [plot ((Treeof (U renderer2d nonrenderer)) + [#:x-min (Option Real)] + [#:x-max (Option Real)] + [#:y-min (Option Real)] + [#:y-max (Option Real)] + [#:width Integer] + [#:height Integer] + [#:title (Option String)] + [#:x-label (Option String)] + [#:y-label (Option String)] + [#:legend-anchor Anchor] + [#:out-file (Option (U Path-String Output-Port))] + [#:out-kind (U 'auto Image-File-Format)] + -> Pict)] + + [plot3d ((Treeof (U renderer3d nonrenderer)) + [#:x-min (Option Real)] + [#:x-max (Option Real)] + [#:y-min (Option Real)] + [#:y-max (Option Real)] + [#:z-min (Option Real)] + [#:z-max (Option Real)] + [#:width Integer] + [#:height Integer] + [#:angle Real] + [#:altitude Real] + [#:title (Option String)] + [#:x-label (Option String)] + [#:y-label (Option String)] + [#:z-label (Option String)] + [#:legend-anchor Anchor] + [#:out-file (Option (U Path-String Output-Port))] + [#:out-kind (U 'auto Image-File-Format)] + -> Pict)] + ) diff --git a/pkgs/plot/typed/plot2d/plot.rkt b/pkgs/plot/typed/private/no-gui/plot2d.rkt similarity index 53% rename from pkgs/plot/typed/plot2d/plot.rkt rename to pkgs/plot/typed/private/no-gui/plot2d.rkt index bed2d405ca..ab7d09dfc9 100644 --- a/pkgs/plot/typed/plot2d/plot.rkt +++ b/pkgs/plot/typed/private/no-gui/plot2d.rkt @@ -1,34 +1,54 @@ #lang typed/racket/base -(require (only-in typed/mred/mred Snip% Bitmap% Frame%) +(require (only-in typed/mred/mred Bitmap%) "../common/types.rkt" "../syntax.rkt") -(provide plot - plot-file - ;plot-pict ; can't be typed yet +(provide plot/dc plot-bitmap - plot-snip - plot-frame - plot/dc) + plot-pict + plot-file) (require/typed* - plot + plot/no-gui - [plot ((Treeof (U renderer2d nonrenderer)) - [#:x-min (Option Real)] - [#:x-max (Option Real)] - [#:y-min (Option Real)] - [#:y-max (Option Real)] - [#:width Integer] - [#:height Integer] - [#:title (Option String)] - [#:x-label (Option String)] - [#:y-label (Option String)] - [#:legend-anchor Anchor] - [#:out-file (Option (U Path-String Output-Port))] - [#:out-kind (U 'auto Image-File-Format)] - -> (U (Instance Snip%) Void))] + [plot/dc ((Treeof (U renderer2d nonrenderer)) + Any Real Real Real Real + [#:x-min (Option Real)] + [#:x-max (Option Real)] + [#:y-min (Option Real)] + [#:y-max (Option Real)] + [#:title (Option String)] + [#:x-label (Option String)] + [#:y-label (Option String)] + [#:legend-anchor Anchor] + -> Void)] + + [plot-bitmap ((Treeof (U renderer2d nonrenderer)) + [#:x-min (Option Real)] + [#:x-max (Option Real)] + [#:y-min (Option Real)] + [#:y-max (Option Real)] + [#:width Integer] + [#:height Integer] + [#:title (Option String)] + [#:x-label (Option String)] + [#:y-label (Option String)] + [#:legend-anchor Anchor] + -> (Instance Bitmap%))] + + [plot-pict ((Treeof (U renderer2d nonrenderer)) + [#:x-min (Option Real)] + [#:x-max (Option Real)] + [#:y-min (Option Real)] + [#:y-max (Option Real)] + [#:width Integer] + [#:height Integer] + [#:title (Option String)] + [#:x-label (Option String)] + [#:y-label (Option String)] + [#:legend-anchor Anchor] + -> Pict)] [plot-file (((Treeof (U renderer2d nonrenderer)) (U Path-String Output-Port)) @@ -44,69 +64,4 @@ [#:y-label (Option String)] [#:legend-anchor Anchor]) ->* Void)] - - #;; Picts are from the pict collection, which isn't typed yet - [plot-pict ((Treeof (U renderer2d nonrenderer)) - [#:x-min (Option Real)] - [#:x-max (Option Real)] - [#:y-min (Option Real)] - [#:y-max (Option Real)] - [#:width Integer] - [#:height Integer] - [#:title (Option String)] - [#:x-label (Option String)] - [#:y-label (Option String)] - [#:legend-anchor Anchor] - -> Pict)] - - [plot-bitmap ((Treeof (U renderer2d nonrenderer)) - [#:x-min (Option Real)] - [#:x-max (Option Real)] - [#:y-min (Option Real)] - [#:y-max (Option Real)] - [#:width Integer] - [#:height Integer] - [#:title (Option String)] - [#:x-label (Option String)] - [#:y-label (Option String)] - [#:legend-anchor Anchor] - -> (Instance Bitmap%))] - - [plot-snip ((Treeof (U renderer2d nonrenderer)) - [#:x-min (Option Real)] - [#:x-max (Option Real)] - [#:y-min (Option Real)] - [#:y-max (Option Real)] - [#:width Integer] - [#:height Integer] - [#:title (Option String)] - [#:x-label (Option String)] - [#:y-label (Option String)] - [#:legend-anchor Anchor] - -> (Instance Snip%))] - - [plot-frame ((Treeof (U renderer2d nonrenderer)) - [#:x-min (Option Real)] - [#:x-max (Option Real)] - [#:y-min (Option Real)] - [#:y-max (Option Real)] - [#:width Integer] - [#:height Integer] - [#:title (Option String)] - [#:x-label (Option String)] - [#:y-label (Option String)] - [#:legend-anchor Anchor] - -> (Instance Frame%))] - - [plot/dc ((Treeof (U renderer2d nonrenderer)) - Any Real Real Real Real - [#:x-min (Option Real)] - [#:x-max (Option Real)] - [#:y-min (Option Real)] - [#:y-max (Option Real)] - [#:title (Option String)] - [#:x-label (Option String)] - [#:y-label (Option String)] - [#:legend-anchor Anchor] - -> Void)] ) diff --git a/pkgs/plot/typed/plot3d/plot.rkt b/pkgs/plot/typed/private/no-gui/plot3d.rkt similarity index 55% rename from pkgs/plot/typed/plot3d/plot.rkt rename to pkgs/plot/typed/private/no-gui/plot3d.rkt index bdbe30e533..00b72cda9f 100644 --- a/pkgs/plot/typed/plot3d/plot.rkt +++ b/pkgs/plot/typed/private/no-gui/plot3d.rkt @@ -1,39 +1,69 @@ #lang typed/racket/base -(require (only-in typed/mred/mred Snip% Bitmap% Frame%) +(require (only-in typed/mred/mred Bitmap%) "../common/types.rkt" "../syntax.rkt") -(provide plot3d - plot3d-file - ;plot3d-pict ; can't be typed yet +(provide plot3d/dc plot3d-bitmap - plot3d-snip - plot3d-frame - plot3d/dc) + plot3d-pict + plot3d-file) (require/typed* - plot + plot/no-gui - [plot3d ((Treeof (U renderer3d nonrenderer)) - [#:x-min (Option Real)] - [#:x-max (Option Real)] - [#:y-min (Option Real)] - [#:y-max (Option Real)] - [#:z-min (Option Real)] - [#:z-max (Option Real)] - [#:width Integer] - [#:height Integer] - [#:angle Real] - [#:altitude Real] - [#:title (Option String)] - [#:x-label (Option String)] - [#:y-label (Option String)] - [#:z-label (Option String)] - [#:legend-anchor Anchor] - [#:out-file (Option (U Path-String Output-Port))] - [#:out-kind (U 'auto Image-File-Format)] - -> (U (Instance Snip%) Void))] + [plot3d/dc ((Treeof (U renderer3d nonrenderer)) + Any Real Real Real Real + [#:x-min (Option Real)] + [#:x-max (Option Real)] + [#:y-min (Option Real)] + [#:y-max (Option Real)] + [#:z-min (Option Real)] + [#:z-max (Option Real)] + [#:angle Real] + [#:altitude Real] + [#:title (Option String)] + [#:x-label (Option String)] + [#:y-label (Option String)] + [#:z-label (Option String)] + [#:legend-anchor Anchor] + -> Void)] + + [plot3d-bitmap ((Treeof (U renderer3d nonrenderer)) + [#:x-min (Option Real)] + [#:x-max (Option Real)] + [#:y-min (Option Real)] + [#:y-max (Option Real)] + [#:z-min (Option Real)] + [#:z-max (Option Real)] + [#:width Integer] + [#:height Integer] + [#:angle Real] + [#:altitude Real] + [#:title (Option String)] + [#:x-label (Option String)] + [#:y-label (Option String)] + [#:z-label (Option String)] + [#:legend-anchor Anchor] + -> (Instance Bitmap%))] + + [plot3d-pict ((Treeof (U renderer3d nonrenderer)) + [#:x-min (Option Real)] + [#:x-max (Option Real)] + [#:y-min (Option Real)] + [#:y-max (Option Real)] + [#:z-min (Option Real)] + [#:z-max (Option Real)] + [#:width Integer] + [#:height Integer] + [#:angle Real] + [#:altitude Real] + [#:title (Option String)] + [#:x-label (Option String)] + [#:y-label (Option String)] + [#:z-label (Option String)] + [#:legend-anchor Anchor] + -> Pict)] [plot3d-file (((Treeof (U renderer3d nonrenderer)) (U Path-String Output-Port)) @@ -54,94 +84,4 @@ [#:z-label (Option String)] [#:legend-anchor Anchor]) ->* Void)] - - #;; Picts are from the pict collection, which isn't typed yet - [plot3d-pict ((Treeof (U renderer3d nonrenderer)) - [#:x-min (Option Real)] - [#:x-max (Option Real)] - [#:y-min (Option Real)] - [#:y-max (Option Real)] - [#:z-min (Option Real)] - [#:z-max (Option Real)] - [#:width Integer] - [#:height Integer] - [#:angle Real] - [#:altitude Real] - [#:title (Option String)] - [#:x-label (Option String)] - [#:y-label (Option String)] - [#:z-label (Option String)] - [#:legend-anchor Anchor] - -> Pict)] - - [plot3d-bitmap ((Treeof (U renderer3d nonrenderer)) - [#:x-min (Option Real)] - [#:x-max (Option Real)] - [#:y-min (Option Real)] - [#:y-max (Option Real)] - [#:z-min (Option Real)] - [#:z-max (Option Real)] - [#:width Integer] - [#:height Integer] - [#:angle Real] - [#:altitude Real] - [#:title (Option String)] - [#:x-label (Option String)] - [#:y-label (Option String)] - [#:z-label (Option String)] - [#:legend-anchor Anchor] - -> (Instance Bitmap%))] - - [plot3d-snip ((Treeof (U renderer3d nonrenderer)) - [#:x-min (Option Real)] - [#:x-max (Option Real)] - [#:y-min (Option Real)] - [#:y-max (Option Real)] - [#:z-min (Option Real)] - [#:z-max (Option Real)] - [#:width Integer] - [#:height Integer] - [#:angle Real] - [#:altitude Real] - [#:title (Option String)] - [#:x-label (Option String)] - [#:y-label (Option String)] - [#:z-label (Option String)] - [#:legend-anchor Anchor] - -> (Instance Snip%))] - - [plot3d-frame ((Treeof (U renderer3d nonrenderer)) - [#:x-min (Option Real)] - [#:x-max (Option Real)] - [#:y-min (Option Real)] - [#:y-max (Option Real)] - [#:z-min (Option Real)] - [#:z-max (Option Real)] - [#:width Integer] - [#:height Integer] - [#:angle Real] - [#:altitude Real] - [#:title (Option String)] - [#:x-label (Option String)] - [#:y-label (Option String)] - [#:z-label (Option String)] - [#:legend-anchor Anchor] - -> (Instance Frame%))] - - [plot3d/dc ((Treeof (U renderer3d nonrenderer)) - Any Real Real Real Real - [#:x-min (Option Real)] - [#:x-max (Option Real)] - [#:y-min (Option Real)] - [#:y-max (Option Real)] - [#:z-min (Option Real)] - [#:z-max (Option Real)] - [#:angle Real] - [#:altitude Real] - [#:title (Option String)] - [#:x-label (Option String)] - [#:y-label (Option String)] - [#:z-label (Option String)] - [#:legend-anchor Anchor] - -> Void)] ) diff --git a/pkgs/plot/typed/plot2d/contour.rkt b/pkgs/plot/typed/private/plot2d/contour.rkt similarity index 100% rename from pkgs/plot/typed/plot2d/contour.rkt rename to pkgs/plot/typed/private/plot2d/contour.rkt diff --git a/pkgs/plot/typed/plot2d/decoration.rkt b/pkgs/plot/typed/private/plot2d/decoration.rkt similarity index 100% rename from pkgs/plot/typed/plot2d/decoration.rkt rename to pkgs/plot/typed/private/plot2d/decoration.rkt diff --git a/pkgs/plot/typed/plot2d/interval.rkt b/pkgs/plot/typed/private/plot2d/interval.rkt similarity index 100% rename from pkgs/plot/typed/plot2d/interval.rkt rename to pkgs/plot/typed/private/plot2d/interval.rkt diff --git a/pkgs/plot/typed/plot2d/line.rkt b/pkgs/plot/typed/private/plot2d/line.rkt similarity index 100% rename from pkgs/plot/typed/plot2d/line.rkt rename to pkgs/plot/typed/private/plot2d/line.rkt diff --git a/pkgs/plot/typed/plot2d/point.rkt b/pkgs/plot/typed/private/plot2d/point.rkt similarity index 100% rename from pkgs/plot/typed/plot2d/point.rkt rename to pkgs/plot/typed/private/plot2d/point.rkt diff --git a/pkgs/plot/typed/plot2d/rectangle.rkt b/pkgs/plot/typed/private/plot2d/rectangle.rkt similarity index 100% rename from pkgs/plot/typed/plot2d/rectangle.rkt rename to pkgs/plot/typed/private/plot2d/rectangle.rkt diff --git a/pkgs/plot/typed/plot3d/contour.rkt b/pkgs/plot/typed/private/plot3d/contour.rkt similarity index 100% rename from pkgs/plot/typed/plot3d/contour.rkt rename to pkgs/plot/typed/private/plot3d/contour.rkt diff --git a/pkgs/plot/typed/plot3d/decoration.rkt b/pkgs/plot/typed/private/plot3d/decoration.rkt similarity index 100% rename from pkgs/plot/typed/plot3d/decoration.rkt rename to pkgs/plot/typed/private/plot3d/decoration.rkt diff --git a/pkgs/plot/typed/plot3d/isosurface.rkt b/pkgs/plot/typed/private/plot3d/isosurface.rkt similarity index 100% rename from pkgs/plot/typed/plot3d/isosurface.rkt rename to pkgs/plot/typed/private/plot3d/isosurface.rkt diff --git a/pkgs/plot/typed/plot3d/line.rkt b/pkgs/plot/typed/private/plot3d/line.rkt similarity index 100% rename from pkgs/plot/typed/plot3d/line.rkt rename to pkgs/plot/typed/private/plot3d/line.rkt diff --git a/pkgs/plot/typed/plot3d/point.rkt b/pkgs/plot/typed/private/plot3d/point.rkt similarity index 100% rename from pkgs/plot/typed/plot3d/point.rkt rename to pkgs/plot/typed/private/plot3d/point.rkt diff --git a/pkgs/plot/typed/plot3d/rectangle.rkt b/pkgs/plot/typed/private/plot3d/rectangle.rkt similarity index 100% rename from pkgs/plot/typed/plot3d/rectangle.rkt rename to pkgs/plot/typed/private/plot3d/rectangle.rkt diff --git a/pkgs/plot/typed/plot3d/surface.rkt b/pkgs/plot/typed/private/plot3d/surface.rkt similarity index 100% rename from pkgs/plot/typed/plot3d/surface.rkt rename to pkgs/plot/typed/private/plot3d/surface.rkt diff --git a/pkgs/plot/typed/syntax.rkt b/pkgs/plot/typed/private/syntax.rkt similarity index 100% rename from pkgs/plot/typed/syntax.rkt rename to pkgs/plot/typed/private/syntax.rkt diff --git a/pkgs/plot/typed/utils.rkt b/pkgs/plot/typed/utils.rkt index 8978a04c7b..312be922a9 100644 --- a/pkgs/plot/typed/utils.rkt +++ b/pkgs/plot/typed/utils.rkt @@ -1,38 +1,38 @@ -#lang typed/racket/base +#lang racket/base ;; The commented-out module paths are those that don't exist yet -(require "common/types.rkt" - ;"common/marching-squares.rkt" - ;"common/marching-cubes.rkt" - "contracted/parameters.rkt" - "contracted/math.rkt" - "contracted/axis-transform.rkt" - "contracted/ticks.rkt" - "contracted/format.rkt" - "contracted/draw.rkt" - "contracted/sample.rkt" ; incomplete - ;"contracted/samplers.rkt" - ;"contracted/legend.rkt" - ;"contracted/plot-element.rkt" - "contracted/date-time.rkt" - "contracted/kde.rkt" +(require "private/common/types.rkt" + ;"private/common/marching-squares.rkt" + ;"private/common/marching-cubes.rkt" + "private/contracted/parameters.rkt" + "private/contracted/math.rkt" + "private/contracted/axis-transform.rkt" + "private/contracted/ticks.rkt" + "private/contracted/format.rkt" + "private/contracted/draw.rkt" + "private/contracted/sample.rkt" ; incomplete + ;"private/contracted/samplers.rkt" + ;"private/contracted/legend.rkt" + ;"private/contracted/plot-element.rkt" + "private/contracted/date-time.rkt" + "private/contracted/kde.rkt" ) (provide (all-from-out - "common/types.rkt" - ;"common/marching-squares.rkt" - ;"common/marching-cubes.rkt" - "contracted/parameters.rkt" - "contracted/math.rkt" - "contracted/axis-transform.rkt" - "contracted/ticks.rkt" - "contracted/format.rkt" - "contracted/draw.rkt" - "contracted/sample.rkt" ; incomplete - ;"contracted/samplers.rkt" - ;"contracted/legend.rkt" - ;"contracted/plot-element.rkt" - "contracted/date-time.rkt" - "contracted/kde.rkt" + "private/common/types.rkt" + ;"private/common/marching-squares.rkt" + ;"private/common/marching-cubes.rkt" + "private/contracted/parameters.rkt" + "private/contracted/math.rkt" + "private/contracted/axis-transform.rkt" + "private/contracted/ticks.rkt" + "private/contracted/format.rkt" + "private/contracted/draw.rkt" + "private/contracted/sample.rkt" ; incomplete + ;"private/contracted/samplers.rkt" + ;"private/contracted/legend.rkt" + ;"private/contracted/plot-element.rkt" + "private/contracted/date-time.rkt" + "private/contracted/kde.rkt" )) diff --git a/pkgs/plot/utils.rkt b/pkgs/plot/utils.rkt index 30b9529448..ef3636a853 100644 --- a/pkgs/plot/utils.rkt +++ b/pkgs/plot/utils.rkt @@ -1,33 +1,33 @@ #lang racket/base -(require "common/contract.rkt" - "common/marching-squares.rkt" - "common/marching-cubes.rkt" - "contracted/parameters.rkt" - "contracted/math.rkt" - "contracted/axis-transform.rkt" - "contracted/ticks.rkt" - "contracted/format.rkt" - "contracted/draw.rkt" - "contracted/sample.rkt" - "contracted/samplers.rkt" - "contracted/legend.rkt" - "contracted/plot-element.rkt" - "contracted/date-time.rkt" - "contracted/kde.rkt") +(require "private/common/contract.rkt" + "private/common/marching-squares.rkt" + "private/common/marching-cubes.rkt" + "private/contracted/parameters.rkt" + "private/contracted/math.rkt" + "private/contracted/axis-transform.rkt" + "private/contracted/ticks.rkt" + "private/contracted/format.rkt" + "private/contracted/draw.rkt" + "private/contracted/sample.rkt" + "private/contracted/samplers.rkt" + "private/contracted/legend.rkt" + "private/contracted/plot-element.rkt" + "private/contracted/date-time.rkt" + "private/contracted/kde.rkt") -(provide (all-from-out "common/contract.rkt") - (all-from-out "common/marching-squares.rkt") - (all-from-out "common/marching-cubes.rkt") - (all-from-out "contracted/parameters.rkt") - (all-from-out "contracted/math.rkt") - (all-from-out "contracted/axis-transform.rkt") - (all-from-out "contracted/ticks.rkt") - (all-from-out "contracted/format.rkt") - (all-from-out "contracted/draw.rkt") - (all-from-out "contracted/sample.rkt") - (all-from-out "contracted/samplers.rkt") - (all-from-out "contracted/legend.rkt") - (all-from-out "contracted/plot-element.rkt") - (all-from-out "contracted/date-time.rkt") - (all-from-out "contracted/kde.rkt")) +(provide (all-from-out "private/common/contract.rkt") + (all-from-out "private/common/marching-squares.rkt") + (all-from-out "private/common/marching-cubes.rkt") + (all-from-out "private/contracted/parameters.rkt") + (all-from-out "private/contracted/math.rkt") + (all-from-out "private/contracted/axis-transform.rkt") + (all-from-out "private/contracted/ticks.rkt") + (all-from-out "private/contracted/format.rkt") + (all-from-out "private/contracted/draw.rkt") + (all-from-out "private/contracted/sample.rkt") + (all-from-out "private/contracted/samplers.rkt") + (all-from-out "private/contracted/legend.rkt") + (all-from-out "private/contracted/plot-element.rkt") + (all-from-out "private/contracted/date-time.rkt") + (all-from-out "private/contracted/kde.rkt"))