vector.src.js 9.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325
  1. /* *
  2. *
  3. * Vector plot series module
  4. *
  5. * (c) 2010-2020 Torstein Honsi
  6. *
  7. * License: www.highcharts.com/license
  8. *
  9. * !!!!!!! SOURCE GETS TRANSPILED BY TYPESCRIPT. EDIT TS FILE ONLY. !!!!!!!
  10. *
  11. * */
  12. 'use strict';
  13. import H from '../parts/Globals.js';
  14. import U from '../parts/Utilities.js';
  15. var animObject = U.animObject, arrayMax = U.arrayMax, pick = U.pick, seriesType = U.seriesType;
  16. /**
  17. * The vector series class.
  18. *
  19. * @private
  20. * @class
  21. * @name Highcharts.seriesTypes.vector
  22. *
  23. * @augments Highcharts.seriesTypes.scatter
  24. */
  25. seriesType('vector', 'scatter'
  26. /**
  27. * A vector plot is a type of cartesian chart where each point has an X and
  28. * Y position, a length and a direction. Vectors are drawn as arrows.
  29. *
  30. * @sample {highcharts|highstock} highcharts/demo/vector-plot/
  31. * Vector pot
  32. *
  33. * @since 6.0.0
  34. * @extends plotOptions.scatter
  35. * @excluding boostThreshold, marker, connectEnds, connectNulls,
  36. * cropThreshold, dashStyle, dragDrop, gapSize, gapUnit,
  37. * dataGrouping, linecap, shadow, stacking, step, jitter
  38. * @product highcharts highstock
  39. * @requires modules/vector
  40. * @optionparent plotOptions.vector
  41. */
  42. , {
  43. /**
  44. * The line width for each vector arrow.
  45. */
  46. lineWidth: 2,
  47. /**
  48. * @ignore
  49. */
  50. marker: null,
  51. /**
  52. * What part of the vector it should be rotated around. Can be one of
  53. * `start`, `center` and `end`. When `start`, the vectors will start
  54. * from the given [x, y] position, and when `end` the vectors will end
  55. * in the [x, y] position.
  56. *
  57. * @sample highcharts/plotoptions/vector-rotationorigin-start/
  58. * Rotate from start
  59. *
  60. * @validvalue ["start", "center", "end"]
  61. */
  62. rotationOrigin: 'center',
  63. states: {
  64. hover: {
  65. /**
  66. * Additonal line width for the vector errors when they are
  67. * hovered.
  68. */
  69. lineWidthPlus: 1
  70. }
  71. },
  72. tooltip: {
  73. /**
  74. * @default [{point.x}, {point.y}] Length: {point.length} Direction: {point.direction}°
  75. */
  76. pointFormat: '<b>[{point.x}, {point.y}]</b><br/>Length: <b>{point.length}</b><br/>Direction: <b>{point.direction}\u00B0</b><br/>'
  77. },
  78. /**
  79. * Maximum length of the arrows in the vector plot. The individual arrow
  80. * length is computed between 0 and this value.
  81. */
  82. vectorLength: 20
  83. }, {
  84. pointArrayMap: ['y', 'length', 'direction'],
  85. parallelArrays: ['x', 'y', 'length', 'direction'],
  86. /* eslint-disable valid-jsdoc */
  87. /**
  88. * Get presentational attributes.
  89. *
  90. * @private
  91. * @function Highcharts.seriesTypes.vector#pointAttribs
  92. *
  93. * @param {Highcharts.Point} point
  94. *
  95. * @param {string} [state]
  96. *
  97. * @return {Highcharts.SVGAttributes}
  98. */
  99. pointAttribs: function (point, state) {
  100. var options = this.options, stroke = point.color || this.color, strokeWidth = this.options.lineWidth;
  101. if (state) {
  102. stroke = options.states[state].color || stroke;
  103. strokeWidth =
  104. (options.states[state].lineWidth || strokeWidth) +
  105. (options.states[state].lineWidthPlus || 0);
  106. }
  107. return {
  108. 'stroke': stroke,
  109. 'stroke-width': strokeWidth
  110. };
  111. },
  112. /**
  113. * @ignore
  114. * @deprecated
  115. * @function Highcharts.seriesTypes.vector#markerAttribs
  116. */
  117. markerAttribs: H.noop,
  118. /**
  119. * @ignore
  120. * @deprecated
  121. * @function Highcharts.seriesTypes.vector#getSymbol
  122. */
  123. getSymbol: H.noop,
  124. /**
  125. * Create a single arrow. It is later rotated around the zero
  126. * centerpoint.
  127. *
  128. * @private
  129. * @function Highcharts.seriesTypes.vector#arrow
  130. *
  131. * @param {Highcharts.Point} point
  132. *
  133. * @return {Highcharts.SVGPathArray}
  134. */
  135. arrow: function (point) {
  136. var path, fraction = point.length / this.lengthMax, u = fraction * this.options.vectorLength / 20, o = {
  137. start: 10 * u,
  138. center: 0,
  139. end: -10 * u
  140. }[this.options.rotationOrigin] || 0;
  141. // The stem and the arrow head. Draw the arrow first with rotation
  142. // 0, which is the arrow pointing down (vector from north to south).
  143. path = [
  144. ['M', 0, 7 * u + o],
  145. ['L', -1.5 * u, 7 * u + o],
  146. ['L', 0, 10 * u + o],
  147. ['L', 1.5 * u, 7 * u + o],
  148. ['L', 0, 7 * u + o],
  149. ['L', 0, -10 * u + o] // top
  150. ];
  151. return path;
  152. },
  153. /**
  154. * @private
  155. * @function Highcharts.seriesTypes.vector#translate
  156. */
  157. translate: function () {
  158. H.Series.prototype.translate.call(this);
  159. this.lengthMax = arrayMax(this.lengthData);
  160. },
  161. /**
  162. * @private
  163. * @function Highcharts.seriesTypes.vector#drawPoints
  164. */
  165. drawPoints: function () {
  166. var chart = this.chart;
  167. this.points.forEach(function (point) {
  168. var plotX = point.plotX, plotY = point.plotY;
  169. if (this.options.clip === false ||
  170. chart.isInsidePlot(plotX, plotY, chart.inverted)) {
  171. if (!point.graphic) {
  172. point.graphic = this.chart.renderer
  173. .path()
  174. .add(this.markerGroup)
  175. .addClass('highcharts-point ' +
  176. 'highcharts-color-' +
  177. pick(point.colorIndex, point.series.colorIndex));
  178. }
  179. point.graphic
  180. .attr({
  181. d: this.arrow(point),
  182. translateX: plotX,
  183. translateY: plotY,
  184. rotation: point.direction
  185. });
  186. if (!this.chart.styledMode) {
  187. point.graphic
  188. .attr(this.pointAttribs(point));
  189. }
  190. }
  191. else if (point.graphic) {
  192. point.graphic = point.graphic.destroy();
  193. }
  194. }, this);
  195. },
  196. /**
  197. * @ignore
  198. * @deprecated
  199. * @function Highcharts.seriesTypes.vector#drawGraph
  200. */
  201. drawGraph: H.noop,
  202. /*
  203. drawLegendSymbol: function (legend, item) {
  204. var options = legend.options,
  205. symbolHeight = legend.symbolHeight,
  206. square = options.squareSymbol,
  207. symbolWidth = square ? symbolHeight : legend.symbolWidth,
  208. path = this.arrow.call({
  209. lengthMax: 1,
  210. options: {
  211. vectorLength: symbolWidth
  212. }
  213. }, {
  214. length: 1
  215. });
  216. item.legendLine = this.chart.renderer.path(path)
  217. .addClass('highcharts-point')
  218. .attr({
  219. zIndex: 3,
  220. translateY: symbolWidth / 2,
  221. rotation: 270,
  222. 'stroke-width': 1,
  223. 'stroke': 'black'
  224. }).add(item.legendGroup);
  225. },
  226. */
  227. /**
  228. * Fade in the arrows on initializing series.
  229. *
  230. * @private
  231. * @function Highcharts.seriesTypes.vector#animate
  232. *
  233. * @param {boolean} [init]
  234. */
  235. animate: function (init) {
  236. if (init) {
  237. this.markerGroup.attr({
  238. opacity: 0.01
  239. });
  240. }
  241. else {
  242. this.markerGroup.animate({
  243. opacity: 1
  244. }, animObject(this.options.animation));
  245. }
  246. }
  247. /* eslint-enable valid-jsdoc */
  248. });
  249. /**
  250. * A `vector` series. If the [type](#series.vector.type) option is not
  251. * specified, it is inherited from [chart.type](#chart.type).
  252. *
  253. * @extends series,plotOptions.vector
  254. * @excluding dataParser, dataURL
  255. * @product highcharts highstock
  256. * @requires modules/vector
  257. * @apioption series.vector
  258. */
  259. /**
  260. * An array of data points for the series. For the `vector` series type,
  261. * points can be given in the following ways:
  262. *
  263. * 1. An array of arrays with 4 values. In this case, the values correspond to
  264. * to `x,y,length,direction`. If the first value is a string, it is applied
  265. * as the name of the point, and the `x` value is inferred.
  266. * ```js
  267. * data: [
  268. * [0, 0, 10, 90],
  269. * [0, 1, 5, 180],
  270. * [1, 1, 2, 270]
  271. * ]
  272. * ```
  273. *
  274. * 2. An array of objects with named values. The following snippet shows only a
  275. * few settings, see the complete options set below. If the total number of
  276. * data points exceeds the series'
  277. * [turboThreshold](#series.area.turboThreshold), this option is not
  278. * available.
  279. * ```js
  280. * data: [{
  281. * x: 0,
  282. * y: 0,
  283. * name: "Point2",
  284. * length: 10,
  285. * direction: 90
  286. * }, {
  287. * x: 1,
  288. * y: 1,
  289. * name: "Point1",
  290. * direction: 270
  291. * }]
  292. * ```
  293. *
  294. * @sample {highcharts} highcharts/series/data-array-of-arrays/
  295. * Arrays of numeric x and y
  296. * @sample {highcharts} highcharts/series/data-array-of-arrays-datetime/
  297. * Arrays of datetime x and y
  298. * @sample {highcharts} highcharts/series/data-array-of-name-value/
  299. * Arrays of point.name and y
  300. * @sample {highcharts} highcharts/series/data-array-of-objects/
  301. * Config objects
  302. *
  303. * @type {Array<Array<(number|string),number,number,number>|*>}
  304. * @extends series.line.data
  305. * @product highcharts highstock
  306. * @apioption series.vector.data
  307. */
  308. /**
  309. * The length of the vector. The rendered length will relate to the
  310. * `vectorLength` setting.
  311. *
  312. * @type {number}
  313. * @product highcharts highstock
  314. * @apioption series.vector.data.length
  315. */
  316. /**
  317. * The vector direction in degrees, where 0 is north (pointing towards south).
  318. *
  319. * @type {number}
  320. * @product highcharts highstock
  321. * @apioption series.vector.data.direction
  322. */
  323. ''; // adds doclets above to the transpiled file