polygon.js 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. "use strict";
  2. exports.__esModule = true;
  3. exports["default"] = void 0;
  4. var _base = _interopRequireDefault(require("./base"));
  5. var _common = require("../util/common");
  6. require("./shape/polygon");
  7. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
  8. function _inheritsLoose(subClass, superClass) { subClass.prototype = Object.create(superClass.prototype); subClass.prototype.constructor = subClass; subClass.__proto__ = superClass; }
  9. var Polygon = /*#__PURE__*/function (_Geom) {
  10. _inheritsLoose(Polygon, _Geom);
  11. function Polygon() {
  12. return _Geom.apply(this, arguments) || this;
  13. }
  14. var _proto = Polygon.prototype;
  15. _proto.getDefaultCfg = function getDefaultCfg() {
  16. var cfg = _Geom.prototype.getDefaultCfg.call(this);
  17. cfg.type = 'polygon';
  18. cfg.shapeType = 'polygon';
  19. cfg.generatePoints = true;
  20. return cfg;
  21. };
  22. _proto.createShapePointsCfg = function createShapePointsCfg(obj) {
  23. var cfg = _Geom.prototype.createShapePointsCfg.call(this, obj);
  24. var self = this;
  25. var x = cfg.x;
  26. var y = cfg.y;
  27. var temp;
  28. if (!((0, _common.isArray)(x) && (0, _common.isArray)(y))) {
  29. var xScale = self.getXScale();
  30. var yScale = self.getYScale();
  31. var xCount = xScale.values ? xScale.values.length : xScale.ticks.length;
  32. var yCount = yScale.values ? yScale.values.length : yScale.ticks.length;
  33. var xOffset = 0.5 * 1 / xCount;
  34. var yOffset = 0.5 * 1 / yCount;
  35. if (xScale.isCategory && yScale.isCategory) {
  36. x = [x - xOffset, x - xOffset, x + xOffset, x + xOffset];
  37. y = [y - yOffset, y + yOffset, y + yOffset, y - yOffset];
  38. } else if ((0, _common.isArray)(x)) {
  39. temp = x;
  40. x = [temp[0], temp[0], temp[1], temp[1]];
  41. y = [y - yOffset / 2, y + yOffset / 2, y + yOffset / 2, y - yOffset / 2];
  42. } else if ((0, _common.isArray)(y)) {
  43. temp = y;
  44. y = [temp[0], temp[1], temp[1], temp[0]];
  45. x = [x - xOffset / 2, x - xOffset / 2, x + xOffset / 2, x + xOffset / 2];
  46. }
  47. cfg.x = x;
  48. cfg.y = y;
  49. }
  50. return cfg;
  51. };
  52. return Polygon;
  53. }(_base["default"]);
  54. _base["default"].Polygon = Polygon;
  55. var _default = Polygon;
  56. exports["default"] = _default;