var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
import "./purify.es-DT70lfR0.js";
import { t as linear } from "./linear-2NnK4cxi.js";
import { n as ordinal } from "./ordinal-B43ZeR68.js";
import { t as range } from "./range-BOiA8qqU.js";
import "./defaultLocale-BpsHxBd7.js";
import { t as line_default } from "./line-C5s_12ee.js";
import { i as cleanAndMerge } from "./chunk-S3R3BYOJ-mQeCz5CE.js";
import { n as initRange } from "./init-uv0kkh4g.js";
import { i as log, r as __name } from "./src-Bf2iLOlr.js";
import { B as setAccTitle, C as getDiagramTitle, I as sanitizeText, T as getThemeVariables3, U as setDiagramTitle, _ as getAccDescription, a as clear, c as configureSvgSize, d as defaultConfig_default, v as getAccTitle, y as getConfig, z as setAccDescription } from "./chunk-ABZYJK2D-D0cLy8Bb.js";
import { t as selectSvgElement } from "./chunk-EXTU4WIE-BKNXdLmD.js";
import "./dist-BGdYVvOu.js";
import { t as computeDimensionOfText } from "./chunk-JA3XYJ7Z-D6c6cOBG.js";
function band() {
  var e = ordinal().unknown(void 0), w = e.domain, T = e.range, D = 0, O = 1, k, A, j = false, M = 0, N = 0, P = 0.5;
  delete e.unknown;
  function F() {
    var e2 = w().length, S = O < D, E = S ? O : D, F2 = S ? D : O;
    k = (F2 - E) / Math.max(1, e2 - M + N * 2), j && (k = Math.floor(k)), E += (F2 - E - k * (e2 - M)) * P, A = k * (1 - M), j && (E = Math.round(E), A = Math.round(A));
    var I = range(e2).map(function(e3) {
      return E + k * e3;
    });
    return T(S ? I.reverse() : I);
  }
  return e.domain = function(e2) {
    return arguments.length ? (w(e2), F()) : w();
  }, e.range = function(e2) {
    return arguments.length ? ([D, O] = e2, D = +D, O = +O, F()) : [D, O];
  }, e.rangeRound = function(e2) {
    return [D, O] = e2, D = +D, O = +O, j = true, F();
  }, e.bandwidth = function() {
    return A;
  }, e.step = function() {
    return k;
  }, e.round = function(e2) {
    return arguments.length ? (j = !!e2, F()) : j;
  }, e.padding = function(e2) {
    return arguments.length ? (M = Math.min(1, N = +e2), F()) : M;
  }, e.paddingInner = function(e2) {
    return arguments.length ? (M = Math.min(1, e2), F()) : M;
  }, e.paddingOuter = function(e2) {
    return arguments.length ? (N = +e2, F()) : N;
  }, e.align = function(e2) {
    return arguments.length ? (P = Math.max(0, Math.min(1, e2)), F()) : P;
  }, e.copy = function() {
    return band(w(), [D, O]).round(j).paddingInner(M).paddingOuter(N).align(P);
  }, initRange.apply(F(), arguments);
}
var parser = (function() {
  var e = /* @__PURE__ */ __name(function(e2, S2, C2, w2) {
    for (C2 || (C2 = {}), w2 = e2.length; w2--; C2[e2[w2]] = S2) ;
    return C2;
  }, "o"), S = [
    1,
    10,
    12,
    14,
    16,
    18,
    19,
    21,
    23
  ], C = [2, 6], w = [1, 3], T = [1, 5], E = [1, 6], D = [1, 7], k = [
    1,
    5,
    10,
    12,
    14,
    16,
    18,
    19,
    21,
    23,
    34,
    35,
    36
  ], A = [1, 25], j = [1, 26], M = [1, 28], N = [1, 29], P = [1, 30], F = [1, 31], I = [1, 32], L = [1, 33], R = [1, 34], z = [1, 35], B = [1, 36], V = [1, 37], H = [1, 43], U = [1, 42], W = [1, 47], G = [1, 50], K = [
    1,
    10,
    12,
    14,
    16,
    18,
    19,
    21,
    23,
    34,
    35,
    36
  ], q = [
    1,
    10,
    12,
    14,
    16,
    18,
    19,
    21,
    23,
    24,
    26,
    27,
    28,
    34,
    35,
    36
  ], J = [
    1,
    10,
    12,
    14,
    16,
    18,
    19,
    21,
    23,
    24,
    26,
    27,
    28,
    34,
    35,
    36,
    41,
    42,
    43,
    44,
    45,
    46,
    47,
    48,
    49,
    50
  ], Y = [1, 64], X = {
    trace: /* @__PURE__ */ __name(function() {
    }, "trace"),
    yy: {},
    symbols_: {
      error: 2,
      start: 3,
      eol: 4,
      XYCHART: 5,
      chartConfig: 6,
      document: 7,
      CHART_ORIENTATION: 8,
      statement: 9,
      title: 10,
      text: 11,
      X_AXIS: 12,
      parseXAxis: 13,
      Y_AXIS: 14,
      parseYAxis: 15,
      LINE: 16,
      plotData: 17,
      BAR: 18,
      acc_title: 19,
      acc_title_value: 20,
      acc_descr: 21,
      acc_descr_value: 22,
      acc_descr_multiline_value: 23,
      SQUARE_BRACES_START: 24,
      commaSeparatedNumbers: 25,
      SQUARE_BRACES_END: 26,
      NUMBER_WITH_DECIMAL: 27,
      COMMA: 28,
      xAxisData: 29,
      bandData: 30,
      ARROW_DELIMITER: 31,
      commaSeparatedTexts: 32,
      yAxisData: 33,
      NEWLINE: 34,
      SEMI: 35,
      EOF: 36,
      alphaNum: 37,
      STR: 38,
      MD_STR: 39,
      alphaNumToken: 40,
      AMP: 41,
      NUM: 42,
      ALPHA: 43,
      PLUS: 44,
      EQUALS: 45,
      MULT: 46,
      DOT: 47,
      BRKT: 48,
      MINUS: 49,
      UNDERSCORE: 50,
      $accept: 0,
      $end: 1
    },
    terminals_: {
      2: "error",
      5: "XYCHART",
      8: "CHART_ORIENTATION",
      10: "title",
      12: "X_AXIS",
      14: "Y_AXIS",
      16: "LINE",
      18: "BAR",
      19: "acc_title",
      20: "acc_title_value",
      21: "acc_descr",
      22: "acc_descr_value",
      23: "acc_descr_multiline_value",
      24: "SQUARE_BRACES_START",
      26: "SQUARE_BRACES_END",
      27: "NUMBER_WITH_DECIMAL",
      28: "COMMA",
      31: "ARROW_DELIMITER",
      34: "NEWLINE",
      35: "SEMI",
      36: "EOF",
      38: "STR",
      39: "MD_STR",
      41: "AMP",
      42: "NUM",
      43: "ALPHA",
      44: "PLUS",
      45: "EQUALS",
      46: "MULT",
      47: "DOT",
      48: "BRKT",
      49: "MINUS",
      50: "UNDERSCORE"
    },
    productions_: [
      0,
      [3, 2],
      [3, 3],
      [3, 2],
      [3, 1],
      [6, 1],
      [7, 0],
      [7, 2],
      [9, 2],
      [9, 2],
      [9, 2],
      [9, 2],
      [9, 2],
      [9, 3],
      [9, 2],
      [9, 3],
      [9, 2],
      [9, 2],
      [9, 1],
      [17, 3],
      [25, 3],
      [25, 1],
      [13, 1],
      [13, 2],
      [13, 1],
      [29, 1],
      [29, 3],
      [30, 3],
      [32, 3],
      [32, 1],
      [15, 1],
      [15, 2],
      [15, 1],
      [33, 3],
      [4, 1],
      [4, 1],
      [4, 1],
      [11, 1],
      [11, 1],
      [11, 1],
      [37, 1],
      [37, 2],
      [40, 1],
      [40, 1],
      [40, 1],
      [40, 1],
      [40, 1],
      [40, 1],
      [40, 1],
      [40, 1],
      [40, 1],
      [40, 1]
    ],
    performAction: /* @__PURE__ */ __name(function(e2, S2, C2, w2, T2, E2, D2) {
      var O = E2.length - 1;
      switch (T2) {
        case 5:
          w2.setOrientation(E2[O]);
          break;
        case 9:
          w2.setDiagramTitle(E2[O].text.trim());
          break;
        case 12:
          w2.setLineData({
            text: "",
            type: "text"
          }, E2[O]);
          break;
        case 13:
          w2.setLineData(E2[O - 1], E2[O]);
          break;
        case 14:
          w2.setBarData({
            text: "",
            type: "text"
          }, E2[O]);
          break;
        case 15:
          w2.setBarData(E2[O - 1], E2[O]);
          break;
        case 16:
          this.$ = E2[O].trim(), w2.setAccTitle(this.$);
          break;
        case 17:
        case 18:
          this.$ = E2[O].trim(), w2.setAccDescription(this.$);
          break;
        case 19:
          this.$ = E2[O - 1];
          break;
        case 20:
          this.$ = [Number(E2[O - 2]), ...E2[O]];
          break;
        case 21:
          this.$ = [Number(E2[O])];
          break;
        case 22:
          w2.setXAxisTitle(E2[O]);
          break;
        case 23:
          w2.setXAxisTitle(E2[O - 1]);
          break;
        case 24:
          w2.setXAxisTitle({
            type: "text",
            text: ""
          });
          break;
        case 25:
          w2.setXAxisBand(E2[O]);
          break;
        case 26:
          w2.setXAxisRangeData(Number(E2[O - 2]), Number(E2[O]));
          break;
        case 27:
          this.$ = E2[O - 1];
          break;
        case 28:
          this.$ = [E2[O - 2], ...E2[O]];
          break;
        case 29:
          this.$ = [E2[O]];
          break;
        case 30:
          w2.setYAxisTitle(E2[O]);
          break;
        case 31:
          w2.setYAxisTitle(E2[O - 1]);
          break;
        case 32:
          w2.setYAxisTitle({
            type: "text",
            text: ""
          });
          break;
        case 33:
          w2.setYAxisRangeData(Number(E2[O - 2]), Number(E2[O]));
          break;
        case 37:
          this.$ = {
            text: E2[O],
            type: "text"
          };
          break;
        case 38:
          this.$ = {
            text: E2[O],
            type: "text"
          };
          break;
        case 39:
          this.$ = {
            text: E2[O],
            type: "markdown"
          };
          break;
        case 40:
          this.$ = E2[O];
          break;
        case 41:
          this.$ = E2[O - 1] + "" + E2[O];
          break;
      }
    }, "anonymous"),
    table: [
      e(S, C, {
        3: 1,
        4: 2,
        7: 4,
        5: w,
        34: T,
        35: E,
        36: D
      }),
      { 1: [3] },
      e(S, C, {
        4: 2,
        7: 4,
        3: 8,
        5: w,
        34: T,
        35: E,
        36: D
      }),
      e(S, C, {
        4: 2,
        7: 4,
        6: 9,
        3: 10,
        5: w,
        8: [1, 11],
        34: T,
        35: E,
        36: D
      }),
      {
        1: [2, 4],
        9: 12,
        10: [1, 13],
        12: [1, 14],
        14: [1, 15],
        16: [1, 16],
        18: [1, 17],
        19: [1, 18],
        21: [1, 19],
        23: [1, 20]
      },
      e(k, [2, 34]),
      e(k, [2, 35]),
      e(k, [2, 36]),
      { 1: [2, 1] },
      e(S, C, {
        4: 2,
        7: 4,
        3: 21,
        5: w,
        34: T,
        35: E,
        36: D
      }),
      { 1: [2, 3] },
      e(k, [2, 5]),
      e(S, [2, 7], {
        4: 22,
        34: T,
        35: E,
        36: D
      }),
      {
        11: 23,
        37: 24,
        38: A,
        39: j,
        40: 27,
        41: M,
        42: N,
        43: P,
        44: F,
        45: I,
        46: L,
        47: R,
        48: z,
        49: B,
        50: V
      },
      {
        11: 39,
        13: 38,
        24: H,
        27: U,
        29: 40,
        30: 41,
        37: 24,
        38: A,
        39: j,
        40: 27,
        41: M,
        42: N,
        43: P,
        44: F,
        45: I,
        46: L,
        47: R,
        48: z,
        49: B,
        50: V
      },
      {
        11: 45,
        15: 44,
        27: W,
        33: 46,
        37: 24,
        38: A,
        39: j,
        40: 27,
        41: M,
        42: N,
        43: P,
        44: F,
        45: I,
        46: L,
        47: R,
        48: z,
        49: B,
        50: V
      },
      {
        11: 49,
        17: 48,
        24: G,
        37: 24,
        38: A,
        39: j,
        40: 27,
        41: M,
        42: N,
        43: P,
        44: F,
        45: I,
        46: L,
        47: R,
        48: z,
        49: B,
        50: V
      },
      {
        11: 52,
        17: 51,
        24: G,
        37: 24,
        38: A,
        39: j,
        40: 27,
        41: M,
        42: N,
        43: P,
        44: F,
        45: I,
        46: L,
        47: R,
        48: z,
        49: B,
        50: V
      },
      { 20: [1, 53] },
      { 22: [1, 54] },
      e(K, [2, 18]),
      { 1: [2, 2] },
      e(K, [2, 8]),
      e(K, [2, 9]),
      e(q, [2, 37], {
        40: 55,
        41: M,
        42: N,
        43: P,
        44: F,
        45: I,
        46: L,
        47: R,
        48: z,
        49: B,
        50: V
      }),
      e(q, [2, 38]),
      e(q, [2, 39]),
      e(J, [2, 40]),
      e(J, [2, 42]),
      e(J, [2, 43]),
      e(J, [2, 44]),
      e(J, [2, 45]),
      e(J, [2, 46]),
      e(J, [2, 47]),
      e(J, [2, 48]),
      e(J, [2, 49]),
      e(J, [2, 50]),
      e(J, [2, 51]),
      e(K, [2, 10]),
      e(K, [2, 22], {
        30: 41,
        29: 56,
        24: H,
        27: U
      }),
      e(K, [2, 24]),
      e(K, [2, 25]),
      { 31: [1, 57] },
      {
        11: 59,
        32: 58,
        37: 24,
        38: A,
        39: j,
        40: 27,
        41: M,
        42: N,
        43: P,
        44: F,
        45: I,
        46: L,
        47: R,
        48: z,
        49: B,
        50: V
      },
      e(K, [2, 11]),
      e(K, [2, 30], {
        33: 60,
        27: W
      }),
      e(K, [2, 32]),
      { 31: [1, 61] },
      e(K, [2, 12]),
      {
        17: 62,
        24: G
      },
      {
        25: 63,
        27: Y
      },
      e(K, [2, 14]),
      {
        17: 65,
        24: G
      },
      e(K, [2, 16]),
      e(K, [2, 17]),
      e(J, [2, 41]),
      e(K, [2, 23]),
      { 27: [1, 66] },
      { 26: [1, 67] },
      {
        26: [2, 29],
        28: [1, 68]
      },
      e(K, [2, 31]),
      { 27: [1, 69] },
      e(K, [2, 13]),
      { 26: [1, 70] },
      {
        26: [2, 21],
        28: [1, 71]
      },
      e(K, [2, 15]),
      e(K, [2, 26]),
      e(K, [2, 27]),
      {
        11: 59,
        32: 72,
        37: 24,
        38: A,
        39: j,
        40: 27,
        41: M,
        42: N,
        43: P,
        44: F,
        45: I,
        46: L,
        47: R,
        48: z,
        49: B,
        50: V
      },
      e(K, [2, 33]),
      e(K, [2, 19]),
      {
        25: 73,
        27: Y
      },
      { 26: [2, 28] },
      { 26: [2, 20] }
    ],
    defaultActions: {
      8: [2, 1],
      10: [2, 3],
      21: [2, 2],
      72: [2, 28],
      73: [2, 20]
    },
    parseError: /* @__PURE__ */ __name(function(e2, S2) {
      if (S2.recoverable) this.trace(e2);
      else {
        var C2 = Error(e2);
        throw C2.hash = S2, C2;
      }
    }, "parseError"),
    parse: /* @__PURE__ */ __name(function(e2) {
      var S2 = this, C2 = [0], w2 = [], T2 = [null], E2 = [], D2 = this.table, k2 = "", A2 = 0, j2 = 0, M2 = 0, N2 = 2, P2 = 1, F2 = E2.slice.call(arguments, 1), I2 = Object.create(this.lexer), L2 = { yy: {} };
      for (var R2 in this.yy) Object.prototype.hasOwnProperty.call(this.yy, R2) && (L2.yy[R2] = this.yy[R2]);
      I2.setInput(e2, L2.yy), L2.yy.lexer = I2, L2.yy.parser = this, I2.yylloc === void 0 && (I2.yylloc = {});
      var z2 = I2.yylloc;
      E2.push(z2);
      var B2 = I2.options && I2.options.ranges;
      typeof L2.yy.parseError == "function" ? this.parseError = L2.yy.parseError : this.parseError = Object.getPrototypeOf(this).parseError;
      function V2(e3) {
        C2.length -= 2 * e3, T2.length -= e3, E2.length -= e3;
      }
      __name(V2, "popStack");
      function H2() {
        var e3 = w2.pop() || I2.lex() || P2;
        return typeof e3 != "number" && (e3 instanceof Array && (w2 = e3, e3 = w2.pop()), e3 = S2.symbols_[e3] || e3), e3;
      }
      __name(H2, "lex");
      for (var U2, W2, G2, K2, q2, J2 = {}, Y2, X2, Z2, Q; ; ) {
        if (G2 = C2[C2.length - 1], this.defaultActions[G2] ? K2 = this.defaultActions[G2] : (U2 ?? (U2 = H2()), K2 = D2[G2] && D2[G2][U2]), K2 === void 0 || !K2.length || !K2[0]) {
          var $ = "";
          for (Y2 in Q = [], D2[G2]) this.terminals_[Y2] && Y2 > N2 && Q.push("'" + this.terminals_[Y2] + "'");
          $ = I2.showPosition ? "Parse error on line " + (A2 + 1) + ":\n" + I2.showPosition() + "\nExpecting " + Q.join(", ") + ", got '" + (this.terminals_[U2] || U2) + "'" : "Parse error on line " + (A2 + 1) + ": Unexpected " + (U2 == P2 ? "end of input" : "'" + (this.terminals_[U2] || U2) + "'"), this.parseError($, {
            text: I2.match,
            token: this.terminals_[U2] || U2,
            line: I2.yylineno,
            loc: z2,
            expected: Q
          });
        }
        if (K2[0] instanceof Array && K2.length > 1) throw Error("Parse Error: multiple actions possible at state: " + G2 + ", token: " + U2);
        switch (K2[0]) {
          case 1:
            C2.push(U2), T2.push(I2.yytext), E2.push(I2.yylloc), C2.push(K2[1]), U2 = null, W2 ? (U2 = W2, W2 = null) : (j2 = I2.yyleng, k2 = I2.yytext, A2 = I2.yylineno, z2 = I2.yylloc, M2 > 0 && M2--);
            break;
          case 2:
            if (X2 = this.productions_[K2[1]][1], J2.$ = T2[T2.length - X2], J2._$ = {
              first_line: E2[E2.length - (X2 || 1)].first_line,
              last_line: E2[E2.length - 1].last_line,
              first_column: E2[E2.length - (X2 || 1)].first_column,
              last_column: E2[E2.length - 1].last_column
            }, B2 && (J2._$.range = [E2[E2.length - (X2 || 1)].range[0], E2[E2.length - 1].range[1]]), q2 = this.performAction.apply(J2, [
              k2,
              j2,
              A2,
              L2.yy,
              K2[1],
              T2,
              E2
            ].concat(F2)), q2 !== void 0) return q2;
            X2 && (C2 = C2.slice(0, -1 * X2 * 2), T2 = T2.slice(0, -1 * X2), E2 = E2.slice(0, -1 * X2)), C2.push(this.productions_[K2[1]][0]), T2.push(J2.$), E2.push(J2._$), Z2 = D2[C2[C2.length - 2]][C2[C2.length - 1]], C2.push(Z2);
            break;
          case 3:
            return true;
        }
      }
      return true;
    }, "parse")
  };
  X.lexer = /* @__PURE__ */ (function() {
    return {
      EOF: 1,
      parseError: /* @__PURE__ */ __name(function(e2, S2) {
        if (this.yy.parser) this.yy.parser.parseError(e2, S2);
        else throw Error(e2);
      }, "parseError"),
      setInput: /* @__PURE__ */ __name(function(e2, S2) {
        return this.yy = S2 || this.yy || {}, this._input = e2, this._more = this._backtrack = this.done = false, this.yylineno = this.yyleng = 0, this.yytext = this.matched = this.match = "", this.conditionStack = ["INITIAL"], this.yylloc = {
          first_line: 1,
          first_column: 0,
          last_line: 1,
          last_column: 0
        }, this.options.ranges && (this.yylloc.range = [0, 0]), this.offset = 0, this;
      }, "setInput"),
      input: /* @__PURE__ */ __name(function() {
        var e2 = this._input[0];
        return this.yytext += e2, this.yyleng++, this.offset++, this.match += e2, this.matched += e2, e2.match(/(?:\r\n?|\n).*/g) ? (this.yylineno++, this.yylloc.last_line++) : this.yylloc.last_column++, this.options.ranges && this.yylloc.range[1]++, this._input = this._input.slice(1), e2;
      }, "input"),
      unput: /* @__PURE__ */ __name(function(e2) {
        var S2 = e2.length, C2 = e2.split(/(?:\r\n?|\n)/g);
        this._input = e2 + this._input, this.yytext = this.yytext.substr(0, this.yytext.length - S2), this.offset -= S2;
        var w2 = this.match.split(/(?:\r\n?|\n)/g);
        this.match = this.match.substr(0, this.match.length - 1), this.matched = this.matched.substr(0, this.matched.length - 1), C2.length - 1 && (this.yylineno -= C2.length - 1);
        var T2 = this.yylloc.range;
        return this.yylloc = {
          first_line: this.yylloc.first_line,
          last_line: this.yylineno + 1,
          first_column: this.yylloc.first_column,
          last_column: C2 ? (C2.length === w2.length ? this.yylloc.first_column : 0) + w2[w2.length - C2.length].length - C2[0].length : this.yylloc.first_column - S2
        }, this.options.ranges && (this.yylloc.range = [T2[0], T2[0] + this.yyleng - S2]), this.yyleng = this.yytext.length, this;
      }, "unput"),
      more: /* @__PURE__ */ __name(function() {
        return this._more = true, this;
      }, "more"),
      reject: /* @__PURE__ */ __name(function() {
        if (this.options.backtrack_lexer) this._backtrack = true;
        else return this.parseError("Lexical error on line " + (this.yylineno + 1) + ". You can only invoke reject() in the lexer when the lexer is of the backtracking persuasion (options.backtrack_lexer = true).\n" + this.showPosition(), {
          text: "",
          token: null,
          line: this.yylineno
        });
        return this;
      }, "reject"),
      less: /* @__PURE__ */ __name(function(e2) {
        this.unput(this.match.slice(e2));
      }, "less"),
      pastInput: /* @__PURE__ */ __name(function() {
        var e2 = this.matched.substr(0, this.matched.length - this.match.length);
        return (e2.length > 20 ? "..." : "") + e2.substr(-20).replace(/\n/g, "");
      }, "pastInput"),
      upcomingInput: /* @__PURE__ */ __name(function() {
        var e2 = this.match;
        return e2.length < 20 && (e2 += this._input.substr(0, 20 - e2.length)), (e2.substr(0, 20) + (e2.length > 20 ? "..." : "")).replace(/\n/g, "");
      }, "upcomingInput"),
      showPosition: /* @__PURE__ */ __name(function() {
        var e2 = this.pastInput(), S2 = Array(e2.length + 1).join("-");
        return e2 + this.upcomingInput() + "\n" + S2 + "^";
      }, "showPosition"),
      test_match: /* @__PURE__ */ __name(function(e2, S2) {
        var C2, w2, T2;
        if (this.options.backtrack_lexer && (T2 = {
          yylineno: this.yylineno,
          yylloc: {
            first_line: this.yylloc.first_line,
            last_line: this.last_line,
            first_column: this.yylloc.first_column,
            last_column: this.yylloc.last_column
          },
          yytext: this.yytext,
          match: this.match,
          matches: this.matches,
          matched: this.matched,
          yyleng: this.yyleng,
          offset: this.offset,
          _more: this._more,
          _input: this._input,
          yy: this.yy,
          conditionStack: this.conditionStack.slice(0),
          done: this.done
        }, this.options.ranges && (T2.yylloc.range = this.yylloc.range.slice(0))), w2 = e2[0].match(/(?:\r\n?|\n).*/g), w2 && (this.yylineno += w2.length), this.yylloc = {
          first_line: this.yylloc.last_line,
          last_line: this.yylineno + 1,
          first_column: this.yylloc.last_column,
          last_column: w2 ? w2[w2.length - 1].length - w2[w2.length - 1].match(/\r?\n?/)[0].length : this.yylloc.last_column + e2[0].length
        }, this.yytext += e2[0], this.match += e2[0], this.matches = e2, this.yyleng = this.yytext.length, this.options.ranges && (this.yylloc.range = [this.offset, this.offset += this.yyleng]), this._more = false, this._backtrack = false, this._input = this._input.slice(e2[0].length), this.matched += e2[0], C2 = this.performAction.call(this, this.yy, this, S2, this.conditionStack[this.conditionStack.length - 1]), this.done && this._input && (this.done = false), C2) return C2;
        if (this._backtrack) {
          for (var E2 in T2) this[E2] = T2[E2];
          return false;
        }
        return false;
      }, "test_match"),
      next: /* @__PURE__ */ __name(function() {
        if (this.done) return this.EOF;
        this._input || (this.done = true);
        var e2, S2, C2, w2;
        this._more || (this.yytext = "", this.match = "");
        for (var T2 = this._currentRules(), E2 = 0; E2 < T2.length; E2++) if (C2 = this._input.match(this.rules[T2[E2]]), C2 && (!S2 || C2[0].length > S2[0].length)) {
          if (S2 = C2, w2 = E2, this.options.backtrack_lexer) {
            if (e2 = this.test_match(C2, T2[E2]), e2 !== false) return e2;
            if (this._backtrack) {
              S2 = false;
              continue;
            } else return false;
          } else if (!this.options.flex) break;
        }
        return S2 ? (e2 = this.test_match(S2, T2[w2]), e2 === false ? false : e2) : this._input === "" ? this.EOF : this.parseError("Lexical error on line " + (this.yylineno + 1) + ". Unrecognized text.\n" + this.showPosition(), {
          text: "",
          token: null,
          line: this.yylineno
        });
      }, "next"),
      lex: /* @__PURE__ */ __name(function() {
        return this.next() || this.lex();
      }, "lex"),
      begin: /* @__PURE__ */ __name(function(e2) {
        this.conditionStack.push(e2);
      }, "begin"),
      popState: /* @__PURE__ */ __name(function() {
        return this.conditionStack.length - 1 > 0 ? this.conditionStack.pop() : this.conditionStack[0];
      }, "popState"),
      _currentRules: /* @__PURE__ */ __name(function() {
        return this.conditionStack.length && this.conditionStack[this.conditionStack.length - 1] ? this.conditions[this.conditionStack[this.conditionStack.length - 1]].rules : this.conditions.INITIAL.rules;
      }, "_currentRules"),
      topState: /* @__PURE__ */ __name(function(e2) {
        return e2 = this.conditionStack.length - 1 - Math.abs(e2 || 0), e2 >= 0 ? this.conditionStack[e2] : "INITIAL";
      }, "topState"),
      pushState: /* @__PURE__ */ __name(function(e2) {
        this.begin(e2);
      }, "pushState"),
      stateStackSize: /* @__PURE__ */ __name(function() {
        return this.conditionStack.length;
      }, "stateStackSize"),
      options: { "case-insensitive": true },
      performAction: /* @__PURE__ */ __name(function(e2, S2, C2, w2) {
        switch (C2) {
          case 0:
            break;
          case 1:
            break;
          case 2:
            return this.popState(), 34;
          case 3:
            return this.popState(), 34;
          case 4:
            return 34;
          case 5:
            break;
          case 6:
            return 10;
          case 7:
            return this.pushState("acc_title"), 19;
          case 8:
            return this.popState(), "acc_title_value";
          case 9:
            return this.pushState("acc_descr"), 21;
          case 10:
            return this.popState(), "acc_descr_value";
          case 11:
            this.pushState("acc_descr_multiline");
            break;
          case 12:
            this.popState();
            break;
          case 13:
            return "acc_descr_multiline_value";
          case 14:
            return 5;
          case 15:
            return 5;
          case 16:
            return 8;
          case 17:
            return this.pushState("axis_data"), "X_AXIS";
          case 18:
            return this.pushState("axis_data"), "Y_AXIS";
          case 19:
            return this.pushState("axis_band_data"), 24;
          case 20:
            return 31;
          case 21:
            return this.pushState("data"), 16;
          case 22:
            return this.pushState("data"), 18;
          case 23:
            return this.pushState("data_inner"), 24;
          case 24:
            return 27;
          case 25:
            return this.popState(), 26;
          case 26:
            this.popState();
            break;
          case 27:
            this.pushState("string");
            break;
          case 28:
            this.popState();
            break;
          case 29:
            return "STR";
          case 30:
            return 24;
          case 31:
            return 26;
          case 32:
            return 43;
          case 33:
            return "COLON";
          case 34:
            return 44;
          case 35:
            return 28;
          case 36:
            return 45;
          case 37:
            return 46;
          case 38:
            return 48;
          case 39:
            return 50;
          case 40:
            return 47;
          case 41:
            return 41;
          case 42:
            return 49;
          case 43:
            return 42;
          case 44:
            break;
          case 45:
            return 35;
          case 46:
            return 36;
        }
      }, "anonymous"),
      rules: [
        /^(?:%%(?!\{)[^\n]*)/i,
        /^(?:[^\}]%%[^\n]*)/i,
        /^(?:(\r?\n))/i,
        /^(?:(\r?\n))/i,
        /^(?:[\n\r]+)/i,
        /^(?:%%[^\n]*)/i,
        /^(?:title\b)/i,
        /^(?:accTitle\s*:\s*)/i,
        /^(?:(?!\n||)*[^\n]*)/i,
        /^(?:accDescr\s*:\s*)/i,
        /^(?:(?!\n||)*[^\n]*)/i,
        /^(?:accDescr\s*\{\s*)/i,
        /^(?:\{)/i,
        /^(?:[^\}]*)/i,
        /^(?:xychart-beta\b)/i,
        /^(?:xychart\b)/i,
        /^(?:(?:vertical|horizontal))/i,
        /^(?:x-axis\b)/i,
        /^(?:y-axis\b)/i,
        /^(?:\[)/i,
        /^(?:-->)/i,
        /^(?:line\b)/i,
        /^(?:bar\b)/i,
        /^(?:\[)/i,
        /^(?:[+-]?(?:\d+(?:\.\d+)?|\.\d+))/i,
        /^(?:\])/i,
        /^(?:(?:`\)                                    \{ this\.pushState\(md_string\); \}\n<md_string>\(\?:\(\?!`"\)\.\)\+                  \{ return MD_STR; \}\n<md_string>\(\?:`))/i,
        /^(?:["])/i,
        /^(?:["])/i,
        /^(?:[^"]*)/i,
        /^(?:\[)/i,
        /^(?:\])/i,
        /^(?:[A-Za-z]+)/i,
        /^(?::)/i,
        /^(?:\+)/i,
        /^(?:,)/i,
        /^(?:=)/i,
        /^(?:\*)/i,
        /^(?:#)/i,
        /^(?:[\_])/i,
        /^(?:\.)/i,
        /^(?:&)/i,
        /^(?:-)/i,
        /^(?:[0-9]+)/i,
        /^(?:\s+)/i,
        /^(?:;)/i,
        /^(?:$)/i
      ],
      conditions: {
        data_inner: {
          rules: [
            0,
            1,
            4,
            5,
            6,
            7,
            9,
            11,
            14,
            15,
            16,
            17,
            18,
            21,
            22,
            24,
            25,
            26,
            27,
            30,
            31,
            32,
            33,
            34,
            35,
            36,
            37,
            38,
            39,
            40,
            41,
            42,
            43,
            44,
            45,
            46
          ],
          inclusive: true
        },
        data: {
          rules: [
            0,
            1,
            3,
            4,
            5,
            6,
            7,
            9,
            11,
            14,
            15,
            16,
            17,
            18,
            21,
            22,
            23,
            26,
            27,
            30,
            31,
            32,
            33,
            34,
            35,
            36,
            37,
            38,
            39,
            40,
            41,
            42,
            43,
            44,
            45,
            46
          ],
          inclusive: true
        },
        axis_band_data: {
          rules: [
            0,
            1,
            4,
            5,
            6,
            7,
            9,
            11,
            14,
            15,
            16,
            17,
            18,
            21,
            22,
            25,
            26,
            27,
            30,
            31,
            32,
            33,
            34,
            35,
            36,
            37,
            38,
            39,
            40,
            41,
            42,
            43,
            44,
            45,
            46
          ],
          inclusive: true
        },
        axis_data: {
          rules: [
            0,
            1,
            2,
            4,
            5,
            6,
            7,
            9,
            11,
            14,
            15,
            16,
            17,
            18,
            19,
            20,
            21,
            22,
            24,
            26,
            27,
            30,
            31,
            32,
            33,
            34,
            35,
            36,
            37,
            38,
            39,
            40,
            41,
            42,
            43,
            44,
            45,
            46
          ],
          inclusive: true
        },
        acc_descr_multiline: {
          rules: [12, 13],
          inclusive: false
        },
        acc_descr: {
          rules: [10],
          inclusive: false
        },
        acc_title: {
          rules: [8],
          inclusive: false
        },
        title: {
          rules: [],
          inclusive: false
        },
        md_string: {
          rules: [],
          inclusive: false
        },
        string: {
          rules: [28, 29],
          inclusive: false
        },
        INITIAL: {
          rules: [
            0,
            1,
            4,
            5,
            6,
            7,
            9,
            11,
            14,
            15,
            16,
            17,
            18,
            21,
            22,
            26,
            27,
            30,
            31,
            32,
            33,
            34,
            35,
            36,
            37,
            38,
            39,
            40,
            41,
            42,
            43,
            44,
            45,
            46
          ],
          inclusive: true
        }
      }
    };
  })();
  function Z() {
    this.yy = {};
  }
  return __name(Z, "Parser"), Z.prototype = X, X.Parser = Z, new Z();
})();
parser.parser = parser;
var xychart_default = parser;
function isBarPlot(e) {
  return e.type === "bar";
}
__name(isBarPlot, "isBarPlot");
function isBandAxisData(e) {
  return e.type === "band";
}
__name(isBandAxisData, "isBandAxisData");
function isLinearAxisData(e) {
  return e.type === "linear";
}
__name(isLinearAxisData, "isLinearAxisData");
var TextDimensionCalculatorWithFont = (_a = class {
  constructor(e) {
    this.parentGroup = e;
  }
  getMaxDimension(e, S) {
    if (!this.parentGroup) return {
      width: e.reduce((e2, S2) => Math.max(S2.length, e2), 0) * S,
      height: S
    };
    let C = {
      width: 0,
      height: 0
    }, w = this.parentGroup.append("g").attr("visibility", "hidden").attr("font-size", S);
    for (let T of e) {
      let e2 = computeDimensionOfText(w, 1, T), E = e2 ? e2.width : T.length * S, D = e2 ? e2.height : S;
      C.width = Math.max(C.width, E), C.height = Math.max(C.height, D);
    }
    return w.remove(), C;
  }
}, __name(_a, "TextDimensionCalculatorWithFont"), _a), BAR_WIDTH_TO_TICK_WIDTH_RATIO = 0.7, MAX_OUTER_PADDING_PERCENT_FOR_WRT_LABEL = 0.2, BaseAxis = (_b = class {
  constructor(e, S, C, w) {
    this.axisConfig = e, this.title = S, this.textDimensionCalculator = C, this.axisThemeConfig = w, this.boundingRect = {
      x: 0,
      y: 0,
      width: 0,
      height: 0
    }, this.axisPosition = "left", this.showTitle = false, this.showLabel = false, this.showTick = false, this.showAxisLine = false, this.outerPadding = 0, this.titleTextHeight = 0, this.labelTextHeight = 0, this.range = [0, 10], this.boundingRect = {
      x: 0,
      y: 0,
      width: 0,
      height: 0
    }, this.axisPosition = "left";
  }
  setRange(e) {
    this.range = e, this.axisPosition === "left" || this.axisPosition === "right" ? this.boundingRect.height = e[1] - e[0] : this.boundingRect.width = e[1] - e[0], this.recalculateScale();
  }
  getRange() {
    return [this.range[0] + this.outerPadding, this.range[1] - this.outerPadding];
  }
  setAxisPosition(e) {
    this.axisPosition = e, this.setRange(this.range);
  }
  getTickDistance() {
    let e = this.getRange();
    return Math.abs(e[0] - e[1]) / this.getTickValues().length;
  }
  getAxisOuterPadding() {
    return this.outerPadding;
  }
  getLabelDimension() {
    return this.textDimensionCalculator.getMaxDimension(this.getTickValues().map((e) => e.toString()), this.axisConfig.labelFontSize);
  }
  recalculateOuterPaddingToDrawBar() {
    BAR_WIDTH_TO_TICK_WIDTH_RATIO * this.getTickDistance() > this.outerPadding * 2 && (this.outerPadding = Math.floor(BAR_WIDTH_TO_TICK_WIDTH_RATIO * this.getTickDistance() / 2)), this.recalculateScale();
  }
  calculateSpaceIfDrawnHorizontally(e) {
    let S = e.height;
    if (this.axisConfig.showAxisLine && S > this.axisConfig.axisLineWidth && (S -= this.axisConfig.axisLineWidth, this.showAxisLine = true), this.axisConfig.showLabel) {
      let C = this.getLabelDimension(), w = MAX_OUTER_PADDING_PERCENT_FOR_WRT_LABEL * e.width;
      this.outerPadding = Math.min(C.width / 2, w);
      let T = C.height + this.axisConfig.labelPadding * 2;
      this.labelTextHeight = C.height, T <= S && (S -= T, this.showLabel = true);
    }
    if (this.axisConfig.showTick && S >= this.axisConfig.tickLength && (this.showTick = true, S -= this.axisConfig.tickLength), this.axisConfig.showTitle && this.title) {
      let e2 = this.textDimensionCalculator.getMaxDimension([this.title], this.axisConfig.titleFontSize), C = e2.height + this.axisConfig.titlePadding * 2;
      this.titleTextHeight = e2.height, C <= S && (S -= C, this.showTitle = true);
    }
    this.boundingRect.width = e.width, this.boundingRect.height = e.height - S;
  }
  calculateSpaceIfDrawnVertical(e) {
    let S = e.width;
    if (this.axisConfig.showAxisLine && S > this.axisConfig.axisLineWidth && (S -= this.axisConfig.axisLineWidth, this.showAxisLine = true), this.axisConfig.showLabel) {
      let C = this.getLabelDimension(), w = MAX_OUTER_PADDING_PERCENT_FOR_WRT_LABEL * e.height;
      this.outerPadding = Math.min(C.height / 2, w);
      let T = C.width + this.axisConfig.labelPadding * 2;
      T <= S && (S -= T, this.showLabel = true);
    }
    if (this.axisConfig.showTick && S >= this.axisConfig.tickLength && (this.showTick = true, S -= this.axisConfig.tickLength), this.axisConfig.showTitle && this.title) {
      let e2 = this.textDimensionCalculator.getMaxDimension([this.title], this.axisConfig.titleFontSize), C = e2.height + this.axisConfig.titlePadding * 2;
      this.titleTextHeight = e2.height, C <= S && (S -= C, this.showTitle = true);
    }
    this.boundingRect.width = e.width - S, this.boundingRect.height = e.height;
  }
  calculateSpace(e) {
    return this.axisPosition === "left" || this.axisPosition === "right" ? this.calculateSpaceIfDrawnVertical(e) : this.calculateSpaceIfDrawnHorizontally(e), this.recalculateScale(), {
      width: this.boundingRect.width,
      height: this.boundingRect.height
    };
  }
  setBoundingBoxXY(e) {
    this.boundingRect.x = e.x, this.boundingRect.y = e.y;
  }
  getDrawableElementsForLeftAxis() {
    let e = [];
    if (this.showAxisLine) {
      let S = this.boundingRect.x + this.boundingRect.width - this.axisConfig.axisLineWidth / 2;
      e.push({
        type: "path",
        groupTexts: ["left-axis", "axisl-line"],
        data: [{
          path: `M ${S},${this.boundingRect.y} L ${S},${this.boundingRect.y + this.boundingRect.height} `,
          strokeFill: this.axisThemeConfig.axisLineColor,
          strokeWidth: this.axisConfig.axisLineWidth
        }]
      });
    }
    if (this.showLabel && e.push({
      type: "text",
      groupTexts: ["left-axis", "label"],
      data: this.getTickValues().map((e2) => ({
        text: e2.toString(),
        x: this.boundingRect.x + this.boundingRect.width - (this.showLabel ? this.axisConfig.labelPadding : 0) - (this.showTick ? this.axisConfig.tickLength : 0) - (this.showAxisLine ? this.axisConfig.axisLineWidth : 0),
        y: this.getScaleValue(e2),
        fill: this.axisThemeConfig.labelColor,
        fontSize: this.axisConfig.labelFontSize,
        rotation: 0,
        verticalPos: "middle",
        horizontalPos: "right"
      }))
    }), this.showTick) {
      let S = this.boundingRect.x + this.boundingRect.width - (this.showAxisLine ? this.axisConfig.axisLineWidth : 0);
      e.push({
        type: "path",
        groupTexts: ["left-axis", "ticks"],
        data: this.getTickValues().map((e2) => ({
          path: `M ${S},${this.getScaleValue(e2)} L ${S - this.axisConfig.tickLength},${this.getScaleValue(e2)}`,
          strokeFill: this.axisThemeConfig.tickColor,
          strokeWidth: this.axisConfig.tickWidth
        }))
      });
    }
    return this.showTitle && e.push({
      type: "text",
      groupTexts: ["left-axis", "title"],
      data: [{
        text: this.title,
        x: this.boundingRect.x + this.axisConfig.titlePadding,
        y: this.boundingRect.y + this.boundingRect.height / 2,
        fill: this.axisThemeConfig.titleColor,
        fontSize: this.axisConfig.titleFontSize,
        rotation: 270,
        verticalPos: "top",
        horizontalPos: "center"
      }]
    }), e;
  }
  getDrawableElementsForBottomAxis() {
    let e = [];
    if (this.showAxisLine) {
      let S = this.boundingRect.y + this.axisConfig.axisLineWidth / 2;
      e.push({
        type: "path",
        groupTexts: ["bottom-axis", "axis-line"],
        data: [{
          path: `M ${this.boundingRect.x},${S} L ${this.boundingRect.x + this.boundingRect.width},${S}`,
          strokeFill: this.axisThemeConfig.axisLineColor,
          strokeWidth: this.axisConfig.axisLineWidth
        }]
      });
    }
    if (this.showLabel && e.push({
      type: "text",
      groupTexts: ["bottom-axis", "label"],
      data: this.getTickValues().map((e2) => ({
        text: e2.toString(),
        x: this.getScaleValue(e2),
        y: this.boundingRect.y + this.axisConfig.labelPadding + (this.showTick ? this.axisConfig.tickLength : 0) + (this.showAxisLine ? this.axisConfig.axisLineWidth : 0),
        fill: this.axisThemeConfig.labelColor,
        fontSize: this.axisConfig.labelFontSize,
        rotation: 0,
        verticalPos: "top",
        horizontalPos: "center"
      }))
    }), this.showTick) {
      let S = this.boundingRect.y + (this.showAxisLine ? this.axisConfig.axisLineWidth : 0);
      e.push({
        type: "path",
        groupTexts: ["bottom-axis", "ticks"],
        data: this.getTickValues().map((e2) => ({
          path: `M ${this.getScaleValue(e2)},${S} L ${this.getScaleValue(e2)},${S + this.axisConfig.tickLength}`,
          strokeFill: this.axisThemeConfig.tickColor,
          strokeWidth: this.axisConfig.tickWidth
        }))
      });
    }
    return this.showTitle && e.push({
      type: "text",
      groupTexts: ["bottom-axis", "title"],
      data: [{
        text: this.title,
        x: this.range[0] + (this.range[1] - this.range[0]) / 2,
        y: this.boundingRect.y + this.boundingRect.height - this.axisConfig.titlePadding - this.titleTextHeight,
        fill: this.axisThemeConfig.titleColor,
        fontSize: this.axisConfig.titleFontSize,
        rotation: 0,
        verticalPos: "top",
        horizontalPos: "center"
      }]
    }), e;
  }
  getDrawableElementsForTopAxis() {
    let e = [];
    if (this.showAxisLine) {
      let S = this.boundingRect.y + this.boundingRect.height - this.axisConfig.axisLineWidth / 2;
      e.push({
        type: "path",
        groupTexts: ["top-axis", "axis-line"],
        data: [{
          path: `M ${this.boundingRect.x},${S} L ${this.boundingRect.x + this.boundingRect.width},${S}`,
          strokeFill: this.axisThemeConfig.axisLineColor,
          strokeWidth: this.axisConfig.axisLineWidth
        }]
      });
    }
    if (this.showLabel && e.push({
      type: "text",
      groupTexts: ["top-axis", "label"],
      data: this.getTickValues().map((e2) => ({
        text: e2.toString(),
        x: this.getScaleValue(e2),
        y: this.boundingRect.y + (this.showTitle ? this.titleTextHeight + this.axisConfig.titlePadding * 2 : 0) + this.axisConfig.labelPadding,
        fill: this.axisThemeConfig.labelColor,
        fontSize: this.axisConfig.labelFontSize,
        rotation: 0,
        verticalPos: "top",
        horizontalPos: "center"
      }))
    }), this.showTick) {
      let S = this.boundingRect.y;
      e.push({
        type: "path",
        groupTexts: ["top-axis", "ticks"],
        data: this.getTickValues().map((e2) => ({
          path: `M ${this.getScaleValue(e2)},${S + this.boundingRect.height - (this.showAxisLine ? this.axisConfig.axisLineWidth : 0)} L ${this.getScaleValue(e2)},${S + this.boundingRect.height - this.axisConfig.tickLength - (this.showAxisLine ? this.axisConfig.axisLineWidth : 0)}`,
          strokeFill: this.axisThemeConfig.tickColor,
          strokeWidth: this.axisConfig.tickWidth
        }))
      });
    }
    return this.showTitle && e.push({
      type: "text",
      groupTexts: ["top-axis", "title"],
      data: [{
        text: this.title,
        x: this.boundingRect.x + this.boundingRect.width / 2,
        y: this.boundingRect.y + this.axisConfig.titlePadding,
        fill: this.axisThemeConfig.titleColor,
        fontSize: this.axisConfig.titleFontSize,
        rotation: 0,
        verticalPos: "top",
        horizontalPos: "center"
      }]
    }), e;
  }
  getDrawableElements() {
    if (this.axisPosition === "left") return this.getDrawableElementsForLeftAxis();
    if (this.axisPosition === "right") throw Error("Drawing of right axis is not implemented");
    return this.axisPosition === "bottom" ? this.getDrawableElementsForBottomAxis() : this.axisPosition === "top" ? this.getDrawableElementsForTopAxis() : [];
  }
}, __name(_b, "BaseAxis"), _b), BandAxis = (_c = class extends BaseAxis {
  constructor(e, S, C, w, T) {
    super(e, w, T, S), this.categories = C, this.scale = band().domain(this.categories).range(this.getRange());
  }
  setRange(e) {
    super.setRange(e);
  }
  recalculateScale() {
    this.scale = band().domain(this.categories).range(this.getRange()).paddingInner(1).paddingOuter(0).align(0.5), log.trace("BandAxis axis final categories, range: ", this.categories, this.getRange());
  }
  getTickValues() {
    return this.categories;
  }
  getScaleValue(e) {
    return this.scale(e) ?? this.getRange()[0];
  }
}, __name(_c, "BandAxis"), _c), LinearAxis = (_d = class extends BaseAxis {
  constructor(S, C, w, T, E) {
    super(S, T, E, C), this.domain = w, this.scale = linear().domain(this.domain).range(this.getRange());
  }
  getTickValues() {
    return this.scale.ticks();
  }
  recalculateScale() {
    let S = [...this.domain];
    this.axisPosition === "left" && S.reverse(), this.scale = linear().domain(S).range(this.getRange());
  }
  getScaleValue(e) {
    return this.scale(e);
  }
}, __name(_d, "LinearAxis"), _d);
function getAxis(e, S, C, w) {
  let T = new TextDimensionCalculatorWithFont(w);
  return isBandAxisData(e) ? new BandAxis(S, C, e.categories, e.title, T) : new LinearAxis(S, C, [e.min, e.max], e.title, T);
}
__name(getAxis, "getAxis");
var ChartTitle = (_e = class {
  constructor(e, S, C, w) {
    this.textDimensionCalculator = e, this.chartConfig = S, this.chartData = C, this.chartThemeConfig = w, this.boundingRect = {
      x: 0,
      y: 0,
      width: 0,
      height: 0
    }, this.showChartTitle = false;
  }
  setBoundingBoxXY(e) {
    this.boundingRect.x = e.x, this.boundingRect.y = e.y;
  }
  calculateSpace(e) {
    let S = this.textDimensionCalculator.getMaxDimension([this.chartData.title], this.chartConfig.titleFontSize), C = Math.max(S.width, e.width), w = S.height + 2 * this.chartConfig.titlePadding;
    return S.width <= C && S.height <= w && this.chartConfig.showTitle && this.chartData.title && (this.boundingRect.width = C, this.boundingRect.height = w, this.showChartTitle = true), {
      width: this.boundingRect.width,
      height: this.boundingRect.height
    };
  }
  getDrawableElements() {
    let e = [];
    return this.showChartTitle && e.push({
      groupTexts: ["chart-title"],
      type: "text",
      data: [{
        fontSize: this.chartConfig.titleFontSize,
        text: this.chartData.title,
        verticalPos: "middle",
        horizontalPos: "center",
        x: this.boundingRect.x + this.boundingRect.width / 2,
        y: this.boundingRect.y + this.boundingRect.height / 2,
        fill: this.chartThemeConfig.titleColor,
        rotation: 0
      }]
    }), e;
  }
}, __name(_e, "ChartTitle"), _e);
function getChartTitleComponent(e, S, C, w) {
  return new ChartTitle(new TextDimensionCalculatorWithFont(w), e, S, C);
}
__name(getChartTitleComponent, "getChartTitleComponent");
var LinePlot = (_f = class {
  constructor(e, S, C, w, T) {
    this.plotData = e, this.xAxis = S, this.yAxis = C, this.orientation = w, this.plotIndex = T;
  }
  getDrawableElement() {
    let e = this.plotData.data.map((e2) => [this.xAxis.getScaleValue(e2[0]), this.yAxis.getScaleValue(e2[1])]), S;
    return S = this.orientation === "horizontal" ? line_default().y((e2) => e2[0]).x((e2) => e2[1])(e) : line_default().x((e2) => e2[0]).y((e2) => e2[1])(e), S ? [{
      groupTexts: ["plot", `line-plot-${this.plotIndex}`],
      type: "path",
      data: [{
        path: S,
        strokeFill: this.plotData.strokeFill,
        strokeWidth: this.plotData.strokeWidth
      }]
    }] : [];
  }
}, __name(_f, "LinePlot"), _f), BarPlot = (_g = class {
  constructor(e, S, C, w, T, E) {
    this.barData = e, this.boundingRect = S, this.xAxis = C, this.yAxis = w, this.orientation = T, this.plotIndex = E;
  }
  getDrawableElement() {
    let e = this.barData.data.map((e2) => [this.xAxis.getScaleValue(e2[0]), this.yAxis.getScaleValue(e2[1])]), S = Math.min(this.xAxis.getAxisOuterPadding() * 2, this.xAxis.getTickDistance()) * 0.95, C = S / 2;
    return this.orientation === "horizontal" ? [{
      groupTexts: ["plot", `bar-plot-${this.plotIndex}`],
      type: "rect",
      data: e.map((e2) => ({
        x: this.boundingRect.x,
        y: e2[0] - C,
        height: S,
        width: e2[1] - this.boundingRect.x,
        fill: this.barData.fill,
        strokeWidth: 0,
        strokeFill: this.barData.fill
      }))
    }] : [{
      groupTexts: ["plot", `bar-plot-${this.plotIndex}`],
      type: "rect",
      data: e.map((e2) => ({
        x: e2[0] - C,
        y: e2[1],
        width: S,
        height: this.boundingRect.y + this.boundingRect.height - e2[1],
        fill: this.barData.fill,
        strokeWidth: 0,
        strokeFill: this.barData.fill
      }))
    }];
  }
}, __name(_g, "BarPlot"), _g), BasePlot = (_h = class {
  constructor(e, S, C) {
    this.chartConfig = e, this.chartData = S, this.chartThemeConfig = C, this.boundingRect = {
      x: 0,
      y: 0,
      width: 0,
      height: 0
    };
  }
  setAxes(e, S) {
    this.xAxis = e, this.yAxis = S;
  }
  setBoundingBoxXY(e) {
    this.boundingRect.x = e.x, this.boundingRect.y = e.y;
  }
  calculateSpace(e) {
    return this.boundingRect.width = e.width, this.boundingRect.height = e.height, {
      width: this.boundingRect.width,
      height: this.boundingRect.height
    };
  }
  getDrawableElements() {
    if (!(this.xAxis && this.yAxis)) throw Error("Axes must be passed to render Plots");
    let e = [];
    for (let [S, C] of this.chartData.plots.entries()) switch (C.type) {
      case "line":
        {
          let w = new LinePlot(C, this.xAxis, this.yAxis, this.chartConfig.chartOrientation, S);
          e.push(...w.getDrawableElement());
        }
        break;
      case "bar":
        {
          let w = new BarPlot(C, this.boundingRect, this.xAxis, this.yAxis, this.chartConfig.chartOrientation, S);
          e.push(...w.getDrawableElement());
        }
        break;
    }
    return e;
  }
}, __name(_h, "BasePlot"), _h);
function getPlotComponent(e, S, C) {
  return new BasePlot(e, S, C);
}
__name(getPlotComponent, "getPlotComponent");
var Orchestrator = (_i = class {
  constructor(e, S, C, w) {
    this.chartConfig = e, this.chartData = S, this.componentStore = {
      title: getChartTitleComponent(e, S, C, w),
      plot: getPlotComponent(e, S, C),
      xAxis: getAxis(S.xAxis, e.xAxis, {
        titleColor: C.xAxisTitleColor,
        labelColor: C.xAxisLabelColor,
        tickColor: C.xAxisTickColor,
        axisLineColor: C.xAxisLineColor
      }, w),
      yAxis: getAxis(S.yAxis, e.yAxis, {
        titleColor: C.yAxisTitleColor,
        labelColor: C.yAxisLabelColor,
        tickColor: C.yAxisTickColor,
        axisLineColor: C.yAxisLineColor
      }, w)
    };
  }
  calculateVerticalSpace() {
    let e = this.chartConfig.width, S = this.chartConfig.height, C = 0, w = 0, T = Math.floor(e * this.chartConfig.plotReservedSpacePercent / 100), E = Math.floor(S * this.chartConfig.plotReservedSpacePercent / 100), D = this.componentStore.plot.calculateSpace({
      width: T,
      height: E
    });
    e -= D.width, S -= D.height, D = this.componentStore.title.calculateSpace({
      width: this.chartConfig.width,
      height: S
    }), w = D.height, S -= D.height, this.componentStore.xAxis.setAxisPosition("bottom"), D = this.componentStore.xAxis.calculateSpace({
      width: e,
      height: S
    }), S -= D.height, this.componentStore.yAxis.setAxisPosition("left"), D = this.componentStore.yAxis.calculateSpace({
      width: e,
      height: S
    }), C = D.width, e -= D.width, e > 0 && (T += e, e = 0), S > 0 && (E += S, S = 0), this.componentStore.plot.calculateSpace({
      width: T,
      height: E
    }), this.componentStore.plot.setBoundingBoxXY({
      x: C,
      y: w
    }), this.componentStore.xAxis.setRange([C, C + T]), this.componentStore.xAxis.setBoundingBoxXY({
      x: C,
      y: w + E
    }), this.componentStore.yAxis.setRange([w, w + E]), this.componentStore.yAxis.setBoundingBoxXY({
      x: 0,
      y: w
    }), this.chartData.plots.some((e2) => isBarPlot(e2)) && this.componentStore.xAxis.recalculateOuterPaddingToDrawBar();
  }
  calculateHorizontalSpace() {
    let e = this.chartConfig.width, S = this.chartConfig.height, C = 0, w = 0, T = 0, E = Math.floor(e * this.chartConfig.plotReservedSpacePercent / 100), D = Math.floor(S * this.chartConfig.plotReservedSpacePercent / 100), O = this.componentStore.plot.calculateSpace({
      width: E,
      height: D
    });
    e -= O.width, S -= O.height, O = this.componentStore.title.calculateSpace({
      width: this.chartConfig.width,
      height: S
    }), C = O.height, S -= O.height, this.componentStore.xAxis.setAxisPosition("left"), O = this.componentStore.xAxis.calculateSpace({
      width: e,
      height: S
    }), e -= O.width, w = O.width, this.componentStore.yAxis.setAxisPosition("top"), O = this.componentStore.yAxis.calculateSpace({
      width: e,
      height: S
    }), S -= O.height, T = C + O.height, e > 0 && (E += e, e = 0), S > 0 && (D += S, S = 0), this.componentStore.plot.calculateSpace({
      width: E,
      height: D
    }), this.componentStore.plot.setBoundingBoxXY({
      x: w,
      y: T
    }), this.componentStore.yAxis.setRange([w, w + E]), this.componentStore.yAxis.setBoundingBoxXY({
      x: w,
      y: C
    }), this.componentStore.xAxis.setRange([T, T + D]), this.componentStore.xAxis.setBoundingBoxXY({
      x: 0,
      y: T
    }), this.chartData.plots.some((e2) => isBarPlot(e2)) && this.componentStore.xAxis.recalculateOuterPaddingToDrawBar();
  }
  calculateSpace() {
    this.chartConfig.chartOrientation === "horizontal" ? this.calculateHorizontalSpace() : this.calculateVerticalSpace();
  }
  getDrawableElement() {
    this.calculateSpace();
    let e = [];
    this.componentStore.plot.setAxes(this.componentStore.xAxis, this.componentStore.yAxis);
    for (let S of Object.values(this.componentStore)) e.push(...S.getDrawableElements());
    return e;
  }
}, __name(_i, "Orchestrator"), _i), XYChartBuilder = (_j = class {
  static build(e, S, C, w) {
    return new Orchestrator(e, S, C, w).getDrawableElement();
  }
}, __name(_j, "XYChartBuilder"), _j), plotIndex = 0, tmpSVGGroup, xyChartConfig = getChartDefaultConfig(), xyChartThemeConfig = getChartDefaultThemeConfig(), xyChartData = getChartDefaultData(), plotColorPalette = xyChartThemeConfig.plotColorPalette.split(",").map((e) => e.trim()), hasSetXAxis = false, hasSetYAxis = false;
function getChartDefaultThemeConfig() {
  let e = getThemeVariables3(), S = getConfig();
  return cleanAndMerge(e.xyChart, S.themeVariables.xyChart);
}
__name(getChartDefaultThemeConfig, "getChartDefaultThemeConfig");
function getChartDefaultConfig() {
  let e = getConfig();
  return cleanAndMerge(defaultConfig_default.xyChart, e.xyChart);
}
__name(getChartDefaultConfig, "getChartDefaultConfig");
function getChartDefaultData() {
  return {
    yAxis: {
      type: "linear",
      title: "",
      min: Infinity,
      max: -Infinity
    },
    xAxis: {
      type: "band",
      title: "",
      categories: []
    },
    title: "",
    plots: []
  };
}
__name(getChartDefaultData, "getChartDefaultData");
function textSanitizer(e) {
  let S = getConfig();
  return sanitizeText(e.trim(), S);
}
__name(textSanitizer, "textSanitizer");
function setTmpSVGG(e) {
  tmpSVGGroup = e;
}
__name(setTmpSVGG, "setTmpSVGG");
function setOrientation(e) {
  e === "horizontal" ? xyChartConfig.chartOrientation = "horizontal" : xyChartConfig.chartOrientation = "vertical";
}
__name(setOrientation, "setOrientation");
function setXAxisTitle(e) {
  xyChartData.xAxis.title = textSanitizer(e.text);
}
__name(setXAxisTitle, "setXAxisTitle");
function setXAxisRangeData(e, S) {
  xyChartData.xAxis = {
    type: "linear",
    title: xyChartData.xAxis.title,
    min: e,
    max: S
  }, hasSetXAxis = true;
}
__name(setXAxisRangeData, "setXAxisRangeData");
function setXAxisBand(e) {
  xyChartData.xAxis = {
    type: "band",
    title: xyChartData.xAxis.title,
    categories: e.map((e2) => textSanitizer(e2.text))
  }, hasSetXAxis = true;
}
__name(setXAxisBand, "setXAxisBand");
function setYAxisTitle(e) {
  xyChartData.yAxis.title = textSanitizer(e.text);
}
__name(setYAxisTitle, "setYAxisTitle");
function setYAxisRangeData(e, S) {
  xyChartData.yAxis = {
    type: "linear",
    title: xyChartData.yAxis.title,
    min: e,
    max: S
  }, hasSetYAxis = true;
}
__name(setYAxisRangeData, "setYAxisRangeData");
function setYAxisRangeFromPlotData(e) {
  let S = Math.min(...e), C = Math.max(...e), w = isLinearAxisData(xyChartData.yAxis) ? xyChartData.yAxis.min : Infinity, T = isLinearAxisData(xyChartData.yAxis) ? xyChartData.yAxis.max : -Infinity;
  xyChartData.yAxis = {
    type: "linear",
    title: xyChartData.yAxis.title,
    min: Math.min(w, S),
    max: Math.max(T, C)
  };
}
__name(setYAxisRangeFromPlotData, "setYAxisRangeFromPlotData");
function transformDataWithoutCategory(e) {
  let S = [];
  if (e.length === 0) return S;
  if (!hasSetXAxis) {
    let S2 = isLinearAxisData(xyChartData.xAxis) ? xyChartData.xAxis.min : Infinity, C = isLinearAxisData(xyChartData.xAxis) ? xyChartData.xAxis.max : -Infinity;
    setXAxisRangeData(Math.min(S2, 1), Math.max(C, e.length));
  }
  if (hasSetYAxis || setYAxisRangeFromPlotData(e), isBandAxisData(xyChartData.xAxis) && (S = xyChartData.xAxis.categories.map((S2, C) => [S2, e[C]])), isLinearAxisData(xyChartData.xAxis)) {
    let C = xyChartData.xAxis.min, w = xyChartData.xAxis.max, T = (w - C) / (e.length - 1), E = [];
    for (let e2 = C; e2 <= w; e2 += T) E.push(`${e2}`);
    S = E.map((S2, C2) => [S2, e[C2]]);
  }
  return S;
}
__name(transformDataWithoutCategory, "transformDataWithoutCategory");
function getPlotColorFromPalette(e) {
  return plotColorPalette[e === 0 ? 0 : e % plotColorPalette.length];
}
__name(getPlotColorFromPalette, "getPlotColorFromPalette");
function setLineData(e, S) {
  let C = transformDataWithoutCategory(S);
  xyChartData.plots.push({
    type: "line",
    strokeFill: getPlotColorFromPalette(plotIndex),
    strokeWidth: 2,
    data: C
  }), plotIndex++;
}
__name(setLineData, "setLineData");
function setBarData(e, S) {
  let C = transformDataWithoutCategory(S);
  xyChartData.plots.push({
    type: "bar",
    fill: getPlotColorFromPalette(plotIndex),
    data: C
  }), plotIndex++;
}
__name(setBarData, "setBarData");
function getDrawableElem() {
  if (xyChartData.plots.length === 0) throw Error("No Plot to render, please provide a plot with some data");
  return xyChartData.title = getDiagramTitle(), XYChartBuilder.build(xyChartConfig, xyChartData, xyChartThemeConfig, tmpSVGGroup);
}
__name(getDrawableElem, "getDrawableElem");
function getChartThemeConfig() {
  return xyChartThemeConfig;
}
__name(getChartThemeConfig, "getChartThemeConfig");
function getChartConfig() {
  return xyChartConfig;
}
__name(getChartConfig, "getChartConfig");
function getXYChartData() {
  return xyChartData;
}
__name(getXYChartData, "getXYChartData");
var diagram = {
  parser: xychart_default,
  db: {
    getDrawableElem,
    clear: /* @__PURE__ */ __name(function() {
      clear(), plotIndex = 0, xyChartConfig = getChartDefaultConfig(), xyChartData = getChartDefaultData(), xyChartThemeConfig = getChartDefaultThemeConfig(), plotColorPalette = xyChartThemeConfig.plotColorPalette.split(",").map((e) => e.trim()), hasSetXAxis = false, hasSetYAxis = false;
    }, "clear"),
    setAccTitle,
    getAccTitle,
    setDiagramTitle,
    getDiagramTitle,
    getAccDescription,
    setAccDescription,
    setOrientation,
    setXAxisTitle,
    setXAxisRangeData,
    setXAxisBand,
    setYAxisTitle,
    setYAxisRangeData,
    setLineData,
    setBarData,
    setTmpSVGG,
    getChartThemeConfig,
    getChartConfig,
    getXYChartData
  },
  renderer: { draw: /* @__PURE__ */ __name((e, S, C, w) => {
    let T = w.db, E = T.getChartThemeConfig(), k = T.getChartConfig(), A = T.getXYChartData().plots[0].data.map((e2) => e2[1]);
    function j(e2) {
      return e2 === "top" ? "text-before-edge" : "middle";
    }
    __name(j, "getDominantBaseLine");
    function M(e2) {
      return e2 === "left" ? "start" : e2 === "right" ? "end" : "middle";
    }
    __name(M, "getTextAnchor");
    function N(e2) {
      return `translate(${e2.x}, ${e2.y}) rotate(${e2.rotation || 0})`;
    }
    __name(N, "getTextTransformation"), log.debug("Rendering xychart chart\n" + e);
    let P = selectSvgElement(S), F = P.append("g").attr("class", "main"), L = F.append("rect").attr("width", k.width).attr("height", k.height).attr("class", "background");
    configureSvgSize(P, k.height, k.width, true), P.attr("viewBox", `0 0 ${k.width} ${k.height}`), L.attr("fill", E.backgroundColor), T.setTmpSVGG(P.append("g").attr("class", "mermaid-tmp-group"));
    let R = T.getDrawableElem(), z = {};
    function B(e2) {
      let S2 = F, C2 = "";
      for (let [w2] of e2.entries()) {
        let T2 = F;
        w2 > 0 && z[C2] && (T2 = z[C2]), C2 += e2[w2], S2 = z[C2], S2 || (S2 = z[C2] = T2.append("g").attr("class", e2[w2]));
      }
      return S2;
    }
    __name(B, "getGroup");
    for (let e2 of R) {
      if (e2.data.length === 0) continue;
      let S2 = B(e2.groupTexts);
      switch (e2.type) {
        case "rect":
          if (S2.selectAll("rect").data(e2.data).enter().append("rect").attr("x", (e3) => e3.x).attr("y", (e3) => e3.y).attr("width", (e3) => e3.width).attr("height", (e3) => e3.height).attr("fill", (e3) => e3.fill).attr("stroke", (e3) => e3.strokeFill).attr("stroke-width", (e3) => e3.strokeWidth), k.showDataLabel) if (k.chartOrientation === "horizontal") {
            let C2 = function(e3, S3) {
              let { data: C3, label: T3 } = e3;
              return S3 * T3.length * w2 <= C3.width - 10;
            };
            __name(C2, "fitsHorizontally");
            let w2 = 0.7, T2 = e2.data.map((e3, S3) => ({
              data: e3,
              label: A[S3].toString()
            })).filter((e3) => e3.data.width > 0 && e3.data.height > 0), E2 = T2.map((e3) => {
              let { data: S3 } = e3, w3 = S3.height * 0.7;
              for (; !C2(e3, w3) && w3 > 0; ) --w3;
              return w3;
            }), D = Math.floor(Math.min(...E2));
            S2.selectAll("text").data(T2).enter().append("text").attr("x", (e3) => e3.data.x + e3.data.width - 10).attr("y", (e3) => e3.data.y + e3.data.height / 2).attr("text-anchor", "end").attr("dominant-baseline", "middle").attr("fill", "black").attr("font-size", `${D}px`).text((e3) => e3.label);
          } else {
            let C2 = function(e3, S3, C3) {
              let { data: w3, label: T3 } = e3, E3 = S3 * T3.length * 0.7, D = w3.x + w3.width / 2, O = D - E3 / 2, k2 = D + E3 / 2, A2 = O >= w3.x && k2 <= w3.x + w3.width, j2 = w3.y + C3 + S3 <= w3.y + w3.height;
              return A2 && j2;
            };
            __name(C2, "fitsInBar");
            let w2 = e2.data.map((e3, S3) => ({
              data: e3,
              label: A[S3].toString()
            })).filter((e3) => e3.data.width > 0 && e3.data.height > 0), T2 = w2.map((e3) => {
              let { data: S3, label: w3 } = e3, T3 = S3.width / (w3.length * 0.7);
              for (; !C2(e3, T3, 10) && T3 > 0; ) --T3;
              return T3;
            }), E2 = Math.floor(Math.min(...T2));
            S2.selectAll("text").data(w2).enter().append("text").attr("x", (e3) => e3.data.x + e3.data.width / 2).attr("y", (e3) => e3.data.y + 10).attr("text-anchor", "middle").attr("dominant-baseline", "hanging").attr("fill", "black").attr("font-size", `${E2}px`).text((e3) => e3.label);
          }
          break;
        case "text":
          S2.selectAll("text").data(e2.data).enter().append("text").attr("x", 0).attr("y", 0).attr("fill", (e3) => e3.fill).attr("font-size", (e3) => e3.fontSize).attr("dominant-baseline", (e3) => j(e3.verticalPos)).attr("text-anchor", (e3) => M(e3.horizontalPos)).attr("transform", (e3) => N(e3)).text((e3) => e3.text);
          break;
        case "path":
          S2.selectAll("path").data(e2.data).enter().append("path").attr("d", (e3) => e3.path).attr("fill", (e3) => e3.fill ? e3.fill : "none").attr("stroke", (e3) => e3.strokeFill).attr("stroke-width", (e3) => e3.strokeWidth);
          break;
      }
    }
  }, "draw") }
};
export {
  diagram
};
