solid-gauge.src.js 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443
  1. /**
  2. * @license Highcharts JS v8.0.0 (2019-12-10)
  3. *
  4. * Solid angular gauge module
  5. *
  6. * (c) 2010-2019 Torstein Honsi
  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('highcharts/modules/solid-gauge', ['highcharts', 'highcharts/highcharts-more'], function (Highcharts) {
  17. factory(Highcharts);
  18. factory.Highcharts = Highcharts;
  19. return factory;
  20. });
  21. } else {
  22. factory(typeof Highcharts !== 'undefined' ? Highcharts : undefined);
  23. }
  24. }(function (Highcharts) {
  25. var _modules = Highcharts ? Highcharts._modules : {};
  26. function _registerModule(obj, path, args, fn) {
  27. if (!obj.hasOwnProperty(path)) {
  28. obj[path] = fn.apply(null, args);
  29. }
  30. }
  31. _registerModule(_modules, 'modules/solid-gauge.src.js', [_modules['parts/Globals.js'], _modules['parts/Utilities.js']], function (H, U) {
  32. /* *
  33. *
  34. * Solid angular gauge module
  35. *
  36. * (c) 2010-2019 Torstein Honsi
  37. *
  38. * License: www.highcharts.com/license
  39. *
  40. * !!!!!!! SOURCE GETS TRANSPILED BY TYPESCRIPT. EDIT TS FILE ONLY. !!!!!!!
  41. *
  42. * */
  43. /**
  44. * Additional options, depending on the actual symbol drawn.
  45. *
  46. * @interface Highcharts.SymbolOptionsObject
  47. */ /**
  48. * Whether to draw rounded edges.
  49. * @name Highcharts.SymbolOptionsObject#rounded
  50. * @type {boolean|undefined}
  51. */
  52. var clamp = U.clamp, extend = U.extend, isNumber = U.isNumber, pick = U.pick, pInt = U.pInt, wrap = U.wrap;
  53. var Renderer = H.Renderer, colorAxisMethods;
  54. /**
  55. * Symbol definition of an arc with round edges.
  56. *
  57. * @private
  58. * @function Highcharts.Renderer#symbols.arc
  59. *
  60. * @param {number} x
  61. * The X coordinate for the top left position.
  62. *
  63. * @param {number} y
  64. * The Y coordinate for the top left position.
  65. *
  66. * @param {number} w
  67. * The pixel width.
  68. *
  69. * @param {number} h
  70. * The pixel height.
  71. *
  72. * @param {Highcharts.SymbolOptionsObject} [options]
  73. * Additional options, depending on the actual symbol drawn.
  74. *
  75. * @return {Highcharts.SVGPathArray}
  76. * Path of the created arc.
  77. */
  78. wrap(Renderer.prototype.symbols, 'arc', function (proceed, x, y, w, h, options) {
  79. var arc = proceed, path = arc(x, y, w, h, options);
  80. if (options.rounded) {
  81. var r = options.r || w, smallR = (r - options.innerR) / 2, x1 = path[1], y1 = path[2], x2 = path[12], y2 = path[13], roundStart = ['A', smallR, smallR, 0, 1, 1, x1, y1], roundEnd = ['A', smallR, smallR, 0, 1, 1, x2, y2];
  82. // Insert rounded edge on end, and remove line.
  83. path.splice.apply(path, [path.length - 1, 0].concat(roundStart));
  84. // Insert rounded edge on end, and remove line.
  85. path.splice.apply(path, [11, 3].concat(roundEnd));
  86. }
  87. return path;
  88. });
  89. // These methods are defined in the ColorAxis object, and copied here.
  90. // If we implement an AMD system we should make ColorAxis a dependency.
  91. colorAxisMethods = {
  92. initDataClasses: function (userOptions) {
  93. var chart = this.chart, dataClasses, colorCounter = 0, options = this.options;
  94. this.dataClasses = dataClasses = [];
  95. userOptions.dataClasses.forEach(function (dataClass, i) {
  96. var colors;
  97. dataClass = H.merge(dataClass);
  98. dataClasses.push(dataClass);
  99. if (!dataClass.color) {
  100. if (options.dataClassColor === 'category') {
  101. colors = chart.options.colors;
  102. dataClass.color = colors[colorCounter++];
  103. // loop back to zero
  104. if (colorCounter === colors.length) {
  105. colorCounter = 0;
  106. }
  107. }
  108. else {
  109. dataClass.color = H.color(options.minColor).tweenTo(H.color(options.maxColor), i / (userOptions.dataClasses.length - 1));
  110. }
  111. }
  112. });
  113. },
  114. initStops: function (userOptions) {
  115. this.stops = userOptions.stops || [
  116. [0, this.options.minColor],
  117. [1, this.options.maxColor]
  118. ];
  119. this.stops.forEach(function (stop) {
  120. stop.color = H.color(stop[1]);
  121. });
  122. },
  123. // Translate from a value to a color
  124. toColor: function (value, point) {
  125. var pos, stops = this.stops, from, to, color, dataClasses = this.dataClasses, dataClass, i;
  126. if (dataClasses) {
  127. i = dataClasses.length;
  128. while (i--) {
  129. dataClass = dataClasses[i];
  130. from = dataClass.from;
  131. to = dataClass.to;
  132. if ((typeof from === 'undefined' || value >= from) &&
  133. (typeof to === 'undefined' || value <= to)) {
  134. color = dataClass.color;
  135. if (point) {
  136. point.dataClass = i;
  137. }
  138. break;
  139. }
  140. }
  141. }
  142. else {
  143. if (this.isLog) {
  144. value = this.val2lin(value);
  145. }
  146. pos = 1 - ((this.max - value) / (this.max - this.min));
  147. i = stops.length;
  148. while (i--) {
  149. if (pos > stops[i][0]) {
  150. break;
  151. }
  152. }
  153. from = stops[i] || stops[i + 1];
  154. to = stops[i + 1] || from;
  155. // The position within the gradient
  156. pos = (1 - (to[0] - pos) / ((to[0] -
  157. from[0]) || 1));
  158. color = from.color.tweenTo(to.color, pos);
  159. }
  160. return color;
  161. }
  162. };
  163. /**
  164. * A solid gauge is a circular gauge where the value is indicated by a filled
  165. * arc, and the color of the arc may variate with the value.
  166. *
  167. * @sample highcharts/demo/gauge-solid/
  168. * Solid gauges
  169. *
  170. * @extends plotOptions.gauge
  171. * @excluding dial, pivot, wrap
  172. * @product highcharts
  173. * @requires modules/solid-gauge
  174. * @optionparent plotOptions.solidgauge
  175. */
  176. var solidGaugeOptions = {
  177. /**
  178. * The inner radius for points in a solid gauge. Can be given as a number
  179. * (pixels) or percentage string.
  180. *
  181. * @sample {highcharts} highcharts/plotoptions/solidgauge-radius/
  182. * Individual radius and innerRadius
  183. *
  184. * @type {number|string}
  185. * @default 60
  186. * @since 4.1.6
  187. * @product highcharts
  188. * @apioption plotOptions.solidgauge.innerRadius
  189. */
  190. /**
  191. * Whether the strokes of the solid gauge should be `round` or `square`.
  192. *
  193. * @sample {highcharts} highcharts/demo/gauge-activity/
  194. * Rounded gauge
  195. *
  196. * @type {string}
  197. * @default round
  198. * @since 4.2.2
  199. * @product highcharts
  200. * @validvalue ["square", "round"]
  201. * @apioption plotOptions.solidgauge.linecap
  202. */
  203. /**
  204. * Allow the gauge to overshoot the end of the perimeter axis by this
  205. * many degrees. Say if the gauge axis goes from 0 to 60, a value of
  206. * 100, or 1000, will show 5 degrees beyond the end of the axis when this
  207. * option is set to 5.
  208. *
  209. * @type {number}
  210. * @default 0
  211. * @since 3.0.10
  212. * @product highcharts
  213. * @apioption plotOptions.solidgauge.overshoot
  214. */
  215. /**
  216. * The outer radius for points in a solid gauge. Can be given as a number
  217. * (pixels) or percentage string.
  218. *
  219. * @sample {highcharts} highcharts/plotoptions/solidgauge-radius/
  220. * Individual radius and innerRadius
  221. *
  222. * @type {number|string}
  223. * @default 100
  224. * @since 4.1.6
  225. * @product highcharts
  226. * @apioption plotOptions.solidgauge.radius
  227. */
  228. /**
  229. * Wether to draw rounded edges on the gauge.
  230. *
  231. * @sample {highcharts} highcharts/demo/gauge-activity/
  232. * Activity Gauge
  233. *
  234. * @type {boolean}
  235. * @default false
  236. * @since 5.0.8
  237. * @product highcharts
  238. * @apioption plotOptions.solidgauge.rounded
  239. */
  240. /**
  241. * The threshold or base level for the gauge.
  242. *
  243. * @sample {highcharts} highcharts/plotoptions/solidgauge-threshold/
  244. * Zero threshold with negative and positive values
  245. *
  246. * @type {number}
  247. * @since 5.0.3
  248. * @product highcharts
  249. * @apioption plotOptions.solidgauge.threshold
  250. */
  251. /**
  252. * Whether to give each point an individual color.
  253. */
  254. colorByPoint: true,
  255. dataLabels: {
  256. y: 0
  257. }
  258. };
  259. // The solidgauge series type
  260. H.seriesType('solidgauge', 'gauge', solidGaugeOptions, {
  261. drawLegendSymbol: H.LegendSymbolMixin.drawRectangle,
  262. // Extend the translate function to extend the Y axis with the necessary
  263. // decoration (#5895).
  264. translate: function () {
  265. var axis = this.yAxis;
  266. extend(axis, colorAxisMethods);
  267. // Prepare data classes
  268. if (!axis.dataClasses && axis.options.dataClasses) {
  269. axis.initDataClasses(axis.options);
  270. }
  271. axis.initStops(axis.options);
  272. // Generate points and inherit data label position
  273. H.seriesTypes.gauge.prototype.translate.call(this);
  274. },
  275. // Draw the points where each point is one needle.
  276. drawPoints: function () {
  277. var series = this, yAxis = series.yAxis, center = yAxis.center, options = series.options, renderer = series.chart.renderer, overshoot = options.overshoot, overshootVal = isNumber(overshoot) ?
  278. overshoot / 180 * Math.PI :
  279. 0, thresholdAngleRad;
  280. // Handle the threshold option
  281. if (isNumber(options.threshold)) {
  282. thresholdAngleRad = yAxis.startAngleRad + yAxis.translate(options.threshold, null, null, null, true);
  283. }
  284. this.thresholdAngleRad = pick(thresholdAngleRad, yAxis.startAngleRad);
  285. series.points.forEach(function (point) {
  286. // #10630 null point should not be draw
  287. if (!point.isNull) { // condition like in pie chart
  288. var graphic = point.graphic, rotation = (yAxis.startAngleRad +
  289. yAxis.translate(point.y, null, null, null, true)), radius = ((pInt(pick(point.options.radius, options.radius, 100)) * center[2]) / 200), innerRadius = ((pInt(pick(point.options.innerRadius, options.innerRadius, 60)) * center[2]) / 200), shapeArgs, d, toColor = yAxis.toColor(point.y, point), axisMinAngle = Math.min(yAxis.startAngleRad, yAxis.endAngleRad), axisMaxAngle = Math.max(yAxis.startAngleRad, yAxis.endAngleRad), minAngle, maxAngle;
  290. if (toColor === 'none') { // #3708
  291. toColor = point.color || series.color || 'none';
  292. }
  293. if (toColor !== 'none') {
  294. point.color = toColor;
  295. }
  296. // Handle overshoot and clipping to axis max/min
  297. rotation = clamp(rotation, axisMinAngle - overshootVal, axisMaxAngle + overshootVal);
  298. // Handle the wrap option
  299. if (options.wrap === false) {
  300. rotation = clamp(rotation, axisMinAngle, axisMaxAngle);
  301. }
  302. minAngle = Math.min(rotation, series.thresholdAngleRad);
  303. maxAngle = Math.max(rotation, series.thresholdAngleRad);
  304. if (maxAngle - minAngle > 2 * Math.PI) {
  305. maxAngle = minAngle + 2 * Math.PI;
  306. }
  307. point.shapeArgs = shapeArgs = {
  308. x: center[0],
  309. y: center[1],
  310. r: radius,
  311. innerR: innerRadius,
  312. start: minAngle,
  313. end: maxAngle,
  314. rounded: options.rounded
  315. };
  316. point.startR = radius; // For PieSeries.animate
  317. if (graphic) {
  318. d = shapeArgs.d;
  319. graphic.animate(extend({ fill: toColor }, shapeArgs));
  320. if (d) {
  321. shapeArgs.d = d; // animate alters it
  322. }
  323. }
  324. else {
  325. point.graphic = graphic = renderer.arc(shapeArgs)
  326. .attr({
  327. fill: toColor,
  328. 'sweep-flag': 0
  329. })
  330. .add(series.group);
  331. }
  332. if (!series.chart.styledMode) {
  333. if (options.linecap !== 'square') {
  334. graphic.attr({
  335. 'stroke-linecap': 'round',
  336. 'stroke-linejoin': 'round'
  337. });
  338. }
  339. graphic.attr({
  340. stroke: options.borderColor || 'none',
  341. 'stroke-width': options.borderWidth || 0
  342. });
  343. }
  344. if (graphic) {
  345. graphic.addClass(point.getClassName(), true);
  346. }
  347. }
  348. });
  349. },
  350. // Extend the pie slice animation by animating from start angle and up.
  351. animate: function (init) {
  352. if (!init) {
  353. this.startAngleRad = this.thresholdAngleRad;
  354. H.seriesTypes.pie.prototype.animate.call(this, init);
  355. }
  356. }
  357. });
  358. /**
  359. * A `solidgauge` series. If the [type](#series.solidgauge.type) option is not
  360. * specified, it is inherited from [chart.type](#chart.type).
  361. *
  362. *
  363. * @extends series,plotOptions.solidgauge
  364. * @excluding animationLimit, boostThreshold, connectEnds, connectNulls,
  365. * cropThreshold, dashStyle, dataParser, dataURL, dial,
  366. * findNearestPointBy, getExtremesFromAll, marker, negativeColor,
  367. * pointPlacement, pivot, shadow, softThreshold, stack, stacking,
  368. * states, step, threshold, turboThreshold, wrap, zoneAxis, zones
  369. * @product highcharts
  370. * @requires modules/solid-gauge
  371. * @apioption series.solidgauge
  372. */
  373. /**
  374. * An array of data points for the series. For the `solidgauge` series
  375. * type, points can be given in the following ways:
  376. *
  377. * 1. An array of numerical values. In this case, the numerical values will be
  378. * interpreted as `y` options. Example:
  379. * ```js
  380. * data: [0, 5, 3, 5]
  381. * ```
  382. *
  383. * 2. An array of objects with named values. The following snippet shows only a
  384. * few settings, see the complete options set below. If the total number of
  385. * data points exceeds the series'
  386. * [turboThreshold](#series.solidgauge.turboThreshold), this option is not
  387. * available.
  388. * ```js
  389. * data: [{
  390. * y: 5,
  391. * name: "Point2",
  392. * color: "#00FF00"
  393. * }, {
  394. * y: 7,
  395. * name: "Point1",
  396. * color: "#FF00FF"
  397. * }]
  398. * ```
  399. *
  400. * The typical gauge only contains a single data value.
  401. *
  402. * @sample {highcharts} highcharts/chart/reflow-true/
  403. * Numerical values
  404. * @sample {highcharts} highcharts/series/data-array-of-objects/
  405. * Config objects
  406. *
  407. * @type {Array<number|null|*>}
  408. * @extends series.gauge.data
  409. * @product highcharts
  410. * @apioption series.solidgauge.data
  411. */
  412. /**
  413. * The inner radius of an individual point in a solid gauge. Can be given as a
  414. * number (pixels) or percentage string.
  415. *
  416. * @sample {highcharts} highcharts/plotoptions/solidgauge-radius/
  417. * Individual radius and innerRadius
  418. *
  419. * @type {number|string}
  420. * @since 4.1.6
  421. * @product highcharts
  422. * @apioption series.solidgauge.data.innerRadius
  423. */
  424. /**
  425. * The outer radius of an individual point in a solid gauge. Can be
  426. * given as a number (pixels) or percentage string.
  427. *
  428. * @sample {highcharts} highcharts/plotoptions/solidgauge-radius/
  429. * Individual radius and innerRadius
  430. *
  431. * @type {number|string}
  432. * @since 4.1.6
  433. * @product highcharts
  434. * @apioption series.solidgauge.data.radius
  435. */
  436. ''; // adds doclets above to transpiled file
  437. });
  438. _registerModule(_modules, 'masters/modules/solid-gauge.src.js', [], function () {
  439. });
  440. }));