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