/* Copyright © 2020 Splunk Inc.
SPLUNK CONFIDENTIAL – Use or disclosure of this material in whole or
in part without a valid written license from Splunk Inc. is PROHIBITED. */
var __create = Object.create;
var __defProp = Object.defineProperty;
var __defProps = Object.defineProperties;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
var __getProtoOf = Object.getPrototypeOf;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __propIsEnum = Object.prototype.propertyIsEnumerable;
var __pow = Math.pow;
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
var __spreadValues = (a, b) => {
  for (var prop in b || (b = {}))
    if (__hasOwnProp.call(b, prop))
      __defNormalProp(a, prop, b[prop]);
  if (__getOwnPropSymbols)
    for (var prop of __getOwnPropSymbols(b)) {
      if (__propIsEnum.call(b, prop))
        __defNormalProp(a, prop, b[prop]);
    }
  return a;
};
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
var __objRest = (source, exclude) => {
  var target = {};
  for (var prop in source)
    if (__hasOwnProp.call(source, prop) && exclude.indexOf(prop) < 0)
      target[prop] = source[prop];
  if (source != null && __getOwnPropSymbols)
    for (var prop of __getOwnPropSymbols(source)) {
      if (exclude.indexOf(prop) < 0 && __propIsEnum.call(source, prop))
        target[prop] = source[prop];
    }
  return target;
};
var __export = (target, all) => {
  for (var name in all)
    __defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
  if (from && typeof from === "object" || typeof from === "function") {
    for (let key of __getOwnPropNames(from))
      if (!__hasOwnProp.call(to, key) && key !== except)
        __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
  }
  return to;
};
var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
  // If the importer is in node compatibility mode or this is not an ESM
  // file that has been converted to a CommonJS file using a Babel-
  // compatible transform (i.e. "__esModule" has not been set), then set
  // "default" to the CommonJS "module.exports" for node compatibility.
  isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
  mod
));
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);

// src/Heatmap.tsx
var Heatmap_exports = {};
__export(Heatmap_exports, {
  Heatmap: () => Heatmap
});
module.exports = __toCommonJS(Heatmap_exports);

// esm-externals:lodash
var lodash_exports = {};
__export(lodash_exports, {
  default: () => lodash_default
});
var defaultImport = __toESM(require("lodash"));
__reExport(lodash_exports, require("lodash"));
var lodash_default = "default" in defaultImport ? defaultImport.default : defaultImport;

// esm-externals:react
var react_exports = {};
__export(react_exports, {
  default: () => react_default
});
var defaultImport2 = __toESM(require("react"));
__reExport(react_exports, require("react"));
var react_default = "default" in defaultImport2 ? defaultImport2.default : defaultImport2;

// esm-externals:uplot
var uplot_exports = {};
__export(uplot_exports, {
  default: () => uplot_default
});
var defaultImport3 = __toESM(require("uplot"));
__reExport(uplot_exports, require("uplot"));
var uplot_default = "default" in defaultImport3 ? defaultImport3.default : defaultImport3;

// esm-externals:uplot-react
var uplot_react_exports = {};
__export(uplot_react_exports, {
  default: () => uplot_react_default
});
var defaultImport4 = __toESM(require("uplot-react"));
__reExport(uplot_react_exports, require("uplot-react"));
var uplot_react_default = "default" in defaultImport4 ? defaultImport4.default : defaultImport4;

// esm-externals:uplot/dist/uPlot.min.css
var uPlot_min_exports = {};
__export(uPlot_min_exports, {
  default: () => uPlot_min_default
});
var defaultImport5 = __toESM(require("uplot/dist/uPlot.min.css"));
__reExport(uPlot_min_exports, require("uplot/dist/uPlot.min.css"));
var uPlot_min_default = "default" in defaultImport5 ? defaultImport5.default : defaultImport5;

// esm-externals:@splunk/themes
var themes_exports = {};
__export(themes_exports, {
  default: () => themes_default
});
var defaultImport6 = __toESM(require("@splunk/themes"));
__reExport(themes_exports, require("@splunk/themes"));
var themes_default = "default" in defaultImport6 ? defaultImport6.default : defaultImport6;

