{"version":3,"file":"thresholds.cjs","sources":["../../../src/field/thresholds.ts"],"sourcesContent":["import { Field } from '../types/dataFrame';\nimport { FALLBACK_COLOR } from '../types/fieldColor';\nimport { Threshold, ThresholdsMode } from '../types/thresholds';\n\nexport const fallBackThreshold: Threshold = { value: 0, color: FALLBACK_COLOR };\n\nexport function getActiveThreshold(value: number, thresholds: Threshold[] | undefined): Threshold {\n  if (!thresholds || thresholds.length === 0) {\n    return fallBackThreshold;\n  }\n\n  let active = thresholds[0];\n\n  for (const threshold of thresholds) {\n    if (value >= threshold.value) {\n      active = threshold;\n    } else {\n      break;\n    }\n  }\n\n  return active;\n}\n\nexport function getActiveThresholdForValue(field: Field, value: number, percent: number): Threshold {\n  const { thresholds } = field.config;\n\n  if (thresholds?.mode === ThresholdsMode.Percentage) {\n    return getActiveThreshold(percent * 100, thresholds?.steps);\n  }\n\n  return getActiveThreshold(value, thresholds?.steps);\n}\n\n/**\n * Sorts the thresholds\n */\nexport function sortThresholds(thresholds: Threshold[]) {\n  return thresholds.sort((t1, t2) => t1.value - t2.value);\n}\n"],"names":["FALLBACK_COLOR","thresholds","ThresholdsMode"],"mappings":";;;;;;;;AAIO,MAAM,iBAAA,GAA+B,EAAE,KAAA,EAAO,CAAA,EAAG,OAAOA,yBAAA;AAExD,SAAS,kBAAA,CAAmB,OAAe,UAAA,EAAgD;AAChG,EAAA,IAAI,CAAC,UAAA,IAAc,UAAA,CAAW,MAAA,KAAW,CAAA,EAAG;AAC1C,IAAA,OAAO,iBAAA;AAAA,EACT;AAEA,EAAA,IAAI,MAAA,GAAS,WAAW,CAAC,CAAA;AAEzB,EAAA,KAAA,MAAW,aAAa,UAAA,EAAY;AAClC,IAAA,IAAI,KAAA,IAAS,UAAU,KAAA,EAAO;AAC5B,MAAA,MAAA,GAAS,SAAA;AAAA,IACX,CAAA,MAAO;AACL,MAAA;AAAA,IACF;AAAA,EACF;AAEA,EAAA,OAAO,MAAA;AACT;AAEO,SAAS,0BAAA,CAA2B,KA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