Skip to content
Snippets Groups Projects
Unverified Commit 910afcec authored by adam-james's avatar adam-james Committed by GitHub
Browse files

Fix condtional to properly render multi-line charts in static-viz (#25216)

parent f3e0dbbb
No related branches found
No related tags found
No related merge requests found
......@@ -85,17 +85,9 @@
(#{:pin_map :state :country} display-type)
(chart-type nil "display-type is %s" display-type)
(#{:area
:bar
:combo
:funnel
:progress
:table
:waterfall} display-type)
(chart-type display-type "display-type is %s" display-type)
;; for scalar/smartscalar, the display-type might actually be :line, so we can't have line above
(= @col-sample-count @row-sample-count 1)
(and (not= display-type :progress)
(= @col-sample-count @row-sample-count 1))
(chart-type :scalar "result has one row and one column")
(and (= display-type :smartscalar)
......@@ -103,19 +95,21 @@
(seq insights))
(chart-type :smartscalar "result has two columns and insights")
(#{:line
:area
:bar
:combo
:funnel
:progress
:table
:waterfall} display-type)
(chart-type display-type "display-type is %s" display-type)
(and (some? maybe-dashcard)
(> (count (dashboard-card/dashcard->multi-cards maybe-dashcard)) 0)
(not (#{:combo} display-type)))
(chart-type :multiple "result has multiple card semantics, a multiple chart")
;; we have to check when display-type is :line that there are enough rows/cols to actually create a line chart
;; if there is only 1 row and 1 col, the chart should be considered scalar, actually.
(and (= @col-sample-count 2)
(> @row-sample-count 1)
(number-field? @col-2)
(not (#{:waterfall :pie :table :area} display-type)))
(chart-type :line "result has 2 cols (%s and %s (number)) and > 1 row" (col-description @col-1) (col-description @col-2))
(and (= @col-sample-count 2)
(number-field? @col-2)
(= display-type :pie))
......
......@@ -38,81 +38,87 @@
"There was a problem with this question."))))
(deftest detect-pulse-chart-type-test
(is (= :scalar
(render/detect-pulse-chart-type {:display :anything}
{}
{:cols [{:base_type :type/Number}]
:rows [[6]]})))
(is (= :smartscalar
(render/detect-pulse-chart-type {:display :smartscalar}
{}
{:cols [{:base_type :type/Temporal
:name "month"}
{:base_type :type/Number
:name "apples"}]
:rows [[#t "2020" 2]
[#t "2021" 3]]
:insights [{:name "apples"
:last-value 3
:previous-value 2
:last-change 50.0}]})))
(is (= :bar
(render/detect-pulse-chart-type {:display :bar}
{}
{:cols [{:base_type :type/Text}
{:base_type :type/Number}]
:rows [["A" 2]]})))
(is (= :combo
(render/detect-pulse-chart-type {:display :combo}
{}
{:cols [{:base_type :type/Temporal}
{:base_type :type/Number}]
:rows [[#t "2020" 2]
[#t "2021" 3]]})))
(is (= :multiple
(mt/with-temp* [Card [card1 {:display :something}]
Card [card2 {:display :whatever}]
Dashboard [dashboard]
DashboardCard [dc1 {:dashboard_id (u/the-id dashboard) :card_id (u/the-id card1)}]
DashboardCardSeries [_ {:dashboardcard_id (u/the-id dc1) :card_id (u/the-id card2)}]]
(render/detect-pulse-chart-type card1
dc1
{:cols [{:base_type :type/Temporal}
(testing "Currently unsupported chart types for static-viz return `nil`."
(is (= [nil nil nil]
(map #(render/detect-pulse-chart-type {:display %}
{}
{:cols [{:base_type :type/Number}]
:rows [[2]]})
[:pin_map :state :country]))))
(testing "Queries resulting in no rows return `:empty`."
(is (= :empty
(render/detect-pulse-chart-type {:display :line}
{}
{:cols [{:base_type :type/Number}]
:rows [[nil]]}))))
(testing "Unrecognized display-types with otherwise valid results return `:table`."
(is (= :table
(render/detect-pulse-chart-type {:display :unrecognized}
{}
{:cols [{:base_type :type/Text}
{:base_type :type/Number}]
:rows [[#t "2020" 2]
[#t "2021" 3]]}))))
(is (= :funnel
(render/detect-pulse-chart-type {:display :funnel}
{}
{:cols [{:base_type :type/Text}
{:base_type :type/Number}]
:rows [["A" 2]]})))
;; timeseries line chart
(is (= :line
(render/detect-pulse-chart-type {:display :line}
{}
{:cols [{:base_type :type/Temporal}
{:base_type :type/Number}]
:rows [[#t "2020" 2]
[#t "2021" 3]]})))
;; Category line chart
(is (= :line
(render/detect-pulse-chart-type {:display :line}
{}
{:cols [{:base_type :type/Text}
{:base_type :type/Number}]
:rows [["Red" 2]
["Blue" 3]]})))
(is (= :categorical/donut
(render/detect-pulse-chart-type {:display :pie}
{}
{:cols [{:base_type :type/Text}
{:base_type :type/Number}]
:rows [["apple" 3]
["banana" 4]]}))))
:rows [["A" 2]
["B" 4]]}))))
(testing "Scalar and Smartscalar charts are correctly identified"
(is (= :scalar
(render/detect-pulse-chart-type {:display :line}
{}
{:cols [{:base_type :type/Number}]
:rows [[3]]})))
(is (= :scalar
(render/detect-pulse-chart-type {:display :scalar}
{}
{:cols [{:base_type :type/Number}]
:rows [[6]]})))
(is (= :smartscalar
(render/detect-pulse-chart-type {:display :smartscalar}
{}
{:cols [{:base_type :type/Temporal
:name "month"}
{:base_type :type/Number
:name "apples"}]
:rows [[#t "2020" 2]
[#t "2021" 3]]
:insights [{:name "apples"
:last-value 3
:previous-value 2
:last-change 50.0}]}))))
(testing "Progress charts are correctly identified"
(is (= :progress
(render/detect-pulse-chart-type {:display :progress}
{}
{:cols [{:base_type :type/Number}]
:rows [[6]]}))))
(testing "Various Single-Series display-types return correct chart-types."
(mapv #(is (= %
(render/detect-pulse-chart-type {:display %}
{}
{:cols [{:base_type :type/Text}
{:base_type :type/Number}]
:rows [["A" 2]
["B" 3]]})))
[:line :area :bar :combo :funnel :progress :table :waterfall]))
(testing "Pie charts are correctly identified and return `:categorical/donut`."
(is (= :categorical/donut
(render/detect-pulse-chart-type {:display :pie}
{}
{:cols [{:base_type :type/Text}
{:base_type :type/Number}]
:rows [["apple" 3]
["banana" 4]]}))))
(testing "Dashboard Cards can return `:multiple`."
(is (= :multiple
(mt/with-temp* [Card [card1 {:display :pie}]
Card [card2 {:display :funnel}]
Dashboard [dashboard]
DashboardCard [dc1 {:dashboard_id (u/the-id dashboard) :card_id (u/the-id card1)}]
DashboardCardSeries [_ {:dashboardcard_id (u/the-id dc1) :card_id (u/the-id card2)}]]
(render/detect-pulse-chart-type card1
dc1
{:cols [{:base_type :type/Temporal}
{:base_type :type/Number}]
:rows [[#t "2020" 2]
[#t "2021" 3]]}))))))
(deftest make-description-if-needed-test
(testing "Use Visualization Settings's description if it exists"
......
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