bullet.src.js 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476
  1. /**
  2. * @license Highcharts JS v9.0.1 (2021-02-16)
  3. *
  4. * Bullet graph series type for Highcharts
  5. *
  6. * (c) 2010-2021 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/Bullet/BulletPoint.js', [_modules['Series/Column/ColumnSeries.js']], function (ColumnSeries) {
  32. /* *
  33. *
  34. * (c) 2010-2021 Torstein Honsi
  35. *
  36. * License: www.highcharts.com/license
  37. *
  38. * !!!!!!! SOURCE GETS TRANSPILED BY TYPESCRIPT. EDIT TS FILE ONLY. !!!!!!!
  39. *
  40. * */
  41. var __extends = (this && this.__extends) || (function () {
  42. var extendStatics = function (d,
  43. b) {
  44. extendStatics = Object.setPrototypeOf ||
  45. ({ __proto__: [] } instanceof Array && function (d,
  46. b) { d.__proto__ = b; }) ||
  47. function (d,
  48. b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
  49. return extendStatics(d, b);
  50. };
  51. return function (d, b) {
  52. extendStatics(d, b);
  53. function __() { this.constructor = d; }
  54. d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
  55. };
  56. })();
  57. /* *
  58. *
  59. * Class
  60. *
  61. * */
  62. var BulletPoint = /** @class */ (function (_super) {
  63. __extends(BulletPoint, _super);
  64. function BulletPoint() {
  65. var _this = _super !== null && _super.apply(this,
  66. arguments) || this;
  67. _this.options = void 0;
  68. _this.series = void 0;
  69. return _this;
  70. /* eslint-enable valid-jsdoc */
  71. }
  72. /* *
  73. *
  74. * Functions
  75. *
  76. * */
  77. /* eslint-disable valid-jsdoc */
  78. /**
  79. * Destroys target graphic.
  80. * @private
  81. */
  82. BulletPoint.prototype.destroy = function () {
  83. if (this.targetGraphic) {
  84. this.targetGraphic = this.targetGraphic.destroy();
  85. }
  86. _super.prototype.destroy.apply(this, arguments);
  87. return;
  88. };
  89. return BulletPoint;
  90. }(ColumnSeries.prototype.pointClass));
  91. /* *
  92. *
  93. * Export Default
  94. *
  95. * */
  96. return BulletPoint;
  97. });
  98. _registerModule(_modules, 'Series/Bullet/BulletSeries.js', [_modules['Series/Bullet/BulletPoint.js'], _modules['Core/Series/SeriesRegistry.js'], _modules['Core/Utilities.js']], function (BulletPoint, SeriesRegistry, U) {
  99. /* *
  100. *
  101. * (c) 2010-2021 Kacper Madej
  102. *
  103. * License: www.highcharts.com/license
  104. *
  105. * !!!!!!! SOURCE GETS TRANSPILED BY TYPESCRIPT. EDIT TS FILE ONLY. !!!!!!!
  106. *
  107. * */
  108. var __extends = (this && this.__extends) || (function () {
  109. var extendStatics = function (d,
  110. b) {
  111. extendStatics = Object.setPrototypeOf ||
  112. ({ __proto__: [] } instanceof Array && function (d,
  113. b) { d.__proto__ = b; }) ||
  114. function (d,
  115. b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
  116. return extendStatics(d, b);
  117. };
  118. return function (d, b) {
  119. extendStatics(d, b);
  120. function __() { this.constructor = d; }
  121. d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
  122. };
  123. })();
  124. var ColumnSeries = SeriesRegistry.seriesTypes.column;
  125. var extend = U.extend,
  126. isNumber = U.isNumber,
  127. merge = U.merge,
  128. pick = U.pick,
  129. relativeLength = U.relativeLength;
  130. /* *
  131. *
  132. * Class
  133. *
  134. * */
  135. /**
  136. * The bullet series type.
  137. *
  138. * @private
  139. * @class
  140. * @name Highcharts.seriesTypes.bullet
  141. *
  142. * @augments Highcharts.Series
  143. */
  144. var BulletSeries = /** @class */ (function (_super) {
  145. __extends(BulletSeries, _super);
  146. function BulletSeries() {
  147. /* *
  148. *
  149. * Static Properties
  150. *
  151. * */
  152. var _this = _super !== null && _super.apply(this,
  153. arguments) || this;
  154. /* *
  155. *
  156. * Properties
  157. *
  158. * */
  159. _this.data = void 0;
  160. _this.options = void 0;
  161. _this.points = void 0;
  162. _this.targetData = void 0;
  163. return _this;
  164. /* eslint-enable valid-jsdoc */
  165. }
  166. /* *
  167. *
  168. * Functions
  169. *
  170. * */
  171. /* eslint-disable valid-jsdoc */
  172. /**
  173. * Draws the targets. For inverted chart, the `series.group` is rotated,
  174. * so the same coordinates apply. This method is based on column series
  175. * drawPoints function.
  176. *
  177. * @ignore
  178. * @function Highcharts.Series#drawPoints
  179. */
  180. BulletSeries.prototype.drawPoints = function () {
  181. var series = this,
  182. chart = series.chart,
  183. options = series.options,
  184. animationLimit = options.animationLimit || 250;
  185. _super.prototype.drawPoints.apply(this, arguments);
  186. series.points.forEach(function (point) {
  187. var pointOptions = point.options,
  188. shapeArgs,
  189. targetGraphic = point.targetGraphic,
  190. targetShapeArgs,
  191. targetVal = point.target,
  192. pointVal = point.y,
  193. width,
  194. height,
  195. targetOptions,
  196. y;
  197. if (isNumber(targetVal) && targetVal !== null) {
  198. targetOptions = merge(options.targetOptions, pointOptions.targetOptions);
  199. height = targetOptions.height;
  200. shapeArgs = point.shapeArgs;
  201. width = relativeLength(targetOptions.width, shapeArgs.width);
  202. y = series.yAxis.translate(targetVal, false, true, false, true) - targetOptions.height / 2 - 0.5;
  203. targetShapeArgs = series.crispCol.apply({
  204. // Use fake series object to set borderWidth of target
  205. chart: chart,
  206. borderWidth: targetOptions.borderWidth,
  207. options: {
  208. crisp: options.crisp
  209. }
  210. }, [
  211. (shapeArgs.x +
  212. shapeArgs.width / 2 - width / 2),
  213. y,
  214. width,
  215. height
  216. ]);
  217. if (targetGraphic) {
  218. // Update
  219. targetGraphic[chart.pointCount < animationLimit ?
  220. 'animate' :
  221. 'attr'](targetShapeArgs);
  222. // Add or remove tooltip reference
  223. if (isNumber(pointVal) && pointVal !== null) {
  224. targetGraphic.element.point = point;
  225. }
  226. else {
  227. targetGraphic.element.point = void 0;
  228. }
  229. }
  230. else {
  231. point.targetGraphic = targetGraphic = chart.renderer
  232. .rect()
  233. .attr(targetShapeArgs)
  234. .add(series.group);
  235. }
  236. // Presentational
  237. if (!chart.styledMode) {
  238. targetGraphic.attr({
  239. fill: pick(targetOptions.color, pointOptions.color, (series.zones.length && (point.getZone.call({
  240. series: series,
  241. x: point.x,
  242. y: targetVal,
  243. options: {}
  244. }).color || series.color)) || void 0, point.color, series.color),
  245. stroke: pick(targetOptions.borderColor, point.borderColor, series.options.borderColor),
  246. 'stroke-width': targetOptions.borderWidth
  247. });
  248. }
  249. // Add tooltip reference
  250. if (isNumber(pointVal) && pointVal !== null) {
  251. targetGraphic.element.point = point;
  252. }
  253. targetGraphic.addClass(point.getClassName() +
  254. ' highcharts-bullet-target', true);
  255. }
  256. else if (targetGraphic) {
  257. // #1269:
  258. point.targetGraphic = targetGraphic.destroy();
  259. }
  260. });
  261. };
  262. /**
  263. * Includes target values to extend extremes from y values.
  264. *
  265. * @ignore
  266. * @function Highcharts.Series#getExtremes
  267. */
  268. BulletSeries.prototype.getExtremes = function (yData) {
  269. var series = this,
  270. targetData = series.targetData,
  271. yMax,
  272. yMin;
  273. var dataExtremes = _super.prototype.getExtremes.call(this,
  274. yData);
  275. if (targetData && targetData.length) {
  276. var targetExtremes = _super.prototype.getExtremes.call(this,
  277. targetData);
  278. if (isNumber(targetExtremes.dataMin)) {
  279. dataExtremes.dataMin = Math.min(pick(dataExtremes.dataMin, Infinity), targetExtremes.dataMin);
  280. }
  281. if (isNumber(targetExtremes.dataMax)) {
  282. dataExtremes.dataMax = Math.max(pick(dataExtremes.dataMax, -Infinity), targetExtremes.dataMax);
  283. }
  284. }
  285. return dataExtremes;
  286. };
  287. /**
  288. * A bullet graph is a variation of a bar graph. The bullet graph features
  289. * a single measure, compares it to a target, and displays it in the context
  290. * of qualitative ranges of performance that could be set using
  291. * [plotBands](#yAxis.plotBands) on [yAxis](#yAxis).
  292. *
  293. * @sample {highcharts} highcharts/demo/bullet-graph/
  294. * Bullet graph
  295. *
  296. * @extends plotOptions.column
  297. * @since 6.0.0
  298. * @product highcharts
  299. * @excluding allAreas, boostThreshold, colorAxis, compare, compareBase,
  300. * dataSorting, boostBlending
  301. * @requires modules/bullet
  302. * @optionparent plotOptions.bullet
  303. */
  304. BulletSeries.defaultOptions = merge(ColumnSeries.defaultOptions, {
  305. /**
  306. * All options related with look and positiong of targets.
  307. *
  308. * @since 6.0.0
  309. */
  310. targetOptions: {
  311. /**
  312. * The width of the rectangle representing the target. Could be set
  313. * as a pixel value or as a percentage of a column width.
  314. *
  315. * @type {number|string}
  316. * @since 6.0.0
  317. */
  318. width: '140%',
  319. /**
  320. * The height of the rectangle representing the target.
  321. *
  322. * @since 6.0.0
  323. */
  324. height: 3,
  325. /**
  326. * The border color of the rectangle representing the target. When
  327. * not set, the point's border color is used.
  328. *
  329. * In styled mode, use class `highcharts-bullet-target` instead.
  330. *
  331. * @type {Highcharts.ColorString}
  332. * @since 6.0.0
  333. * @product highcharts
  334. * @apioption plotOptions.bullet.targetOptions.borderColor
  335. */
  336. /**
  337. * The color of the rectangle representing the target. When not set,
  338. * point's color (if set in point's options -
  339. * [`color`](#series.bullet.data.color)) or zone of the target value
  340. * (if [`zones`](#plotOptions.bullet.zones) or
  341. * [`negativeColor`](#plotOptions.bullet.negativeColor) are set)
  342. * or the same color as the point has is used.
  343. *
  344. * In styled mode, use class `highcharts-bullet-target` instead.
  345. *
  346. * @type {Highcharts.ColorString|Highcharts.GradientColorObject|Highcharts.PatternObject}
  347. * @since 6.0.0
  348. * @product highcharts
  349. * @apioption plotOptions.bullet.targetOptions.color
  350. */
  351. /**
  352. * The border width of the rectangle representing the target.
  353. *
  354. * In styled mode, use class `highcharts-bullet-target` instead.
  355. *
  356. * @since 6.0.0
  357. */
  358. borderWidth: 0
  359. },
  360. tooltip: {
  361. pointFormat: '<span style="color:{series.color}">\u25CF</span>' +
  362. ' {series.name}: <b>{point.y}</b>. Target: <b>{point.target}' +
  363. '</b><br/>'
  364. }
  365. });
  366. return BulletSeries;
  367. }(ColumnSeries));
  368. extend(BulletSeries.prototype, {
  369. parallelArrays: ['x', 'y', 'target'],
  370. pointArrayMap: ['y', 'target']
  371. });
  372. BulletSeries.prototype.pointClass = BulletPoint;
  373. SeriesRegistry.registerSeriesType('bullet', BulletSeries);
  374. /* *
  375. *
  376. * Default Export
  377. *
  378. * */
  379. /* *
  380. *
  381. * API Options
  382. *
  383. * */
  384. /**
  385. * A `bullet` series. If the [type](#series.bullet.type) option is not
  386. * specified, it is inherited from [chart.type](#chart.type).
  387. *
  388. * @extends series,plotOptions.bullet
  389. * @since 6.0.0
  390. * @product highcharts
  391. * @excluding dataParser, dataURL, marker, dataSorting, boostThreshold,
  392. * boostBlending
  393. * @requires modules/bullet
  394. * @apioption series.bullet
  395. */
  396. /**
  397. * An array of data points for the series. For the `bullet` series type,
  398. * points can be given in the following ways:
  399. *
  400. * 1. An array of arrays with 3 or 2 values. In this case, the values correspond
  401. * to `x,y,target`. If the first value is a string, it is applied as the name
  402. * of the point, and the `x` value is inferred. The `x` value can also be
  403. * omitted, in which case the inner arrays should be of length 2\. Then the
  404. * `x` value is automatically calculated, either starting at 0 and
  405. * incremented by 1, or from `pointStart` and `pointInterval` given in the
  406. * series options.
  407. * ```js
  408. * data: [
  409. * [0, 40, 75],
  410. * [1, 50, 50],
  411. * [2, 60, 40]
  412. * ]
  413. * ```
  414. *
  415. * 2. An array of objects with named values. The following snippet shows only a
  416. * few settings, see the complete options set below. If the total number of
  417. * data points exceeds the series'
  418. * [turboThreshold](#series.bullet.turboThreshold), this option is not
  419. * available.
  420. * ```js
  421. * data: [{
  422. * x: 0,
  423. * y: 40,
  424. * target: 75,
  425. * name: "Point1",
  426. * color: "#00FF00"
  427. * }, {
  428. * x: 1,
  429. * y: 60,
  430. * target: 40,
  431. * name: "Point2",
  432. * color: "#FF00FF"
  433. * }]
  434. * ```
  435. *
  436. * @type {Array<Array<(number|string),number>|Array<(number|string),number,number>|*>}
  437. * @extends series.column.data
  438. * @since 6.0.0
  439. * @product highcharts
  440. * @apioption series.bullet.data
  441. */
  442. /**
  443. * The target value of a point.
  444. *
  445. * @type {number}
  446. * @since 6.0.0
  447. * @product highcharts
  448. * @apioption series.bullet.data.target
  449. */
  450. /**
  451. * Individual target options for each point.
  452. *
  453. * @extends plotOptions.bullet.targetOptions
  454. * @product highcharts
  455. * @apioption series.bullet.data.targetOptions
  456. */
  457. /**
  458. * @product highcharts
  459. * @excluding halo, lineWidth, lineWidthPlus, marker
  460. * @apioption series.bullet.states.hover
  461. */
  462. /**
  463. * @product highcharts
  464. * @excluding halo, lineWidth, lineWidthPlus, marker
  465. * @apioption series.bullet.states.select
  466. */
  467. ''; // adds doclets above to transpiled file
  468. return BulletSeries;
  469. });
  470. _registerModule(_modules, 'masters/modules/bullet.src.js', [], function () {
  471. });
  472. }));