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
|
--- -*- coding: utf-8 -*-
--- licensed under GPL, any version
newPackage(
"Graphics",
Version => "0.3",
Date => "June 4, 2013",
Authors => {
{Name => "Baptiste Calmes",
HomePage => "http://bcalmes.perso.math.cnrs.fr/"},
{Name => "Viktor Petrov"}
},
Headline => "create graphics",
Keywords => {"Graphics"},
DebuggingMode => false)
-- Put here the name of functions that should be visible to users
export{
"Point2D", "Point3D", "Segment2D", "Segment3D", "Polygon2D", "Polygon3D", "Circle", "Sphere", "TextTag", "GraphicPrimitive",
"FormattedGraphicPrimitives", "Picture",
"point", "segment", "polygon", "circle", "sphere", "textTag", "formatGraphicPrimitives", "picture",
"pictureZone",
"mergeFormattedGraphicPrimitives",
"svgObject", "svgPicture", "defaultSVGOpening",
"pgfObject", "pgfPicture",
"viewPicture"
}
-- Variables that can be modified by the user
exportMutable{
"possibleSVGOptions", "defaultSVGOptions", "defaultSVGValues", "defaultSVGHeading", "defaultSVGClosing",
"possiblePGFOptions", "defaultPGFOptions", "defaultPGFValues"
}
-- Package code
--Defining the class of a GraphicPrimitive. It will have child types like Points, etc.
GraphicPrimitive = new Type of BasicList
--Defining the class of a FormattedGraphicPrimitives. It is a basic list that contains a list of GraphicPrimitives and a hash table of formatting options (like color, thickness, width, etc.)
FormattedGraphicPrimitives = new Type of BasicList
--Defining the class of a FormattedGraphicPrimitive. It is a basic list that contains a GraphicPrimitive and a hash table of formatting options (like color, thickness, width, etc.)
--FormattedGraphicPrimitive = new Type of BasicList
--Defining the class of a Picture. It is a basic list containing FormattedGraphicPrimitives. Some functions should be written to optimize it as far as options are concerned. The order of the FGPs should not be changed, for reasons of what should appear above what on screen.
Picture = new Type of BasicList
--Defining the class of a point (each point is at least two coordinates)
Point2D = new Type of GraphicPrimitive
--Defining the class of a point (each point is at least two coordinates)
Point3D = new Type of GraphicPrimitive
--Defining the class of a line segment (two points)
Segment2D = new Type of GraphicPrimitive
--Defining the class of a line segment (two points)
Segment3D = new Type of GraphicPrimitive
--Defining the class of a polygon (set of points)
Polygon2D = new Type of GraphicPrimitive
--Defining the class of a polygon (set of points)
Polygon3D = new Type of GraphicPrimitive
--Defining the class of a sphere (a center point and a radius)
Circle = new Type of GraphicPrimitive
--Defining the class of a sphere (a center point and a radius)
Sphere = new Type of GraphicPrimitive
--Defining the class of a text tag (a string and a position where to put it)
TextTag = new Type of GraphicPrimitive
--Making a Point (2D or 3D)
point = method()
point(ZZ,ZZ) := (x,y) -> new Point2D from {x,y}
point(RR,RR) := (x,y) -> new Point2D from {round(x),round(y)}
point(ZZ,ZZ,ZZ) := (x,y,z) -> new Point3D from {x,y,z}
point(RR,RR,RR) := (x,y,z) -> new Point3D from {round(x),round(y),round(z)}
--Making a Segment from points
segment = method()
segment(Point2D,Point2D) := (p,q) -> new Segment2D from {p,q}
segment(Point3D,Point3D) := (p,q) -> new Segment3D from {p,q}
--Making a polygon from a list points
polygon = method()
polygon(List) := (L) ->
(
cl:=keys set(class\L);
if cl === {Point2D} then return new Polygon2D from L;
if cl === {Point3D} then return new Polygon3D from L;
error "The list should be non empty, all elements in it should have the same type, either Point2D or Point3D."
)
--Making a circle from a center point and a radius
circle = method()
circle(Point2D,ZZ) := (p,r) -> new Circle from {p,r}
circle(Point2D,RR) := (p,r) -> new Circle from {p,round(r)}
--Making a sphere from a center point and a radius
sphere = method()
sphere(Point3D,ZZ) := (p,r) -> new Sphere from {p,r}
sphere(Point3D,RR) := (p,r) -> new Sphere from {p,round(r)}
--Making a text tag from a point and a string
textTag = method()
textTag(Point2D,String) := (p,s) -> new TextTag from {p,s}
textTag(Point3D,String) := (p,s) -> new TextTag from {p,s}
--Turning a GraphicPrimitive object into a formatted one by specifying options. These options will be passed to the different methods to create pictures in different formats (ex: SVG, etc.) so they are not constrained here because I don't know what graphic formats will be supported in the future.
formatGraphicPrimitives = method()
formatGraphicPrimitives(BasicList,HashTable) := (gplist, h) ->
(
if all(gplist,x->instance(x,GraphicPrimitive)) then new FormattedGraphicPrimitives from {gplist,h} else error "All elements of the list should be of the type GraphicPrimitive."
)
--make a picture out of a list of FormattedGraphicPrimitives. No optimization is done on the options.
picture = method()
picture(BasicList) := (fgplist) ->
(
if all(fgplist,x->instance(x,FormattedGraphicPrimitives)) then new Picture from fgplist else error "All elements of the list should be of the type FormattedGraphicPrimitives."
)
--merging two FormattedGraphicPrimitives
mergeFormattedGraphicPrimitives = method(Options => true)
mergeFormattedGraphicPrimitives(FormattedGraphicPrimitives,FormattedGraphicPrimitives) := {"keep"=>"1","priority"=>"1"} >> opts -> (fgp1,fgp2) ->
(
new FormattedGraphicPrimitives from {(fgp1#0)|(fgp2#0),mergeOptions(fgp1#1,fgp2#1,"keep"=>opts#"keep","priority"=>opts#"priority")}
)
mergeOptions = {"keep"=>"1or2","priority"=>"1"} >> opts -> (h1,h2) ->
(
if opts#"keep" === "1" or opts#"keep" === "1and2" then h2 = applyPairs(h2,(k,v)->if (h1)#?k then (k,v));
if opts#"keep" === "2" or opts#"keep" === "1and2" then h1 = applyPairs(h1,(k,v)->if (h2)#?k then (k,v));
if opts#"priority" === "1" then return merge(h1,h2,(x,y)->x);
if opts#"priority" === "2" then return merge(h1,h2,(x,y)->y);
)
--determine the zone in which a GraphicPrimitive object lives. It is given as a list {xmin,xmax,ymin,ymax} for 2D objects and {xmin,xmax,ymin,ymax} for 3D objects.
pictureZone = method()
pictureZone(Point2D) := (GP) -> {GP#0,GP#0,GP#1,GP#1}
pictureZone(Point3D) := (GP) -> {GP#0,GP#0,GP#1,GP#1,GP#2,GP#2}
pictureZone(Segment2D) := (GP) -> {min(GP#0#0,GP#1#0),max(GP#0#0,GP#1#0),min(GP#0#1,GP#1#1),max(GP#0#1,GP#1#1)}
pictureZone(Segment3D) := (GP) -> {min(GP#0#0,GP#1#0),max(GP#0#0,GP#1#0),min(GP#0#1,GP#1#1),max(GP#0#1,GP#1#1),min(GP#0#2,GP#1#2),max(GP#0#2,GP#1#2)}
pictureZone(Circle) := (GP) -> {GP#0#0-GP#1,GP#0#0+GP#1,GP#0#1-GP#1,GP#0#1+GP#1}
pictureZone(Sphere) := (GP) -> {GP#0#0-GP#1,GP#0#0+GP#1,GP#0#1-GP#1,GP#0#1+GP#1,GP#0#2-GP#1,GP#0#2+GP#1}
pictureZone(Polygon2D) := (GP) ->
(
Lx:=toList apply(GP,x->x#0);
Ly:=toList apply(GP,x->x#1);
{min Lx,max Lx, min Ly, max Ly}
)
pictureZone(Polygon3D) := (GP) ->
(
Lx:=toList apply(GP,x->x#0);
Ly:=toList apply(GP,x->x#1);
Lz:=toList apply(GP,x->x#2);
{min Lx,max Lx, min Ly, max Ly,min Lz, max Lz}
)
pictureZone(TextTag) := (GP) -> pictureZone(GP#0)
--determine the zone in which a list of GraphicPrimitives lie. It is supposed a nonempty list and to be consistent in containing only 2D objects or only 3D objects.
pictureZone(FormattedGraphicPrimitives) := (fgps) ->
(
mylist:=apply(fgps#0,pictureZone);
if #(mylist#0)==4 then
{min apply(mylist,x->x#0), max apply(mylist,x->x#1), min apply(mylist,x->x#2), max apply(mylist,x->x#3)}
else if #(mylist#0)==6 then
{min apply(mylist,x->x#0), max apply(mylist,x->x#1), min apply(mylist,x->x#2), max apply(mylist,x->x#3), min apply(mylist,x->x#4), max apply(mylist,x->x#5)}
)
--determine the zone in which a picture lies
pictureZone(Picture) := (pict) ->
(
mylist:=apply(toList(pict),pictureZone);
if #(mylist#0)==4 then
{min apply(mylist,x->x#0), max apply(mylist,x->x#1), min apply(mylist,x->x#2), max apply(mylist,x->x#3)}
else if #(mylist#0)==6 then
{min apply(mylist,x->x#0), max apply(mylist,x->x#1), min apply(mylist,x->x#2), max apply(mylist,x->x#3), min apply(mylist,x->x#4), max apply(mylist,x->x#5)}
)
-- SVG section
--
--Functions are defined to translate graphic primitives into SVG language.
--
--Default SVG values for coordinates, etc.
defaultSVGValues= hashTable{
Point2D => hashTable{
"cx"=>"0",
"cy"=>"0",
"r"=>"2",
},
Circle => hashTable{
"cx"=>"0",
"cy"=>"0",
"r"=>"10",
},
Segment2D => hashTable{
"x1"=>"0",
"y1"=>"0",
"x2"=>"0",
"y2"=>"0",
},
Polygon2D => hashTable{
"points"=>"0,0",
},
TextTag => hashTable{
"x"=>"0",
"y"=>"0",
}
}
--possible SVG options
possibleSVGOptions = hashTable{
Point2D => set{"stroke","stroke-width","stroke-opacity","fill","fill-opacity"},
Circle => set{"stroke","stroke-width","stroke-opacity","fill","fill-opacity"},
Segment2D => set{"stroke","stroke-width","stroke-opacity"},
Polygon2D => set{"stroke","stroke-width","stroke-opacity","fill","fill-opacity"},
TextTag => set{"stroke","stroke-width","stroke-opacity","fill","fill-opacity","font-family","font-size"}
}
--Default SVG options for each graphic primitive
defaultSVGOptions = hashTable{
Point2D => hashTable{
"stroke"=>"black",
"stroke-width"=>"0",
"stroke-opacity"=>"1",
"fill"=>"black",
"fill-opacity"=>"1"
},
Circle => hashTable{
"stroke"=>"black",
"stroke-width"=>"1",
"stroke-opacity"=>"1",
"fill"=>"black",
"fill-opacity"=>"0"
},
Segment2D => hashTable{
"stroke"=>"black",
"stroke-width"=>"1",
"stroke-opacity"=>"1",
},
Polygon2D => hashTable{
"stroke"=>"black",
"stroke-width"=>"1",
"stroke-opacity"=>"1",
"fill"=>"black",
"fill-opacity"=>"1"
},
TextTag => hashTable{
"stroke"=>"black",
"stroke-width"=>"0",
"stroke-opacity"=>"0",
"fill"=>"black",
"fill-opacity"=>"1",
"font-family"=>"Verdana",
"font-size"=>"12"
}
}
--default SVG document heading
defaultSVGHeading =
(///<?xml version="1.0" standalone="no"?>
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN"
"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
///)
--default SVG opening
defaultSVGOpening = method()
defaultSVGOpening(ZZ,ZZ) := (wid,hei) ->
(///<svg width="///|toString(wid)|///" height="///|toString(hei)|///" version="1.1"
xmlns="http://www.w3.org/2000/svg">
///)
--default SVG closing
defaultSVGClosing =
(///</svg>
///)
--Making an SVG object (stored in a string) from a Graphic Primitive and some options
svgObject = method()
svgObject(Point2D,HashTable) := (mypt,opts) ->
(
opts= mergeOptions(mergeOptions(opts,possibleSVGOptions#Point2D,"keep"=>"1and2","priority"=>"1"),defaultSVGOptions#Point2D);
"<circle "
|///cx="///|toString(mypt#0)|///" cy="///|toString(mypt#1)|///" r="///|defaultSVGValues#Point2D#("r")|///" ///
|concatenate(apply(pairs(opts),x->(x#0|///="///|x#1|///" ///)))
|"/>"
)
svgObject(Circle,HashTable) := (mycirc,opts) ->
(
opts= mergeOptions(mergeOptions(opts,possibleSVGOptions#Circle,"keep"=>"1and2","priority"=>"1"),defaultSVGOptions#Circle);
"<circle "
|///cx="///|toString(mycirc#0#0)|///" cy="///|toString(mycirc#0#1)|///" r="///|toString(mycirc#1)|///" ///
|concatenate(apply(pairs(opts),x->(x#0|///="///|x#1|///" ///)))
|"/>"
)
svgObject(Segment2D,HashTable) := (myseg,opts) ->
(
opts= mergeOptions(mergeOptions(opts,possibleSVGOptions#Segment2D,"keep"=>"1and2","priority"=>"1"),defaultSVGOptions#Segment2D);
"<line "
|///x1="///|toString(myseg#0#0)|///" y1="///|toString(myseg#0#1)|///" x2="///|toString(myseg#1#0)|///" y2="///|toString(myseg#1#1)|///" ///
|concatenate(apply(pairs(opts),x->(x#0|///="///|x#1|///" ///)))
|"/>"
)
svgObject(Polygon2D,HashTable) := (mypoly,opts) ->
(
opts= mergeOptions(mergeOptions(opts,possibleSVGOptions#Polygon2D,"keep"=>"1and2","priority"=>"1"),defaultSVGOptions#Polygon2D);
"<polygon "
|///points="///|concatenate(apply(mypoly,x->toString(x#0)|","|toString(x#1)|" "))|///" ///
|concatenate(apply(pairs(opts),x->(x#0|///="///|x#1|///" ///)))
|"/>"
)
svgObject(TextTag,HashTable) := (mytext,opts) ->
(
opts= mergeOptions(mergeOptions(opts,possibleSVGOptions#TextTag,"keep"=>"1and2","priority"=>"1"),defaultSVGOptions#TextTag);
///<text id="TextElement" ///
|///x="///|toString(mytext#0#0)|///" y="///|toString(mytext#0#1)|///" ///
|concatenate(apply(pairs(opts),x->(x#0|///="///|x#1|///" ///)))
|">"
|mytext#1
|"</text>"
)
svgObject(FormattedGraphicPrimitives) := (fgp) -> concatenate(apply(fgp#0,x->svgObject(x,fgp#1)|newline|newline))
svgObject(Picture) := (pict) -> concatenate(apply(toList pict,svgObject))
--Making an SVG picture (stored in a string) from a Picture with prescribed size. It only accepts Pictures with 2D primitives.
svgPicture = method()
svgPicture(Picture,ZZ,ZZ) := (pict,w,h) ->
(
defaultSVGHeading
|defaultSVGOpening(w,h)
|svgObject(pict)
|defaultSVGClosing
)
--Making an SVG picture (stored in a string) from a Picture with size computed to be just the size of the picture.
svgPicture(Picture) := (pict) ->
(
z:=pictureZone(pict);
w:=z#1+100;
h:=z#3+100;
svgPicture(pict,w,h)
)
--Making an SVG picture from a Picture with prescribed size, and storing it in a file
svgPicture(Picture,ZZ,ZZ,String) := (pict,w,h,s) ->
(
(if match(///\.svg\'///,s) then s else s|".svg") << svgPicture(pict,w,h) << endl << close
)
--Making an SVG picture from a Picture with size computed to be just the size of the picture, and storing it in a file
svgPicture(Picture,String) := (pict,s) ->
(
(if match(///\.svg\'///,s) then s else s|".svg") << svgPicture(pict) << endl << close
)
--view a picture document (that is in SVG for the moment) in the default browser.
viewPicture = method()
viewPicture(String) := (filename) ->
(
if match(///\.svg\'///,filename) then show new URL from {filename}
)
--
--PGF section
--containing functions to turn Pictures into the pgf/tikz language for latex
--
--Default PGF options for each graphic primitive
possiblePGFOptions = hashTable{
Picture => set {"scale","x","y"},
Point2D => set {"fill","draw","style","line width","fill opacity","draw opacity","opacity"},
Circle => set{"fill","draw","style","line width","fill opacity","draw opacity","opacity","dashed"},
Segment2D => set{"draw","style","line width","draw opacity","opacity","dashed"},
Polygon2D => set{"fill","draw","style","line width","fill opacity","draw opacity","opacity","dashed"},
TextTag => set{}
}
--Default PGF values for coordinates
defaultPGFValues = hashTable{
Point2D => hashTable{
"cx"=>"0",
"cy"=>"0",
"r"=>"0.1",
},
Circle => hashTable{
"cx"=>"0",
"cy"=>"0",
"r"=>"1",
},
Segment2D => hashTable{},
Polygon2D => hashTable{},
TextTag => hashTable{}
}
--Default PGF options for each graphic primitive
defaultPGFOptions = hashTable{
Picture => hashTable{
},
Point2D => hashTable{
"fill"=>"black"
},
Circle => hashTable{
},
Segment2D => hashTable{
},
Polygon2D => hashTable{
"fill"=>"black",
"fill opacity"=>"1"
},
TextTag => hashTable{
}
}
--making pdf code out of a graphic primitive
pgfObject = method()
pgfObject(Circle,HashTable) := (mycirc,opts)->
(
opts= mergeOptions(mergeOptions(opts,possiblePGFOptions#Circle,"keep"=>"1and2","priority"=>"1"),defaultPGFOptions#Circle);
///\draw[///
|(if #opts==0 then "" else fold(apply(pairs(opts),x->(if x#1===null then x#0 else x#0|"="|x#1)),(a,b)->a|","|b))
|///] (///
|mycirc#0#0|","|mycirc#0#1
|///) circle (///
|mycirc#1
|///);///
)
pgfObject(Point2D,HashTable) := (mypt,opts)->
(
opts= mergeOptions(mergeOptions(opts,possiblePGFOptions#Point2D,"keep"=>"1and2","priority"=>"1"),defaultPGFOptions#Point2D);
///\draw[///
|(if #opts==0 then "" else fold(apply(pairs(opts),x->(if x#1===null then x#0 else x#0|"="|x#1)),(a,b)->a|","|b))
|///] ///
|///(///|mypt#0|","|mypt#1|///) circle (///|defaultPGFValues#Point2D#"r"|///);///
)
pgfObject(Segment2D,HashTable) := (myseg,opts)->
(
opts= mergeOptions(mergeOptions(opts,possiblePGFOptions#Segment2D,"keep"=>"1and2","priority"=>"1"),defaultPGFOptions#Segment2D);
///\draw[///
|(if #opts==0 then "" else fold(apply(pairs(opts),x->(if x#1===null then x#0 else x#0|"="|x#1)),(a,b)->a|","|b))
|///] ///
|///(///|myseg#0#0|","|myseg#0#1|///) -- (///|myseg#1#0|","|myseg#1#1|///);///
)
pgfObject(Polygon2D,HashTable) := (mypoly,opts)->
(
opts= mergeOptions(mergeOptions(opts,possiblePGFOptions#Polygon2D,"keep"=>"1and2","priority"=>"1"),defaultPGFOptions#Polygon2D);
///\draw[///
|fold(apply(pairs(opts),x->(if x#1===null then x#0 else x#0|"="|x#1)),(a,b)->a|","|b)
|///] ///
|(if #opts==0 then "" else fold(apply(toList(mypoly),x->///(///|toString(x#0)|","|toString(x#1)|///)///),(a,b)->a|/// -- ///|b))
|/// -- cycle;///
)
pgfObject(TextTag,HashTable) := (mytext,opts)->
(
opts= mergeOptions(mergeOptions(opts,possiblePGFOptions#TextTag,"keep"=>"1and2","priority"=>"1"),defaultPGFOptions#TextTag);
///\draw ///
|///(///|mytext#0#0|","|mytext#0#1|///) ///
|///node[///
|(if #opts==0 then "" else fold(apply(pairs(opts),x->(if x#1===null then x#0 else x#0|"="|x#1)),(a,b)->a|","|b))
|///] ///
|///{///|mytext#1|///};///
)
--This is bad. One should use a scope for each FormattedGraphicPrimitive. I will fix this later.
pgfObject(FormattedGraphicPrimitives) := (fgp) -> concatenate(apply(fgp#0,x->pgfObject(x,fgp#1)|newline))
--Here one could maybe accept global options for scope.
pgfObject(Picture) := (pict) -> concatenate(apply(toList pict,pgfObject))
--making a complete pgf picture out a Picture object and some global options
pgfPicture = method()
pgfPicture(Picture,HashTable) := (pict,opts) ->
(
opts= mergeOptions(mergeOptions(opts,possiblePGFOptions#Picture,"keep"=>"1and2","priority"=>"1"),defaultPGFOptions#Picture);
///\begin{tikzpicture}[///
|(if #opts==0 then "" else fold(apply(pairs(opts),x->(if x#1===null then x#0 else x#0|"="|x#1)),(a,b)->a|","|b))
|///]///|newline
|pgfObject(pict)
|///\end{tikzpicture}///|newline
)
pgfPicture(Picture) := (pict) ->
(
///\begin{tikzpicture}///|newline
|pgfObject(pict)
|///\end{tikzpicture}///|newline
)
pgfPicture(Picture,HashTable,String) := (pict,opts,filename) ->
(
(if match(///\.tex\'///,filename) then filename else filename|".tex") << pgfPicture(pict,opts) << endl << close
)
pgfPicture(Picture,String) := (pict,filename) ->
(
(if match(///\.tex\'///,filename) then filename else filename|".tex") << pgfPicture(pict) << endl << close
)
--The rest of the file is documentation.
beginDocumentation()
doc ///
Key
Graphics
Headline
Graphics
Description
Text
This package provides graphic primitives and functions to turn them into pictures in different formats. The formats supported include svg and pgf/tikz.
///
doc ///
Key
GraphicPrimitive
Headline
the class of all graphic primitives
///
doc ///
Key
FormattedGraphicPrimitives
Headline
the class of lists of graphic primitives together with formatting options
///
doc ///
Key
Picture
Headline
the class of pictures containing several FormattedGraphicPrimitives
///
doc ///
Key
Point2D
Headline
the class of a point in a 2D space
///
doc ///
Key
Point3D
Headline
the class of a point in a 3D space
///
doc ///
Key
Segment2D
Headline
the class of a line segment in a 2D space
///
doc ///
Key
Segment3D
Headline
the class of a line segment in a 3D space
///
doc ///
Key
Polygon2D
Headline
the class of a polygon in a 2D space
///
doc ///
Key
Polygon3D
Headline
the class of a polygon in a 3D space
///
doc ///
Key
Circle
Headline
the class of a circle in a 2D space
///
doc ///
Key
Sphere
Headline
the class of a sphere in a 3D space
///
doc ///
Key
TextTag
Headline
the class of a text tag
///
doc ///
Key
point
Headline
create a point
///
doc ///
Key
(point,ZZ,ZZ)
Headline
a point from two coordinates
Usage
point(x,y)
Inputs
x: ZZ
y: ZZ
Outputs
: Point2D
the point with coordinates {\tt x} and {\tt y}
Description
Example
point(20, 30)
///
doc ///
Key
(point,RR,RR)
Headline
a point from two coordinates
Usage
point(x,y)
Inputs
x: RR
y: RR
Outputs
: Point2D
the point with coordinates {\tt x} and {\tt y}
Description
Example
point(2.1, 3.)
///
doc ///
Key
(point,ZZ,ZZ,ZZ)
Headline
a point from three coordinates
Usage
point(x,y,z)
Inputs
x: ZZ
y: ZZ
z: ZZ
Outputs
: Point3D
the point with coordinates {\tt x}, {\tt y} and {\tt z}
Description
Example
point(20,30,40)
///
doc ///
Key
(point,RR,RR,RR)
Headline
a point from three coordinates
Usage
point(x,y,z)
Inputs
x: RR
y: RR
z: RR
Outputs
: Point3D
the point with coordinates {\tt x}, {\tt y} and {\tt z}
Description
Example
point(2.1, 3.,4.)
///
doc ///
Key
segment
Headline
create a line segment
///
doc ///
Key
(segment,Point2D,Point2D)
Headline
a line segment from two points
Usage
segment(p,q)
Inputs
p: Point2D
q: Point2D
Outputs
: Segment2D
the line segment with endpoints {\tt p} and {\tt q}
Description
Example
p=point(2.1, 3.)
q=point(.4, 4.6)
segment(p,q)
///
doc ///
Key
(segment,Point3D,Point3D)
Headline
a line segment from two points
Usage
segment(p,q)
Inputs
p: Point3D
q: Point3D
Outputs
: Segment3D
the line segment with endpoints {\tt p} and {\tt q}
Description
Example
p=point(2.1, 3.,4.)
q=point(.4, 4.6,5.3)
segment(p,q)
///
doc ///
Key
polygon
Headline
create a polygon from a list of points
///
doc ///
Key
(polygon,List)
Headline
a polygon from a list of points
Usage
polygon(L)
Inputs
L: List
of @TO Point2D@s or of @TO Point3D@s
Outputs
: Thing
the polygon defined by the points in {\tt L}
Description
Text
All the points must be of the same class, either @TO Point2D@ or @TO Point3D@.
Example
L={point(2.1, 3.),point(.4, 4.6),point(3.1,5.)}
polygon(L)
///
doc ///
Key
circle
Headline
create a circle from a point and a radius
///
doc ///
Key
(circle,Point2D,ZZ)
Headline
a circle from a center and a radius
Usage
circle(p,r)
Inputs
p: Point2D
the center of the circle
r: ZZ
the radius of the circle
Outputs
: Circle
the circle with center {\tt p} and radius {\tt r}
Description
Example
circle(point(20,30),10)
///
doc ///
Key
(circle,Point2D,RR)
Headline
a circle from a center and a radius
Usage
circle(p,r)
Inputs
p: Point2D
the center of the circle
r: RR
the radius of the circle
Outputs
: Circle
the circle with center {\tt p} and radius {\tt r}
Description
Example
circle(point(20.1, 30.),30.)
///
doc ///
Key
sphere
Headline
create a sphere from a point and a radius
///
doc ///
Key
(sphere,Point3D,ZZ)
Headline
a sphere from a center and a radius
Usage
sphere(p,r)
Inputs
p: Point3D
the center of the sphere
r: ZZ
the radius of the sphere
Outputs
: Sphere
the sphere with center {\tt p} and radius {\tt r}
Description
Example
sphere(point(20,30,100),10)
///
doc ///
Key
(sphere,Point3D,RR)
Headline
a sphere from a center and a radius
Usage
sphere(p,r)
Inputs
p: Point3D
the center of the sphere
r: RR
the radius of the sphere
Outputs
: Sphere
the sphere with center {\tt p} and radius {\tt r}
Description
Example
sphere(point(20.1, 30.,100.),30.)
///
doc ///
Key
textTag
Headline
create a text tag at a position
///
doc ///
Key
(textTag,Point2D,String)
Headline
a text tag at a position
Usage
textTag(p,s)
Inputs
p: Point2D
the position of the tag
s: String
the text of the tag
Outputs
: TextTag
the {\tt TextTag} with text {\tt s} at position {\tt p}
Description
Example
textTag(point(2.1, 3.),"My Tag")
///
doc ///
Key
(textTag,Point3D,String)
Headline
a text tag at a position
Usage
textTag(p,s)
Inputs
p: Point3D
the position of the tag
s: String
the text of the tag
Outputs
: TextTag
the {\tt TextTag} with text {\tt s} at position {\tt p}
Description
Example
textTag(point(2.1, 3.,4.),"My Tag")
///
doc ///
Key
formatGraphicPrimitives
Headline
create a FormattedGraphicPrimitives object
///
doc ///
Key
(formatGraphicPrimitives,BasicList,HashTable)
Headline
create a formatted graphic primitive object
Usage
textTag(gplist,h)
Inputs
gplist: BasicList
h: HashTable
containing graphic options
Outputs
: FormattedGraphicPrimitives
Description
Example
myPoint1=point(20.,30.)
myPoint2=point(30.,40.)
myOptions = hashTable {"fill"=>"black"}
formatGraphicPrimitives({myPoint1,myPoint2},myOptions)
///
TEST ///
mylist={point(20.,30.),point(30.,40.)};
myOptions = hashTable {"fill"=>"black"};
assert(formatGraphicPrimitives(mylist,myOptions)===new FormattedGraphicPrimitives from {mylist,myOptions})
///
doc ///
Key
picture
Headline
create a Picture object
///
doc ///
Key
(picture,BasicList)
Headline
create a picture object
Usage
picture(fgplist,h)
Inputs
fgplist: BasicList
a list of FormattedGraphicPrimitives
Outputs
: Picture
Description
Example
myfgp1=formatGraphicPrimitives({point(20.,30.),point(30.,40.)},hashTable {"fill"=>"black"})
myfgp2=formatGraphicPrimitives({circle(point(20.,30.),10)},hashTable {"fill"=>"red"})
picture({myfgp1,myfgp2})
///
doc ///
Key
pictureZone
Headline
find the zone in which a picture lies
///
doc ///
Key
(pictureZone,Point2D)
Headline
find the zone that contains the point
Usage
pictureZone(p)
Inputs
p: Point2D
Outputs
: List
of the form {xmin,xmax,ymin,ymax}
Description
Example
pictureZone(point(20,30))
///
TEST ///
assert(pictureZone(point(20,30))==={20,20,30,30})
///
doc ///
Key
(pictureZone,Point3D)
Headline
find the zone that contains the point
Usage
pictureZone(p)
Inputs
p: Point3D
Outputs
: List
of the form {xmin,xmax,ymin,ymax,zmin,zmax}
Description
Example
pictureZone(point(20,30,40))
///
TEST ///
assert(pictureZone(point(20,30,40))==={20,20,30,30,40,40})
///
doc ///
Key
(pictureZone,Segment2D)
Headline
find the zone that contains the line segment
Usage
pictureZone(l)
Inputs
l: Segment2D
Outputs
: List
of the form {xmin,xmax,ymin,ymax}
Description
Example
pictureZone(segment(point(20,30),point(30,40)))
///
TEST ///
assert(pictureZone(segment(point(20,30),point(30,40)))==={20,30,30,40})
///
doc ///
Key
(pictureZone,Segment3D)
Headline
find the zone that contains the line segment
Usage
pictureZone(l)
Inputs
l: Segment3D
Outputs
: List
of the form {xmin,xmax,ymin,ymax,zmin,zmax}
Description
Example
pictureZone(segment(point(20,30,40),point(30,40,50)))
///
TEST ///
assert(pictureZone(segment(point(20,30,40),point(30,40,50)))==={20,30,30,40,40,50})
///
doc ///
Key
(pictureZone,Circle)
Headline
find the zone that contains the circle
Usage
pictureZone(c)
Inputs
c: Circle
Outputs
: List
of the form {xmin,xmax,ymin,ymax}
Description
Example
pictureZone(circle(point(20,30),10))
///
TEST ///
assert(pictureZone(circle(point(20,30),10))==={10,30,20,40})
///
doc ///
Key
(pictureZone,Sphere)
Headline
find the zone that contains the sphere
Usage
pictureZone(s)
Inputs
s: Sphere
Outputs
: List
of the form {xmin,xmax,ymin,ymax,zmin,zmax}
Description
Example
pictureZone(sphere(point(20,30,40),10))
///
TEST ///
assert(pictureZone(sphere(point(20,30,40),10))==={10,30,20,40,30,50})
///
doc ///
Key
(pictureZone,Polygon2D)
Headline
find the zone that contains the polygon
Usage
pictureZone(p)
Inputs
p: Polygon2D
Outputs
: List
of the form {xmin,xmax,ymin,ymax}
Description
Example
pictureZone(polygon({point(20,30),point(25,30),point(20,35)}))
///
TEST ///
assert(pictureZone(polygon({point(20,30),point(25,30),point(20,35)}))==={20,25,30,35})
///
doc ///
Key
(pictureZone,Polygon3D)
Headline
find the zone that contains the polygon
Usage
pictureZone(p)
Inputs
p: Polygon3D
Outputs
: List
of the form {xmin,xmax,ymin,ymax,zmin,zmax}
Description
Example
pictureZone(polygon({point(20,30,40),point(25,30,40),point(20,35,45)}))
///
TEST ///
assert(pictureZone(polygon({point(20,30,40),point(25,30,40),point(20,35,40)}))==={20,25,30,35,40,40})
///
doc ///
Key
(pictureZone,TextTag)
Headline
find the zone that contains the tag
Usage
pictureZone(t)
Inputs
t: TextTag
Outputs
: List
of the form {xmin,xmax,ymin,ymax} or {xmin,xmax,ymin,ymax,zmin,zmax}
Description
Example
pictureZone(textTag(point(20,30),"my tag"))
pictureZone(textTag(point(20,30,40),"my tag"))
///
TEST ///
assert(pictureZone(textTag(point(20,30),"my tag"))==={20,20,30,30})
assert(pictureZone(textTag(point(20,30,40),"my tag"))==={20,20,30,30,40,40})
///
doc ///
Key
(pictureZone,FormattedGraphicPrimitives)
Headline
find the zone that contains the whole list of graphic primitive
Usage
pictureZone(fgp)
Inputs
fgp: FormattedGraphicPrimitives
Outputs
: List
of the form {xmin,xmax,ymin,ymax} (or {xmin,xmax,ymin,ymax,zmin,zmax} for 3D objects) describing a zone containing the object fgp
Description
Example
pictureZone(formatGraphicPrimitives({circle(point(20,30),10)},hashTable {"fill"=>"black"}))
///
TEST ///
assert(pictureZone(formatGraphicPrimitives({circle(point(20,30),10),point(50,40)},hashTable {"fill"=>"black"}))==={10,50,20,40})
///
doc ///
Key
(pictureZone,Picture)
Headline
find the zone that contains the whole picture
Usage
pictureZone(mypict)
Inputs
mypict: Picture
Outputs
: List
of the form {xmin,xmax,ymin,ymax} (or {xmin,xmax,ymin,ymax,zmin,zmax} for 3D objects) describing a zone containing the object fgp
Description
Example
myfgp1=formatGraphicPrimitives({point(20.,30.),point(30.,40.)},hashTable {"fill"=>"black"})
myfgp2=formatGraphicPrimitives({circle(point(20.,30.),10)},hashTable {"fill"=>"red"})
mypict=picture({myfgp1,myfgp2})
pictureZone(mypict)
///
TEST ///
myfgp1=formatGraphicPrimitives({point(20.,30.),point(30.,40.)},hashTable {"fill"=>"black"});
myfgp2=formatGraphicPrimitives({circle(point(20.,30.),10)},hashTable {"fill"=>"red"});
mypict=picture({myfgp1,myfgp2});
assert(pictureZone(mypict)==={10,30,20,40})
///
doc ///
Key
mergeFormattedGraphicPrimitives
Headline
merge two lists of graphic primitives with options
///
doc ///
Key
(mergeFormattedGraphicPrimitives,FormattedGraphicPrimitives,FormattedGraphicPrimitives)
Headline
merge two lists of graphic primitives with options
Usage
mergeFormattedGraphicPrimitives(fgp1,fgp2)
Inputs
fgp1: FormattedGraphicPrimitives
fgp2: FormattedGraphicPrimitives
Outputs
: FormattedGraphicPrimitives
Description
Text
The list of graphic primitives are concatenated and the graphic options are merged according to the value of two options {\tt "keep"} (either "1or2", "1" or "2") and {\tt "priority"} (either "1" or "2").
Example
myoptions1= new HashTable from {"fill"=>"black"}
myoptions2= new HashTable from {"fill"=>"blue","stroke"=>"red"}
fgp1=formatGraphicPrimitives({point(20,30),point(40,50)},myoptions1)
fgp2=formatGraphicPrimitives({circle(point(30,40),10)},myoptions2)
mergeFormattedGraphicPrimitives(fgp1,fgp2)
mergeFormattedGraphicPrimitives(fgp1,fgp2,"keep"=>"2","priority"=>"1")
///
doc ///
Key
"defaultSVGOptions"
Headline
the default SVG options
Description
Text
It's a hash table containing the default SVG options for all graphic primitives that can be used to create an SVG document.
///
doc ///
Key
"defaultSVGValues"
Headline
the default SVG values of coordinates
Description
Text
It's a hash table containing the default SVG values for some graphic primitives. They can be used while creating an SVG document.
///
doc ///
Key
"possibleSVGOptions"
Headline
the possible SVG options
Description
Text
It's a hash table containing the possible SVG options for graphic primitives that can be used to create an SVG picture. Options not listed here will usually be discarded when the primitive is turned into an SVG object.
///
doc ///
Key
"defaultSVGHeading"
Headline
the default SVG heading
Description
Text
It's a string containing the default SVG heading used to create SVG pictures.
///
doc ///
Key
defaultSVGOpening
Headline
the default SVG opening
///
doc ///
Key
(defaultSVGOpening,ZZ,ZZ)
Headline
default SVG opening for a picture of a given size
Usage
defaultSVGOpening(w,h)
Inputs
w: ZZ
h: ZZ
Outputs
: String
Description
Text
It returns a string containing the default SVG opening of the form <svg etc. used to create an SVG picture.
///
doc ///
Key
"defaultSVGClosing"
Headline
the default SVG closing
Description
Text
It's a string containing the default SVG closing </svg> used to create SVG pictures.
///
doc ///
Key
svgObject
Headline
create an SVG object
///
doc ///
Key
(svgObject,FormattedGraphicPrimitives)
Headline
create a string describing in SVG a list of formatted graphic primitive object
Usage
svgObject(fgp)
Inputs
fgp: FormattedGraphicPrimitives
Outputs
: String
containing the description of an object in SVG
Description
Text
The options that are not given in the hash table part of {\tt fgp} are set at the default values contained in {\tt defaultSVGOptions}.
Example
myoptions = hashTable {"fill"=>"black"}
myfgp= formatGraphicPrimitives({point(20,30)},myoptions)
svgObject(myfgp)
///
doc ///
Key
(svgObject,Picture)
Headline
create a string describing the picture in SVG
Usage
svgObject(mypict)
Inputs
mypict: Picture
Outputs
: String
containing the description of the picture in SVG
Description
Example
myfgp1=formatGraphicPrimitives({point(20.,30.),point(30.,40.)},hashTable {"fill"=>"black"})
myfgp2=formatGraphicPrimitives({circle(point(20.,30.),10)},hashTable {"fill"=>"red"})
mypict=picture({myfgp1,myfgp2})
svgObject(mypict)
SeeAlso
svgPicture
viewPicture
///
doc ///
Key
(svgObject,Point2D,HashTable)
Headline
create the string describing a point in SVG
Usage
svgObject(mypoint,myoptions)
Inputs
mypoint: Point2D
myoptions: HashTable
giving values to some options (see @TO "defaultSVGOptions"@).
Outputs
: String
containing the description of the point in SVG
Description
Text
The options that are not given in {\tt myoptions} are set at the default values contained in @TO "defaultSVGOptions"@.
Example
myoptions = hashTable {"fill"=>"black"}
svgObject(point(20,30),myoptions)
///
doc ///
Key
(svgObject,Segment2D,HashTable)
Headline
create the string describing a line segment in SVG
Usage
svgObject(mysegment,myoptions)
Inputs
mysegment: Segment2D
myoptions: HashTable
giving values to some options (see @TO "defaultSVGOptions"@).
Outputs
: String
containing the description of the segment in SVG
Description
Text
The options that are not given in {\tt myoptions} are set at the default values contained in @TO "defaultSVGOptions"@.
Example
myoptions = hashTable {"stroke-width"=>"2"}
svgObject(segment(point(20,30),point(40,50)),myoptions)
///
doc ///
Key
(svgObject,Circle,HashTable)
Headline
create the string describing a circle in SVG
Usage
svgObject(mycircle,myoptions)
Inputs
mycircle: Circle
myoptions: HashTable
giving values to some options (see @TO "defaultSVGOptions"@).
Outputs
: String
containing the description of the circle in SVG
Description
Text
The options that are not given in {\tt myoptions} are set at the default values contained in @TO "defaultSVGOptions"@.
Example
myoptions = hashTable {"fill"=>"black"}
svgObject(circle(point(20,30),10),myoptions)
///
doc ///
Key
(svgObject,Polygon2D,HashTable)
Headline
create the string describing a circle in SVG
Usage
svgObject(mypolygon,myoptions)
Inputs
mypolygon: Polygon2D
myoptions: HashTable
giving values to some options (see @TO "defaultSVGOptions"@).
Outputs
: String
containing the description of the polygon in SVG
Description
Text
The options that are not given in {\tt myoptions} are set at the default values contained in @TO "defaultSVGOptions"@.
Example
myoptions = hashTable {"fill"=>"black"}
svgObject(polygon({point(20,30),point(40,50),point(10,40)}),myoptions)
///
doc ///
Key
(svgObject,TextTag,HashTable)
Headline
create the string describing a circle in SVG
Usage
svgObject(mytext,myoptions)
Inputs
mytext: TextTag
myoptions: HashTable
giving values to some options (see @TO "defaultSVGOptions"@).
Outputs
: String
containing the description of the text tag in SVG
Description
Text
The options that are not given in {\tt myoptions} are set at the default values contained in @TO "defaultSVGOptions"@.
Example
myoptions = hashTable {"font-family"=>"verdana"}
svgObject(textTag(point(20,30),"Hello world"),myoptions)
///
doc ///
Key
svgPicture
Headline
create an SVG picture
///
doc ///
Key
(svgPicture,Picture,ZZ,ZZ)
Headline
create an SVG picture from a Picture object
Usage
svgPicture(mypict,w,h)
Inputs
mypict: Picture
w: ZZ
the width of the picture
h: ZZ
the height of the picture
Outputs
: String
containing the SVG picture
Description
Text
The heading used is stored in @TO "defaultSVGHeading"@ and the SVG opening bracket (resp. closing) used is stored in @TO "defaultSVGOpening"@ (resp. @TO "defaultSVGClosing"@).
Example
myfgp1 = formatGraphicPrimitives({point(20,30)},hashTable {"fill"=>"black"})
myfgp2 = formatGraphicPrimitives({circle(point(20,30),10),point(50,60)},hashTable {"fill"=>"red","fill-opacity"=>"0.2"})
mypict = picture {myfgp1,myfgp2}
svgPicture(mypict,100,100)
SeeAlso
(svgPicture,Picture)
(svgPicture,Picture,ZZ,ZZ,String)
(svgPicture,Picture,String)
(pgfPicture,Picture)
///
doc ///
Key
(svgPicture,Picture)
Headline
create an SVG picture from a Picture object
Usage
svgPicture(mypict)
Inputs
mypict: Picture
Outputs
: String
containing the SVG picture
Description
Text
The heading used is stored in @TO "defaultSVGHeading"@ and the SVG opening bracket (resp. closing) used is stored in @TO "defaultSVGOpening"@ (resp. @TO "defaultSVGClosing"@).
Example
myfgp1 = formatGraphicPrimitives({point(20,30)},hashTable {"fill"=>"black"})
myfgp2 = formatGraphicPrimitives({circle(point(20,30),10),point(50,60)},hashTable {"fill"=>"red","fill-opacity"=>"0.2"})
mypict = picture {myfgp1,myfgp2}
svgPicture(mypict)
SeeAlso
(svgPicture,Picture,ZZ,ZZ)
(svgPicture,Picture,ZZ,ZZ,String)
(svgPicture,Picture,String)
(pgfPicture,Picture)
///
doc ///
Key
(svgPicture,Picture,String)
Headline
create an SVG picture from a Picture object and store it in a file
Usage
svgPicture(mypict,filename)
Inputs
mypict: Picture
filename: String
the name of the storage file
Description
Text
If the filename is without a .svg suffix, it will be added.
Text
The heading used is stored in @TO "defaultSVGHeading"@ and the SVG opening bracket (resp. closing) used is stored in @TO "defaultSVGOpening"@ (resp. @TO "defaultSVGClosing"@).
SeeAlso
(svgPicture,Picture)
(pgfPicture,Picture)
///
doc ///
Key
(svgPicture,Picture,ZZ,ZZ,String)
Headline
create an SVG picture from a Picture object and store it in a file
Usage
svgPicture(mypict,w,h,filename)
Inputs
mypict: Picture
w: ZZ
the width of the SVG picture
h: ZZ
the height of the SVG picture
filename: String
the name of the storage file
Description
Text
If the filename is without a .svg suffix, it will be added.
Text
The heading used is stored in @TO "defaultSVGHeading"@ and the SVG opening bracket (resp. closing) used is stored in @TO "defaultSVGOpening"@ (resp. @TO "defaultSVGClosing"@).
SeeAlso
(svgPicture,Picture)
(pgfPicture,Picture)
///
doc ///
Key
"defaultPGFOptions"
Headline
the default pgf options
Description
Text
It's a hash table containing the default pgf options for graphic primitives that can be used to create a pgf picture.
///
doc ///
Key
"possiblePGFOptions"
Headline
the possible pgf options
Description
Text
It's a hash table containing the possible pgf options for graphic primitives that can be used to create a pgf picture. Options not listed here will usually be discarded.
///
doc ///
Key
"defaultPGFValues"
Headline
the default pgf values
Description
Text
It's a hash table containing the default pgf values for some graphic primitives that are used to create a pgf picture.
///
doc ///
Key
pgfObject
Headline
create a pgf object
///
doc ///
Key
(pgfObject,Point2D,HashTable)
Headline
create the string describing a point in pgf
Usage
pgfObject(mypoint,myoptions)
Inputs
mypoint: Point2D
myoptions: HashTable
giving values to some options
Outputs
: String
containing the description of the point in pgf
Description
Text
The options that are not given in {\tt myoptions} are set at their default values if they are contained in @TO "defaultPGFOptions"@. Options not listed in @TO "possiblePGFOptions"@ are discarded. The size of the point comes from @TO "defaultPGFValues"@.
Example
myoptions = hashTable {"fill"=>"red"}
pgfObject(point(20,30),myoptions)
///
doc ///
Key
(pgfObject,Segment2D,HashTable)
Headline
create the string describing a line segment in pgf
Usage
pgfObject(mysegment,myoptions)
Inputs
mysegment: Segment2D
myoptions: HashTable
giving values to some options
Outputs
: String
containing the description of the segment in pgf
Description
Text
The options that are not given in {\tt myoptions} are set at their default values if they are contained in @TO "defaultPGFOptions"@. Options not listed in @TO "possiblePGFOptions"@ are discarded.
Example
myoptions = hashTable {"fill"=>"black"}
pgfObject(segment(point(20,30),point(40,50)),myoptions)
///
doc ///
Key
(pgfObject,Circle,HashTable)
Headline
create the string describing a circle in pgf
Usage
pgfObject(mycircle,myoptions)
Inputs
mycircle: Circle
myoptions: HashTable
giving values to some options
Outputs
: String
containing the description of the circle in pgf
Description
Text
The options that are not given in {\tt myoptions} are set at their default values if they are contained in @TO "defaultPGFOptions"@. Options not listed in @TO "possiblePGFOptions"@ are discarded.
Example
myoptions = hashTable {"fill"=>"black"}
pgfObject(circle(point(20,30),10),myoptions)
///
doc ///
Key
(pgfObject,Polygon2D,HashTable)
Headline
create the string describing a circle in pgf
Usage
svgObject(mypolygon,myoptions)
Inputs
mypolygon: Polygon2D
myoptions: HashTable
giving values to some options
Outputs
: String
containing the description of the polygon in pgf
Description
Text
The options that are not given in {\tt myoptions} are set at their default values if they are contained in @TO "defaultPGFOptions"@. Options not listed in @TO "possiblePGFOptions"@ are discarded.
Example
myoptions = hashTable {"fill"=>"black"}
pgfObject(polygon({point(20,30),point(40,50),point(10,40)}),myoptions)
///
doc ///
Key
(pgfObject,TextTag,HashTable)
Headline
create the string describing a circle in pgf
Usage
pgfObject(mytext,myoptions)
Inputs
mytext: TextTag
myoptions: HashTable
giving values to some options
Outputs
: String
containing the description of the text tag in pgf
Description
Text
The options that are not given in {\tt myoptions} are set at their default values if they are contained in @TO "defaultPGFOptions"@. Options not listed in @TO "possiblePGFOptions"@ are discarded.
Example
myoptions = hashTable {"fill"=>"black"}
pgfObject(textTag(point(20,30),"Hello world"),myoptions)
///
doc ///
Key
(pgfObject,FormattedGraphicPrimitives)
Headline
create the string describing a series of graphic primitives in pgf
Usage
pgfObject(FGP)
Inputs
FGP: FormattedGraphicPrimitives
Outputs
: String
containing the description of all the graphic primitives contained in the FormattedGraphicPrimitives in pgf
Description
Text
The options that are not given in the hash table part of FGP are set at their default values if they are contained in @TO "defaultPGFOptions"@. Options not listed in @TO "possiblePGFOptions"@ are discarded.
Example
myoptions = hashTable {"fill"=>"black"}
myfgp= formatGraphicPrimitives({point(20,30)},myoptions)
pgfObject(myfgp)
///
doc ///
Key
(pgfObject,Picture)
Headline
create the string describing a series of graphic primitives in pgf
Usage
pgfObject(pict)
Inputs
pict: Picture
Outputs
: String
containing the description of all the graphic primitives contained in the Picture in pgf
Description
Text
The options that are not given in the hash table parts of the various FormattedGraphicPrimitives in the picture are set at their default values if they are contained in @TO "defaultPGFOptions"@. Options not listed in @TO "possiblePGFOptions"@ are discarded.
Example
myfgp1=formatGraphicPrimitives({point(20.,30.),point(30.,40.)},hashTable {"fill"=>"black"})
myfgp2=formatGraphicPrimitives({circle(point(20.,30.),10)},hashTable {"fill"=>"red"})
mypict=picture({myfgp1,myfgp2})
pgfObject(mypict)
///
doc ///
Key
pgfPicture
Headline
create a pgf picture
///
doc ///
Key
(pgfPicture,Picture)
Headline
create a pgf picture from a Picture object
Usage
pgfPicture(mypict)
Inputs
mypict: Picture
Outputs
: String
containing the pgf picture
Description
Example
myfgp1 = formatGraphicPrimitives({point(20,30)},hashTable {"fill"=>"black"})
myfgp2 = formatGraphicPrimitives({circle(point(20,30),10),point(50,60)},hashTable {"fill"=>"red","fill-opacity"=>"0.2"})
mypict = picture {myfgp1,myfgp2}
pgfPicture(mypict)
SeeAlso
(pgfPicture,Picture,HashTable)
(svgPicture,Picture)
///
doc ///
Key
(pgfPicture,Picture,HashTable)
Headline
create a pgf picture from a Picture object with some options
Usage
pgfPicture(mypict,myoptions)
Inputs
mypict: Picture
myoptions: HashTable
Outputs
: String
containing the picture in pgf
Description
Example
myfgp1 = formatGraphicPrimitives({point(20,30)},hashTable {"fill"=>"black"})
myfgp2 = formatGraphicPrimitives({circle(point(20,30),10),point(50,60)},hashTable {"fill"=>"red","fill-opacity"=>"0.2"})
mypict = picture {myfgp1,myfgp2}
myoptions = hashTable{"scale"=>"0.5","x"=>"0.1cm","y"=>"0.2cm"}
pgfPicture(mypict,myoptions)
SeeAlso
(pgfPicture,Picture)
(svgPicture,Picture)
///
doc ///
Key
(pgfPicture,Picture,String)
Headline
create a pgf picture from a Picture object and store it in a file
Usage
pgfPicture(mypict,filename)
Inputs
mypict: Picture
filename: String
the name of the storage file
Description
Text
If the filename is without a .tex suffix, it will be added.
SeeAlso
(pgfPicture,Picture,HashTable,String)
(pgfPicture,Picture)
(pgfPicture,Picture,HashTable)
(svgPicture,Picture)
///
doc ///
Key
(pgfPicture,Picture,HashTable,String)
Headline
create a pgf picture from a Picture object with options and store it in a file
Usage
pgfPicture(mypict,opts,filename)
Inputs
mypict: Picture
opts: HashTable
containing the options
filename: String
the name of the storage file
Description
Text
If the filename is without a .tex suffix, it will be added.
SeeAlso
(pgfPicture,Picture,String)
(pgfPicture,Picture)
(pgfPicture,Picture,HashTable)
(svgPicture,Picture)
///
doc ///
Key
viewPicture
Headline
view a picture in a browser
///
doc ///
Key
(viewPicture,String)
Headline
view a Picture in a browser
Usage
viewPicture(filename)
Inputs
filename: String
the name of the file (possibly with path) containing the picture
Caveat
For the moment, it only works with SVG pictures and browsers supporting them.
///
|