Skip to content

Commit a3fc67e

Browse files
author
matt
committed
Fixed scaling for graph
1 parent c862ca5 commit a3fc67e

File tree

2 files changed

+43
-23
lines changed

2 files changed

+43
-23
lines changed

dashboard.scm

+42-22
Original file line numberDiff line numberDiff line change
@@ -2641,15 +2641,16 @@ Misc
26412641
(zeroth-point (conc "SELECT " timef "," varfn "," valfn " FROM " tablen " WHERE " varfn "='" fieldname "' AND " timef " < " tstart " LIMIT 1")))
26422642
(print "all-dat-qrystr: " all-dat-qrystr)
26432643
(hash-table-set! res-ht fieldname ;; (fetch-rows (sql db qrystr)))))
2644-
(sqlite3:fold-row
2645-
(lambda (res t var val)
2646-
(cons (vector t var val) res))
2647-
'() db all-dat-qrystr))
2644+
(reverse
2645+
(sqlite3:fold-row
2646+
(lambda (res t var val)
2647+
(cons (vector t var val) res))
2648+
'() db all-dat-qrystr)))
26482649
(let ((zeropt (handle-exceptions
26492650
exn
26502651
#f
26512652
(sqlite3:first-row db all-dat-qrystr))))
2652-
(if zeropt
2653+
(if zeropt ;; NOTE: Add zeropt to the beginning of the list as the list was reversed above.
26532654
(hash-table-set! res-ht
26542655
fieldname
26552656
(cons
@@ -2669,7 +2670,7 @@ Misc
26692670
(dur (- tstart tend)) ;; time duration
26702671
(cmp (vg:get-component dwg "runslib" compname))
26712672
(cfg (configf:get-section *configdat* "graph"))
2672-
(stdcolor (vg:rgb->number 20 30 40)))
2673+
(stdcolor (vg:rgb->number 120 130 140)))
26732674
(vg:add-obj-to-comp
26742675
cmp
26752676
(vg:make-rect-obj llx lly ulx uly))
@@ -2682,23 +2683,42 @@ Misc
26822683
(let* ((dat (hash-table-ref alldat fieldn ))
26832684
(vals (map (lambda (x)(vector-ref x 2)) dat)))
26842685
(if (not (null? vals))
2685-
(let* ((maxval (apply max vals))
2686-
(minval (apply min vals))
2687-
(yoff (- lly minval))
2688-
(yscale (/ (- maxval minval)(- uly lly)))
2689-
(yfunc (lambda (y)(* (+ y yoff) yscale))))
2686+
(let* ((maxval (apply max vals))
2687+
(minval (apply min vals))
2688+
(yoff (- lly minval))
2689+
(deltaval (- maxval minval))
2690+
(yscale (/ (- uly lly)(if (eq? deltaval 0) 1 deltaval)))
2691+
(yfunc (lambda (y)(* (+ y yoff) yscale))))
26902692
;; (print (car cf) ": " (hash-table->alist
2691-
(for-each
2692-
(lambda (dpt)
2693-
(let* ((tval (vector-ref dpt 0))
2694-
(yval (vector-ref dpt 2))
2695-
(stval (tfn tval))
2696-
(syval (yfunc yval)))
2697-
(vg:add-obj-to-comp
2698-
cmp
2699-
(vg:make-rect-obj (- stval 2) lly (+ stval 2)(+ lly (* yval yscale))
2700-
fill-color: stdcolor))))
2701-
dat))))) ;; for each data point in the series
2693+
(fold
2694+
(lambda (next prev) ;; #(time ? val) #(time ? val)
2695+
(if prev
2696+
(let* ((last-tval (tfn (vector-ref prev 0)))
2697+
(last-yval (+ lly (* yscale (vector-ref prev 2))))
2698+
(curr-tval (tfn (vector-ref next 0))))
2699+
(if (> curr-tval last-tval)
2700+
(vg:add-obj-to-comp
2701+
cmp
2702+
(vg:make-rect-obj last-tval lly curr-tval last-yval ;; (- stval 2) lly (+ stval 2)(+ lly (* yval yscale))
2703+
fill-color: stdcolor
2704+
line-color: stdcolor))
2705+
(print "ERROR: curr-tval is not > last-tval; curr-tval " curr-tval ", last-tval " last-tval))))
2706+
next)
2707+
;; for init create vector tstart,0
2708+
#f ;; (vector tstart minval minval)
2709+
dat)
2710+
;; (for-each
2711+
;; (lambda (dpt)
2712+
;; (let* ((tval (vector-ref dpt 0))
2713+
;; (yval (vector-ref dpt 2))
2714+
;; (stval (tfn tval))
2715+
;; (syval (yfunc yval)))
2716+
;; (vg:add-obj-to-comp
2717+
;; cmp
2718+
;; (vg:make-rect-obj (- stval 2) lly (+ stval 2)(+ lly (* yval yscale))
2719+
;; fill-color: stdcolor))))
2720+
;; dat)
2721+
)))) ;; for each data point in the series
27022722
(hash-table-keys alldat)))))
27032723
cfg)))
27042724

gen-data-for-graph.scm

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
(+ thetime sec) ;; (* sec 60))
2424
"stuff"
2525
(if (even? thehour)
26-
(random 100)
26+
(random 1000)
2727
(random 6))))
2828
(if (< count 20)
2929
(loop (max sec lastsec)(random 60)(+ count 1))))))))

0 commit comments

Comments
 (0)