polygon.js 802 B

12345678910111213141516171819202122232425262728293031323334353637
  1. "use strict";
  2. var Shape = require('./shape');
  3. var Util = require('../../util/common');
  4. var Polygon = Shape.registerFactory('polygon', {
  5. defaultShapeType: 'polygon',
  6. getDefaultPoints: function getDefaultPoints(pointInfo) {
  7. var points = [];
  8. var x = pointInfo.x,
  9. y = pointInfo.y;
  10. for (var i = 0, len = x.length; i < len; i++) {
  11. points.push({
  12. x: x[i],
  13. y: y[i]
  14. });
  15. }
  16. return points;
  17. }
  18. });
  19. Shape.registerShape('polygon', 'polygon', {
  20. draw: function draw(cfg, container) {
  21. var points = this.parsePoints(cfg.points);
  22. var style = Util.mix({
  23. fill: cfg.color,
  24. points: points
  25. }, cfg.style);
  26. return container.addShape('Polygon', {
  27. className: 'polygon',
  28. attrs: style
  29. });
  30. }
  31. });
  32. module.exports = Polygon;