solid-gauge.src.js 16 KB

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