Skip to content
Snippets Groups Projects
Commit b3023382 authored by Simon Belak's avatar Simon Belak
Browse files

Add customizable labels

parent fd818bb3
Branches
Tags
No related merge requests found
......@@ -4,7 +4,9 @@ metrics:
- Count: ["count"]
- CountDistinctFKs: [distinct, [dimension, FK]]
- Sum: [sum, [dimension, GenericNumber]]
- Avg: [avg, [dimension, GenericNumber]]
- Avg:
metric: [avg, [dimension, GenericNumber]]
name: Mean of [[GenericNumber]]
dimensions:
- Country:
field_type: GenericTable.Country
......@@ -36,10 +38,10 @@ dimensions:
- Timestamp:
field_type: DateTime
score: 60
- JoinDate:
- JoinDate:
field_type: GenericTable.JoinTimestamp
score: 50
- CreateDate:
- CreateDate:
field_type: CreationTimestamp
score: 80
- FK: FK
......
......@@ -348,7 +348,7 @@
definitions))
(defn- instantate-visualization
[dimensions metrics [k v]]
[[k v] dimensions metrics]
(let [dimension->name (comp vector :name dimensions)
metric->name (comp vector first :metric metrics)]
[k (-> v
......@@ -358,14 +358,14 @@
(u/update-when :graph.dimensions dimension->name))]))
(defn- instantiate-metadata
[context bindings x]
(let [fill-template (partial fill-template :string context bindings)]
(-> x
(update :title fill-template)
(u/update-when :visualization (partial instantate-visualization bindings
(:metrics context)))
(u/update-when :description fill-template)
(u/update-when :text fill-template))))
[x context bindings]
(-> (walk/postwalk (fn [form]
(if (string? form)
(fill-template :string context bindings form)
form))
x)
(u/update-when :visualization #(instantate-visualization % bindings
(:metrics context)))))
(defn- card-candidates
"Generate all potential cards given a card definition and bindings for
......@@ -398,7 +398,9 @@
dimensions
limit
order_by))]
(-> (instantiate-metadata context bindings card)
(-> card
(assoc :metrics metrics)
(instantiate-metadata context bindings)
(assoc :score score
:dataset_query query))))))))
......@@ -525,10 +527,10 @@
(let [context (->> rule
(make-context root)
(inject-root root))
dashboard (instantiate-metadata context {"this" root}
(-> rule
(select-keys [:title :description :groups])
(update :title str (name-postfix root))))
dashboard (-> rule
(select-keys [:title :description :groups])
(update :title str (name-postfix root))
(instantiate-metadata context {"this" root}))
filters (->> rule
:dashboard_filters
(mapcat (comp :matches (:dimensions context))))
......
......@@ -90,20 +90,35 @@
(map (comp colors #(mod % (count colors)) hash))
ensure-distinct-colors)}))))
(defn- visualization-settings
[{:keys [metrics x_label y_label series_labels visualization dimensions] :as card}]
(let [[display visualization-settings] visualization
metric-name (some-fn :name
(comp str/capitalize
name
first
:metric))]
{:display display
:visualization_settings
(-> visualization-settings
(merge (colorize card))
(cond->
(some :name metrics) (assoc :graph.series_labels (map metric-name metrics))
series_labels (assoc :graph.series_labels series_labels)
x_label (assoc :graph.x_axis.title_text x_label)
y_label (assoc :graph.y_axis.title_text y_label)))}))
(defn- add-card
"Add a card to dashboard `dashboard` at position [`x`, `y`]."
[dashboard {:keys [visualization title description dataset_query width height
collection] :as card} [x y]]
(let [[display visualization-settings] visualization
card (-> {:creator_id api/*current-user-id*
:dataset_query dataset_query
:description description
:display display
:name title
:visualization_settings (-> visualization-settings
(merge (colorize card)))
:collection_id collection
:id (gensym)}
[dashboard {:keys [title description dataset_query width height collection]
:as card} [x y]]
(let [card (-> {:creator_id api/*current-user-id*
:dataset_query dataset_query
:description description
:name title
:collection_id collection
:id (gensym)}
(merge (visualization-settings card))
card/populate-query-fields)]
(update dashboard :ordered_cards conj {:col y
:row x
......
......@@ -23,7 +23,8 @@
(def ^:private Identifier s/Str)
(def ^:private Metric {Identifier {(s/required-key :metric) MBQL
(s/required-key :score) Score}})
(s/required-key :score) Score
(s/optional-key :name) s/Str}})
(def ^:private Filter {Identifier {(s/required-key :filter) MBQL
(s/required-key :score) Score}})
......@@ -96,7 +97,10 @@
(s/optional-key :query) s/Str
(s/optional-key :width) Width
(s/optional-key :height) Height
(s/optional-key :group) s/Str}})
(s/optional-key :group) s/Str
(s/optional-key :y_label) s/Str
(s/optional-key :x_label) s/Str
(s/optional-key :series_labels) [s/Str]}})
(def ^:private Groups
{Identifier {(s/required-key :title) s/Str
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment