vector.src.js 13 KB

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