Changed uses of dynamic-require to uses of lazy-require
Changed return contracts of 'plot', 'plot-snip', 'plot3d' and 'plot3d-snip' to (is-a?/c image-snip%)
This commit is contained in:
parent
35ef2ade0c
commit
c9ffe2830b
|
@ -1,5 +1,9 @@
|
|||
(module fit mzscheme
|
||||
(require "math.rkt")
|
||||
(require unstable/lazy-require
|
||||
"math.rkt")
|
||||
|
||||
;; Require lazily so the rest of 'plot' still works without libfit:
|
||||
(lazy-require ["fit-low-level.rkt" (fit-internal)])
|
||||
|
||||
; a structure contain a the results of a curve-fit
|
||||
(define-struct fit-result (
|
||||
|
@ -14,8 +18,6 @@
|
|||
|
||||
; fit-int : (number* -> number) (list-of (symbol number)) (list-of (vector number [number] number number)) -> fit-result
|
||||
(define (fit-int function guesses data)
|
||||
;; Require dynamically so the rest of 'plot' still works without libfit:
|
||||
(define fit-internal (dynamic-require 'plot/deprecated/fit-low-level 'fit-internal))
|
||||
(let* ((independent-vars (- (procedure-arity function) (length guesses)))
|
||||
(f-of-x-y (cond
|
||||
[(= 1 independent-vars)
|
||||
|
|
|
@ -3,7 +3,10 @@
|
|||
;; Procedures that plot 2D renderers.
|
||||
|
||||
(require racket/draw racket/snip racket/contract racket/list racket/class racket/match
|
||||
(for-syntax racket/base syntax/strip-context racket/syntax)
|
||||
unstable/lazy-require
|
||||
(for-syntax racket/base
|
||||
syntax/strip-context
|
||||
racket/syntax)
|
||||
"../common/math.rkt"
|
||||
"../common/contract.rkt" "../common/contract-doc.rkt"
|
||||
"../common/legend.rkt"
|
||||
|
@ -15,6 +18,10 @@
|
|||
"renderer.rkt"
|
||||
"bounds.rkt")
|
||||
|
||||
;; Require lazily: without this, Racket complains while generating documentation:
|
||||
;; cannot instantiate `racket/gui/base' a second time in the same process
|
||||
(lazy-require ["../common/gui.rkt" (make-snip-frame)])
|
||||
|
||||
(provide plot/dc plot plot-bitmap plot-snip plot-frame plot-file)
|
||||
|
||||
;; ===================================================================================================
|
||||
|
@ -109,7 +116,7 @@
|
|||
[#: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 snip%)
|
||||
) (is-a?/c image-snip%)
|
||||
(define bm
|
||||
(plot-bitmap
|
||||
renderer-tree
|
||||
|
@ -128,7 +135,6 @@
|
|||
[#: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 make-snip-frame (dynamic-require 'plot/common/gui 'make-snip-frame))
|
||||
(define snip
|
||||
(plot-snip
|
||||
renderer-tree
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
#lang racket/base
|
||||
|
||||
(require racket/draw racket/snip racket/match racket/list racket/class racket/contract
|
||||
unstable/lazy-require
|
||||
(for-syntax racket/base)
|
||||
"../common/math.rkt"
|
||||
"../common/file-type.rkt"
|
||||
|
@ -12,6 +13,11 @@
|
|||
"renderer.rkt"
|
||||
"bounds.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)])
|
||||
|
||||
(provide plot3d/dc plot3d plot3d-bitmap plot3d-snip plot3d-frame plot3d-file)
|
||||
|
||||
;; ===================================================================================================
|
||||
|
@ -131,17 +137,16 @@
|
|||
[#: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 snip%)
|
||||
(define 3d-plot-snip% (dynamic-require 'plot/plot3d/snip '3d-plot-snip%))
|
||||
(make-object 3d-plot-snip%
|
||||
(λ (angle altitude anim?)
|
||||
(parameterize ([plot3d-animating? (if anim? #t (plot3d-animating?))])
|
||||
(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)))
|
||||
angle altitude))
|
||||
) (is-a?/c image-snip%)
|
||||
(make-3d-plot-snip
|
||||
(λ (angle altitude anim?)
|
||||
(parameterize ([plot3d-animating? (if anim? #t (plot3d-animating?))])
|
||||
(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)))
|
||||
angle altitude))
|
||||
|
||||
;; Plot to a frame
|
||||
(defproc (plot3d-frame [renderer-tree (treeof renderer3d?)]
|
||||
|
@ -158,7 +163,6 @@
|
|||
[#: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 make-snip-frame (dynamic-require 'plot/common/gui 'make-snip-frame))
|
||||
(define snip
|
||||
(plot3d-snip
|
||||
renderer-tree
|
||||
|
|
|
@ -5,7 +5,7 @@
|
|||
"../common/math.rkt"
|
||||
"area.rkt")
|
||||
|
||||
(provide 3d-plot-snip%)
|
||||
(provide 3d-plot-snip% make-3d-plot-snip)
|
||||
|
||||
(struct render-thread (state command-channel response-channel thread) #:mutable #:transparent)
|
||||
|
||||
|
@ -140,3 +140,7 @@
|
|||
(define/override (adjust-cursor dc x y editorx editory evt) cross-cursor)
|
||||
|
||||
(send this set-flags (list* 'handles-events (send this get-flags)))))
|
||||
|
||||
;; make-3d-plot-snip : (real real real -> bitmap) real real -> 3d-plot-snip%
|
||||
(define (make-3d-plot-snip make-bm angle altitude)
|
||||
(make-object 3d-plot-snip% make-bm angle altitude))
|
||||
|
|
|
@ -16,7 +16,7 @@ When @(racket #t), prints a deprecation warning to @(racket current-error-port)
|
|||
|
||||
@subsection{Output}
|
||||
|
||||
@doc-apply[plot-new-window?]{When @(racket #t), @(racket plot) and @(racket plot3d) open a new window for each plot instead of returning a snip.
|
||||
@doc-apply[plot-new-window?]{When @(racket #t), @(racket plot) and @(racket plot3d) open a new window for each plot instead of returning an @(racket image-snip%).
|
||||
|
||||
Users of command-line Racket, which cannot display image snips, should enter
|
||||
|
||||
|
|
|
@ -18,7 +18,7 @@
|
|||
[#: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 snip%) void?)]{
|
||||
) (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.
|
||||
|
@ -34,7 +34,7 @@ For example, they may be put in lists:
|
|||
|
||||
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 a @(racket snip%) or opening a new window.
|
||||
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,
|
||||
|
||||
|
@ -70,7 +70,7 @@ The @(racket #:lncolor) keyword argument is also accepted for backward compatibi
|
|||
[kind (one-of/c 'auto 'png 'jpeg 'xmb 'xpm 'bmp 'ps 'pdf 'svg) 'auto]
|
||||
[#:<plot-keyword> <plot-keyword> <plot-keyword-contract>] ...) void?]
|
||||
@defproc[(plot-bitmap [renderer-tree (treeof renderer2d?)] ...) (is-a?/c bitmap%)]
|
||||
@defproc[(plot-snip [renderer-tree (treeof renderer2d?)] ...) (is-a?/c snip%)]
|
||||
@defproc[(plot-snip [renderer-tree (treeof renderer2d?)] ...) (is-a?/c image-snip%)]
|
||||
@defproc[(plot-frame [renderer-tree (treeof renderer2d?)] ...) (is-a?/c frame%)])]{
|
||||
Plot to different backends. Each of these procedures has the same keyword arguments as @(racket plot).
|
||||
|
||||
|
@ -84,7 +84,7 @@ Use @(racket plot-bitmap) to create a bitmap.
|
|||
|
||||
Use @(racket plot-frame) to create a frame regardless of the value of @(racket plot-new-window?). The frame is initially hidden.
|
||||
|
||||
Use @(racket plot-snip) to create a snip regardless of the value of @(racket plot-new-window?).
|
||||
Use @(racket plot-snip) to create an image snip regardless of the value of @(racket plot-new-window?).
|
||||
}
|
||||
|
||||
@doc-apply[plot/dc]{
|
||||
|
|
|
@ -23,12 +23,12 @@ Each 3D plot procedure corresponds with a @(secref "plot2d") procedure. Each beh
|
|||
[#: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 snip%) void?)]{
|
||||
) (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 snip%) or opening a new window.
|
||||
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.
|
||||
|
||||
|
@ -45,7 +45,7 @@ The @(racket #:az) and @(racket #:alt) keyword arguments are backward-compatible
|
|||
[kind (one-of/c 'auto 'png 'jpeg 'xmb 'xpm 'bmp 'ps 'pdf 'svg) 'auto]
|
||||
[#:<plot-keyword> <plot-keyword> <plot-keyword-contract>] ...) void?]
|
||||
@defproc[(plot3d-bitmap [renderer-tree (treeof renderer3d?)] ...) (is-a?/c bitmap%)]
|
||||
@defproc[(plot3d-snip [renderer-tree (treeof renderer3d?)] ...) (is-a?/c snip%)]
|
||||
@defproc[(plot3d-snip [renderer-tree (treeof renderer3d?)] ...) (is-a?/c image-snip%)]
|
||||
@defproc[(plot3d-frame [renderer-tree (treeof renderer3d?)] ...) (is-a?/c frame%)])]{
|
||||
Plot to different backends. Each of these procedures has the same keyword arguments as @(racket plot3d).
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user