vector.src.js 11 KB

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