fix(funnel): fallback to 0 if nan for funnel
This commit is contained in:
@@ -27,3 +27,8 @@ export const max = (arr: (number | null | undefined)[]): number =>
|
|||||||
Math.max(...arr.filter(isNumber));
|
Math.max(...arr.filter(isNumber));
|
||||||
|
|
||||||
export const isFloat = (n: number) => n % 1 !== 0;
|
export const isFloat = (n: number) => n % 1 !== 0;
|
||||||
|
|
||||||
|
export const ifNaN = <T extends number>(
|
||||||
|
n: number | null | undefined,
|
||||||
|
defaultValue: T,
|
||||||
|
): T => (Number.isNaN(n) ? defaultValue : (n as T));
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
|
import { ifNaN } from '@openpanel/common';
|
||||||
import type { IChartEvent, IChartInput } from '@openpanel/validation';
|
import type { IChartEvent, IChartInput } from '@openpanel/validation';
|
||||||
import { last, reverse } from 'ramda';
|
import { last, reverse } from 'ramda';
|
||||||
import { escape } from 'sqlstring';
|
import { escape } from 'sqlstring';
|
||||||
@@ -222,9 +223,10 @@ export class FunnelService {
|
|||||||
}[],
|
}[],
|
||||||
)
|
)
|
||||||
.map((step, index, list) => {
|
.map((step, index, list) => {
|
||||||
const next = list[index + 1];
|
|
||||||
return {
|
return {
|
||||||
...step,
|
...step,
|
||||||
|
percent: ifNaN(step.percent, 0),
|
||||||
|
dropoffPercent: ifNaN(step.dropoffPercent, 0),
|
||||||
isHighestDropoff: (() => {
|
isHighestDropoff: (() => {
|
||||||
// Skip if current step has no dropoff
|
// Skip if current step has no dropoff
|
||||||
if (!step?.dropoffCount) return false;
|
if (!step?.dropoffCount) return false;
|
||||||
|
|||||||
Reference in New Issue
Block a user