Aucune description

index.js 3.7KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", { value: true });
  3. var SvgHelper = (function () {
  4. function SvgHelper() {
  5. }
  6. SvgHelper.createRect = function (width, height, attributes) {
  7. var rect = document.createElementNS('http://www.w3.org/2000/svg', 'rect');
  8. rect.setAttribute('width', width.toString());
  9. rect.setAttribute('height', height.toString());
  10. if (attributes) {
  11. SvgHelper.setAttributes(rect, attributes);
  12. }
  13. return rect;
  14. };
  15. SvgHelper.createLine = function (x1, y1, x2, y2, attributes) {
  16. var line = document.createElementNS('http://www.w3.org/2000/svg', 'line');
  17. line.setAttribute('x1', x1.toString());
  18. line.setAttribute('y1', y1.toString());
  19. line.setAttribute('x2', x2.toString());
  20. line.setAttribute('y2', y2.toString());
  21. if (attributes) {
  22. SvgHelper.setAttributes(line, attributes);
  23. }
  24. return line;
  25. };
  26. SvgHelper.createPolygon = function (points, attributes) {
  27. var polygon = document.createElementNS('http://www.w3.org/2000/svg', 'polygon');
  28. polygon.setAttribute('points', points);
  29. if (attributes) {
  30. SvgHelper.setAttributes(polygon, attributes);
  31. }
  32. return polygon;
  33. };
  34. SvgHelper.createCircle = function (radius, attributes) {
  35. var circle = document.createElementNS('http://www.w3.org/2000/svg', 'circle');
  36. circle.setAttribute('cx', (radius / 2).toString());
  37. circle.setAttribute('cy', (radius / 2).toString());
  38. circle.setAttribute('r', radius.toString());
  39. if (attributes) {
  40. SvgHelper.setAttributes(circle, attributes);
  41. }
  42. return circle;
  43. };
  44. SvgHelper.createGroup = function (attributes) {
  45. var g = document.createElementNS('http://www.w3.org/2000/svg', 'g');
  46. if (attributes) {
  47. SvgHelper.setAttributes(g, attributes);
  48. }
  49. return g;
  50. };
  51. SvgHelper.setAttributes = function (el, attributes) {
  52. for (var _i = 0, attributes_1 = attributes; _i < attributes_1.length; _i++) {
  53. var _a = attributes_1[_i], attr = _a[0], value = _a[1];
  54. el.setAttribute(attr, value);
  55. }
  56. };
  57. SvgHelper.createTransform = function () {
  58. var svg = document.createElementNS('http://www.w3.org/2000/svg', 'svg');
  59. return svg.createSVGTransform();
  60. };
  61. SvgHelper.createDefs = function () {
  62. var defs = document.createElementNS('http://www.w3.org/2000/svg', 'defs');
  63. return defs;
  64. };
  65. SvgHelper.createMarker = function (id, orient, markerWidth, markerHeight, refX, refY, markerElement) {
  66. var marker = document.createElementNS('http://www.w3.org/2000/svg', 'marker');
  67. SvgHelper.setAttributes(marker, [
  68. ['id', id],
  69. ['orient', orient],
  70. ['markerWidth', markerWidth.toString()],
  71. ['markerHeight', markerHeight.toString()],
  72. ['refX', refX.toString()],
  73. ['refY', refY.toString()]
  74. ]);
  75. marker.appendChild(markerElement);
  76. return marker;
  77. };
  78. SvgHelper.createText = function (attributes) {
  79. var text = document.createElementNS('http://www.w3.org/2000/svg', 'text');
  80. text.setAttribute('x', '0');
  81. text.setAttribute('y', '0');
  82. if (attributes) {
  83. SvgHelper.setAttributes(text, attributes);
  84. }
  85. return text;
  86. };
  87. SvgHelper.createTSpan = function (text, attributes) {
  88. var tspan = document.createElementNS('http://www.w3.org/2000/svg', 'tspan');
  89. tspan.textContent = text;
  90. if (attributes) {
  91. SvgHelper.setAttributes(tspan, attributes);
  92. }
  93. return tspan;
  94. };
  95. return SvgHelper;
  96. }());
  97. exports.SvgHelper = SvgHelper;