LinePath.js 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. /*
  2. * Licensed to the Apache Software Foundation (ASF) under one
  3. * or more contributor license agreements. See the NOTICE file
  4. * distributed with this work for additional information
  5. * regarding copyright ownership. The ASF licenses this file
  6. * to you under the Apache License, Version 2.0 (the
  7. * "License"); you may not use this file except in compliance
  8. * with the License. You may obtain a copy of the License at
  9. *
  10. * http://www.apache.org/licenses/LICENSE-2.0
  11. *
  12. * Unless required by applicable law or agreed to in writing,
  13. * software distributed under the License is distributed on an
  14. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  15. * KIND, either express or implied. See the License for the
  16. * specific language governing permissions and limitations
  17. * under the License.
  18. */
  19. /**
  20. * AUTO-GENERATED FILE. DO NOT MODIFY.
  21. */
  22. /*
  23. * Licensed to the Apache Software Foundation (ASF) under one
  24. * or more contributor license agreements. See the NOTICE file
  25. * distributed with this work for additional information
  26. * regarding copyright ownership. The ASF licenses this file
  27. * to you under the Apache License, Version 2.0 (the
  28. * "License"); you may not use this file except in compliance
  29. * with the License. You may obtain a copy of the License at
  30. *
  31. * http://www.apache.org/licenses/LICENSE-2.0
  32. *
  33. * Unless required by applicable law or agreed to in writing,
  34. * software distributed under the License is distributed on an
  35. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  36. * KIND, either express or implied. See the License for the
  37. * specific language governing permissions and limitations
  38. * under the License.
  39. */
  40. import { __extends } from "tslib";
  41. /**
  42. * Line path for bezier and straight line draw
  43. */
  44. import * as graphic from '../../util/graphic.js';
  45. import * as vec2 from 'zrender/lib/core/vector.js';
  46. var straightLineProto = graphic.Line.prototype;
  47. var bezierCurveProto = graphic.BezierCurve.prototype;
  48. var StraightLineShape = /** @class */function () {
  49. function StraightLineShape() {
  50. // Start point
  51. this.x1 = 0;
  52. this.y1 = 0;
  53. // End point
  54. this.x2 = 0;
  55. this.y2 = 0;
  56. this.percent = 1;
  57. }
  58. return StraightLineShape;
  59. }();
  60. var CurveShape = /** @class */function (_super) {
  61. __extends(CurveShape, _super);
  62. function CurveShape() {
  63. return _super !== null && _super.apply(this, arguments) || this;
  64. }
  65. return CurveShape;
  66. }(StraightLineShape);
  67. function isStraightLine(shape) {
  68. return isNaN(+shape.cpx1) || isNaN(+shape.cpy1);
  69. }
  70. var ECLinePath = /** @class */function (_super) {
  71. __extends(ECLinePath, _super);
  72. function ECLinePath(opts) {
  73. var _this = _super.call(this, opts) || this;
  74. _this.type = 'ec-line';
  75. return _this;
  76. }
  77. ECLinePath.prototype.getDefaultStyle = function () {
  78. return {
  79. stroke: '#000',
  80. fill: null
  81. };
  82. };
  83. ECLinePath.prototype.getDefaultShape = function () {
  84. return new StraightLineShape();
  85. };
  86. ECLinePath.prototype.buildPath = function (ctx, shape) {
  87. if (isStraightLine(shape)) {
  88. straightLineProto.buildPath.call(this, ctx, shape);
  89. } else {
  90. bezierCurveProto.buildPath.call(this, ctx, shape);
  91. }
  92. };
  93. ECLinePath.prototype.pointAt = function (t) {
  94. if (isStraightLine(this.shape)) {
  95. return straightLineProto.pointAt.call(this, t);
  96. } else {
  97. return bezierCurveProto.pointAt.call(this, t);
  98. }
  99. };
  100. ECLinePath.prototype.tangentAt = function (t) {
  101. var shape = this.shape;
  102. var p = isStraightLine(shape) ? [shape.x2 - shape.x1, shape.y2 - shape.y1] : bezierCurveProto.tangentAt.call(this, t);
  103. return vec2.normalize(p, p);
  104. };
  105. return ECLinePath;
  106. }(graphic.Path);
  107. export default ECLinePath;