solid-gauge.src.js 20 KB

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