{"version":3,"file":"get-candle-geometry.cjs","names":["isRenderableValue"],"sources":["../../../src/CandlestickChart/get-candle-geometry/get-candle-geometry.ts"],"sourcesContent":["import { isRenderableValue } from '../get-candlestick-domain/get-candlestick-domain';\n\nexport interface GetCandleGeometryInput {\n  /** Left edge of the slot recharts allocated to the candle */\n  x: number;\n\n  /** Top edge of the slot, corresponding to `high` */\n  y: number;\n\n  /** Width of the slot */\n  width: number;\n\n  /** Height of the slot, spanning `high` to `low` */\n  height: number;\n\n  open: unknown;\n  high: unknown;\n  low: unknown;\n  close: unknown;\n}\n\nexport interface CandleGeometry {\n  /** Horizontal center of the slot, where the wick is drawn */\n  centerX: number;\n\n  /** Top of the open/close body */\n  bodyY: number;\n\n  /** Height of the open/close body, never less than 1px so a doji stays visible */\n  bodyHeight: number;\n\n  /** `true` when the candle closed at or above its open */\n  isUp: boolean;\n}\n\n/**\n * Maps one OHLC row onto the slot recharts allocated for it. Returns `null` when the row\n * cannot be drawn – the same condition `getCandlestickDomain` uses to decide which rows\n * contribute to the axis, so the two never disagree about what is on the chart.\n */\nexport function getCandleGeometry({\n  x,\n  y,\n  width,\n  height,\n  open,\n  high,\n  low,\n  close,\n}: GetCandleGeometryInput): CandleGeometry | null {\n  if (![open, high, low, close].every(isRenderableValue)) {\n    return null;\n  }\n\n  const range = (high as number) - (low as number);\n  const ratio = range === 0 ? 0 : height / range;\n  const openY = y + ((high as number) - (open as number)) * ratio;\n  const closeY = y + ((high as number) - (close as number)) * ratio;\n\n  return {\n    centerX: x + width / 2,\n    bodyY: Math.min(openY, closeY),\n    bodyHeight: Math.max(Math.abs(closeY - openY), 1),\n    isUp: (close as number) >= (open as number),\n  };\n}\n"],"mappings":";;;;;;;;AAwCA,SAAgB,kBAAkB,EAChC,GACA,GACA,OACA,QACA,MACA,MACA,KACA,SACgD;CAChD,IAAI,CAAC;EAAC;EAAM;EAAM;EAAK;CAAK,CAAC,CAAC,MAAMA,+BAAAA,iBAAiB,GACnD,OAAO;CAGT,MAAM,QAAS,OAAmB;CAClC,MAAM,QAAQ,UAAU,IAAI,IAAI,SAAS;CACzC,MAAM,QAAQ,KAAM,OAAmB,QAAmB;CAC1D,MAAM,SAAS,KAAM,OAAmB,SAAoB;CAE5D,OAAO;EACL,SAAS,IAAI,QAAQ;EACrB,OAAO,KAAK,IAAI,OAAO,MAAM;EAC7B,YAAY,KAAK,IAAI,KAAK,IAAI,SAAS,KAAK,GAAG,CAAC;EAChD,MAAO,SAAqB;CAC9B;AACF"}