marker.js 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. "use strict";
  2. var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
  3. var _possibleConstructorReturn2 = _interopRequireDefault(require("@babel/runtime/helpers/possibleConstructorReturn"));
  4. var _getPrototypeOf2 = _interopRequireDefault(require("@babel/runtime/helpers/getPrototypeOf"));
  5. var _inheritsLoose2 = _interopRequireDefault(require("@babel/runtime/helpers/inheritsLoose"));
  6. function _createSuper(Derived) { return function () { var Super = (0, _getPrototypeOf2["default"])(Derived), result; if (_isNativeReflectConstruct()) { var NewTarget = (0, _getPrototypeOf2["default"])(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return (0, _possibleConstructorReturn2["default"])(this, result); }; }
  7. function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Date.prototype.toString.call(Reflect.construct(Date, [], function () {})); return true; } catch (e) { return false; } }
  8. /**
  9. * marker shapes,used for tooltip and legend
  10. */
  11. var Util = require('../util/common');
  12. var _require = require('../graphic/index'),
  13. Shape = _require.Shape;
  14. var SYMBOLS = {
  15. circle: function circle(x, y, r, ctx) {
  16. ctx.arc(x, y, r, 0, Math.PI * 2, false);
  17. },
  18. square: function square(x, y, r, ctx) {
  19. ctx.moveTo(x - r, y - r);
  20. ctx.lineTo(x + r, y - r);
  21. ctx.lineTo(x + r, y + r);
  22. ctx.lineTo(x - r, y + r);
  23. ctx.closePath();
  24. }
  25. };
  26. var Marker = /*#__PURE__*/function (_Shape) {
  27. (0, _inheritsLoose2["default"])(Marker, _Shape);
  28. var _super = _createSuper(Marker);
  29. function Marker() {
  30. return _Shape.apply(this, arguments) || this;
  31. }
  32. var _proto = Marker.prototype;
  33. _proto._initProperties = function _initProperties() {
  34. _Shape.prototype._initProperties.call(this);
  35. this._attrs.canFill = true;
  36. this._attrs.canStroke = true;
  37. this._attrs.type = 'marker';
  38. };
  39. _proto.getDefaultAttrs = function getDefaultAttrs() {
  40. return {
  41. x: 0,
  42. y: 0,
  43. lineWidth: 0
  44. };
  45. };
  46. _proto.createPath = function createPath(context) {
  47. var attrs = this.get('attrs');
  48. var x = attrs.x,
  49. y = attrs.y,
  50. radius = attrs.radius;
  51. var symbol = attrs.symbol || 'circle';
  52. var method;
  53. if (Util.isFunction(symbol)) {
  54. method = symbol;
  55. } else {
  56. method = SYMBOLS[symbol];
  57. }
  58. context.beginPath();
  59. method(x, y, radius, context, this);
  60. };
  61. _proto.calculateBox = function calculateBox() {
  62. var attrs = this.get('attrs');
  63. var x = attrs.x,
  64. y = attrs.y,
  65. radius = attrs.radius;
  66. return {
  67. minX: x - radius,
  68. minY: y - radius,
  69. maxX: x + radius,
  70. maxY: y + radius
  71. };
  72. };
  73. return Marker;
  74. }(Shape);
  75. module.exports = Marker;