dumbbell.src.js 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469
  1. /**
  2. * @license Highcharts JS v8.1.2 (2020-06-16)
  3. *
  4. * (c) 2009-2019 Sebastian Bochan, Rafal Sebestjanski
  5. *
  6. * License: www.highcharts.com/license
  7. */
  8. 'use strict';
  9. (function (factory) {
  10. if (typeof module === 'object' && module.exports) {
  11. factory['default'] = factory;
  12. module.exports = factory;
  13. } else if (typeof define === 'function' && define.amd) {
  14. define('highcharts/modules/dumbbell', ['highcharts'], function (Highcharts) {
  15. factory(Highcharts);
  16. factory.Highcharts = Highcharts;
  17. return factory;
  18. });
  19. } else {
  20. factory(typeof Highcharts !== 'undefined' ? Highcharts : undefined);
  21. }
  22. }(function (Highcharts) {
  23. var _modules = Highcharts ? Highcharts._modules : {};
  24. function _registerModule(obj, path, args, fn) {
  25. if (!obj.hasOwnProperty(path)) {
  26. obj[path] = fn.apply(null, args);
  27. }
  28. }
  29. _registerModule(_modules, 'modules/dumbbell.src.js', [_modules['parts/Globals.js'], _modules['parts/Utilities.js']], function (H, U) {
  30. /* *
  31. *
  32. * (c) 2010-2020 Sebastian Bochan, Rafal Sebestjanski
  33. *
  34. * License: www.highcharts.com/license
  35. *
  36. * !!!!!!! SOURCE GETS TRANSPILED BY TYPESCRIPT. EDIT TS FILE ONLY. !!!!!!!
  37. *
  38. * */
  39. var SVGRenderer = H.SVGRenderer;
  40. var extend = U.extend, pick = U.pick, seriesType = U.seriesType;
  41. var seriesTypes = H.seriesTypes, seriesProto = H.Series.prototype, areaRangeProto = seriesTypes.arearange.prototype, columnRangeProto = seriesTypes.columnrange.prototype, colProto = seriesTypes.column.prototype, areaRangePointProto = areaRangeProto.pointClass.prototype;
  42. /**
  43. * The dumbbell series is a cartesian series with higher and lower values for
  44. * each point along an X axis, connected with a line between the values.
  45. * Requires `highcharts-more.js` and `modules/dumbbell.js`.
  46. *
  47. * @sample {highcharts} highcharts/demo/dumbbell/
  48. * Dumbbell chart
  49. * @sample {highcharts} highcharts/series-dumbbell/styled-mode-dumbbell/
  50. * Styled mode
  51. *
  52. * @extends plotOptions.arearange
  53. * @product highcharts highstock
  54. * @excluding fillColor, fillOpacity, lineWidth, stack, stacking,
  55. * stickyTracking, trackByArea
  56. * @since 8.0.0
  57. * @optionparent plotOptions.dumbbell
  58. */
  59. seriesType('dumbbell', 'arearange', {
  60. /** @ignore-option */
  61. trackByArea: false,
  62. /** @ignore-option */
  63. fillColor: 'none',
  64. /** @ignore-option */
  65. lineWidth: 0,
  66. pointRange: 1,
  67. /**
  68. * Pixel width of the line that connects the dumbbell point's values.
  69. *
  70. * @since 8.0.0
  71. * @product highcharts highstock
  72. */
  73. connectorWidth: 1,
  74. /** @ignore-option */
  75. stickyTracking: false,
  76. groupPadding: 0.2,
  77. crisp: false,
  78. pointPadding: 0.1,
  79. /**
  80. * Color of the start markers in a dumbbell graph.
  81. *
  82. * @type {Highcharts.ColorString|Highcharts.GradientColorObject|Highcharts.PatternObject}
  83. * @since 8.0.0
  84. * @product highcharts highstock
  85. */
  86. lowColor: '#333333',
  87. /**
  88. * Color of the line that connects the dumbbell point's values.
  89. * By default it is the series' color.
  90. *
  91. * @type {string}
  92. * @product highcharts highstock
  93. * @since 8.0.0
  94. * @apioption plotOptions.dumbbell.connectorColor
  95. */
  96. states: {
  97. hover: {
  98. /** @ignore-option */
  99. lineWidthPlus: 0,
  100. /**
  101. * The additional connector line width for a hovered point.
  102. *
  103. * @since 8.0.0
  104. * @product highcharts highstock
  105. */
  106. connectorWidthPlus: 1,
  107. /** @ignore-option */
  108. halo: false
  109. }
  110. }
  111. }, {
  112. trackerGroups: ['group', 'markerGroup', 'dataLabelsGroup'],
  113. drawTracker: H.TrackerMixin.drawTrackerPoint,
  114. drawGraph: H.noop,
  115. crispCol: colProto.crispCol,
  116. /**
  117. * Get connector line path and styles that connects dumbbell point's low and
  118. * high values.
  119. * @private
  120. *
  121. * @param {Highcharts.Series} this The series of points.
  122. * @param {Highcharts.Point} point The point to inspect.
  123. *
  124. * @return {Highcharts.SVGAttributes} attribs The path and styles.
  125. */
  126. getConnectorAttribs: function (point) {
  127. var series = this, chart = series.chart, pointOptions = point.options, seriesOptions = series.options, xAxis = series.xAxis, yAxis = series.yAxis, connectorWidth = pick(pointOptions.connectorWidth, seriesOptions.connectorWidth), connectorColor = pick(pointOptions.connectorColor, seriesOptions.connectorColor, pointOptions.color, point.zone ? point.zone.color : void 0, point.color), connectorWidthPlus = pick(seriesOptions.states &&
  128. seriesOptions.states.hover &&
  129. seriesOptions.states.hover.connectorWidthPlus, 1), dashStyle = pick(pointOptions.dashStyle, seriesOptions.dashStyle), pointTop = pick(point.plotLow, point.plotY), pxThreshold = yAxis.toPixels(seriesOptions.threshold || 0, true), pointHeight = chart.inverted ?
  130. yAxis.len - pxThreshold : pxThreshold, pointBottom = pick(point.plotHigh, pointHeight), attribs, origProps;
  131. if (point.state) {
  132. connectorWidth = connectorWidth + connectorWidthPlus;
  133. }
  134. if (pointTop < 0) {
  135. pointTop = 0;
  136. }
  137. else if (pointTop >= yAxis.len) {
  138. pointTop = yAxis.len;
  139. }
  140. if (pointBottom < 0) {
  141. pointBottom = 0;
  142. }
  143. else if (pointBottom >= yAxis.len) {
  144. pointBottom = yAxis.len;
  145. }
  146. if (point.plotX < 0 || point.plotX > xAxis.len) {
  147. connectorWidth = 0;
  148. }
  149. // Connector should reflect upper marker's zone color
  150. if (point.upperGraphic) {
  151. origProps = {
  152. y: point.y,
  153. zone: point.zone
  154. };
  155. point.y = point.high;
  156. point.zone = point.zone ? point.getZone() : void 0;
  157. connectorColor = pick(pointOptions.connectorColor, seriesOptions.connectorColor, pointOptions.color, point.zone ? point.zone.color : void 0, point.color);
  158. extend(point, origProps);
  159. }
  160. attribs = {
  161. d: SVGRenderer.prototype.crispLine([[
  162. 'M',
  163. point.plotX,
  164. pointTop
  165. ], [
  166. 'L',
  167. point.plotX,
  168. pointBottom
  169. ]], connectorWidth, 'ceil')
  170. };
  171. if (!chart.styledMode) {
  172. attribs.stroke = connectorColor;
  173. attribs['stroke-width'] = connectorWidth;
  174. if (dashStyle) {
  175. attribs.dashstyle = dashStyle;
  176. }
  177. }
  178. return attribs;
  179. },
  180. /**
  181. * Draw connector line that connects dumbbell point's low and high values.
  182. * @private
  183. *
  184. * @param {Highcharts.Series} this The series of points.
  185. * @param {Highcharts.Point} point The point to inspect.
  186. *
  187. * @return {void}
  188. */
  189. drawConnector: function (point) {
  190. var series = this, animationLimit = pick(series.options.animationLimit, 250), verb = point.connector && series.chart.pointCount < animationLimit ?
  191. 'animate' : 'attr';
  192. if (!point.connector) {
  193. point.connector = series.chart.renderer.path()
  194. .addClass('highcharts-lollipop-stem')
  195. .attr({
  196. zIndex: -1
  197. })
  198. .add(series.markerGroup);
  199. }
  200. point.connector[verb](this.getConnectorAttribs(point));
  201. },
  202. /**
  203. * Return the width and x offset of the dumbbell adjusted for grouping,
  204. * groupPadding, pointPadding, pointWidth etc.
  205. *
  206. * @private
  207. *
  208. * @function Highcharts.seriesTypes.column#getColumnMetrics
  209. *
  210. * @param {Highcharts.Series} this The series of points.
  211. *
  212. * @return {Highcharts.ColumnMetricsObject} metrics shapeArgs
  213. *
  214. */
  215. getColumnMetrics: function () {
  216. var metrics = colProto.getColumnMetrics.apply(this, arguments);
  217. metrics.offset += metrics.width / 2;
  218. return metrics;
  219. },
  220. translatePoint: areaRangeProto.translate,
  221. setShapeArgs: columnRangeProto.translate,
  222. /**
  223. * Translate each point to the plot area coordinate system and find
  224. * shape positions
  225. *
  226. * @private
  227. *
  228. * @function Highcharts.seriesTypes.dumbbell#translate
  229. *
  230. * @param {Highcharts.Series} this The series of points.
  231. *
  232. * @return {void}
  233. */
  234. translate: function () {
  235. // Calculate shapeargs
  236. this.setShapeArgs.apply(this);
  237. // Calculate point low / high values
  238. this.translatePoint.apply(this, arguments);
  239. // Correct x position
  240. this.points.forEach(function (point) {
  241. var shapeArgs = point.shapeArgs, pointWidth = point.pointWidth;
  242. point.plotX = shapeArgs.x;
  243. shapeArgs.x = point.plotX - pointWidth / 2;
  244. point.tooltipPos = null;
  245. });
  246. this.columnMetrics.offset -= this.columnMetrics.width / 2;
  247. },
  248. seriesDrawPoints: areaRangeProto.drawPoints,
  249. /**
  250. * Extend the arearange series' drawPoints method by applying a connector
  251. * and coloring markers.
  252. * @private
  253. *
  254. * @function Highcharts.Series#drawPoints
  255. *
  256. * @param {Highcharts.Series} this The series of points.
  257. *
  258. * @return {void}
  259. */
  260. drawPoints: function () {
  261. var series = this, chart = series.chart, pointLength = series.points.length, seriesLowColor = series.lowColor = series.options.lowColor, i = 0, lowerGraphicColor, point, zoneColor;
  262. this.seriesDrawPoints.apply(series, arguments);
  263. // Draw connectors and color upper markers
  264. while (i < pointLength) {
  265. point = series.points[i];
  266. series.drawConnector(point);
  267. if (point.upperGraphic) {
  268. point.upperGraphic.element.point = point;
  269. point.upperGraphic.addClass('highcharts-lollipop-high');
  270. }
  271. point.connector.element.point = point;
  272. if (point.lowerGraphic) {
  273. zoneColor = point.zone && point.zone.color;
  274. lowerGraphicColor = pick(point.options.lowColor, seriesLowColor, point.options.color, zoneColor, point.color, series.color);
  275. if (!chart.styledMode) {
  276. point.lowerGraphic.attr({
  277. fill: lowerGraphicColor
  278. });
  279. }
  280. point.lowerGraphic.addClass('highcharts-lollipop-low');
  281. }
  282. i++;
  283. }
  284. },
  285. /**
  286. * Get non-presentational attributes for a point. Used internally for
  287. * both styled mode and classic. Set correct position in link with connector
  288. * line.
  289. *
  290. * @see Series#pointAttribs
  291. *
  292. * @function Highcharts.Series#markerAttribs
  293. *
  294. * @param {Highcharts.Series} this The series of points.
  295. *
  296. * @return {Highcharts.SVGAttributes}
  297. * A hash containing those attributes that are not settable from
  298. * CSS.
  299. */
  300. markerAttribs: function () {
  301. var ret = areaRangeProto.markerAttribs.apply(this, arguments);
  302. ret.x = Math.floor(ret.x);
  303. ret.y = Math.floor(ret.y);
  304. return ret;
  305. },
  306. /**
  307. * Get presentational attributes
  308. *
  309. * @private
  310. * @function Highcharts.seriesTypes.column#pointAttribs
  311. *
  312. * @param {Highcharts.Series} this The series of points.
  313. * @param {Highcharts.Point} point The point to inspect.
  314. * @param {string} state current state of point (normal, hover, select)
  315. *
  316. * @return {Highcharts.SVGAttributes} pointAttribs SVGAttributes
  317. */
  318. pointAttribs: function (point, state) {
  319. var pointAttribs;
  320. pointAttribs = seriesProto.pointAttribs.apply(this, arguments);
  321. if (state === 'hover') {
  322. delete pointAttribs.fill;
  323. }
  324. return pointAttribs;
  325. }
  326. }, {
  327. // seriesTypes doesn't inherit from arearange point proto so put below
  328. // methods rigidly.
  329. destroyElements: areaRangePointProto.destroyElements,
  330. isValid: areaRangePointProto.isValid,
  331. pointSetState: areaRangePointProto.setState,
  332. /**
  333. * Set the point's state extended by have influence on the connector
  334. * (between low and high value).
  335. *
  336. * @private
  337. * @param {Highcharts.Point} this The point to inspect.
  338. *
  339. * @return {void}
  340. */
  341. setState: function () {
  342. var point = this, series = point.series, chart = series.chart, seriesLowColor = series.options.lowColor, seriesMarker = series.options.marker, pointOptions = point.options, pointLowColor = pointOptions.lowColor, zoneColor = point.zone && point.zone.color, lowerGraphicColor = pick(pointLowColor, seriesLowColor, pointOptions.color, zoneColor, point.color, series.color), verb = 'attr', upperGraphicColor, origProps;
  343. this.pointSetState.apply(this, arguments);
  344. if (!point.state) {
  345. verb = 'animate';
  346. if (point.lowerGraphic && !chart.styledMode) {
  347. point.lowerGraphic.attr({
  348. fill: lowerGraphicColor
  349. });
  350. if (point.upperGraphic) {
  351. origProps = {
  352. y: point.y,
  353. zone: point.zone
  354. };
  355. point.y = point.high;
  356. point.zone = point.zone ? point.getZone() : void 0;
  357. upperGraphicColor = pick(point.marker ? point.marker.fillColor : void 0, seriesMarker ? seriesMarker.fillColor : void 0, pointOptions.color, point.zone ? point.zone.color : void 0, point.color);
  358. point.upperGraphic.attr({
  359. fill: upperGraphicColor
  360. });
  361. extend(point, origProps);
  362. }
  363. }
  364. }
  365. point.connector[verb](series.getConnectorAttribs(point));
  366. }
  367. });
  368. /**
  369. * The `dumbbell` series. If the [type](#series.dumbbell.type) option is
  370. * not specified, it is inherited from [chart.type](#chart.type).
  371. *
  372. * @extends series,plotOptions.dumbbell
  373. * @product highcharts highstock
  374. * @requires highcharts-more
  375. * @requires modules/dumbbell
  376. * @apioption series.dumbbell
  377. */
  378. /**
  379. * An array of data points for the series. For the `dumbbell` series
  380. * type, points can be given in the following ways:
  381. *
  382. * 1. An array of arrays with 3 or 2 values. In this case, the values correspond
  383. * to `x,low,high`. If the first value is a string, it is applied as the name
  384. * of the point, and the `x` value is inferred. The `x` value can also be
  385. * omitted, in which case the inner arrays should be of length 2\. Then the
  386. * `x` value is automatically calculated, either starting at 0 and
  387. * incremented by 1, or from `pointStart` and `pointInterval` given in the
  388. * series options.
  389. * ```js
  390. * data: [
  391. * [0, 4, 2],
  392. * [1, 2, 1],
  393. * [2, 9, 10]
  394. * ]
  395. * ```
  396. *
  397. * 2. An array of objects with named values. The following snippet shows only a
  398. * few settings, see the complete options set below. If the total number of
  399. * data points exceeds the series'
  400. * [turboThreshold](#series.dumbbell.turboThreshold), this option is not
  401. * available.
  402. * ```js
  403. * data: [{
  404. * x: 1,
  405. * low: 0,
  406. * high: 4,
  407. * name: "Point2",
  408. * color: "#00FF00",
  409. * lowColor: "#00FFFF",
  410. * connectorWidth: 3,
  411. * connectorColor: "#FF00FF"
  412. * }, {
  413. * x: 1,
  414. * low: 5,
  415. * high: 3,
  416. * name: "Point1",
  417. * color: "#FF00FF"
  418. * }]
  419. * ```
  420. *
  421. * @sample {highcharts} highcharts/series/data-array-of-arrays/
  422. * Arrays of numeric x and y
  423. * @sample {highcharts} highcharts/series/data-array-of-arrays-datetime/
  424. * Arrays of datetime x and y
  425. * @sample {highcharts} highcharts/series/data-array-of-name-value/
  426. * Arrays of point.name and y
  427. * @sample {highcharts} highcharts/series/data-array-of-objects/
  428. * Config objects
  429. *
  430. * @type {Array<Array<(number|string),number>|Array<(number|string),number,number>|*>}
  431. * @extends series.arearange.data
  432. * @product highcharts highstock
  433. * @apioption series.dumbbell.data
  434. */
  435. /**
  436. * Color of the line that connects the dumbbell point's values.
  437. * By default it is the series' color.
  438. *
  439. * @type {string}
  440. * @since 8.0.0
  441. * @product highcharts highstock
  442. * @apioption series.dumbbell.data.connectorColor
  443. */
  444. /**
  445. * Pixel width of the line that connects the dumbbell point's values.
  446. *
  447. * @type {number}
  448. * @since 8.0.0
  449. * @default 1
  450. * @product highcharts highstock
  451. * @apioption series.dumbbell.data.connectorWidth
  452. */
  453. /**
  454. * Color of the start markers in a dumbbell graph.
  455. *
  456. * @type {Highcharts.ColorString|Highcharts.GradientColorObject|Highcharts.PatternObject}
  457. * @since 8.0.0
  458. * @default #333333
  459. * @product highcharts highstock
  460. * @apioption series.dumbbell.data.lowColor
  461. */
  462. ''; // adds doclets above to transpiled file
  463. });
  464. _registerModule(_modules, 'masters/modules/dumbbell.src.js', [], function () {
  465. });
  466. }));