ArrowSymbols.js 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198
  1. /* *
  2. * (c) 2017 Highsoft AS
  3. * Authors: Lars A. V. Cabrera
  4. *
  5. * License: www.highcharts.com/license
  6. */
  7. 'use strict';
  8. import H from '../parts/Globals.js';
  9. /**
  10. * Creates an arrow symbol. Like a triangle, except not filled.
  11. * ```
  12. * o
  13. * o
  14. * o
  15. * o
  16. * o
  17. * o
  18. * o
  19. * ```
  20. *
  21. * @private
  22. * @function
  23. *
  24. * @param {number} x
  25. * x position of the arrow
  26. *
  27. * @param {number} y
  28. * y position of the arrow
  29. *
  30. * @param {number} w
  31. * width of the arrow
  32. *
  33. * @param {number} h
  34. * height of the arrow
  35. *
  36. * @return {Highcharts.SVGPathArray}
  37. * Path array
  38. */
  39. H.SVGRenderer.prototype.symbols.arrow = function (x, y, w, h) {
  40. return [
  41. 'M', x, y + h / 2,
  42. 'L', x + w, y,
  43. 'L', x, y + h / 2,
  44. 'L', x + w, y + h
  45. ];
  46. };
  47. /**
  48. * Creates a half-width arrow symbol. Like a triangle, except not filled.
  49. * ```
  50. * o
  51. * o
  52. * o
  53. * o
  54. * o
  55. * ```
  56. *
  57. * @private
  58. * @function
  59. *
  60. * @param {number} x
  61. * x position of the arrow
  62. *
  63. * @param {number} y
  64. * y position of the arrow
  65. *
  66. * @param {number} w
  67. * width of the arrow
  68. *
  69. * @param {number} h
  70. * height of the arrow
  71. *
  72. * @return {Highcharts.SVGPathArray}
  73. * Path array
  74. */
  75. H.SVGRenderer.prototype.symbols['arrow-half'] = function (x, y, w, h) {
  76. return H.SVGRenderer.prototype.symbols.arrow(x, y, w / 2, h);
  77. };
  78. /**
  79. * Creates a left-oriented triangle.
  80. * ```
  81. * o
  82. * ooooooo
  83. * ooooooooooooo
  84. * ooooooo
  85. * o
  86. * ```
  87. *
  88. * @private
  89. * @function
  90. *
  91. * @param {number} x
  92. * x position of the triangle
  93. *
  94. * @param {number} y
  95. * y position of the triangle
  96. *
  97. * @param {number} w
  98. * width of the triangle
  99. *
  100. * @param {number} h
  101. * height of the triangle
  102. *
  103. * @return {Highcharts.SVGPathArray}
  104. * Path array
  105. */
  106. H.SVGRenderer.prototype.symbols['triangle-left'] = function (x, y, w, h) {
  107. return [
  108. 'M', x + w, y,
  109. 'L', x, y + h / 2,
  110. 'L', x + w, y + h,
  111. 'Z'
  112. ];
  113. };
  114. /**
  115. * Alias function for triangle-left.
  116. *
  117. * @private
  118. * @function
  119. *
  120. * @param {number} x
  121. * x position of the arrow
  122. *
  123. * @param {number} y
  124. * y position of the arrow
  125. *
  126. * @param {number} w
  127. * width of the arrow
  128. *
  129. * @param {number} h
  130. * height of the arrow
  131. *
  132. * @return {Highcharts.SVGPathArray}
  133. * Path array
  134. */
  135. H.SVGRenderer.prototype.symbols['arrow-filled'] =
  136. H.SVGRenderer.prototype.symbols['triangle-left'];
  137. /**
  138. * Creates a half-width, left-oriented triangle.
  139. * ```
  140. * o
  141. * oooo
  142. * ooooooo
  143. * oooo
  144. * o
  145. * ```
  146. *
  147. * @private
  148. * @function
  149. *
  150. * @param {number} x
  151. * x position of the triangle
  152. *
  153. * @param {number} y
  154. * y position of the triangle
  155. *
  156. * @param {number} w
  157. * width of the triangle
  158. *
  159. * @param {number} h
  160. * height of the triangle
  161. *
  162. * @return {Highcharts.SVGPathArray}
  163. * Path array
  164. */
  165. H.SVGRenderer.prototype.symbols['triangle-left-half'] = function (x, y, w, h) {
  166. return H.SVGRenderer.prototype.symbols['triangle-left'](x, y, w / 2, h);
  167. };
  168. /**
  169. * Alias function for triangle-left-half.
  170. *
  171. * @private
  172. * @function
  173. *
  174. * @param {number} x
  175. * x position of the arrow
  176. *
  177. * @param {number} y
  178. * y position of the arrow
  179. *
  180. * @param {number} w
  181. * width of the arrow
  182. *
  183. * @param {number} h
  184. * height of the arrow
  185. *
  186. * @return {Highcharts.SVGPathArray}
  187. * Path array
  188. */
  189. H.SVGRenderer.prototype.symbols['arrow-filled-half'] =
  190. H.SVGRenderer.prototype.symbols['triangle-left-half'];