solid-gauge.src.js 25 KB

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