Skip to content

Commit bbfdf23

Browse files
committed
Merge pull request #1837 from metabase/fix-pulse-rendering
manually back porting the fix from #1830 to the 0.14.0 release branch.
2 parents 8548ae3 + a078060 commit bbfdf23

File tree

1 file changed

+17
-10
lines changed

1 file changed

+17
-10
lines changed

src/metabase/pulse.clj

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
(ns metabase.pulse
22
(:require [clojure.java.io :as io]
33
(clojure [pprint :refer [cl-format]]
4+
[stacktrace :refer [print-stack-trace]]
45
[string :refer [upper-case]])
56
[clojure.tools.logging :as log]
67
(clj-time [coerce :as c]
@@ -324,12 +325,12 @@
324325
xmin (apply min xs)
325326
xmax (apply max xs)
326327
xrange (- xmax xmin)
327-
xs' (map #(/ (- % xmin) xrange) xs)
328+
xs' (map #(/ (double (- % xmin)) xrange) xs)
328329
ys (map second rows)
329330
ymin (apply min ys)
330331
ymax (apply max ys)
331332
yrange (max 1 (- ymax ymin)) ; `(max 1 ...)` so we don't divide by zero
332-
ys' (map #(/ (- % ymin) yrange) ys)
333+
ys' (map #(/ (double (- % ymin)) yrange) ys) ; cast to double to avoid "Non-terminating decimal expansion" errors
333334
rows' (reverse (take-last 2 rows))
334335
values (map (comp format-number second) rows')
335336
labels (format-timestamp-pair (map first rows') (first cols))]
@@ -376,12 +377,17 @@
376377
aggregation (-> card :dataset_query :query :aggregation first)]
377378
(cond
378379
(or (= aggregation :rows)
379-
(contains? #{:pin_map :state :country} (:display card))) nil
380-
(zero? row-count) :empty
381-
(and (= col-count 1) (= row-count 1)) :scalar
382-
(and (= col-count 2) (datetime-field? col-1) (number-field? col-2)) :sparkline
383-
(and (= col-count 2) (number-field? col-2)) :bar
384-
:else :table)))
380+
(contains? #{:pin_map :state :country} (:display card))) nil
381+
(zero? row-count) :empty
382+
(and (= col-count 1)
383+
(= row-count 1)) :scalar
384+
(and (= col-count 2)
385+
(> row-count 1)
386+
(datetime-field? col-1)
387+
(number-field? col-2)) :sparkline
388+
(and (= col-count 2)
389+
(number-field? col-2)) :bar
390+
:else :table)))
385391

386392
(defn render-pulse-card
387393
[card data render-img include-title include-buttons]
@@ -415,10 +421,11 @@
415421
:font-weight 700})}
416422
"We were unable to display this card." [:br] "Please view this card in Metabase."])]
417423
(catch Throwable e
418-
(log/warn (str "Pulse card render error:" e))
424+
(log/warn "Pulse card render error:" e)
419425
[:div {:style (style font-style
420426
{:color "#EF8C8C"
421-
:font-weight 700})}
427+
:font-weight 700
428+
:padding :16px})}
422429
"An error occurred while displaying this card."])))
423430

424431

0 commit comments

Comments
 (0)