LinePath.js 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. var graphic = require("../../util/graphic");
  2. var vec2 = require("zrender/lib/core/vector");
  3. /**
  4. * Line path for bezier and straight line draw
  5. */
  6. var straightLineProto = graphic.Line.prototype;
  7. var bezierCurveProto = graphic.BezierCurve.prototype;
  8. function isLine(shape) {
  9. return isNaN(+shape.cpx1) || isNaN(+shape.cpy1);
  10. }
  11. var _default = graphic.extendShape({
  12. type: 'ec-line',
  13. style: {
  14. stroke: '#000',
  15. fill: null
  16. },
  17. shape: {
  18. x1: 0,
  19. y1: 0,
  20. x2: 0,
  21. y2: 0,
  22. percent: 1,
  23. cpx1: null,
  24. cpy1: null
  25. },
  26. buildPath: function (ctx, shape) {
  27. (isLine(shape) ? straightLineProto : bezierCurveProto).buildPath(ctx, shape);
  28. },
  29. pointAt: function (t) {
  30. return isLine(this.shape) ? straightLineProto.pointAt.call(this, t) : bezierCurveProto.pointAt.call(this, t);
  31. },
  32. tangentAt: function (t) {
  33. var shape = this.shape;
  34. var p = isLine(shape) ? [shape.x2 - shape.x1, shape.y2 - shape.y1] : bezierCurveProto.tangentAt.call(this, t);
  35. return vec2.normalize(p, p);
  36. }
  37. });
  38. module.exports = _default;