LinePath.js 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  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 =
  49. /** @class */
  50. function () {
  51. function StraightLineShape() {
  52. // Start point
  53. this.x1 = 0;
  54. this.y1 = 0; // End point
  55. this.x2 = 0;
  56. this.y2 = 0;
  57. this.percent = 1;
  58. }
  59. return StraightLineShape;
  60. }();
  61. var CurveShape =
  62. /** @class */
  63. function (_super) {
  64. __extends(CurveShape, _super);
  65. function CurveShape() {
  66. return _super !== null && _super.apply(this, arguments) || this;
  67. }
  68. return CurveShape;
  69. }(StraightLineShape);
  70. function isStraightLine(shape) {
  71. return isNaN(+shape.cpx1) || isNaN(+shape.cpy1);
  72. }
  73. var ECLinePath =
  74. /** @class */
  75. function (_super) {
  76. __extends(ECLinePath, _super);
  77. function ECLinePath(opts) {
  78. var _this = _super.call(this, opts) || this;
  79. _this.type = 'ec-line';
  80. return _this;
  81. }
  82. ECLinePath.prototype.getDefaultStyle = function () {
  83. return {
  84. stroke: '#000',
  85. fill: null
  86. };
  87. };
  88. ECLinePath.prototype.getDefaultShape = function () {
  89. return new StraightLineShape();
  90. };
  91. ECLinePath.prototype.buildPath = function (ctx, shape) {
  92. if (isStraightLine(shape)) {
  93. straightLineProto.buildPath.call(this, ctx, shape);
  94. } else {
  95. bezierCurveProto.buildPath.call(this, ctx, shape);
  96. }
  97. };
  98. ECLinePath.prototype.pointAt = function (t) {
  99. if (isStraightLine(this.shape)) {
  100. return straightLineProto.pointAt.call(this, t);
  101. } else {
  102. return bezierCurveProto.pointAt.call(this, t);
  103. }
  104. };
  105. ECLinePath.prototype.tangentAt = function (t) {
  106. var shape = this.shape;
  107. var p = isStraightLine(shape) ? [shape.x2 - shape.x1, shape.y2 - shape.y1] : bezierCurveProto.tangentAt.call(this, t);
  108. return vec2.normalize(p, p);
  109. };
  110. return ECLinePath;
  111. }(graphic.Path);
  112. export default ECLinePath;