VectorSeries.js 9.7 KB

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