index.js 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. "use strict";
  2. /**
  3. * @fileoverview defs
  4. * @author dengfuping_develop@163.com
  5. */
  6. Object.defineProperty(exports, "__esModule", { value: true });
  7. var util_1 = require("@antv/util");
  8. var gradient_1 = require("./gradient");
  9. var shadow_1 = require("./shadow");
  10. var arrow_1 = require("./arrow");
  11. var clip_1 = require("./clip");
  12. var pattern_1 = require("./pattern");
  13. var dom_1 = require("../util/dom");
  14. var Defs = /** @class */ (function () {
  15. function Defs(canvas) {
  16. var el = dom_1.createSVGElement('defs');
  17. var id = util_1.uniqueId('defs_');
  18. el.id = id;
  19. canvas.appendChild(el);
  20. this.children = [];
  21. this.defaultArrow = {};
  22. this.el = el;
  23. this.canvas = canvas;
  24. }
  25. Defs.prototype.find = function (type, attr) {
  26. var children = this.children;
  27. var result = null;
  28. for (var i = 0; i < children.length; i++) {
  29. if (children[i].match(type, attr)) {
  30. result = children[i].id;
  31. break;
  32. }
  33. }
  34. return result;
  35. };
  36. Defs.prototype.findById = function (id) {
  37. var children = this.children;
  38. var flag = null;
  39. for (var i = 0; i < children.length; i++) {
  40. if (children[i].id === id) {
  41. flag = children[i];
  42. break;
  43. }
  44. }
  45. return flag;
  46. };
  47. Defs.prototype.add = function (item) {
  48. this.children.push(item);
  49. item.canvas = this.canvas;
  50. item.parent = this;
  51. };
  52. Defs.prototype.getDefaultArrow = function (attrs, name) {
  53. var stroke = attrs.stroke || attrs.strokeStyle;
  54. if (this.defaultArrow[stroke]) {
  55. return this.defaultArrow[stroke].id;
  56. }
  57. var arrow = new arrow_1.default(attrs, name);
  58. this.defaultArrow[stroke] = arrow;
  59. this.el.appendChild(arrow.el);
  60. this.add(arrow);
  61. return arrow.id;
  62. };
  63. Defs.prototype.addGradient = function (cfg) {
  64. var gradient = new gradient_1.default(cfg);
  65. this.el.appendChild(gradient.el);
  66. this.add(gradient);
  67. return gradient.id;
  68. };
  69. Defs.prototype.addArrow = function (attrs, name) {
  70. var arrow = new arrow_1.default(attrs, name);
  71. this.el.appendChild(arrow.el);
  72. this.add(arrow);
  73. return arrow.id;
  74. };
  75. Defs.prototype.addShadow = function (cfg) {
  76. var shadow = new shadow_1.default(cfg);
  77. this.el.appendChild(shadow.el);
  78. this.add(shadow);
  79. return shadow.id;
  80. };
  81. Defs.prototype.addPattern = function (cfg) {
  82. var pattern = new pattern_1.default(cfg);
  83. this.el.appendChild(pattern.el);
  84. this.add(pattern);
  85. return pattern.id;
  86. };
  87. Defs.prototype.addClip = function (cfg) {
  88. var clip = new clip_1.default(cfg);
  89. this.el.appendChild(clip.el);
  90. this.add(clip);
  91. return clip.id;
  92. };
  93. return Defs;
  94. }());
  95. exports.default = Defs;
  96. //# sourceMappingURL=index.js.map