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