vector.src.js 9.5 KB

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