vector.src.js 13 KB

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