BulletSeries.js 12 KB

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