bullet.src.js 12 KB

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