29.1 kBJavaScriptView Raw
1import { V as tau, W as defaultConfig, C as setDiagramTitle, D as getDiagramTitle, s as setAccTitle, g as getAccTitle, b as setAccDescription, a as getAccDescription, E as clear$1, d as sanitizeText, c as getConfig$1, l as log, X as cleanAndMerge, U as selectSvgElement, Y as parseFontSize, k as configureSvgSize } from "./mermaid-dcacb631.js";
2import { d as d3arc } from "./arc-c0f908ab.js";
3import { o as ordinal } from "./ordinal-475e0c0c.js";
4import { a as array } from "./array-b7dcf730.js";
5import { c as constant } from "./path-39bad7e2.js";
6import "./init-cc95ec8e.js";
7function descending(a, b) {
8 return b < a ? -1 : b > a ? 1 : b >= a ? 0 : NaN;
9}
10function identity(d) {
11 return d;
12}
13function d3pie() {
14 var value = identity, sortValues = descending, sort = null, startAngle = constant(0), endAngle = constant(tau), padAngle = constant(0);
15 function pie(data) {
16 var i, n = (data = array(data)).length, j, k, sum = 0, index = new Array(n), arcs = new Array(n), a0 = +startAngle.apply(this, arguments), da = Math.min(tau, Math.max(-tau, endAngle.apply(this, arguments) - a0)), a1, p = Math.min(Math.abs(da) / n, padAngle.apply(this, arguments)), pa = p * (da < 0 ? -1 : 1), v;
17 for (i = 0; i < n; ++i) {
18 if ((v = arcs[index[i] = i] = +value(data[i], i, data)) > 0) {
19 sum += v;
20 }
21 }
22 if (sortValues != null)
23 index.sort(function(i2, j2) {
24 return sortValues(arcs[i2], arcs[j2]);
25 });
26 else if (sort != null)
27 index.sort(function(i2, j2) {
28 return sort(data[i2], data[j2]);
29 });
30 for (i = 0, k = sum ? (da - n * pa) / sum : 0; i < n; ++i, a0 = a1) {
31 j = index[i], v = arcs[j], a1 = a0 + (v > 0 ? v * k : 0) + pa, arcs[j] = {
32 data: data[j],
33 index: i,
34 value: v,
35 startAngle: a0,
36 endAngle: a1,
37 padAngle: p
38 };
39 }
40 return arcs;
41 }
42 pie.value = function(_) {
43 return arguments.length ? (value = typeof _ === "function" ? _ : constant(+_), pie) : value;
44 };
45 pie.sortValues = function(_) {
46 return arguments.length ? (sortValues = _, sort = null, pie) : sortValues;
47 };
48 pie.sort = function(_) {
49 return arguments.length ? (sort = _, sortValues = null, pie) : sort;
50 };
51 pie.startAngle = function(_) {
52 return arguments.length ? (startAngle = typeof _ === "function" ? _ : constant(+_), pie) : startAngle;
53 };
54 pie.endAngle = function(_) {
55 return arguments.length ? (endAngle = typeof _ === "function" ? _ : constant(+_), pie) : endAngle;
56 };
57 pie.padAngle = function(_) {
58 return arguments.length ? (padAngle = typeof _ === "function" ? _ : constant(+_), pie) : padAngle;
59 };
60 return pie;
61}
62var parser = function() {
63 var o = function(k, v, o2, l) {
64 for (o2 = o2 || {}, l = k.length; l--; o2[k[l]] = v)
65 ;
66 return o2;
67 }, $V0 = [1, 3], $V1 = [1, 4], $V2 = [1, 5], $V3 = [1, 6], $V4 = [1, 10, 12, 14, 16, 18, 19, 20, 21, 22], $V5 = [2, 4], $V6 = [1, 5, 10, 12, 14, 16, 18, 19, 20, 21, 22], $V7 = [20, 21, 22], $V8 = [2, 7], $V9 = [1, 12], $Va = [1, 13], $Vb = [1, 14], $Vc = [1, 15], $Vd = [1, 16], $Ve = [1, 17];
68 var parser2 = {
69 trace: function trace() {
70 },
71 yy: {},
72 symbols_: { "error": 2, "start": 3, "eol": 4, "PIE": 5, "document": 6, "showData": 7, "line": 8, "statement": 9, "txt": 10, "value": 11, "title": 12, "title_value": 13, "acc_title": 14, "acc_title_value": 15, "acc_descr": 16, "acc_descr_value": 17, "acc_descr_multiline_value": 18, "section": 19, "NEWLINE": 20, ";": 21, "EOF": 22, "$accept": 0, "$end": 1 },
73 terminals_: { 2: "error", 5: "PIE", 7: "showData", 10: "txt", 11: "value", 12: "title", 13: "title_value", 14: "acc_title", 15: "acc_title_value", 16: "acc_descr", 17: "acc_descr_value", 18: "acc_descr_multiline_value", 19: "section", 20: "NEWLINE", 21: ";", 22: "EOF" },
74 productions_: [0, [3, 2], [3, 2], [3, 3], [6, 0], [6, 2], [8, 2], [9, 0], [9, 2], [9, 2], [9, 2], [9, 2], [9, 1], [9, 1], [4, 1], [4, 1], [4, 1]],
75 performAction: function anonymous(yytext, yyleng, yylineno, yy, yystate, $$, _$) {
76 var $0 = $$.length - 1;
77 switch (yystate) {
78 case 3:
79 yy.setShowData(true);
80 break;
81 case 6:
82 this.$ = $$[$0 - 1];
83 break;
84 case 8:
85 yy.addSection($$[$0 - 1], yy.cleanupValue($$[$0]));
86 break;
87 case 9:
88 this.$ = $$[$0].trim();
89 yy.setDiagramTitle(this.$);
90 break;
91 case 10:
92 this.$ = $$[$0].trim();
93 yy.setAccTitle(this.$);
94 break;
95 case 11:
96 case 12:
97 this.$ = $$[$0].trim();
98 yy.setAccDescription(this.$);
99 break;
100 case 13:
101 yy.addSection($$[$0].substr(8));
102 this.$ = $$[$0].substr(8);
103 break;
104 }
105 },
106 table: [{ 3: 1, 4: 2, 5: $V0, 20: $V1, 21: $V2, 22: $V3 }, { 1: [3] }, { 3: 7, 4: 2, 5: $V0, 20: $V1, 21: $V2, 22: $V3 }, o($V4, $V5, { 6: 8, 7: [1, 9] }), o($V6, [2, 14]), o($V6, [2, 15]), o($V6, [2, 16]), { 1: [2, 1] }, o($V7, $V8, { 8: 10, 9: 11, 1: [2, 2], 10: $V9, 12: $Va, 14: $Vb, 16: $Vc, 18: $Vd, 19: $Ve }), o($V4, $V5, { 6: 18 }), o($V4, [2, 5]), { 4: 19, 20: $V1, 21: $V2, 22: $V3 }, { 11: [1, 20] }, { 13: [1, 21] }, { 15: [1, 22] }, { 17: [1, 23] }, o($V7, [2, 12]), o($V7, [2, 13]), o($V7, $V8, { 8: 10, 9: 11, 1: [2, 3], 10: $V9, 12: $Va, 14: $Vb, 16: $Vc, 18: $Vd, 19: $Ve }), o($V4, [2, 6]), o($V7, [2, 8]), o($V7, [2, 9]), o($V7, [2, 10]), o($V7, [2, 11])],
107 defaultActions: { 7: [2, 1] },
108 parseError: function parseError(str, hash) {
109 if (hash.recoverable) {
110 this.trace(str);
111 } else {
112 var error = new Error(str);
113 error.hash = hash;
114 throw error;
115 }
116 },
117 parse: function parse(input) {
118 var self = this, stack = [0], tstack = [], vstack = [null], lstack = [], table = this.table, yytext = "", yylineno = 0, yyleng = 0, TERROR = 2, EOF = 1;
119 var args = lstack.slice.call(arguments, 1);
120 var lexer2 = Object.create(this.lexer);
121 var sharedState = { yy: {} };
122 for (var k in this.yy) {
123 if (Object.prototype.hasOwnProperty.call(this.yy, k)) {
124 sharedState.yy[k] = this.yy[k];
125 }
126 }
127 lexer2.setInput(input, sharedState.yy);
128 sharedState.yy.lexer = lexer2;
129 sharedState.yy.parser = this;
130 if (typeof lexer2.yylloc == "undefined") {
131 lexer2.yylloc = {};
132 }
133 var yyloc = lexer2.yylloc;
134 lstack.push(yyloc);
135 var ranges = lexer2.options && lexer2.options.ranges;
136 if (typeof sharedState.yy.parseError === "function") {
137 this.parseError = sharedState.yy.parseError;
138 } else {
139 this.parseError = Object.getPrototypeOf(this).parseError;
140 }
141 function lex() {
142 var token;
143 token = tstack.pop() || lexer2.lex() || EOF;
144 if (typeof token !== "number") {
145 if (token instanceof Array) {
146 tstack = token;
147 token = tstack.pop();
148 }
149 token = self.symbols_[token] || token;
150 }
151 return token;
152 }
153 var symbol, state, action, r, yyval = {}, p, len, newState, expected;
154 while (true) {
155 state = stack[stack.length - 1];
156 if (this.defaultActions[state]) {
157 action = this.defaultActions[state];
158 } else {
159 if (symbol === null || typeof symbol == "undefined") {
160 symbol = lex();
161 }
162 action = table[state] && table[state][symbol];
163 }
164 if (typeof action === "undefined" || !action.length || !action[0]) {
165 var errStr = "";
166 expected = [];
167 for (p in table[state]) {
168 if (this.terminals_[p] && p > TERROR) {
169 expected.push("'" + this.terminals_[p] + "'");
170 }
171 }
172 if (lexer2.showPosition) {
173 errStr = "Parse error on line " + (yylineno + 1) + ":\n" + lexer2.showPosition() + "\nExpecting " + expected.join(", ") + ", got '" + (this.terminals_[symbol] || symbol) + "'";
174 } else {
175 errStr = "Parse error on line " + (yylineno + 1) + ": Unexpected " + (symbol == EOF ? "end of input" : "'" + (this.terminals_[symbol] || symbol) + "'");
176 }
177 this.parseError(errStr, {
178 text: lexer2.match,
179 token: this.terminals_[symbol] || symbol,
180 line: lexer2.yylineno,
181 loc: yyloc,
182 expected
183 });
184 }
185 if (action[0] instanceof Array && action.length > 1) {
186 throw new Error("Parse Error: multiple actions possible at state: " + state + ", token: " + symbol);
187 }
188 switch (action[0]) {
189 case 1:
190 stack.push(symbol);
191 vstack.push(lexer2.yytext);
192 lstack.push(lexer2.yylloc);
193 stack.push(action[1]);
194 symbol = null;
195 {
196 yyleng = lexer2.yyleng;
197 yytext = lexer2.yytext;
198 yylineno = lexer2.yylineno;
199 yyloc = lexer2.yylloc;
200 }
201 break;
202 case 2:
203 len = this.productions_[action[1]][1];
204 yyval.$ = vstack[vstack.length - len];
205 yyval._$ = {
206 first_line: lstack[lstack.length - (len || 1)].first_line,
207 last_line: lstack[lstack.length - 1].last_line,
208 first_column: lstack[lstack.length - (len || 1)].first_column,
209 last_column: lstack[lstack.length - 1].last_column
210 };
211 if (ranges) {
212 yyval._$.range = [
213 lstack[lstack.length - (len || 1)].range[0],
214 lstack[lstack.length - 1].range[1]
215 ];
216 }
217 r = this.performAction.apply(yyval, [
218 yytext,
219 yyleng,
220 yylineno,
221 sharedState.yy,
222 action[1],
223 vstack,
224 lstack
225 ].concat(args));
226 if (typeof r !== "undefined") {
227 return r;
228 }
229 if (len) {
230 stack = stack.slice(0, -1 * len * 2);
231 vstack = vstack.slice(0, -1 * len);
232 lstack = lstack.slice(0, -1 * len);
233 }
234 stack.push(this.productions_[action[1]][0]);
235 vstack.push(yyval.$);
236 lstack.push(yyval._$);
237 newState = table[stack[stack.length - 2]][stack[stack.length - 1]];
238 stack.push(newState);
239 break;
240 case 3:
241 return true;
242 }
243 }
244 return true;
245 }
246 };
247 var lexer = function() {
248 var lexer2 = {
249 EOF: 1,
250 parseError: function parseError(str, hash) {
251 if (this.yy.parser) {
252 this.yy.parser.parseError(str, hash);
253 } else {
254 throw new Error(str);
255 }
256 },
257 // resets the lexer, sets new input
258 setInput: function(input, yy) {
259 this.yy = yy || this.yy || {};
260 this._input = input;
261 this._more = this._backtrack = this.done = false;
262 this.yylineno = this.yyleng = 0;
263 this.yytext = this.matched = this.match = "";
264 this.conditionStack = ["INITIAL"];
265 this.yylloc = {
266 first_line: 1,
267 first_column: 0,
268 last_line: 1,
269 last_column: 0
270 };
271 if (this.options.ranges) {
272 this.yylloc.range = [0, 0];
273 }
274 this.offset = 0;
275 return this;
276 },
277 // consumes and returns one char from the input
278 input: function() {
279 var ch = this._input[0];
280 this.yytext += ch;
281 this.yyleng++;
282 this.offset++;
283 this.match += ch;
284 this.matched += ch;
285 var lines = ch.match(/(?:\r\n?|\n).*/g);
286 if (lines) {
287 this.yylineno++;
288 this.yylloc.last_line++;
289 } else {
290 this.yylloc.last_column++;
291 }
292 if (this.options.ranges) {
293 this.yylloc.range[1]++;
294 }
295 this._input = this._input.slice(1);
296 return ch;
297 },
298 // unshifts one char (or a string) into the input
299 unput: function(ch) {
300 var len = ch.length;
301 var lines = ch.split(/(?:\r\n?|\n)/g);
302 this._input = ch + this._input;
303 this.yytext = this.yytext.substr(0, this.yytext.length - len);
304 this.offset -= len;
305 var oldLines = this.match.split(/(?:\r\n?|\n)/g);
306 this.match = this.match.substr(0, this.match.length - 1);
307 this.matched = this.matched.substr(0, this.matched.length - 1);
308 if (lines.length - 1) {
309 this.yylineno -= lines.length - 1;
310 }
311 var r = this.yylloc.range;
312 this.yylloc = {
313 first_line: this.yylloc.first_line,
314 last_line: this.yylineno + 1,
315 first_column: this.yylloc.first_column,
316 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
317 };
318 if (this.options.ranges) {
319 this.yylloc.range = [r[0], r[0] + this.yyleng - len];
320 }
321 this.yyleng = this.yytext.length;
322 return this;
323 },
324 // When called from action, caches matched text and appends it on next action
325 more: function() {
326 this._more = true;
327 return this;
328 },
329 // 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.
330 reject: function() {
331 if (this.options.backtrack_lexer) {
332 this._backtrack = true;
333 } else {
334 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(), {
335 text: "",
336 token: null,
337 line: this.yylineno
338 });
339 }
340 return this;
341 },
342 // retain first n characters of the match
343 less: function(n) {
344 this.unput(this.match.slice(n));
345 },
346 // displays already matched input, i.e. for error messages
347 pastInput: function() {
348 var past = this.matched.substr(0, this.matched.length - this.match.length);
349 return (past.length > 20 ? "..." : "") + past.substr(-20).replace(/\n/g, "");
350 },
351 // displays upcoming input, i.e. for error messages
352 upcomingInput: function() {
353 var next = this.match;
354 if (next.length < 20) {
355 next += this._input.substr(0, 20 - next.length);
356 }
357 return (next.substr(0, 20) + (next.length > 20 ? "..." : "")).replace(/\n/g, "");
358 },
359 // displays the character position where the lexing error occurred, i.e. for error messages
360 showPosition: function() {
361 var pre = this.pastInput();
362 var c = new Array(pre.length + 1).join("-");
363 return pre + this.upcomingInput() + "\n" + c + "^";
364 },
365 // test the lexed token: return FALSE when not a match, otherwise return token
366 test_match: function(match, indexed_rule) {
367 var token, lines, backup;
368 if (this.options.backtrack_lexer) {
369 backup = {
370 yylineno: this.yylineno,
371 yylloc: {
372 first_line: this.yylloc.first_line,
373 last_line: this.last_line,
374 first_column: this.yylloc.first_column,
375 last_column: this.yylloc.last_column
376 },
377 yytext: this.yytext,
378 match: this.match,
379 matches: this.matches,
380 matched: this.matched,
381 yyleng: this.yyleng,
382 offset: this.offset,
383 _more: this._more,
384 _input: this._input,
385 yy: this.yy,
386 conditionStack: this.conditionStack.slice(0),
387 done: this.done
388 };
389 if (this.options.ranges) {
390 backup.yylloc.range = this.yylloc.range.slice(0);
391 }
392 }
393 lines = match[0].match(/(?:\r\n?|\n).*/g);
394 if (lines) {
395 this.yylineno += lines.length;
396 }
397 this.yylloc = {
398 first_line: this.yylloc.last_line,
399 last_line: this.yylineno + 1,
400 first_column: this.yylloc.last_column,
401 last_column: lines ? lines[lines.length - 1].length - lines[lines.length - 1].match(/\r?\n?/)[0].length : this.yylloc.last_column + match[0].length
402 };
403 this.yytext += match[0];
404 this.match += match[0];
405 this.matches = match;
406 this.yyleng = this.yytext.length;
407 if (this.options.ranges) {
408 this.yylloc.range = [this.offset, this.offset += this.yyleng];
409 }
410 this._more = false;
411 this._backtrack = false;
412 this._input = this._input.slice(match[0].length);
413 this.matched += match[0];
414 token = this.performAction.call(this, this.yy, this, indexed_rule, this.conditionStack[this.conditionStack.length - 1]);
415 if (this.done && this._input) {
416 this.done = false;
417 }
418 if (token) {
419 return token;
420 } else if (this._backtrack) {
421 for (var k in backup) {
422 this[k] = backup[k];
423 }
424 return false;
425 }
426 return false;
427 },
428 // return next match in input
429 next: function() {
430 if (this.done) {
431 return this.EOF;
432 }
433 if (!this._input) {
434 this.done = true;
435 }
436 var token, match, tempMatch, index;
437 if (!this._more) {
438 this.yytext = "";
439 this.match = "";
440 }
441 var rules = this._currentRules();
442 for (var i = 0; i < rules.length; i++) {
443 tempMatch = this._input.match(this.rules[rules[i]]);
444 if (tempMatch && (!match || tempMatch[0].length > match[0].length)) {
445 match = tempMatch;
446 index = i;
447 if (this.options.backtrack_lexer) {
448 token = this.test_match(tempMatch, rules[i]);
449 if (token !== false) {
450 return token;
451 } else if (this._backtrack) {
452 match = false;
453 continue;
454 } else {
455 return false;
456 }
457 } else if (!this.options.flex) {
458 break;
459 }
460 }
461 }
462 if (match) {
463 token = this.test_match(match, rules[index]);
464 if (token !== false) {
465 return token;
466 }
467 return false;
468 }
469 if (this._input === "") {
470 return this.EOF;
471 } else {
472 return this.parseError("Lexical error on line " + (this.yylineno + 1) + ". Unrecognized text.\n" + this.showPosition(), {
473 text: "",
474 token: null,
475 line: this.yylineno
476 });
477 }
478 },
479 // return next match that has a token
480 lex: function lex() {
481 var r = this.next();
482 if (r) {
483 return r;
484 } else {
485 return this.lex();
486 }
487 },
488 // activates a new lexer condition state (pushes the new lexer condition state onto the condition stack)
489 begin: function begin(condition) {
490 this.conditionStack.push(condition);
491 },
492 // pop the previously active lexer condition state off the condition stack
493 popState: function popState() {
494 var n = this.conditionStack.length - 1;
495 if (n > 0) {
496 return this.conditionStack.pop();
497 } else {
498 return this.conditionStack[0];
499 }
500 },
501 // produce the lexer rule set which is active for the currently active lexer condition state
502 _currentRules: function _currentRules() {
503 if (this.conditionStack.length && this.conditionStack[this.conditionStack.length - 1]) {
504 return this.conditions[this.conditionStack[this.conditionStack.length - 1]].rules;
505 } else {
506 return this.conditions["INITIAL"].rules;
507 }
508 },
509 // return the currently active lexer condition state; when an index argument is provided it produces the N-th previous condition state, if available
510 topState: function topState(n) {
511 n = this.conditionStack.length - 1 - Math.abs(n || 0);
512 if (n >= 0) {
513 return this.conditionStack[n];
514 } else {
515 return "INITIAL";
516 }
517 },
518 // alias for begin(condition)
519 pushState: function pushState(condition) {
520 this.begin(condition);
521 },
522 // return the number of states currently on the stack
523 stateStackSize: function stateStackSize() {
524 return this.conditionStack.length;
525 },
526 options: { "case-insensitive": true },
527 performAction: function anonymous(yy, yy_, $avoiding_name_collisions, YY_START) {
528 switch ($avoiding_name_collisions) {
529 case 0:
530 break;
531 case 1:
532 break;
533 case 2:
534 return 20;
535 case 3:
536 break;
537 case 4:
538 break;
539 case 5:
540 this.begin("title");
541 return 12;
542 case 6:
543 this.popState();
544 return "title_value";
545 case 7:
546 this.begin("acc_title");
547 return 14;
548 case 8:
549 this.popState();
550 return "acc_title_value";
551 case 9:
552 this.begin("acc_descr");
553 return 16;
554 case 10:
555 this.popState();
556 return "acc_descr_value";
557 case 11:
558 this.begin("acc_descr_multiline");
559 break;
560 case 12:
561 this.popState();
562 break;
563 case 13:
564 return "acc_descr_multiline_value";
565 case 14:
566 this.begin("string");
567 break;
568 case 15:
569 this.popState();
570 break;
571 case 16:
572 return "txt";
573 case 17:
574 return 5;
575 case 18:
576 return 7;
577 case 19:
578 return "value";
579 case 20:
580 return 22;
581 }
582 },
583 rules: [/^(?:%%(?!\{)[^\n]*)/i, /^(?:[^\}]%%[^\n]*)/i, /^(?:[\n\r]+)/i, /^(?:%%[^\n]*)/i, /^(?:[\s]+)/i, /^(?:title\b)/i, /^(?:(?!\n||)*[^\n]*)/i, /^(?:accTitle\s*:\s*)/i, /^(?:(?!\n||)*[^\n]*)/i, /^(?:accDescr\s*:\s*)/i, /^(?:(?!\n||)*[^\n]*)/i, /^(?:accDescr\s*\{\s*)/i, /^(?:[\}])/i, /^(?:[^\}]*)/i, /^(?:["])/i, /^(?:["])/i, /^(?:[^"]*)/i, /^(?:pie\b)/i, /^(?:showData\b)/i, /^(?::[\s]*[\d]+(?:\.[\d]+)?)/i, /^(?:$)/i],
584 conditions: { "acc_descr_multiline": { "rules": [12, 13], "inclusive": false }, "acc_descr": { "rules": [10], "inclusive": false }, "acc_title": { "rules": [8], "inclusive": false }, "title": { "rules": [6], "inclusive": false }, "string": { "rules": [15, 16], "inclusive": false }, "INITIAL": { "rules": [0, 1, 2, 3, 4, 5, 7, 9, 11, 14, 17, 18, 19, 20], "inclusive": true } }
585 };
586 return lexer2;
587 }();
588 parser2.lexer = lexer;
589 function Parser() {
590 this.yy = {};
591 }
592 Parser.prototype = parser2;
593 parser2.Parser = Parser;
594 return new Parser();
595}();
596parser.parser = parser;
597const parser$1 = parser;
598const DEFAULT_PIE_CONFIG = defaultConfig.pie;
599const DEFAULT_PIE_DB = {
600 sections: {},
601 showData: false,
602 config: DEFAULT_PIE_CONFIG
603};
604let sections = DEFAULT_PIE_DB.sections;
605let showData = DEFAULT_PIE_DB.showData;
606const config = structuredClone(DEFAULT_PIE_CONFIG);
607const getConfig = () => structuredClone(config);
608const clear = () => {
609 sections = structuredClone(DEFAULT_PIE_DB.sections);
610 showData = DEFAULT_PIE_DB.showData;
611 clear$1();
612};
613const addSection = (label, value) => {
614 label = sanitizeText(label, getConfig$1());
615 if (sections[label] === void 0) {
616 sections[label] = value;
617 log.debug(`added new section: ${label}, with value: ${value}`);
618 }
619};
620const getSections = () => sections;
621const cleanupValue = (value) => {
622 if (value.substring(0, 1) === ":") {
623 value = value.substring(1).trim();
624 }
625 return Number(value.trim());
626};
627const setShowData = (toggle) => {
628 showData = toggle;
629};
630const getShowData = () => showData;
631const db = {
632 getConfig,
633 clear,
634 setDiagramTitle,
635 getDiagramTitle,
636 setAccTitle,
637 getAccTitle,
638 setAccDescription,
639 getAccDescription,
640 addSection,
641 getSections,
642 cleanupValue,
643 setShowData,
644 getShowData
645};
646const getStyles = (options) => `
647 .pieCircle{
648 stroke: ${options.pieStrokeColor};
649 stroke-width : ${options.pieStrokeWidth};
650 opacity : ${options.pieOpacity};
651 }
652 .pieOuterCircle{
653 stroke: ${options.pieOuterStrokeColor};
654 stroke-width: ${options.pieOuterStrokeWidth};
655 fill: none;
656 }
657 .pieTitleText {
658 text-anchor: middle;
659 font-size: ${options.pieTitleTextSize};
660 fill: ${options.pieTitleTextColor};
661 font-family: ${options.fontFamily};
662 }
663 .slice {
664 font-family: ${options.fontFamily};
665 fill: ${options.pieSectionTextColor};
666 font-size:${options.pieSectionTextSize};
667 // fill: white;
668 }
669 .legend text {
670 fill: ${options.pieLegendTextColor};
671 font-family: ${options.fontFamily};
672 font-size: ${options.pieLegendTextSize};
673 }
674`;
675const styles = getStyles;
676const createPieArcs = (sections2) => {
677 const pieData = Object.entries(sections2).map((element) => {
678 return {
679 label: element[0],
680 value: element[1]
681 };
682 }).sort((a, b) => {
683 return b.value - a.value;
684 });
685 const pie = d3pie().value(
686 (d3Section) => d3Section.value
687 );
688 return pie(pieData);
689};
690const draw = (text, id, _version, diagObj) => {
691 log.debug("rendering pie chart\n" + text);
692 const db2 = diagObj.db;
693 const globalConfig = getConfig$1();
694 const pieConfig = cleanAndMerge(db2.getConfig(), globalConfig.pie);
695 const MARGIN = 40;
696 const LEGEND_RECT_SIZE = 18;
697 const LEGEND_SPACING = 4;
698 const height = 450;
699 const pieWidth = height;
700 const svg = selectSvgElement(id);
701 const group = svg.append("g");
702 const sections2 = db2.getSections();
703 group.attr("transform", "translate(" + pieWidth / 2 + "," + height / 2 + ")");
704 const { themeVariables } = globalConfig;
705 let [outerStrokeWidth] = parseFontSize(themeVariables.pieOuterStrokeWidth);
706 outerStrokeWidth ?? (outerStrokeWidth = 2);
707 const textPosition = pieConfig.textPosition;
708 const radius = Math.min(pieWidth, height) / 2 - MARGIN;
709 const arcGenerator = d3arc().innerRadius(0).outerRadius(radius);
710 const labelArcGenerator = d3arc().innerRadius(radius * textPosition).outerRadius(radius * textPosition);
711 group.append("circle").attr("cx", 0).attr("cy", 0).attr("r", radius + outerStrokeWidth / 2).attr("class", "pieOuterCircle");
712 const arcs = createPieArcs(sections2);
713 const myGeneratedColors = [
714 themeVariables.pie1,
715 themeVariables.pie2,
716 themeVariables.pie3,
717 themeVariables.pie4,
718 themeVariables.pie5,
719 themeVariables.pie6,
720 themeVariables.pie7,
721 themeVariables.pie8,
722 themeVariables.pie9,
723 themeVariables.pie10,
724 themeVariables.pie11,
725 themeVariables.pie12
726 ];
727 const color = ordinal(myGeneratedColors);
728 group.selectAll("mySlices").data(arcs).enter().append("path").attr("d", arcGenerator).attr("fill", (datum) => {
729 return color(datum.data.label);
730 }).attr("class", "pieCircle");
731 let sum = 0;
732 Object.keys(sections2).forEach((key) => {
733 sum += sections2[key];
734 });
735 group.selectAll("mySlices").data(arcs).enter().append("text").text((datum) => {
736 return (datum.data.value / sum * 100).toFixed(0) + "%";
737 }).attr("transform", (datum) => {
738 return "translate(" + labelArcGenerator.centroid(datum) + ")";
739 }).style("text-anchor", "middle").attr("class", "slice");
740 group.append("text").text(db2.getDiagramTitle()).attr("x", 0).attr("y", -(height - 50) / 2).attr("class", "pieTitleText");
741 const legend = group.selectAll(".legend").data(color.domain()).enter().append("g").attr("class", "legend").attr("transform", (_datum, index) => {
742 const height2 = LEGEND_RECT_SIZE + LEGEND_SPACING;
743 const offset = height2 * color.domain().length / 2;
744 const horizontal = 12 * LEGEND_RECT_SIZE;
745 const vertical = index * height2 - offset;
746 return "translate(" + horizontal + "," + vertical + ")";
747 });
748 legend.append("rect").attr("width", LEGEND_RECT_SIZE).attr("height", LEGEND_RECT_SIZE).style("fill", color).style("stroke", color);
749 legend.data(arcs).append("text").attr("x", LEGEND_RECT_SIZE + LEGEND_SPACING).attr("y", LEGEND_RECT_SIZE - LEGEND_SPACING).text((datum) => {
750 const { label, value } = datum.data;
751 if (db2.getShowData()) {
752 return `${label} [${value}]`;
753 }
754 return label;
755 });
756 const longestTextWidth = Math.max(
757 ...legend.selectAll("text").nodes().map((node) => (node == null ? void 0 : node.getBoundingClientRect().width) ?? 0)
758 );
759 const totalWidth = pieWidth + MARGIN + LEGEND_RECT_SIZE + LEGEND_SPACING + longestTextWidth;
760 svg.attr("viewBox", `0 0 ${totalWidth} ${height}`);
761 configureSvgSize(svg, height, totalWidth, pieConfig.useMaxWidth);
762};
763const renderer = { draw };
764const diagram = {
765 parser: parser$1,
766 db,
767 renderer,
768 styles
769};
770export {
771 diagram
772};