bullet.src.js 14 KB

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