index.js 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. /**
  2. * @fileoverview marker
  3. * @author dengfuping_develop@163.com
  4. */
  5. import { __extends } from "tslib";
  6. import { isArray, isFunction } from '@antv/util';
  7. import ShapeBase from '../base';
  8. import symbolsFactory from './symbols';
  9. var Marker = /** @class */ (function (_super) {
  10. __extends(Marker, _super);
  11. function Marker() {
  12. var _this = _super !== null && _super.apply(this, arguments) || this;
  13. _this.type = 'marker';
  14. _this.canFill = true;
  15. _this.canStroke = true;
  16. return _this;
  17. }
  18. Marker.prototype.createPath = function (context) {
  19. var el = this.get('el');
  20. el.setAttribute('d', this._assembleMarker());
  21. };
  22. Marker.prototype._assembleMarker = function () {
  23. var d = this._getPath();
  24. if (isArray(d)) {
  25. return d
  26. .map(function (path) {
  27. return path.join(' ');
  28. })
  29. .join('');
  30. }
  31. return d;
  32. };
  33. Marker.prototype._getPath = function () {
  34. var attrs = this.attr();
  35. var x = attrs.x, y = attrs.y;
  36. // 兼容 r 和 radius 两种写法,推荐使用 r
  37. var r = attrs.r || attrs.radius;
  38. var symbol = attrs.symbol || 'circle';
  39. var method;
  40. if (isFunction(symbol)) {
  41. method = symbol;
  42. }
  43. else {
  44. method = symbolsFactory.get(symbol);
  45. }
  46. if (!method) {
  47. console.warn(method + " symbol is not exist.");
  48. return null;
  49. }
  50. return method(x, y, r);
  51. };
  52. // 作为其静态属性
  53. Marker.symbolsFactory = symbolsFactory;
  54. return Marker;
  55. }(ShapeBase));
  56. export default Marker;
  57. //# sourceMappingURL=index.js.map