bullet.src.js 15 KB

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