File size: 101,770 Bytes
f56a29b | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 1765 1766 1767 1768 1769 1770 1771 1772 1773 1774 1775 1776 1777 1778 1779 1780 1781 1782 1783 1784 1785 1786 1787 1788 1789 1790 1791 1792 1793 1794 1795 1796 1797 1798 1799 1800 1801 1802 1803 1804 1805 1806 1807 1808 1809 1810 1811 1812 1813 1814 1815 1816 1817 1818 1819 1820 1821 1822 1823 1824 1825 1826 1827 1828 1829 1830 1831 1832 1833 1834 1835 1836 1837 1838 1839 1840 1841 1842 1843 1844 1845 1846 1847 1848 1849 1850 1851 1852 1853 1854 1855 1856 1857 1858 1859 1860 1861 1862 1863 1864 1865 1866 1867 1868 1869 1870 1871 1872 1873 1874 1875 1876 1877 1878 1879 1880 1881 1882 1883 1884 1885 1886 1887 1888 1889 1890 1891 1892 1893 1894 1895 1896 1897 1898 1899 1900 1901 1902 1903 1904 1905 1906 1907 1908 1909 1910 1911 1912 1913 1914 1915 1916 1917 1918 1919 1920 1921 1922 1923 1924 1925 1926 1927 1928 1929 1930 1931 1932 1933 1934 1935 1936 1937 1938 1939 1940 1941 1942 1943 1944 1945 1946 1947 1948 1949 1950 1951 1952 1953 1954 1955 1956 1957 1958 1959 1960 1961 1962 1963 1964 1965 1966 1967 1968 1969 1970 1971 1972 1973 1974 1975 1976 1977 1978 1979 1980 1981 1982 1983 1984 1985 1986 1987 1988 1989 1990 1991 1992 1993 1994 1995 1996 1997 1998 1999 2000 2001 2002 2003 2004 2005 2006 2007 2008 2009 2010 2011 2012 2013 2014 2015 2016 2017 2018 2019 2020 2021 2022 2023 2024 2025 2026 2027 2028 2029 2030 2031 2032 2033 2034 2035 2036 2037 2038 2039 2040 2041 2042 2043 | /**
* PptxGenJS: Chart Generation
*/
import {
AXIS_ID_CATEGORY_PRIMARY,
AXIS_ID_CATEGORY_SECONDARY,
AXIS_ID_SERIES_PRIMARY,
AXIS_ID_VALUE_PRIMARY,
AXIS_ID_VALUE_SECONDARY,
BARCHART_COLORS,
CHART_NAME,
CHART_TYPE,
DEF_CHART_GRIDLINE,
DEF_FONT_COLOR,
DEF_FONT_SIZE,
DEF_FONT_TITLE_SIZE,
DEF_SHAPE_SHADOW,
LETTERS,
ONEPT,
} from './core-enums'
import { IChartOptsLib, ISlideRelChart, ShadowProps, IChartPropsTitle, OptsChartGridLine, IOptsChartData, ChartLineCap } from './core-interfaces'
import { createColorElement, genXmlColorSelection, convertRotationDegrees, encodeXmlEntities, getUuid, valToPts } from './gen-utils'
import JSZip from 'jszip'
/**
* Based on passed data, creates Excel Worksheet that is used as a data source for a chart.
* @param {ISlideRelChart} chartObject - chart object
* @param {JSZip} zip - file that the resulting XLSX should be added to
* @return {Promise} promise of generating the XLSX file
*/
export async function createExcelWorksheet (chartObject: ISlideRelChart, zip: JSZip): Promise<string> {
const data = chartObject.data
return await new Promise((resolve, reject) => {
const zipExcel = new JSZip()
const intBubbleCols = (data.length - 1) * 2 + 1 // 1 for "X-Values", then 2 for every Y-Axis
const IS_MULTI_CAT_AXES = data[0]?.labels?.length > 1
// A: Add folders
zipExcel.folder('_rels')
zipExcel.folder('docProps')
zipExcel.folder('xl/_rels')
zipExcel.folder('xl/tables')
zipExcel.folder('xl/theme')
zipExcel.folder('xl/worksheets')
zipExcel.folder('xl/worksheets/_rels')
// B: Add core contents
{
zipExcel.file(
'[Content_Types].xml',
'<?xml version="1.0" encoding="UTF-8" standalone="yes"?><Types xmlns="http://schemas.openxmlformats.org/package/2006/content-types">' +
' <Default Extension="rels" ContentType="application/vnd.openxmlformats-package.relationships+xml"/>' +
' <Default Extension="xml" ContentType="application/xml"/>' +
' <Override PartName="/xl/workbook.xml" ContentType="application/vnd.openxmlformats-officedocument.spreadsheetml.sheet.main+xml"/>' +
' <Override PartName="/xl/worksheets/sheet1.xml" ContentType="application/vnd.openxmlformats-officedocument.spreadsheetml.worksheet+xml"/>' +
' <Override PartName="/xl/theme/theme1.xml" ContentType="application/vnd.openxmlformats-officedocument.theme+xml"/>' +
' <Override PartName="/xl/styles.xml" ContentType="application/vnd.openxmlformats-officedocument.spreadsheetml.styles+xml"/>' +
' <Override PartName="/xl/sharedStrings.xml" ContentType="application/vnd.openxmlformats-officedocument.spreadsheetml.sharedStrings+xml"/>' +
' <Override PartName="/xl/tables/table1.xml" ContentType="application/vnd.openxmlformats-officedocument.spreadsheetml.table+xml"/>' +
' <Override PartName="/docProps/core.xml" ContentType="application/vnd.openxmlformats-package.core-properties+xml"/>' +
' <Override PartName="/docProps/app.xml" ContentType="application/vnd.openxmlformats-officedocument.extended-properties+xml"/>' +
'</Types>\n'
)
zipExcel.file(
'_rels/.rels',
'<?xml version="1.0" encoding="UTF-8" standalone="yes"?><Relationships xmlns="http://schemas.openxmlformats.org/package/2006/relationships">' +
'<Relationship Id="rId1" Type="http://schemas.openxmlformats.org/package/2006/relationships/metadata/core-properties" Target="docProps/core.xml"/>' +
'<Relationship Id="rId2" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/extended-properties" Target="docProps/app.xml"/>' +
'<Relationship Id="rId3" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/officeDocument" Target="xl/workbook.xml"/>' +
'</Relationships>\n'
)
zipExcel.file(
'docProps/app.xml',
'<?xml version="1.0" encoding="UTF-8" standalone="yes"?><Properties xmlns="http://schemas.openxmlformats.org/officeDocument/2006/extended-properties" xmlns:vt="http://schemas.openxmlformats.org/officeDocument/2006/docPropsVTypes">' +
'<Application>Microsoft Macintosh Excel</Application>' +
'<DocSecurity>0</DocSecurity>' +
'<ScaleCrop>false</ScaleCrop>' +
'<HeadingPairs><vt:vector size="2" baseType="variant"><vt:variant><vt:lpstr>Worksheets</vt:lpstr></vt:variant><vt:variant><vt:i4>1</vt:i4></vt:variant></vt:vector></HeadingPairs>' +
'<TitlesOfParts><vt:vector size="1" baseType="lpstr"><vt:lpstr>Sheet1</vt:lpstr></vt:vector></TitlesOfParts>' +
'<Company></Company><LinksUpToDate>false</LinksUpToDate><SharedDoc>false</SharedDoc><HyperlinksChanged>false</HyperlinksChanged><AppVersion>16.0300</AppVersion>' +
'</Properties>\n'
)
zipExcel.file(
'docProps/core.xml',
'<?xml version="1.0" encoding="UTF-8" standalone="yes"?><cp:coreProperties xmlns:cp="http://schemas.openxmlformats.org/package/2006/metadata/core-properties" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:dcterms="http://purl.org/dc/terms/" xmlns:dcmitype="http://purl.org/dc/dcmitype/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">' +
'<dc:creator>PptxGenJS</dc:creator>' +
'<cp:lastModifiedBy>PptxGenJS</cp:lastModifiedBy>' +
'<dcterms:created xsi:type="dcterms:W3CDTF">' +
new Date().toISOString() +
'</dcterms:created>' +
'<dcterms:modified xsi:type="dcterms:W3CDTF">' +
new Date().toISOString() +
'</dcterms:modified>' +
'</cp:coreProperties>'
)
zipExcel.file(
'xl/_rels/workbook.xml.rels',
'<?xml version="1.0" encoding="UTF-8" standalone="yes"?>' +
'<Relationships xmlns="http://schemas.openxmlformats.org/package/2006/relationships">' +
'<Relationship Id="rId3" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/styles" Target="styles.xml"/>' +
'<Relationship Id="rId2" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/theme" Target="theme/theme1.xml"/>' +
'<Relationship Id="rId1" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/worksheet" Target="worksheets/sheet1.xml"/>' +
'<Relationship Id="rId4" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/sharedStrings" Target="sharedStrings.xml"/>' +
'</Relationships>'
)
zipExcel.file(
'xl/styles.xml',
'<?xml version="1.0" encoding="UTF-8" standalone="yes"?><styleSheet xmlns="http://schemas.openxmlformats.org/spreadsheetml/2006/main"><numFmts count="1"><numFmt numFmtId="0" formatCode="General"/></numFmts><fonts count="4"><font><sz val="9"/><color indexed="8"/><name val="Geneva"/></font><font><sz val="9"/><color indexed="8"/><name val="Geneva"/></font><font><sz val="10"/><color indexed="8"/><name val="Geneva"/></font><font><sz val="18"/><color indexed="8"/>' +
'<name val="Arial"/></font></fonts><fills count="2"><fill><patternFill patternType="none"/></fill><fill><patternFill patternType="gray125"/></fill></fills><borders count="1"><border><left/><right/><top/><bottom/><diagonal/></border></borders><dxfs count="0"/><tableStyles count="0"/><colors><indexedColors><rgbColor rgb="ff000000"/><rgbColor rgb="ffffffff"/><rgbColor rgb="ffff0000"/><rgbColor rgb="ff00ff00"/><rgbColor rgb="ff0000ff"/>' +
'<rgbColor rgb="ffffff00"/><rgbColor rgb="ffff00ff"/><rgbColor rgb="ff00ffff"/><rgbColor rgb="ff000000"/><rgbColor rgb="ffffffff"/><rgbColor rgb="ff878787"/><rgbColor rgb="fff9f9f9"/></indexedColors></colors></styleSheet>\n'
)
zipExcel.file(
'xl/theme/theme1.xml',
'<?xml version="1.0" encoding="UTF-8" standalone="yes"?><a:theme xmlns:a="http://schemas.openxmlformats.org/drawingml/2006/main" name="Office Theme"><a:themeElements><a:clrScheme name="Office"><a:dk1><a:sysClr val="windowText" lastClr="000000"/></a:dk1><a:lt1><a:sysClr val="window" lastClr="FFFFFF"/></a:lt1><a:dk2><a:srgbClr val="44546A"/></a:dk2><a:lt2><a:srgbClr val="E7E6E6"/></a:lt2><a:accent1><a:srgbClr val="4472C4"/></a:accent1><a:accent2><a:srgbClr val="ED7D31"/></a:accent2><a:accent3><a:srgbClr val="A5A5A5"/></a:accent3><a:accent4><a:srgbClr val="FFC000"/></a:accent4><a:accent5><a:srgbClr val="5B9BD5"/></a:accent5><a:accent6><a:srgbClr val="70AD47"/></a:accent6><a:hlink><a:srgbClr val="0563C1"/></a:hlink><a:folHlink><a:srgbClr val="954F72"/></a:folHlink></a:clrScheme><a:fontScheme name="Office"><a:majorFont><a:latin typeface="Calibri Light" panose="020F0302020204030204"/><a:ea typeface=""/><a:cs typeface=""/><a:font script="Jpan" typeface="Yu Gothic Light"/><a:font script="Hang" typeface="맑은 고딕"/><a:font script="Hans" typeface="DengXian Light"/><a:font script="Hant" typeface="新細明體"/><a:font script="Arab" typeface="Times New Roman"/><a:font script="Hebr" typeface="Times New Roman"/><a:font script="Thai" typeface="Tahoma"/><a:font script="Ethi" typeface="Nyala"/><a:font script="Beng" typeface="Vrinda"/><a:font script="Gujr" typeface="Shruti"/><a:font script="Khmr" typeface="MoolBoran"/><a:font script="Knda" typeface="Tunga"/><a:font script="Guru" typeface="Raavi"/><a:font script="Cans" typeface="Euphemia"/><a:font script="Cher" typeface="Plantagenet Cherokee"/><a:font script="Yiii" typeface="Microsoft Yi Baiti"/><a:font script="Tibt" typeface="Microsoft Himalaya"/><a:font script="Thaa" typeface="MV Boli"/><a:font script="Deva" typeface="Mangal"/><a:font script="Telu" typeface="Gautami"/><a:font script="Taml" typeface="Latha"/><a:font script="Syrc" typeface="Estrangelo Edessa"/><a:font script="Orya" typeface="Kalinga"/><a:font script="Mlym" typeface="Kartika"/><a:font script="Laoo" typeface="DokChampa"/><a:font script="Sinh" typeface="Iskoola Pota"/><a:font script="Mong" typeface="Mongolian Baiti"/><a:font script="Viet" typeface="Times New Roman"/><a:font script="Uigh" typeface="Microsoft Uighur"/><a:font script="Geor" typeface="Sylfaen"/></a:majorFont><a:minorFont><a:latin typeface="Calibri" panose="020F0502020204030204"/><a:ea typeface=""/><a:cs typeface=""/><a:font script="Jpan" typeface="Yu Gothic"/><a:font script="Hang" typeface="맑은 고딕"/><a:font script="Hans" typeface="DengXian"/><a:font script="Hant" typeface="新細明體"/><a:font script="Arab" typeface="Arial"/><a:font script="Hebr" typeface="Arial"/><a:font script="Thai" typeface="Tahoma"/><a:font script="Ethi" typeface="Nyala"/><a:font script="Beng" typeface="Vrinda"/><a:font script="Gujr" typeface="Shruti"/><a:font script="Khmr" typeface="DaunPenh"/><a:font script="Knda" typeface="Tunga"/><a:font script="Guru" typeface="Raavi"/><a:font script="Cans" typeface="Euphemia"/><a:font script="Cher" typeface="Plantagenet Cherokee"/><a:font script="Yiii" typeface="Microsoft Yi Baiti"/><a:font script="Tibt" typeface="Microsoft Himalaya"/><a:font script="Thaa" typeface="MV Boli"/><a:font script="Deva" typeface="Mangal"/><a:font script="Telu" typeface="Gautami"/><a:font script="Taml" typeface="Latha"/><a:font script="Syrc" typeface="Estrangelo Edessa"/><a:font script="Orya" typeface="Kalinga"/><a:font script="Mlym" typeface="Kartika"/><a:font script="Laoo" typeface="DokChampa"/><a:font script="Sinh" typeface="Iskoola Pota"/><a:font script="Mong" typeface="Mongolian Baiti"/><a:font script="Viet" typeface="Arial"/><a:font script="Uigh" typeface="Microsoft Uighur"/><a:font script="Geor" typeface="Sylfaen"/></a:minorFont></a:fontScheme><a:fmtScheme name="Office"><a:fillStyleLst><a:solidFill><a:schemeClr val="phClr"/></a:solidFill><a:gradFill rotWithShape="1"><a:gsLst><a:gs pos="0"><a:schemeClr val="phClr"><a:lumMod val="110000"/><a:satMod val="105000"/><a:tint val="67000"/></a:schemeClr></a:gs><a:gs pos="50000"><a:schemeClr val="phClr"><a:lumMod val="105000"/><a:satMod val="103000"/><a:tint val="73000"/></a:schemeClr></a:gs><a:gs pos="100000"><a:schemeClr val="phClr"><a:lumMod val="105000"/><a:satMod val="109000"/><a:tint val="81000"/></a:schemeClr></a:gs></a:gsLst><a:lin ang="5400000" scaled="0"/></a:gradFill><a:gradFill rotWithShape="1"><a:gsLst><a:gs pos="0"><a:schemeClr val="phClr"><a:satMod val="103000"/><a:lumMod val="102000"/><a:tint val="94000"/></a:schemeClr></a:gs><a:gs pos="50000"><a:schemeClr val="phClr"><a:satMod val="110000"/><a:lumMod val="100000"/><a:shade val="100000"/></a:schemeClr></a:gs><a:gs pos="100000"><a:schemeClr val="phClr"><a:lumMod val="99000"/><a:satMod val="120000"/><a:shade val="78000"/></a:schemeClr></a:gs></a:gsLst><a:lin ang="5400000" scaled="0"/></a:gradFill></a:fillStyleLst><a:lnStyleLst><a:ln w="6350" cap="flat" cmpd="sng" algn="ctr"><a:solidFill><a:schemeClr val="phClr"/></a:solidFill><a:prstDash val="solid"/><a:miter lim="800000"/></a:ln><a:ln w="12700" cap="flat" cmpd="sng" algn="ctr"><a:solidFill><a:schemeClr val="phClr"/></a:solidFill><a:prstDash val="solid"/><a:miter lim="800000"/></a:ln><a:ln w="19050" cap="flat" cmpd="sng" algn="ctr"><a:solidFill><a:schemeClr val="phClr"/></a:solidFill><a:prstDash val="solid"/><a:miter lim="800000"/></a:ln></a:lnStyleLst><a:effectStyleLst><a:effectStyle><a:effectLst/></a:effectStyle><a:effectStyle><a:effectLst/></a:effectStyle><a:effectStyle><a:effectLst><a:outerShdw blurRad="57150" dist="19050" dir="5400000" algn="ctr" rotWithShape="0"><a:srgbClr val="000000"><a:alpha val="63000"/></a:srgbClr></a:outerShdw></a:effectLst></a:effectStyle></a:effectStyleLst><a:bgFillStyleLst><a:solidFill><a:schemeClr val="phClr"/></a:solidFill><a:solidFill><a:schemeClr val="phClr"><a:tint val="95000"/><a:satMod val="170000"/></a:schemeClr></a:solidFill><a:gradFill rotWithShape="1"><a:gsLst><a:gs pos="0"><a:schemeClr val="phClr"><a:tint val="93000"/><a:satMod val="150000"/><a:shade val="98000"/><a:lumMod val="102000"/></a:schemeClr></a:gs><a:gs pos="50000"><a:schemeClr val="phClr"><a:tint val="98000"/><a:satMod val="130000"/><a:shade val="90000"/><a:lumMod val="103000"/></a:schemeClr></a:gs><a:gs pos="100000"><a:schemeClr val="phClr"><a:shade val="63000"/><a:satMod val="120000"/></a:schemeClr></a:gs></a:gsLst><a:lin ang="5400000" scaled="0"/></a:gradFill></a:bgFillStyleLst></a:fmtScheme></a:themeElements><a:objectDefaults/><a:extraClrSchemeLst/><a:extLst><a:ext uri="{05A4C25C-085E-4340-85A3-A5531E510DB2}"><thm15:themeFamily xmlns:thm15="http://schemas.microsoft.com/office/thememl/2012/main" name="Office Theme" id="{62F939B6-93AF-4DB8-9C6B-D6C7DFDC589F}" vid="{4A3C46E8-61CC-4603-A589-7422A47A8E4A}"/></a:ext></a:extLst></a:theme>'
)
zipExcel.file(
'xl/workbook.xml',
'<?xml version="1.0" encoding="UTF-8" standalone="yes"?>' +
'<workbook xmlns="http://schemas.openxmlformats.org/spreadsheetml/2006/main" xmlns:r="http://schemas.openxmlformats.org/officeDocument/2006/relationships" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" mc:Ignorable="x15" xmlns:x15="http://schemas.microsoft.com/office/spreadsheetml/2010/11/main">' +
'<fileVersion appName="xl" lastEdited="7" lowestEdited="6" rupBuild="10507"/>' +
'<workbookPr/>' +
'<bookViews><workbookView xWindow="0" yWindow="500" windowWidth="20960" windowHeight="15960"/></bookViews>' +
'<sheets><sheet name="Sheet1" sheetId="1" r:id="rId1"/></sheets>' +
'<calcPr calcId="0" concurrentCalc="0"/>' +
'</workbook>\n'
)
zipExcel.file(
'xl/worksheets/_rels/sheet1.xml.rels',
'<?xml version="1.0" encoding="UTF-8" standalone="yes"?>' +
'<Relationships xmlns="http://schemas.openxmlformats.org/package/2006/relationships">' +
'<Relationship Id="rId1" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/table" Target="../tables/table1.xml"/>' +
'</Relationships>\n'
)
}
// sharedStrings.xml
{
// A: Start XML
let strSharedStrings = '<?xml version="1.0" encoding="UTF-8" standalone="yes"?>'
if (chartObject.opts._type === CHART_TYPE.BUBBLE || chartObject.opts._type === CHART_TYPE.BUBBLE3D) {
strSharedStrings += `<sst xmlns="http://schemas.openxmlformats.org/spreadsheetml/2006/main" count="${intBubbleCols}" uniqueCount="${intBubbleCols}">`
} else if (chartObject.opts._type === CHART_TYPE.SCATTER) {
strSharedStrings += `<sst xmlns="http://schemas.openxmlformats.org/spreadsheetml/2006/main" count="${data.length}" uniqueCount="${data.length}">`
} else if (IS_MULTI_CAT_AXES) {
let totCount = data.length
data[0].labels.forEach(arrLabel => (totCount += arrLabel.filter(label => label && label !== '').length))
strSharedStrings += `<sst xmlns="http://schemas.openxmlformats.org/spreadsheetml/2006/main" count="${totCount}" uniqueCount="${totCount}">`
strSharedStrings += '<si><t/></si>'
} else {
// series names + all labels of one series + number of label groups (data.labels.length) of one series (i.e. how many times the blank string is used)
const totCount = data.length + data[0].labels.length * data[0].labels[0].length + data[0].labels.length
// series names + labels of one series + blank string (same for all label groups)
const unqCount = data.length + data[0].labels.length * data[0].labels[0].length + 1
// start `sst`
strSharedStrings += `<sst xmlns="http://schemas.openxmlformats.org/spreadsheetml/2006/main" count="${totCount}" uniqueCount="${unqCount}">`
// B: Add 'blank' for A1, B1, ..., of every label group inside data[n].labels
strSharedStrings += '<si><t xml:space="preserve"></t></si>'
}
// C: Add `name`/Series
if (chartObject.opts._type === CHART_TYPE.BUBBLE || chartObject.opts._type === CHART_TYPE.BUBBLE3D) {
data.forEach((objData, idx) => {
if (idx === 0) strSharedStrings += '<si><t>X-Axis</t></si>'
else {
strSharedStrings += `<si><t>${encodeXmlEntities(objData.name || `Y-Axis${idx}`)}</t></si>`
strSharedStrings += `<si><t>${encodeXmlEntities(`Size${idx}`)}</t></si>`
}
})
} else {
data.forEach(objData => {
strSharedStrings += `<si><t>${encodeXmlEntities((objData.name || ' ').replace('X-Axis', 'X-Values'))}</t></si>`
})
}
// D: Add `labels`/Categories
if (chartObject.opts._type !== CHART_TYPE.BUBBLE && chartObject.opts._type !== CHART_TYPE.BUBBLE3D && chartObject.opts._type !== CHART_TYPE.SCATTER) {
// Use forEach backwards & check for '' to support multi-cat axes
data[0].labels
.slice()
.reverse()
.forEach(labelsGroup => {
labelsGroup
.filter(label => label && label !== '')
.forEach(label => {
strSharedStrings += `<si><t>${encodeXmlEntities(label)}</t></si>`
})
})
}
// DONE:
strSharedStrings += '</sst>\n'
zipExcel.file('xl/sharedStrings.xml', strSharedStrings)
}
// tables/table1.xml
{
let strTableXml = '<?xml version="1.0" encoding="UTF-8" standalone="yes"?>'
if (chartObject.opts._type === CHART_TYPE.BUBBLE || chartObject.opts._type === CHART_TYPE.BUBBLE3D) {
strTableXml += `<table xmlns="http://schemas.openxmlformats.org/spreadsheetml/2006/main" id="1" name="Table1" displayName="Table1" ref="A1:${getExcelColName(intBubbleCols)}${intBubbleCols}" totalsRowShown="0">`
strTableXml += `<tableColumns count="${intBubbleCols}">`
let idxColLtr = 1
data.forEach((obj, idx) => {
if (idx === 0) {
strTableXml += `<tableColumn id="${idx + 1}" name="X-Values"/>`
} else {
strTableXml += `<tableColumn id="${idx + idxColLtr}" name="${obj.name}"/>`
idxColLtr++
strTableXml += `<tableColumn id="${idx + idxColLtr}" name="Size${idx}"/>`
}
})
} else if (chartObject.opts._type === CHART_TYPE.SCATTER) {
strTableXml += `<table xmlns="http://schemas.openxmlformats.org/spreadsheetml/2006/main" id="1" name="Table1" displayName="Table1" ref="A1:${getExcelColName(data.length)}${data[0].values.length + 1}" totalsRowShown="0">`
strTableXml += `<tableColumns count="${data.length}">`
data.forEach((_obj, idx) => {
strTableXml += `<tableColumn id="${idx + 1}" name="${idx === 0 ? 'X-Values' : 'Y-Value '}${idx}"/>`
})
} else {
strTableXml += `<table xmlns="http://schemas.openxmlformats.org/spreadsheetml/2006/main" id="1" name="Table1" displayName="Table1" ref="A1:${getExcelColName(data.length + data[0].labels.length)}${data[0].labels[0].length + 1}'" totalsRowShown="0">`
strTableXml += `<tableColumns count="${data.length + data[0].labels.length}">`
data[0].labels.forEach((_labelsGroup, idx) => {
strTableXml += `<tableColumn id="${idx + 1}" name="Column${idx + 1}"/>`
})
data.forEach((obj, idx) => {
strTableXml += `<tableColumn id="${idx + data[0].labels.length + 1}" name="${encodeXmlEntities(obj.name)}"/>`
})
}
strTableXml += '</tableColumns>'
strTableXml += '<tableStyleInfo showFirstColumn="0" showLastColumn="0" showRowStripes="1" showColumnStripes="0"/>'
strTableXml += '</table>'
zipExcel.file('xl/tables/table1.xml', strTableXml)
}
// worksheets/sheet1.xml
{
let strSheetXml = '<?xml version="1.0" encoding="UTF-8" standalone="yes"?>'
strSheetXml +=
'<worksheet xmlns="http://schemas.openxmlformats.org/spreadsheetml/2006/main" xmlns:r="http://schemas.openxmlformats.org/officeDocument/2006/relationships" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" mc:Ignorable="x14ac" xmlns:x14ac="http://schemas.microsoft.com/office/spreadsheetml/2009/9/ac">'
if (chartObject.opts._type === CHART_TYPE.BUBBLE || chartObject.opts._type === CHART_TYPE.BUBBLE3D) {
strSheetXml += `<dimension ref="A1:${getExcelColName(intBubbleCols)}${data[0].values.length + 1}"/>`
} else if (chartObject.opts._type === CHART_TYPE.SCATTER) {
strSheetXml += `<dimension ref="A1:${getExcelColName(data.length)}${data[0].values.length + 1}"/>`
} else {
strSheetXml += `<dimension ref="A1:${getExcelColName(data.length + 1)}${data[0].values.length + 1}"/>`
}
strSheetXml += '<sheetViews><sheetView tabSelected="1" workbookViewId="0"><selection activeCell="B1" sqref="B1"/></sheetView></sheetViews>'
strSheetXml += '<sheetFormatPr baseColWidth="10" defaultRowHeight="16"/>'
if (chartObject.opts._type === CHART_TYPE.BUBBLE || chartObject.opts._type === CHART_TYPE.BUBBLE3D) {
// UNUSED: strSheetXml += `<cols><col min="1" max="${data.length}" width="11" customWidth="1" /></cols>`
/* EX: INPUT: `data`
[
{ name:'X-Axis' , values:[10,11,12,13,14,15,16,17,18,19,20] },
{ name:'Y-Axis 1', values:[ 1, 6, 7, 8, 9], sizes:[ 4, 5, 6, 7, 8] },
{ name:'Y-Axis 2', values:[33,32,42,53,63], sizes:[11,12,13,14,15] }
];
*/
/* EX: OUTPUT: bubbleChart Worksheet:
-|----A-----|------B-----|------C-----|------D-----|------E-----|
1| X-Values | Y-Values 1 | Y-Sizes 1 | Y-Values 2 | Y-Sizes 2 |
2| 11 | 22 | 4 | 33 | 8 |
-|----------|------------|------------|------------|------------|
*/
strSheetXml += '<sheetData>'
// A: Create header row first (NOTE: Start at index=1 as headers cols start with 'B')
strSheetXml += `<row r="1" spans="1:${intBubbleCols}">`
strSheetXml += '<c r="A1" t="s"><v>0</v></c>'
for (let idx = 1; idx < intBubbleCols; idx++) {
strSheetXml += `<c r="${getExcelColName(idx + 1)}1" t="s"><v>${idx}</v></c>` // NOTE: add `t="s"` for label cols!
}
strSheetXml += '</row>'
// B: Add row for each X-Axis value (Y-Axis* value is optional)
data[0].values.forEach((val, idx) => {
// Leading col is reserved for the 'X-Axis' value, so hard-code it, then loop over col values
strSheetXml += `<row r="${idx + 2}" spans="1:${intBubbleCols}">`
strSheetXml += `<c r="A${idx + 2}"><v>${val}</v></c>`
// Add Y-Axis 1->N (idy=0 = Xaxis)
let idxColLtr = 2
for (let idy = 1; idy < data.length; idy++) {
// y-value
strSheetXml += `<c r="${getExcelColName(idxColLtr)}${idx + 2}"><v>${data[idy].values[idx] || ''}</v></c>`
idxColLtr++
// y-size
strSheetXml += `<c r="${getExcelColName(idxColLtr)}${idx + 2}"><v>${data[idy].sizes[idx] || ''}</v></c>`
idxColLtr++
}
strSheetXml += '</row>'
})
} else if (chartObject.opts._type === CHART_TYPE.SCATTER) {
/* UNUSED:
strSheetXml += '<cols>'
strSheetXml += '<col min="1" max="' + data.length + '" width="11" customWidth="1" />'
//data.forEach((obj,idx)=>{ strSheetXml += '<col min="'+(idx+1)+'" max="'+(idx+1)+'" width="11" customWidth="1" />' });
strSheetXml += '</cols>'
*/
/* EX: INPUT: `data`
[
{ name:'X-AxisA', values:[ 1, 2, 3, 4, 5] },
{ name:'Y-AxisB', values:[ 2,22,42,52,62] },
{ name:'Y-AxisC', values:[ 3,33,43,53,63] }
];
*/
/* EX: OUTPUT: sheet1.xml:
-|----A----|----B----|----C----|
1| X-AxisA | Y-AxisB | Y-AxisC |
2| 1 | 2 | 3 |
-|---------|---------|---------|
*/
strSheetXml += '<sheetData>'
// A: Create header row first (every `name` row provided)
strSheetXml += `<row r="1" spans="1:${data.length}">`
for (let idx = 0; idx < data.length; idx++) {
strSheetXml += `<c r="${getExcelColName(idx + 1)}1" t="s"><v>${idx}</v></c>` // NOTE: add `t="s"` for label cols!
}
strSheetXml += '</row>'
// B: Add row for each X-Axis value (Y-Axis* value is optional)
data[0].values.forEach((val, idx) => {
// Leading col is reserved for the 'X-Axis' value, so hard-code it, then loop over col values
strSheetXml += `<row r="${idx + 2}" spans="1:${data.length}">`
strSheetXml += `<c r="A${idx + 2}"><v>${val}</v></c>`
// Add Y-Axis 1->N
for (let idy = 1; idy < data.length; idy++) {
strSheetXml += `<c r="${getExcelColName(idy + 1)}${idx + 2}"><v>${data[idy].values[idx] || data[idy].values[idx] === 0 ? data[idy].values[idx] : ''
}</v></c>`
}
strSheetXml += '</row>'
})
} else {
// strSheetXml += '<cols><col min="1" max="1" width="11" customWidth="1" /></cols>'
strSheetXml += '<sheetData>'
/* EX: INPUT: `data`
[
{ name:'Red', labels:['Jan..May-17'], values:[11,13,14,15,16] },
{ name:'Amb', labels:['Jan..May-17'], values:[22, 6, 7, 8, 9] },
{ name:'Grn', labels:['Jan..May-17'], values:[33,32,42,53,63] }
];
*/
/* EX: OUTPUT: lineChart Worksheet:
-|---A---|--B--|--C--|--D--|
1| | Red | Amb | Grn |
2|Jan-17 | 11| 22| 33|
3|Feb-17 | 55| 43| 70|
4|Mar-17 | 56| 143| 99|
5|Apr-17 | 65| 3| 120|
6|May-17 | 75| 93| 170|
-|-------|-----|-----|-----|
*/
if (!IS_MULTI_CAT_AXES) {
// A: Create header row first
strSheetXml += `<row r="1" spans="1:${data.length + data[0].labels.length}">`
data[0].labels.forEach((_labelsGroup, idx) => {
strSheetXml += `<c r="${getExcelColName(idx + 1)}1" t="s"><v>0</v></c>`
})
for (let idx = 0; idx < data.length; idx++) {
strSheetXml += `<c r="${getExcelColName(idx + 1 + data[0].labels.length)}1" t="s"><v>${idx + 1}</v></c>` // NOTE: use `t="s"` for label cols!
}
strSheetXml += '</row>'
// B: Add data row(s) for each category
data[0].labels[0].forEach((_cat, idx) => {
strSheetXml += `<row r="${idx + 2}" spans="1:${data.length + data[0].labels.length}">`
// Leading cols are reserved for the label groups
for (let idx2 = data[0].labels.length - 1; idx2 >= 0; idx2--) {
strSheetXml += `<c r="${getExcelColName(data[0].labels.length - idx2)}${idx + 2}" t="s">`
strSheetXml += `<v>${data.length + idx + 1}</v>`
strSheetXml += '</c>'
}
for (let idy = 0; idy < data.length; idy++) {
strSheetXml += `<c r="${getExcelColName(data[0].labels.length + idy + 1)}${idx + 2}"><v>${data[idy].values[idx] || ''}</v></c>`
}
strSheetXml += '</row>'
})
} else {
// A: create header row
strSheetXml += `<row r="1" spans="1:${data.length + data[0].labels.length}">`
for (let idx = 0; idx < data[0].labels.length; idx++) {
strSheetXml += `<c r="${getExcelColName(idx + 1)}1" t="s"><v>0</v></c>`
}
for (let idx = data[0].labels.length - 1; idx < data.length + data[0].labels.length - 1; idx++) {
strSheetXml += `<c r="${getExcelColName(idx + data[0].labels.length)}1" t="s"><v>${idx}</v></c>` // NOTE: use `t="s"` for label cols!
}
strSheetXml += '</row>'
// FIXME: 20220524 (v3.11.0)
/**
* @example INPUT
* const LABELS = [
* ["Gear", "Berg", "Motr", "Swch", "Plug", "Cord", "Pump", "Leak", "Seal"],
* ["Mech", "", "", "Elec", "", "", "Hydr", "", ""],
* ];
* const arrDataRegions = [
* { name: "West", labels: LABELS, values: [11, 8, 3, 0, 11, 3, 0, 0, 0] },
* { name: "Ctrl", labels: LABELS, values: [0, 11, 6, 19, 12, 5, 0, 0, 0] },
* { name: "East", labels: LABELS, values: [0, 3, 2, 0, 0, 0, 4, 3, 1] },
* ];
*/
/**
* @example OUTPUT EXCEL SHEET
* |/|---A--|---B--|---C--|---D--|---E--|
* |1| | | West | Ctrl | East |
* |2| Mech | Gear | ## | ## | ## |
* |3| | Brng | ## | ## | ## |
* |4| | Motr | ## | ## | ## |
* |5| Elec | Swch | ## | ## | ## |
* |6| | Plug | ## | ## | ## |
* |7| | Cord | ## | ## | ## |
* |8| Hydr | Pump | ## | ## | ## |
* |9| | Leak | ## | ## | ## |
*|10| | Seal | ## | ## | ## |
*/
/**
* @example OUTPUT EXCEL SHEET XML
* <row r="1" spans="1:5">
* <c r="A1" t="s"><v>0</v></c>
* <c r="B1" t="s"><v>0</v></c>
* <c r="C1" t="s"><v>1</v></c>
* <c r="D1" t="s"><v>2</v></c>
* <c r="E1" t="s"><v>3</v></c>
* </row>
* <row r="2" spans="1:5">
* <c r="A2" t="s"><v>4</v></c>
* <c r="B2" t="s"><v>7</v></c>
* <c r="C2" ><v>###</v></c>
* </row>
* <row r="3" spans="1:5">
* <c r="A3" />
* <c r="B3" t="s"><v>8</v></c>
* <c r="C3" ><v>###</v></c>
* </row>
*/
/**
* @example SHARED-STRINGS
* 1=West, 2=Ctrl, 3=East, 4=Mech, 5=Elec, 6=Mydr, 7=Gear, 8=Brng, [...], 15=Seal
*/
// B: Add data row(s) for each category
/**
* const LABELS = [
* ["Gear", "Berg", "Motr", "Swch", "Plug", "Cord", "Pump", "Leak", "Seal"],
* ["Mech", "", "", "Elec", "", "", "Hydr", "", ""],
* ["2010", "", "", "", "", "", "", "", ""],
* ];
*/
const TOT_SER = data.length
const TOT_CAT = data[0].labels[0].length
const TOT_LVL = data[0].labels.length
// Iterate across labels/cats as these are the <row>'s
for (let idx = 0; idx < TOT_CAT; idx++) {
// A: start row
strSheetXml += `<row r="${idx + 2}" spans="1:${TOT_SER + TOT_LVL}">`
// WIP: FIXME:
// B: add a col for each label/cat
let totLabels = TOT_SER
const revLabelGroups = data[0].labels.slice().reverse()
revLabelGroups.forEach((labelsGroup, idy) => {
/**
* const LABELS_REVERSED = [
* ["Mech", "", "", "Elec", "", "", "Hydr", "", ""],
* ["Gear", "Berg", "Motr", "Swch", "Plug", "Cord", "Pump", "Leak", "Seal"],
* ];
*/
const colLabel = labelsGroup[idx]
if (colLabel) {
const totGrpLbls = idy === 0 ? 1 : revLabelGroups[idy - 1].filter(label => label && label !== '').length // get unique label so we can add to get proper shared-string #
totLabels += totGrpLbls
strSheetXml += `<c r="${getExcelColName(idx + 1 + idy)}${idx + 2}" t="s"><v>${totLabels}</v></c>`
}
})
// WIP: FIXME:
// C: add a col for each data value
for (let idy = 0; idy < TOT_SER; idy++) {
strSheetXml += `<c r="${getExcelColName(TOT_LVL + idy + 1)}${idx + 2}"><v>${data[idy].values[idx] || 0}</v></c>`
}
// D: Done
strSheetXml += '</row>'
}
// console.log(strSheetXml) // WIP: CHECK:
// console.log(`---CHECK ABOVE---------------------`)
}
}
strSheetXml += '</sheetData>'
/* FIXME: support multi-level
if (IS_MULTI_CAT_AXES) {
strSheetXml += '<mergeCells count="3">'
strSheetXml += ' <mergeCell ref="A2:A4"/>'
strSheetXml += ' <mergeCell ref="A10:A12"/>'
strSheetXml += ' <mergeCell ref="A5:A9"/>'
strSheetXml += '</mergeCells>'
}
*/
strSheetXml += '<pageMargins left="0.7" right="0.7" top="0.75" bottom="0.75" header="0.3" footer="0.3"/>'
// Link the `table1.xml` file to define an actual Table in Excel
// NOTE: This only works with scatter charts - all others give a "cannot find linked file" error
// ....: Since we dont need the table anyway (chart data can be edited/range selected, etc.), just dont use this
// ....: Leaving this so nobody foolishly attempts to add this in the future
// strSheetXml += '<tableParts count="1"><tablePart r:id="rId1"/></tableParts>'
strSheetXml += '</worksheet>\n'
zipExcel.file('xl/worksheets/sheet1.xml', strSheetXml)
}
// C: Add XLSX to PPTX export
zipExcel
.generateAsync({ type: 'base64' })
.then(content => {
// 1: Create the embedded Excel worksheet with labels and data
zip.file(`ppt/embeddings/Microsoft_Excel_Worksheet${chartObject.globalId}.xlsx`, content, { base64: true })
// 2: Create the chart.xml and rel files
zip.file(
'ppt/charts/_rels/' + chartObject.fileName + '.rels',
'<?xml version="1.0" encoding="UTF-8" standalone="yes"?>' +
'<Relationships xmlns="http://schemas.openxmlformats.org/package/2006/relationships">' +
`<Relationship Id="rId1" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/package" Target="../embeddings/Microsoft_Excel_Worksheet${chartObject.globalId}.xlsx"/>` +
'</Relationships>'
)
zip.file(`ppt/charts/${chartObject.fileName}`, makeXmlCharts(chartObject))
// 3: Done
resolve('')
})
.catch(strErr => {
reject(strErr)
})
})
}
/**
* Main entry point method for create charts
* @see: http://www.datypic.com/sc/ooxml/s-dml-chart.xsd.html
* @param {ISlideRelChart} rel - chart object
* @return {string} XML
*/
export function makeXmlCharts (rel: ISlideRelChart): string {
let strXml = '<?xml version="1.0" encoding="UTF-8" standalone="yes"?>'
let usesSecondaryValAxis = false
// STEP 1: Create chart
{
// CHARTSPACE: BEGIN vvv
strXml +=
'<c:chartSpace xmlns:c="http://schemas.openxmlformats.org/drawingml/2006/chart" xmlns:a="http://schemas.openxmlformats.org/drawingml/2006/main" xmlns:r="http://schemas.openxmlformats.org/officeDocument/2006/relationships">'
strXml += '<c:date1904 val="0"/>' // ppt defaults to 1904 dates, excel to 1900
strXml += `<c:roundedCorners val="${rel.opts.chartArea.roundedCorners ? '1' : '0'}"/>`
strXml += '<c:chart>'
// OPTION: Title
if (rel.opts.showTitle) {
strXml += genXmlTitle(
{
title: rel.opts.title || 'Chart Title',
color: rel.opts.titleColor,
fontFace: rel.opts.titleFontFace,
fontSize: rel.opts.titleFontSize || DEF_FONT_TITLE_SIZE,
titleAlign: rel.opts.titleAlign,
titleBold: rel.opts.titleBold,
titlePos: rel.opts.titlePos,
titleRotate: rel.opts.titleRotate,
},
rel.opts.x as number,
rel.opts.y as number
)
strXml += '<c:autoTitleDeleted val="0"/>'
} else {
// NOTE: Add autoTitleDeleted tag in else to prevent default creation of chart title even when showTitle is set to false
strXml += '<c:autoTitleDeleted val="1"/>'
}
/** Add 3D view tag
* @see: https://c-rex.net/projects/samples/ooxml/e1/Part4/OOXML_P4_DOCX_perspective_topic_ID0E6BUQB.html
*/
if (rel.opts._type === CHART_TYPE.BAR3D) {
strXml += `<c:view3D><c:rotX val="${rel.opts.v3DRotX}"/><c:rotY val="${rel.opts.v3DRotY}"/><c:rAngAx val="${!rel.opts.v3DRAngAx ? 0 : 1}"/><c:perspective val="${rel.opts.v3DPerspective}"/></c:view3D>`
}
strXml += '<c:plotArea>'
// IMPORTANT: Dont specify layout to enable auto-fit: PPT does a great job maximizing space with all 4 TRBL locations
if (rel.opts.layout) {
strXml += '<c:layout>'
strXml += ' <c:manualLayout>'
strXml += ' <c:layoutTarget val="inner" />'
strXml += ' <c:xMode val="edge" />'
strXml += ' <c:yMode val="edge" />'
strXml += ' <c:x val="' + (rel.opts.layout.x || 0) + '" />'
strXml += ' <c:y val="' + (rel.opts.layout.y || 0) + '" />'
strXml += ' <c:w val="' + (rel.opts.layout.w || 1) + '" />'
strXml += ' <c:h val="' + (rel.opts.layout.h || 1) + '" />'
strXml += ' </c:manualLayout>'
strXml += '</c:layout>'
} else {
strXml += '<c:layout/>'
}
}
// A: Create Chart XML -----------------------------------------------------------
if (Array.isArray(rel.opts._type)) {
rel.opts._type.forEach(type => {
// TODO: FIXME: theres `options` on chart rels??
const options = { ...rel.opts, ...type.options }
// let options: IChartOptsLib = { type: type.type, }
const valAxisId = options.secondaryValAxis ? AXIS_ID_VALUE_SECONDARY : AXIS_ID_VALUE_PRIMARY
const catAxisId = options.secondaryCatAxis ? AXIS_ID_CATEGORY_SECONDARY : AXIS_ID_CATEGORY_PRIMARY
usesSecondaryValAxis = usesSecondaryValAxis || options.secondaryValAxis
strXml += makeChartType(type.type, type.data, options, valAxisId, catAxisId, true)
})
} else {
strXml += makeChartType(rel.opts._type, rel.data, rel.opts, AXIS_ID_VALUE_PRIMARY, AXIS_ID_CATEGORY_PRIMARY, false)
}
// B: Axes -----------------------------------------------------------
if (rel.opts._type !== CHART_TYPE.PIE && rel.opts._type !== CHART_TYPE.DOUGHNUT) {
// Param check
if (rel.opts.valAxes && rel.opts.valAxes.length > 1 && !usesSecondaryValAxis) {
throw new Error('Secondary axis must be used by one of the multiple charts')
}
if (rel.opts.catAxes) {
if (!rel.opts.valAxes || rel.opts.valAxes.length !== rel.opts.catAxes.length) {
throw new Error('There must be the same number of value and category axes.')
}
strXml += makeCatAxis({ ...rel.opts, ...rel.opts.catAxes[0] }, AXIS_ID_CATEGORY_PRIMARY, AXIS_ID_VALUE_PRIMARY)
} else {
strXml += makeCatAxis(rel.opts, AXIS_ID_CATEGORY_PRIMARY, AXIS_ID_VALUE_PRIMARY)
}
if (rel.opts.valAxes) {
strXml += makeValAxis({ ...rel.opts, ...rel.opts.valAxes[0] }, AXIS_ID_VALUE_PRIMARY)
if (rel.opts.valAxes[1]) {
strXml += makeValAxis({ ...rel.opts, ...rel.opts.valAxes[1] }, AXIS_ID_VALUE_SECONDARY)
}
} else {
strXml += makeValAxis(rel.opts, AXIS_ID_VALUE_PRIMARY)
// Add series axis for 3D bar
if (rel.opts._type === CHART_TYPE.BAR3D) {
strXml += makeSerAxis(rel.opts, AXIS_ID_SERIES_PRIMARY, AXIS_ID_VALUE_PRIMARY)
}
}
// Combo Charts: Add secondary axes after all vals
if (rel.opts?.catAxes && rel.opts?.catAxes[1]) {
strXml += makeCatAxis({ ...rel.opts, ...rel.opts.catAxes[1] }, AXIS_ID_CATEGORY_SECONDARY, AXIS_ID_VALUE_SECONDARY)
}
}
// C: Chart Properties and plotArea Options: Border, Data Table, Fill, Legend
{
// NOTE: DataTable goes between '</c:valAx>' and '<c:spPr>'
if (rel.opts.showDataTable) {
strXml += '<c:dTable>'
strXml += ` <c:showHorzBorder val="${!rel.opts.showDataTableHorzBorder ? 0 : 1}"/>`
strXml += ` <c:showVertBorder val="${!rel.opts.showDataTableVertBorder ? 0 : 1}"/>`
strXml += ` <c:showOutline val="${!rel.opts.showDataTableOutline ? 0 : 1}"/>`
strXml += ` <c:showKeys val="${!rel.opts.showDataTableKeys ? 0 : 1}"/>`
strXml += ' <c:spPr>'
strXml += ' <a:noFill/>'
strXml += ' <a:ln w="9525" cap="flat" cmpd="sng" algn="ctr"><a:solidFill><a:schemeClr val="tx1"><a:lumMod val="15000"/><a:lumOff val="85000"/></a:schemeClr></a:solidFill><a:round/></a:ln>'
strXml += ' <a:effectLst/>'
strXml += ' </c:spPr>'
strXml += ' <c:txPr>'
strXml += ' <a:bodyPr rot="0" spcFirstLastPara="1" vertOverflow="ellipsis" vert="horz" wrap="square" anchor="ctr" anchorCtr="1"/>'
strXml += ' <a:lstStyle/>'
strXml += ' <a:p>'
strXml += ' <a:pPr rtl="0">'
strXml += ` <a:defRPr sz="${Math.round((rel.opts.dataTableFontSize || DEF_FONT_SIZE) * 100)}" b="0" i="0" u="none" strike="noStrike" kern="1200" baseline="0">`
strXml += ' <a:solidFill><a:schemeClr val="tx1"><a:lumMod val="65000"/><a:lumOff val="35000"/></a:schemeClr></a:solidFill>'
strXml += ' <a:latin typeface="+mn-lt"/>'
strXml += ' <a:ea typeface="+mn-ea"/>'
strXml += ' <a:cs typeface="+mn-cs"/>'
strXml += ' </a:defRPr>'
strXml += ' </a:pPr>'
strXml += ' <a:endParaRPr lang="en-US"/>'
strXml += ' </a:p>'
strXml += ' </c:txPr>'
strXml += '</c:dTable>'
}
strXml += ' <c:spPr>'
// OPTION: Fill
strXml += rel.opts.plotArea.fill?.color ? genXmlColorSelection(rel.opts.plotArea.fill) : '<a:noFill/>'
// OPTION: Border
strXml += rel.opts.plotArea.border
? `<a:ln w="${valToPts(rel.opts.plotArea.border.pt)}" cap="flat">${genXmlColorSelection(rel.opts.plotArea.border.color)}</a:ln>`
: '<a:ln><a:noFill/></a:ln>'
// Close shapeProp/plotArea before Legend
strXml += ' <a:effectLst/>'
strXml += ' </c:spPr>'
strXml += '</c:plotArea>'
// OPTION: Legend
// IMPORTANT: Dont specify layout to enable auto-fit: PPT does a great job maximizing space with all 4 TRBL locations
if (rel.opts.showLegend) {
strXml += '<c:legend>'
strXml += '<c:legendPos val="' + rel.opts.legendPos + '"/>'
// strXml += '<c:layout/>'
strXml += '<c:overlay val="0"/>'
if (rel.opts.legendFontFace || rel.opts.legendFontSize || rel.opts.legendColor) {
strXml += '<c:txPr>'
strXml += ' <a:bodyPr/>'
strXml += ' <a:lstStyle/>'
strXml += ' <a:p>'
strXml += ' <a:pPr>'
strXml += rel.opts.legendFontSize ? `<a:defRPr sz="${Math.round(Number(rel.opts.legendFontSize) * 100)}">` : '<a:defRPr>'
if (rel.opts.legendColor) strXml += genXmlColorSelection(rel.opts.legendColor)
if (rel.opts.legendFontFace) strXml += '<a:latin typeface="' + rel.opts.legendFontFace + '"/>'
if (rel.opts.legendFontFace) strXml += '<a:cs typeface="' + rel.opts.legendFontFace + '"/>'
strXml += ' </a:defRPr>'
strXml += ' </a:pPr>'
strXml += ' <a:endParaRPr lang="en-US"/>'
strXml += ' </a:p>'
strXml += '</c:txPr>'
}
strXml += '</c:legend>'
}
}
strXml += ' <c:plotVisOnly val="1"/>'
strXml += ' <c:dispBlanksAs val="' + rel.opts.displayBlanksAs + '"/>'
if (rel.opts._type === CHART_TYPE.SCATTER) strXml += '<c:showDLblsOverMax val="1"/>'
strXml += '</c:chart>'
// D: CHARTSPACE SHAPE PROPS
strXml += '<c:spPr>'
strXml += rel.opts.chartArea.fill?.color ? genXmlColorSelection(rel.opts.chartArea.fill) : '<a:noFill/>'
strXml += rel.opts.chartArea.border
? `<a:ln w="${valToPts(rel.opts.chartArea.border.pt)}" cap="flat">${genXmlColorSelection(rel.opts.chartArea.border.color)}</a:ln>`
: '<a:ln><a:noFill/></a:ln>'
strXml += ' <a:effectLst/>'
strXml += '</c:spPr>'
// E: DATA (Add relID)
strXml += '<c:externalData r:id="rId1"><c:autoUpdate val="0"/></c:externalData>'
// LAST: chartSpace end
strXml += '</c:chartSpace>'
return strXml
}
/**
* Create XML string for any given chart type
* @param {CHART_NAME} chartType chart type name
* @param {IOptsChartData[]} data chart data
* @param {IChartOptsLib} opts chart options
* @param {string} valAxisId chart val axis id
* @param {string} catAxisId chart cat axis id
* @param {boolean} isMultiTypeChart is this a mutli-type chart?
* @example 'bubble' returns <c:bubbleChart></c>
* @example '<c:lineChart>'
* @return {string} XML chart
*/
function makeChartType (chartType: CHART_NAME, data: IOptsChartData[], opts: IChartOptsLib, valAxisId: string, catAxisId: string, isMultiTypeChart: boolean): string {
// NOTE: "Chart Range" (as shown in "select Chart Area dialog") is calculated.
// ....: Ensure each X/Y Axis/Col has same row height (esp. applicable to XY Scatter where X can often be larger than Y's)
let colorIndex = -1 // Maintain the color index by region
let idxColLtr = 1
let optsChartData: IOptsChartData = null
let strXml = ''
switch (chartType) {
case CHART_TYPE.AREA:
case CHART_TYPE.BAR:
case CHART_TYPE.BAR3D:
case CHART_TYPE.LINE:
case CHART_TYPE.RADAR:
// 1: Start Chart
strXml += `<c:${chartType}Chart>`
if (chartType === CHART_TYPE.AREA && opts.barGrouping === 'stacked') {
strXml += '<c:grouping val="' + opts.barGrouping + '"/>'
}
if (chartType === CHART_TYPE.BAR || chartType === CHART_TYPE.BAR3D) {
strXml += '<c:barDir val="' + opts.barDir + '"/>'
strXml += '<c:grouping val="' + (opts.barGrouping || 'clustered') + '"/>'
}
if (chartType === CHART_TYPE.RADAR) {
strXml += '<c:radarStyle val="' + opts.radarStyle + '"/>'
}
strXml += '<c:varyColors val="0"/>'
// 2: "Series" block for every data row
/* EX1:
data: [
{
name: 'Region 1',
labels: [['April', 'May', 'June', 'July']],
values: [17, 26, 53, 96]
},
{
name: 'Region 2',
labels: [['April', 'May', 'June', 'July']],
values: [55, 43, 70, 58]
}
]
*/
/* EX2:
data: [
{
name: 'Region 1',
labels: [
['April', 'May', 'June', 'April', 'May', 'June'],
['2020', '', '', '2021', '', '']
],
values: [17, 26, 53, 96, 40, 33]
},
{
name: 'Region 2',
labels: [
['April', 'May', 'June', 'April', 'May', 'June'],
['2020', '', '', '2021', '', '']
],
values: [55, 43, 70, 58, 78, 63]
}
]
*/
data.forEach(obj => {
colorIndex++
strXml += '<c:ser>'
strXml += ` <c:idx val="${obj._dataIndex}"/><c:order val="${obj._dataIndex}"/>`
strXml += ' <c:tx>'
strXml += ' <c:strRef>'
strXml += ' <c:f>Sheet1!$' + getExcelColName(obj._dataIndex + obj.labels.length + 1) + '$1</c:f>'
strXml += ' <c:strCache><c:ptCount val="1"/><c:pt idx="0"><c:v>' + encodeXmlEntities(obj.name) + '</c:v></c:pt></c:strCache>'
strXml += ' </c:strRef>'
strXml += ' </c:tx>'
// Fill and Border
// TODO: CURRENT: Pull#727
// TODO: let seriesColor = obj.color ? obj.color : opts.chartColors ? opts.chartColors[colorIndex % opts.chartColors.length] : null
const seriesColor = opts.chartColors ? opts.chartColors[colorIndex % opts.chartColors.length] : null
strXml += ' <c:spPr>'
if (seriesColor === 'transparent') {
strXml += '<a:noFill/>'
} else if (opts.chartColorsOpacity) {
strXml += '<a:solidFill>' + createColorElement(seriesColor, `<a:alpha val="${Math.round(opts.chartColorsOpacity * 1000)}"/>`) + '</a:solidFill>'
} else {
strXml += '<a:solidFill>' + createColorElement(seriesColor) + '</a:solidFill>'
}
if (chartType === CHART_TYPE.LINE || chartType === CHART_TYPE.RADAR) {
if (opts.lineSize === 0) {
strXml += '<a:ln><a:noFill/></a:ln>'
} else {
strXml += `<a:ln w="${valToPts(opts.lineSize)}" cap="${createLineCap(opts.lineCap)}"><a:solidFill>${createColorElement(seriesColor)}</a:solidFill>`
strXml += '<a:prstDash val="' + (opts.lineDash || 'solid') + '"/><a:round/></a:ln>'
}
} else if (opts.dataBorder) {
strXml += `<a:ln w="${valToPts(opts.dataBorder.pt)}" cap="${createLineCap(opts.lineCap)}"><a:solidFill>${createColorElement(opts.dataBorder.color)}</a:solidFill><a:prstDash val="solid"/><a:round/></a:ln>`
}
strXml += createShadowElement(opts.shadow, DEF_SHAPE_SHADOW)
strXml += ' </c:spPr>'
strXml += ' <c:invertIfNegative val="0"/>'
// Data Labels per series
// NOTE: [20190117] Adding these to RADAR chart causes unrecoverable corruption!
if (chartType !== CHART_TYPE.RADAR) {
strXml += '<c:dLbls>'
strXml += `<c:numFmt formatCode="${encodeXmlEntities(opts.dataLabelFormatCode) || 'General'}" sourceLinked="0"/>`
if (opts.dataLabelBkgrdColors) strXml += `<c:spPr><a:solidFill>${createColorElement(seriesColor)}</a:solidFill></c:spPr>`
strXml += '<c:txPr><a:bodyPr/><a:lstStyle/><a:p><a:pPr>'
strXml += `<a:defRPr b="${opts.dataLabelFontBold ? 1 : 0}" i="${opts.dataLabelFontItalic ? 1 : 0}" strike="noStrike" sz="${Math.round(
(opts.dataLabelFontSize || DEF_FONT_SIZE) * 100
)}" u="none">`
strXml += `<a:solidFill>${createColorElement(opts.dataLabelColor || DEF_FONT_COLOR)}</a:solidFill>`
strXml += `<a:latin typeface="${opts.dataLabelFontFace || 'Arial'}"/>`
strXml += '</a:defRPr></a:pPr></a:p></c:txPr>'
if (opts.dataLabelPosition) strXml += `<c:dLblPos val="${opts.dataLabelPosition}"/>`
strXml += '<c:showLegendKey val="0"/>'
strXml += `<c:showVal val="${opts.showValue ? '1' : '0'}"/>`
strXml += `<c:showCatName val="0"/><c:showSerName val="${opts.showSerName ? '1' : '0'}"/><c:showPercent val="0"/><c:showBubbleSize val="0"/>`
strXml += `<c:showLeaderLines val="${opts.showLeaderLines ? '1' : '0'}"/>`
strXml += '</c:dLbls>'
}
// 'c:marker' tag: `lineDataSymbol`
if (chartType === CHART_TYPE.LINE || chartType === CHART_TYPE.RADAR) {
strXml += '<c:marker>'
strXml += ' <c:symbol val="' + opts.lineDataSymbol + '"/>'
if (opts.lineDataSymbolSize) strXml += `<c:size val="${opts.lineDataSymbolSize}"/>` // Defaults to "auto" otherwise (but this is usually too small, so there is a default)
strXml += ' <c:spPr>'
strXml += ` <a:solidFill>${createColorElement(opts.chartColors[obj._dataIndex + 1 > opts.chartColors.length ? Math.floor(Math.random() * opts.chartColors.length) : obj._dataIndex])}</a:solidFill>`
strXml += ` <a:ln w="${opts.lineDataSymbolLineSize}" cap="flat"><a:solidFill>${createColorElement(opts.lineDataSymbolLineColor || seriesColor)}</a:solidFill><a:prstDash val="solid"/><a:round/></a:ln>`
strXml += ' <a:effectLst/>'
strXml += ' </c:spPr>'
strXml += '</c:marker>'
}
// Allow users with a single data set to pass their own array of colors (check for this using != ours)
// Color chart bars various colors when >1 color
// NOTE: `<c:dPt>` created with various colors will change PPT legend by design so each dataPt/color is an legend item!
if (
(chartType === CHART_TYPE.BAR || chartType === CHART_TYPE.BAR3D) &&
data.length === 1 &&
((opts.chartColors && opts.chartColors !== BARCHART_COLORS && opts.chartColors.length > 1) || (opts.invertedColors?.length))
) {
// Series Data Point colors
obj.values.forEach((value, index) => {
const arrColors = value < 0 ? opts.invertedColors || opts.chartColors || BARCHART_COLORS : opts.chartColors || []
strXml += ' <c:dPt>'
strXml += ` <c:idx val="${index}"/>`
strXml += ' <c:invertIfNegative val="0"/>'
strXml += ' <c:bubble3D val="0"/>'
strXml += ' <c:spPr>'
if (opts.lineSize === 0) {
strXml += '<a:ln><a:noFill/></a:ln>'
} else if (chartType === CHART_TYPE.BAR) {
strXml += '<a:solidFill>'
strXml += ' <a:srgbClr val="' + arrColors[index % arrColors.length] + '"/>'
strXml += '</a:solidFill>'
} else {
strXml += '<a:ln>'
strXml += ' <a:solidFill>'
strXml += ' <a:srgbClr val="' + arrColors[index % arrColors.length] + '"/>'
strXml += ' </a:solidFill>'
strXml += '</a:ln>'
}
strXml += createShadowElement(opts.shadow, DEF_SHAPE_SHADOW)
strXml += ' </c:spPr>'
strXml += ' </c:dPt>'
})
}
// 2: "Categories"
{
strXml += '<c:cat>'
if (opts.catLabelFormatCode) {
// Use 'numRef' as catLabelFormatCode implies that we are expecting numbers here
strXml += ' <c:numRef>'
strXml += ` <c:f>Sheet1!$A$2:$A$${obj.labels[0].length + 1}</c:f>`
strXml += ' <c:numCache>'
strXml += ' <c:formatCode>' + (opts.catLabelFormatCode || 'General') + '</c:formatCode>'
strXml += ` <c:ptCount val="${obj.labels[0].length}"/>`
obj.labels[0].forEach((label, idx) => (strXml += `<c:pt idx="${idx}"><c:v>${encodeXmlEntities(label)}</c:v></c:pt>`))
strXml += ' </c:numCache>'
strXml += ' </c:numRef>'
} else {
strXml += ' <c:multiLvlStrRef>'
strXml += ` <c:f>Sheet1!$A$2:$${getExcelColName(obj.labels.length)}$${obj.labels[0].length + 1}</c:f>`
strXml += ' <c:multiLvlStrCache>'
strXml += ` <c:ptCount val="${obj.labels[0].length}"/>`
obj.labels.forEach(labelsGroup => {
strXml += '<c:lvl>'
labelsGroup.forEach((label, idx) => (strXml += `<c:pt idx="${idx}"><c:v>${encodeXmlEntities(label)}</c:v></c:pt>`))
strXml += '</c:lvl>'
})
strXml += ' </c:multiLvlStrCache>'
strXml += ' </c:multiLvlStrRef>'
}
strXml += '</c:cat>'
}
// 3: "Values"
{
strXml += '<c:val>'
strXml += ' <c:numRef>'
strXml += `<c:f>Sheet1!$${getExcelColName(obj._dataIndex + obj.labels.length + 1)}$2:$${getExcelColName(obj._dataIndex + obj.labels.length + 1)}$${obj.labels[0].length + 1}</c:f>`
strXml += ' <c:numCache>'
strXml += ' <c:formatCode>' + (opts.valLabelFormatCode || opts.dataTableFormatCode || 'General') + '</c:formatCode>'
strXml += ` <c:ptCount val="${obj.labels[0].length}"/>`
obj.values.forEach((value, idx) => (strXml += `<c:pt idx="${idx}"><c:v>${value || value === 0 ? value : ''}</c:v></c:pt>`))
strXml += ' </c:numCache>'
strXml += ' </c:numRef>'
strXml += '</c:val>'
}
// Option: `smooth`
if (chartType === CHART_TYPE.LINE) strXml += '<c:smooth val="' + (opts.lineSmooth ? '1' : '0') + '"/>'
// 4: Close "SERIES"
strXml += '</c:ser>'
})
// 3: "Data Labels"
{
strXml += ' <c:dLbls>'
strXml += ` <c:numFmt formatCode="${encodeXmlEntities(opts.dataLabelFormatCode) || 'General'}" sourceLinked="0"/>`
strXml += ' <c:txPr>'
strXml += ' <a:bodyPr/>'
strXml += ' <a:lstStyle/>'
strXml += ' <a:p><a:pPr>'
strXml += ` <a:defRPr b="${opts.dataLabelFontBold ? 1 : 0}" i="${opts.dataLabelFontItalic ? 1 : 0}" strike="noStrike" sz="${Math.round((opts.dataLabelFontSize || DEF_FONT_SIZE) * 100)}" u="none">`
strXml += ' <a:solidFill>' + createColorElement(opts.dataLabelColor || DEF_FONT_COLOR) + '</a:solidFill>'
strXml += ' <a:latin typeface="' + (opts.dataLabelFontFace || 'Arial') + '"/>'
strXml += ' </a:defRPr>'
strXml += ' </a:pPr></a:p>'
strXml += ' </c:txPr>'
if (opts.dataLabelPosition) strXml += ' <c:dLblPos val="' + opts.dataLabelPosition + '"/>'
strXml += ' <c:showLegendKey val="0"/>'
strXml += ' <c:showVal val="' + (opts.showValue ? '1' : '0') + '"/>'
strXml += ' <c:showCatName val="0"/>'
strXml += ' <c:showSerName val="' + (opts.showSerName ? '1' : '0') + '"/>'
strXml += ' <c:showPercent val="0"/>'
strXml += ' <c:showBubbleSize val="0"/>'
strXml += ` <c:showLeaderLines val="${opts.showLeaderLines ? '1' : '0'}"/>`
strXml += ' </c:dLbls>'
}
// 4: Add more chart options (gapWidth, line Marker, etc.)
if (chartType === CHART_TYPE.BAR) {
strXml += ` <c:gapWidth val="${opts.barGapWidthPct}"/>`
strXml += ` <c:overlap val="${(opts.barGrouping || '').includes('tacked') ? 100 : opts.barOverlapPct ? opts.barOverlapPct : 0}"/>`
} else if (chartType === CHART_TYPE.BAR3D) {
strXml += ` <c:gapWidth val="${opts.barGapWidthPct}"/>`
strXml += ` <c:gapDepth val="${opts.barGapDepthPct}"/>`
strXml += ' <c:shape val="' + opts.bar3DShape + '"/>'
} else if (chartType === CHART_TYPE.LINE) {
strXml += ' <c:marker val="1"/>'
}
// 5: Add axisId (NOTE: order matters! (category comes first))
strXml += `<c:axId val="${catAxisId}"/><c:axId val="${valAxisId}"/><c:axId val="${AXIS_ID_SERIES_PRIMARY}"/>`
// 6: Close Chart tag
strXml += `</c:${chartType}Chart>`
// end switch
break
case CHART_TYPE.SCATTER:
/*
`data` = [
{ name:'X-Axis', values:[1,2,3,4,5,6,7,8,9,10,11,12] },
{ name:'Y-Value 1', values:[13, 20, 21, 25] },
{ name:'Y-Value 2', values:[ 1, 2, 5, 9] }
];
*/
// 1: Start Chart
strXml += '<c:' + chartType + 'Chart>'
strXml += '<c:scatterStyle val="lineMarker"/>'
strXml += '<c:varyColors val="0"/>'
// 2: Series: (One for each Y-Axis)
colorIndex = -1
data.filter((_obj, idx) => idx > 0).forEach((obj, idx) => {
colorIndex++
strXml += '<c:ser>'
strXml += ` <c:idx val="${idx}"/>`
strXml += ` <c:order val="${idx}"/>`
strXml += ' <c:tx>'
strXml += ' <c:strRef>'
strXml += ` <c:f>Sheet1!$${getExcelColName(idx + 2)}$1</c:f>`
strXml += ' <c:strCache><c:ptCount val="1"/><c:pt idx="0"><c:v>' + encodeXmlEntities(obj.name) + '</c:v></c:pt></c:strCache>'
strXml += ' </c:strRef>'
strXml += ' </c:tx>'
// 'c:spPr': Fill, Border, Line, LineStyle (dash, etc.), Shadow
strXml += ' <c:spPr>'
{
const tmpSerColor = opts.chartColors[colorIndex % opts.chartColors.length]
if (tmpSerColor === 'transparent') {
strXml += '<a:noFill/>'
} else if (opts.chartColorsOpacity) {
strXml += '<a:solidFill>' + createColorElement(tmpSerColor, '<a:alpha val="' + Math.round(opts.chartColorsOpacity * 1000).toString() + '"/>') + '</a:solidFill>'
} else {
strXml += '<a:solidFill>' + createColorElement(tmpSerColor) + '</a:solidFill>'
}
if (opts.lineSize === 0) {
strXml += '<a:ln><a:noFill/></a:ln>'
} else {
strXml += `<a:ln w="${valToPts(opts.lineSize)}" cap="${createLineCap(opts.lineCap)}"><a:solidFill>${createColorElement(tmpSerColor)}</a:solidFill>`
strXml += `<a:prstDash val="${opts.lineDash || 'solid'}"/><a:round/></a:ln>`
}
// Shadow
strXml += createShadowElement(opts.shadow, DEF_SHAPE_SHADOW)
}
strXml += ' </c:spPr>'
// 'c:marker' tag: `lineDataSymbol`
{
strXml += '<c:marker>'
strXml += ' <c:symbol val="' + opts.lineDataSymbol + '"/>'
if (opts.lineDataSymbolSize) {
// Defaults to "auto" otherwise (but this is usually too small, so there is a default)
strXml += `<c:size val="${opts.lineDataSymbolSize}"/>`
}
strXml += '<c:spPr>'
strXml += `<a:solidFill>${createColorElement(opts.chartColors[idx + 1 > opts.chartColors.length ? Math.floor(Math.random() * opts.chartColors.length) : idx])}</a:solidFill>`
strXml += `<a:ln w="${opts.lineDataSymbolLineSize}" cap="flat"><a:solidFill>${createColorElement(opts.lineDataSymbolLineColor || opts.chartColors[colorIndex % opts.chartColors.length])}</a:solidFill><a:prstDash val="solid"/><a:round/></a:ln>`
strXml += '<a:effectLst/>'
strXml += '</c:spPr>'
strXml += '</c:marker>'
}
// Option: scatter data point labels
if (opts.showLabel) {
const chartUuid = getUuid('-xxxx-xxxx-xxxx-xxxxxxxxxxxx')
if (obj.labels[0] && (opts.dataLabelFormatScatter === 'custom' || opts.dataLabelFormatScatter === 'customXY')) {
strXml += '<c:dLbls>'
obj.labels[0].forEach((label, idx) => {
if (opts.dataLabelFormatScatter === 'custom' || opts.dataLabelFormatScatter === 'customXY') {
strXml += ' <c:dLbl>'
strXml += ` <c:idx val="${idx}"/>`
strXml += ' <c:tx>'
strXml += ' <c:rich>'
strXml += ' <a:bodyPr>'
strXml += ' <a:spAutoFit/>'
strXml += ' </a:bodyPr>'
strXml += ' <a:lstStyle/>'
strXml += ' <a:p>'
strXml += ' <a:pPr>'
strXml += ' <a:defRPr/>'
strXml += ' </a:pPr>'
strXml += ' <a:r>'
strXml += ' <a:rPr lang="' + (opts.lang || 'en-US') + '" dirty="0"/>'
strXml += ' <a:t>' + encodeXmlEntities(label) + '</a:t>'
strXml += ' </a:r>'
// Apply XY values at end of custom label
// Do not apply the values if the label was empty or just spaces
// This allows for selective labelling where required
if (opts.dataLabelFormatScatter === 'customXY' && !/^ *$/.test(label)) {
strXml += ' <a:r>'
strXml += ' <a:rPr lang="' + (opts.lang || 'en-US') + '" baseline="0" dirty="0"/>'
strXml += ' <a:t> (</a:t>'
strXml += ' </a:r>'
strXml += ' <a:fld id="{' + getUuid('xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx') + '}" type="XVALUE">'
strXml += ' <a:rPr lang="' + (opts.lang || 'en-US') + '" baseline="0"/>'
strXml += ' <a:pPr>'
strXml += ' <a:defRPr/>'
strXml += ' </a:pPr>'
strXml += ' <a:t>[' + encodeXmlEntities(obj.name) + '</a:t>'
strXml += ' </a:fld>'
strXml += ' <a:r>'
strXml += ' <a:rPr lang="' + (opts.lang || 'en-US') + '" baseline="0" dirty="0"/>'
strXml += ' <a:t>, </a:t>'
strXml += ' </a:r>'
strXml += ' <a:fld id="{' + getUuid('xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx') + '}" type="YVALUE">'
strXml += ' <a:rPr lang="' + (opts.lang || 'en-US') + '" baseline="0"/>'
strXml += ' <a:pPr>'
strXml += ' <a:defRPr/>'
strXml += ' </a:pPr>'
strXml += ' <a:t>[' + encodeXmlEntities(obj.name) + ']</a:t>'
strXml += ' </a:fld>'
strXml += ' <a:r>'
strXml += ' <a:rPr lang="' + (opts.lang || 'en-US') + '" baseline="0" dirty="0"/>'
strXml += ' <a:t>)</a:t>'
strXml += ' </a:r>'
strXml += ' <a:endParaRPr lang="' + (opts.lang || 'en-US') + '" dirty="0"/>'
}
strXml += ' </a:p>'
strXml += ' </c:rich>'
strXml += ' </c:tx>'
strXml += ' <c:spPr>'
strXml += ' <a:noFill/>'
strXml += ' <a:ln>'
strXml += ' <a:noFill/>'
strXml += ' </a:ln>'
strXml += ' <a:effectLst/>'
strXml += ' </c:spPr>'
if (opts.dataLabelPosition) strXml += ' <c:dLblPos val="' + opts.dataLabelPosition + '"/>'
strXml += ' <c:showLegendKey val="0"/>'
strXml += ' <c:showVal val="0"/>'
strXml += ' <c:showCatName val="0"/>'
strXml += ' <c:showSerName val="0"/>'
strXml += ' <c:showPercent val="0"/>'
strXml += ' <c:showBubbleSize val="0"/>'
strXml += ' <c:showLeaderLines val="1"/>'
strXml += ' <c:extLst>'
strXml += ' <c:ext uri="{CE6537A1-D6FC-4f65-9D91-7224C49458BB}" xmlns:c15="http://schemas.microsoft.com/office/drawing/2012/chart"/>'
strXml += ' <c:ext uri="{C3380CC4-5D6E-409C-BE32-E72D297353CC}" xmlns:c16="http://schemas.microsoft.com/office/drawing/2014/chart">'
strXml += ` <c16:uniqueId val="{${'00000000'.substring(0, 8 - (idx + 1).toString().length).toString()}${idx + 1}${chartUuid}}"/>`
strXml += ' </c:ext>'
strXml += ' </c:extLst>'
strXml += '</c:dLbl>'
}
})
strXml += '</c:dLbls>'
}
if (opts.dataLabelFormatScatter === 'XY') {
strXml += '<c:dLbls>'
strXml += ' <c:spPr>'
strXml += ' <a:noFill/>'
strXml += ' <a:ln>'
strXml += ' <a:noFill/>'
strXml += ' </a:ln>'
strXml += ' <a:effectLst/>'
strXml += ' </c:spPr>'
strXml += ' <c:txPr>'
strXml += ' <a:bodyPr>'
strXml += ' <a:spAutoFit/>'
strXml += ' </a:bodyPr>'
strXml += ' <a:lstStyle/>'
strXml += ' <a:p>'
strXml += ' <a:pPr>'
strXml += ' <a:defRPr/>'
strXml += ' </a:pPr>'
strXml += ' <a:endParaRPr lang="en-US"/>'
strXml += ' </a:p>'
strXml += ' </c:txPr>'
if (opts.dataLabelPosition) strXml += ' <c:dLblPos val="' + opts.dataLabelPosition + '"/>'
strXml += ' <c:showLegendKey val="0"/>'
strXml += ` <c:showVal val="${opts.showLabel ? '1' : '0'}"/>`
strXml += ` <c:showCatName val="${opts.showLabel ? '1' : '0'}"/>`
strXml += ` <c:showSerName val="${opts.showSerName ? '1' : '0'}"/>`
strXml += ' <c:showPercent val="0"/>'
strXml += ' <c:showBubbleSize val="0"/>'
strXml += ' <c:extLst>'
strXml += ' <c:ext uri="{CE6537A1-D6FC-4f65-9D91-7224C49458BB}" xmlns:c15="http://schemas.microsoft.com/office/drawing/2012/chart">'
strXml += ' <c15:showLeaderLines val="1"/>'
strXml += ' </c:ext>'
strXml += ' </c:extLst>'
strXml += '</c:dLbls>'
}
}
// Color bar chart bars various colors
// Allow users with a single data set to pass their own array of colors (check for this using != ours)
if (data.length === 1 && opts.chartColors !== BARCHART_COLORS) {
// Series Data Point colors
obj.values.forEach((value, index) => {
const arrColors = value < 0 ? opts.invertedColors || opts.chartColors || BARCHART_COLORS : opts.chartColors || []
strXml += ' <c:dPt>'
strXml += ` <c:idx val="${index}"/>`
strXml += ' <c:invertIfNegative val="0"/>'
strXml += ' <c:bubble3D val="0"/>'
strXml += ' <c:spPr>'
if (opts.lineSize === 0) {
strXml += '<a:ln><a:noFill/></a:ln>'
} else {
strXml += '<a:solidFill>'
strXml += ' <a:srgbClr val="' + arrColors[index % arrColors.length] + '"/>'
strXml += '</a:solidFill>'
}
strXml += createShadowElement(opts.shadow, DEF_SHAPE_SHADOW)
strXml += ' </c:spPr>'
strXml += ' </c:dPt>'
})
}
// 3: "Values": Scatter Chart has 2: `xVal` and `yVal`
{
// X-Axis is always the same
strXml += '<c:xVal>'
strXml += ' <c:numRef>'
strXml += ` <c:f>Sheet1!$A$2:$A$${data[0].values.length + 1}</c:f>`
strXml += ' <c:numCache>'
strXml += ' <c:formatCode>General</c:formatCode>'
strXml += ` <c:ptCount val="${data[0].values.length}"/>`
data[0].values.forEach((value, idx) => {
strXml += `<c:pt idx="${idx}"><c:v>${value || value === 0 ? value : ''}</c:v></c:pt>`
})
strXml += ' </c:numCache>'
strXml += ' </c:numRef>'
strXml += '</c:xVal>'
// Y-Axis vals are this object's `values`
strXml += '<c:yVal>'
strXml += ' <c:numRef>'
strXml += ` <c:f>Sheet1!$${getExcelColName(idx + 2)}$2:$${getExcelColName(idx + 2)}$${data[0].values.length + 1}</c:f>`
strXml += ' <c:numCache>'
strXml += ' <c:formatCode>General</c:formatCode>'
// NOTE: Use pt count and iterate over data[0] (X-Axis) as user can have more values than data (eg: timeline where only first few months are populated)
strXml += ` <c:ptCount val="${data[0].values.length}"/>`
data[0].values.forEach((_value, idx) => {
strXml += `<c:pt idx="${idx}"><c:v>${obj.values[idx] || obj.values[idx] === 0 ? obj.values[idx] : ''}</c:v></c:pt>`
})
strXml += ' </c:numCache>'
strXml += ' </c:numRef>'
strXml += '</c:yVal>'
}
// Option: `smooth`
strXml += '<c:smooth val="' + (opts.lineSmooth ? '1' : '0') + '"/>'
// 4: Close "SERIES"
strXml += '</c:ser>'
})
// 3: Data Labels
{
strXml += ' <c:dLbls>'
strXml += ` <c:numFmt formatCode="${encodeXmlEntities(opts.dataLabelFormatCode) || 'General'}" sourceLinked="0"/>`
strXml += ' <c:txPr>'
strXml += ' <a:bodyPr/>'
strXml += ' <a:lstStyle/>'
strXml += ' <a:p><a:pPr>'
strXml += ` <a:defRPr b="${opts.dataLabelFontBold ? '1' : '0'}" i="${opts.dataLabelFontItalic ? '1' : '0'}" strike="noStrike" sz="${Math.round((opts.dataLabelFontSize || DEF_FONT_SIZE) * 100)}" u="none">`
strXml += ' <a:solidFill>' + createColorElement(opts.dataLabelColor || DEF_FONT_COLOR) + '</a:solidFill>'
strXml += ' <a:latin typeface="' + (opts.dataLabelFontFace || 'Arial') + '"/>'
strXml += ' </a:defRPr>'
strXml += ' </a:pPr></a:p>'
strXml += ' </c:txPr>'
if (opts.dataLabelPosition) strXml += ' <c:dLblPos val="' + opts.dataLabelPosition + '"/>'
strXml += ' <c:showLegendKey val="0"/>'
strXml += ' <c:showVal val="' + (opts.showValue ? '1' : '0') + '"/>'
strXml += ' <c:showCatName val="0"/>'
strXml += ' <c:showSerName val="' + (opts.showSerName ? '1' : '0') + '"/>'
strXml += ' <c:showPercent val="0"/>'
strXml += ' <c:showBubbleSize val="0"/>'
strXml += ' </c:dLbls>'
}
// 4: Add axis Id (NOTE: order matters! - category comes first)
strXml += `<c:axId val="${catAxisId}"/><c:axId val="${valAxisId}"/>`
// 5: Close Chart tag
strXml += '</c:' + chartType + 'Chart>'
// end switch
break
case CHART_TYPE.BUBBLE:
case CHART_TYPE.BUBBLE3D:
/*
`data` = [
{ name:'X-Axis', values:[1,2,3,4,5,6,7,8,9,10,11,12] },
{ name:'Y-Values 1', values:[13, 20, 21, 25], sizes:[10, 5, 20, 15] },
{ name:'Y-Values 2', values:[ 1, 2, 5, 9], sizes:[ 5, 3, 9, 3] }
];
*/
// 1: Start Chart
strXml += '<c:bubbleChart>'
strXml += '<c:varyColors val="0"/>'
// 2: Series: (One for each Y-Axis)
colorIndex = -1
data.filter((_obj, idx) => idx > 0).forEach((obj, idx) => {
colorIndex++
strXml += '<c:ser>'
strXml += ` <c:idx val="${idx}"/>`
strXml += ` <c:order val="${idx}"/>`
// A: `<c:tx>`
strXml += ' <c:tx>'
strXml += ' <c:strRef>'
strXml += ' <c:f>Sheet1!$' + getExcelColName(idxColLtr + 1) + '$1</c:f>'
strXml += ' <c:strCache><c:ptCount val="1"/><c:pt idx="0"><c:v>' + encodeXmlEntities(obj.name) + '</c:v></c:pt></c:strCache>'
strXml += ' </c:strRef>'
strXml += ' </c:tx>'
// B: '<c:spPr>': Fill, Border, Line, LineStyle (dash, etc.), Shadow
{
strXml += '<c:spPr>'
const tmpSerColor = opts.chartColors[colorIndex % opts.chartColors.length]
if (tmpSerColor === 'transparent') {
strXml += '<a:noFill/>'
} else if (opts.chartColorsOpacity) {
strXml += `<a:solidFill>${createColorElement(tmpSerColor, '<a:alpha val="' + Math.round(opts.chartColorsOpacity * 1000).toString() + '"/>')}</a:solidFill>`
} else {
strXml += '<a:solidFill>' + createColorElement(tmpSerColor) + '</a:solidFill>'
}
if (opts.lineSize === 0) {
strXml += '<a:ln><a:noFill/></a:ln>'
} else if (opts.dataBorder) {
strXml += `<a:ln w="${valToPts(opts.dataBorder.pt)}" cap="flat"><a:solidFill>${createColorElement(opts.dataBorder.color)}</a:solidFill><a:prstDash val="solid"/><a:round/></a:ln>`
} else {
strXml += `<a:ln w="${valToPts(opts.lineSize)}" cap="flat"><a:solidFill>${createColorElement(tmpSerColor)}</a:solidFill>`
strXml += `<a:prstDash val="${opts.lineDash || 'solid'}"/><a:round/></a:ln>`
}
// Shadow
strXml += createShadowElement(opts.shadow, DEF_SHAPE_SHADOW)
strXml += '</c:spPr>'
}
// C: '<c:dLbls>' "Data Labels"
// Let it be defaulted for now
// D: '<c:xVal>'/'<c:yVal>' "Values": Scatter Chart has 2: `xVal` and `yVal`
{
// X-Axis is always the same
strXml += '<c:xVal>'
strXml += ' <c:numRef>'
strXml += ` <c:f>Sheet1!$A$2:$A$${data[0].values.length + 1}</c:f>`
strXml += ' <c:numCache>'
strXml += ' <c:formatCode>General</c:formatCode>'
strXml += ` <c:ptCount val="${data[0].values.length}"/>`
data[0].values.forEach((value, idx) => {
strXml += `<c:pt idx="${idx}"><c:v>${value || value === 0 ? value : ''}</c:v></c:pt>`
})
strXml += ' </c:numCache>'
strXml += ' </c:numRef>'
strXml += '</c:xVal>'
// Y-Axis vals are this object's `values`
strXml += '<c:yVal>'
strXml += ' <c:numRef>'
strXml += `<c:f>Sheet1!$${getExcelColName(idxColLtr + 1)}$2:$${getExcelColName(idxColLtr + 1)}$${data[0].values.length + 1}</c:f>`
idxColLtr++
strXml += ' <c:numCache>'
strXml += ' <c:formatCode>General</c:formatCode>'
// NOTE: Use pt count and iterate over data[0] (X-Axis) as user can have more values than data (eg: timeline where only first few months are populated)
strXml += ` <c:ptCount val="${data[0].values.length}"/>`
data[0].values.forEach((_value, idx) => {
strXml += `<c:pt idx="${idx}"><c:v>${obj.values[idx] || obj.values[idx] === 0 ? obj.values[idx] : ''}</c:v></c:pt>`
})
strXml += ' </c:numCache>'
strXml += ' </c:numRef>'
strXml += '</c:yVal>'
}
// E: '<c:bubbleSize>'
strXml += ' <c:bubbleSize>'
strXml += ' <c:numRef>'
strXml += `<c:f>Sheet1!$${getExcelColName(idxColLtr + 1)}$2:$${getExcelColName(idxColLtr + 1)}$${obj.sizes.length + 1}</c:f>`
idxColLtr++
strXml += ' <c:numCache>'
strXml += ' <c:formatCode>General</c:formatCode>'
strXml += ` <c:ptCount val="${obj.sizes.length}"/>`
obj.sizes.forEach((value, idx) => {
strXml += `<c:pt idx="${idx}"><c:v>${value || ''}</c:v></c:pt>`
})
strXml += ' </c:numCache>'
strXml += ' </c:numRef>'
strXml += ' </c:bubbleSize>'
strXml += ' <c:bubble3D val="' + (chartType === CHART_TYPE.BUBBLE3D ? '1' : '0') + '"/>'
// F: Close "SERIES"
strXml += '</c:ser>'
})
// 3: Data Labels
{
strXml += '<c:dLbls>'
strXml += `<c:numFmt formatCode="${encodeXmlEntities(opts.dataLabelFormatCode) || 'General'}" sourceLinked="0"/>`
strXml += '<c:txPr><a:bodyPr/><a:lstStyle/><a:p><a:pPr>'
strXml += `<a:defRPr b="${opts.dataLabelFontBold ? 1 : 0}" i="${opts.dataLabelFontItalic ? 1 : 0}" strike="noStrike" sz="${Math.round(
Math.round(opts.dataLabelFontSize || DEF_FONT_SIZE) * 100
)}" u="none">`
strXml += `<a:solidFill>${createColorElement(opts.dataLabelColor || DEF_FONT_COLOR)}</a:solidFill>`
strXml += `<a:latin typeface="${opts.dataLabelFontFace || 'Arial'}"/>`
strXml += '</a:defRPr></a:pPr></a:p></c:txPr>'
if (opts.dataLabelPosition) strXml += `<c:dLblPos val="${opts.dataLabelPosition}"/>`
strXml += '<c:showLegendKey val="0"/>'
strXml += `<c:showVal val="${opts.showValue ? '1' : '0'}"/>`
strXml += `<c:showCatName val="0"/><c:showSerName val="${opts.showSerName ? '1' : '0'}"/><c:showPercent val="0"/><c:showBubbleSize val="0"/>`
strXml += '<c:extLst>'
strXml += ' <c:ext uri="{CE6537A1-D6FC-4f65-9D91-7224C49458BB}" xmlns:c15="http://schemas.microsoft.com/office/drawing/2012/chart">'
strXml += ' <c15:showLeaderLines val="' + (opts.showLeaderLines ? '1' : '0') + '"/>'
strXml += ' </c:ext>'
strXml += '</c:extLst>'
strXml += '</c:dLbls>'
}
// 4: Bubble options
// strXml += ' <c:bubbleScale val="100"/>';
// strXml += ' <c:showNegBubbles val="0"/>';
// Commented out to let it default to PPT until we create options
// 5: AxisId (NOTE: order matters! (category comes first))
strXml += `<c:axId val="${catAxisId}"/><c:axId val="${valAxisId}"/>`
// 6: Close Chart tag
strXml += '</c:bubbleChart>'
// end switch
break
case CHART_TYPE.DOUGHNUT:
case CHART_TYPE.PIE:
// Use the same let name so code blocks from barChart are interchangeable
optsChartData = data[0]
/* EX:
data: [
{
name: 'Project Status',
labels: ['Red', 'Amber', 'Green', 'Unknown'],
values: [10, 20, 38, 2]
}
]
*/
// 1: Start Chart
strXml += '<c:' + chartType + 'Chart>'
strXml += ' <c:varyColors val="1"/>'
strXml += '<c:ser>'
strXml += ' <c:idx val="0"/>'
strXml += ' <c:order val="0"/>'
strXml += ' <c:tx>'
strXml += ' <c:strRef>'
strXml += ' <c:f>Sheet1!$B$1</c:f>'
strXml += ' <c:strCache>'
strXml += ' <c:ptCount val="1"/>'
strXml += ' <c:pt idx="0"><c:v>' + encodeXmlEntities(optsChartData.name) + '</c:v></c:pt>'
strXml += ' </c:strCache>'
strXml += ' </c:strRef>'
strXml += ' </c:tx>'
strXml += ' <c:spPr>'
strXml += ' <a:solidFill><a:schemeClr val="accent1"/></a:solidFill>'
strXml += ' <a:ln w="9525" cap="flat"><a:solidFill><a:srgbClr val="F9F9F9"/></a:solidFill><a:prstDash val="solid"/><a:round/></a:ln>'
if (opts.dataNoEffects) {
strXml += '<a:effectLst/>'
} else {
strXml += createShadowElement(opts.shadow, DEF_SHAPE_SHADOW)
}
strXml += ' </c:spPr>'
// strXml += '<c:explosion val="0"/>'
// 2: "Data Point" block for every data row
optsChartData.labels[0].forEach((_label, idx) => {
strXml += '<c:dPt>'
strXml += ` <c:idx val="${idx}"/>`
strXml += ' <c:bubble3D val="0"/>'
strXml += ' <c:spPr>'
strXml += `<a:solidFill>${createColorElement(
opts.chartColors[idx + 1 > opts.chartColors.length ? Math.floor(Math.random() * opts.chartColors.length) : idx]
)}</a:solidFill>`
if (opts.dataBorder) {
strXml += `<a:ln w="${valToPts(opts.dataBorder.pt)}" cap="flat"><a:solidFill>${createColorElement(
opts.dataBorder.color
)}</a:solidFill><a:prstDash val="solid"/><a:round/></a:ln>`
}
strXml += createShadowElement(opts.shadow, DEF_SHAPE_SHADOW)
strXml += ' </c:spPr>'
strXml += '</c:dPt>'
})
// 3: "Data Label" block for every data Label
strXml += '<c:dLbls>'
optsChartData.labels[0].forEach((_label, idx) => {
strXml += '<c:dLbl>'
strXml += ` <c:idx val="${idx}"/>`
strXml += ` <c:numFmt formatCode="${encodeXmlEntities(opts.dataLabelFormatCode) || 'General'}" sourceLinked="0"/>`
strXml += ' <c:spPr/><c:txPr>'
strXml += ' <a:bodyPr/><a:lstStyle/>'
strXml += ' <a:p><a:pPr>'
strXml += ` <a:defRPr sz="${Math.round((opts.dataLabelFontSize || DEF_FONT_SIZE) * 100)}" b="${opts.dataLabelFontBold ? 1 : 0}" i="${opts.dataLabelFontItalic ? 1 : 0
}" u="none" strike="noStrike">`
strXml += ' <a:solidFill>' + createColorElement(opts.dataLabelColor || DEF_FONT_COLOR) + '</a:solidFill>'
strXml += ` <a:latin typeface="${opts.dataLabelFontFace || 'Arial'}"/>`
strXml += ' </a:defRPr>'
strXml += ' </a:pPr></a:p>'
strXml += ' </c:txPr>'
if (chartType === CHART_TYPE.PIE && opts.dataLabelPosition) strXml += `<c:dLblPos val="${opts.dataLabelPosition}"/>`
strXml += ' <c:showLegendKey val="0"/>'
strXml += ' <c:showVal val="' + (opts.showValue ? '1' : '0') + '"/>'
strXml += ' <c:showCatName val="' + (opts.showLabel ? '1' : '0') + '"/>'
strXml += ' <c:showSerName val="' + (opts.showSerName ? '1' : '0') + '"/>'
strXml += ' <c:showPercent val="' + (opts.showPercent ? '1' : '0') + '"/>'
strXml += ' <c:showBubbleSize val="0"/>'
strXml += ' </c:dLbl>'
})
strXml += ` <c:numFmt formatCode="${encodeXmlEntities(opts.dataLabelFormatCode) || 'General'}" sourceLinked="0"/>`
strXml += ' <c:txPr>'
strXml += ' <a:bodyPr/>'
strXml += ' <a:lstStyle/>'
strXml += ' <a:p>'
strXml += ' <a:pPr>'
strXml += ` <a:defRPr sz="1800" b="${opts.dataLabelFontBold ? '1' : '0'}" i="${opts.dataLabelFontItalic ? '1' : '0'}" u="none" strike="noStrike">`
strXml += ' <a:solidFill><a:srgbClr val="000000"/></a:solidFill><a:latin typeface="Arial"/>'
strXml += ' </a:defRPr>'
strXml += ' </a:pPr>'
strXml += ' </a:p>'
strXml += ' </c:txPr>'
strXml += chartType === CHART_TYPE.PIE ? '<c:dLblPos val="ctr"/>' : ''
strXml += ' <c:showLegendKey val="0"/>'
strXml += ' <c:showVal val="0"/>'
strXml += ' <c:showCatName val="1"/>'
strXml += ' <c:showSerName val="0"/>'
strXml += ' <c:showPercent val="1"/>'
strXml += ' <c:showBubbleSize val="0"/>'
strXml += ` <c:showLeaderLines val="${opts.showLeaderLines ? '1' : '0'}"/>`
strXml += '</c:dLbls>'
// 2: "Categories"
strXml += '<c:cat>'
strXml += ' <c:strRef>'
strXml += ` <c:f>Sheet1!$A$2:$A$${optsChartData.labels[0].length + 1}</c:f>`
strXml += ' <c:strCache>'
strXml += ` <c:ptCount val="${optsChartData.labels[0].length}"/>`
optsChartData.labels[0].forEach((label, idx) => {
strXml += `<c:pt idx="${idx}"><c:v>${encodeXmlEntities(label)}</c:v></c:pt>`
})
strXml += ' </c:strCache>'
strXml += ' </c:strRef>'
strXml += '</c:cat>'
// 3: Create vals
strXml += ' <c:val>'
strXml += ' <c:numRef>'
strXml += ` <c:f>Sheet1!$B$2:$B$${optsChartData.labels[0].length + 1}</c:f>`
strXml += ' <c:numCache>'
strXml += ` <c:ptCount val="${optsChartData.labels[0].length}"/>`
optsChartData.values.forEach((value, idx) => {
strXml += `<c:pt idx="${idx}"><c:v>${value || value === 0 ? value : ''}</c:v></c:pt>`
})
strXml += ' </c:numCache>'
strXml += ' </c:numRef>'
strXml += ' </c:val>'
// 4: Close "SERIES"
strXml += ' </c:ser>'
strXml += ` <c:firstSliceAng val="${opts.firstSliceAng ? Math.round(opts.firstSliceAng) : 0}"/>`
if (chartType === CHART_TYPE.DOUGHNUT) strXml += `<c:holeSize val="${typeof opts.holeSize === 'number' ? opts.holeSize : '50'}"/>`
strXml += '</c:' + chartType + 'Chart>'
// Done with Doughnut/Pie
break
default:
strXml += ''
break
}
return strXml
}
/**
* Create Category axis
* @param {IChartOptsLib} opts - chart options
* @param {string} axisId - value
* @param {string} valAxisId - value
* @return {string} XML
*/
function makeCatAxis (opts: IChartOptsLib, axisId: string, valAxisId: string): string {
let strXml = ''
// Build cat axis tag
// NOTE: Scatter and Bubble chart need two Val axises as they display numbers on x axis
if (opts._type === CHART_TYPE.SCATTER || opts._type === CHART_TYPE.BUBBLE || opts._type === CHART_TYPE.BUBBLE3D) {
strXml += '<c:valAx>'
} else {
strXml += '<c:' + (opts.catLabelFormatCode ? 'dateAx' : 'catAx') + '>'
}
strXml += ' <c:axId val="' + axisId + '"/>'
strXml += ' <c:scaling>'
strXml += '<c:orientation val="' + (opts.catAxisOrientation || (opts.barDir === 'col' ? 'minMax' : 'minMax')) + '"/>'
if (opts.catAxisMaxVal || opts.catAxisMaxVal === 0) strXml += `<c:max val="${opts.catAxisMaxVal}"/>`
if (opts.catAxisMinVal || opts.catAxisMinVal === 0) strXml += `<c:min val="${opts.catAxisMinVal}"/>`
strXml += '</c:scaling>'
strXml += ' <c:delete val="' + (opts.catAxisHidden ? '1' : '0') + '"/>'
strXml += ' <c:axPos val="' + (opts.barDir === 'col' ? 'b' : 'l') + '"/>'
strXml += opts.catGridLine.style !== 'none' ? createGridLineElement(opts.catGridLine) : ''
// '<c:title>' comes between '</c:majorGridlines>' and '<c:numFmt>'
if (opts.showCatAxisTitle) {
strXml += genXmlTitle({
color: opts.catAxisTitleColor,
fontFace: opts.catAxisTitleFontFace,
fontSize: opts.catAxisTitleFontSize,
titleRotate: opts.catAxisTitleRotate,
title: opts.catAxisTitle || 'Axis Title',
})
}
// NOTE: Adding Val Axis Formatting if scatter or bubble charts
if (opts._type === CHART_TYPE.SCATTER || opts._type === CHART_TYPE.BUBBLE || opts._type === CHART_TYPE.BUBBLE3D) {
strXml += ' <c:numFmt formatCode="' + (opts.valAxisLabelFormatCode ? encodeXmlEntities(opts.valAxisLabelFormatCode) : 'General') + '" sourceLinked="1"/>'
} else {
strXml += ' <c:numFmt formatCode="' + (encodeXmlEntities(opts.catLabelFormatCode) || 'General') + '" sourceLinked="1"/>'
}
if (opts._type === CHART_TYPE.SCATTER) {
strXml += ' <c:majorTickMark val="none"/>'
strXml += ' <c:minorTickMark val="none"/>'
strXml += ' <c:tickLblPos val="nextTo"/>'
} else {
strXml += ' <c:majorTickMark val="' + (opts.catAxisMajorTickMark || 'out') + '"/>'
strXml += ' <c:minorTickMark val="' + (opts.catAxisMinorTickMark || 'none') + '"/>'
strXml += ' <c:tickLblPos val="' + (opts.catAxisLabelPos || (opts.barDir === 'col' ? 'low' : 'nextTo')) + '"/>'
}
strXml += ' <c:spPr>'
strXml += ` <a:ln w="${opts.catAxisLineSize ? valToPts(opts.catAxisLineSize) : ONEPT}" cap="flat">`
strXml += !opts.catAxisLineShow ? '<a:noFill/>' : '<a:solidFill>' + createColorElement(opts.catAxisLineColor || DEF_CHART_GRIDLINE.color) + '</a:solidFill>'
strXml += ' <a:prstDash val="' + (opts.catAxisLineStyle || 'solid') + '"/>'
strXml += ' <a:round/>'
strXml += ' </a:ln>'
strXml += ' </c:spPr>'
strXml += ' <c:txPr>'
if (opts.catAxisLabelRotate) {
strXml += `<a:bodyPr rot="${convertRotationDegrees(opts.catAxisLabelRotate)}"/>`
} else {
// NOTE: don't specify "`rot=0" - that way the object will be auto behavior
strXml += '<a:bodyPr/>'
}
strXml += ' <a:lstStyle/>'
strXml += ' <a:p>'
strXml += ' <a:pPr>'
strXml += ` <a:defRPr sz="${Math.round((opts.catAxisLabelFontSize || DEF_FONT_SIZE) * 100)}" b="${opts.catAxisLabelFontBold ? 1 : 0}" i="${opts.catAxisLabelFontItalic ? 1 : 0}" u="none" strike="noStrike">`
strXml += ' <a:solidFill>' + createColorElement(opts.catAxisLabelColor || DEF_FONT_COLOR) + '</a:solidFill>'
strXml += ' <a:latin typeface="' + (opts.catAxisLabelFontFace || 'Arial') + '"/>'
strXml += ' </a:defRPr>'
strXml += ' </a:pPr>'
strXml += ' <a:endParaRPr lang="' + (opts.lang || 'en-US') + '"/>'
strXml += ' </a:p>'
strXml += ' </c:txPr>'
strXml += ' <c:crossAx val="' + valAxisId + '"/>'
strXml += ` <c:${typeof opts.valAxisCrossesAt === 'number' ? 'crossesAt' : 'crosses'} val="${opts.valAxisCrossesAt || 'autoZero'}"/>`
strXml += ' <c:auto val="1"/>'
strXml += ' <c:lblAlgn val="ctr"/>'
strXml += ` <c:noMultiLvlLbl val="${opts.catAxisMultiLevelLabels ? 0 : 1}"/>`
if (opts.catAxisLabelFrequency) strXml += ' <c:tickLblSkip val="' + opts.catAxisLabelFrequency + '"/>'
// Issue#149: PPT will auto-adjust these as needed after calcing the date bounds, so we only include them when specified by user
// Allow major and minor units to be set for double value axis charts
if (opts.catLabelFormatCode || opts._type === CHART_TYPE.SCATTER || opts._type === CHART_TYPE.BUBBLE || opts._type === CHART_TYPE.BUBBLE3D) {
if (opts.catLabelFormatCode) {
['catAxisBaseTimeUnit', 'catAxisMajorTimeUnit', 'catAxisMinorTimeUnit'].forEach(opt => {
// Validate input as poorly chosen/garbage options will cause chart corruption and it wont render at all!
if (opts[opt] && (typeof opts[opt] !== 'string' || !['days', 'months', 'years'].includes(opts[opt].toLowerCase()))) {
console.warn(`"${opt}" must be one of: 'days','months','years' !`)
opts[opt] = null
}
})
if (opts.catAxisBaseTimeUnit) strXml += '<c:baseTimeUnit val="' + opts.catAxisBaseTimeUnit.toLowerCase() + '"/>'
if (opts.catAxisMajorTimeUnit) strXml += '<c:majorTimeUnit val="' + opts.catAxisMajorTimeUnit.toLowerCase() + '"/>'
if (opts.catAxisMinorTimeUnit) strXml += '<c:minorTimeUnit val="' + opts.catAxisMinorTimeUnit.toLowerCase() + '"/>'
}
if (opts.catAxisMajorUnit) strXml += `<c:majorUnit val="${opts.catAxisMajorUnit}"/>`
if (opts.catAxisMinorUnit) strXml += `<c:minorUnit val="${opts.catAxisMinorUnit}"/>`
}
// Close cat axis tag
// NOTE: Added closing tag of val or cat axis based on chart type
if (opts._type === CHART_TYPE.SCATTER || opts._type === CHART_TYPE.BUBBLE || opts._type === CHART_TYPE.BUBBLE3D) {
strXml += '</c:valAx>'
} else {
strXml += '</c:' + (opts.catLabelFormatCode ? 'dateAx' : 'catAx') + '>'
}
return strXml
}
/**
* Create Value Axis (Used by `bar3D`)
* @param {IChartOptsLib} opts - chart options
* @param {string} valAxisId - value
* @return {string} XML
*/
function makeValAxis (opts: IChartOptsLib, valAxisId: string): string {
let axisPos = valAxisId === AXIS_ID_VALUE_PRIMARY ? (opts.barDir === 'col' ? 'l' : 'b') : opts.barDir !== 'col' ? 'r' : 't'
if (valAxisId === AXIS_ID_VALUE_SECONDARY) axisPos = 'r' // default behavior for PPT is showing 2nd val axis on right (primary axis on left)
const crossAxId = valAxisId === AXIS_ID_VALUE_PRIMARY ? AXIS_ID_CATEGORY_PRIMARY : AXIS_ID_CATEGORY_SECONDARY
let strXml = ''
strXml += '<c:valAx>'
strXml += ' <c:axId val="' + valAxisId + '"/>'
strXml += ' <c:scaling>'
if (opts.valAxisLogScaleBase) strXml += `<c:logBase val="${opts.valAxisLogScaleBase}"/>`
strXml += '<c:orientation val="' + (opts.valAxisOrientation || (opts.barDir === 'col' ? 'minMax' : 'minMax')) + '"/>'
if (opts.valAxisMaxVal || opts.valAxisMaxVal === 0) strXml += `<c:max val="${opts.valAxisMaxVal}"/>`
if (opts.valAxisMinVal || opts.valAxisMinVal === 0) strXml += `<c:min val="${opts.valAxisMinVal}"/>`
strXml += ' </c:scaling>'
strXml += ` <c:delete val="${opts.valAxisHidden ? 1 : 0}"/>`
strXml += ' <c:axPos val="' + axisPos + '"/>'
if (opts.valGridLine.style !== 'none') strXml += createGridLineElement(opts.valGridLine)
// '<c:title>' comes between '</c:majorGridlines>' and '<c:numFmt>'
if (opts.showValAxisTitle) {
strXml += genXmlTitle({
color: opts.valAxisTitleColor,
fontFace: opts.valAxisTitleFontFace,
fontSize: opts.valAxisTitleFontSize,
titleRotate: opts.valAxisTitleRotate,
title: opts.valAxisTitle || 'Axis Title',
})
}
strXml += `<c:numFmt formatCode="${opts.valAxisLabelFormatCode ? encodeXmlEntities(opts.valAxisLabelFormatCode) : 'General'}" sourceLinked="0"/>`
if (opts._type === CHART_TYPE.SCATTER) {
strXml += ' <c:majorTickMark val="none"/>'
strXml += ' <c:minorTickMark val="none"/>'
strXml += ' <c:tickLblPos val="nextTo"/>'
} else {
strXml += ' <c:majorTickMark val="' + (opts.valAxisMajorTickMark || 'out') + '"/>'
strXml += ' <c:minorTickMark val="' + (opts.valAxisMinorTickMark || 'none') + '"/>'
strXml += ' <c:tickLblPos val="' + (opts.valAxisLabelPos || (opts.barDir === 'col' ? 'nextTo' : 'low')) + '"/>'
}
strXml += ' <c:spPr>'
strXml += ` <a:ln w="${opts.valAxisLineSize ? valToPts(opts.valAxisLineSize) : ONEPT}" cap="flat">`
strXml += !opts.valAxisLineShow ? '<a:noFill/>' : '<a:solidFill>' + createColorElement(opts.valAxisLineColor || DEF_CHART_GRIDLINE.color) + '</a:solidFill>'
strXml += ' <a:prstDash val="' + (opts.valAxisLineStyle || 'solid') + '"/>'
strXml += ' <a:round/>'
strXml += ' </a:ln>'
strXml += ' </c:spPr>'
strXml += ' <c:txPr>'
strXml += ` <a:bodyPr${opts.valAxisLabelRotate ? (' rot="' + convertRotationDegrees(opts.valAxisLabelRotate).toString() + '"') : ''}/>` // don't specify rot 0 so we get the auto behavior
strXml += ' <a:lstStyle/>'
strXml += ' <a:p>'
strXml += ' <a:pPr>'
strXml += ` <a:defRPr sz="${Math.round((opts.valAxisLabelFontSize || DEF_FONT_SIZE) * 100)}" b="${opts.valAxisLabelFontBold ? 1 : 0}" i="${opts.valAxisLabelFontItalic ? 1 : 0}" u="none" strike="noStrike">`
strXml += ' <a:solidFill>' + createColorElement(opts.valAxisLabelColor || DEF_FONT_COLOR) + '</a:solidFill>'
strXml += ' <a:latin typeface="' + (opts.valAxisLabelFontFace || 'Arial') + '"/>'
strXml += ' </a:defRPr>'
strXml += ' </a:pPr>'
strXml += ' <a:endParaRPr lang="' + (opts.lang || 'en-US') + '"/>'
strXml += ' </a:p>'
strXml += ' </c:txPr>'
strXml += ' <c:crossAx val="' + crossAxId + '"/>'
if (typeof opts.catAxisCrossesAt === 'number') {
strXml += ` <c:crossesAt val="${opts.catAxisCrossesAt}"/>`
} else if (typeof opts.catAxisCrossesAt === 'string') {
strXml += ' <c:crosses val="' + opts.catAxisCrossesAt + '"/>'
} else {
const isRight = axisPos === 'r' || axisPos === 't'
const crosses = isRight ? 'max' : 'autoZero'
strXml += ' <c:crosses val="' + crosses + '"/>'
}
strXml +=
' <c:crossBetween val="' +
(opts._type === CHART_TYPE.SCATTER || (!!(Array.isArray(opts._type) && opts._type.filter(type => type.type === CHART_TYPE.AREA).length > 0)) ? 'midCat' : 'between') +
'"/>'
if (opts.valAxisMajorUnit) strXml += ` <c:majorUnit val="${opts.valAxisMajorUnit}"/>`
if (opts.valAxisDisplayUnit) { strXml += `<c:dispUnits><c:builtInUnit val="${opts.valAxisDisplayUnit}"/>${opts.valAxisDisplayUnitLabel ? '<c:dispUnitsLbl/>' : ''}</c:dispUnits>` }
strXml += '</c:valAx>'
return strXml
}
/**
* Create Series Axis (Used by `bar3D`)
* @param {IChartOptsLib} opts - chart options
* @param {string} axisId - axis ID
* @param {string} valAxisId - value
* @return {string} XML
*/
function makeSerAxis (opts: IChartOptsLib, axisId: string, valAxisId: string): string {
let strXml = ''
// Build ser axis tag
strXml += '<c:serAx>'
strXml += ' <c:axId val="' + axisId + '"/>'
strXml += ' <c:scaling><c:orientation val="' + (opts.serAxisOrientation || (opts.barDir === 'col' ? 'minMax' : 'minMax')) + '"/></c:scaling>'
strXml += ' <c:delete val="' + (opts.serAxisHidden ? '1' : '0') + '"/>'
strXml += ' <c:axPos val="' + (opts.barDir === 'col' ? 'b' : 'l') + '"/>'
strXml += opts.serGridLine.style !== 'none' ? createGridLineElement(opts.serGridLine) : ''
// '<c:title>' comes between '</c:majorGridlines>' and '<c:numFmt>'
if (opts.showSerAxisTitle) {
strXml += genXmlTitle({
color: opts.serAxisTitleColor,
fontFace: opts.serAxisTitleFontFace,
fontSize: opts.serAxisTitleFontSize,
titleRotate: opts.serAxisTitleRotate,
title: opts.serAxisTitle || 'Axis Title',
})
}
strXml += ` <c:numFmt formatCode="${encodeXmlEntities(opts.serLabelFormatCode) || 'General'}" sourceLinked="0"/>`
strXml += ' <c:majorTickMark val="out"/>'
strXml += ' <c:minorTickMark val="none"/>'
strXml += ` <c:tickLblPos val="${opts.serAxisLabelPos || opts.barDir === 'col' ? 'low' : 'nextTo'}"/>`
strXml += ' <c:spPr>'
strXml += ' <a:ln w="12700" cap="flat">'
strXml += !opts.serAxisLineShow ? '<a:noFill/>' : `<a:solidFill>${createColorElement(opts.serAxisLineColor || DEF_CHART_GRIDLINE.color)}</a:solidFill>`
strXml += ' <a:prstDash val="solid"/>'
strXml += ' <a:round/>'
strXml += ' </a:ln>'
strXml += ' </c:spPr>'
strXml += ' <c:txPr>'
strXml += ' <a:bodyPr/>' // don't specify rot 0 so we get the auto behavior
strXml += ' <a:lstStyle/>'
strXml += ' <a:p>'
strXml += ' <a:pPr>'
strXml += ` <a:defRPr sz="${Math.round((opts.serAxisLabelFontSize || DEF_FONT_SIZE) * 100)}" b="${opts.serAxisLabelFontBold ? '1' : '0'}" i="${opts.serAxisLabelFontItalic ? '1' : '0'}" u="none" strike="noStrike">`
strXml += ` <a:solidFill>${createColorElement(opts.serAxisLabelColor || DEF_FONT_COLOR)}</a:solidFill>`
strXml += ` <a:latin typeface="${opts.serAxisLabelFontFace || 'Arial'}"/>`
strXml += ' </a:defRPr>'
strXml += ' </a:pPr>'
strXml += ' <a:endParaRPr lang="' + (opts.lang || 'en-US') + '"/>'
strXml += ' </a:p>'
strXml += ' </c:txPr>'
strXml += ' <c:crossAx val="' + valAxisId + '"/>'
strXml += ' <c:crosses val="autoZero"/>'
if (opts.serAxisLabelFrequency) strXml += ' <c:tickLblSkip val="' + opts.serAxisLabelFrequency + '"/>'
// Issue#149: PPT will auto-adjust these as needed after calcing the date bounds, so we only include them when specified by user
if (opts.serLabelFormatCode) {
['serAxisBaseTimeUnit', 'serAxisMajorTimeUnit', 'serAxisMinorTimeUnit'].forEach(opt => {
// Validate input as poorly chosen/garbage options will cause chart corruption and it wont render at all!
if (opts[opt] && (typeof opts[opt] !== 'string' || !['days', 'months', 'years'].includes(opt.toLowerCase()))) {
console.warn(`"${opt}" must be one of: 'days','months','years' !`)
opts[opt] = null
}
})
if (opts.serAxisBaseTimeUnit) strXml += ` <c:baseTimeUnit val="${opts.serAxisBaseTimeUnit.toLowerCase()}"/>`
if (opts.serAxisMajorTimeUnit) strXml += ` <c:majorTimeUnit val="${opts.serAxisMajorTimeUnit.toLowerCase()}"/>`
if (opts.serAxisMinorTimeUnit) strXml += ` <c:minorTimeUnit val="${opts.serAxisMinorTimeUnit.toLowerCase()}"/>`
if (opts.serAxisMajorUnit) strXml += ` <c:majorUnit val="${opts.serAxisMajorUnit}"/>`
if (opts.serAxisMinorUnit) strXml += ` <c:minorUnit val="${opts.serAxisMinorUnit}"/>`
}
// Close ser axis tag
strXml += '</c:serAx>'
return strXml
}
/**
* Create char title elements
* @param {IChartPropsTitle} opts - options
* @return {string} XML `<c:title>`
*/
function genXmlTitle (opts: IChartPropsTitle, chartX?: number, chartY?: number): string {
const align = opts.titleAlign === 'left' || opts.titleAlign === 'right' ? `<a:pPr algn="${opts.titleAlign.substring(0, 1)}">` : '<a:pPr>'
const rotate = opts.titleRotate ? `<a:bodyPr rot="${convertRotationDegrees(opts.titleRotate)}"/>` : '<a:bodyPr/>' // don't specify rotation to get default (ex. vertical for cat axis)
const sizeAttr = opts.fontSize ? `sz="${Math.round(opts.fontSize * 100)}"` : '' // only set the font size if specified. Powerpoint will handle the default size
const titleBold = opts.titleBold ? 1 : 0
let layout = '<c:layout/>'
if (opts.titlePos && typeof opts.titlePos.x === 'number' && typeof opts.titlePos.y === 'number') {
// NOTE: manualLayout x/y vals are *relative to entire slide*
const totalX = opts.titlePos.x + chartX
const totalY = opts.titlePos.y + chartY
let valX = totalX === 0 ? 0 : (totalX * (totalX / 5)) / 10
if (valX >= 1) valX = valX / 10
if (valX >= 0.1) valX = valX / 10
let valY = totalY === 0 ? 0 : (totalY * (totalY / 5)) / 10
if (valY >= 1) valY = valY / 10
if (valY >= 0.1) valY = valY / 10
layout = `<c:layout><c:manualLayout><c:xMode val="edge"/><c:yMode val="edge"/><c:x val="${valX}"/><c:y val="${valY}"/></c:manualLayout></c:layout>`
}
return `<c:title>
<c:tx>
<c:rich>
${rotate}
<a:lstStyle/>
<a:p>
${align}
<a:defRPr ${sizeAttr} b="${titleBold}" i="0" u="none" strike="noStrike">
<a:solidFill>${createColorElement(opts.color || DEF_FONT_COLOR)}</a:solidFill>
<a:latin typeface="${opts.fontFace || 'Arial'}"/>
</a:defRPr>
</a:pPr>
<a:r>
<a:rPr ${sizeAttr} b="${titleBold}" i="0" u="none" strike="noStrike">
<a:solidFill>${createColorElement(opts.color || DEF_FONT_COLOR)}</a:solidFill>
<a:latin typeface="${opts.fontFace || 'Arial'}"/>
</a:rPr>
<a:t>${encodeXmlEntities(opts.title) || ''}</a:t>
</a:r>
</a:p>
</c:rich>
</c:tx>
${layout}
<c:overlay val="0"/>
</c:title>`
}
/**
* Calc and return excel column name for a given column length
* @param colIndex column index
* @return column name
* @example 1 returns 'A'
* @example 27 returns 'AA'
*/
function getExcelColName (colIndex: number): string {
let colStr = ''
const colIdx = colIndex - 1 // Subtract 1 so `LETTERS[columnIndex]` returns "A" etc
if (colIdx <= 25) {
// A-Z
colStr = LETTERS[colIdx]
} else {
// AA-ZZ (ZZ = index 702)
colStr = `${LETTERS[Math.floor(colIdx / LETTERS.length - 1)]}${LETTERS[colIdx % LETTERS.length]}`
}
return colStr
}
/**
* Creates `a:innerShdw` or `a:outerShdw` depending on pass options `opts`.
* @param {Object} opts optional shadow properties
* @param {Object} defaults defaults for unspecified properties in `opts`
* @see http://officeopenxml.com/drwSp-effects.php
* @example { type: 'outer', blur: 3, offset: (23000 / 12700), angle: 90, color: '000000', opacity: 0.35, rotateWithShape: true };
* @return {string} XML
*/
function createShadowElement (options: ShadowProps, defaults: object): string {
if (!options) {
return '<a:effectLst/>'
} else if (typeof options !== 'object') {
console.warn('`shadow` options must be an object. Ex: `{shadow: {type:\'none\'}}`')
return '<a:effectLst/>'
}
let strXml = '<a:effectLst>'
const opts = { ...defaults, ...options }
const type = opts.type || 'outer'
const blur = valToPts(opts.blur)
const offset = valToPts(opts.offset)
const angle = Math.round(opts.angle * 60000)
const color = opts.color
const opacity = Math.round(opts.opacity * 100000)
const rotShape = opts.rotateWithShape ? 1 : 0
strXml += `<a:${type}Shdw sx="100000" sy="100000" kx="0" ky="0" algn="bl" blurRad="${blur}" rotWithShape="${rotShape}" dist="${offset}" dir="${angle}">`
strXml += `<a:srgbClr val="${color}">`
strXml += `<a:alpha val="${opacity}"/></a:srgbClr>`
strXml += `</a:${type}Shdw>`
strXml += '</a:effectLst>'
return strXml
}
/**
* Create Grid Line Element
* @param {OptsChartGridLine} glOpts {size, color, style}
* @return {string} XML
*/
function createGridLineElement (glOpts: OptsChartGridLine): string {
let strXml = '<c:majorGridlines>'
strXml += ' <c:spPr>'
strXml += ` <a:ln w="${valToPts(glOpts.size || DEF_CHART_GRIDLINE.size)}" cap="${createLineCap(glOpts.cap || DEF_CHART_GRIDLINE.cap)}">`
strXml += ' <a:solidFill><a:srgbClr val="' + (glOpts.color || DEF_CHART_GRIDLINE.color) + '"/></a:solidFill>' // should accept scheme colors as implemented in [Pull #135]
strXml += ' <a:prstDash val="' + (glOpts.style || DEF_CHART_GRIDLINE.style) + '"/><a:round/>'
strXml += ' </a:ln>'
strXml += ' </c:spPr>'
strXml += '</c:majorGridlines>'
return strXml
}
function createLineCap (lineCap: ChartLineCap): string {
if (!lineCap || lineCap === 'flat') {
return 'flat'
} else if (lineCap === 'square') {
return 'sq'
} else if (lineCap === 'round') {
return 'rnd'
} else {
const neverLineCap: never = lineCap
throw new Error(`Invalid chart line cap: ${neverLineCap}`)
}
}
|