// esm-externals:@splunk/ui-utils/format
var format_exports = {};
__export(format_exports, {
  default: () => format_default
});
var defaultImport7 = __toESM(require("@splunk/ui-utils/format"));
__reExport(format_exports, require("@splunk/ui-utils/format"));
var format_default = "default" in defaultImport7 ? defaultImport7.default : defaultImport7;

// src/utilities/def.ts
var def = (value) => value !== void 0 && value !== null;

// src/utilities/scaleTime.ts
var timeScaleMap = {
  ["w" /* Weeks */]: { unit: "w", scaleUp: null, scaleUpValue: null, decimalPlaces: 0 },
  ["d" /* Days */]: {
    unit: "d",
    scaleUp: "w" /* Weeks */,
    scaleUpValue: 7,
    decimalPlaces: 0
  },
  ["h" /* Hours */]: { unit: "h", scaleUp: "d" /* Days */, scaleUpValue: 24, decimalPlaces: 1 },
  ["m" /* Minutes */]: {
    unit: "m",
    scaleUp: "h" /* Hours */,
    scaleUpValue: 60,
    decimalPlaces: 1
  },
  ["s" /* Seconds */]: {
    unit: "s",
    scaleUp: "m" /* Minutes */,
    scaleUpValue: 60,
    decimalPlaces: 2
  },
  ["ms" /* Milliseconds */]: {
    unit: "ms",
    scaleUp: "s" /* Seconds */,
    scaleUpValue: 1e3,
    decimalPlaces: 0
  },
  ["us" /* Microseconds */]: {
    unit: `${String.fromCharCode(181)}s`,
    scaleUp: "ms" /* Milliseconds */,
    scaleUpValue: 1e3,
    decimalPlaces: 0
  },
  ["ns" /* Nanoseconds */]: {
    unit: "ns",
    scaleUp: "us" /* Microseconds */,
    scaleUpValue: 1e3,
    decimalPlaces: 0
  }
};
function scaleTime(time, startingScale = "us" /* Microseconds */, decimalPlaces) {
  if (!time || time === 0) {
    return {
      scale: timeScaleMap["ms" /* Milliseconds */].unit,
      value: 0
    };
  }
  let iScale = timeScaleMap[startingScale];
  let timeValue = time;
  let sign = 1;
  if (time < 0) {
    sign = -1;
    timeValue = Math.abs(time);
  }
  while (iScale.scaleUpValue !== null && timeValue >= iScale.scaleUpValue && iScale.scaleUp) {
    timeValue /= iScale.scaleUpValue;
    iScale = timeScaleMap[iScale.scaleUp];
  }
  timeValue *= sign;
  return {
    scale: iScale.unit,
    value: timeValue.toFixed(typeof decimalPlaces !== "undefined" ? decimalPlaces : iScale.decimalPlaces)
  };
}

// src/utilities/formatDuration.ts
var formatDurationMicros = (tickValue, decimalPlaces) => {
  const { value, scale } = scaleTime(tickValue, "us" /* Microseconds */, decimalPlaces || void 0);
  return parseFloat(value.toString()).toString() + scale;
};

// esm-externals:temporal-polyfill
var temporal_polyfill_exports = {};
__export(temporal_polyfill_exports, {
  default: () => temporal_polyfill_default
});
var defaultImport8 = __toESM(require("temporal-polyfill"));
__reExport(temporal_polyfill_exports, require("temporal-polyfill"));
var temporal_polyfill_default = "default" in defaultImport8 ? defaultImport8.default : defaultImport8;

// esm-externals:string-format-obj
var string_format_obj_exports = {};
__export(string_format_obj_exports, {
  default: () => string_format_obj_default
});
var defaultImport9 = __toESM(require("string-format-obj"));
__reExport(string_format_obj_exports, require("string-format-obj"));
var string_format_obj_default = "default" in defaultImport9 ? defaultImport9.default : defaultImport9;

// src/utilities/formatTimestamp.ts
var EPOCH_SECONDS_MAX_VALUE = Date.now() / 100;

