sausage.js 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  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. import { Path } from '../graphic.js';
  42. /**
  43. * Sausage: similar to sector, but have half circle on both sides
  44. */
  45. var SausageShape = /** @class */function () {
  46. function SausageShape() {
  47. this.cx = 0;
  48. this.cy = 0;
  49. this.r0 = 0;
  50. this.r = 0;
  51. this.startAngle = 0;
  52. this.endAngle = Math.PI * 2;
  53. this.clockwise = true;
  54. }
  55. return SausageShape;
  56. }();
  57. var SausagePath = /** @class */function (_super) {
  58. __extends(SausagePath, _super);
  59. function SausagePath(opts) {
  60. var _this = _super.call(this, opts) || this;
  61. _this.type = 'sausage';
  62. return _this;
  63. }
  64. SausagePath.prototype.getDefaultShape = function () {
  65. return new SausageShape();
  66. };
  67. SausagePath.prototype.buildPath = function (ctx, shape) {
  68. var cx = shape.cx;
  69. var cy = shape.cy;
  70. var r0 = Math.max(shape.r0 || 0, 0);
  71. var r = Math.max(shape.r, 0);
  72. var dr = (r - r0) * 0.5;
  73. var rCenter = r0 + dr;
  74. var startAngle = shape.startAngle;
  75. var endAngle = shape.endAngle;
  76. var clockwise = shape.clockwise;
  77. var PI2 = Math.PI * 2;
  78. var lessThanCircle = clockwise ? endAngle - startAngle < PI2 : startAngle - endAngle < PI2;
  79. if (!lessThanCircle) {
  80. // Normalize angles
  81. startAngle = endAngle - (clockwise ? PI2 : -PI2);
  82. }
  83. var unitStartX = Math.cos(startAngle);
  84. var unitStartY = Math.sin(startAngle);
  85. var unitEndX = Math.cos(endAngle);
  86. var unitEndY = Math.sin(endAngle);
  87. if (lessThanCircle) {
  88. ctx.moveTo(unitStartX * r0 + cx, unitStartY * r0 + cy);
  89. ctx.arc(unitStartX * rCenter + cx, unitStartY * rCenter + cy, dr, -Math.PI + startAngle, startAngle, !clockwise);
  90. } else {
  91. ctx.moveTo(unitStartX * r + cx, unitStartY * r + cy);
  92. }
  93. ctx.arc(cx, cy, r, startAngle, endAngle, !clockwise);
  94. ctx.arc(unitEndX * rCenter + cx, unitEndY * rCenter + cy, dr, endAngle - Math.PI * 2, endAngle - Math.PI, !clockwise);
  95. if (r0 !== 0) {
  96. ctx.arc(cx, cy, r0, endAngle, startAngle, clockwise);
  97. }
  98. // ctx.closePath();
  99. };
  100. return SausagePath;
  101. }(Path);
  102. export default SausagePath;