import {
  axisstyle,
  font,
  make_table_2col
} from "./chunk-SA7APTJR.js";
import "./chunk-HJ6L54YS.js";
import "./chunk-LSEFWW72.js";
import "./chunk-SKREEF3H.js";
import {
  Menu
} from "./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 "./chunk-KSGA62R2.js";
import {
  axisBottom,
  axisLeft,
  axisRight
} from "./chunk-LOZEKOES.js";
import "./chunk-TOU7EVFQ.js";
import {
  linear
} 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.2dvaf.js
var gray = "#999";
var centercolor = "#d95f02";
var xcolor = "#7570b3";
var ycolor = "#1b9e77";
var rectfill = "#f3f3f3";
var dotstrokeopacity = 0.9;
function plot_2dvaf(data, cfg, holder) {
  if (cfg.individualcategories) {
    for (const d of data) {
      const value = d[cfg.individualcategories.categorykey];
      if (value && cfg.individualcategories.categories[value]) {
        d.color = cfg.individualcategories.categories[value].color;
      }
    }
  }
  const ik = cfg.individualkey;
  {
    const div = holder.append("div").style("margin", "5px 10px 10px 30px");
    const s = /* @__PURE__ */ new Set();
    for (const d of data) {
      s.add(d[ik]);
    }
    div.append("div").text(s.size + " " + ik + (s.size > 1 ? "s" : ""));
    if (cfg.individualcategories) {
      for (const k in cfg.individualcategories.categories) {
        const s2 = /* @__PURE__ */ new Set();
        for (const d of data) {
          const ikname = d[ik];
          if (!ikname) continue;
          if (d[cfg.individualcategories.categorykey] == k) {
            s2.add(ikname);
          }
        }
        const row = div.append("div").style("margin", "5px");
        row.append("div").style("display", "inline-block").attr("class", "sja_mcdot").style("background-color", cfg.individualcategories.categories[k].color).style("padding", "1px 3px").text(s2.size).style("margin-right", "5px");
        row.append("span").text(cfg.individualcategories.categories[k].label || k).style("color", cfg.individualcategories.categories[k].color);
      }
    }
  }
  const tip = new Menu({ border: "none", padding: "0px" });
  const mouseover = (s, x, y) => {
    if (circle_yleft) {
      circle_yleft.filter((d) => d[ik] == s[ik]).attr("fill-opacity", 0.5);
    }
    if (circle_yright) {
      circle_yright.filter((d) => d[ik] == s[ik]).attr("fill-opacity", 0.5);
    }
    circle_xdp.filter((d) => d[ik] == s[ik]).attr("fill-opacity", 0.5);
    circle_center.filter((d) => d[ik] == s[ik]).attr("fill-opacity", 0.5);
    tip.show(x, y);
    tip.clear();
    const lst = [
      { k: ik, v: s[ik] },
      {
        k: cfg.xsampletype,
        v: s.sampletypes[cfg.xsampletype].vaf.toFixed(2) + ", " + s.sampletypes[cfg.xsampletype].total
      }
    ];
    if (cfg.individualcategories) {
      const v = s[cfg.individualcategories.categorykey];
      if (v && cfg.individualcategories.categories[v]) {
        lst.push({
          k: cfg.individualcategories.categorylabel || cfg.individualcategories.categorykey,
          v: cfg.individualcategories.categories[v].label || v
        });
      }
    }
    if (s.sampletypes[cfg.yleftsampletype]) {
      lst.push({
        k: cfg.yleftsampletype,
        v: s.sampletypes[cfg.yleftsampletype].vaf.toFixed(2) + ", " + s.sampletypes[cfg.yleftsampletype].total
      });
    }
    if (s.sampletypes[cfg.yrightsampletype]) {
      lst.push({
        k: cfg.yrightsampletype,
        v: s.sampletypes[cfg.yrightsampletype].vaf.toFixed(2) + ", " + s.sampletypes[cfg.yrightsampletype].total
      });
    }
    make_table_2col(tip.d, lst);
  };
  const mouseout = (s) => {
    tip.hide();
    if (circle_yleft) {
      circle_yleft.filter((d) => d[ik] == s[ik]).attr("fill-opacity", 0);
    }
    if (circle_yright) {
      circle_yright.filter((d) => d[ik] == s[ik]).attr("fill-opacity", 0);
    }
    circle_xdp.filter((d) => d[ik] == s[ik]).attr("fill-opacity", 0);
    circle_center.filter((d) => d[ik] == s[ik]).attr("fill-opacity", 0);
  };
  let xwidth = 300;
  let yheight = 300;
  let marksize;
  let xvafheight = 80;
  let yvafwidth = 80;
  let xdpheight = 100;
  let ydpheight = 100;
  let sp = 10;
  let sp2 = 10;
  let toppad = 10;
  let rightpad = 10;
  let radius = 8;
  let fontsize = 12;
  let ticksize = 6;
  let maxdp_x = 0;
  let maxdp_yleft = 0;
  let maxdp_yright = 0;
  for (const d of data) {
    maxdp_x = Math.max(maxdp_x, d.sampletypes[cfg.xsampletype].total);
    if (d.sampletypes[cfg.yleftsampletype]) {
      maxdp_yleft = Math.max(maxdp_yleft, d.sampletypes[cfg.yleftsampletype].total);
    }
    if (d.sampletypes[cfg.yrightsampletype]) {
      maxdp_yright = Math.max(maxdp_yleft, d.sampletypes[cfg.yrightsampletype].total);
    }
  }
  let maxvaf = 1;
  let minvaf = 0;
  const scalevaf_x = linear().domain([minvaf, maxvaf]);
  const scalevaf_y = linear().domain([minvaf, maxvaf]);
  const scaledp_x = linear().domain([0, maxdp_x]);
  let scaledp_yleft;
  let scaledp_yright;
  if (maxdp_yleft) {
    scaledp_yleft = linear().domain([0, maxdp_yleft]);
  }
  if (maxdp_yright) {
    scaledp_yright = linear().domain([0, maxdp_yright]);
  }
  const svg = holder.append("svg").style("margin", "10px");
  let axevaf_yleft, axisvaf_yleft, yleftlabg, yleftlab;
  if (maxdp_yleft) {
    axevaf_yleft = svg.append("g");
    axisvaf_yleft = axevaf_yleft.append("g");
    yleftlabg = axevaf_yleft.append("g");
    yleftlab = yleftlabg.append("text").attr("transform", "rotate(-90)").text(cfg.yleftsampletype + " VAF").attr("font-family", font).attr("fill", ycolor).attr("text-anchor", "middle").attr("dominant-baseline", "central");
  }
  let axevaf_yright, axisvaf_yright, yrightlabg, yrightlab;
  if (maxdp_yright) {
    axevaf_yright = svg.append("g");
    axisvaf_yright = axevaf_yright.append("g");
    yrightlabg = axevaf_yright.append("g");
    yrightlab = yrightlabg.append("text").attr("transform", "rotate(-90)").text(cfg.yrightsampletype + " VAF").attr("font-family", font).attr("fill", ycolor).attr("text-anchor", "middle").attr("dominant-baseline", "central");
  }
  const axe_xvaf = svg.append("g");
  const axis_xvaf = axe_xvaf.append("g");
  const xlab = axe_xvaf.append("text").text(cfg.xsampletype + " VAF").attr("font-family", font).attr("fill", xcolor).attr("text-anchor", "middle");
  let axedp_yleft, rectdp_yleft, midlinedp_yleft, axisdp_yleft, dotg_yleft, circle_yleft;
  if (maxdp_yleft) {
    axedp_yleft = svg.append("g");
    rectdp_yleft = axedp_yleft.append("rect").attr("fill", rectfill);
    midlinedp_yleft = axedp_yleft.append("line").attr("stroke", "white").attr("stroke-width", 2);
    axisdp_yleft = axedp_yleft.append("g");
    dotg_yleft = axedp_yleft.append("g").selectAll().data(data.filter((d) => d.sampletypes[cfg.yleftsampletype])).enter().append("g");
    circle_yleft = dotg_yleft.append("circle").attr("fill", (d) => d.color || ycolor).attr("fill-opacity", 0).attr("stroke", (d) => d.color || ycolor).attr("stroke-opacity", dotstrokeopacity).on("mouseover", (event, d) => mouseover(d, event.clientX, event.clientY)).on("mouseout", mouseout);
  }
  let axedp_yright, rectdp_yright, midlinedp_yright, axisdp_yright, dotg_yright, circle_yright;
  if (maxdp_yright) {
    axedp_yright = svg.append("g");
    rectdp_yright = axedp_yright.append("rect").attr("fill", rectfill);
    midlinedp_yright = axedp_yleft.append("line").attr("stroke", "white").attr("stroke-width", 2);
    axisdp_yright = axedp_yright.append("g");
    dotg_yright = axedp_yright.append("g").selectAll().data(data.filter((d) => d.sampletypes[cfg.yrightsampletype])).enter().append("g");
    circle_yright = dotg_yright.append("rect").attr("fill", (d) => d.color || ycolor).attr("fill-opacity", 0).attr("stroke", (d) => d.color || ycolor).attr("stroke-opacity", dotstrokeopacity).on("mouseover", (event, d) => mouseover(d, event.clientX, event.clientY)).on("mouseout", mouseout);
  }
  const axe_xdp = svg.append("g");
  const rect_xdp = axe_xdp.append("rect").attr("fill", rectfill);
  const midlinedp_x = axe_xdp.append("line").attr("stroke", "white").attr("stroke-width", 2);
  const dplab = axe_xdp.append("text").text("Coverage").attr("text-anchor", "end").attr("dominant-baseline", "central").attr("font-family", font).attr("fill", gray);
  const axis_xdp = axe_xdp.append("g");
  const dotg_xdp = axe_xdp.append("g").selectAll().data(data).enter().append("g");
  const circle_xdp = dotg_xdp.append("circle").attr("fill", (d) => d.color || xcolor).attr("fill-opacity", 0).attr("stroke", (d) => d.color || xcolor).attr("stroke-opacity", dotstrokeopacity).on("mouseover", (event, d) => mouseover(d, event.clientX, event.clientY)).on("mouseout", mouseout);
  const plotg_center = svg.append("g");
  const rect_center = plotg_center.append("rect").attr("fill", rectfill);
  const midline_xcenter = plotg_center.append("line").attr("stroke", "white").attr("stroke-width", 2);
  const midline_ycenter = plotg_center.append("line").attr("stroke", "white").attr("stroke-width", 2);
  const dotg_center = plotg_center.append("g").selectAll().data(data).enter().append("g");
  const circle_center = dotg_center.append("circle").attr("fill", (d) => d.color || centercolor).attr("fill-opacity", 0).attr("stroke", (d) => d.color || centercolor).attr("stroke-opacity", dotstrokeopacity).on("mouseover", (event, d) => mouseover(d, event.clientX, event.clientY)).on("mouseout", mouseout);
  const render = () => {
    xvafheight = ticksize + fontsize + 10 + fontsize * 2;
    yvafwidth = ticksize + fontsize * 2 + 10 + fontsize * 2;
    sp = radius * 2;
    sp2 = ticksize + fontsize + radius + 10;
    scalevaf_x.range([0, xwidth]);
    scalevaf_y.range([0, -yheight]);
    scaledp_x.range([0, xdpheight]);
    if (scaledp_yleft) {
      scaledp_yleft.range([0, -ydpheight]);
    }
    if (scaledp_yright) {
      scaledp_yright.range([0, ydpheight]);
    }
    if (axevaf_yleft) {
      axevaf_yleft.attr("transform", "translate(" + yvafwidth + "," + (toppad + yheight) + ")");
      yleftlabg.attr("transform", "translate(-" + (yvafwidth - fontsize) + ",-" + yheight / 2 + ")");
      yleftlab.attr("font-size", fontsize * 2);
    }
    if (axevaf_yright) {
      axevaf_yright.attr(
        "transform",
        "translate(" + ((maxdp_yleft ? yvafwidth + sp + ydpheight : 0) + sp2 + xwidth + sp2 + ydpheight + sp) + "," + (toppad + yheight) + ")"
      );
      yrightlabg.attr("transform", "translate(" + (yvafwidth - fontsize) + ",-" + yheight / 2 + ")");
      yrightlab.attr("font-size", fontsize * 2);
    }
    axe_xvaf.attr(
      "transform",
      "translate(" + (yvafwidth + sp + ydpheight + sp2) + "," + (toppad + yheight + sp2 + xdpheight + sp) + ")"
    );
    xlab.attr("font-size", fontsize * 2).attr("x", xwidth / 2).attr("y", xvafheight);
    if (axedp_yleft) {
      axedp_yleft.attr("transform", "translate(" + (yvafwidth + sp + ydpheight) + "," + (toppad + yheight) + ")");
      axisdp_yleft.attr("transform", "translate(0," + (5 + radius) + ")");
      rectdp_yleft.attr("x", -ydpheight).attr("y", -yheight).attr("width", ydpheight).attr("height", yheight);
      midlinedp_yleft.attr("x1", -ydpheight).attr("y1", -yheight / 2).attr("y2", -yheight / 2);
    }
    if (axedp_yright) {
      axedp_yright.attr(
        "transform",
        "translate(" + ((maxdp_yleft ? yvafwidth + sp + ydpheight : 0) + sp2 + xwidth + sp2) + "," + (toppad + yheight) + ")"
      );
      axisdp_yright.attr("transform", "translate(0," + (5 + radius) + ")");
      rectdp_yright.attr("y", -yheight).attr("width", ydpheight).attr("height", yheight);
      midlinedp_yright.attr("y1", -yheight / 2).attr("y2", -yheight / 2).attr("x2", ydpheight);
    }
    axe_xdp.attr("transform", "translate(" + (yvafwidth + sp + ydpheight + sp2) + "," + (toppad + yheight + sp2) + ")");
    axis_xdp.attr("transform", "translate(-" + (5 + radius) + ",0)");
    rect_xdp.attr("width", xwidth).attr("height", xdpheight);
    midlinedp_x.attr("x1", xwidth / 2).attr("x2", xwidth / 2).attr("y2", xdpheight);
    dplab.attr("x", -40).attr("y", xdpheight / 2).attr("font-size", fontsize * 1.5);
    plotg_center.attr("transform", "translate(" + (yvafwidth + sp + ydpheight + sp2) + "," + (toppad + yheight) + ")");
    rect_center.attr("y", -yheight).attr("width", xwidth).attr("height", yheight);
    midline_xcenter.attr("y1", -yheight / 2).attr("y2", -yheight / 2).attr("x2", xwidth);
    midline_ycenter.attr("x1", xwidth / 2).attr("x2", xwidth / 2).attr("y2", -yheight);
    if (axisvaf_yleft) {
      axisstyle({
        axis: axisvaf_yleft.call(
          axisLeft().scale(scalevaf_y).tickSize(ticksize - 2)
        ),
        showline: true,
        color: gray,
        fontsize
      });
    }
    if (axisvaf_yright) {
      axisstyle({
        axis: axisvaf_yright.call(
          axisRight().scale(scalevaf_y).tickSize(ticksize - 2)
        ),
        showline: true,
        color: gray,
        fontsize
      });
    }
    axisstyle({
      axis: axis_xvaf.call(
        axisBottom().scale(scalevaf_x).tickSize(ticksize - 2)
      ),
      showline: true,
      color: gray,
      fontsize
    });
    axisstyle({
      axis: axis_xdp.call(
        axisLeft().scale(scaledp_x).tickSize(ticksize - 2).tickValues([0, maxdp_x])
      ),
      showline: true,
      color: gray,
      fontsize
    });
    if (axisdp_yleft) {
      axisstyle({
        axis: axisdp_yleft.call(
          axisBottom().scale(scaledp_yleft).tickSize(ticksize - 2).tickValues([0, maxdp_yleft])
        ),
        showline: true,
        color: gray,
        fontsize
      });
    }
    if (axisdp_yright) {
      axisstyle({
        axis: axisdp_yright.call(
          axisBottom().scale(scaledp_yright).tickSize(ticksize - 2).tickValues([0, maxdp_yright])
        ),
        showline: true,
        color: gray,
        fontsize
      });
    }
    if (dotg_yleft) {
      dotg_yleft.attr("transform", (d) => {
        const i = d.sampletypes[cfg.yleftsampletype];
        return "translate(" + scaledp_yleft(i.total) + "," + scalevaf_y(i.vaf) + ")";
      });
    }
    if (dotg_yright) {
      dotg_yright.attr("transform", (d) => {
        const i = d.sampletypes[cfg.yrightsampletype];
        return "translate(" + scaledp_yright(i.total) + "," + scalevaf_y(i.vaf) + ")";
      });
    }
    dotg_xdp.attr("transform", (d) => {
      const i = d.sampletypes[cfg.xsampletype];
      return "translate(" + scalevaf_x(i.vaf) + "," + scaledp_x(i.total) + ")";
    });
    dotg_center.attr("transform", (d) => {
      const x = d.sampletypes[cfg.xsampletype];
      const y = d.sampletypes[cfg.yleftsampletype] || d.sampletypes[cfg.yrightsampletype];
      return "translate(" + scalevaf_x(x.vaf) + "," + scalevaf_y(y.vaf) + ")";
    });
    circle_xdp.attr("r", radius);
    circle_center.attr("r", radius);
    if (circle_yleft) {
      circle_yleft.attr("r", radius);
    }
    if (circle_yright) {
      circle_yright.attr("x", -radius).attr("y", -radius).attr("width", radius * 2).attr("height", radius * 2);
    }
    svg.attr(
      "width",
      (maxdp_yleft ? yvafwidth + sp + ydpheight : 0) + sp2 + xwidth + sp2 + (maxdp_yright ? ydpheight + sp + yvafwidth : 0)
    ).attr("height", toppad + yheight + sp2 + xdpheight + sp + xvafheight);
  };
  render();
}
export {
  plot_2dvaf as default
};
//# sourceMappingURL=plot.2dvaf-BNRZPIKU.js.map
