BulletSeries.js 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308
  1. /* *
  2. *
  3. * (c) 2010-2020 Kacper Madej
  4. *
  5. * License: www.highcharts.com/license
  6. *
  7. * !!!!!!! SOURCE GETS TRANSPILED BY TYPESCRIPT. EDIT TS FILE ONLY. !!!!!!!
  8. *
  9. * */
  10. 'use strict';
  11. import H from '../Core/Globals.js';
  12. import U from '../Core/Utilities.js';
  13. var isNumber = U.isNumber, merge = U.merge, pick = U.pick, relativeLength = U.relativeLength, seriesType = U.seriesType;
  14. var columnProto = H.seriesTypes.column.prototype;
  15. /**
  16. * The bullet series type.
  17. *
  18. * @private
  19. * @class
  20. * @name Highcharts.seriesTypes.bullet
  21. *
  22. * @augments Highcharts.Series
  23. */
  24. seriesType('bullet', 'column'
  25. /**
  26. * A bullet graph is a variation of a bar graph. The bullet graph features
  27. * a single measure, compares it to a target, and displays it in the context
  28. * of qualitative ranges of performance that could be set using
  29. * [plotBands](#yAxis.plotBands) on [yAxis](#yAxis).
  30. *
  31. * @sample {highcharts} highcharts/demo/bullet-graph/
  32. * Bullet graph
  33. *
  34. * @extends plotOptions.column
  35. * @since 6.0.0
  36. * @product highcharts
  37. * @excluding allAreas, boostThreshold, colorAxis, compare, compareBase,
  38. * dataSorting, boostBlending
  39. * @requires modules/bullet
  40. * @optionparent plotOptions.bullet
  41. */
  42. , {
  43. /**
  44. * All options related with look and positiong of targets.
  45. *
  46. * @since 6.0.0
  47. */
  48. targetOptions: {
  49. /**
  50. * The width of the rectangle representing the target. Could be set
  51. * as a pixel value or as a percentage of a column width.
  52. *
  53. * @type {number|string}
  54. * @since 6.0.0
  55. */
  56. width: '140%',
  57. /**
  58. * The height of the rectangle representing the target.
  59. *
  60. * @since 6.0.0
  61. */
  62. height: 3,
  63. /**
  64. * The border color of the rectangle representing the target. When
  65. * not set, the point's border color is used.
  66. *
  67. * In styled mode, use class `highcharts-bullet-target` instead.
  68. *
  69. * @type {Highcharts.ColorString}
  70. * @since 6.0.0
  71. * @product highcharts
  72. * @apioption plotOptions.bullet.targetOptions.borderColor
  73. */
  74. /**
  75. * The color of the rectangle representing the target. When not set,
  76. * point's color (if set in point's options -
  77. * [`color`](#series.bullet.data.color)) or zone of the target value
  78. * (if [`zones`](#plotOptions.bullet.zones) or
  79. * [`negativeColor`](#plotOptions.bullet.negativeColor) are set)
  80. * or the same color as the point has is used.
  81. *
  82. * In styled mode, use class `highcharts-bullet-target` instead.
  83. *
  84. * @type {Highcharts.ColorString|Highcharts.GradientColorObject|Highcharts.PatternObject}
  85. * @since 6.0.0
  86. * @product highcharts
  87. * @apioption plotOptions.bullet.targetOptions.color
  88. */
  89. /**
  90. * The border width of the rectangle representing the target.
  91. *
  92. * In styled mode, use class `highcharts-bullet-target` instead.
  93. *
  94. * @since 6.0.0
  95. */
  96. borderWidth: 0
  97. },
  98. tooltip: {
  99. pointFormat: '<span style="color:{series.color}">\u25CF</span>' +
  100. ' {series.name}: <b>{point.y}</b>. Target: <b>{point.target}' +
  101. '</b><br/>'
  102. }
  103. }, {
  104. pointArrayMap: ['y', 'target'],
  105. parallelArrays: ['x', 'y', 'target'],
  106. /* eslint-disable valid-jsdoc */
  107. /**
  108. * Draws the targets. For inverted chart, the `series.group` is rotated,
  109. * so the same coordinates apply. This method is based on column series
  110. * drawPoints function.
  111. *
  112. * @ignore
  113. * @function Highcharts.Series#drawPoints
  114. */
  115. drawPoints: function () {
  116. var series = this, chart = series.chart, options = series.options, animationLimit = options.animationLimit || 250;
  117. columnProto.drawPoints.apply(this);
  118. series.points.forEach(function (point) {
  119. var pointOptions = point.options, shapeArgs, targetGraphic = point.targetGraphic, targetShapeArgs, targetVal = point.target, pointVal = point.y, width, height, targetOptions, y;
  120. if (isNumber(targetVal) && targetVal !== null) {
  121. targetOptions = merge(options.targetOptions, pointOptions.targetOptions);
  122. height = targetOptions.height;
  123. shapeArgs = point.shapeArgs;
  124. width = relativeLength(targetOptions.width, shapeArgs.width);
  125. y = series.yAxis.translate(targetVal, false, true, false, true) - targetOptions.height / 2 - 0.5;
  126. targetShapeArgs = series.crispCol.apply({
  127. // Use fake series object to set borderWidth of target
  128. chart: chart,
  129. borderWidth: targetOptions.borderWidth,
  130. options: {
  131. crisp: options.crisp
  132. }
  133. }, [
  134. (shapeArgs.x +
  135. shapeArgs.width / 2 - width / 2),
  136. y,
  137. width,
  138. height
  139. ]);
  140. if (targetGraphic) {
  141. // Update
  142. targetGraphic[chart.pointCount < animationLimit ?
  143. 'animate' :
  144. 'attr'](targetShapeArgs);
  145. // Add or remove tooltip reference
  146. if (isNumber(pointVal) && pointVal !== null) {
  147. targetGraphic.element.point = point;
  148. }
  149. else {
  150. targetGraphic.element.point = void 0;
  151. }
  152. }
  153. else {
  154. point.targetGraphic = targetGraphic = chart.renderer
  155. .rect()
  156. .attr(targetShapeArgs)
  157. .add(series.group);
  158. }
  159. // Presentational
  160. if (!chart.styledMode) {
  161. targetGraphic.attr({
  162. fill: pick(targetOptions.color, pointOptions.color, (series.zones.length && (point.getZone.call({
  163. series: series,
  164. x: point.x,
  165. y: targetVal,
  166. options: {}
  167. }).color || series.color)) || void 0, point.color, series.color),
  168. stroke: pick(targetOptions.borderColor, point.borderColor, series.options.borderColor),
  169. 'stroke-width': targetOptions.borderWidth
  170. });
  171. }
  172. // Add tooltip reference
  173. if (isNumber(pointVal) && pointVal !== null) {
  174. targetGraphic.element.point = point;
  175. }
  176. targetGraphic.addClass(point.getClassName() +
  177. ' highcharts-bullet-target', true);
  178. }
  179. else if (targetGraphic) {
  180. // #1269:
  181. point.targetGraphic = targetGraphic.destroy();
  182. }
  183. });
  184. },
  185. /**
  186. * Includes target values to extend extremes from y values.
  187. *
  188. * @ignore
  189. * @function Highcharts.Series#getExtremes
  190. */
  191. getExtremes: function (yData) {
  192. var series = this, targetData = series.targetData, yMax, yMin;
  193. var dataExtremes = columnProto.getExtremes.call(this, yData);
  194. if (targetData && targetData.length) {
  195. var targetExtremes = columnProto.getExtremes.call(this, targetData);
  196. if (isNumber(targetExtremes.dataMin)) {
  197. dataExtremes.dataMin = Math.min(pick(dataExtremes.dataMin, Infinity), targetExtremes.dataMin);
  198. }
  199. if (isNumber(targetExtremes.dataMax)) {
  200. dataExtremes.dataMax = Math.max(pick(dataExtremes.dataMax, -Infinity), targetExtremes.dataMax);
  201. }
  202. }
  203. return dataExtremes;
  204. }
  205. /* eslint-enable valid-jsdoc */
  206. },
  207. /** @lends Highcharts.seriesTypes.ohlc.prototype.pointClass.prototype */
  208. {
  209. // eslint-disable-next-line valid-jsdoc
  210. /**
  211. * Destroys target graphic.
  212. *
  213. * @private
  214. * @function
  215. */
  216. destroy: function () {
  217. if (this.targetGraphic) {
  218. this.targetGraphic = this.targetGraphic.destroy();
  219. }
  220. columnProto.pointClass.prototype.destroy
  221. .apply(this, arguments);
  222. return;
  223. }
  224. });
  225. /**
  226. * A `bullet` series. If the [type](#series.bullet.type) option is not
  227. * specified, it is inherited from [chart.type](#chart.type).
  228. *
  229. * @extends series,plotOptions.bullet
  230. * @since 6.0.0
  231. * @product highcharts
  232. * @excluding dataParser, dataURL, marker, dataSorting, boostThreshold,
  233. * boostBlending
  234. * @requires modules/bullet
  235. * @apioption series.bullet
  236. */
  237. /**
  238. * An array of data points for the series. For the `bullet` series type,
  239. * points can be given in the following ways:
  240. *
  241. * 1. An array of arrays with 3 or 2 values. In this case, the values correspond
  242. * to `x,y,target`. If the first value is a string, it is applied as the name
  243. * of the point, and the `x` value is inferred. The `x` value can also be
  244. * omitted, in which case the inner arrays should be of length 2\. Then the
  245. * `x` value is automatically calculated, either starting at 0 and
  246. * incremented by 1, or from `pointStart` and `pointInterval` given in the
  247. * series options.
  248. * ```js
  249. * data: [
  250. * [0, 40, 75],
  251. * [1, 50, 50],
  252. * [2, 60, 40]
  253. * ]
  254. * ```
  255. *
  256. * 2. An array of objects with named values. The following snippet shows only a
  257. * few settings, see the complete options set below. If the total number of
  258. * data points exceeds the series'
  259. * [turboThreshold](#series.bullet.turboThreshold), this option is not
  260. * available.
  261. * ```js
  262. * data: [{
  263. * x: 0,
  264. * y: 40,
  265. * target: 75,
  266. * name: "Point1",
  267. * color: "#00FF00"
  268. * }, {
  269. * x: 1,
  270. * y: 60,
  271. * target: 40,
  272. * name: "Point2",
  273. * color: "#FF00FF"
  274. * }]
  275. * ```
  276. *
  277. * @type {Array<Array<(number|string),number>|Array<(number|string),number,number>|*>}
  278. * @extends series.column.data
  279. * @since 6.0.0
  280. * @product highcharts
  281. * @apioption series.bullet.data
  282. */
  283. /**
  284. * The target value of a point.
  285. *
  286. * @type {number}
  287. * @since 6.0.0
  288. * @product highcharts
  289. * @apioption series.bullet.data.target
  290. */
  291. /**
  292. * Individual target options for each point.
  293. *
  294. * @extends plotOptions.bullet.targetOptions
  295. * @product highcharts
  296. * @apioption series.bullet.data.targetOptions
  297. */
  298. /**
  299. * @product highcharts
  300. * @excluding halo, lineWidth, lineWidthPlus, marker
  301. * @apioption series.bullet.states.hover
  302. */
  303. /**
  304. * @product highcharts
  305. * @excluding halo, lineWidth, lineWidthPlus, marker
  306. * @apioption series.bullet.states.select
  307. */
  308. ''; // adds doclets above to transpiled file