|
1 | 1 | (ns metabase.pulse
|
2 | 2 | (:require [clojure.java.io :as io]
|
3 | 3 | (clojure [pprint :refer [cl-format]]
|
| 4 | + [stacktrace :refer [print-stack-trace]] |
4 | 5 | [string :refer [upper-case]])
|
5 | 6 | [clojure.tools.logging :as log]
|
6 | 7 | (clj-time [coerce :as c]
|
|
324 | 325 | xmin (apply min xs)
|
325 | 326 | xmax (apply max xs)
|
326 | 327 | xrange (- xmax xmin)
|
327 |
| - xs' (map #(/ (- % xmin) xrange) xs) |
| 328 | + xs' (map #(/ (double (- % xmin)) xrange) xs) |
328 | 329 | ys (map second rows)
|
329 | 330 | ymin (apply min ys)
|
330 | 331 | ymax (apply max ys)
|
331 | 332 | 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 |
333 | 334 | rows' (reverse (take-last 2 rows))
|
334 | 335 | values (map (comp format-number second) rows')
|
335 | 336 | labels (format-timestamp-pair (map first rows') (first cols))]
|
|
376 | 377 | aggregation (-> card :dataset_query :query :aggregation first)]
|
377 | 378 | (cond
|
378 | 379 | (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))) |
385 | 391 |
|
386 | 392 | (defn render-pulse-card
|
387 | 393 | [card data render-img include-title include-buttons]
|
|
415 | 421 | :font-weight 700})}
|
416 | 422 | "We were unable to display this card." [:br] "Please view this card in Metabase."])]
|
417 | 423 | (catch Throwable e
|
418 |
| - (log/warn (str "Pulse card render error:" e)) |
| 424 | + (log/warn "Pulse card render error:" e) |
419 | 425 | [:div {:style (style font-style
|
420 | 426 | {:color "#EF8C8C"
|
421 |
| - :font-weight 700})} |
| 427 | + :font-weight 700 |
| 428 | + :padding :16px})} |
422 | 429 | "An error occurred while displaying this card."])))
|
423 | 430 |
|
424 | 431 |
|
|
0 commit comments