bullet.src.js 19 KB

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