vector.src.js 13 KB

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