Skip to content

Instantly share code, notes, and snippets.

Created Nov 4, 2018
What would you like to do?
Comparison of gnuplot, Incanter, oz/vega-lite for plotting usage data - Oz
(ns clj-charting.oz
[oz.core :as oz]
[incanter.core :refer :all]
[clj-charting.usage-chart-preparation :refer [read-usage-data moving-window-means]]))
(defn dataset->map-list
"Incanter dataset into a list of maps like
{\"0\" 1541065398391, \"1\" 446693376, \"2\" 99.9, \"cpu_mean\" 89}"
(let [rows (to-list ds)
means (moving-window-means 60 (sel ds :cols 2))]
(zipmap (map str (range)) %1)
"cpu_mean" %2)
(def gb4 (* 3 1024 1024 1024))
;; TODO Display legend - IMPOSSIBLE :-( until Datum
(def line-plot
(let [data (dataset->map-list (read-usage-data "siege-c10-all-urls-async-node11.dat"))
x-enc {:field "0"
:type "temporal"
:timeUnit "hoursminutesseconds" ; :aggregate "mean" l <- this kills points with same value
:axis {:title "Time"}
:scale {:zero false}}]
{:width 700
:data {:values data}
;;; 👇 requires VL v3 until then we have to compute cpu_mean using Incanter
;:transform [{:window [{:op "mean"
; :field "1"
; :as "cpu_mean"}]
; :frame [-10, 10]}]
; TODO VLv3: use this 👇 instead of repeating the X on each plot
;:encoding {:x x-enc}
:layer [{:mark {:type "line"
:clip true
:color "red"}
:encoding {:x x-enc
:y {:field "1"
:type "quantitative"
:axis {:format ".1s" :title "Memory" :labelColor "red" #_"required VL 3"}
:scale {:domain [0 gb4]}}}}
{:layer [
{:mark {:type "point"
:clip true}
:encoding {:x x-enc
:y {:field "2"
:type "quantitative"
:axis {:title "CPU [%]" :labelColor "blue"}}}}
{:mark {:type "line"
:clip true
:color "blue"}
:encoding {:x x-enc
:y {:field "cpu_mean"
:type "quantitative"
:title nil
:axis nil}}}]}]
:resolve {:scale {:y "independent"}}}))
(oz/v! line-plot)
Copy link

holyjak commented Nov 4, 2018

You can open the chart in the online Vega Editor and play with it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment