Skip to content
Snippets Groups Projects
Unverified Commit 18659376 authored by dpsutton's avatar dpsutton Committed by GitHub
Browse files

categorical bar on the backend (#17620)

parent da3a3f58
No related branches found
No related tags found
No related merge requests found
......@@ -215,13 +215,17 @@
(list table-body))}))
(s/defmethod render :bar :- common/RenderedPulseCard
[_ render-type _timezone-id :- (s/maybe s/Str) card {:keys [cols] :as data}]
[_ render-type _timezone-id :- (s/maybe s/Str) card {:keys [cols rows] :as data}]
(let [[x-axis-rowfn y-axis-rowfn] (common/graphing-column-row-fns card data)
rows (common/non-nil-rows x-axis-rowfn y-axis-rowfn (:rows data))
rows (map (juxt x-axis-rowfn y-axis-rowfn)
(common/non-nil-rows x-axis-rowfn y-axis-rowfn rows))
svg-fn (if (isa? (-> cols x-axis-rowfn :effective_type) :type/Temporal)
js-svg/timelineseries-bar
js-svg/categorical-bar)
image-bundle (image-bundle/make-image-bundle
render-type
(js-svg/timelineseries-bar
(mapv (juxt x-axis-rowfn y-axis-rowfn) rows)
(svg-fn
rows
{:bottom (-> cols x-axis-rowfn :display_name)
:left (-> cols y-axis-rowfn :display_name)}))]
{:attachments
......
......@@ -45,6 +45,11 @@ const date_accessors = {
y: (row) => row[1],
}
const positional_accessors = {
x: (row) => row[0],
y: (row) => row[1],
}
const dimension_accessors = {
dimension: (row) => row[0],
metric: (row) => row[1],
......@@ -66,6 +71,14 @@ function timeseries_bar (data, labels) {
})
}
function categorical_bar (data, labels) {
return StaticViz.RenderChart(\"categorical/bar\", {
data: toJSArray(data),
labels: toJSMap(labels),
accessors: positional_accessors
})
}
function categorical_donut (rows, colors) {
return StaticViz.RenderChart(\"categorical/donut\", {
data: toJSArray(rows),
......@@ -157,12 +170,20 @@ function categorical_donut (rows, colors) {
(defn timelineseries-bar
"Clojure entrypoint to render a timeseries bar char. Rows should be tuples of [datetime numeric-value]. Labels is a
map of {:left \"left-label\" :right \"right-label\"}. Returns a byte array of a png file"
map of {:left \"left-label\" :right \"right-label\"}. Returns a byte array of a png file."
[rows labels]
(let [svg-string (.asString (js/execute-fn-name @context "timeseries_bar" rows
(map (fn [[k v]] [(name k) v]) labels)))]
(svg-string->bytes svg-string)))
(defn categorical-bar
"Clojure entrypoint to render a categorical bar chart. Rows should be tuples of [stringable numeric-value]. Labels is
a map of {:left \"left-label\" :right \"right-label\". Returns a byte array of a png file. "
[rows labels]
(let [svg-string (.asString (js/execute-fn-name @context "categorical_bar" rows
(map (fn [[k v]] [(name k) v]) labels)))]
(svg-string->bytes svg-string)))
(defn categorical-donut
"Clojure entrypoint to render a categorical donut chart. Rows should be tuples of [category numeric-value]. Returns a
byte array of a png file"
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment