From 890882a6fde724a95a730508843bd7d3eea2f05a Mon Sep 17 00:00:00 2001 From: Robby Findler Date: Wed, 1 Jul 2009 18:24:47 +0000 Subject: [PATCH] added x-spacing and y-spacing parameters to traces and traces/ps svn: r15356 --- collects/redex/private/traces.ss | 22 ++++++++++++++-------- collects/redex/redex.scrbl | 7 +++++++ 2 files changed, 21 insertions(+), 8 deletions(-) diff --git a/collects/redex/private/traces.ss b/collects/redex/private/traces.ss index 633012865b..42ba9b4cad 100644 --- a/collects/redex/private/traces.ss +++ b/collects/redex/private/traces.ss @@ -124,8 +124,8 @@ get-point-size))) ;; the initial spacing between row and columns of the reduction terms -(define x-spacing 15) -(define y-spacing 15) +(define default-x-spacing 15) +(define default-y-spacing 15) (define (traces/ps reductions pre-exprs filename #:multiple? [multiple? #f] @@ -138,7 +138,9 @@ #:edge-labels? [edge-labels? #t] #:graph-pasteboard-mixin [extra-graph-pasteboard-mixin values] #:filter [term-filter (lambda (x y) #t)] - #:post-process [post-process void]) + #:post-process [post-process void] + #:x-spacing [x-spacing default-x-spacing] + #:y-spacing [y-spacing default-x-spacing]) (let-values ([(graph-pb canvas) (traces reductions pre-exprs #:no-show-frame? #t @@ -151,7 +153,9 @@ #:edge-label-font edge-label-font #:edge-labels? edge-labels? #:graph-pasteboard-mixin extra-graph-pasteboard-mixin - #:filter term-filter)]) + #:filter term-filter + #:x-spacing x-spacing + #:y-spacing y-spacing)]) (post-process graph-pb) (print-to-ps graph-pb canvas filename))) @@ -243,7 +247,9 @@ #:edge-labels? [edge-labels? #t] #:filter [term-filter (lambda (x y) #t)] #:graph-pasteboard-mixin [extra-graph-pasteboard-mixin values] - #:no-show-frame? [no-show-frame? #f]) + #:no-show-frame? [no-show-frame? #f] + #:x-spacing [x-spacing default-x-spacing] + #:y-spacing [y-spacing default-y-spacing]) (define exprs (if multiple? pre-exprs (list pre-exprs))) (define main-eventspace (current-eventspace)) (define saved-parameterization (current-parameterization)) @@ -438,7 +444,7 @@ (unless col ;; only compute col here, incase user moves snips (set! col (+ x-spacing (find-rightmost-x graph-pb)))) (begin0 - (insert-into col y graph-pb new-snips) + (insert-into col y graph-pb new-snips y-spacing) (send graph-pb end-edit-sequence) (send status-message set-label (string-append (term-count (count-snips)) "...")))))]) @@ -610,7 +616,7 @@ null))) (out-of-dot-state) ;; make sure the state is initialized right (set-font-size (initial-font-size)) ;; have to call this before 'insert-into' or else it triggers resizing - (insert-into init-rightmost-x 0 graph-pb frontier) + (insert-into init-rightmost-x 0 graph-pb frontier y-spacing) (cond [no-show-frame? (let ([s (make-semaphore)]) @@ -759,7 +765,7 @@ ;; inserts the snips into the pasteboard vertically ;; aligned, starting at (x,y). Returns ;; the y coordinate where another snip might be inserted. -(define (insert-into x y pb exprs) +(define (insert-into x y pb exprs y-spacing) (let loop ([exprs exprs] [y y]) (cond diff --git a/collects/redex/redex.scrbl b/collects/redex/redex.scrbl index 8a7027cd59..d55410a50c 100644 --- a/collects/redex/redex.scrbl +++ b/collects/redex/redex.scrbl @@ -1272,6 +1272,8 @@ exploring reduction sequences. [#:scheme-colors? scheme-colors? boolean? #t] [#:filter term-filter (-> any/c (or/c #f string?) any/c) (lambda (x y) #t)] + [#:x-spacing number? 15] + [#:y-spacing number? 15] [#:layout layout (-> (listof term-node?) void) void] [#:edge-labels? edge-label-font boolean? #t] [#:edge-label-font edge-label-font (or/c #f (is-a?/c font%)) #f] @@ -1338,6 +1340,9 @@ The @scheme[term-filter] function is called each time a new node is about to be inserted into the graph. If the filter returns false, the node is not inserted into the graph. +The @scheme[x-spacing] and @scheme[y-spacing] control the amount of +space put between the snips in the default layout. + The @scheme[layout] argument is called (with all of the terms) when new terms is inserted into the window. In general, it is called when after new terms are inserted in response to the user clicking on the @@ -1378,6 +1383,8 @@ inserted into the editor by this library have a [#:colors colors (listof (list string string)) '()] [#:filter term-filter (-> any/c (or/c #f string?) any/c) (lambda (x y) #t)] [#:layout layout (-> (listof term-node?) void) void] + [#:x-spacing number? 15] + [#:y-spacing number? 15] [#:edge-labels? edge-label-font boolean? #t] [#:edge-label-font edge-label-font (or/c #f (is-a?/c font%)) #f] [#:graph-pasteboard-mixin graph-pasteboard-mixin (make-mixin-contract graph-pasteboard<%>) values]