vector.src.js 9.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327
  1. /* *
  2. *
  3. * Vector plot series module
  4. *
  5. * (c) 2010-2019 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;
  16. var seriesType = H.seriesType;
  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. * @product highcharts highstock
  40. * @requires modules/vector
  41. * @optionparent plotOptions.vector
  42. */
  43. , {
  44. /**
  45. * The line width for each vector arrow.
  46. */
  47. lineWidth: 2,
  48. /**
  49. * @ignore
  50. */
  51. marker: null,
  52. /**
  53. * What part of the vector it should be rotated around. Can be one of
  54. * `start`, `center` and `end`. When `start`, the vectors will start
  55. * from the given [x, y] position, and when `end` the vectors will end
  56. * in the [x, y] position.
  57. *
  58. * @sample highcharts/plotoptions/vector-rotationorigin-start/
  59. * Rotate from start
  60. *
  61. * @validvalue ["start", "center", "end"]
  62. */
  63. rotationOrigin: 'center',
  64. states: {
  65. hover: {
  66. /**
  67. * Additonal line width for the vector errors when they are
  68. * hovered.
  69. */
  70. lineWidthPlus: 1
  71. }
  72. },
  73. tooltip: {
  74. /**
  75. * @default [{point.x}, {point.y}] Length: {point.length} Direction: {point.direction}°
  76. */
  77. pointFormat: '<b>[{point.x}, {point.y}]</b><br/>Length: <b>{point.length}</b><br/>Direction: <b>{point.direction}\u00B0</b><br/>'
  78. },
  79. /**
  80. * Maximum length of the arrows in the vector plot. The individual arrow
  81. * length is computed between 0 and this value.
  82. */
  83. vectorLength: 20
  84. }, {
  85. pointArrayMap: ['y', 'length', 'direction'],
  86. parallelArrays: ['x', 'y', 'length', 'direction'],
  87. /* eslint-disable valid-jsdoc */
  88. /**
  89. * Get presentational attributes.
  90. *
  91. * @private
  92. * @function Highcharts.seriesTypes.vector#pointAttribs
  93. *
  94. * @param {Highcharts.Point} point
  95. *
  96. * @param {string} [state]
  97. *
  98. * @return {Highcharts.SVGAttributes}
  99. */
  100. pointAttribs: function (point, state) {
  101. var options = this.options, stroke = point.color || this.color, strokeWidth = this.options.lineWidth;
  102. if (state) {
  103. stroke = options.states[state].color || stroke;
  104. strokeWidth =
  105. (options.states[state].lineWidth || strokeWidth) +
  106. (options.states[state].lineWidthPlus || 0);
  107. }
  108. return {
  109. 'stroke': stroke,
  110. 'stroke-width': strokeWidth
  111. };
  112. },
  113. /**
  114. * @ignore
  115. * @deprecated
  116. * @function Highcharts.seriesTypes.vector#markerAttribs
  117. */
  118. markerAttribs: H.noop,
  119. /**
  120. * @ignore
  121. * @deprecated
  122. * @function Highcharts.seriesTypes.vector#getSymbol
  123. */
  124. getSymbol: H.noop,
  125. /**
  126. * Create a single arrow. It is later rotated around the zero
  127. * centerpoint.
  128. *
  129. * @private
  130. * @function Highcharts.seriesTypes.vector#arrow
  131. *
  132. * @param {Highcharts.Point} point
  133. *
  134. * @return {Highcharts.SVGPathArray}
  135. */
  136. arrow: function (point) {
  137. var path, fraction = point.length / this.lengthMax, u = fraction * this.options.vectorLength / 20, o = {
  138. start: 10 * u,
  139. center: 0,
  140. end: -10 * u
  141. }[this.options.rotationOrigin] || 0;
  142. // The stem and the arrow head. Draw the arrow first with rotation
  143. // 0, which is the arrow pointing down (vector from north to south).
  144. path = [
  145. 'M', 0, 7 * u + o,
  146. 'L', -1.5 * u, 7 * u + o,
  147. 0, 10 * u + o,
  148. 1.5 * u, 7 * u + o,
  149. 0, 7 * u + o,
  150. 0, -10 * u + o // top
  151. ];
  152. return path;
  153. },
  154. /**
  155. * @private
  156. * @function Highcharts.seriesTypes.vector#translate
  157. */
  158. translate: function () {
  159. H.Series.prototype.translate.call(this);
  160. this.lengthMax = arrayMax(this.lengthData);
  161. },
  162. /**
  163. * @private
  164. * @function Highcharts.seriesTypes.vector#drawPoints
  165. */
  166. drawPoints: function () {
  167. var chart = this.chart;
  168. this.points.forEach(function (point) {
  169. var plotX = point.plotX, plotY = point.plotY;
  170. if (this.options.clip === false ||
  171. chart.isInsidePlot(plotX, plotY, chart.inverted)) {
  172. if (!point.graphic) {
  173. point.graphic = this.chart.renderer
  174. .path()
  175. .add(this.markerGroup)
  176. .addClass('highcharts-point ' +
  177. 'highcharts-color-' +
  178. pick(point.colorIndex, point.series.colorIndex));
  179. }
  180. point.graphic
  181. .attr({
  182. d: this.arrow(point),
  183. translateX: plotX,
  184. translateY: plotY,
  185. rotation: point.direction
  186. });
  187. if (!this.chart.styledMode) {
  188. point.graphic
  189. .attr(this.pointAttribs(point));
  190. }
  191. }
  192. else if (point.graphic) {
  193. point.graphic = point.graphic.destroy();
  194. }
  195. }, this);
  196. },
  197. /**
  198. * @ignore
  199. * @deprecated
  200. * @function Highcharts.seriesTypes.vector#drawGraph
  201. */
  202. drawGraph: H.noop,
  203. /*
  204. drawLegendSymbol: function (legend, item) {
  205. var options = legend.options,
  206. symbolHeight = legend.symbolHeight,
  207. square = options.squareSymbol,
  208. symbolWidth = square ? symbolHeight : legend.symbolWidth,
  209. path = this.arrow.call({
  210. lengthMax: 1,
  211. options: {
  212. vectorLength: symbolWidth
  213. }
  214. }, {
  215. length: 1
  216. });
  217. item.legendLine = this.chart.renderer.path(path)
  218. .addClass('highcharts-point')
  219. .attr({
  220. zIndex: 3,
  221. translateY: symbolWidth / 2,
  222. rotation: 270,
  223. 'stroke-width': 1,
  224. 'stroke': 'black'
  225. }).add(item.legendGroup);
  226. },
  227. */
  228. /**
  229. * Fade in the arrows on initializing series.
  230. *
  231. * @private
  232. * @function Highcharts.seriesTypes.vector#animate
  233. *
  234. * @param {boolean} [init]
  235. */
  236. animate: function (init) {
  237. if (init) {
  238. this.markerGroup.attr({
  239. opacity: 0.01
  240. });
  241. }
  242. else {
  243. this.markerGroup.animate({
  244. opacity: 1
  245. }, animObject(this.options.animation));
  246. this.animate = null;
  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
  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