// src/utilities/shortenNumber.ts
var generateShortenNumberComponents = (num, decimalPlaces) => {
  let str;
  let suffix = "";
  let value;
  if (num === 0 || !num) {
    value = 0;
    return { value, str: "0", suffix };
  }
  if (typeof decimalPlaces === "undefined") {
    decimalPlaces = num < 10 ? 2 : 1;
  }
  num = +num.toFixed(decimalPlaces);
  const factor = __pow(10, decimalPlaces);
  if (num === 0) {
    if (decimalPlaces === 0) {
      str = "<1";
    } else {
      str = `<0.${"0".repeat(decimalPlaces - 1)}1`;
    }
  } else if (num < 1e3) {
    value = num;
    str = value;
  } else if (num < 1e6) {
    value = Math.floor(num / (1e3 / factor)) / factor;
    str = value;
    suffix = "k";
  } else if (num < 1e9) {
    value = Math.floor(num / (1e6 / factor)) / factor;
    str = value;
    suffix = "m";
  } else if (num < 1e12) {
    value = Math.floor(num / (1e9 / factor)) / factor;
    str = value;
    suffix = "b";
  } else if (num < 1e15) {
    value = Math.floor(num / (1e12 / factor)) / factor;
    str = value;
    suffix = "t";
  }
  return { value, str: String(str), suffix };
};
function shortenNumber(num, decimalPlaces) {
  const { str, suffix } = generateShortenNumberComponents(num, decimalPlaces);
  return str + suffix;
}

// src/utilities/shortenByte.ts
function shortenByte(num, decimalPlaces = 1) {
  let str;
  let suffix = "";
  if (!num) {
    return "0B";
  }
  decimalPlaces = decimalPlaces || 0;
  num = +num.toFixed(decimalPlaces);
  const factor = __pow(10, decimalPlaces);
  if (num < 1e3) {
    str = num;
    suffix = "B";
  } else if (num < 1e6) {
    str = Math.floor(num / (1e3 / factor)) / factor;
    suffix = "KB";
  } else if (num < 1e9) {
    str = Math.floor(num / (1e6 / factor)) / factor;
    suffix = "MB";
  } else if (num < 1e12) {
    str = Math.floor(num / (1e9 / factor)) / factor;
    suffix = "GB";
  } else if (num < 1e15) {
    str = Math.floor(num / (1e12 / factor)) / factor;
    suffix = "TB";
  } else if (num < 1e18) {
    str = Math.floor(num / (1e15 / factor)) / factor;
    suffix = "PB";
  }
  return str + suffix;
}

// esm-externals:styled-components
var styled_components_exports = {};
__export(styled_components_exports, {
  default: () => styled_components_default
});
var defaultImport10 = __toESM(require("styled-components"));
__reExport(styled_components_exports, require("styled-components"));
var styled_components_default = "default" in defaultImport10 ? defaultImport10.default : defaultImport10;

// src/Heatmap.styled.tsx
var StyledHeatMap = styled_components_default.div`
    ${({ gap, theme }) => `
        gap: ${gap}px;
        --tooltip-line-stroke: ${theme.tooltip.lineStroke};
    `}
    align-items: center;
    display: flex;

    /* Overwrite uplot style */
    .uplot {
        position: relative;
    }

    .u-select {
        background: rgba(0, 0, 0, 0.3);
    }

    .u-hz .u-cursor-x {
        border-right: 1px solid var(--tooltip-line-stroke);
    }
`;

