SolidGaugeSeries.js 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358
  1. /* *
  2. *
  3. * Solid angular gauge module
  4. *
  5. * (c) 2010-2021 Torstein Honsi
  6. *
  7. * License: www.highcharts.com/license
  8. *
  9. * !!!!!!! SOURCE GETS TRANSPILED BY TYPESCRIPT. EDIT TS FILE ONLY. !!!!!!!
  10. *
  11. * */
  12. 'use strict';
  13. var __extends = (this && this.__extends) || (function () {
  14. var extendStatics = function (d, b) {
  15. extendStatics = Object.setPrototypeOf ||
  16. ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
  17. function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
  18. return extendStatics(d, b);
  19. };
  20. return function (d, b) {
  21. extendStatics(d, b);
  22. function __() { this.constructor = d; }
  23. d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
  24. };
  25. })();
  26. import LegendSymbolMixin from '../../Mixins/LegendSymbol.js';
  27. import SeriesRegistry from '../../Core/Series/SeriesRegistry.js';
  28. var _a = SeriesRegistry.seriesTypes, GaugeSeries = _a.gauge, pieProto = _a.pie.prototype;
  29. import SolidGaugeAxis from '../../Core/Axis/SolidGaugeAxis.js';
  30. import U from '../../Core/Utilities.js';
  31. var clamp = U.clamp, extend = U.extend, isNumber = U.isNumber, merge = U.merge, pick = U.pick, pInt = U.pInt;
  32. import './SolidGaugeComposition.js';
  33. /**
  34. * A solid gauge is a circular gauge where the value is indicated by a filled
  35. * arc, and the color of the arc may variate with the value.
  36. *
  37. * @sample highcharts/demo/gauge-solid/
  38. * Solid gauges
  39. *
  40. * @extends plotOptions.gauge
  41. * @excluding dial, pivot, wrap
  42. * @product highcharts
  43. * @requires modules/solid-gauge
  44. * @optionparent plotOptions.solidgauge
  45. */
  46. var solidGaugeOptions = {
  47. /**
  48. * The inner radius for points in a solid gauge. Can be given as a number
  49. * (pixels) or percentage string.
  50. *
  51. * @sample {highcharts} highcharts/plotoptions/solidgauge-radius/
  52. * Individual radius and innerRadius
  53. *
  54. * @type {number|string}
  55. * @default 60
  56. * @since 4.1.6
  57. * @product highcharts
  58. * @apioption plotOptions.solidgauge.innerRadius
  59. */
  60. /**
  61. * Whether the strokes of the solid gauge should be `round` or `square`.
  62. *
  63. * @sample {highcharts} highcharts/demo/gauge-activity/
  64. * Rounded gauge
  65. *
  66. * @type {string}
  67. * @default round
  68. * @since 4.2.2
  69. * @product highcharts
  70. * @validvalue ["square", "round"]
  71. * @apioption plotOptions.solidgauge.linecap
  72. */
  73. /**
  74. * Allow the gauge to overshoot the end of the perimeter axis by this
  75. * many degrees. Say if the gauge axis goes from 0 to 60, a value of
  76. * 100, or 1000, will show 5 degrees beyond the end of the axis when this
  77. * option is set to 5.
  78. *
  79. * @type {number}
  80. * @default 0
  81. * @since 3.0.10
  82. * @product highcharts
  83. * @apioption plotOptions.solidgauge.overshoot
  84. */
  85. /**
  86. * The outer radius for points in a solid gauge. Can be given as a number
  87. * (pixels) or percentage string.
  88. *
  89. * @sample {highcharts} highcharts/plotoptions/solidgauge-radius/
  90. * Individual radius and innerRadius
  91. *
  92. * @type {number|string}
  93. * @default 100
  94. * @since 4.1.6
  95. * @product highcharts
  96. * @apioption plotOptions.solidgauge.radius
  97. */
  98. /**
  99. * Wether to draw rounded edges on the gauge.
  100. *
  101. * @sample {highcharts} highcharts/demo/gauge-activity/
  102. * Activity Gauge
  103. *
  104. * @type {boolean}
  105. * @default false
  106. * @since 5.0.8
  107. * @product highcharts
  108. * @apioption plotOptions.solidgauge.rounded
  109. */
  110. /**
  111. * The threshold or base level for the gauge.
  112. *
  113. * @sample {highcharts} highcharts/plotoptions/solidgauge-threshold/
  114. * Zero threshold with negative and positive values
  115. *
  116. * @type {number|null}
  117. * @since 5.0.3
  118. * @product highcharts
  119. * @apioption plotOptions.solidgauge.threshold
  120. */
  121. /**
  122. * Whether to give each point an individual color.
  123. */
  124. colorByPoint: true,
  125. dataLabels: {
  126. y: 0
  127. }
  128. };
  129. /* *
  130. *
  131. * Class
  132. *
  133. * */
  134. /**
  135. * SolidGauge series type.
  136. *
  137. * @private
  138. * @class
  139. * @name Highcharts.seriesTypes.solidgauge
  140. *
  141. * @augments Highcarts.Series
  142. */
  143. var SolidGaugeSeries = /** @class */ (function (_super) {
  144. __extends(SolidGaugeSeries, _super);
  145. function SolidGaugeSeries() {
  146. /* *
  147. *
  148. * Static properties
  149. *
  150. * */
  151. var _this = _super !== null && _super.apply(this, arguments) || this;
  152. /* *
  153. *
  154. * Properties
  155. *
  156. * */
  157. _this.data = void 0;
  158. _this.points = void 0;
  159. _this.options = void 0;
  160. _this.axis = void 0;
  161. _this.yAxis = void 0;
  162. _this.startAngleRad = void 0;
  163. _this.thresholdAngleRad = void 0;
  164. return _this;
  165. }
  166. /* *
  167. *
  168. * Functions
  169. *
  170. * */
  171. // Extend the translate function to extend the Y axis with the necessary
  172. // decoration (#5895).
  173. SolidGaugeSeries.prototype.translate = function () {
  174. var axis = this.yAxis;
  175. SolidGaugeAxis.init(axis);
  176. // Prepare data classes
  177. if (!axis.dataClasses && axis.options.dataClasses) {
  178. axis.initDataClasses(axis.options);
  179. }
  180. axis.initStops(axis.options);
  181. // Generate points and inherit data label position
  182. GaugeSeries.prototype.translate.call(this);
  183. };
  184. // Draw the points where each point is one needle.
  185. SolidGaugeSeries.prototype.drawPoints = function () {
  186. var series = this, yAxis = series.yAxis, center = yAxis.center, options = series.options, renderer = series.chart.renderer, overshoot = options.overshoot, overshootVal = isNumber(overshoot) ?
  187. overshoot / 180 * Math.PI :
  188. 0, thresholdAngleRad;
  189. // Handle the threshold option
  190. if (isNumber(options.threshold)) {
  191. thresholdAngleRad = yAxis.startAngleRad + yAxis.translate(options.threshold, null, null, null, true);
  192. }
  193. this.thresholdAngleRad = pick(thresholdAngleRad, yAxis.startAngleRad);
  194. series.points.forEach(function (point) {
  195. // #10630 null point should not be draw
  196. if (!point.isNull) { // condition like in pie chart
  197. var graphic = point.graphic, rotation = (yAxis.startAngleRad +
  198. 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;
  199. if (toColor === 'none') { // #3708
  200. toColor = point.color || series.color || 'none';
  201. }
  202. if (toColor !== 'none') {
  203. point.color = toColor;
  204. }
  205. // Handle overshoot and clipping to axis max/min
  206. rotation = clamp(rotation, axisMinAngle - overshootVal, axisMaxAngle + overshootVal);
  207. // Handle the wrap option
  208. if (options.wrap === false) {
  209. rotation = clamp(rotation, axisMinAngle, axisMaxAngle);
  210. }
  211. minAngle = Math.min(rotation, series.thresholdAngleRad);
  212. maxAngle = Math.max(rotation, series.thresholdAngleRad);
  213. if (maxAngle - minAngle > 2 * Math.PI) {
  214. maxAngle = minAngle + 2 * Math.PI;
  215. }
  216. point.shapeArgs = shapeArgs = {
  217. x: center[0],
  218. y: center[1],
  219. r: radius,
  220. innerR: innerRadius,
  221. start: minAngle,
  222. end: maxAngle,
  223. rounded: options.rounded
  224. };
  225. point.startR = radius; // For PieSeries.animate
  226. if (graphic) {
  227. d = shapeArgs.d;
  228. graphic.animate(extend({ fill: toColor }, shapeArgs));
  229. if (d) {
  230. shapeArgs.d = d; // animate alters it
  231. }
  232. }
  233. else {
  234. point.graphic = graphic = renderer.arc(shapeArgs)
  235. .attr({
  236. fill: toColor,
  237. 'sweep-flag': 0
  238. })
  239. .add(series.group);
  240. }
  241. if (!series.chart.styledMode) {
  242. if (options.linecap !== 'square') {
  243. graphic.attr({
  244. 'stroke-linecap': 'round',
  245. 'stroke-linejoin': 'round'
  246. });
  247. }
  248. graphic.attr({
  249. stroke: options.borderColor || 'none',
  250. 'stroke-width': options.borderWidth || 0
  251. });
  252. }
  253. if (graphic) {
  254. graphic.addClass(point.getClassName(), true);
  255. }
  256. }
  257. });
  258. };
  259. // Extend the pie slice animation by animating from start angle and up.
  260. SolidGaugeSeries.prototype.animate = function (init) {
  261. if (!init) {
  262. this.startAngleRad = this.thresholdAngleRad;
  263. pieProto.animate.call(this, init);
  264. }
  265. };
  266. SolidGaugeSeries.defaultOptions = merge(GaugeSeries.defaultOptions, solidGaugeOptions);
  267. return SolidGaugeSeries;
  268. }(GaugeSeries));
  269. extend(SolidGaugeSeries.prototype, {
  270. drawLegendSymbol: LegendSymbolMixin.drawRectangle
  271. });
  272. SeriesRegistry.registerSeriesType('solidgauge', SolidGaugeSeries);
  273. /* *
  274. *
  275. * Default export
  276. *
  277. * */
  278. export default SolidGaugeSeries;
  279. /**
  280. * A `solidgauge` series. If the [type](#series.solidgauge.type) option is not
  281. * specified, it is inherited from [chart.type](#chart.type).
  282. *
  283. *
  284. * @extends series,plotOptions.solidgauge
  285. * @excluding animationLimit, boostThreshold, connectEnds, connectNulls,
  286. * cropThreshold, dashStyle, dataParser, dataURL, dial,
  287. * findNearestPointBy, getExtremesFromAll, marker, negativeColor,
  288. * pointPlacement, pivot, shadow, softThreshold, stack, stacking,
  289. * states, step, threshold, turboThreshold, wrap, zoneAxis, zones,
  290. * dataSorting, boostBlending
  291. * @product highcharts
  292. * @requires modules/solid-gauge
  293. * @apioption series.solidgauge
  294. */
  295. /**
  296. * An array of data points for the series. For the `solidgauge` series
  297. * type, points can be given in the following ways:
  298. *
  299. * 1. An array of numerical values. In this case, the numerical values will be
  300. * interpreted as `y` options. Example:
  301. * ```js
  302. * data: [0, 5, 3, 5]
  303. * ```
  304. *
  305. * 2. An array of objects with named values. The following snippet shows only a
  306. * few settings, see the complete options set below. If the total number of
  307. * data points exceeds the series'
  308. * [turboThreshold](#series.solidgauge.turboThreshold), this option is not
  309. * available.
  310. * ```js
  311. * data: [{
  312. * y: 5,
  313. * name: "Point2",
  314. * color: "#00FF00"
  315. * }, {
  316. * y: 7,
  317. * name: "Point1",
  318. * color: "#FF00FF"
  319. * }]
  320. * ```
  321. *
  322. * The typical gauge only contains a single data value.
  323. *
  324. * @sample {highcharts} highcharts/chart/reflow-true/
  325. * Numerical values
  326. * @sample {highcharts} highcharts/series/data-array-of-objects/
  327. * Config objects
  328. *
  329. * @type {Array<number|null|*>}
  330. * @extends series.gauge.data
  331. * @product highcharts
  332. * @apioption series.solidgauge.data
  333. */
  334. /**
  335. * The inner radius of an individual point in a solid gauge. Can be given as a
  336. * number (pixels) or percentage string.
  337. *
  338. * @sample {highcharts} highcharts/plotoptions/solidgauge-radius/
  339. * Individual radius and innerRadius
  340. *
  341. * @type {number|string}
  342. * @since 4.1.6
  343. * @product highcharts
  344. * @apioption series.solidgauge.data.innerRadius
  345. */
  346. /**
  347. * The outer radius of an individual point in a solid gauge. Can be
  348. * given as a number (pixels) or percentage string.
  349. *
  350. * @sample {highcharts} highcharts/plotoptions/solidgauge-radius/
  351. * Individual radius and innerRadius
  352. *
  353. * @type {number|string}
  354. * @since 4.1.6
  355. * @product highcharts
  356. * @apioption series.solidgauge.data.radius
  357. */
  358. ''; // adds doclets above to transpiled file