polygon.js 1.9 KB

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