bullet.src.js 10 KB

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