Easy Module:canvas example "dashboard part" (unix)

Started by newdep, July 27, 2009, 04:41:41 AM

Previous topic - Next topic

newdep

Below the dashboard part for disks, Easy use of the canvas module.


#!/usr/bin/newlisp
# part of system dashboard v0.1 by nodep (c) 2009

;; -------------------------------------------------------------------
;; Disk PIE Usage from OS
;; -------------------------------------------------------------------
;; get data from 'df' and create a data-list can differ per OS.
;; output is here in GIGABYTES -h, no swap space included.
;; -------------------------------------------------------------------
(setq disks (exec {df -lhP}))
(setq disks-usage (pop disks))
(setq disks (map (fn(x) (clean empty? (parse x " "))) disks))
;; -------------------------------------------------------------------

(load "canvas.lsp")

(html "<h3>DashBoard</h3>")

;; overall canvas size
(setq canvas-width  800)
(setq canvas-height 400)
(cv:canvas "dashboard" canvas-width canvas-height)

;; display global date indicator
(cv:font "normal 18px sans-serif")
(cv:goto 10 (- canvas-height 18) )
(cv:angle 90)
(cv:text (string "System Status:  " (date)))
(cv:angle 0)

;; create a pie with usage for the disk
;; x, y position the canvas
(define (pie-disk x y disk)

    (setq radius  50)
    (setq grad   360)

    (cv:goto x y)
    (cv:fill-color 1 1 0.9)
    (cv:rectangle 160 200 true)
    (cv:fill-color 0 0 1)
    (cv:font "normal 8px sans-serif")
    (cv:angle 90)
    (cv:goto (+ x 10) (+ y 180))
    (cv:text (string "Disk name: " (disk  0)) )
    (cv:goto (+ x 10) (+ y 170))
    (cv:text (string "Disk mount:" (disk -1)) )
    (cv:goto (+ x 10) (+ y 160))
    (cv:text (string "Disk Size: " (disk  1)) )
    (cv:goto (+ x 10) (+ y 150))
    (cv:text (string "Disk Used: " (disk  2)) )
    (cv:goto (+ x 10) (+ y 140))
    (cv:text (string "Disk Free: " (disk  3)) )

    ;; return value or 0 when nil returned from int
    (setq disk-used (or (int (0 -1 (disk 2))) 0))
    (setq disk-size (int (0 -1 (disk 1))) )
    (setq pie-used  (div grad (div disk-size disk-used)))

    (cv:angle 0)
    (cv:goto (+ x 80) (+ y 80))
    (cv:fill-color 0 0.5 0)
    (cv:pie radius grad true)
    (cv:fill-color 0.9 0 0)
    (cv:pie radius pie-used true)
)

;; -------------------------------------------------------------------
;; PIE
;; -------------------------------------------------------------------
(setq pie-disk-width  160)
(setq pie-disk-height 200)

;; draw pie-disks horizontal
(dolist (d disks)
  (pie-disk (+ (* $idx pie-disk-width) (+ (* $idx 10) 10)) (- canvas-height pie-disk-height 50) (disks $idx) ))

;(cv:render "dashboard.html")
(cv:render)
(exit)






The result can be saved from youre browser directly

and could look like this ->



http://www.nodep.nl/downloads/newlisp/dashboard.png">
-- (define? (Cornflakes))