vector.src.js 15 KB

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