LinePath.js 3.6 KB

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