solid-gauge.src.js 22 KB

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