// src/theme.tsx
var lightVizTheme = {
  name: "light",
  color: "#2C2C2C",
  font: "10px Arial",
  labelFont: "12px Arial",
  axis: {
    axisStroke: "#E6E6E6",
    gridStroke: "#DDDDDD",
    xLabelStroke: "#6B6B6B",
    yLabelStroke: "#4D4D4D"
  },
  tooltip: {
    lineStroke: "rgba(44, 44, 44, 0.85)",
    inactiveLineStroke: "#999",
    backgroundColor: "rgba(44, 44, 44, 0.85)",
    color: "white",
    secondaryColor: "#999"
  },
  pin: {
    iconStroke: "white",
    lineStroke: "#9e9e9e",
    dotFill: "#9e9e9e"
  },
  heatmap: {
    axisStroke: "#2c2c2c",
    axisFontSize: 12,
    colorScheme: [
      "#ffffff",
      "#ccd6d7",
      "#aec8cd",
      "#8fb8c7",
      "#6ea8c1",
      "#4b96bd",
      "#2181bb",
      "#0067ba",
      "#0047bd",
      "#0502ca"
    ]
  },
  annotationIcon: {
    customEventIconColor: "#818285",
    alertIconColor: {
      critical: "#E00000",
      major: "#C97705",
      minor: "#155A4E",
      warning: "#006BE5",
      info: "#7B4DF5"
    }
  }
};
var darkVizTheme = {
  name: "dark",
  color: "#FAFAFA",
  font: "10px Arial",
  labelFont: "12px Arial",
  axis: {
    axisStroke: "#43454B",
    gridStroke: "#43454B",
    xLabelStroke: "#909090",
    yLabelStroke: "#B5B5B5"
  },
  tooltip: {
    lineStroke: "white",
    inactiveLineStroke: "#666",
    backgroundColor: "rgba(64, 64, 64, 0.85)",
    color: "white",
    secondaryColor: "#999"
  },
  pin: {
    iconStroke: "white",
    lineStroke: "white",
    dotFill: "#bdbdbd"
  },
  heatmap: {
    axisStroke: "#fafafa",
    axisFontSize: 12,
    colorScheme: [
      "#000000",
      "#15355a",
      "#315272",
      "#496d89",
      "#60869e",
      "#759db3",
      "#89b4c7",
      "#9ccad9",
      "#afdfec",
      "#c2f5ff"
    ]
  },
  annotationIcon: {
    customEventIconColor: "#818285",
    alertIconColor: {
      critical: "#FF4242",
      major: "#F49106",
      minor: "#2CBDA3",
      warning: "#61CAFA",
      info: "#AB74F1"
    }
  }
};
function getVizThemeForKey(key) {
  switch (key) {
    case "dark": {
      return darkVizTheme;
    }
    case "light":
    default: {
      return lightVizTheme;
    }
  }
}

// esm-externals:lodash/some
var some_exports = {};
__export(some_exports, {
  default: () => some_default
});
var defaultImport11 = __toESM(require("lodash/some"));
__reExport(some_exports, require("lodash/some"));
var some_default = "default" in defaultImport11 ? defaultImport11.default : defaultImport11;

// src/renderers/uplot-utils.ts
var { bars } = uplot_default.paths;
var bars90PercentGap100MaxWidthPaths = bars ? bars({ size: [0.9, 100] }) : void 0;

// src/utilities/utils.ts
var DAY = 24 * 60 * 60;
var formatKibBytes = (bytes, decimals = 2) => {
  if (!+bytes) {
    return "0B";
  }
  const k = 1024;
  const dm = decimals < 0 ? 0 : decimals;
  const sizes = ["B", "KiB", "MiB", "GiB", "TiB", "PiB", "EiB", "ZiB", "YiB"];
  const i = Math.floor(Math.log(bytes) / Math.log(k));
  return `${parseFloat((bytes / __pow(k, i)).toFixed(dm))}${sizes[i]}`;
};
var namedFormatters = {
  durationMicros: (value) => formatDurationMicros(value),
  rate: (value, xAxisResolution) => `${shortenNumber(value / (xAxisResolution || 1))} /s`,
  count: (value) => `${shortenNumber(value)}`,
  bytes: (value) => `${shortenByte(value)}`,
  percentage: (value) => `${shortenNumber(value)}%`,
  kibBytes: (value) => `${formatKibBytes(value, 0)}`
};
var scaleNamedFormatters = __spreadProps(__spreadValues({}, namedFormatters), {
  percentage: (value) => `${shortenNumber(value, value < 10 ? 3 : 2)}%`
});
var buildColorFunction = (maxDensity, theme) => (value) => {
  const colors = theme.heatmap.colorScheme;
  const bucketIndex = Math.round(value / maxDensity * (colors.length - 1));
  return colors[bucketIndex];
};
var timeTickFormatter = (tickValue, startingScale, decimalPlaces) => {
  const { value, scale } = scaleTime(tickValue, startingScale, decimalPlaces);
  return value + scale;
};
var filterSplit = (index, split, splitsPos, u) => {
  const mod = index % 9;
  if (mod === 0) {
    return split;
  }
  if (mod === 1) {
    const textMetrics = u.ctx.measureText(String(split));
    const textHeight = textMetrics.actualBoundingBoxAscent + textMetrics.actualBoundingBoxDescent;
    return textHeight + 1 <= Math.abs(splitsPos[index] - splitsPos[index - 1]) ? split : null;
  }
  return null;
};
var roundToPoT = (value, roundFunc) => __pow(10, roundFunc(Math.log10(value)));
var pixelStrToNum = (str) => Number(str.replace("px", ""));

