fix(funnel): fallback to 0 if nan for funnel

This commit is contained in:
Carl-Gerhard Lindesvärd
2025-03-23 22:13:10 +01:00
parent aeb9abcb13
commit f313356096
2 changed files with 8 additions and 1 deletions

View File

@@ -27,3 +27,8 @@ export const max = (arr: (number | null | undefined)[]): number =>
Math.max(...arr.filter(isNumber));
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));

View File

@@ -1,3 +1,4 @@
import { ifNaN } from '@openpanel/common';
import type { IChartEvent, IChartInput } from '@openpanel/validation';
import { last, reverse } from 'ramda';
import { escape } from 'sqlstring';
@@ -222,9 +223,10 @@ export class FunnelService {
}[],
)
.map((step, index, list) => {
const next = list[index + 1];
return {
...step,
percent: ifNaN(step.percent, 0),
dropoffPercent: ifNaN(step.dropoffPercent, 0),
isHighestDropoff: (() => {
// Skip if current step has no dropoff
if (!step?.dropoffCount) return false;