solid-gauge.src.js 22 KB

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