BulletSeries.js 12 KB

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