bullet.src.js 15 KB

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