// src/Heatmap.tsx
var DEFAULT_LEGEND_HEIGHT = 300;
var DEFAULT_LEGEND_WIDTH = 25;
var LEGEND_WIDTH = 100;
var CHART_GAP = 20;
var HeatmapLegend = ({ yMaxValue, width, height, yLegendLabel, data, theme }) => {
  const buildPathsForLegend = (legendWidth) => (u, seriesIdx) => {
    uplot_default.orient(
      u,
      seriesIdx,
      (series, dataX, dataY, scaleX, scaleY, valToPosX, valToPosY, xOff, yOff, xDim, yDim) => {
        const resolutionScale = window.devicePixelRatio || 1;
        const legendValuePosition = (legendWidth + 5) * resolutionScale;
        const scaledLegendWidth = legendWidth * resolutionScale;
        const textSize = theme.heatmap.axisFontSize * resolutionScale;
        u.ctx.font = `${textSize}px Arial`;
        const colors = theme.heatmap.colorScheme;
        const numColors = colors.length;
        const bucketPixelHeight = Math.round(yDim / numColors);
        let bucketColorIdx = 0;
        u.ctx.fillStyle = theme.heatmap.axisStroke;
        u.ctx.fillText("0", legendValuePosition, yOff + yDim);
        u.ctx.fillText(
          (0, format_exports.abbreviateNumber)(yMaxValue >= 10 ? Math.round(yMaxValue) : yMaxValue),
          legendValuePosition,
          yOff
        );
        for (let i = 0; i < yDim; i += 1) {
          u.ctx.fillStyle = colors[bucketColorIdx];
          u.ctx.fillRect(0, yOff + yDim - i, scaledLegendWidth, 1);
          if (i !== 0 && i % bucketPixelHeight === 0) {
            bucketColorIdx += 1;
            const bucketValue = yMaxValue / numColors * bucketColorIdx;
            u.ctx.fillStyle = theme.heatmap.axisStroke;
            u.ctx.fillText(
              // only use decimals when values < 10 so that axis label does not get cut off
              (0, format_exports.abbreviateNumber)(bucketValue >= 10 ? Math.round(bucketValue) : bucketValue),
              legendValuePosition,
              yOff + yDim - i
            );
          }
        }
      }
    );
    return null;
  };
  const normalizedHeight = height <= 0 ? DEFAULT_LEGEND_HEIGHT : height;
  const normalizedWidth = width <= 0 ? DEFAULT_LEGEND_WIDTH : width;
  const options = {
    width: LEGEND_WIDTH,
    height: normalizedHeight,
    mode: 2,
    cursor: { show: false },
    legend: { show: false },
    axes: [
      {
        // invisible axis here to match canvas positioning of heatmap path
        size: 75,
        grid: { show: false },
        ticks: { show: false }
      },
      {
        show: true,
        size: 45,
        label: yLegendLabel,
        labelFont: "bold 12px Arial",
        side: 1,
        grid: { show: false },
        ticks: { show: false },
        values: [null],
        stroke: theme.heatmap.axisStroke
      }
    ],
    scales: {
      x: { min: 0, max: normalizedWidth, time: false },
      y: {
        min: 0,
        max: yMaxValue
      }
    },
    series: [{}, { paths: buildPathsForLegend(DEFAULT_LEGEND_WIDTH) }]
  };
  return /* @__PURE__ */ react_default.createElement(uplot_react_default, { options, data: [Array(data.length), data] });
};
function paths(timeInterval, sendLegendRangeMax, theme, sendAnalytics) {
  return (u, seriesIdx) => {
    uplot_default.orient(
      u,
      seriesIdx,
      (series, dataX, dataY, scaleX, scaleY, valToPosX, valToPosY, xOff, yOff, xDim, yDim) => {
        try {
          const [startTimes, yStarts, yEnds, counts] = u.data[seriesIdx];
          const dlen = startTimes.length;
          const startTimePixelMap = {};
          let globalMaxCountPerSecond = 0;
          for (let i = 0; i < dlen; i += 1) {
            const startTime = startTimes[i];
            const yStart = yStarts[i];
            const yEnd = yEnds[i];
            const count = counts[i];
            const yDimInteger = Math.round(yDim);
            if (!startTimePixelMap[startTime]) {
              startTimePixelMap[startTime] = new Array(yDimInteger).fill(0);
            }
            const yTopPixelPos = Math.floor(valToPosY(yEnd, scaleY, yDim, 0));
            const yBottomPixelPos = Math.ceil(valToPosY(yStart, scaleY, yDim, 0));
            const heightPixels = Math.max(1, yBottomPixelPos - yTopPixelPos);
            const countPerSecond = count / heightPixels / timeInterval;
            for (let j = yTopPixelPos; j <= yTopPixelPos + heightPixels; j += 1) {
              startTimePixelMap[startTime][j] += countPerSecond;
              const val = startTimePixelMap[startTime][j];
              if (val) {
                globalMaxCountPerSecond = Math.max(globalMaxCountPerSecond, val);
              }
            }
          }
          const colorFn = buildColorFunction(globalMaxCountPerSecond, theme);
          u.ctx.fillStyle = theme.heatmap.colorScheme[0];
          u.ctx.fillRect(xOff, yOff, xDim, yDim);
          const uniqueStartTimes = Object.keys(startTimePixelMap);
          for (let i = 0; i < uniqueStartTimes.length; i += 1) {
            const rectangleStartTime = uniqueStartTimes[i];
            const rectanglePixelCountPerSecond = startTimePixelMap[rectangleStartTime];
            const numberStartTime = Number(rectangleStartTime);
            for (let j = 0; j < rectanglePixelCountPerSecond.length; j += 1) {
              const x = valToPosX(numberStartTime, scaleX, xDim, xOff);
              const width = valToPosX(numberStartTime + timeInterval, scaleX, xDim, xOff) - valToPosX(numberStartTime, scaleX, xDim, xOff);
              const canvasY = j + yOff;
              u.ctx.fillStyle = colorFn(rectanglePixelCountPerSecond[j]);
              u.ctx.fillRect(x, canvasY, width, 1);
            }
          }
          sendAnalytics == null ? void 0 : sendAnalytics("Data_View/Heatmap_Analyzer", "View_Load", null, "RenderSuccess");
          sendLegendRangeMax(globalMaxCountPerSecond);
        } catch (e) {
          sendAnalytics == null ? void 0 : sendAnalytics("Data_View/Heatmap_Analyzer", "View_Load", yDim, "RenderError");
        }
      }
    );
    return null;
  };
}
var InternalHeatmap = ({
  width,
  height,
  timeZone,
  userAnalytics,
  data,
  timeRangeEpochSeconds = { start: Infinity, end: 0 },
  yLegendLabel,
  yLabel,
  overlay
}) => {
  const { colorScheme } = (0, themes_exports.useSplunkTheme)();
  const theme = getVizThemeForKey(colorScheme);
  const [legendRangeMax, setLegendRange] = (0, react_exports.useState)();
  const [overlayParams, setOverlayParams] = (0, react_exports.useState)(null);
  let xMin;
  let xMax;
  let yMinRounded;
  let yMaxRounded;
  let xIntervalSeconds;
  const xs = data[0];
  const secondXValue = xs.find((x) => x !== xs[0]);
  if (secondXValue) {
    xMin = (timeRangeEpochSeconds == null ? void 0 : timeRangeEpochSeconds.start) || xs[0];
    xIntervalSeconds = secondXValue - xs[0];
    xMax = (timeRangeEpochSeconds == null ? void 0 : timeRangeEpochSeconds.end) || (0, lodash_exports.last)(xs) + xIntervalSeconds;
    const allYValues = [...data[1], ...data[2]];
    const yMin = (0, lodash_exports.min)(allYValues);
    yMinRounded = roundToPoT(yMin, Math.floor);
    const yMax = (0, lodash_exports.max)(allYValues);
    const yMaxNearestPoT = roundToPoT(yMax, Math.floor);
    yMaxRounded = Math.ceil(yMax / yMaxNearestPoT) * yMaxNearestPoT;
  } else if (timeRangeEpochSeconds) {
    xMin = timeRangeEpochSeconds.start;
    xMax = timeRangeEpochSeconds.end;
    yMinRounded = 1e6;
    yMaxRounded = 1e8;
    xIntervalSeconds = 1;
    data = [[], [], [], []];
  } else {
    throw new Error("Heatmap requires two or more points on the x axis, or a timeRangeEpochSeconds prop");
  }
  const heatmapWidth = width - (LEGEND_WIDTH + CHART_GAP);
  const options = {
    hooks: {
      setSize: [
        (u) => {
          if (def(u.over)) {
            const uOverStyles = u.over.style;
            const tempRenderProp = {
              uOverRect: {
                left: pixelStrToNum(uOverStyles.left),
                top: pixelStrToNum(uOverStyles.top),
                height: pixelStrToNum(uOverStyles.height),
                width: pixelStrToNum(uOverStyles.width)
              },
              posToVal: u.posToVal,
              valToPos: u.valToPos
            };
            if (!(0, lodash_exports.isEqual)(tempRenderProp.uOverRect, overlayParams == null ? void 0 : overlayParams.uOverRect)) {
              setOverlayParams(tempRenderProp);
            }
          }
        }
      ]
    },
    width: heatmapWidth,
    height,
    mode: 2,
    tzDate: (ts) => uplot_default.tzDate(new Date(ts * 1e3), timeZone),
    scales: {
      x: {
        time: true,
        min: xMin,
        max: xMax
      },
      y: {
        min: yMinRounded,
        max: yMaxRounded,
        distr: 3,
        auto: false
      }
    },
    series: [
      {},
      {
        paths: paths(xIntervalSeconds, setLegendRange, theme, userAnalytics == null ? void 0 : userAnalytics.event),
        stroke: theme.heatmap.axisStroke
      }
    ],
    cursor: {
      y: false,
      bind: {
        dblclick: () => null
      },
      drag: {
        setScale: false
      }
    },
    select: {
      show: false
    },
    axes: [
      {
        size: 75,
        grid: { show: false },
        ticks: { show: true, stroke: theme.heatmap.axisStroke, width: 1 },
        stroke: theme.heatmap.axisStroke
      },
      {
        show: true,
        size: 75,
        label: yLabel,
        labelGap: 5,
        labelSize: 30,
        filter: (u, splits) => {
          const splitsPos = splits.map((split) => u.valToPos(split, "y"));
          return splits.map((split, index) => filterSplit(index, split, splitsPos, u));
        },
        values: (u, splits) => splits.map((split) => split ? timeTickFormatter(split, "ns" /* Nanoseconds */) : ""),
        side: 3,
        grid: { show: false },
        ticks: { show: true, stroke: theme.heatmap.axisStroke, width: 1 },
        stroke: theme.heatmap.axisStroke
      }
    ],
    legend: {
      show: false
    }
  };
  return /* @__PURE__ */ react_default.createElement(react_default.Fragment, null, overlayParams ? overlay == null ? void 0 : overlay(overlayParams) : null, /* @__PURE__ */ react_default.createElement(StyledHeatMap, { "data-testid": "heatmap-root", gap: CHART_GAP, theme }, /* @__PURE__ */ react_default.createElement(
    uplot_react_default,
    {
      options,
      data: [Array(data.length), data]
    }
  ), legendRangeMax && /* @__PURE__ */ react_default.createElement("div", null, /* @__PURE__ */ react_default.createElement(
    HeatmapLegend,
    {
      yMaxValue: legendRangeMax,
      data,
      width: LEGEND_WIDTH,
      height,
      yLegendLabel,
      theme
    }
  ))));
};
var Heatmap = (_a) => {
  var _b = _a, { theme } = _b, props = __objRest(_b, ["theme"]);
  if (!theme) {
    return /* @__PURE__ */ react_default.createElement(InternalHeatmap, __spreadValues({}, props));
  }
  return /* @__PURE__ */ react_default.createElement(themes_exports.SplunkThemeProvider, { colorScheme: theme }, /* @__PURE__ */ react_default.createElement(InternalHeatmap, __spreadValues({}, props)));
};
//# sourceMappingURL=Heatmap.js.map
