You can use the table pict constructor to construct tables, 
https://docs.racket-lang.org/pict/Pict_Combiners.html?q=table#%28def._%28%28lib._pict%2Fmain..rkt%29._table%29%29

Here is an example:

    #lang racket
    (require racket/draw pict)

    (define (make-pretty-table items)
      (define column-count (length (car items)))
      (define picts '())
      (for (([row index] (in-indexed items)))
        (define font
          (if (= index 0) ;; header
              (send the-font-list find-or-create-font 12 'default 'normal 
'normal)
              (send the-font-list find-or-create-font 10 'default 'normal 
'normal)))
        (define color
          (if (= index 0)
              (make-object color% #x77 #x88 #x99)
              (make-object color% #x2f #x4f #x4f)))
        (define face (cons color font))
        (for ([item (in-list row)])
          (set! picts (cons (text (~a item) face) picts))))
      (let ((p0 (table column-count (reverse picts) lc-superimpose 
cc-superimpose 15 3)))
        (cc-superimpose
         (filled-rounded-rectangle (+ (pict-width p0) 20) (+ (pict-height 
p0) 20) -0.1
                                   #:draw-border? #f
                                   #:color "LightYellow")
         p0)))

Will produce

[image: Capture.PNG]
You can control how the text in the columns is aligned as well and gives 
you full flexibility on how each cell is displayed (it can be an arbitrary 
pict).

The disadvantage is that the output is not interactive, and for large sets 
of data it is impractical, still, you can get really nice results for small 
amounts of data.

A snip% would also be feasible, and this would allow to implement scrolling 
and other nice interactive features, but that is more of a weekend project, 
not a "before my morning coffee one" like the above code :-)

Alex.

On Thursday, March 14, 2019 at 2:19:07 AM UTC+8, Matt Jadud wrote:
>
> Hi all,
>
> I have a tabular data type that I'd like (I think) to be able to render it 
> either in ASCII or in a prettier way in the Interactions pane. I've 
> explored gen:write and friends, and can get the struct to display the way I 
> want---with ASCII. Essentially easy-peasy.
>
> What I wonder is: am I able to do something prettier? Can I encapsulate 
> some kind of styled rendering as a snip%, or... something... so that I can 
> render the first 5 and last 5 rows of a table with bolding of headers, 
> etc.? 
>
> I don't know where to start, essentially, if I wanted to try and do this. 
> Or, perhaps it is not particularly doable. 
>
> Pointers to examples in codebases are welcome (if such examples exist), 
> and I can work from there. Or, indications that this might be really 
> difficult are also welcome.
>
> Cheers,
> Matt
>
> (Apologies if this somehow comes through twice... I sent it to plt-scheme 
> first...)
>

-- 
You received this message because you are subscribed to the Google Groups 
"Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to racket-users+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to