square.js 1.2 KB

12345678910111213141516171819202122232425
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", { value: true });
  3. var tslib_1 = require("tslib");
  4. var g2_1 = require("@antv/g2");
  5. (0, g2_1.registerShape)('polygon', 'square', {
  6. draw: function (cfg, group) {
  7. var _a, _b;
  8. var cx = cfg.x;
  9. var cy = cfg.y;
  10. var points = this.parsePoints(cfg.points);
  11. var width = Math.abs(points[2].x - points[1].x);
  12. var height = Math.abs(points[1].y - points[0].y);
  13. var maxSideLength = Math.min(width, height);
  14. var value = Number(cfg.shape[1]);
  15. var sizeRatio = Number(cfg.shape[2]);
  16. var lenRatio = Math.sqrt(sizeRatio);
  17. var sideLength = maxSideLength * lenRatio * Math.sqrt(value);
  18. var fill = ((_a = cfg.style) === null || _a === void 0 ? void 0 : _a.fill) || cfg.color || ((_b = cfg.defaultStyle) === null || _b === void 0 ? void 0 : _b.fill);
  19. var polygon = group.addShape('rect', {
  20. attrs: tslib_1.__assign(tslib_1.__assign(tslib_1.__assign({ x: cx - sideLength / 2, y: cy - sideLength / 2, width: sideLength, height: sideLength }, cfg.defaultStyle), cfg.style), { fill: fill }),
  21. });
  22. return polygon;
  23. },
  24. });
  25. //# sourceMappingURL=square.js.map