Ribbon.js 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  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. var graphic = require("../../util/graphic");
  20. /*
  21. * Licensed to the Apache Software Foundation (ASF) under one
  22. * or more contributor license agreements. See the NOTICE file
  23. * distributed with this work for additional information
  24. * regarding copyright ownership. The ASF licenses this file
  25. * to you under the Apache License, Version 2.0 (the
  26. * "License"); you may not use this file except in compliance
  27. * with the License. You may obtain a copy of the License at
  28. *
  29. * http://www.apache.org/licenses/LICENSE-2.0
  30. *
  31. * Unless required by applicable law or agreed to in writing,
  32. * software distributed under the License is distributed on an
  33. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  34. * KIND, either express or implied. See the License for the
  35. * specific language governing permissions and limitations
  36. * under the License.
  37. */
  38. var sin = Math.sin;
  39. var cos = Math.cos;
  40. var _default = graphic.extendShape({
  41. type: 'ec-ribbon',
  42. shape: {
  43. cx: 0,
  44. cy: 0,
  45. r: 0,
  46. s0: 0,
  47. s1: 0,
  48. t0: 0,
  49. t1: 0
  50. },
  51. style: {
  52. fill: '#000'
  53. },
  54. buildPath: function (ctx, shape) {
  55. var clockwise = shape.clockwise || false;
  56. var cx = shape.cx;
  57. var cy = shape.cy;
  58. var r = shape.r;
  59. var s0 = shape.s0;
  60. var s1 = shape.s1;
  61. var t0 = shape.t0;
  62. var t1 = shape.t1;
  63. var sx0 = cx + cos(s0) * r;
  64. var sy0 = cy + sin(s0) * r;
  65. var sx1 = cx + cos(s1) * r;
  66. var sy1 = cy + sin(s1) * r;
  67. var tx0 = cx + cos(t0) * r;
  68. var ty0 = cy + sin(t0) * r;
  69. var tx1 = cx + cos(t1) * r;
  70. var ty1 = cy + sin(t1) * r;
  71. ctx.moveTo(sx0, sy0);
  72. ctx.arc(cx, cy, shape.r, s0, s1, !clockwise);
  73. ctx.bezierCurveTo((cx - sx1) * 0.70 + sx1, (cy - sy1) * 0.70 + sy1, (cx - tx0) * 0.70 + tx0, (cy - ty0) * 0.70 + ty0, tx0, ty0); // Chord to self
  74. if (shape.s0 === shape.t0 && shape.s1 === shape.t1) {
  75. return;
  76. }
  77. ctx.arc(cx, cy, shape.r, t0, t1, !clockwise);
  78. ctx.bezierCurveTo((cx - tx1) * 0.70 + tx1, (cy - ty1) * 0.70 + ty1, (cx - sx0) * 0.70 + sx0, (cy - sy0) * 0.70 + sy0, sx0, sy0);
  79. }
  80. });
  81. module.exports = _default;