Line.js 951 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. var Path = require("../Path");
  2. /**
  3. * 直线
  4. * @module zrender/graphic/shape/Line
  5. */
  6. var _default = Path.extend({
  7. type: 'line',
  8. shape: {
  9. // Start point
  10. x1: 0,
  11. y1: 0,
  12. // End point
  13. x2: 0,
  14. y2: 0,
  15. percent: 1
  16. },
  17. style: {
  18. stroke: '#000',
  19. fill: null
  20. },
  21. buildPath: function (ctx, shape) {
  22. var x1 = shape.x1;
  23. var y1 = shape.y1;
  24. var x2 = shape.x2;
  25. var y2 = shape.y2;
  26. var percent = shape.percent;
  27. if (percent === 0) {
  28. return;
  29. }
  30. ctx.moveTo(x1, y1);
  31. if (percent < 1) {
  32. x2 = x1 * (1 - percent) + x2 * percent;
  33. y2 = y1 * (1 - percent) + y2 * percent;
  34. }
  35. ctx.lineTo(x2, y2);
  36. },
  37. /**
  38. * Get point at percent
  39. * @param {number} percent
  40. * @return {Array.<number>}
  41. */
  42. pointAt: function (p) {
  43. var shape = this.shape;
  44. return [shape.x1 * (1 - p) + shape.x2 * p, shape.y1 * (1 - p) + shape.y2 * p];
  45. }
  46. });
  47. module.exports = _default;