diff --git a/src/metabase/pulse/render/body.clj b/src/metabase/pulse/render/body.clj index 7445467300bcb1b3c05606772af5a4e1a5b4f6a2..902f68c8ac7c139e64d6f80f5c1d7b76ace0302d 100644 --- a/src/metabase/pulse/render/body.clj +++ b/src/metabase/pulse/render/body.clj @@ -309,24 +309,28 @@ x-col-settings (or (settings-from-column x-col column-settings) {}) y-col-settings (or (settings-from-column y-col column-settings) {}) x-format (merge - (if (isa? (:effective_type x-col) :type/Temporal) - {:date_style "MMMM D, YYYY"} - default-format) - x-col-settings) + (if (isa? (:effective_type x-col) :type/Temporal) + {:date_style "MMMM D, YYYY"} + default-format) + x-col-settings) y-format (merge - default-format - y-col-settings) + default-format + y-col-settings) default-x-type (if (isa? (:effective_type x-col) :type/Temporal) "timeseries" "ordinal")] - {:colors (public-settings/application-colors) - :stacking (if (:stackable.stack_type viz-settings) "stack" "none") - :show_values (boolean (:graph.show_values viz-settings)) - :x {:type (or (:graph.x_axis.scale viz-settings) default-x-type) - :format x-format} - :y {:type (or (:graph.y_axis.scale viz-settings) "linear") - :format y-format} - :labels labels})) + (merge + {:colors (public-settings/application-colors) + :stacking (if (:stackable.stack_type viz-settings) "stack" "none") + :show_values (boolean (:graph.show_values viz-settings)) + :x {:type (or (:graph.x_axis.scale viz-settings) default-x-type) + :format x-format} + :y {:type (or (:graph.y_axis.scale viz-settings) "linear") + :format y-format} + :labels labels} + (when (:graph.show_goal viz-settings) + {:goal {:value (:graph.goal_value viz-settings) + :label (or (:graph.goal_label viz-settings) (tru "Goal"))}})))) (defn- set-default-stacked "Default stack type is stacked for area chart with more than one metric. diff --git a/test/metabase/pulse/render/js_svg_test.clj b/test/metabase/pulse/render/js_svg_test.clj index 6d4f7b493f8c0e1f4145ca7a4bb45842c925a872..098894d9f15b89795dedd9d5c3efaa7c7f680b8b 100644 --- a/test/metabase/pulse/render/js_svg_test.clj +++ b/test/metabase/pulse/render/js_svg_test.clj @@ -119,6 +119,33 @@ (is (= true (s/valid? spec text-nodes)) text-nodes)))))) +(defn- combo-chart-hiccup + [series settings] + (let [s (.asString (js/execute-fn-name @context + "combo_chart" + (json/generate-string series) + (json/generate-string settings) + (json/generate-string (:colors settings))))] + (-> s parse-svg document-tag-hiccup))) + +(deftest goal-line-test + (let [goal-label "ASDF" + series [{:color "#999AC4" + :type :line + :data [["A" 1] ["B" 20] ["C" -4] ["D" 100]] + :yAxisPosition "left"}] + settings {:x {:type "ordinal"} + :y {:type "linear"} + :labels {:bottom "" :left "" :right ""}} + non-goal-hiccup (combo-chart-hiccup series settings) + non-goal-node (->> non-goal-hiccup (tree-seq vector? rest) (filter #(= goal-label (second %))) first)] + (testing "No goal line exists when there are no goal settings." + (is (= nil (second non-goal-node)))) + (let [goal-hiccup (combo-chart-hiccup series (merge settings {:goal {:value 0 :label goal-label}})) + goal-node (->> goal-hiccup (tree-seq vector? rest) (filter #(= goal-label (second %))) first)] + (testing "A goal line does exist when goal settings are present in the viz-settings" + (is (= goal-label (second goal-node))))))) + (deftest timelineseries-bar-test (let [rows [[#t "2020" 2] [#t "2021" 3]]