sausage.js 3.7 KB

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