UNPKG

65.6 kBJavaScriptView Raw
1import { l as log, s as setAccTitle, g as getAccTitle, q as setDiagramTitle, t as getDiagramTitle, a as getAccDescription, b as setAccDescription, E as getThemeVariables, F as getConfig, C as cleanAndMerge, B as defaultConfig, v as clear$1, d as sanitizeText, A as selectSvgElement, i as configureSvgSize } from "./mermaid-6dc72991.js";
2import { c as computeDimensionOfText } from "./createText-ca0c5216.js";
3import { scaleBand, scaleLinear, line } from "d3";
4import "ts-dedent";
5import "dayjs";
6import "@braintree/sanitize-url";
7import "dompurify";
8import "khroma";
9import "lodash-es/memoize.js";
10import "lodash-es/merge.js";
11import "stylis";
12import "lodash-es/isEmpty.js";
13import "mdast-util-from-markdown";
14var parser = function() {
15 var o = function(k, v, o2, l) {
16 for (o2 = o2 || {}, l = k.length; l--; o2[k[l]] = v)
17 ;
18 return o2;
19 }, $V0 = [1, 10, 12, 14, 16, 18, 19, 21, 23], $V1 = [2, 6], $V2 = [1, 3], $V3 = [1, 5], $V4 = [1, 6], $V5 = [1, 7], $V6 = [1, 5, 10, 12, 14, 16, 18, 19, 21, 23, 34, 35, 36], $V7 = [1, 25], $V8 = [1, 26], $V9 = [1, 28], $Va = [1, 29], $Vb = [1, 30], $Vc = [1, 31], $Vd = [1, 32], $Ve = [1, 33], $Vf = [1, 34], $Vg = [1, 35], $Vh = [1, 36], $Vi = [1, 37], $Vj = [1, 43], $Vk = [1, 42], $Vl = [1, 47], $Vm = [1, 50], $Vn = [1, 10, 12, 14, 16, 18, 19, 21, 23, 34, 35, 36], $Vo = [1, 10, 12, 14, 16, 18, 19, 21, 23, 24, 26, 27, 28, 34, 35, 36], $Vp = [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], $Vq = [1, 64];
20 var parser2 = {
21 trace: function trace() {
22 },
23 yy: {},
24 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 },
25 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" },
26 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]],
27 performAction: function anonymous(yytext, yyleng, yylineno, yy, yystate, $$, _$) {
28 var $0 = $$.length - 1;
29 switch (yystate) {
30 case 5:
31 yy.setOrientation($$[$0]);
32 break;
33 case 9:
34 yy.setDiagramTitle($$[$0].text.trim());
35 break;
36 case 12:
37 yy.setLineData({ text: "", type: "text" }, $$[$0]);
38 break;
39 case 13:
40 yy.setLineData($$[$0 - 1], $$[$0]);
41 break;
42 case 14:
43 yy.setBarData({ text: "", type: "text" }, $$[$0]);
44 break;
45 case 15:
46 yy.setBarData($$[$0 - 1], $$[$0]);
47 break;
48 case 16:
49 this.$ = $$[$0].trim();
50 yy.setAccTitle(this.$);
51 break;
52 case 17:
53 case 18:
54 this.$ = $$[$0].trim();
55 yy.setAccDescription(this.$);
56 break;
57 case 19:
58 this.$ = $$[$0 - 1];
59 break;
60 case 20:
61 this.$ = [Number($$[$0 - 2]), ...$$[$0]];
62 break;
63 case 21:
64 this.$ = [Number($$[$0])];
65 break;
66 case 22:
67 yy.setXAxisTitle($$[$0]);
68 break;
69 case 23:
70 yy.setXAxisTitle($$[$0 - 1]);
71 break;
72 case 24:
73 yy.setXAxisTitle({ type: "text", text: "" });
74 break;
75 case 25:
76 yy.setXAxisBand($$[$0]);
77 break;
78 case 26:
79 yy.setXAxisRangeData(Number($$[$0 - 2]), Number($$[$0]));
80 break;
81 case 27:
82 this.$ = $$[$0 - 1];
83 break;
84 case 28:
85 this.$ = [$$[$0 - 2], ...$$[$0]];
86 break;
87 case 29:
88 this.$ = [$$[$0]];
89 break;
90 case 30:
91 yy.setYAxisTitle($$[$0]);
92 break;
93 case 31:
94 yy.setYAxisTitle($$[$0 - 1]);
95 break;
96 case 32:
97 yy.setYAxisTitle({ type: "text", text: "" });
98 break;
99 case 33:
100 yy.setYAxisRangeData(Number($$[$0 - 2]), Number($$[$0]));
101 break;
102 case 37:
103 this.$ = { text: $$[$0], type: "text" };
104 break;
105 case 38:
106 this.$ = { text: $$[$0], type: "text" };
107 break;
108 case 39:
109 this.$ = { text: $$[$0], type: "markdown" };
110 break;
111 case 40:
112 this.$ = $$[$0];
113 break;
114 case 41:
115 this.$ = $$[$0 - 1] + "" + $$[$0];
116 break;
117 }
118 },
119 table: [o($V0, $V1, { 3: 1, 4: 2, 7: 4, 5: $V2, 34: $V3, 35: $V4, 36: $V5 }), { 1: [3] }, o($V0, $V1, { 4: 2, 7: 4, 3: 8, 5: $V2, 34: $V3, 35: $V4, 36: $V5 }), o($V0, $V1, { 4: 2, 7: 4, 6: 9, 3: 10, 5: $V2, 8: [1, 11], 34: $V3, 35: $V4, 36: $V5 }), { 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] }, o($V6, [2, 34]), o($V6, [2, 35]), o($V6, [2, 36]), { 1: [2, 1] }, o($V0, $V1, { 4: 2, 7: 4, 3: 21, 5: $V2, 34: $V3, 35: $V4, 36: $V5 }), { 1: [2, 3] }, o($V6, [2, 5]), o($V0, [2, 7], { 4: 22, 34: $V3, 35: $V4, 36: $V5 }), { 11: 23, 37: 24, 38: $V7, 39: $V8, 40: 27, 41: $V9, 42: $Va, 43: $Vb, 44: $Vc, 45: $Vd, 46: $Ve, 47: $Vf, 48: $Vg, 49: $Vh, 50: $Vi }, { 11: 39, 13: 38, 24: $Vj, 27: $Vk, 29: 40, 30: 41, 37: 24, 38: $V7, 39: $V8, 40: 27, 41: $V9, 42: $Va, 43: $Vb, 44: $Vc, 45: $Vd, 46: $Ve, 47: $Vf, 48: $Vg, 49: $Vh, 50: $Vi }, { 11: 45, 15: 44, 27: $Vl, 33: 46, 37: 24, 38: $V7, 39: $V8, 40: 27, 41: $V9, 42: $Va, 43: $Vb, 44: $Vc, 45: $Vd, 46: $Ve, 47: $Vf, 48: $Vg, 49: $Vh, 50: $Vi }, { 11: 49, 17: 48, 24: $Vm, 37: 24, 38: $V7, 39: $V8, 40: 27, 41: $V9, 42: $Va, 43: $Vb, 44: $Vc, 45: $Vd, 46: $Ve, 47: $Vf, 48: $Vg, 49: $Vh, 50: $Vi }, { 11: 52, 17: 51, 24: $Vm, 37: 24, 38: $V7, 39: $V8, 40: 27, 41: $V9, 42: $Va, 43: $Vb, 44: $Vc, 45: $Vd, 46: $Ve, 47: $Vf, 48: $Vg, 49: $Vh, 50: $Vi }, { 20: [1, 53] }, { 22: [1, 54] }, o($Vn, [2, 18]), { 1: [2, 2] }, o($Vn, [2, 8]), o($Vn, [2, 9]), o($Vo, [2, 37], { 40: 55, 41: $V9, 42: $Va, 43: $Vb, 44: $Vc, 45: $Vd, 46: $Ve, 47: $Vf, 48: $Vg, 49: $Vh, 50: $Vi }), o($Vo, [2, 38]), o($Vo, [2, 39]), o($Vp, [2, 40]), o($Vp, [2, 42]), o($Vp, [2, 43]), o($Vp, [2, 44]), o($Vp, [2, 45]), o($Vp, [2, 46]), o($Vp, [2, 47]), o($Vp, [2, 48]), o($Vp, [2, 49]), o($Vp, [2, 50]), o($Vp, [2, 51]), o($Vn, [2, 10]), o($Vn, [2, 22], { 30: 41, 29: 56, 24: $Vj, 27: $Vk }), o($Vn, [2, 24]), o($Vn, [2, 25]), { 31: [1, 57] }, { 11: 59, 32: 58, 37: 24, 38: $V7, 39: $V8, 40: 27, 41: $V9, 42: $Va, 43: $Vb, 44: $Vc, 45: $Vd, 46: $Ve, 47: $Vf, 48: $Vg, 49: $Vh, 50: $Vi }, o($Vn, [2, 11]), o($Vn, [2, 30], { 33: 60, 27: $Vl }), o($Vn, [2, 32]), { 31: [1, 61] }, o($Vn, [2, 12]), { 17: 62, 24: $Vm }, { 25: 63, 27: $Vq }, o($Vn, [2, 14]), { 17: 65, 24: $Vm }, o($Vn, [2, 16]), o($Vn, [2, 17]), o($Vp, [2, 41]), o($Vn, [2, 23]), { 27: [1, 66] }, { 26: [1, 67] }, { 26: [2, 29], 28: [1, 68] }, o($Vn, [2, 31]), { 27: [1, 69] }, o($Vn, [2, 13]), { 26: [1, 70] }, { 26: [2, 21], 28: [1, 71] }, o($Vn, [2, 15]), o($Vn, [2, 26]), o($Vn, [2, 27]), { 11: 59, 32: 72, 37: 24, 38: $V7, 39: $V8, 40: 27, 41: $V9, 42: $Va, 43: $Vb, 44: $Vc, 45: $Vd, 46: $Ve, 47: $Vf, 48: $Vg, 49: $Vh, 50: $Vi }, o($Vn, [2, 33]), o($Vn, [2, 19]), { 25: 73, 27: $Vq }, { 26: [2, 28] }, { 26: [2, 20] }],
120 defaultActions: { 8: [2, 1], 10: [2, 3], 21: [2, 2], 72: [2, 28], 73: [2, 20] },
121 parseError: function parseError(str, hash) {
122 if (hash.recoverable) {
123 this.trace(str);
124 } else {
125 var error = new Error(str);
126 error.hash = hash;
127 throw error;
128 }
129 },
130 parse: function parse(input) {
131 var self = this, stack = [0], tstack = [], vstack = [null], lstack = [], table = this.table, yytext = "", yylineno = 0, yyleng = 0, TERROR = 2, EOF = 1;
132 var args = lstack.slice.call(arguments, 1);
133 var lexer2 = Object.create(this.lexer);
134 var sharedState = { yy: {} };
135 for (var k in this.yy) {
136 if (Object.prototype.hasOwnProperty.call(this.yy, k)) {
137 sharedState.yy[k] = this.yy[k];
138 }
139 }
140 lexer2.setInput(input, sharedState.yy);
141 sharedState.yy.lexer = lexer2;
142 sharedState.yy.parser = this;
143 if (typeof lexer2.yylloc == "undefined") {
144 lexer2.yylloc = {};
145 }
146 var yyloc = lexer2.yylloc;
147 lstack.push(yyloc);
148 var ranges = lexer2.options && lexer2.options.ranges;
149 if (typeof sharedState.yy.parseError === "function") {
150 this.parseError = sharedState.yy.parseError;
151 } else {
152 this.parseError = Object.getPrototypeOf(this).parseError;
153 }
154 function lex() {
155 var token;
156 token = tstack.pop() || lexer2.lex() || EOF;
157 if (typeof token !== "number") {
158 if (token instanceof Array) {
159 tstack = token;
160 token = tstack.pop();
161 }
162 token = self.symbols_[token] || token;
163 }
164 return token;
165 }
166 var symbol, state, action, r, yyval = {}, p, len, newState, expected;
167 while (true) {
168 state = stack[stack.length - 1];
169 if (this.defaultActions[state]) {
170 action = this.defaultActions[state];
171 } else {
172 if (symbol === null || typeof symbol == "undefined") {
173 symbol = lex();
174 }
175 action = table[state] && table[state][symbol];
176 }
177 if (typeof action === "undefined" || !action.length || !action[0]) {
178 var errStr = "";
179 expected = [];
180 for (p in table[state]) {
181 if (this.terminals_[p] && p > TERROR) {
182 expected.push("'" + this.terminals_[p] + "'");
183 }
184 }
185 if (lexer2.showPosition) {
186 errStr = "Parse error on line " + (yylineno + 1) + ":\n" + lexer2.showPosition() + "\nExpecting " + expected.join(", ") + ", got '" + (this.terminals_[symbol] || symbol) + "'";
187 } else {
188 errStr = "Parse error on line " + (yylineno + 1) + ": Unexpected " + (symbol == EOF ? "end of input" : "'" + (this.terminals_[symbol] || symbol) + "'");
189 }
190 this.parseError(errStr, {
191 text: lexer2.match,
192 token: this.terminals_[symbol] || symbol,
193 line: lexer2.yylineno,
194 loc: yyloc,
195 expected
196 });
197 }
198 if (action[0] instanceof Array && action.length > 1) {
199 throw new Error("Parse Error: multiple actions possible at state: " + state + ", token: " + symbol);
200 }
201 switch (action[0]) {
202 case 1:
203 stack.push(symbol);
204 vstack.push(lexer2.yytext);
205 lstack.push(lexer2.yylloc);
206 stack.push(action[1]);
207 symbol = null;
208 {
209 yyleng = lexer2.yyleng;
210 yytext = lexer2.yytext;
211 yylineno = lexer2.yylineno;
212 yyloc = lexer2.yylloc;
213 }
214 break;
215 case 2:
216 len = this.productions_[action[1]][1];
217 yyval.$ = vstack[vstack.length - len];
218 yyval._$ = {
219 first_line: lstack[lstack.length - (len || 1)].first_line,
220 last_line: lstack[lstack.length - 1].last_line,
221 first_column: lstack[lstack.length - (len || 1)].first_column,
222 last_column: lstack[lstack.length - 1].last_column
223 };
224 if (ranges) {
225 yyval._$.range = [
226 lstack[lstack.length - (len || 1)].range[0],
227 lstack[lstack.length - 1].range[1]
228 ];
229 }
230 r = this.performAction.apply(yyval, [
231 yytext,
232 yyleng,
233 yylineno,
234 sharedState.yy,
235 action[1],
236 vstack,
237 lstack
238 ].concat(args));
239 if (typeof r !== "undefined") {
240 return r;
241 }
242 if (len) {
243 stack = stack.slice(0, -1 * len * 2);
244 vstack = vstack.slice(0, -1 * len);
245 lstack = lstack.slice(0, -1 * len);
246 }
247 stack.push(this.productions_[action[1]][0]);
248 vstack.push(yyval.$);
249 lstack.push(yyval._$);
250 newState = table[stack[stack.length - 2]][stack[stack.length - 1]];
251 stack.push(newState);
252 break;
253 case 3:
254 return true;
255 }
256 }
257 return true;
258 }
259 };
260 var lexer = function() {
261 var lexer2 = {
262 EOF: 1,
263 parseError: function parseError(str, hash) {
264 if (this.yy.parser) {
265 this.yy.parser.parseError(str, hash);
266 } else {
267 throw new Error(str);
268 }
269 },
270 // resets the lexer, sets new input
271 setInput: function(input, yy) {
272 this.yy = yy || this.yy || {};
273 this._input = input;
274 this._more = this._backtrack = this.done = false;
275 this.yylineno = this.yyleng = 0;
276 this.yytext = this.matched = this.match = "";
277 this.conditionStack = ["INITIAL"];
278 this.yylloc = {
279 first_line: 1,
280 first_column: 0,
281 last_line: 1,
282 last_column: 0
283 };
284 if (this.options.ranges) {
285 this.yylloc.range = [0, 0];
286 }
287 this.offset = 0;
288 return this;
289 },
290 // consumes and returns one char from the input
291 input: function() {
292 var ch = this._input[0];
293 this.yytext += ch;
294 this.yyleng++;
295 this.offset++;
296 this.match += ch;
297 this.matched += ch;
298 var lines = ch.match(/(?:\r\n?|\n).*/g);
299 if (lines) {
300 this.yylineno++;
301 this.yylloc.last_line++;
302 } else {
303 this.yylloc.last_column++;
304 }
305 if (this.options.ranges) {
306 this.yylloc.range[1]++;
307 }
308 this._input = this._input.slice(1);
309 return ch;
310 },
311 // unshifts one char (or a string) into the input
312 unput: function(ch) {
313 var len = ch.length;
314 var lines = ch.split(/(?:\r\n?|\n)/g);
315 this._input = ch + this._input;
316 this.yytext = this.yytext.substr(0, this.yytext.length - len);
317 this.offset -= len;
318 var oldLines = this.match.split(/(?:\r\n?|\n)/g);
319 this.match = this.match.substr(0, this.match.length - 1);
320 this.matched = this.matched.substr(0, this.matched.length - 1);
321 if (lines.length - 1) {
322 this.yylineno -= lines.length - 1;
323 }
324 var r = this.yylloc.range;
325 this.yylloc = {
326 first_line: this.yylloc.first_line,
327 last_line: this.yylineno + 1,
328 first_column: this.yylloc.first_column,
329 last_column: lines ? (lines.length === oldLines.length ? this.yylloc.first_column : 0) + oldLines[oldLines.length - lines.length].length - lines[0].length : this.yylloc.first_column - len
330 };
331 if (this.options.ranges) {
332 this.yylloc.range = [r[0], r[0] + this.yyleng - len];
333 }
334 this.yyleng = this.yytext.length;
335 return this;
336 },
337 // When called from action, caches matched text and appends it on next action
338 more: function() {
339 this._more = true;
340 return this;
341 },
342 // When called from action, signals the lexer that this rule fails to match the input, so the next matching rule (regex) should be tested instead.
343 reject: function() {
344 if (this.options.backtrack_lexer) {
345 this._backtrack = true;
346 } else {
347 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(), {
348 text: "",
349 token: null,
350 line: this.yylineno
351 });
352 }
353 return this;
354 },
355 // retain first n characters of the match
356 less: function(n) {
357 this.unput(this.match.slice(n));
358 },
359 // displays already matched input, i.e. for error messages
360 pastInput: function() {
361 var past = this.matched.substr(0, this.matched.length - this.match.length);
362 return (past.length > 20 ? "..." : "") + past.substr(-20).replace(/\n/g, "");
363 },
364 // displays upcoming input, i.e. for error messages
365 upcomingInput: function() {
366 var next = this.match;
367 if (next.length < 20) {
368 next += this._input.substr(0, 20 - next.length);
369 }
370 return (next.substr(0, 20) + (next.length > 20 ? "..." : "")).replace(/\n/g, "");
371 },
372 // displays the character position where the lexing error occurred, i.e. for error messages
373 showPosition: function() {
374 var pre = this.pastInput();
375 var c = new Array(pre.length + 1).join("-");
376 return pre + this.upcomingInput() + "\n" + c + "^";
377 },
378 // test the lexed token: return FALSE when not a match, otherwise return token
379 test_match: function(match, indexed_rule) {
380 var token, lines, backup;
381 if (this.options.backtrack_lexer) {
382 backup = {
383 yylineno: this.yylineno,
384 yylloc: {
385 first_line: this.yylloc.first_line,
386 last_line: this.last_line,
387 first_column: this.yylloc.first_column,
388 last_column: this.yylloc.last_column
389 },
390 yytext: this.yytext,
391 match: this.match,
392 matches: this.matches,
393 matched: this.matched,
394 yyleng: this.yyleng,
395 offset: this.offset,
396 _more: this._more,
397 _input: this._input,
398 yy: this.yy,
399 conditionStack: this.conditionStack.slice(0),
400 done: this.done
401 };
402 if (this.options.ranges) {
403 backup.yylloc.range = this.yylloc.range.slice(0);
404 }
405 }
406 lines = match[0].match(/(?:\r\n?|\n).*/g);
407 if (lines) {
408 this.yylineno += lines.length;
409 }
410 this.yylloc = {
411 first_line: this.yylloc.last_line,
412 last_line: this.yylineno + 1,
413 first_column: this.yylloc.last_column,
414 last_column: lines ? lines[lines.length - 1].length - lines[lines.length - 1].match(/\r?\n?/)[0].length : this.yylloc.last_column + match[0].length
415 };
416 this.yytext += match[0];
417 this.match += match[0];
418 this.matches = match;
419 this.yyleng = this.yytext.length;
420 if (this.options.ranges) {
421 this.yylloc.range = [this.offset, this.offset += this.yyleng];
422 }
423 this._more = false;
424 this._backtrack = false;
425 this._input = this._input.slice(match[0].length);
426 this.matched += match[0];
427 token = this.performAction.call(this, this.yy, this, indexed_rule, this.conditionStack[this.conditionStack.length - 1]);
428 if (this.done && this._input) {
429 this.done = false;
430 }
431 if (token) {
432 return token;
433 } else if (this._backtrack) {
434 for (var k in backup) {
435 this[k] = backup[k];
436 }
437 return false;
438 }
439 return false;
440 },
441 // return next match in input
442 next: function() {
443 if (this.done) {
444 return this.EOF;
445 }
446 if (!this._input) {
447 this.done = true;
448 }
449 var token, match, tempMatch, index;
450 if (!this._more) {
451 this.yytext = "";
452 this.match = "";
453 }
454 var rules = this._currentRules();
455 for (var i = 0; i < rules.length; i++) {
456 tempMatch = this._input.match(this.rules[rules[i]]);
457 if (tempMatch && (!match || tempMatch[0].length > match[0].length)) {
458 match = tempMatch;
459 index = i;
460 if (this.options.backtrack_lexer) {
461 token = this.test_match(tempMatch, rules[i]);
462 if (token !== false) {
463 return token;
464 } else if (this._backtrack) {
465 match = false;
466 continue;
467 } else {
468 return false;
469 }
470 } else if (!this.options.flex) {
471 break;
472 }
473 }
474 }
475 if (match) {
476 token = this.test_match(match, rules[index]);
477 if (token !== false) {
478 return token;
479 }
480 return false;
481 }
482 if (this._input === "") {
483 return this.EOF;
484 } else {
485 return this.parseError("Lexical error on line " + (this.yylineno + 1) + ". Unrecognized text.\n" + this.showPosition(), {
486 text: "",
487 token: null,
488 line: this.yylineno
489 });
490 }
491 },
492 // return next match that has a token
493 lex: function lex() {
494 var r = this.next();
495 if (r) {
496 return r;
497 } else {
498 return this.lex();
499 }
500 },
501 // activates a new lexer condition state (pushes the new lexer condition state onto the condition stack)
502 begin: function begin(condition) {
503 this.conditionStack.push(condition);
504 },
505 // pop the previously active lexer condition state off the condition stack
506 popState: function popState() {
507 var n = this.conditionStack.length - 1;
508 if (n > 0) {
509 return this.conditionStack.pop();
510 } else {
511 return this.conditionStack[0];
512 }
513 },
514 // produce the lexer rule set which is active for the currently active lexer condition state
515 _currentRules: function _currentRules() {
516 if (this.conditionStack.length && this.conditionStack[this.conditionStack.length - 1]) {
517 return this.conditions[this.conditionStack[this.conditionStack.length - 1]].rules;
518 } else {
519 return this.conditions["INITIAL"].rules;
520 }
521 },
522 // return the currently active lexer condition state; when an index argument is provided it produces the N-th previous condition state, if available
523 topState: function topState(n) {
524 n = this.conditionStack.length - 1 - Math.abs(n || 0);
525 if (n >= 0) {
526 return this.conditionStack[n];
527 } else {
528 return "INITIAL";
529 }
530 },
531 // alias for begin(condition)
532 pushState: function pushState(condition) {
533 this.begin(condition);
534 },
535 // return the number of states currently on the stack
536 stateStackSize: function stateStackSize() {
537 return this.conditionStack.length;
538 },
539 options: { "case-insensitive": true },
540 performAction: function anonymous(yy, yy_, $avoiding_name_collisions, YY_START) {
541 switch ($avoiding_name_collisions) {
542 case 0:
543 break;
544 case 1:
545 break;
546 case 2:
547 this.popState();
548 return 34;
549 case 3:
550 this.popState();
551 return 34;
552 case 4:
553 return 34;
554 case 5:
555 break;
556 case 6:
557 return 10;
558 case 7:
559 this.pushState("acc_title");
560 return 19;
561 case 8:
562 this.popState();
563 return "acc_title_value";
564 case 9:
565 this.pushState("acc_descr");
566 return 21;
567 case 10:
568 this.popState();
569 return "acc_descr_value";
570 case 11:
571 this.pushState("acc_descr_multiline");
572 break;
573 case 12:
574 this.popState();
575 break;
576 case 13:
577 return "acc_descr_multiline_value";
578 case 14:
579 return 5;
580 case 15:
581 return 8;
582 case 16:
583 this.pushState("axis_data");
584 return "X_AXIS";
585 case 17:
586 this.pushState("axis_data");
587 return "Y_AXIS";
588 case 18:
589 this.pushState("axis_band_data");
590 return 24;
591 case 19:
592 return 31;
593 case 20:
594 this.pushState("data");
595 return 16;
596 case 21:
597 this.pushState("data");
598 return 18;
599 case 22:
600 this.pushState("data_inner");
601 return 24;
602 case 23:
603 return 27;
604 case 24:
605 this.popState();
606 return 26;
607 case 25:
608 this.popState();
609 break;
610 case 26:
611 this.pushState("string");
612 break;
613 case 27:
614 this.popState();
615 break;
616 case 28:
617 return "STR";
618 case 29:
619 return 24;
620 case 30:
621 return 26;
622 case 31:
623 return 43;
624 case 32:
625 return "COLON";
626 case 33:
627 return 44;
628 case 34:
629 return 28;
630 case 35:
631 return 45;
632 case 36:
633 return 46;
634 case 37:
635 return 48;
636 case 38:
637 return 50;
638 case 39:
639 return 47;
640 case 40:
641 return 41;
642 case 41:
643 return 49;
644 case 42:
645 return 42;
646 case 43:
647 break;
648 case 44:
649 return 35;
650 case 45:
651 return 36;
652 }
653 },
654 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, /^(?:(?: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],
655 conditions: { "data_inner": { "rules": [0, 1, 4, 5, 6, 7, 9, 11, 14, 15, 16, 17, 20, 21, 23, 24, 25, 26, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45], "inclusive": true }, "data": { "rules": [0, 1, 3, 4, 5, 6, 7, 9, 11, 14, 15, 16, 17, 20, 21, 22, 25, 26, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45], "inclusive": true }, "axis_band_data": { "rules": [0, 1, 4, 5, 6, 7, 9, 11, 14, 15, 16, 17, 20, 21, 24, 25, 26, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45], "inclusive": true }, "axis_data": { "rules": [0, 1, 2, 4, 5, 6, 7, 9, 11, 14, 15, 16, 17, 18, 19, 20, 21, 23, 25, 26, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45], "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": [27, 28], "inclusive": false }, "INITIAL": { "rules": [0, 1, 4, 5, 6, 7, 9, 11, 14, 15, 16, 17, 20, 21, 25, 26, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45], "inclusive": true } }
656 };
657 return lexer2;
658 }();
659 parser2.lexer = lexer;
660 function Parser() {
661 this.yy = {};
662 }
663 Parser.prototype = parser2;
664 parser2.Parser = Parser;
665 return new Parser();
666}();
667parser.parser = parser;
668const parser$1 = parser;
669function isBarPlot(data) {
670 return data.type === "bar";
671}
672function isBandAxisData(data) {
673 return data.type === "band";
674}
675function isLinearAxisData(data) {
676 return data.type === "linear";
677}
678class TextDimensionCalculatorWithFont {
679 constructor(parentGroup) {
680 this.parentGroup = parentGroup;
681 }
682 getMaxDimension(texts, fontSize) {
683 if (!this.parentGroup) {
684 return {
685 width: texts.reduce((acc, cur) => Math.max(cur.length, acc), 0) * fontSize,
686 height: fontSize
687 };
688 }
689 const dimension = {
690 width: 0,
691 height: 0
692 };
693 const elem = this.parentGroup.append("g").attr("visibility", "hidden").attr("font-size", fontSize);
694 for (const t of texts) {
695 const bbox = computeDimensionOfText(elem, 1, t);
696 const width = bbox ? bbox.width : t.length * fontSize;
697 const height = bbox ? bbox.height : fontSize;
698 dimension.width = Math.max(dimension.width, width);
699 dimension.height = Math.max(dimension.height, height);
700 }
701 elem.remove();
702 return dimension;
703 }
704}
705const BAR_WIDTH_TO_TICK_WIDTH_RATIO = 0.7;
706const MAX_OUTER_PADDING_PERCENT_FOR_WRT_LABEL = 0.2;
707class BaseAxis {
708 constructor(axisConfig, title, textDimensionCalculator, axisThemeConfig) {
709 this.axisConfig = axisConfig;
710 this.title = title;
711 this.textDimensionCalculator = textDimensionCalculator;
712 this.axisThemeConfig = axisThemeConfig;
713 this.boundingRect = { x: 0, y: 0, width: 0, height: 0 };
714 this.axisPosition = "left";
715 this.showTitle = false;
716 this.showLabel = false;
717 this.showTick = false;
718 this.showAxisLine = false;
719 this.outerPadding = 0;
720 this.titleTextHeight = 0;
721 this.labelTextHeight = 0;
722 this.range = [0, 10];
723 this.boundingRect = { x: 0, y: 0, width: 0, height: 0 };
724 this.axisPosition = "left";
725 }
726 setRange(range) {
727 this.range = range;
728 if (this.axisPosition === "left" || this.axisPosition === "right") {
729 this.boundingRect.height = range[1] - range[0];
730 } else {
731 this.boundingRect.width = range[1] - range[0];
732 }
733 this.recalculateScale();
734 }
735 getRange() {
736 return [this.range[0] + this.outerPadding, this.range[1] - this.outerPadding];
737 }
738 setAxisPosition(axisPosition) {
739 this.axisPosition = axisPosition;
740 this.setRange(this.range);
741 }
742 getTickDistance() {
743 const range = this.getRange();
744 return Math.abs(range[0] - range[1]) / this.getTickValues().length;
745 }
746 getAxisOuterPadding() {
747 return this.outerPadding;
748 }
749 getLabelDimension() {
750 return this.textDimensionCalculator.getMaxDimension(
751 this.getTickValues().map((tick) => tick.toString()),
752 this.axisConfig.labelFontSize
753 );
754 }
755 recalculateOuterPaddingToDrawBar() {
756 if (BAR_WIDTH_TO_TICK_WIDTH_RATIO * this.getTickDistance() > this.outerPadding * 2) {
757 this.outerPadding = Math.floor(BAR_WIDTH_TO_TICK_WIDTH_RATIO * this.getTickDistance() / 2);
758 }
759 this.recalculateScale();
760 }
761 calculateSpaceIfDrawnHorizontally(availableSpace) {
762 let availableHeight = availableSpace.height;
763 if (this.axisConfig.showAxisLine && availableHeight > this.axisConfig.axisLineWidth) {
764 availableHeight -= this.axisConfig.axisLineWidth;
765 this.showAxisLine = true;
766 }
767 if (this.axisConfig.showLabel) {
768 const spaceRequired = this.getLabelDimension();
769 const maxPadding = MAX_OUTER_PADDING_PERCENT_FOR_WRT_LABEL * availableSpace.width;
770 this.outerPadding = Math.min(spaceRequired.width / 2, maxPadding);
771 const heightRequired = spaceRequired.height + this.axisConfig.labelPadding * 2;
772 this.labelTextHeight = spaceRequired.height;
773 if (heightRequired <= availableHeight) {
774 availableHeight -= heightRequired;
775 this.showLabel = true;
776 }
777 }
778 if (this.axisConfig.showTick && availableHeight >= this.axisConfig.tickLength) {
779 this.showTick = true;
780 availableHeight -= this.axisConfig.tickLength;
781 }
782 if (this.axisConfig.showTitle && this.title) {
783 const spaceRequired = this.textDimensionCalculator.getMaxDimension(
784 [this.title],
785 this.axisConfig.titleFontSize
786 );
787 const heightRequired = spaceRequired.height + this.axisConfig.titlePadding * 2;
788 this.titleTextHeight = spaceRequired.height;
789 if (heightRequired <= availableHeight) {
790 availableHeight -= heightRequired;
791 this.showTitle = true;
792 }
793 }
794 this.boundingRect.width = availableSpace.width;
795 this.boundingRect.height = availableSpace.height - availableHeight;
796 }
797 calculateSpaceIfDrawnVertical(availableSpace) {
798 let availableWidth = availableSpace.width;
799 if (this.axisConfig.showAxisLine && availableWidth > this.axisConfig.axisLineWidth) {
800 availableWidth -= this.axisConfig.axisLineWidth;
801 this.showAxisLine = true;
802 }
803 if (this.axisConfig.showLabel) {
804 const spaceRequired = this.getLabelDimension();
805 const maxPadding = MAX_OUTER_PADDING_PERCENT_FOR_WRT_LABEL * availableSpace.height;
806 this.outerPadding = Math.min(spaceRequired.height / 2, maxPadding);
807 const widthRequired = spaceRequired.width + this.axisConfig.labelPadding * 2;
808 if (widthRequired <= availableWidth) {
809 availableWidth -= widthRequired;
810 this.showLabel = true;
811 }
812 }
813 if (this.axisConfig.showTick && availableWidth >= this.axisConfig.tickLength) {
814 this.showTick = true;
815 availableWidth -= this.axisConfig.tickLength;
816 }
817 if (this.axisConfig.showTitle && this.title) {
818 const spaceRequired = this.textDimensionCalculator.getMaxDimension(
819 [this.title],
820 this.axisConfig.titleFontSize
821 );
822 const widthRequired = spaceRequired.height + this.axisConfig.titlePadding * 2;
823 this.titleTextHeight = spaceRequired.height;
824 if (widthRequired <= availableWidth) {
825 availableWidth -= widthRequired;
826 this.showTitle = true;
827 }
828 }
829 this.boundingRect.width = availableSpace.width - availableWidth;
830 this.boundingRect.height = availableSpace.height;
831 }
832 calculateSpace(availableSpace) {
833 if (this.axisPosition === "left" || this.axisPosition === "right") {
834 this.calculateSpaceIfDrawnVertical(availableSpace);
835 } else {
836 this.calculateSpaceIfDrawnHorizontally(availableSpace);
837 }
838 this.recalculateScale();
839 return {
840 width: this.boundingRect.width,
841 height: this.boundingRect.height
842 };
843 }
844 setBoundingBoxXY(point) {
845 this.boundingRect.x = point.x;
846 this.boundingRect.y = point.y;
847 }
848 getDrawableElementsForLeftAxis() {
849 const drawableElement = [];
850 if (this.showAxisLine) {
851 const x = this.boundingRect.x + this.boundingRect.width - this.axisConfig.axisLineWidth / 2;
852 drawableElement.push({
853 type: "path",
854 groupTexts: ["left-axis", "axisl-line"],
855 data: [
856 {
857 path: `M ${x},${this.boundingRect.y} L ${x},${this.boundingRect.y + this.boundingRect.height} `,
858 strokeFill: this.axisThemeConfig.axisLineColor,
859 strokeWidth: this.axisConfig.axisLineWidth
860 }
861 ]
862 });
863 }
864 if (this.showLabel) {
865 drawableElement.push({
866 type: "text",
867 groupTexts: ["left-axis", "label"],
868 data: this.getTickValues().map((tick) => ({
869 text: tick.toString(),
870 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),
871 y: this.getScaleValue(tick),
872 fill: this.axisThemeConfig.labelColor,
873 fontSize: this.axisConfig.labelFontSize,
874 rotation: 0,
875 verticalPos: "middle",
876 horizontalPos: "right"
877 }))
878 });
879 }
880 if (this.showTick) {
881 const x = this.boundingRect.x + this.boundingRect.width - (this.showAxisLine ? this.axisConfig.axisLineWidth : 0);
882 drawableElement.push({
883 type: "path",
884 groupTexts: ["left-axis", "ticks"],
885 data: this.getTickValues().map((tick) => ({
886 path: `M ${x},${this.getScaleValue(tick)} L ${x - this.axisConfig.tickLength},${this.getScaleValue(tick)}`,
887 strokeFill: this.axisThemeConfig.tickColor,
888 strokeWidth: this.axisConfig.tickWidth
889 }))
890 });
891 }
892 if (this.showTitle) {
893 drawableElement.push({
894 type: "text",
895 groupTexts: ["left-axis", "title"],
896 data: [
897 {
898 text: this.title,
899 x: this.boundingRect.x + this.axisConfig.titlePadding,
900 y: this.boundingRect.y + this.boundingRect.height / 2,
901 fill: this.axisThemeConfig.titleColor,
902 fontSize: this.axisConfig.titleFontSize,
903 rotation: 270,
904 verticalPos: "top",
905 horizontalPos: "center"
906 }
907 ]
908 });
909 }
910 return drawableElement;
911 }
912 getDrawableElementsForBottomAxis() {
913 const drawableElement = [];
914 if (this.showAxisLine) {
915 const y = this.boundingRect.y + this.axisConfig.axisLineWidth / 2;
916 drawableElement.push({
917 type: "path",
918 groupTexts: ["bottom-axis", "axis-line"],
919 data: [
920 {
921 path: `M ${this.boundingRect.x},${y} L ${this.boundingRect.x + this.boundingRect.width},${y}`,
922 strokeFill: this.axisThemeConfig.axisLineColor,
923 strokeWidth: this.axisConfig.axisLineWidth
924 }
925 ]
926 });
927 }
928 if (this.showLabel) {
929 drawableElement.push({
930 type: "text",
931 groupTexts: ["bottom-axis", "label"],
932 data: this.getTickValues().map((tick) => ({
933 text: tick.toString(),
934 x: this.getScaleValue(tick),
935 y: this.boundingRect.y + this.axisConfig.labelPadding + (this.showTick ? this.axisConfig.tickLength : 0) + (this.showAxisLine ? this.axisConfig.axisLineWidth : 0),
936 fill: this.axisThemeConfig.labelColor,
937 fontSize: this.axisConfig.labelFontSize,
938 rotation: 0,
939 verticalPos: "top",
940 horizontalPos: "center"
941 }))
942 });
943 }
944 if (this.showTick) {
945 const y = this.boundingRect.y + (this.showAxisLine ? this.axisConfig.axisLineWidth : 0);
946 drawableElement.push({
947 type: "path",
948 groupTexts: ["bottom-axis", "ticks"],
949 data: this.getTickValues().map((tick) => ({
950 path: `M ${this.getScaleValue(tick)},${y} L ${this.getScaleValue(tick)},${y + this.axisConfig.tickLength}`,
951 strokeFill: this.axisThemeConfig.tickColor,
952 strokeWidth: this.axisConfig.tickWidth
953 }))
954 });
955 }
956 if (this.showTitle) {
957 drawableElement.push({
958 type: "text",
959 groupTexts: ["bottom-axis", "title"],
960 data: [
961 {
962 text: this.title,
963 x: this.range[0] + (this.range[1] - this.range[0]) / 2,
964 y: this.boundingRect.y + this.boundingRect.height - this.axisConfig.titlePadding - this.titleTextHeight,
965 fill: this.axisThemeConfig.titleColor,
966 fontSize: this.axisConfig.titleFontSize,
967 rotation: 0,
968 verticalPos: "top",
969 horizontalPos: "center"
970 }
971 ]
972 });
973 }
974 return drawableElement;
975 }
976 getDrawableElementsForTopAxis() {
977 const drawableElement = [];
978 if (this.showAxisLine) {
979 const y = this.boundingRect.y + this.boundingRect.height - this.axisConfig.axisLineWidth / 2;
980 drawableElement.push({
981 type: "path",
982 groupTexts: ["top-axis", "axis-line"],
983 data: [
984 {
985 path: `M ${this.boundingRect.x},${y} L ${this.boundingRect.x + this.boundingRect.width},${y}`,
986 strokeFill: this.axisThemeConfig.axisLineColor,
987 strokeWidth: this.axisConfig.axisLineWidth
988 }
989 ]
990 });
991 }
992 if (this.showLabel) {
993 drawableElement.push({
994 type: "text",
995 groupTexts: ["top-axis", "label"],
996 data: this.getTickValues().map((tick) => ({
997 text: tick.toString(),
998 x: this.getScaleValue(tick),
999 y: this.boundingRect.y + (this.showTitle ? this.titleTextHeight + this.axisConfig.titlePadding * 2 : 0) + this.axisConfig.labelPadding,
1000 fill: this.axisThemeConfig.labelColor,
1001 fontSize: this.axisConfig.labelFontSize,
1002 rotation: 0,
1003 verticalPos: "top",
1004 horizontalPos: "center"
1005 }))
1006 });
1007 }
1008 if (this.showTick) {
1009 const y = this.boundingRect.y;
1010 drawableElement.push({
1011 type: "path",
1012 groupTexts: ["top-axis", "ticks"],
1013 data: this.getTickValues().map((tick) => ({
1014 path: `M ${this.getScaleValue(tick)},${y + this.boundingRect.height - (this.showAxisLine ? this.axisConfig.axisLineWidth : 0)} L ${this.getScaleValue(tick)},${y + this.boundingRect.height - this.axisConfig.tickLength - (this.showAxisLine ? this.axisConfig.axisLineWidth : 0)}`,
1015 strokeFill: this.axisThemeConfig.tickColor,
1016 strokeWidth: this.axisConfig.tickWidth
1017 }))
1018 });
1019 }
1020 if (this.showTitle) {
1021 drawableElement.push({
1022 type: "text",
1023 groupTexts: ["top-axis", "title"],
1024 data: [
1025 {
1026 text: this.title,
1027 x: this.boundingRect.x + this.boundingRect.width / 2,
1028 y: this.boundingRect.y + this.axisConfig.titlePadding,
1029 fill: this.axisThemeConfig.titleColor,
1030 fontSize: this.axisConfig.titleFontSize,
1031 rotation: 0,
1032 verticalPos: "top",
1033 horizontalPos: "center"
1034 }
1035 ]
1036 });
1037 }
1038 return drawableElement;
1039 }
1040 getDrawableElements() {
1041 if (this.axisPosition === "left") {
1042 return this.getDrawableElementsForLeftAxis();
1043 }
1044 if (this.axisPosition === "right") {
1045 throw Error("Drawing of right axis is not implemented");
1046 }
1047 if (this.axisPosition === "bottom") {
1048 return this.getDrawableElementsForBottomAxis();
1049 }
1050 if (this.axisPosition === "top") {
1051 return this.getDrawableElementsForTopAxis();
1052 }
1053 return [];
1054 }
1055}
1056class BandAxis extends BaseAxis {
1057 constructor(axisConfig, axisThemeConfig, categories, title, textDimensionCalculator) {
1058 super(axisConfig, title, textDimensionCalculator, axisThemeConfig);
1059 this.categories = categories;
1060 this.scale = scaleBand().domain(this.categories).range(this.getRange());
1061 }
1062 setRange(range) {
1063 super.setRange(range);
1064 }
1065 recalculateScale() {
1066 this.scale = scaleBand().domain(this.categories).range(this.getRange()).paddingInner(1).paddingOuter(0).align(0.5);
1067 log.trace("BandAxis axis final categories, range: ", this.categories, this.getRange());
1068 }
1069 getTickValues() {
1070 return this.categories;
1071 }
1072 getScaleValue(value) {
1073 return this.scale(value) || this.getRange()[0];
1074 }
1075}
1076class LinearAxis extends BaseAxis {
1077 constructor(axisConfig, axisThemeConfig, domain, title, textDimensionCalculator) {
1078 super(axisConfig, title, textDimensionCalculator, axisThemeConfig);
1079 this.domain = domain;
1080 this.scale = scaleLinear().domain(this.domain).range(this.getRange());
1081 }
1082 getTickValues() {
1083 return this.scale.ticks();
1084 }
1085 recalculateScale() {
1086 const domain = [...this.domain];
1087 if (this.axisPosition === "left") {
1088 domain.reverse();
1089 }
1090 this.scale = scaleLinear().domain(domain).range(this.getRange());
1091 }
1092 getScaleValue(value) {
1093 return this.scale(value);
1094 }
1095}
1096function getAxis(data, axisConfig, axisThemeConfig, tmpSVGGroup2) {
1097 const textDimensionCalculator = new TextDimensionCalculatorWithFont(tmpSVGGroup2);
1098 if (isBandAxisData(data)) {
1099 return new BandAxis(
1100 axisConfig,
1101 axisThemeConfig,
1102 data.categories,
1103 data.title,
1104 textDimensionCalculator
1105 );
1106 }
1107 return new LinearAxis(
1108 axisConfig,
1109 axisThemeConfig,
1110 [data.min, data.max],
1111 data.title,
1112 textDimensionCalculator
1113 );
1114}
1115class ChartTitle {
1116 constructor(textDimensionCalculator, chartConfig, chartData, chartThemeConfig) {
1117 this.textDimensionCalculator = textDimensionCalculator;
1118 this.chartConfig = chartConfig;
1119 this.chartData = chartData;
1120 this.chartThemeConfig = chartThemeConfig;
1121 this.boundingRect = {
1122 x: 0,
1123 y: 0,
1124 width: 0,
1125 height: 0
1126 };
1127 this.showChartTitle = false;
1128 }
1129 setBoundingBoxXY(point) {
1130 this.boundingRect.x = point.x;
1131 this.boundingRect.y = point.y;
1132 }
1133 calculateSpace(availableSpace) {
1134 const titleDimension = this.textDimensionCalculator.getMaxDimension(
1135 [this.chartData.title],
1136 this.chartConfig.titleFontSize
1137 );
1138 const widthRequired = Math.max(titleDimension.width, availableSpace.width);
1139 const heightRequired = titleDimension.height + 2 * this.chartConfig.titlePadding;
1140 if (titleDimension.width <= widthRequired && titleDimension.height <= heightRequired && this.chartConfig.showTitle && this.chartData.title) {
1141 this.boundingRect.width = widthRequired;
1142 this.boundingRect.height = heightRequired;
1143 this.showChartTitle = true;
1144 }
1145 return {
1146 width: this.boundingRect.width,
1147 height: this.boundingRect.height
1148 };
1149 }
1150 getDrawableElements() {
1151 const drawableElem = [];
1152 if (this.showChartTitle) {
1153 drawableElem.push({
1154 groupTexts: ["chart-title"],
1155 type: "text",
1156 data: [
1157 {
1158 fontSize: this.chartConfig.titleFontSize,
1159 text: this.chartData.title,
1160 verticalPos: "middle",
1161 horizontalPos: "center",
1162 x: this.boundingRect.x + this.boundingRect.width / 2,
1163 y: this.boundingRect.y + this.boundingRect.height / 2,
1164 fill: this.chartThemeConfig.titleColor,
1165 rotation: 0
1166 }
1167 ]
1168 });
1169 }
1170 return drawableElem;
1171 }
1172}
1173function getChartTitleComponent(chartConfig, chartData, chartThemeConfig, tmpSVGGroup2) {
1174 const textDimensionCalculator = new TextDimensionCalculatorWithFont(tmpSVGGroup2);
1175 return new ChartTitle(textDimensionCalculator, chartConfig, chartData, chartThemeConfig);
1176}
1177class LinePlot {
1178 constructor(plotData, xAxis, yAxis, orientation, plotIndex2) {
1179 this.plotData = plotData;
1180 this.xAxis = xAxis;
1181 this.yAxis = yAxis;
1182 this.orientation = orientation;
1183 this.plotIndex = plotIndex2;
1184 }
1185 getDrawableElement() {
1186 const finalData = this.plotData.data.map((d) => [
1187 this.xAxis.getScaleValue(d[0]),
1188 this.yAxis.getScaleValue(d[1])
1189 ]);
1190 let path;
1191 if (this.orientation === "horizontal") {
1192 path = line().y((d) => d[0]).x((d) => d[1])(finalData);
1193 } else {
1194 path = line().x((d) => d[0]).y((d) => d[1])(finalData);
1195 }
1196 if (!path) {
1197 return [];
1198 }
1199 return [
1200 {
1201 groupTexts: ["plot", `line-plot-${this.plotIndex}`],
1202 type: "path",
1203 data: [
1204 {
1205 path,
1206 strokeFill: this.plotData.strokeFill,
1207 strokeWidth: this.plotData.strokeWidth
1208 }
1209 ]
1210 }
1211 ];
1212 }
1213}
1214class BarPlot {
1215 constructor(barData, boundingRect, xAxis, yAxis, orientation, plotIndex2) {
1216 this.barData = barData;
1217 this.boundingRect = boundingRect;
1218 this.xAxis = xAxis;
1219 this.yAxis = yAxis;
1220 this.orientation = orientation;
1221 this.plotIndex = plotIndex2;
1222 }
1223 getDrawableElement() {
1224 const finalData = this.barData.data.map((d) => [
1225 this.xAxis.getScaleValue(d[0]),
1226 this.yAxis.getScaleValue(d[1])
1227 ]);
1228 const barPaddingPercent = 0.05;
1229 const barWidth = Math.min(this.xAxis.getAxisOuterPadding() * 2, this.xAxis.getTickDistance()) * (1 - barPaddingPercent);
1230 const barWidthHalf = barWidth / 2;
1231 if (this.orientation === "horizontal") {
1232 return [
1233 {
1234 groupTexts: ["plot", `bar-plot-${this.plotIndex}`],
1235 type: "rect",
1236 data: finalData.map((data) => ({
1237 x: this.boundingRect.x,
1238 y: data[0] - barWidthHalf,
1239 height: barWidth,
1240 width: data[1] - this.boundingRect.x,
1241 fill: this.barData.fill,
1242 strokeWidth: 0,
1243 strokeFill: this.barData.fill
1244 }))
1245 }
1246 ];
1247 }
1248 return [
1249 {
1250 groupTexts: ["plot", `bar-plot-${this.plotIndex}`],
1251 type: "rect",
1252 data: finalData.map((data) => ({
1253 x: data[0] - barWidthHalf,
1254 y: data[1],
1255 width: barWidth,
1256 height: this.boundingRect.y + this.boundingRect.height - data[1],
1257 fill: this.barData.fill,
1258 strokeWidth: 0,
1259 strokeFill: this.barData.fill
1260 }))
1261 }
1262 ];
1263 }
1264}
1265class BasePlot {
1266 constructor(chartConfig, chartData, chartThemeConfig) {
1267 this.chartConfig = chartConfig;
1268 this.chartData = chartData;
1269 this.chartThemeConfig = chartThemeConfig;
1270 this.boundingRect = {
1271 x: 0,
1272 y: 0,
1273 width: 0,
1274 height: 0
1275 };
1276 }
1277 setAxes(xAxis, yAxis) {
1278 this.xAxis = xAxis;
1279 this.yAxis = yAxis;
1280 }
1281 setBoundingBoxXY(point) {
1282 this.boundingRect.x = point.x;
1283 this.boundingRect.y = point.y;
1284 }
1285 calculateSpace(availableSpace) {
1286 this.boundingRect.width = availableSpace.width;
1287 this.boundingRect.height = availableSpace.height;
1288 return {
1289 width: this.boundingRect.width,
1290 height: this.boundingRect.height
1291 };
1292 }
1293 getDrawableElements() {
1294 if (!(this.xAxis && this.yAxis)) {
1295 throw Error("Axes must be passed to render Plots");
1296 }
1297 const drawableElem = [];
1298 for (const [i, plot] of this.chartData.plots.entries()) {
1299 switch (plot.type) {
1300 case "line":
1301 {
1302 const linePlot = new LinePlot(
1303 plot,
1304 this.xAxis,
1305 this.yAxis,
1306 this.chartConfig.chartOrientation,
1307 i
1308 );
1309 drawableElem.push(...linePlot.getDrawableElement());
1310 }
1311 break;
1312 case "bar":
1313 {
1314 const barPlot = new BarPlot(
1315 plot,
1316 this.boundingRect,
1317 this.xAxis,
1318 this.yAxis,
1319 this.chartConfig.chartOrientation,
1320 i
1321 );
1322 drawableElem.push(...barPlot.getDrawableElement());
1323 }
1324 break;
1325 }
1326 }
1327 return drawableElem;
1328 }
1329}
1330function getPlotComponent(chartConfig, chartData, chartThemeConfig) {
1331 return new BasePlot(chartConfig, chartData, chartThemeConfig);
1332}
1333class Orchestrator {
1334 constructor(chartConfig, chartData, chartThemeConfig, tmpSVGGroup2) {
1335 this.chartConfig = chartConfig;
1336 this.chartData = chartData;
1337 this.componentStore = {
1338 title: getChartTitleComponent(chartConfig, chartData, chartThemeConfig, tmpSVGGroup2),
1339 plot: getPlotComponent(chartConfig, chartData, chartThemeConfig),
1340 xAxis: getAxis(
1341 chartData.xAxis,
1342 chartConfig.xAxis,
1343 {
1344 titleColor: chartThemeConfig.xAxisTitleColor,
1345 labelColor: chartThemeConfig.xAxisLabelColor,
1346 tickColor: chartThemeConfig.xAxisTickColor,
1347 axisLineColor: chartThemeConfig.xAxisLineColor
1348 },
1349 tmpSVGGroup2
1350 ),
1351 yAxis: getAxis(
1352 chartData.yAxis,
1353 chartConfig.yAxis,
1354 {
1355 titleColor: chartThemeConfig.yAxisTitleColor,
1356 labelColor: chartThemeConfig.yAxisLabelColor,
1357 tickColor: chartThemeConfig.yAxisTickColor,
1358 axisLineColor: chartThemeConfig.yAxisLineColor
1359 },
1360 tmpSVGGroup2
1361 )
1362 };
1363 }
1364 calculateVerticalSpace() {
1365 let availableWidth = this.chartConfig.width;
1366 let availableHeight = this.chartConfig.height;
1367 let plotX = 0;
1368 let plotY = 0;
1369 let chartWidth = Math.floor(availableWidth * this.chartConfig.plotReservedSpacePercent / 100);
1370 let chartHeight = Math.floor(
1371 availableHeight * this.chartConfig.plotReservedSpacePercent / 100
1372 );
1373 let spaceUsed = this.componentStore.plot.calculateSpace({
1374 width: chartWidth,
1375 height: chartHeight
1376 });
1377 availableWidth -= spaceUsed.width;
1378 availableHeight -= spaceUsed.height;
1379 spaceUsed = this.componentStore.title.calculateSpace({
1380 width: this.chartConfig.width,
1381 height: availableHeight
1382 });
1383 plotY = spaceUsed.height;
1384 availableHeight -= spaceUsed.height;
1385 this.componentStore.xAxis.setAxisPosition("bottom");
1386 spaceUsed = this.componentStore.xAxis.calculateSpace({
1387 width: availableWidth,
1388 height: availableHeight
1389 });
1390 availableHeight -= spaceUsed.height;
1391 this.componentStore.yAxis.setAxisPosition("left");
1392 spaceUsed = this.componentStore.yAxis.calculateSpace({
1393 width: availableWidth,
1394 height: availableHeight
1395 });
1396 plotX = spaceUsed.width;
1397 availableWidth -= spaceUsed.width;
1398 if (availableWidth > 0) {
1399 chartWidth += availableWidth;
1400 availableWidth = 0;
1401 }
1402 if (availableHeight > 0) {
1403 chartHeight += availableHeight;
1404 availableHeight = 0;
1405 }
1406 this.componentStore.plot.calculateSpace({
1407 width: chartWidth,
1408 height: chartHeight
1409 });
1410 this.componentStore.plot.setBoundingBoxXY({ x: plotX, y: plotY });
1411 this.componentStore.xAxis.setRange([plotX, plotX + chartWidth]);
1412 this.componentStore.xAxis.setBoundingBoxXY({ x: plotX, y: plotY + chartHeight });
1413 this.componentStore.yAxis.setRange([plotY, plotY + chartHeight]);
1414 this.componentStore.yAxis.setBoundingBoxXY({ x: 0, y: plotY });
1415 if (this.chartData.plots.some((p) => isBarPlot(p))) {
1416 this.componentStore.xAxis.recalculateOuterPaddingToDrawBar();
1417 }
1418 }
1419 calculateHorizontalSpace() {
1420 let availableWidth = this.chartConfig.width;
1421 let availableHeight = this.chartConfig.height;
1422 let titleYEnd = 0;
1423 let plotX = 0;
1424 let plotY = 0;
1425 let chartWidth = Math.floor(availableWidth * this.chartConfig.plotReservedSpacePercent / 100);
1426 let chartHeight = Math.floor(
1427 availableHeight * this.chartConfig.plotReservedSpacePercent / 100
1428 );
1429 let spaceUsed = this.componentStore.plot.calculateSpace({
1430 width: chartWidth,
1431 height: chartHeight
1432 });
1433 availableWidth -= spaceUsed.width;
1434 availableHeight -= spaceUsed.height;
1435 spaceUsed = this.componentStore.title.calculateSpace({
1436 width: this.chartConfig.width,
1437 height: availableHeight
1438 });
1439 titleYEnd = spaceUsed.height;
1440 availableHeight -= spaceUsed.height;
1441 this.componentStore.xAxis.setAxisPosition("left");
1442 spaceUsed = this.componentStore.xAxis.calculateSpace({
1443 width: availableWidth,
1444 height: availableHeight
1445 });
1446 availableWidth -= spaceUsed.width;
1447 plotX = spaceUsed.width;
1448 this.componentStore.yAxis.setAxisPosition("top");
1449 spaceUsed = this.componentStore.yAxis.calculateSpace({
1450 width: availableWidth,
1451 height: availableHeight
1452 });
1453 availableHeight -= spaceUsed.height;
1454 plotY = titleYEnd + spaceUsed.height;
1455 if (availableWidth > 0) {
1456 chartWidth += availableWidth;
1457 availableWidth = 0;
1458 }
1459 if (availableHeight > 0) {
1460 chartHeight += availableHeight;
1461 availableHeight = 0;
1462 }
1463 this.componentStore.plot.calculateSpace({
1464 width: chartWidth,
1465 height: chartHeight
1466 });
1467 this.componentStore.plot.setBoundingBoxXY({ x: plotX, y: plotY });
1468 this.componentStore.yAxis.setRange([plotX, plotX + chartWidth]);
1469 this.componentStore.yAxis.setBoundingBoxXY({ x: plotX, y: titleYEnd });
1470 this.componentStore.xAxis.setRange([plotY, plotY + chartHeight]);
1471 this.componentStore.xAxis.setBoundingBoxXY({ x: 0, y: plotY });
1472 if (this.chartData.plots.some((p) => isBarPlot(p))) {
1473 this.componentStore.xAxis.recalculateOuterPaddingToDrawBar();
1474 }
1475 }
1476 calculateSpace() {
1477 if (this.chartConfig.chartOrientation === "horizontal") {
1478 this.calculateHorizontalSpace();
1479 } else {
1480 this.calculateVerticalSpace();
1481 }
1482 }
1483 getDrawableElement() {
1484 this.calculateSpace();
1485 const drawableElem = [];
1486 this.componentStore.plot.setAxes(this.componentStore.xAxis, this.componentStore.yAxis);
1487 for (const component of Object.values(this.componentStore)) {
1488 drawableElem.push(...component.getDrawableElements());
1489 }
1490 return drawableElem;
1491 }
1492}
1493class XYChartBuilder {
1494 static build(config, chartData, chartThemeConfig, tmpSVGGroup2) {
1495 const orchestrator = new Orchestrator(config, chartData, chartThemeConfig, tmpSVGGroup2);
1496 return orchestrator.getDrawableElement();
1497 }
1498}
1499let plotIndex = 0;
1500let tmpSVGGroup;
1501let xyChartConfig = getChartDefaultConfig();
1502let xyChartThemeConfig = getChartDefaultThemeConfig();
1503let xyChartData = getChartDefaultData();
1504let plotColorPalette = xyChartThemeConfig.plotColorPalette.split(",").map((color) => color.trim());
1505let hasSetXAxis = false;
1506let hasSetYAxis = false;
1507function getChartDefaultThemeConfig() {
1508 const defaultThemeVariables = getThemeVariables();
1509 const config = getConfig();
1510 return cleanAndMerge(defaultThemeVariables.xyChart, config.themeVariables.xyChart);
1511}
1512function getChartDefaultConfig() {
1513 const config = getConfig();
1514 return cleanAndMerge(
1515 defaultConfig.xyChart,
1516 config.xyChart
1517 );
1518}
1519function getChartDefaultData() {
1520 return {
1521 yAxis: {
1522 type: "linear",
1523 title: "",
1524 min: Infinity,
1525 max: -Infinity
1526 },
1527 xAxis: {
1528 type: "band",
1529 title: "",
1530 categories: []
1531 },
1532 title: "",
1533 plots: []
1534 };
1535}
1536function textSanitizer(text) {
1537 const config = getConfig();
1538 return sanitizeText(text.trim(), config);
1539}
1540function setTmpSVGG(SVGG) {
1541 tmpSVGGroup = SVGG;
1542}
1543function setOrientation(orientation) {
1544 if (orientation === "horizontal") {
1545 xyChartConfig.chartOrientation = "horizontal";
1546 } else {
1547 xyChartConfig.chartOrientation = "vertical";
1548 }
1549}
1550function setXAxisTitle(title) {
1551 xyChartData.xAxis.title = textSanitizer(title.text);
1552}
1553function setXAxisRangeData(min, max) {
1554 xyChartData.xAxis = { type: "linear", title: xyChartData.xAxis.title, min, max };
1555 hasSetXAxis = true;
1556}
1557function setXAxisBand(categories) {
1558 xyChartData.xAxis = {
1559 type: "band",
1560 title: xyChartData.xAxis.title,
1561 categories: categories.map((c) => textSanitizer(c.text))
1562 };
1563 hasSetXAxis = true;
1564}
1565function setYAxisTitle(title) {
1566 xyChartData.yAxis.title = textSanitizer(title.text);
1567}
1568function setYAxisRangeData(min, max) {
1569 xyChartData.yAxis = { type: "linear", title: xyChartData.yAxis.title, min, max };
1570 hasSetYAxis = true;
1571}
1572function setYAxisRangeFromPlotData(data) {
1573 const minValue = Math.min(...data);
1574 const maxValue = Math.max(...data);
1575 const prevMinValue = isLinearAxisData(xyChartData.yAxis) ? xyChartData.yAxis.min : Infinity;
1576 const prevMaxValue = isLinearAxisData(xyChartData.yAxis) ? xyChartData.yAxis.max : -Infinity;
1577 xyChartData.yAxis = {
1578 type: "linear",
1579 title: xyChartData.yAxis.title,
1580 min: Math.min(prevMinValue, minValue),
1581 max: Math.max(prevMaxValue, maxValue)
1582 };
1583}
1584function transformDataWithoutCategory(data) {
1585 let retData = [];
1586 if (data.length === 0) {
1587 return retData;
1588 }
1589 if (!hasSetXAxis) {
1590 const prevMinValue = isLinearAxisData(xyChartData.xAxis) ? xyChartData.xAxis.min : Infinity;
1591 const prevMaxValue = isLinearAxisData(xyChartData.xAxis) ? xyChartData.xAxis.max : -Infinity;
1592 setXAxisRangeData(Math.min(prevMinValue, 1), Math.max(prevMaxValue, data.length));
1593 }
1594 if (!hasSetYAxis) {
1595 setYAxisRangeFromPlotData(data);
1596 }
1597 if (isBandAxisData(xyChartData.xAxis)) {
1598 retData = xyChartData.xAxis.categories.map((c, i) => [c, data[i]]);
1599 }
1600 if (isLinearAxisData(xyChartData.xAxis)) {
1601 const min = xyChartData.xAxis.min;
1602 const max = xyChartData.xAxis.max;
1603 const step = (max - min + 1) / data.length;
1604 const categories = [];
1605 for (let i = min; i <= max; i += step) {
1606 categories.push(`${i}`);
1607 }
1608 retData = categories.map((c, i) => [c, data[i]]);
1609 }
1610 return retData;
1611}
1612function getPlotColorFromPalette(plotIndex2) {
1613 return plotColorPalette[plotIndex2 === 0 ? 0 : plotIndex2 % plotColorPalette.length];
1614}
1615function setLineData(title, data) {
1616 const plotData = transformDataWithoutCategory(data);
1617 xyChartData.plots.push({
1618 type: "line",
1619 strokeFill: getPlotColorFromPalette(plotIndex),
1620 strokeWidth: 2,
1621 data: plotData
1622 });
1623 plotIndex++;
1624}
1625function setBarData(title, data) {
1626 const plotData = transformDataWithoutCategory(data);
1627 xyChartData.plots.push({
1628 type: "bar",
1629 fill: getPlotColorFromPalette(plotIndex),
1630 data: plotData
1631 });
1632 plotIndex++;
1633}
1634function getDrawableElem() {
1635 if (xyChartData.plots.length === 0) {
1636 throw Error("No Plot to render, please provide a plot with some data");
1637 }
1638 xyChartData.title = getDiagramTitle();
1639 return XYChartBuilder.build(xyChartConfig, xyChartData, xyChartThemeConfig, tmpSVGGroup);
1640}
1641function getChartThemeConfig() {
1642 return xyChartThemeConfig;
1643}
1644function getChartConfig() {
1645 return xyChartConfig;
1646}
1647const clear = function() {
1648 clear$1();
1649 plotIndex = 0;
1650 xyChartConfig = getChartDefaultConfig();
1651 xyChartData = getChartDefaultData();
1652 xyChartThemeConfig = getChartDefaultThemeConfig();
1653 plotColorPalette = xyChartThemeConfig.plotColorPalette.split(",").map((color) => color.trim());
1654 hasSetXAxis = false;
1655 hasSetYAxis = false;
1656};
1657const db = {
1658 getDrawableElem,
1659 clear,
1660 setAccTitle,
1661 getAccTitle,
1662 setDiagramTitle,
1663 getDiagramTitle,
1664 getAccDescription,
1665 setAccDescription,
1666 setOrientation,
1667 setXAxisTitle,
1668 setXAxisRangeData,
1669 setXAxisBand,
1670 setYAxisTitle,
1671 setYAxisRangeData,
1672 setLineData,
1673 setBarData,
1674 setTmpSVGG,
1675 getChartThemeConfig,
1676 getChartConfig
1677};
1678const draw = (txt, id, _version, diagObj) => {
1679 const db2 = diagObj.db;
1680 const themeConfig = db2.getChartThemeConfig();
1681 const chartConfig = db2.getChartConfig();
1682 function getDominantBaseLine(horizontalPos) {
1683 return horizontalPos === "top" ? "text-before-edge" : "middle";
1684 }
1685 function getTextAnchor(verticalPos) {
1686 return verticalPos === "left" ? "start" : verticalPos === "right" ? "end" : "middle";
1687 }
1688 function getTextTransformation(data) {
1689 return `translate(${data.x}, ${data.y}) rotate(${data.rotation || 0})`;
1690 }
1691 log.debug("Rendering xychart chart\n" + txt);
1692 const svg = selectSvgElement(id);
1693 const group = svg.append("g").attr("class", "main");
1694 const background = group.append("rect").attr("width", chartConfig.width).attr("height", chartConfig.height).attr("class", "background");
1695 configureSvgSize(svg, chartConfig.height, chartConfig.width, true);
1696 svg.attr("viewBox", `0 0 ${chartConfig.width} ${chartConfig.height}`);
1697 background.attr("fill", themeConfig.backgroundColor);
1698 db2.setTmpSVGG(svg.append("g").attr("class", "mermaid-tmp-group"));
1699 const shapes = db2.getDrawableElem();
1700 const groups = {};
1701 function getGroup(gList) {
1702 let elem = group;
1703 let prefix = "";
1704 for (const [i] of gList.entries()) {
1705 let parent = group;
1706 if (i > 0 && groups[prefix]) {
1707 parent = groups[prefix];
1708 }
1709 prefix += gList[i];
1710 elem = groups[prefix];
1711 if (!elem) {
1712 elem = groups[prefix] = parent.append("g").attr("class", gList[i]);
1713 }
1714 }
1715 return elem;
1716 }
1717 for (const shape of shapes) {
1718 if (shape.data.length === 0) {
1719 continue;
1720 }
1721 const shapeGroup = getGroup(shape.groupTexts);
1722 switch (shape.type) {
1723 case "rect":
1724 shapeGroup.selectAll("rect").data(shape.data).enter().append("rect").attr("x", (data) => data.x).attr("y", (data) => data.y).attr("width", (data) => data.width).attr("height", (data) => data.height).attr("fill", (data) => data.fill).attr("stroke", (data) => data.strokeFill).attr("stroke-width", (data) => data.strokeWidth);
1725 break;
1726 case "text":
1727 shapeGroup.selectAll("text").data(shape.data).enter().append("text").attr("x", 0).attr("y", 0).attr("fill", (data) => data.fill).attr("font-size", (data) => data.fontSize).attr("dominant-baseline", (data) => getDominantBaseLine(data.verticalPos)).attr("text-anchor", (data) => getTextAnchor(data.horizontalPos)).attr("transform", (data) => getTextTransformation(data)).text((data) => data.text);
1728 break;
1729 case "path":
1730 shapeGroup.selectAll("path").data(shape.data).enter().append("path").attr("d", (data) => data.path).attr("fill", (data) => data.fill ? data.fill : "none").attr("stroke", (data) => data.strokeFill).attr("stroke-width", (data) => data.strokeWidth);
1731 break;
1732 }
1733 }
1734};
1735const renderer = {
1736 draw
1737};
1738const diagram = {
1739 parser: parser$1,
1740 db,
1741 renderer
1742};
1743export {
1744 diagram
1745};