9.1 KB472 lines
Blame
1import { imgSnapshotTest } from '../../helpers/util.ts';
2
3describe('Treemap Diagram', () => {
4 it('1: should render a basic treemap', () => {
5 imgSnapshotTest(
6 `treemap-beta
7"Category A"
8 "Item A1": 10
9 "Item A2": 20
10"Category B"
11 "Item B1": 15
12 "Item B2": 25
13 `,
14 {}
15 );
16 });
17
18 it('2: should render a hierarchical treemap', () => {
19 imgSnapshotTest(
20 `treemap-beta
21"Products"
22 "Electronics"
23 "Phones": 50
24 "Computers": 30
25 "Accessories": 20
26 "Clothing"
27 "Men's"
28 "Shirts": 10
29 "Pants": 15
30 "Women's"
31 "Dresses": 20
32 "Skirts": 10
33 `,
34 {}
35 );
36 });
37
38 it('3: should render a treemap with styling using classDef', () => {
39 imgSnapshotTest(
40 `treemap-beta
41"Section 1"
42 "Leaf 1.1": 12
43 "Section 1.2":::class1
44 "Leaf 1.2.1": 12
45"Section 2"
46 "Leaf 2.1": 20:::class1
47 "Leaf 2.2": 25
48 "Leaf 2.3": 12
49
50classDef class1 fill:red,color:blue,stroke:#FFD600;
51 `,
52 {}
53 );
54 });
55
56 it('4: should handle long text that wraps', () => {
57 imgSnapshotTest(
58 `treemap-beta
59"Main Category"
60 "This is a very long item name that should wrap to the next line when rendered in the treemap diagram": 50
61 "Short item": 20
62 `,
63 {}
64 );
65 });
66
67 it('5: should render with a forest theme', () => {
68 imgSnapshotTest(
69 `---
70config:
71 theme: forest
72---
73treemap-beta
74"Category A"
75 "Item A1": 10
76 "Item A2": 20
77"Category B"
78 "Item B1": 15
79 "Item B2": 25
80 `,
81 {}
82 );
83 });
84
85 it('6: should handle multiple levels of nesting', () => {
86 imgSnapshotTest(
87 `treemap-beta
88"Level 1"
89 "Level 2A"
90 "Level 3A": 10
91 "Level 3B": 15
92 "Level 2B"
93 "Level 3C": 20
94 "Level 3D"
95 "Level 4A": 5
96 "Level 4B": 5
97 `,
98 {}
99 );
100 });
101
102 it('7: should handle classDef with multiple styles', () => {
103 imgSnapshotTest(
104 `treemap-beta
105"Main"
106 "A": 20
107 "B":::important
108 "B1": 10
109 "B2": 15
110 "C": 5:::secondary
111
112classDef important fill:#f96,stroke:#333,stroke-width:2px;
113classDef secondary fill:#6cf,stroke:#333,stroke-dasharray:5 5;
114 `,
115 {}
116 );
117 });
118
119 it('8: should handle dollar value formatting with thousands separator', () => {
120 imgSnapshotTest(
121 `---
122config:
123 treemap:
124 valueFormat: "$0,0"
125---
126treemap
127"Budget"
128 "Operations"
129 "Salaries": 700000
130 "Equipment": 200000
131 "Supplies": 100000
132 "Marketing"
133 "Advertising": 400000
134 "Events": 100000
135 `,
136 {}
137 );
138 });
139
140 it('8a: should handle percentage formatting', () => {
141 imgSnapshotTest(
142 `---
143config:
144 treemap:
145 valueFormat: ".1%"
146---
147treemap-beta
148"Market Share"
149 "Company A": 0.35
150 "Company B": 0.25
151 "Company C": 0.15
152 "Others": 0.25
153 `,
154 {}
155 );
156 });
157
158 it('8b: should handle decimal formatting', () => {
159 imgSnapshotTest(
160 `---
161config:
162 treemap:
163 valueFormat: ".2f"
164---
165treemap-beta
166"Metrics"
167 "Conversion Rate": 0.0567
168 "Bounce Rate": 0.6723
169 "Click-through Rate": 0.1289
170 "Engagement": 0.4521
171 `,
172 {}
173 );
174 });
175
176 it('8c: should handle dollar sign with decimal places', () => {
177 imgSnapshotTest(
178 `---
179config:
180 treemap:
181 valueFormat: "$.2f"
182---
183treemap-beta
184"Product Prices"
185 "Basic": 19.99
186 "Standard": 49.99
187 "Premium": 99.99
188 "Enterprise": 199.99
189 `,
190 {}
191 );
192 });
193
194 it('8d: should handle dollar sign with thousands separator and decimal places', () => {
195 imgSnapshotTest(
196 `---
197config:
198 treemap:
199 valueFormat: "$,.2f"
200---
201treemap-beta
202"Revenue"
203 "Q1": 1250345.75
204 "Q2": 1645789.25
205 "Q3": 1845123.50
206 "Q4": 2145678.75
207 `,
208 {}
209 );
210 });
211
212 it('8e: should handle simple thousands separator', () => {
213 imgSnapshotTest(
214 `---
215config:
216 treemap:
217 valueFormat: ","
218---
219treemap-beta
220"User Counts"
221 "Active Users": 1250345
222 "New Signups": 45789
223 "Churned": 12350
224 "Converted": 78975
225 `,
226 {}
227 );
228 });
229
230 it('8f: should handle valueFormat set via directive with dollar and thousands separator', () => {
231 imgSnapshotTest(
232 `---
233config:
234 treemap:
235 valueFormat: "$,.0f"
236---
237treemap-beta
238"Sales by Region"
239 "North": 1234567
240 "South": 7654321
241 "East": 4567890
242 "West": 9876543
243 `,
244 {}
245 );
246 });
247
248 it('8g: should handle scientific notation format', () => {
249 imgSnapshotTest(
250 `---
251config:
252 treemap:
253 valueFormat: ".2e"
254---
255treemap-beta
256"Scientific Values"
257 "Value 1": 1234567
258 "Value 2": 0.0000123
259 "Value 3": 1000000000
260 `,
261 {}
262 );
263 });
264
265 it('9: should handle a complex example with multiple features', () => {
266 imgSnapshotTest(
267 `---
268config:
269 theme: dark
270 treemap:
271 valueFormat: "$0,0"
272---
273treemap-beta
274"Company Budget"
275 "Engineering":::engineering
276 "Frontend": 300000
277 "Backend": 400000
278 "DevOps": 200000
279 "Marketing":::marketing
280 "Digital": 250000
281 "Print": 100000
282 "Events": 150000
283 "Sales":::sales
284 "Direct": 500000
285 "Channel": 300000
286
287classDef engineering fill:#6b9bc3,stroke:#333;
288classDef marketing fill:#c36b9b,stroke:#333;
289classDef sales fill:#c3a66b,stroke:#333;
290 `,
291 {}
292 );
293 });
294
295 it('10: should render the example from documentation', () => {
296 imgSnapshotTest(
297 `
298 treemap-beta
299 "Section 1"
300 "Leaf 1.1": 12
301 "Section 1.2":::class1
302 "Leaf 1.2.1": 12
303 "Section 2"
304 "Leaf 2.1": 20:::class1
305 "Leaf 2.2": 25
306 "Leaf 2.3": 12
307
308 classDef class1 fill:red,color:blue,stroke:#FFD600;
309 `,
310 {}
311 );
312 });
313
314 it('11: should handle comments', () => {
315 imgSnapshotTest(
316 `
317 treemap-beta
318 %% This is a comment
319 "Category A"
320 "Item A1": 10
321 "Item A2": 20
322 %% Another comment
323 "Category B"
324 "Item B1": 15
325 "Item B2": 25
326 `,
327 {}
328 );
329 });
330
331 it('12: should apply classDef fill color to leaf nodes', () => {
332 imgSnapshotTest(
333 `treemap-beta
334"Root"
335 "Item A": 30:::redClass
336 "Item B": 20
337 "Item C": 25:::blueClass
338
339classDef redClass fill:#ff0000;
340classDef blueClass fill:#0000ff;
341 `,
342 {}
343 );
344 });
345
346 it('13: should apply classDef stroke styles to sections', () => {
347 imgSnapshotTest(
348 `treemap-beta
349 %% This is a comment
350 "Category A":::thickBorder
351 "Item A1": 10
352 "Item A2": 20
353 %% Another comment
354 "Category B":::dashedBorder
355 "Item B1": 15
356 "Item B2": 25
357
358classDef thickBorder stroke:red,stroke-width:8px;
359classDef dashedBorder stroke:black,stroke-dasharray:5,stroke-width:8px;
360 `,
361 {}
362 );
363 });
364
365 it('14: should apply classDef color to text labels', () => {
366 imgSnapshotTest(
367 `treemap-beta
368"Products"
369 "Electronics":::whiteText
370 "Phones": 40
371 "Laptops": 30
372 "Furniture":::darkText
373 "Chairs": 25
374 "Tables": 20
375
376classDef whiteText fill:#2c3e50,color:#ffffff;
377classDef darkText fill:#ecf0f1,color:#000000;
378 `,
379 {}
380 );
381 });
382
383 it('15: should apply multiple classDef properties simultaneously', () => {
384 imgSnapshotTest(
385 `treemap-beta
386"Budget"
387 "Critical":::critical
388 "Server Costs": 50000
389 "Salaries": 80000
390 "Normal":::normal
391 "Office Supplies": 5000
392 "Marketing": 15000
393classDef critical fill:#e74c3c,color:#fff,stroke:#c0392b,stroke-width:3px;
394classDef normal fill:#3498db,color:#fff,stroke:#2980b9,stroke-width:1px;
395 `,
396 {}
397 );
398 });
399
400 it('16: should handle classDef on nested sections and leaves', () => {
401 imgSnapshotTest(
402 `treemap-beta
403"Company"
404 "Engineering":::engSection
405 "Frontend": 30:::highlight
406 "Backend": 40
407 "DevOps": 20:::highlight
408 "Sales"
409 "Direct": 35
410 "Channel": 25:::highlight
411
412classDef engSection fill:#9b59b6,stroke:#8e44ad,stroke-width:2px;
413classDef highlight fill:#f39c12,color:#000,stroke:#e67e22,stroke-width:2px;
414 `,
415 {}
416 );
417 });
418
419 /*
420 it.skip('17: should render a treemap with title', () => {
421 imgSnapshotTest(
422 `
423 treemap-beta
424 title Treemap with Title
425 "Category A"
426 "Item A1": 10
427 "Item A2": 20
428 "Category B"
429 "Item B1": 15
430 "Item B2": 25
431 `,
432 {}
433 );
434 });
435
436 it.skip('13: should render a treemap with accessibility attributes', () => {
437 imgSnapshotTest(
438 `
439 treemap-beta
440 accTitle: Accessible Treemap Title
441 accDescr: This is a description of the treemap for accessibility purposes
442 "Category A"
443 "Item A1": 10
444 "Item A2": 20
445 "Category B"
446 "Item B1": 15
447 "Item B2": 25
448 `,
449 {}
450 );
451 });
452
453 it.skip('14: should render a treemap with title and accessibility attributes', () => {
454 imgSnapshotTest(
455 `
456 treemap
457 title Treemap with Title and Accessibility
458 accTitle: Accessible Treemap Title
459 accDescr: This is a description of the treemap for accessibility purposes
460 "Category A"
461 "Item A1": 10
462 "Item A2": 20
463 "Category B"
464 "Item B1": 15
465 "Item B2": 25
466 `,
467 {}
468 );
469 });
470 */
471});
472