import {
  axisstyle,
  font
} from "./chunk-SA7APTJR.js";
import "./chunk-HJ6L54YS.js";
import "./chunk-LSEFWW72.js";
import "./chunk-SKREEF3H.js";
import "./chunk-HYOEWQ5P.js";
import "./chunk-HBW42TDT.js";
import "./chunk-G6O3URDN.js";
import "./chunk-FN5XPUPH.js";
import "./chunk-IIT367QZ.js";
import "./chunk-RZGEKL77.js";
import "./chunk-UI7OCM2A.js";
import "./chunk-YZK37YCC.js";
import "./chunk-7EMWHCVW.js";
import "./chunk-7IYJZZQI.js";
import "./chunk-M3J4MINX.js";
import "./chunk-PF4DSFDR.js";
import "./chunk-QH6W3NVF.js";
import "./chunk-NOEAT6CX.js";
import "./chunk-4UWS5Y3N.js";
import "./chunk-DD4R5P6W.js";
import "./chunk-JNITUVXP.js";
import {
  category10_default
} from "./chunk-KSGA62R2.js";
import {
  axisTop
} from "./chunk-LOZEKOES.js";
import "./chunk-TOU7EVFQ.js";
import {
  linear,
  ordinal
} from "./chunk-OAWQ6LOO.js";
import "./chunk-TLT4YIG3.js";
import "./chunk-KYBIQBXE.js";
import "./chunk-I6Y4O3RR.js";
import "./chunk-OMR2DT66.js";
import "./chunk-DQC5FFGV.js";
import "./chunk-HFNDKYVF.js";

// src/old/plot.boxplot.js
function plot_boxplot_default(arg) {
  if (!arg.holder) return ".holder missing for boxplot";
  if (!arg.list) return ".list[] missing";
  if (!Array.isArray(arg.list)) return ".list should be array";
  for (const group of arg.list) {
    if (!group.label) return ".label missing for a group";
    if (group.samples) {
      for (const s of group.samples) {
        if (!Number.isFinite(s.value)) return ".value missing from a sample";
      }
    } else {
      if (!Number.isFinite(group.minvalue)) return ".minvalue missing for a group";
      if (!Number.isFinite(group.maxvalue)) return ".maxvalue missing for a group";
      if (!group.percentile) return ".percentile{} missing from a group";
      if (!Number.isFinite(group.percentile.p05)) return ".percentile.p05 missing for a group";
      if (!Number.isFinite(group.percentile.p25)) return ".percentile.p25 missing for a group";
      if (!Number.isFinite(group.percentile.p50)) return ".percentile.p50 missing for a group";
      if (!Number.isFinite(group.percentile.p75)) return ".percentile.p75 missing for a group";
      if (!Number.isFinite(group.percentile.p95)) return ".percentile.p95 missing for a group";
    }
  }
  const label2color = ordinal(category10_default);
  const svg = arg.holder.append("svg");
  let axisheight = 40, width = 300, ypad = 10, xpad = 10, boxheight = 30, axisfontsize = 12, fontsize = 15;
  let maxlabelw = 0;
  let minv = null;
  let maxv = null;
  for (const g2 of arg.list) {
    const samplecount = g2.samplecount ? g2.samplecount : g2.samples ? g2.samples.length : null;
    svg.append("text").text(g2.label + (samplecount ? " (n=" + samplecount + ")" : "")).attr("font-family", font).attr("font-size", fontsize).each(function() {
      maxlabelw = Math.max(maxlabelw, this.getBBox().width);
    }).remove();
    if (g2.samples) {
      for (const s of g2.samples) {
        if (s.value == void 0) continue;
        if (minv == null) {
          minv = s.value;
          maxv = s.value;
        } else {
          minv = Math.min(minv, s.value);
          maxv = Math.max(maxv, s.value);
        }
      }
    } else {
      if (minv == null) {
        minv = g2.minvalue;
        maxv = g2.maxvalue;
      } else {
        minv = Math.min(minv, g2.minvalue);
        maxv = Math.max(maxv, g2.maxvalue);
      }
    }
  }
  svg.attr("width", maxlabelw + xpad + width + xpad).attr("height", axisheight + (ypad + boxheight) * arg.list.length + 10);
  const g = svg.append("g").attr("transform", "translate(" + (maxlabelw + xpad) + "," + axisheight + ")");
  const xscale = linear().domain([minv, maxv]).range([0, width]);
  const axisg = g.append("g");
  axisstyle({
    axis: axisg.call(
      axisTop().scale(xscale).ticks(5)
    ),
    showline: true,
    fontsize: axisfontsize,
    color: "black"
  });
  if (arg.axislabel) {
    g.append("text").text(arg.axislabel).attr("x", width / 2).attr("y", -axisfontsize - 13).attr("font-family", font).attr("font-size", fontsize).attr("text-anchor", "middle");
  }
  let y = 0;
  for (const grp of arg.list) {
    y += ypad;
    const sg = g.append("g").attr("transform", "translate(0," + y + ")");
    y += boxheight;
    const samplecount = grp.samplecount ? grp.samplecount : grp.samples ? grp.samples.length : null;
    sg.append("text").text(grp.label + (samplecount ? " (n=" + samplecount + ")" : "")).attr("x", -xpad).attr("y", boxheight / 2).attr("text-anchor", "end").attr("dominant-baseline", "central").attr("font-family", font).attr("font-size", fontsize).attr("fill", "black");
    let p05, p25, p50, p75, p95;
    if (grp.samples) {
      const vlst = grp.samples.map((i) => i.value);
      vlst.sort((a, b) => a - b);
      p05 = vlst[Math.floor(vlst.length * 0.05)];
      p25 = vlst[Math.floor(vlst.length * 0.25)];
      p50 = vlst[Math.floor(vlst.length * 0.5)];
      p75 = vlst[Math.floor(vlst.length * 0.75)];
      p95 = vlst[Math.floor(vlst.length * 0.95)];
    } else {
      p05 = grp.percentile.p05;
      p25 = grp.percentile.p25;
      p50 = grp.percentile.p50;
      p75 = grp.percentile.p75;
      p95 = grp.percentile.p95;
    }
    const x05 = xscale(p05);
    const x25 = xscale(p25);
    const x50 = xscale(p50);
    const x75 = xscale(p75);
    const x95 = xscale(p95);
    const color = grp.color || label2color(grp.label);
    sg.append("line").attr("y1", boxheight / 2).attr("y2", boxheight / 2).attr("x1", x05).attr("x2", x95).attr("stroke", color).attr("shape-rendering", "crispEdges");
    sg.append("line").attr("y2", boxheight).attr("x1", x05).attr("x2", x05).attr("stroke", color).attr("shape-rendering", "crispEdges");
    sg.append("line").attr("y2", boxheight).attr("x1", x95).attr("x2", x95).attr("stroke", color).attr("shape-rendering", "crispEdges");
    sg.append("rect").attr("x", x25).attr("width", x75 - x25).attr("height", boxheight).attr("stroke", color).attr("fill", "white").attr("shape-rendering", "crispEdges");
    sg.append("line").attr("y2", boxheight).attr("x1", x50).attr("x2", x50).attr("stroke", color).attr("shape-rendering", "crispEdges");
  }
  return null;
}
export {
  plot_boxplot_default as default
};
//# sourceMappingURL=plot.boxplot-OHEJDPTW.js.map
