Line.js 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. import { __extends } from "tslib";
  2. import Path from '../Path.js';
  3. import { subPixelOptimizeLine } from '../helper/subPixelOptimize.js';
  4. var subPixelOptimizeOutputShape = {};
  5. var LineShape = (function () {
  6. function LineShape() {
  7. this.x1 = 0;
  8. this.y1 = 0;
  9. this.x2 = 0;
  10. this.y2 = 0;
  11. this.percent = 1;
  12. }
  13. return LineShape;
  14. }());
  15. export { LineShape };
  16. var Line = (function (_super) {
  17. __extends(Line, _super);
  18. function Line(opts) {
  19. return _super.call(this, opts) || this;
  20. }
  21. Line.prototype.getDefaultStyle = function () {
  22. return {
  23. stroke: '#000',
  24. fill: null
  25. };
  26. };
  27. Line.prototype.getDefaultShape = function () {
  28. return new LineShape();
  29. };
  30. Line.prototype.buildPath = function (ctx, shape) {
  31. var x1;
  32. var y1;
  33. var x2;
  34. var y2;
  35. if (this.subPixelOptimize) {
  36. var optimizedShape = subPixelOptimizeLine(subPixelOptimizeOutputShape, shape, this.style);
  37. x1 = optimizedShape.x1;
  38. y1 = optimizedShape.y1;
  39. x2 = optimizedShape.x2;
  40. y2 = optimizedShape.y2;
  41. }
  42. else {
  43. x1 = shape.x1;
  44. y1 = shape.y1;
  45. x2 = shape.x2;
  46. y2 = shape.y2;
  47. }
  48. var percent = shape.percent;
  49. if (percent === 0) {
  50. return;
  51. }
  52. ctx.moveTo(x1, y1);
  53. if (percent < 1) {
  54. x2 = x1 * (1 - percent) + x2 * percent;
  55. y2 = y1 * (1 - percent) + y2 * percent;
  56. }
  57. ctx.lineTo(x2, y2);
  58. };
  59. Line.prototype.pointAt = function (p) {
  60. var shape = this.shape;
  61. return [
  62. shape.x1 * (1 - p) + shape.x2 * p,
  63. shape.y1 * (1 - p) + shape.y2 * p
  64. ];
  65. };
  66. return Line;
  67. }(Path));
  68. Line.prototype.type = 'line';
  69. export default Line;