bullet.src.js 19 KB

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