added support for customizing the edge label font to the graph library and propogated that argument to the redex traces and traces/ps functions

svn: r13155
This commit is contained in:
Robby Findler 2009-01-15 21:29:26 +00:00
parent b75dfb878a
commit a4799be53c
5 changed files with 38 additions and 13 deletions

View File

@ -231,6 +231,8 @@
(mixin ((class->interface pasteboard%)) (graph-pasteboard<%>) (mixin ((class->interface pasteboard%)) (graph-pasteboard<%>)
(inherit find-first-snip find-next-selected-snip) (inherit find-first-snip find-next-selected-snip)
(init-field [edge-label-font #f])
(define draw-arrow-heads? #t) (define draw-arrow-heads? #t)
(inherit refresh get-admin) (inherit refresh get-admin)
(define/public (set-draw-arrow-heads? x) (define/public (set-draw-arrow-heads? x)
@ -248,6 +250,8 @@
(unbox wb) (unbox wb)
(unbox hb)))))) (unbox hb))))))
(define arrowhead-angle-width (* 1/4 pi)) (define arrowhead-angle-width (* 1/4 pi))
(define arrowhead-short-side 8) (define arrowhead-short-side 8)
(define arrowhead-long-side 12) (define arrowhead-long-side 12)
@ -484,7 +488,12 @@
(define/override (on-paint before? dc left top right bottom dx dy draw-caret) (define/override (on-paint before? dc left top right bottom dx dy draw-caret)
(when before? (when before?
(draw-edges dc left top right bottom dx dy)) (let ([old-font (send dc get-font)])
(when edge-label-font
(send dc set-font edge-label-font))
(draw-edges dc left top right bottom dx dy)
(when edge-label-font
(send dc set-font old-font))))
(super on-paint before? dc left top right bottom dx dy draw-caret)) (super on-paint before? dc left top right bottom dx dy draw-caret))
(define/public (draw-edges dc left top right bottom dx dy) (define/public (draw-edges dc left top right bottom dx dy)

View File

@ -3,5 +3,13 @@
@defmixin/title[graph-pasteboard-mixin (pasteboard%) (graph-pasteboard<%>)]{ @defmixin/title[graph-pasteboard-mixin (pasteboard%) (graph-pasteboard<%>)]{
@defconstructor/auto-super[([edge-label-font (or/c #f (is-a?/c font%)) #f])]{
If @scheme[edge-label-font] is supplied, it is used when drawing the
labels on the edges. Otherwise, the font is not set before drawing
the labels, defaulting to the @scheme[dc<%>] object's font.
}
This mixin overrides many methods to draw lines between This mixin overrides many methods to draw lines between
@scheme[graph-snip<%>] that it contains.} @scheme[graph-snip<%>] that it contains.}

View File

@ -35,7 +35,8 @@
#:pp pp-contract #:pp pp-contract
#:colors (listof (list/c string? string?)) #:colors (listof (list/c string? string?))
#:scheme-colors? boolean? #:scheme-colors? boolean?
#:layout (-> any/c any/c)) #:layout (-> any/c any/c)
#:edge-label-font (or/c #f (is-a?/c font%)))
any)] any)]
[traces/ps (->* (reduction-relation? [traces/ps (->* (reduction-relation?
any/c any/c
@ -46,7 +47,8 @@
(any/c term-node? . -> . any)) (any/c term-node? . -> . any))
#:pp pp-contract #:pp pp-contract
#:colors (listof any/c) #:colors (listof any/c)
#:layout (-> any/c any/c)) #:layout (-> any/c any/c)
#:edge-label-font (or/c #f (is-a?/c font%)))
any)] any)]
[term-node? (-> any/c boolean?)] [term-node? (-> any/c boolean?)]

View File

@ -131,7 +131,9 @@
#:pp [pp default-pretty-printer] #:pp [pp default-pretty-printer]
#:scheme-colors? [scheme-colors? #t] #:scheme-colors? [scheme-colors? #t]
#:colors [colors '()] #:colors [colors '()]
#:layout [layout void]) #:layout [layout void]
#:edge-label-font [edge-label-font #f]
)
(let-values ([(graph-pb canvas) (let-values ([(graph-pb canvas)
(traces reductions pre-exprs (traces reductions pre-exprs
#:no-show-frame? #t #:no-show-frame? #t
@ -140,7 +142,8 @@
#:pp pp #:pp pp
#:scheme-colors? scheme-colors? #:scheme-colors? scheme-colors?
#:colors colors #:colors colors
#:layout layout)]) #:layout layout
#:edge-label-font edge-label-font)])
(print-to-ps graph-pb canvas filename))) (print-to-ps graph-pb canvas filename)))
(define (print-to-ps graph-pb canvas filename) (define (print-to-ps graph-pb canvas filename)
@ -227,11 +230,12 @@
#:colors [colors '()] #:colors [colors '()]
#:scheme-colors? [scheme-colors? #t] #:scheme-colors? [scheme-colors? #t]
#:layout [layout void] #:layout [layout void]
#:edge-label-font [edge-label-font #f]
#:no-show-frame? [no-show-frame? #f]) #:no-show-frame? [no-show-frame? #f])
(define exprs (if multiple? pre-exprs (list pre-exprs))) (define exprs (if multiple? pre-exprs (list pre-exprs)))
(define main-eventspace (current-eventspace)) (define main-eventspace (current-eventspace))
(define saved-parameterization (current-parameterization)) (define saved-parameterization (current-parameterization))
(define graph-pb (new graph-pasteboard% [layout layout])) (define graph-pb (new graph-pasteboard% [layout layout] [edge-label-font edge-label-font]))
(define f (instantiate red-sem-frame% () (define f (instantiate red-sem-frame% ()
(label "PLT Redex Reduction Graph") (label "PLT Redex Reduction Graph")
(style '(toolbar-button)) (style '(toolbar-button))

View File

@ -1157,7 +1157,8 @@ exploring reduction sequences.
(lambda (x) (member (length x) '(2 3 4 6))))))] (lambda (x) (member (length x) '(2 3 4 6))))))]
[#:scheme-colors? scheme-colors? boolean?] [#:scheme-colors? scheme-colors? boolean?]
[#:layout layout (-> (listof term-node?) void)]) [#:layout layout (-> (listof term-node?) void)]
[#:edge-label-font edge-label-font (or/c #f (is-a?/c font%)) #f])
void?]{ void?]{
This function opens a new window and inserts each expression This function opens a new window and inserts each expression
@ -1169,7 +1170,7 @@ found, or no more reductions can occur. It inserts each new
term into the gui. Clicking the @onscreen{reduce} button reduces term into the gui. Clicking the @onscreen{reduce} button reduces
until reduction-steps-cutoff more terms are found. until reduction-steps-cutoff more terms are found.
The pred function indicates if a term has a particular The @scheme[pred] function indicates if a term has a particular
property. If it returns @scheme[#f], the term is displayed with a property. If it returns @scheme[#f], the term is displayed with a
pink background. If it returns a string or a @scheme[color%] object, pink background. If it returns a string or a @scheme[color%] object,
the term is displayed with a background of that color (using the term is displayed with a background of that color (using
@ -1211,8 +1212,6 @@ the color that fills the arrow head. If fewer than six colors are
specified, the colors specified colors are used and then defaults are specified, the colors specified colors are used and then defaults are
filled in for the remaining colors. filled in for the remaining colors.
The @scheme[scheme-colors?] argument, if @scheme[#t] causes The @scheme[scheme-colors?] argument, if @scheme[#t] causes
@scheme[traces] to color the contents of each of the windows according @scheme[traces] to color the contents of each of the windows according
to DrScheme's Scheme mode color Scheme. If it is @scheme[#f], to DrScheme's Scheme mode color Scheme. If it is @scheme[#f],
@ -1224,8 +1223,10 @@ after new terms are inserted in response to the user clicking on the
reduce button, and after the initial set of terms is inserted. reduce button, and after the initial set of terms is inserted.
See also @scheme[term-node-set-position!]. See also @scheme[term-node-set-position!].
You can save the contents of the window as a postscript file The @scheme[edge-label-font] argument is used as the font on the edge
from the menus. labels. If nothign is suppled, the @scheme[dc<%>] object's default
font is used.
} }
@defproc[(traces/ps [reductions reduction-relation?] @defproc[(traces/ps [reductions reduction-relation?]
@ -1241,7 +1242,8 @@ from the menus.
(any output-port number (is-a?/c text%) -> void)) (any output-port number (is-a?/c text%) -> void))
default-pretty-printer] default-pretty-printer]
[#:colors colors (listof (list string string)) '()] [#:colors colors (listof (list string string)) '()]
[#:layout layout (-> (listof term-node?) void)]) [#:layout layout (-> (listof term-node?) void)]
[#:edge-label-font edge-label-font (or/c #f (is-a?/c font%)) #f])
void?]{ void?]{
The arguments behave just like the function @scheme[traces], but The arguments behave just like the function @scheme[traces], but