Skip to content

Commit

Permalink
FranzCross,result-detail: add barChart support
Browse files Browse the repository at this point in the history
  • Loading branch information
Bogdanp committed Nov 2, 2023
1 parent 2164030 commit 1272efa
Show file tree
Hide file tree
Showing 3 changed files with 76 additions and 55 deletions.
10 changes: 5 additions & 5 deletions FranzCross/records-table.rkt
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
"observable.rkt"
"preference.rkt"
"record-detail.rkt"
"result-dialog.rkt"
"result-detail.rkt"
"thread.rkt"
"topic-config.rkt"
"validator.rkt"
Expand Down Expand Up @@ -129,10 +129,10 @@
(apply-script script originals id))
(when (ApplyResult-reduced res)
(render
(result-dialog
(format "[~a] Result" topic)
(ApplyResult-reduced res))
(get-parent)))
(window
#:title (format "[~a] Result" topic)
(result-detail
(ApplyResult-reduced res)))))
(list->vector
(ApplyResult-items res))))
(define (do-publish-tombstone r)
Expand Down
71 changes: 71 additions & 0 deletions FranzCross/result-detail.rkt
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
#lang racket/gui/easy

(require franz/script
plot
racket/match
"common.rkt")

(provide
result-detail)

(define (result-detail v)
(match v
[(ReduceResult.text s)
(text-view s)]
[(ReduceResult.number n)
(text-view (number->string n))]
[(ReduceResult.barChart xlabel xs ylabel ys)
(plot-view
#:x-label xlabel
#:y-label ylabel
(discrete-histogram (map list xs ys)))]
[(ReduceResult.lineChart xlabel xs ylabel ys)
(plot-view
#:x-label xlabel
#:y-label ylabel
(lines (map list xs ys)))]))

(define (text-view s)
(hpanel
#:margin '(20 20)
#:min-size '(200 100)
#:alignment '(center center)
(text #:font system-font-xl s)))

(define (plot-view #:x-label x-label
#:y-label y-label
. trees)
(hpanel
#:min-size '(800 600)
(snip #f (λ (_ width height)
(apply
plot-snip
#:width width
#:height height
#:x-label x-label
#:y-label y-label
trees)))))

(module+ main
(require "observable.rkt")
(define-observables
[@kind 'text])
(render
(window
(vpanel
(choice
#:stretch '(#t #f)
'(text number lineChart)
#:choice->label symbol->string
#:selection @kind
@kind:=))
(observable-view
@kind
(lambda (kind)
(result-detail
(match kind
['text (ReduceResult.text "Hello")]
['number (ReduceResult.number 42)]
['lineChart (ReduceResult.lineChart
"x" '(1 2 3)
"y" '(4 5 6))])))))))
50 changes: 0 additions & 50 deletions FranzCross/result-dialog.rkt

This file was deleted.

0 comments on commit 1272efa

Please sign in to comment.