Skip to content
Snippets Groups Projects
Unverified Commit 0c190ec6 authored by Howon Lee's avatar Howon Lee Committed by GitHub
Browse files

Waterfall bignum display fix (#19025) (#19563)

This actually has nothing to do with waterfalls. Really, it's that static viz is brutally incompatible with bignum types, bigint and bigdec. However, nothing will fit in the screen anyways if you actually need a bignum or bigint type so the solution was to just coerce and be OK with exploding if it actually needed bignum range.
parent 14e18c55
No related merge requests found
......@@ -404,7 +404,7 @@
[_ render-type _timezone-id :- (s/maybe s/Str) card _ {:keys [rows] :as data}]
(let [[x-axis-rowfn y-axis-rowfn] (common/graphing-column-row-fns card data)
rows (map (juxt (comp str x-axis-rowfn) y-axis-rowfn)
(common/non-nil-rows x-axis-rowfn y-axis-rowfn rows))
(common/row-preprocess x-axis-rowfn y-axis-rowfn rows))
slice-threshold (or (get-in card [:visualization_settings :pie.slice_threshold])
2.5)
{:keys [rows percentages]} (donut-info slice-threshold rows)
......@@ -489,7 +489,7 @@
row-seqs (for [[row-seq rowfnpair] (map vector row-seqs rowfns)]
(let [[x-rowfn y-rowfn] rowfnpair]
(map (juxt x-rowfn y-rowfn)
(common/non-nil-rows x-rowfn y-rowfn row-seq))))
(common/row-preprocess x-rowfn y-rowfn row-seq))))
col-seqs (map :cols multi-data)
first-rowfns (first rowfns)
[x-col y-col] ((juxt (first first-rowfns) (second first-rowfns)) (first col-seqs))
......@@ -742,10 +742,8 @@
y-axis-rowfn] (common/graphing-column-row-fns card data)
[x-col y-col] ((juxt x-axis-rowfn y-axis-rowfn) cols)
rows (map (juxt x-axis-rowfn y-axis-rowfn)
(common/non-nil-rows x-axis-rowfn y-axis-rowfn rows))
(common/row-preprocess x-axis-rowfn y-axis-rowfn rows))
last-rows (reverse (take-last 2 rows))
values (for [row last-rows]
(some-> row y-axis-rowfn common/format-number))
labels (x-and-y-axis-label-info x-col y-col viz-settings)
render-fn (if (isa? (-> cols x-axis-rowfn :effective_type) :type/Temporal)
js-svg/timelineseries-waterfall
......@@ -767,7 +765,7 @@
(s/defmethod render :funnel :- common/RenderedPulseCard
[_ render-type timezone-id card _ {:keys [rows cols viz-settings] :as data}]
;; x-axis-rowfn is always first, y-axis-rowfn is always second
(let [rows (common/non-nil-rows first second rows)
(let [rows (common/row-preprocess first second rows)
[x-col y-col] cols
settings (->js-viz x-col y-col viz-settings)
settings (assoc settings
......
......@@ -94,13 +94,31 @@
(or (ui-logic/y-axis-rowfn card data)
second)])
(defn non-nil-rows
"Remove any rows that have a nil value for the `x-axis-fn` OR `y-axis-fn`"
[x-axis-fn y-axis-fn rows]
(filter (every-pred x-axis-fn y-axis-fn) rows))
(defn coerce-bignum-to-int
"Graal polyglot system (not the JS machine itself, the polyglot system)
is not happy with BigInts or BigDecimals.
For more information, this is the GraalVM issue, open a while
https://github.com/oracle/graal/issues/2737
Because of this unfortunately they all have to get smushed into normal ints and decimals in JS land."
[row]
(for [member row]
(cond
;; this returns true for bigint only, not normal int or long
(instance? clojure.lang.BigInt member)
(int member)
;; this returns true for bigdec only, not actual normal decimals
;; not the clearest clojure native function in the world
(decimal? member)
(double member)
:else
member)))
(defn non-nil-combo-rows
"Remove any rows that have a nil value for the entire row because
the row-function-generating functions themselves choke on nil values, for combo rowfuncs"
[rows]
(filter #(every? some? %) rows))
(defn row-preprocess
"Preprocess rows.
- Removes any rows that have a nil value for the `x-axis-fn` OR `y-axis-fn`
- Normalizes bigints and bigdecs to ordinary sizes"
[x-axis-fn y-axis-fn rows]
(map coerce-bignum-to-int (filter (every-pred x-axis-fn y-axis-fn) rows)))
......@@ -107,7 +107,7 @@
[timezone-id :- (s/maybe s/Str) card {:keys [rows cols], :as data}]
(let [[x-axis-rowfn y-axis-rowfn] (common/graphing-column-row-fns card data)
format-val (format-val-fn timezone-id cols x-axis-rowfn)
present-rows (common/non-nil-rows x-axis-rowfn y-axis-rowfn rows)
present-rows (common/row-preprocess x-axis-rowfn y-axis-rowfn rows)
formatted-value (comp format-val x-axis-rowfn)
x-col (x-axis-rowfn cols)]
(if (and (comparable? x-col)
......
......@@ -481,6 +481,10 @@
(is (has-inline-image?
(render-waterfall {:cols default-columns
:rows [[10.0 1] [5.0 10] [2.50 20] [1.25 30]]}))))
(testing "Render a waterfall graph with bigdec, bigint values for the x and y axis"
(is (has-inline-image?
(render-waterfall {:cols default-columns
:rows [[10.0M 1M] [5.0 10N] [2.50 20N] [1.25M 30]]}))))
(testing "Check to make sure we allow nil values for the y-axis"
(is (has-inline-image?
(render-waterfall {:cols default-columns
......
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