VectorSeries.js 9.8 KB

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