bullet.src.js 13 KB

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