solid-gauge.src.js 14.8 KB
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475
/**
 * @license  Highcharts JS v6.2.0 (2018-10-17)
 * Solid angular gauge module
 *
 * (c) 2010-2018 Torstein Honsi
 *
 * License: www.highcharts.com/license
 */
'use strict';
(function (factory) {
	if (typeof module === 'object' && module.exports) {
		module.exports = factory;
	} else if (typeof define === 'function' && define.amd) {
		define(function () {
			return factory;
		});
	} else {
		factory(Highcharts);
	}
}(function (Highcharts) {
	(function (H) {
		/**
		 * Solid angular gauge module
		 *
		 * (c) 2010-2018 Torstein Honsi
		 *
		 * License: www.highcharts.com/license
		 */

		var pInt = H.pInt,
		    pick = H.pick,
		    each = H.each,
		    isNumber = H.isNumber,
		    wrap = H.wrap,
		    Renderer = H.Renderer,
		    colorAxisMethods;

		/**
		 * Symbol definition of an arc with round edges.
		 *
		 * @param  {Number} x - The X coordinate for the top left position.
		 * @param  {Number} y - The Y coordinate for the top left position.
		 * @param  {Number} w - The pixel width.
		 * @param  {Number} h - The pixel height.
		 * @param  {Object} [options] - Additional options, depending on the actual
		 *    symbol drawn.
		 * @param {boolean} [options.rounded] - Whether to draw rounded edges.
		 * @return {Array} Path of the created arc.
		 */
		wrap(
		    Renderer.prototype.symbols,
		    'arc',
		    function (proceed, x, y, w, h, options) {
		        var arc = proceed,
		            path = arc(x, y, w, h, options);
		        if (options.rounded) {
		            var r = options.r || w,
		                smallR = (r - options.innerR) / 2,
		                x1 = path[1],
		                y1 = path[2],
		                x2 = path[12],
		                y2 = path[13],
		                roundStart = ['A', smallR, smallR, 0, 1, 1, x1, y1],
		                roundEnd = ['A', smallR, smallR, 0, 1, 1, x2, y2];
		            // Insert rounded edge on end, and remove line.
		            path.splice.apply(path, [path.length - 1, 0].concat(roundStart));
		            // Insert rounded edge on end, and remove line.
		            path.splice.apply(path, [11, 3].concat(roundEnd));
		        }

		        return path;
		    }
		);

		// These methods are defined in the ColorAxis object, and copied here.
		// If we implement an AMD system we should make ColorAxis a dependency.
		colorAxisMethods = {


		    initDataClasses: function (userOptions) {
		        var chart = this.chart,
		            dataClasses,
		            colorCounter = 0,
		            options = this.options;
		        this.dataClasses = dataClasses = [];

		        each(userOptions.dataClasses, function (dataClass, i) {
		            var colors;

		            dataClass = H.merge(dataClass);
		            dataClasses.push(dataClass);
		            if (!dataClass.color) {
		                if (options.dataClassColor === 'category') {
		                    colors = chart.options.colors;
		                    dataClass.color = colors[colorCounter++];
		                    // loop back to zero
		                    if (colorCounter === colors.length) {
		                        colorCounter = 0;
		                    }
		                } else {
		                    dataClass.color = H.color(options.minColor).tweenTo(
		                        H.color(options.maxColor),
		                        i / (userOptions.dataClasses.length - 1)
		                    );
		                }
		            }
		        });
		    },

		    initStops: function (userOptions) {
		        this.stops = userOptions.stops || [
		            [0, this.options.minColor],
		            [1, this.options.maxColor]
		        ];
		        each(this.stops, function (stop) {
		            stop.color = H.color(stop[1]);
		        });
		    },
		    /**
		     * Translate from a value to a color
		     */
		    toColor: function (value, point) {
		        var pos,
		            stops = this.stops,
		            from,
		            to,
		            color,
		            dataClasses = this.dataClasses,
		            dataClass,
		            i;

		        if (dataClasses) {
		            i = dataClasses.length;
		            while (i--) {
		                dataClass = dataClasses[i];
		                from = dataClass.from;
		                to = dataClass.to;
		                if (
		                    (from === undefined || value >= from) &&
		                    (to === undefined || value <= to)
		                ) {
		                    color = dataClass.color;
		                    if (point) {
		                        point.dataClass = i;
		                    }
		                    break;
		                }
		            }

		        } else {

		            if (this.isLog) {
		                value = this.val2lin(value);
		            }
		            pos = 1 - ((this.max - value) / (this.max - this.min));
		            i = stops.length;
		            while (i--) {
		                if (pos > stops[i][0]) {
		                    break;
		                }
		            }
		            from = stops[i] || stops[i + 1];
		            to = stops[i + 1] || from;

		            // The position within the gradient
		            pos = 1 - (to[0] - pos) / ((to[0] - from[0]) || 1);

		            color = from.color.tweenTo(
		                to.color,
		                pos
		            );
		        }
		        return color;
		    }
		};
		/**
		 * A solid gauge is a circular gauge where the value is indicated by a filled
		 * arc, and the color of the arc may variate with the value.
		 *
		 * @sample highcharts/demo/gauge-solid/ Solid gauges
		 * @extends plotOptions.gauge
		 * @excluding dial,pivot,wrap
		 * @product highcharts
		 * @optionparent plotOptions.solidgauge
		 */
		var solidGaugeOptions = {
		    /**
		     * Whether the strokes of the solid gauge should be `round` or `square`.
		     *
		     * @validvalue ["square", "round"]
		     * @type {String}
		     * @sample {highcharts} highcharts/demo/gauge-activity/ Rounded gauge
		     * @default round
		     * @since 4.2.2
		     * @product highcharts
		     * @apioption plotOptions.solidgauge.linecap
		     */

		    /**
		     * Allow the gauge to overshoot the end of the perimeter axis by this
		     * many degrees. Say if the gauge axis goes from 0 to 60, a value of
		     * 100, or 1000, will show 5 degrees beyond the end of the axis when this
		     * option is set to 5.
		     *
		     * @type      {Number}
		     * @default   0
		     * @since     3.0.10
		     * @product   highcharts
		     * @apioption plotOptions.solidgauge.overshoot
		     */

		    /**
		     * Wether to draw rounded edges on the gauge.
		     *
		     * @type {Boolean}
		     * @sample {highcharts} highcharts/demo/gauge-activity/ Activity Gauge
		     * @default false
		     * @since 5.0.8
		     * @product highcharts
		     * @apioption plotOptions.solidgauge.rounded
		     */

		    /**
		     * The threshold or base level for the gauge.
		     *
		     * @type {Number}
		     * @sample {highcharts} highcharts/plotoptions/solidgauge-threshold/
		     *         Zero threshold with negative and positive values
		     * @default null
		     * @since 5.0.3
		     * @product highcharts
		     * @apioption plotOptions.solidgauge.threshold
		     */

		    /**
		     * Whether to give each point an individual color.
		     */
		    colorByPoint: true

		};


		// The solidgauge series type
		H.seriesType('solidgauge', 'gauge', solidGaugeOptions, {

		    /**
		     * Extend the translate function to extend the Y axis with the necessary
		     * decoration (#5895).
		     */
		    translate: function () {
		        var axis = this.yAxis;
		        H.extend(axis, colorAxisMethods);

		        // Prepare data classes
		        if (!axis.dataClasses && axis.options.dataClasses) {
		            axis.initDataClasses(axis.options);
		        }
		        axis.initStops(axis.options);

		        // Generate points and inherit data label position
		        H.seriesTypes.gauge.prototype.translate.call(this);
		    },

		    /**
		     * Draw the points where each point is one needle
		     */
		    drawPoints: function () {
		        var series = this,
		            yAxis = series.yAxis,
		            center = yAxis.center,
		            options = series.options,
		            renderer = series.chart.renderer,
		            overshoot = options.overshoot,
		            overshootVal = isNumber(overshoot) ? overshoot / 180 * Math.PI : 0,
		            thresholdAngleRad;

		        // Handle the threshold option
		        if (isNumber(options.threshold)) {
		            thresholdAngleRad = yAxis.startAngleRad + yAxis.translate(
		                options.threshold,
		                null,
		                null,
		                null,
		                true
		            );
		        }
		        this.thresholdAngleRad = pick(thresholdAngleRad, yAxis.startAngleRad);


		        each(series.points, function (point) {
		            var graphic = point.graphic,
		                rotation = yAxis.startAngleRad +
		                    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;

		            if (toColor === 'none') { // #3708
		                toColor = point.color || series.color || 'none';
		            }
		            if (toColor !== 'none') {
		                point.color = toColor;
		            }

		            // Handle overshoot and clipping to axis max/min
		            rotation = Math.max(
		                axisMinAngle - overshootVal,
		                Math.min(axisMaxAngle + overshootVal, rotation)
		            );

		            // Handle the wrap option
		            if (options.wrap === false) {
		                rotation = Math.max(
		                    axisMinAngle,
		                    Math.min(axisMaxAngle, rotation)
		                );
		            }

		            minAngle = Math.min(rotation, series.thresholdAngleRad);
		            maxAngle = Math.max(rotation, series.thresholdAngleRad);

		            if (maxAngle - minAngle > 2 * Math.PI) {
		                maxAngle = minAngle + 2 * Math.PI;
		            }

		            point.shapeArgs = shapeArgs = {
		                x: center[0],
		                y: center[1],
		                r: radius,
		                innerR: innerRadius,
		                start: minAngle,
		                end: maxAngle,
		                rounded: options.rounded
		            };
		            point.startR = radius; // For PieSeries.animate

		            if (graphic) {
		                d = shapeArgs.d;
		                graphic.animate(H.extend({ fill: toColor }, shapeArgs));
		                if (d) {
		                    shapeArgs.d = d; // animate alters it
		                }
		            } else {
		                point.graphic = graphic = renderer.arc(shapeArgs)
		                    .attr({
		                        fill: toColor,
		                        'sweep-flag': 0
		                    })
		                    .add(series.group);

                
		            }

		            if (graphic) {
		                graphic.addClass(point.getClassName(), true);
		            }
		        });
		    },

		    /**
		     * Extend the pie slice animation by animating from start angle and up
		     */
		    animate: function (init) {

		        if (!init) {
		            this.startAngleRad = this.thresholdAngleRad;
		            H.seriesTypes.pie.prototype.animate.call(this, init);
		        }
		    }
		});

		/**
		 * A `solidgauge` series. If the [type](#series.solidgauge.type) option
		 * is not specified, it is inherited from [chart.type](#chart.type).
		 *
		 *
		 * @type      {Object}
		 * @extends   series,plotOptions.solidgauge
		 * @excluding animationLimit,boostThreshold,connectEnds,connectNulls,
		 *            cropThreshold,dashStyle,dataParser,dataURL,dial,
		 *            findNearestPointBy,getExtremesFromAll,marker,negativeColor,
		 *            pointPlacement,pivot,shadow,softThreshold,stack,stacking,states,
		 *            step,threshold,turboThreshold,wrap,zoneAxis,zones
		 * @product   highcharts
		 * @apioption series.solidgauge
		 */

		/**
		 * An array of data points for the series. For the `solidgauge` series
		 * type, points can be given in the following ways:
		 *
		 * 1.  An array of numerical values. In this case, the numerical values
		 * will be interpreted as `y` options. Example:
		 *
		 *  ```js
		 *  data: [0, 5, 3, 5]
		 *  ```
		 *
		 * 2.  An array of objects with named values. The following snippet shows only a
		 * few settings, see the complete options set below. If the total number of data
		 * points exceeds the series' [turboThreshold](
		 * #series.solidgauge.turboThreshold), this option is not available.
		 *
		 *  ```js
		 *     data: [{
		 *         y: 5,
		 *         name: "Point2",
		 *         color: "#00FF00"
		 *     }, {
		 *         y: 7,
		 *         name: "Point1",
		 *         color: "#FF00FF"
		 *     }]
		 *  ```
		 *
		 * The typical gauge only contains a single data value.
		 *
		 * @type {Array<Object|Number>}
		 * @extends series.gauge.data
		 * @sample {highcharts} highcharts/chart/reflow-true/
		 *         Numerical values
		 * @sample {highcharts} highcharts/series/data-array-of-arrays/
		 *         Arrays of numeric x and y
		 * @sample {highcharts} highcharts/series/data-array-of-arrays-datetime/
		 *         Arrays of datetime x and y
		 * @sample {highcharts} highcharts/series/data-array-of-name-value/
		 *         Arrays of point.name and y
		 * @sample {highcharts} highcharts/series/data-array-of-objects/
		 *         Config objects
		 * @product highcharts
		 * @apioption series.solidgauge.data
		 */

		/**
		 * The inner radius of an individual point in a solid gauge. Can be
		 * given as a number (pixels) or percentage string.
		 *
		 * @type {Number|String}
		 * @sample {highcharts} highcharts/plotoptions/solidgauge-radius/ Individual radius and innerRadius
		 * @since 4.1.6
		 * @product highcharts
		 * @apioption series.solidgauge.data.innerRadius
		 */

		/**
		 * The outer radius of an individual point in a solid gauge. Can be
		 * given as a number (pixels) or percentage string.
		 *
		 * @type {Number|String}
		 * @sample {highcharts} highcharts/plotoptions/solidgauge-radius/ Individual radius and innerRadius
		 * @since 4.1.6
		 * @product highcharts
		 * @apioption series.solidgauge.data.radius
		 */

	}(Highcharts));
	return (function () {


	}());
}));