point.js 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. "use strict";
  2. var Util = require('../../util/common');
  3. var Global = require('../../global');
  4. var ShapeUtil = require('./util');
  5. var Shape = require('./shape');
  6. var SHAPES = ['circle', 'hollowCircle', 'rect'];
  7. var Point = Shape.registerFactory('point', {
  8. defaultShapeType: 'circle',
  9. getDefaultPoints: function getDefaultPoints(pointInfo) {
  10. return ShapeUtil.splitPoints(pointInfo);
  11. }
  12. });
  13. function getPointsCfg(cfg) {
  14. var style = {
  15. lineWidth: 0,
  16. stroke: cfg.color,
  17. fill: cfg.color
  18. };
  19. if (cfg.size) {
  20. style.size = cfg.size;
  21. }
  22. Util.mix(style, cfg.style);
  23. return Util.mix({}, Global.shape.point, style);
  24. }
  25. function drawShape(cfg, container, shape) {
  26. if (cfg.size === 0) return;
  27. var pointCfg = getPointsCfg(cfg);
  28. var size = pointCfg.r || pointCfg.size;
  29. var x = cfg.x;
  30. var y = !Util.isArray(cfg.y) ? [cfg.y] : cfg.y;
  31. if (shape === 'hollowCircle') {
  32. pointCfg.lineWidth = 1;
  33. pointCfg.fill = null;
  34. }
  35. for (var i = 0, len = y.length; i < len; i++) {
  36. if (shape === 'rect') {
  37. return container.addShape('Rect', {
  38. className: 'point',
  39. attrs: Util.mix({
  40. x: x - size,
  41. y: y[i] - size,
  42. width: size * 2,
  43. height: size * 2
  44. }, pointCfg)
  45. });
  46. }
  47. return container.addShape('Circle', {
  48. className: 'point',
  49. attrs: Util.mix({
  50. x: x,
  51. y: y[i],
  52. r: size
  53. }, pointCfg)
  54. });
  55. }
  56. }
  57. Util.each(SHAPES, function (shapeType) {
  58. Shape.registerShape('point', shapeType, {
  59. draw: function draw(cfg, container) {
  60. return drawShape(cfg, container, shapeType);
  61. }
  62. });
  63. });
  64. module.exports = Point;