bullet.src.js 14 KB

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