import {
  axisstyle,
  font,
  newpane,
  to_svg
} 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 "./chunk-KSGA62R2.js";
import {
  axisTop
} from "./chunk-LOZEKOES.js";
import "./chunk-TOU7EVFQ.js";
import {
  format,
  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.barplot.js
function plot_barplot(data, barcolor, label, pos) {
  const pane = newpane({ x: pos.left + 200, y: pos.top });
  pane.body.style("padding", "10px");
  pane.header.html(label);
  data.sort((a, b) => b.size - a.size);
  plot({
    lst: data,
    holder: pane.body,
    barcolor,
    limit: Math.min(data.length, 20)
  });
}
function plot(p) {
  p.holder.selectAll("*").remove();
  const row = p.holder.append("div").style("margin-bottom", "10px");
  row.append("button").text("more").on("click", () => {
    p.limit = Math.min(p.lst.length, p.limit + 10);
    plot(p);
  });
  row.append("button").text("less").on("click", () => {
    p.limit = Math.max(1, p.limit - 10);
    plot(p);
  });
  row.append("button").text("screenshot").on("click", () => to_svg(svg.node(), "barplot"));
  let barheight = 20, barwidth = 300, space = 5, axisheight = barheight + 5, barspace = barheight / 8, maxlabelwidth = 0, maxvalue = 0;
  const svg = p.holder.append("svg");
  const axisg = svg.append("g");
  for (let i = 0; i < p.limit; i++) {
    let j = p.lst[i];
    maxvalue = Math.max(maxvalue, j.size);
    svg.append("text").text(j.name).attr("font-size", barheight - 2).attr("font-family", font).each(function() {
      maxlabelwidth = Math.max(maxlabelwidth, this.getBBox().width);
    }).remove();
  }
  svg.attr("width", maxlabelwidth + space + barwidth + space).attr("height", axisheight + space + p.limit * (barheight + barspace));
  axisg.attr("transform", "translate(" + (maxlabelwidth + space) + "," + axisheight + ")").call(
    axisTop().scale(
      linear().domain([0, maxvalue]).range([0, barwidth])
    ).tickFormat(format("d"))
  );
  axisstyle({
    axis: axisg,
    showline: true,
    fontsize: barheight * 0.8,
    color: "black"
  });
  let y = axisheight + space;
  const sf = barwidth / maxvalue;
  for (let i = 0; i < p.limit; i++) {
    const j = p.lst[i];
    svg.append("text").text(j.name).attr("x", maxlabelwidth).attr("y", y + barheight / 2).attr("text-anchor", "end").attr("font-size", barheight - 2).attr("font-family", font).attr("dominant-baseline", "central");
    svg.append("rect").attr("x", maxlabelwidth + space).attr("y", y).attr("width", sf * j.size).attr("height", barheight - 1).attr("fill", p.barcolor);
    y += barheight + barspace;
  }
}
export {
  plot_barplot as default
};
//# sourceMappingURL=plot.barplot-342AYQC7.js.map
