{"version":3,"file":"get-candlestick-domain.cjs","names":[],"sources":["../../../src/CandlestickChart/get-candlestick-domain/get-candlestick-domain.ts"],"sourcesContent":["export function isRenderableValue(value: unknown): value is number {\n  return typeof value === 'number' && Number.isFinite(value);\n}\n\ninterface GetCandlestickDomainInput {\n  data: Record<string, any>[];\n  openKey: string;\n  highKey: string;\n  lowKey: string;\n  closeKey: string;\n}\n\n/**\n * Calculates an explicit y-axis domain padded by 5% of the range. Rows with missing or\n * non-finite values are ignored – `NaN` and `Infinity` are numbers, and letting either\n * reach the bounds produces a `NaN` domain that blanks the entire chart instead of just\n * the offending row. Bounds are reduced iteratively rather than spread into\n * `Math.min`/`Math.max`, which throws on large datasets.\n *\n * A row counts only when all four OHLC values are renderable, which is the same condition\n * the candle shape uses. Taking `low`/`high` independently would let a half-filled row\n * stretch the domain toward a candle that is never drawn, squashing the real ones.\n */\nexport function getCandlestickDomain({\n  data,\n  openKey,\n  highKey,\n  lowKey,\n  closeKey,\n}: GetCandlestickDomainInput): [number, number] | undefined {\n  let dataMin = Infinity;\n  let dataMax = -Infinity;\n\n  for (const item of data) {\n    const low = item[lowKey];\n    const high = item[highKey];\n\n    if (![item[openKey], high, low, item[closeKey]].every(isRenderableValue)) {\n      continue;\n    }\n\n    if (low < dataMin) {\n      dataMin = low;\n    }\n\n    if (high > dataMax) {\n      dataMax = high;\n    }\n  }\n\n  if (dataMin === Infinity || dataMax === -Infinity) {\n    return undefined;\n  }\n\n  const padding = (dataMax - dataMin) * 0.05 || 1;\n\n  return [dataMin - padding, dataMax + padding];\n}\n"],"mappings":";;AAAA,SAAgB,kBAAkB,OAAiC;CACjE,OAAO,OAAO,UAAU,YAAY,OAAO,SAAS,KAAK;AAC3D;;;;;;;;;;;;AAqBA,SAAgB,qBAAqB,EACnC,MACA,SACA,SACA,QACA,YAC0D;CAC1D,IAAI,UAAU;CACd,IAAI,UAAU;CAEd,KAAK,MAAM,QAAQ,MAAM;EACvB,MAAM,MAAM,KAAK;EACjB,MAAM,OAAO,KAAK;EAElB,IAAI,CAAC;GAAC,KAAK;GAAU;GAAM;GAAK,KAAK;EAAS,CAAC,CAAC,MAAM,iBAAiB,GACrE;EAGF,IAAI,MAAM,SACR,UAAU;EAGZ,IAAI,OAAO,SACT,UAAU;CAEd;CAEA,IAAI,YAAY,YAAY,YAAY,WACtC;CAGF,MAAM,WAAW,UAAU,WAAW,OAAQ;CAE9C,OAAO,CAAC,UAAU,SAAS,UAAU,OAAO;AAC9C"}