From 8d26675c6ecca5092d112aff44ea1504bd2155cc Mon Sep 17 00:00:00 2001 From: Knight2601 Date: Mon, 20 Nov 2017 10:39:09 +0000 Subject: [PATCH 01/24] update for coffeescript v2.0 --- dist/gauge.coffee | 6 + dist/gauge.js | 1045 ++- node_modules/.bin/cake | 15 + node_modules/.bin/cake.cmd | 7 + node_modules/.bin/coffee | 15 + node_modules/.bin/coffee.cmd | 7 + node_modules/coffeescript/LICENSE | 22 + node_modules/coffeescript/README.md | 62 + node_modules/coffeescript/bin/cake | 18 + node_modules/coffeescript/bin/coffee | 18 + .../coffeescript/lib/coffeescript/browser.js | 141 + .../coffeescript/lib/coffeescript/cake.js | 135 + .../lib/coffeescript/coffeescript.js | 437 ++ .../coffeescript/lib/coffeescript/command.js | 719 ++ .../coffeescript/lib/coffeescript/grammar.js | 1654 +++++ .../coffeescript/lib/coffeescript/helpers.js | 333 + .../coffeescript/lib/coffeescript/index.js | 177 + .../coffeescript/lib/coffeescript/lexer.js | 1690 +++++ .../coffeescript/lib/coffeescript/nodes.js | 5754 +++++++++++++++++ .../coffeescript/lib/coffeescript/optparse.js | 230 + .../coffeescript/lib/coffeescript/parser.js | 1069 +++ .../coffeescript/lib/coffeescript/register.js | 85 + .../coffeescript/lib/coffeescript/repl.js | 289 + .../coffeescript/lib/coffeescript/rewriter.js | 949 +++ .../coffeescript/lib/coffeescript/scope.js | 187 + .../lib/coffeescript/sourcemap.js | 211 + node_modules/coffeescript/package.json | 128 + node_modules/coffeescript/register.js | 1 + node_modules/coffeescript/repl.js | 1 + package.json | 5 +- 30 files changed, 14884 insertions(+), 526 deletions(-) create mode 100644 node_modules/.bin/cake create mode 100644 node_modules/.bin/cake.cmd create mode 100644 node_modules/.bin/coffee create mode 100644 node_modules/.bin/coffee.cmd create mode 100644 node_modules/coffeescript/LICENSE create mode 100644 node_modules/coffeescript/README.md create mode 100644 node_modules/coffeescript/bin/cake create mode 100644 node_modules/coffeescript/bin/coffee create mode 100644 node_modules/coffeescript/lib/coffeescript/browser.js create mode 100644 node_modules/coffeescript/lib/coffeescript/cake.js create mode 100644 node_modules/coffeescript/lib/coffeescript/coffeescript.js create mode 100644 node_modules/coffeescript/lib/coffeescript/command.js create mode 100644 node_modules/coffeescript/lib/coffeescript/grammar.js create mode 100644 node_modules/coffeescript/lib/coffeescript/helpers.js create mode 100644 node_modules/coffeescript/lib/coffeescript/index.js create mode 100644 node_modules/coffeescript/lib/coffeescript/lexer.js create mode 100644 node_modules/coffeescript/lib/coffeescript/nodes.js create mode 100644 node_modules/coffeescript/lib/coffeescript/optparse.js create mode 100644 node_modules/coffeescript/lib/coffeescript/parser.js create mode 100644 node_modules/coffeescript/lib/coffeescript/register.js create mode 100644 node_modules/coffeescript/lib/coffeescript/repl.js create mode 100644 node_modules/coffeescript/lib/coffeescript/rewriter.js create mode 100644 node_modules/coffeescript/lib/coffeescript/scope.js create mode 100644 node_modules/coffeescript/lib/coffeescript/sourcemap.js create mode 100644 node_modules/coffeescript/package.json create mode 100644 node_modules/coffeescript/register.js create mode 100644 node_modules/coffeescript/repl.js diff --git a/dist/gauge.coffee b/dist/gauge.coffee index fde9c69..650244d 100644 --- a/dist/gauge.coffee +++ b/dist/gauge.coffee @@ -168,6 +168,9 @@ class AnimatedText extends ValueUpdater @value = 1 * value constructor: (@elem, @text=false) -> + super() + if @elem is undefined + throw new Error 'The element isn\'t defined.' @value = 1 * @elem.innerHTML if @text @value = 0 @@ -198,6 +201,9 @@ class GaugePointer extends ValueUpdater img: null constructor: (@gauge) -> + super() + if @gauge is undefined + throw new Error 'The element isn\'t defined.' @ctx = @gauge.ctx @canvas = @gauge.canvas super(false, false) diff --git a/dist/gauge.js b/dist/gauge.js index f7d7203..93f7953 100644 --- a/dist/gauge.js +++ b/dist/gauge.js @@ -1,9 +1,9 @@ -// Generated by CoffeeScript 1.11.1 +// Generated by CoffeeScript 2.0.2 (function() { + // Request Animation Frame Polyfill + // CoffeeScript version of http://paulirish.com/2011/requestanimationframe-for-smart-animating/ var AnimatedText, AnimatedTextFactory, Bar, BaseDonut, BaseGauge, Donut, Gauge, GaugePointer, TextRenderer, ValueUpdater, addCommas, cutHex, formatNumber, mergeObjects, secondsToString, - slice = [].slice, - hasProp = {}.hasOwnProperty, - extend = function(child, parent) { for (var key in parent) { if (hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; }; + hasProp = {}.hasOwnProperty; (function() { var browserRequestAnimationFrame, isCancelled, j, lastId, len, vendor, vendors; @@ -30,6 +30,8 @@ lastTime = currTime + timeToCall; return id; }; + // This implementation should only be used with the setTimeout() + // version of window.requestAnimationFrame(). return window.cancelAnimationFrame = function(id) { return clearTimeout(id); }; @@ -68,9 +70,8 @@ return hr + min + ':' + sec; }; - formatNumber = function() { - var digits, num, value; - num = 1 <= arguments.length ? slice.call(arguments, 0) : []; + formatNumber = function(...num) { + var digits, value; value = num[0]; digits = 0 || num[1]; return addCommas(value.toFixed(digits)); @@ -116,174 +117,166 @@ }; ValueUpdater = (function() { - ValueUpdater.prototype.animationSpeed = 32; - - function ValueUpdater(addToAnimationQueue, clear) { - if (addToAnimationQueue == null) { - addToAnimationQueue = true; - } - this.clear = clear != null ? clear : true; - if (addToAnimationQueue) { - AnimationUpdater.add(this); + class ValueUpdater { + constructor(addToAnimationQueue = true, clear = true) { + this.clear = clear; + if (addToAnimationQueue) { + AnimationUpdater.add(this); + } } - } - ValueUpdater.prototype.update = function(force) { - var diff; - if (force == null) { - force = false; - } - if (force || this.displayedValue !== this.value) { - if (this.ctx && this.clear) { - this.ctx.clearRect(0, 0, this.canvas.width, this.canvas.height); - } - diff = this.value - this.displayedValue; - if (Math.abs(diff / this.animationSpeed) <= 0.001) { - this.displayedValue = this.value; - } else { - this.displayedValue = this.displayedValue + diff / this.animationSpeed; + update(force = false) { + var diff; + if (force || this.displayedValue !== this.value) { + if (this.ctx && this.clear) { + this.ctx.clearRect(0, 0, this.canvas.width, this.canvas.height); + } + diff = this.value - this.displayedValue; + if (Math.abs(diff / this.animationSpeed) <= 0.001) { + this.displayedValue = this.value; + } else { + this.displayedValue = this.displayedValue + diff / this.animationSpeed; + } + this.render(); + return true; } - this.render(); - return true; + return false; } - return false; + }; + ValueUpdater.prototype.animationSpeed = 32; + return ValueUpdater; })(); - BaseGauge = (function(superClass) { - extend(BaseGauge, superClass); - - function BaseGauge() { - return BaseGauge.__super__.constructor.apply(this, arguments); - } - - BaseGauge.prototype.displayScale = 1; - - BaseGauge.prototype.forceUpdate = true; - - BaseGauge.prototype.setTextField = function(textField, fractionDigits) { - return this.textField = textField instanceof TextRenderer ? textField : new TextRenderer(textField, fractionDigits); - }; - - BaseGauge.prototype.setMinValue = function(minValue, updateStartValue) { - var gauge, j, len, ref, results; - this.minValue = minValue; - if (updateStartValue == null) { - updateStartValue = true; - } - if (updateStartValue) { - this.displayedValue = this.minValue; - ref = this.gp || []; - results = []; - for (j = 0, len = ref.length; j < len; j++) { - gauge = ref[j]; - results.push(gauge.displayedValue = this.minValue); + BaseGauge = (function() { + class BaseGauge extends ValueUpdater { + setTextField(textField, fractionDigits) { + return this.textField = textField instanceof TextRenderer ? textField : new TextRenderer(textField, fractionDigits); + } + + setMinValue(minValue, updateStartValue = true) { + var gauge, j, len, ref, results; + this.minValue = minValue; + if (updateStartValue) { + this.displayedValue = this.minValue; + ref = this.gp || []; + results = []; + for (j = 0, len = ref.length; j < len; j++) { + gauge = ref[j]; + results.push(gauge.displayedValue = this.minValue); + } + return results; } - return results; } - }; - BaseGauge.prototype.setOptions = function(options) { - if (options == null) { - options = null; - } - this.options = mergeObjects(this.options, options); - if (this.textField) { - this.textField.el.style.fontSize = options.fontSize + 'px'; - } - if (this.options.angle > .5) { - this.options.angle = .5; + setOptions(options = null) { + this.options = mergeObjects(this.options, options); + if (this.textField) { + this.textField.el.style.fontSize = options.fontSize + 'px'; + } + if (this.options.angle > .5) { + this.options.angle = .5; + } + this.configDisplayScale(); + return this; } - this.configDisplayScale(); - return this; - }; - BaseGauge.prototype.configDisplayScale = function() { - var backingStorePixelRatio, devicePixelRatio, height, prevDisplayScale, width; - prevDisplayScale = this.displayScale; - if (this.options.highDpiSupport === false) { - delete this.displayScale; - } else { - devicePixelRatio = window.devicePixelRatio || 1; - backingStorePixelRatio = this.ctx.webkitBackingStorePixelRatio || this.ctx.mozBackingStorePixelRatio || this.ctx.msBackingStorePixelRatio || this.ctx.oBackingStorePixelRatio || this.ctx.backingStorePixelRatio || 1; - this.displayScale = devicePixelRatio / backingStorePixelRatio; - } - if (this.displayScale !== prevDisplayScale) { - width = this.canvas.G__width || this.canvas.width; - height = this.canvas.G__height || this.canvas.height; - this.canvas.width = width * this.displayScale; - this.canvas.height = height * this.displayScale; - this.canvas.style.width = width + "px"; - this.canvas.style.height = height + "px"; - this.canvas.G__width = width; - this.canvas.G__height = height; + configDisplayScale() { + var backingStorePixelRatio, devicePixelRatio, height, prevDisplayScale, width; + prevDisplayScale = this.displayScale; + if (this.options.highDpiSupport === false) { + delete this.displayScale; + } else { + devicePixelRatio = window.devicePixelRatio || 1; + backingStorePixelRatio = this.ctx.webkitBackingStorePixelRatio || this.ctx.mozBackingStorePixelRatio || this.ctx.msBackingStorePixelRatio || this.ctx.oBackingStorePixelRatio || this.ctx.backingStorePixelRatio || 1; + this.displayScale = devicePixelRatio / backingStorePixelRatio; + } + if (this.displayScale !== prevDisplayScale) { + width = this.canvas.G__width || this.canvas.width; + height = this.canvas.G__height || this.canvas.height; + this.canvas.width = width * this.displayScale; + this.canvas.height = height * this.displayScale; + this.canvas.style.width = `${width}px`; + this.canvas.style.height = `${height}px`; + this.canvas.G__width = width; + this.canvas.G__height = height; + } + return this; } - return this; - }; - BaseGauge.prototype.parseValue = function(value) { - value = parseFloat(value) || Number(value); - if (isFinite(value)) { - return value; - } else { - return 0; + parseValue(value) { + value = parseFloat(value) || Number(value); + if (isFinite(value)) { + return value; + } else { + return 0; + } } + }; + BaseGauge.prototype.displayScale = 1; + + BaseGauge.prototype.forceUpdate = true; + return BaseGauge; - })(ValueUpdater); + })(); - TextRenderer = (function() { - function TextRenderer(el, fractionDigits1) { + TextRenderer = class TextRenderer { + constructor(el, fractionDigits1) { this.el = el; this.fractionDigits = fractionDigits1; } - TextRenderer.prototype.render = function(gauge) { + // Default behaviour, override to customize rendering + render(gauge) { return this.el.innerHTML = formatNumber(gauge.displayedValue, this.fractionDigits); - }; - - return TextRenderer; + } - })(); + }; - AnimatedText = (function(superClass) { - extend(AnimatedText, superClass); + AnimatedText = (function() { + class AnimatedText extends ValueUpdater { + setVal(value) { + return this.value = 1 * value; + } - AnimatedText.prototype.displayedValue = 0; + constructor(elem1, text = false) { + super(); + this.elem = elem1; + this.text = text; + if (this.elem === void 0) { + throw new Error('The element isn\'t defined.'); + } + this.value = 1 * this.elem.innerHTML; + if (this.text) { + this.value = 0; + } + } - AnimatedText.prototype.value = 0; + render() { + var textVal; + if (this.text) { + textVal = secondsToString(this.displayedValue.toFixed(0)); + } else { + textVal = addCommas(formatNumber(this.displayedValue)); + } + return this.elem.innerHTML = textVal; + } - AnimatedText.prototype.setVal = function(value) { - return this.value = 1 * value; }; - function AnimatedText(elem1, text) { - this.elem = elem1; - this.text = text != null ? text : false; - this.value = 1 * this.elem.innerHTML; - if (this.text) { - this.value = 0; - } - } + AnimatedText.prototype.displayedValue = 0; - AnimatedText.prototype.render = function() { - var textVal; - if (this.text) { - textVal = secondsToString(this.displayedValue.toFixed(0)); - } else { - textVal = addCommas(formatNumber(this.displayedValue)); - } - return this.elem.innerHTML = textVal; - }; + AnimatedText.prototype.value = 0; return AnimatedText; - })(ValueUpdater); + })(); AnimatedTextFactory = { create: function(objList) { @@ -297,8 +290,65 @@ } }; - GaugePointer = (function(superClass) { - extend(GaugePointer, superClass); + GaugePointer = (function() { + class GaugePointer extends ValueUpdater { + constructor(gauge1) { + super(); + this.gauge = gauge1; + if (this.gauge === void 0) { + throw new Error('The element isn\'t defined.'); + } + this.ctx = this.gauge.ctx; + this.canvas = this.gauge.canvas; + super(false, false); + this.gauge = gauge1; + this.setOptions(); + } + + setOptions(options = null) { + this.options = mergeObjects(this.options, options); + this.length = 2 * this.gauge.radius * this.gauge.options.radiusScale * this.options.length; + this.strokeWidth = this.canvas.height * this.options.strokeWidth; + this.maxValue = this.gauge.maxValue; + this.minValue = this.gauge.minValue; + this.animationSpeed = this.gauge.animationSpeed; + this.options.angle = this.gauge.options.angle; + if (this.options.iconPath) { + this.img = new Image(); + return this.img.src = this.options.iconPath; + } + } + + render() { + var angle, endX, endY, imgX, imgY, startX, startY, x, y; + angle = this.gauge.getAngle.call(this, this.displayedValue); + x = Math.round(this.length * Math.cos(angle)); + y = Math.round(this.length * Math.sin(angle)); + startX = Math.round(this.strokeWidth * Math.cos(angle - Math.PI / 2)); + startY = Math.round(this.strokeWidth * Math.sin(angle - Math.PI / 2)); + endX = Math.round(this.strokeWidth * Math.cos(angle + Math.PI / 2)); + endY = Math.round(this.strokeWidth * Math.sin(angle + Math.PI / 2)); + this.ctx.fillStyle = this.options.color; + this.ctx.beginPath(); + this.ctx.arc(0, 0, this.strokeWidth, 0, Math.PI * 2, true); + this.ctx.fill(); + this.ctx.beginPath(); + this.ctx.moveTo(startX, startY); + this.ctx.lineTo(x, y); + this.ctx.lineTo(endX, endY); + this.ctx.fill(); + if (this.img) { + imgX = Math.round(this.img.width * this.options.iconScale); + imgY = Math.round(this.img.height * this.options.iconScale); + this.ctx.save(); + this.ctx.translate(x, y); + this.ctx.rotate(angle + Math.PI / 180.0 * (90 + this.options.iconAngle)); + this.ctx.drawImage(this.img, -imgX / 2, -imgY / 2, imgX, imgY); + return this.ctx.restore(); + } + } + + }; GaugePointer.prototype.displayedValue = 0; @@ -315,77 +365,23 @@ GaugePointer.prototype.img = null; - function GaugePointer(gauge1) { - this.gauge = gauge1; - this.ctx = this.gauge.ctx; - this.canvas = this.gauge.canvas; - GaugePointer.__super__.constructor.call(this, false, false); - this.setOptions(); - } - - GaugePointer.prototype.setOptions = function(options) { - if (options == null) { - options = null; - } - this.options = mergeObjects(this.options, options); - this.length = 2 * this.gauge.radius * this.gauge.options.radiusScale * this.options.length; - this.strokeWidth = this.canvas.height * this.options.strokeWidth; - this.maxValue = this.gauge.maxValue; - this.minValue = this.gauge.minValue; - this.animationSpeed = this.gauge.animationSpeed; - this.options.angle = this.gauge.options.angle; - if (this.options.iconPath) { - this.img = new Image(); - return this.img.src = this.options.iconPath; - } - }; - - GaugePointer.prototype.render = function() { - var angle, endX, endY, imgX, imgY, startX, startY, x, y; - angle = this.gauge.getAngle.call(this, this.displayedValue); - x = Math.round(this.length * Math.cos(angle)); - y = Math.round(this.length * Math.sin(angle)); - startX = Math.round(this.strokeWidth * Math.cos(angle - Math.PI / 2)); - startY = Math.round(this.strokeWidth * Math.sin(angle - Math.PI / 2)); - endX = Math.round(this.strokeWidth * Math.cos(angle + Math.PI / 2)); - endY = Math.round(this.strokeWidth * Math.sin(angle + Math.PI / 2)); - this.ctx.fillStyle = this.options.color; - this.ctx.beginPath(); - this.ctx.arc(0, 0, this.strokeWidth, 0, Math.PI * 2, true); - this.ctx.fill(); - this.ctx.beginPath(); - this.ctx.moveTo(startX, startY); - this.ctx.lineTo(x, y); - this.ctx.lineTo(endX, endY); - this.ctx.fill(); - if (this.img) { - imgX = Math.round(this.img.width * this.options.iconScale); - imgY = Math.round(this.img.height * this.options.iconScale); - this.ctx.save(); - this.ctx.translate(x, y); - this.ctx.rotate(angle + Math.PI / 180.0 * (90 + this.options.iconAngle)); - this.ctx.drawImage(this.img, -imgX / 2, -imgY / 2, imgX, imgY); - return this.ctx.restore(); - } - }; - return GaugePointer; - })(ValueUpdater); + })(); - Bar = (function() { - function Bar(elem1) { + Bar = class Bar { + constructor(elem1) { this.elem = elem1; } - Bar.prototype.updateValues = function(arrValues) { + updateValues(arrValues) { this.value = arrValues[0]; this.maxValue = arrValues[1]; this.avgValue = arrValues[2]; return this.render(); - }; + } - Bar.prototype.render = function() { + render() { var avgPercent, valPercent; if (this.textField) { this.textField.text(formatNumber(this.value)); @@ -401,18 +397,273 @@ return $(".typical-value", this.elem).css({ "width": avgPercent + "%" }); - }; + } - return Bar; + }; - })(); + Gauge = (function() { + class Gauge extends BaseGauge { + constructor(canvas) { + var h, w; + super(); + this.canvas = canvas; + this.percentColors = null; + if (typeof G_vmlCanvasManager !== 'undefined') { + this.canvas = window.G_vmlCanvasManager.initElement(this.canvas); + } + this.ctx = this.canvas.getContext('2d'); + // Set canvas size to parent size + h = this.canvas.clientHeight; + w = this.canvas.clientWidth; + this.canvas.height = h; + this.canvas.width = w; + this.gp = [new GaugePointer(this)]; + this.setOptions(); + this.render(); + } + + setOptions(options = null) { + var gauge, j, len, phi, ref; + super.setOptions(options); + this.configPercentColors(); + this.extraPadding = 0; + if (this.options.angle < 0) { + phi = Math.PI * (1 + this.options.angle); + this.extraPadding = Math.sin(phi); + } + this.availableHeight = this.canvas.height * (1 - this.paddingTop - this.paddingBottom); + this.lineWidth = this.availableHeight * this.options.lineWidth; // .2 - .7 + this.radius = (this.availableHeight - this.lineWidth / 2) / (1.0 + this.extraPadding); + this.ctx.clearRect(0, 0, this.canvas.width, this.canvas.height); + ref = this.gp; + // @render() + for (j = 0, len = ref.length; j < len; j++) { + gauge = ref[j]; + gauge.setOptions(this.options.pointer); + gauge.render(); + } + return this; + } + + configPercentColors() { + var bval, gval, i, j, ref, results, rval; + this.percentColors = null; + if (this.options.percentColors !== void 0) { + this.percentColors = new Array(); + results = []; + for (i = j = 0, ref = this.options.percentColors.length - 1; 0 <= ref ? j <= ref : j >= ref; i = 0 <= ref ? ++j : --j) { + rval = parseInt((cutHex(this.options.percentColors[i][1])).substring(0, 2), 16); + gval = parseInt((cutHex(this.options.percentColors[i][1])).substring(2, 4), 16); + bval = parseInt((cutHex(this.options.percentColors[i][1])).substring(4, 6), 16); + results.push(this.percentColors[i] = { + pct: this.options.percentColors[i][0], + color: { + r: rval, + g: gval, + b: bval + } + }); + } + return results; + } + } + + set(value) { + var gp, i, j, k, l, len, ref, ref1, val; + if (!(value instanceof Array)) { + value = [value]; + } + // Ensure values are OK + for (i = j = 0, ref = value.length - 1; 0 <= ref ? j <= ref : j >= ref; i = 0 <= ref ? ++j : --j) { + value[i] = this.parseValue(value[i]); + } + // check if we have enough GaugePointers initialized + // lazy initialization + if (value.length > this.gp.length) { + for (i = k = 0, ref1 = value.length - this.gp.length; 0 <= ref1 ? k < ref1 : k > ref1; i = 0 <= ref1 ? ++k : --k) { + gp = new GaugePointer(this); + gp.setOptions(this.options.pointer); + this.gp.push(gp); + } + } else if (value.length < this.gp.length) { + // Delete redundant GaugePointers + this.gp = this.gp.slice(this.gp.length - value.length); + } + // get max value and update pointer(s) + i = 0; + for (l = 0, len = value.length; l < len; l++) { + val = value[l]; + // Limit pointer within min and max? + if (val > this.maxValue) { + if (this.options.limitMax) { + val = this.maxValue; + } else { + this.maxValue = val + 1; + } + } else if (val < this.minValue) { + if (this.options.limitMin) { + val = this.minValue; + } else { + this.minValue = val - 1; + } + } + this.gp[i].value = val; + this.gp[i++].setOptions({ + minValue: this.minValue, + maxValue: this.maxValue, + angle: this.options.angle + }); + } + this.value = Math.max(Math.min(value[value.length - 1], this.maxValue), this.minValue); // TODO: Span maybe?? + + // Force first .set() + AnimationUpdater.run(this.forceUpdate); + return this.forceUpdate = false; + } + + getAngle(value) { + return (1 + this.options.angle) * Math.PI + ((value - this.minValue) / (this.maxValue - this.minValue)) * (1 - this.options.angle * 2) * Math.PI; + } + + getColorForPercentage(pct, grad) { + var color, endColor, i, j, rangePct, ref, startColor; + if (pct === 0) { + color = this.percentColors[0].color; + } else { + color = this.percentColors[this.percentColors.length - 1].color; + for (i = j = 0, ref = this.percentColors.length - 1; 0 <= ref ? j <= ref : j >= ref; i = 0 <= ref ? ++j : --j) { + if (pct <= this.percentColors[i].pct) { + if (grad === true) { + // Gradually change between colors + startColor = this.percentColors[i - 1] || this.percentColors[0]; + endColor = this.percentColors[i]; + rangePct = (pct - startColor.pct) / (endColor.pct - startColor.pct); // How far between both colors + color = { + r: Math.floor(startColor.color.r * (1 - rangePct) + endColor.color.r * rangePct), + g: Math.floor(startColor.color.g * (1 - rangePct) + endColor.color.g * rangePct), + b: Math.floor(startColor.color.b * (1 - rangePct) + endColor.color.b * rangePct) + }; + } else { + color = this.percentColors[i].color; + } + break; + } + } + } + return 'rgb(' + [color.r, color.g, color.b].join(',') + ')'; + } + + getColorForValue(val, grad) { + var pct; + pct = (val - this.minValue) / (this.maxValue - this.minValue); + return this.getColorForPercentage(pct, grad); + } - Gauge = (function(superClass) { - extend(Gauge, superClass); + renderStaticLabels(staticLabels, w, h, radius) { + var font, fontsize, j, len, match, re, ref, rest, rotationAngle, value; + this.ctx.save(); + this.ctx.translate(w, h); + // Scale font size the hard way - assuming size comes first. + font = staticLabels.font || "10px Times"; + re = /\d+\.?\d?/; + match = font.match(re)[0]; + rest = font.slice(match.length); + fontsize = parseFloat(match) * this.displayScale; + this.ctx.font = fontsize + rest; + this.ctx.fillStyle = staticLabels.color || "#000000"; + this.ctx.textBaseline = "bottom"; + this.ctx.textAlign = "center"; + ref = staticLabels.labels; + for (j = 0, len = ref.length; j < len; j++) { + value = ref[j]; + // Draw labels depending on limitMin/Max + if ((!this.options.limitMin || value >= this.minValue) && (!this.options.limitMax || value <= this.maxValue)) { + rotationAngle = this.getAngle(value) - 3 * Math.PI / 2; + this.ctx.rotate(rotationAngle); + this.ctx.fillText(formatNumber(value, staticLabels.fractionDigits), 0, -radius - this.lineWidth / 2); + this.ctx.rotate(-rotationAngle); + } + } + return this.ctx.restore(); + } + + render() { + var displayedAngle, fillStyle, gauge, h, j, k, len, len1, max, min, radius, ref, ref1, w, zone; + // Draw using canvas + w = this.canvas.width / 2; + h = this.canvas.height * this.paddingTop + this.availableHeight - (this.radius + this.lineWidth / 2) * this.extraPadding; + displayedAngle = this.getAngle(this.displayedValue); + if (this.textField) { + this.textField.render(this); + } + this.ctx.lineCap = "butt"; + radius = this.radius * this.options.radiusScale; + if (this.options.staticLabels) { + this.renderStaticLabels(this.options.staticLabels, w, h, radius); + } + if (this.options.staticZones) { + this.ctx.save(); + this.ctx.translate(w, h); + this.ctx.lineWidth = this.lineWidth; + ref = this.options.staticZones; + for (j = 0, len = ref.length; j < len; j++) { + zone = ref[j]; + // Draw zones depending on limitMin/Max + min = zone.min; + if (this.options.limitMin && min < this.minValue) { + min = this.minValue; + } + max = zone.max; + if (this.options.limitMax && max > this.maxValue) { + max = this.maxValue; + } + this.ctx.strokeStyle = zone.strokeStyle; + this.ctx.beginPath(); + this.ctx.arc(0, 0, radius, this.getAngle(min), this.getAngle(max), false); + this.ctx.stroke(); + } + this.ctx.restore(); + } else { + if (this.options.customFillStyle !== void 0) { + fillStyle = this.options.customFillStyle(this); + } else if (this.percentColors !== null) { + fillStyle = this.getColorForValue(this.displayedValue, this.options.generateGradient); + } else if (this.options.colorStop !== void 0) { + if (this.options.gradientType === 0) { + fillStyle = this.ctx.createRadialGradient(w, h, 9, w, h, 70); + } else { + fillStyle = this.ctx.createLinearGradient(0, 0, w, 0); + } + fillStyle.addColorStop(0, this.options.colorStart); + fillStyle.addColorStop(1, this.options.colorStop); + } else { + fillStyle = this.options.colorStart; + } + this.ctx.strokeStyle = fillStyle; + this.ctx.beginPath(); + this.ctx.arc(w, h, radius, (1 + this.options.angle) * Math.PI, displayedAngle, false); + this.ctx.lineWidth = this.lineWidth; + this.ctx.stroke(); + this.ctx.strokeStyle = this.options.strokeColor; + this.ctx.beginPath(); + this.ctx.arc(w, h, radius, displayedAngle, (2 - this.options.angle) * Math.PI, false); + this.ctx.stroke(); + } + // Draw pointers from (w, h) + this.ctx.translate(w, h); + ref1 = this.gp; + for (k = 0, len1 = ref1.length; k < len1; k++) { + gauge = ref1[k]; + gauge.update(true); + } + return this.ctx.translate(-w, -h); + } + + }; Gauge.prototype.elem = null; - Gauge.prototype.value = [20]; + Gauge.prototype.value = [20]; // we support multiple pointers Gauge.prototype.maxValue = 80; @@ -433,7 +684,7 @@ Gauge.prototype.options = { colorStart: "#6fadcf", colorStop: void 0, - gradientType: 0, + gradientType: 0, // 0 : radial, 1 : linear strokeColor: "#e0e0e0", pointer: { length: 0.8, @@ -448,255 +699,79 @@ limitMin: false }; - function Gauge(canvas) { - var h, w; - this.canvas = canvas; - Gauge.__super__.constructor.call(this); - this.percentColors = null; - if (typeof G_vmlCanvasManager !== 'undefined') { - this.canvas = window.G_vmlCanvasManager.initElement(this.canvas); - } - this.ctx = this.canvas.getContext('2d'); - h = this.canvas.clientHeight; - w = this.canvas.clientWidth; - this.canvas.height = h; - this.canvas.width = w; - this.gp = [new GaugePointer(this)]; - this.setOptions(); - this.render(); - } + return Gauge; - Gauge.prototype.setOptions = function(options) { - var gauge, j, len, phi, ref; - if (options == null) { - options = null; - } - Gauge.__super__.setOptions.call(this, options); - this.configPercentColors(); - this.extraPadding = 0; - if (this.options.angle < 0) { - phi = Math.PI * (1 + this.options.angle); - this.extraPadding = Math.sin(phi); - } - this.availableHeight = this.canvas.height * (1 - this.paddingTop - this.paddingBottom); - this.lineWidth = this.availableHeight * this.options.lineWidth; - this.radius = (this.availableHeight - this.lineWidth / 2) / (1.0 + this.extraPadding); - this.ctx.clearRect(0, 0, this.canvas.width, this.canvas.height); - ref = this.gp; - for (j = 0, len = ref.length; j < len; j++) { - gauge = ref[j]; - gauge.setOptions(this.options.pointer); - gauge.render(); - } - return this; - }; + })(); - Gauge.prototype.configPercentColors = function() { - var bval, gval, i, j, ref, results, rval; - this.percentColors = null; - if (this.options.percentColors !== void 0) { - this.percentColors = new Array(); - results = []; - for (i = j = 0, ref = this.options.percentColors.length - 1; 0 <= ref ? j <= ref : j >= ref; i = 0 <= ref ? ++j : --j) { - rval = parseInt((cutHex(this.options.percentColors[i][1])).substring(0, 2), 16); - gval = parseInt((cutHex(this.options.percentColors[i][1])).substring(2, 4), 16); - bval = parseInt((cutHex(this.options.percentColors[i][1])).substring(4, 6), 16); - results.push(this.percentColors[i] = { - pct: this.options.percentColors[i][0], - color: { - r: rval, - g: gval, - b: bval - } - }); + BaseDonut = (function() { + class BaseDonut extends BaseGauge { + constructor(canvas) { + super(); + this.canvas = canvas; + if (typeof G_vmlCanvasManager !== 'undefined') { + this.canvas = window.G_vmlCanvasManager.initElement(this.canvas); } - return results; + this.ctx = this.canvas.getContext('2d'); + this.setOptions(); + this.render(); } - }; - Gauge.prototype.set = function(value) { - var gp, i, j, k, l, len, ref, ref1, val; - if (!(value instanceof Array)) { - value = [value]; - } - for (i = j = 0, ref = value.length - 1; 0 <= ref ? j <= ref : j >= ref; i = 0 <= ref ? ++j : --j) { - value[i] = this.parseValue(value[i]); + getAngle(value) { + return (1 - this.options.angle) * Math.PI + ((value - this.minValue) / (this.maxValue - this.minValue)) * ((2 + this.options.angle) - (1 - this.options.angle)) * Math.PI; } - if (value.length > this.gp.length) { - for (i = k = 0, ref1 = value.length - this.gp.length; 0 <= ref1 ? k < ref1 : k > ref1; i = 0 <= ref1 ? ++k : --k) { - gp = new GaugePointer(this); - gp.setOptions(this.options.pointer); - this.gp.push(gp); - } - } else if (value.length < this.gp.length) { - this.gp = this.gp.slice(this.gp.length - value.length); + + setOptions(options = null) { + super.setOptions(options); + this.lineWidth = this.canvas.height * this.options.lineWidth; + this.radius = this.options.radiusScale * (this.canvas.height / 2 - this.lineWidth / 2); + return this; } - i = 0; - for (l = 0, len = value.length; l < len; l++) { - val = value[l]; - if (val > this.maxValue) { + + set(value) { + this.value = this.parseValue(value); + if (this.value > this.maxValue) { if (this.options.limitMax) { - val = this.maxValue; + this.value = this.maxValue; } else { - this.maxValue = val + 1; + this.maxValue = this.value; } - } else if (val < this.minValue) { + } else if (this.value < this.minValue) { if (this.options.limitMin) { - val = this.minValue; + this.value = this.minValue; } else { - this.minValue = val - 1; + this.minValue = this.value; } } - this.gp[i].value = val; - this.gp[i++].setOptions({ - minValue: this.minValue, - maxValue: this.maxValue, - angle: this.options.angle - }); + AnimationUpdater.run(this.forceUpdate); + return this.forceUpdate = false; } - this.value = Math.max(Math.min(value[value.length - 1], this.maxValue), this.minValue); - AnimationUpdater.run(this.forceUpdate); - return this.forceUpdate = false; - }; - - Gauge.prototype.getAngle = function(value) { - return (1 + this.options.angle) * Math.PI + ((value - this.minValue) / (this.maxValue - this.minValue)) * (1 - this.options.angle * 2) * Math.PI; - }; - Gauge.prototype.getColorForPercentage = function(pct, grad) { - var color, endColor, i, j, rangePct, ref, startColor; - if (pct === 0) { - color = this.percentColors[0].color; - } else { - color = this.percentColors[this.percentColors.length - 1].color; - for (i = j = 0, ref = this.percentColors.length - 1; 0 <= ref ? j <= ref : j >= ref; i = 0 <= ref ? ++j : --j) { - if (pct <= this.percentColors[i].pct) { - if (grad === true) { - startColor = this.percentColors[i - 1] || this.percentColors[0]; - endColor = this.percentColors[i]; - rangePct = (pct - startColor.pct) / (endColor.pct - startColor.pct); - color = { - r: Math.floor(startColor.color.r * (1 - rangePct) + endColor.color.r * rangePct), - g: Math.floor(startColor.color.g * (1 - rangePct) + endColor.color.g * rangePct), - b: Math.floor(startColor.color.b * (1 - rangePct) + endColor.color.b * rangePct) - }; - } else { - color = this.percentColors[i].color; - } - break; - } + render() { + var displayedAngle, grdFill, h, start, stop, w; + displayedAngle = this.getAngle(this.displayedValue); + w = this.canvas.width / 2; + h = this.canvas.height / 2; + if (this.textField) { + this.textField.render(this); } - } - return 'rgb(' + [color.r, color.g, color.b].join(',') + ')'; - }; - - Gauge.prototype.getColorForValue = function(val, grad) { - var pct; - pct = (val - this.minValue) / (this.maxValue - this.minValue); - return this.getColorForPercentage(pct, grad); - }; - - Gauge.prototype.renderStaticLabels = function(staticLabels, w, h, radius) { - var font, fontsize, j, len, match, re, ref, rest, rotationAngle, value; - this.ctx.save(); - this.ctx.translate(w, h); - font = staticLabels.font || "10px Times"; - re = /\d+\.?\d?/; - match = font.match(re)[0]; - rest = font.slice(match.length); - fontsize = parseFloat(match) * this.displayScale; - this.ctx.font = fontsize + rest; - this.ctx.fillStyle = staticLabels.color || "#000000"; - this.ctx.textBaseline = "bottom"; - this.ctx.textAlign = "center"; - ref = staticLabels.labels; - for (j = 0, len = ref.length; j < len; j++) { - value = ref[j]; - if ((!this.options.limitMin || value >= this.minValue) && (!this.options.limitMax || value <= this.maxValue)) { - rotationAngle = this.getAngle(value) - 3 * Math.PI / 2; - this.ctx.rotate(rotationAngle); - this.ctx.fillText(formatNumber(value, staticLabels.fractionDigits), 0, -radius - this.lineWidth / 2); - this.ctx.rotate(-rotationAngle); - } - } - return this.ctx.restore(); - }; - - Gauge.prototype.render = function() { - var displayedAngle, fillStyle, gauge, h, j, k, len, len1, max, min, radius, ref, ref1, w, zone; - w = this.canvas.width / 2; - h = this.canvas.height * this.paddingTop + this.availableHeight - (this.radius + this.lineWidth / 2) * this.extraPadding; - displayedAngle = this.getAngle(this.displayedValue); - if (this.textField) { - this.textField.render(this); - } - this.ctx.lineCap = "butt"; - radius = this.radius * this.options.radiusScale; - if (this.options.staticLabels) { - this.renderStaticLabels(this.options.staticLabels, w, h, radius); - } - if (this.options.staticZones) { - this.ctx.save(); - this.ctx.translate(w, h); - this.ctx.lineWidth = this.lineWidth; - ref = this.options.staticZones; - for (j = 0, len = ref.length; j < len; j++) { - zone = ref[j]; - min = zone.min; - if (this.options.limitMin && min < this.minValue) { - min = this.minValue; - } - max = zone.max; - if (this.options.limitMax && max > this.maxValue) { - max = this.maxValue; - } - this.ctx.strokeStyle = zone.strokeStyle; - this.ctx.beginPath(); - this.ctx.arc(0, 0, radius, this.getAngle(min), this.getAngle(max), false); - this.ctx.stroke(); - } - this.ctx.restore(); - } else { - if (this.options.customFillStyle !== void 0) { - fillStyle = this.options.customFillStyle(this); - } else if (this.percentColors !== null) { - fillStyle = this.getColorForValue(this.displayedValue, this.options.generateGradient); - } else if (this.options.colorStop !== void 0) { - if (this.options.gradientType === 0) { - fillStyle = this.ctx.createRadialGradient(w, h, 9, w, h, 70); - } else { - fillStyle = this.ctx.createLinearGradient(0, 0, w, 0); - } - fillStyle.addColorStop(0, this.options.colorStart); - fillStyle.addColorStop(1, this.options.colorStop); - } else { - fillStyle = this.options.colorStart; - } - this.ctx.strokeStyle = fillStyle; + grdFill = this.ctx.createRadialGradient(w, h, 39, w, h, 70); + grdFill.addColorStop(0, this.options.colorStart); + grdFill.addColorStop(1, this.options.colorStop); + start = this.radius - this.lineWidth / 2; + stop = this.radius + this.lineWidth / 2; + this.ctx.strokeStyle = this.options.strokeColor; this.ctx.beginPath(); - this.ctx.arc(w, h, radius, (1 + this.options.angle) * Math.PI, displayedAngle, false); + this.ctx.arc(w, h, this.radius, (1 - this.options.angle) * Math.PI, (2 + this.options.angle) * Math.PI, false); this.ctx.lineWidth = this.lineWidth; + this.ctx.lineCap = "round"; this.ctx.stroke(); - this.ctx.strokeStyle = this.options.strokeColor; + this.ctx.strokeStyle = grdFill; this.ctx.beginPath(); - this.ctx.arc(w, h, radius, displayedAngle, (2 - this.options.angle) * Math.PI, false); - this.ctx.stroke(); - } - this.ctx.translate(w, h); - ref1 = this.gp; - for (k = 0, len1 = ref1.length; k < len1; k++) { - gauge = ref1[k]; - gauge.update(true); + this.ctx.arc(w, h, this.radius, (1 - this.options.angle) * Math.PI, displayedAngle, false); + return this.ctx.stroke(); } - return this.ctx.translate(-w, -h); - }; - - return Gauge; - - })(BaseGauge); - BaseDonut = (function(superClass) { - extend(BaseDonut, superClass); + }; BaseDonut.prototype.lineWidth = 15; @@ -718,87 +793,12 @@ radiusScale: 1.0 }; - function BaseDonut(canvas) { - this.canvas = canvas; - BaseDonut.__super__.constructor.call(this); - if (typeof G_vmlCanvasManager !== 'undefined') { - this.canvas = window.G_vmlCanvasManager.initElement(this.canvas); - } - this.ctx = this.canvas.getContext('2d'); - this.setOptions(); - this.render(); - } - - BaseDonut.prototype.getAngle = function(value) { - return (1 - this.options.angle) * Math.PI + ((value - this.minValue) / (this.maxValue - this.minValue)) * ((2 + this.options.angle) - (1 - this.options.angle)) * Math.PI; - }; - - BaseDonut.prototype.setOptions = function(options) { - if (options == null) { - options = null; - } - BaseDonut.__super__.setOptions.call(this, options); - this.lineWidth = this.canvas.height * this.options.lineWidth; - this.radius = this.options.radiusScale * (this.canvas.height / 2 - this.lineWidth / 2); - return this; - }; - - BaseDonut.prototype.set = function(value) { - this.value = this.parseValue(value); - if (this.value > this.maxValue) { - if (this.options.limitMax) { - this.value = this.maxValue; - } else { - this.maxValue = this.value; - } - } else if (this.value < this.minValue) { - if (this.options.limitMin) { - this.value = this.minValue; - } else { - this.minValue = this.value; - } - } - AnimationUpdater.run(this.forceUpdate); - return this.forceUpdate = false; - }; - - BaseDonut.prototype.render = function() { - var displayedAngle, grdFill, h, start, stop, w; - displayedAngle = this.getAngle(this.displayedValue); - w = this.canvas.width / 2; - h = this.canvas.height / 2; - if (this.textField) { - this.textField.render(this); - } - grdFill = this.ctx.createRadialGradient(w, h, 39, w, h, 70); - grdFill.addColorStop(0, this.options.colorStart); - grdFill.addColorStop(1, this.options.colorStop); - start = this.radius - this.lineWidth / 2; - stop = this.radius + this.lineWidth / 2; - this.ctx.strokeStyle = this.options.strokeColor; - this.ctx.beginPath(); - this.ctx.arc(w, h, this.radius, (1 - this.options.angle) * Math.PI, (2 + this.options.angle) * Math.PI, false); - this.ctx.lineWidth = this.lineWidth; - this.ctx.lineCap = "round"; - this.ctx.stroke(); - this.ctx.strokeStyle = grdFill; - this.ctx.beginPath(); - this.ctx.arc(w, h, this.radius, (1 - this.options.angle) * Math.PI, displayedAngle, false); - return this.ctx.stroke(); - }; - return BaseDonut; - })(BaseGauge); - - Donut = (function(superClass) { - extend(Donut, superClass); - - function Donut() { - return Donut.__super__.constructor.apply(this, arguments); - } + })(); - Donut.prototype.strokeGradient = function(w, h, start, stop) { + Donut = class Donut extends BaseDonut { + strokeGradient(w, h, start, stop) { var grd; grd = this.ctx.createRadialGradient(w, h, start, w, h, stop); grd.addColorStop(0, this.options.shadowColor); @@ -806,14 +806,11 @@ grd.addColorStop(0.88, this.options._orgStrokeColor); grd.addColorStop(1, this.options.shadowColor); return grd; - }; + } - Donut.prototype.setOptions = function(options) { + setOptions(options = null) { var h, start, stop, w; - if (options == null) { - options = null; - } - Donut.__super__.setOptions.call(this, options); + super.setOptions(options); w = this.canvas.width / 2; h = this.canvas.height / 2; start = this.radius - this.lineWidth / 2; @@ -821,11 +818,9 @@ this.options._orgStrokeColor = this.options.strokeColor; this.options.strokeColor = this.strokeGradient(w, h, start, stop); return this; - }; - - return Donut; + } - })(BaseDonut); + }; window.AnimationUpdater = { elements: [], @@ -842,11 +837,12 @@ add: function(object) { return AnimationUpdater.elements.push(object); }, - run: function(force) { + run: function(force = false) { var elem, finished, isCallback, j, len, ref; - if (force == null) { - force = false; - } + // 'force' can take three values, for which these paths should be taken + // true: Force repaint of the gauges (typically on first Gauge.set) + // false: Schedule repaint (2nd or later call to Gauge.set) + // a number: It's a callback. Repaint and schedule new callback if not done. isCallback = isFinite(parseFloat(force)); if (isCallback || force === true) { finished = true; @@ -860,6 +856,7 @@ return AnimationUpdater.animId = finished ? null : requestAnimationFrame(AnimationUpdater.run); } else if (force === false) { if (AnimationUpdater.animId === !null) { + // Cancel pending callback if animId is already set to avoid overflow cancelAnimationFrame(AnimationUpdater.animId); } return AnimationUpdater.animId = requestAnimationFrame(AnimationUpdater.run); @@ -891,5 +888,3 @@ } }).call(this); - -//# sourceMappingURL=gauge.js.map diff --git a/node_modules/.bin/cake b/node_modules/.bin/cake new file mode 100644 index 0000000..8051e8c --- /dev/null +++ b/node_modules/.bin/cake @@ -0,0 +1,15 @@ +#!/bin/sh +basedir=$(dirname "$(echo "$0" | sed -e 's,\\,/,g')") + +case `uname` in + *CYGWIN*) basedir=`cygpath -w "$basedir"`;; +esac + +if [ -x "$basedir/node" ]; then + "$basedir/node" "$basedir/../coffeescript/bin/cake" "$@" + ret=$? +else + node "$basedir/../coffeescript/bin/cake" "$@" + ret=$? +fi +exit $ret diff --git a/node_modules/.bin/cake.cmd b/node_modules/.bin/cake.cmd new file mode 100644 index 0000000..9d857b6 --- /dev/null +++ b/node_modules/.bin/cake.cmd @@ -0,0 +1,7 @@ +@IF EXIST "%~dp0\node.exe" ( + "%~dp0\node.exe" "%~dp0\..\coffeescript\bin\cake" %* +) ELSE ( + @SETLOCAL + @SET PATHEXT=%PATHEXT:;.JS;=;% + node "%~dp0\..\coffeescript\bin\cake" %* +) \ No newline at end of file diff --git a/node_modules/.bin/coffee b/node_modules/.bin/coffee new file mode 100644 index 0000000..57082f8 --- /dev/null +++ b/node_modules/.bin/coffee @@ -0,0 +1,15 @@ +#!/bin/sh +basedir=$(dirname "$(echo "$0" | sed -e 's,\\,/,g')") + +case `uname` in + *CYGWIN*) basedir=`cygpath -w "$basedir"`;; +esac + +if [ -x "$basedir/node" ]; then + "$basedir/node" "$basedir/../coffeescript/bin/coffee" "$@" + ret=$? +else + node "$basedir/../coffeescript/bin/coffee" "$@" + ret=$? +fi +exit $ret diff --git a/node_modules/.bin/coffee.cmd b/node_modules/.bin/coffee.cmd new file mode 100644 index 0000000..744913a --- /dev/null +++ b/node_modules/.bin/coffee.cmd @@ -0,0 +1,7 @@ +@IF EXIST "%~dp0\node.exe" ( + "%~dp0\node.exe" "%~dp0\..\coffeescript\bin\coffee" %* +) ELSE ( + @SETLOCAL + @SET PATHEXT=%PATHEXT:;.JS;=;% + node "%~dp0\..\coffeescript\bin\coffee" %* +) \ No newline at end of file diff --git a/node_modules/coffeescript/LICENSE b/node_modules/coffeescript/LICENSE new file mode 100644 index 0000000..2b8b228 --- /dev/null +++ b/node_modules/coffeescript/LICENSE @@ -0,0 +1,22 @@ +Copyright (c) 2009-2017 Jeremy Ashkenas + +Permission is hereby granted, free of charge, to any person +obtaining a copy of this software and associated documentation +files (the "Software"), to deal in the Software without +restriction, including without limitation the rights to use, +copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the +Software is furnished to do so, subject to the following +conditions: + +The above copyright notice and this permission notice shall be +included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES +OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT +HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, +WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR +OTHER DEALINGS IN THE SOFTWARE. diff --git a/node_modules/coffeescript/README.md b/node_modules/coffeescript/README.md new file mode 100644 index 0000000..cded313 --- /dev/null +++ b/node_modules/coffeescript/README.md @@ -0,0 +1,62 @@ + @@@@@@@ @@@@ @@@@@ + { @@@@@@@@@@ @@@ @@@ + } } { @@@@ @@ @@@ @@@ + { { } } @@@@ @@@@@@@ @@@ @@@ @@@@@@ @@@@@@ + } }{ { @@@@ @@@ @@ @@@@@ @@@@@@ @@@ @@ @@@@ @@ + { }{ } } @@@@ @@@@ @@ @@@ @@@ @@@ @@@ @@@ @@@ + { }{ }{ { } @@@@ @@@@ @@ @@@ @@@ @@@@@@@@ @@@@@@@@ + { { } { } { } } @@@@@ @@@@ @@ @@@ @@@ @@@ @@@ + { } { } { } @@@@@@@@@@ @@@@@@@@ @@@ @@@ @@@@@@@@ @@@@@@@@ + @@@@@@ { } { } @@@@@@@ @@@@@ @@@ @@@ @@@@@ @@@@@ + @@@@@@@@@@@@@@@@@@@@@@@@@@@@ @@@ @@@ + @@ @@@@@@@@@@@@@@@@@@@@@@@@@@ @@@@@@ @@@ @@@ + @@ @@@@@@@@@@@@@@@@@@@@@@@@ @@@@ @@ @@@ @@@@ + @@@ @@@@@@@@@@@@@@@@@@@@@ @@@@ @@@ @@ @@@@ + @@@ @@@@@@@@@@@@@@@@@@ @@@@@ @@@@@ @@ @@ @@@ @@@@@@@ @@@@@ + @@@ @@@@@@@@@@@@@@@@ @@@@@ @@@ @@@ @@@@@@@@ @@@@ @@@@ @@@@@@@ + @@@@@@@@@@@@@@ @@@@@ @@@ @@@@ @@@@ @@@ @@@ @@@ + @@@@@ @@@@ @@@@ @@@@ @@@@ @@@@ @@@@ @@@@ + @@@ @@@@ @@@ @@@@ @@@@ @@@ @@@@ @@@@ + @@@ @@@@ @@@@ @@@@ @@@@ @@@@ @@@@ @@@@ + @@@@@@@@@ @@@@@@ @@@@ @@@@ @@@@@@@@@ @@@@ + @@@ @@@@ + @@@ + @@@ + +CoffeeScript is a little language that compiles into JavaScript. + +## Installation + +Once you have Node.js installed: + +```shell +npm install --global coffeescript +``` + +Leave off the `--global` if you don’t wish to install globally. + +## Getting Started + +Execute a script: + +```shell +coffee /path/to/script.coffee +``` + +Compile a script: + +```shell +coffee -c /path/to/script.coffee +``` + +For documentation, usage, and examples, see: http://coffeescript.org/ + +To suggest a feature or report a bug: https://github.com/jashkenas/coffeescript/issues + +If you’d like to chat, drop by #coffeescript on Freenode IRC. + +The source repository: https://github.com/jashkenas/coffeescript.git + +Changelog: http://coffeescript.org/#changelog + +Our lovely and talented contributors are listed here: https://github.com/jashkenas/coffeescript/contributors diff --git a/node_modules/coffeescript/bin/cake b/node_modules/coffeescript/bin/cake new file mode 100644 index 0000000..5694676 --- /dev/null +++ b/node_modules/coffeescript/bin/cake @@ -0,0 +1,18 @@ +#!/usr/bin/env node + +var path = require('path'); +var fs = require('fs'); + +var potentialPaths = [ + path.join(process.cwd(), 'node_modules/coffeescript/lib/coffeescript'), + path.join(process.cwd(), 'node_modules/coffeescript/lib/coffee-script'), + path.join(process.cwd(), 'node_modules/coffee-script/lib/coffee-script'), + path.join(__dirname, '../lib/coffeescript') +]; + +for (var i = 0, len = potentialPaths.length; i < len; i++) { + if (fs.existsSync(potentialPaths[i])) { + require(potentialPaths[i] + '/cake').run(); + break; + } +} diff --git a/node_modules/coffeescript/bin/coffee b/node_modules/coffeescript/bin/coffee new file mode 100644 index 0000000..9d8468b --- /dev/null +++ b/node_modules/coffeescript/bin/coffee @@ -0,0 +1,18 @@ +#!/usr/bin/env node + +var path = require('path'); +var fs = require('fs'); + +var potentialPaths = [ + path.join(process.cwd(), 'node_modules/coffeescript/lib/coffeescript'), + path.join(process.cwd(), 'node_modules/coffeescript/lib/coffee-script'), + path.join(process.cwd(), 'node_modules/coffee-script/lib/coffee-script'), + path.join(__dirname, '../lib/coffeescript') +]; + +for (var i = 0, len = potentialPaths.length; i < len; i++) { + if (fs.existsSync(potentialPaths[i])) { + require(potentialPaths[i] + '/command').run(); + break; + } +} diff --git a/node_modules/coffeescript/lib/coffeescript/browser.js b/node_modules/coffeescript/lib/coffeescript/browser.js new file mode 100644 index 0000000..468661b --- /dev/null +++ b/node_modules/coffeescript/lib/coffeescript/browser.js @@ -0,0 +1,141 @@ +// Generated by CoffeeScript 2.0.2 +(function() { + // This **Browser** compatibility layer extends core CoffeeScript functions + // to make things work smoothly when compiling code directly in the browser. + // We add support for loading remote Coffee scripts via **XHR**, and + // `text/coffeescript` script tags, source maps via data-URLs, and so on. + var CoffeeScript, compile, runScripts, + indexOf = [].indexOf; + + CoffeeScript = require('./coffeescript'); + + compile = CoffeeScript.compile; + + // Use standard JavaScript `eval` to eval code. + CoffeeScript.eval = function(code, options = {}) { + if (options.bare == null) { + options.bare = true; + } + return eval(compile(code, options)); + }; + + // Running code does not provide access to this scope. + CoffeeScript.run = function(code, options = {}) { + options.bare = true; + options.shiftLine = true; + return Function(compile(code, options))(); + }; + + // Export this more limited `CoffeeScript` than what is exported by + // `index.coffee`, which is intended for a Node environment. + module.exports = CoffeeScript; + + // If we’re not in a browser environment, we’re finished with the public API. + if (typeof window === "undefined" || window === null) { + return; + } + + // Include source maps where possible. If we’ve got a base64 encoder, a + // JSON serializer, and tools for escaping unicode characters, we’re good to go. + // Ported from https://developer.mozilla.org/en-US/docs/DOM/window.btoa + if ((typeof btoa !== "undefined" && btoa !== null) && (typeof JSON !== "undefined" && JSON !== null)) { + compile = function(code, options = {}) { + options.inlineMap = true; + return CoffeeScript.compile(code, options); + }; + } + + // Load a remote script from the current domain via XHR. + CoffeeScript.load = function(url, callback, options = {}, hold = false) { + var xhr; + options.sourceFiles = [url]; + xhr = window.ActiveXObject ? new window.ActiveXObject('Microsoft.XMLHTTP') : new window.XMLHttpRequest(); + xhr.open('GET', url, true); + if ('overrideMimeType' in xhr) { + xhr.overrideMimeType('text/plain'); + } + xhr.onreadystatechange = function() { + var param, ref; + if (xhr.readyState === 4) { + if ((ref = xhr.status) === 0 || ref === 200) { + param = [xhr.responseText, options]; + if (!hold) { + CoffeeScript.run(...param); + } + } else { + throw new Error(`Could not load ${url}`); + } + if (callback) { + return callback(param); + } + } + }; + return xhr.send(null); + }; + + // Activate CoffeeScript in the browser by having it compile and evaluate + // all script tags with a content-type of `text/coffeescript`. + // This happens on page load. + runScripts = function() { + var coffees, coffeetypes, execute, fn, i, index, j, len, s, script, scripts; + scripts = window.document.getElementsByTagName('script'); + coffeetypes = ['text/coffeescript', 'text/literate-coffeescript']; + coffees = (function() { + var j, len, ref, results; + results = []; + for (j = 0, len = scripts.length; j < len; j++) { + s = scripts[j]; + if (ref = s.type, indexOf.call(coffeetypes, ref) >= 0) { + results.push(s); + } + } + return results; + })(); + index = 0; + execute = function() { + var param; + param = coffees[index]; + if (param instanceof Array) { + CoffeeScript.run(...param); + index++; + return execute(); + } + }; + fn = function(script, i) { + var options, source; + options = { + literate: script.type === coffeetypes[1] + }; + source = script.src || script.getAttribute('data-src'); + if (source) { + options.filename = source; + return CoffeeScript.load(source, function(param) { + coffees[i] = param; + return execute(); + }, options, true); + } else { + // `options.filename` defines the filename the source map appears as + // in Developer Tools. If a script tag has an `id`, use that as the + // filename; otherwise use `coffeescript`, or `coffeescript1` etc., + // leaving the first one unnumbered for the common case that there’s + // only one CoffeeScript script block to parse. + options.filename = script.id && script.id !== '' ? script.id : `coffeescript${(i !== 0 ? i : '')}`; + options.sourceFiles = ['embedded']; + return coffees[i] = [script.innerHTML, options]; + } + }; + for (i = j = 0, len = coffees.length; j < len; i = ++j) { + script = coffees[i]; + fn(script, i); + } + return execute(); + }; + + // Listen for window load, both in decent browsers and in IE. + if (window.addEventListener) { + window.addEventListener('DOMContentLoaded', runScripts, false); + } else { + window.attachEvent('onload', runScripts); + } + +}).call(this); diff --git a/node_modules/coffeescript/lib/coffeescript/cake.js b/node_modules/coffeescript/lib/coffeescript/cake.js new file mode 100644 index 0000000..cd4e4d7 --- /dev/null +++ b/node_modules/coffeescript/lib/coffeescript/cake.js @@ -0,0 +1,135 @@ +// Generated by CoffeeScript 2.0.2 +(function() { + // `cake` is a simplified version of [Make](http://www.gnu.org/software/make/) + // ([Rake](http://rake.rubyforge.org/), [Jake](https://github.com/280north/jake)) + // for CoffeeScript. You define tasks with names and descriptions in a Cakefile, + // and can call them from the command line, or invoke them from other tasks. + + // Running `cake` with no arguments will print out a list of all the tasks in the + // current directory's Cakefile. + + // External dependencies. + var CoffeeScript, cakefileDirectory, fatalError, fs, helpers, missingTask, oparse, options, optparse, path, printTasks, switches, tasks; + + fs = require('fs'); + + path = require('path'); + + helpers = require('./helpers'); + + optparse = require('./optparse'); + + CoffeeScript = require('./'); + + // Register .coffee extension + CoffeeScript.register(); + + // Keep track of the list of defined tasks, the accepted options, and so on. + tasks = {}; + + options = {}; + + switches = []; + + oparse = null; + + // Mixin the top-level Cake functions for Cakefiles to use directly. + helpers.extend(global, { + // Define a Cake task with a short name, an optional sentence description, + // and the function to run as the action itself. + task: function(name, description, action) { + if (!action) { + [action, description] = [description, action]; + } + return tasks[name] = {name, description, action}; + }, + // Define an option that the Cakefile accepts. The parsed options hash, + // containing all of the command-line options passed, will be made available + // as the first argument to the action. + option: function(letter, flag, description) { + return switches.push([letter, flag, description]); + }, + // Invoke another task in the current Cakefile. + invoke: function(name) { + if (!tasks[name]) { + missingTask(name); + } + return tasks[name].action(options); + } + }); + + // Run `cake`. Executes all of the tasks you pass, in order. Note that Node's + // asynchrony may cause tasks to execute in a different order than you'd expect. + // If no tasks are passed, print the help screen. Keep a reference to the + // original directory name, when running Cake tasks from subdirectories. + exports.run = function() { + var arg, args, e, i, len, ref, results; + global.__originalDirname = fs.realpathSync('.'); + process.chdir(cakefileDirectory(__originalDirname)); + args = process.argv.slice(2); + CoffeeScript.run(fs.readFileSync('Cakefile').toString(), { + filename: 'Cakefile' + }); + oparse = new optparse.OptionParser(switches); + if (!args.length) { + return printTasks(); + } + try { + options = oparse.parse(args); + } catch (error) { + e = error; + return fatalError(`${e}`); + } + ref = options.arguments; + results = []; + for (i = 0, len = ref.length; i < len; i++) { + arg = ref[i]; + results.push(invoke(arg)); + } + return results; + }; + + // Display the list of Cake tasks in a format similar to `rake -T` + printTasks = function() { + var cakefilePath, desc, name, relative, spaces, task; + relative = path.relative || path.resolve; + cakefilePath = path.join(relative(__originalDirname, process.cwd()), 'Cakefile'); + console.log(`${cakefilePath} defines the following tasks:\n`); + for (name in tasks) { + task = tasks[name]; + spaces = 20 - name.length; + spaces = spaces > 0 ? Array(spaces + 1).join(' ') : ''; + desc = task.description ? `# ${task.description}` : ''; + console.log(`cake ${name}${spaces} ${desc}`); + } + if (switches.length) { + return console.log(oparse.help()); + } + }; + + // Print an error and exit when attempting to use an invalid task/option. + fatalError = function(message) { + console.error(message + '\n'); + console.log('To see a list of all tasks/options, run "cake"'); + return process.exit(1); + }; + + missingTask = function(task) { + return fatalError(`No such task: ${task}`); + }; + + // When `cake` is invoked, search in the current and all parent directories + // to find the relevant Cakefile. + cakefileDirectory = function(dir) { + var parent; + if (fs.existsSync(path.join(dir, 'Cakefile'))) { + return dir; + } + parent = path.normalize(path.join(dir, '..')); + if (parent !== dir) { + return cakefileDirectory(parent); + } + throw new Error(`Cakefile not found in ${process.cwd()}`); + }; + +}).call(this); diff --git a/node_modules/coffeescript/lib/coffeescript/coffeescript.js b/node_modules/coffeescript/lib/coffeescript/coffeescript.js new file mode 100644 index 0000000..004e2eb --- /dev/null +++ b/node_modules/coffeescript/lib/coffeescript/coffeescript.js @@ -0,0 +1,437 @@ +// Generated by CoffeeScript 2.0.2 +(function() { + // CoffeeScript can be used both on the server, as a command-line compiler based + // on Node.js/V8, or to run CoffeeScript directly in the browser. This module + // contains the main entry functions for tokenizing, parsing, and compiling + // source CoffeeScript into JavaScript. + var FILE_EXTENSIONS, Lexer, SourceMap, base64encode, checkShebangLine, compile, formatSourcePosition, getSourceMap, helpers, lexer, packageJson, parser, sourceMaps, sources, withPrettyErrors, + indexOf = [].indexOf; + + ({Lexer} = require('./lexer')); + + ({parser} = require('./parser')); + + helpers = require('./helpers'); + + SourceMap = require('./sourcemap'); + + // Require `package.json`, which is two levels above this file, as this file is + // evaluated from `lib/coffeescript`. + packageJson = require('../../package.json'); + + // The current CoffeeScript version number. + exports.VERSION = packageJson.version; + + exports.FILE_EXTENSIONS = FILE_EXTENSIONS = ['.coffee', '.litcoffee', '.coffee.md']; + + // Expose helpers for testing. + exports.helpers = helpers; + + // Function that allows for btoa in both nodejs and the browser. + base64encode = function(src) { + switch (false) { + case typeof Buffer !== 'function': + return Buffer.from(src).toString('base64'); + case typeof btoa !== 'function': + // The contents of a ` - + + + + + + + +
+ +
+
+ + + + \ No newline at end of file From 6d9f07fdfe999cd8a88069754f4c6b55a403f288 Mon Sep 17 00:00:00 2001 From: Knight2601 Date: Tue, 28 Nov 2017 12:29:06 +0000 Subject: [PATCH 14/24] moved render call which was happening before init to setOptions end --- dist/gauge.coffee | 45 +++++++++++++++++++--------------------- dist/gauge.js | 53 +++++++++++++++++++++++++++-------------------- dist/gauge.min.js | 2 +- 3 files changed, 52 insertions(+), 48 deletions(-) diff --git a/dist/gauge.coffee b/dist/gauge.coffee index cca96d5..0e3a9e4 100644 --- a/dist/gauge.coffee +++ b/dist/gauge.coffee @@ -201,7 +201,7 @@ class GaugePointer extends ValueUpdater img: null constructor: (@gauge) -> - super() + #super() if @gauge is undefined throw new Error 'The element isn\'t defined.' @ctx = @gauge.ctx @@ -233,13 +233,11 @@ class GaugePointer extends ValueUpdater endX = Math.round(@strokeWidth * Math.cos(angle + Math.PI/2)) endY = Math.round(@strokeWidth * Math.sin(angle + Math.PI/2)) - console.log(@strokeWidth, startX, startY, @length, endX, endY, @img) - - @ctx.fillStyle = @options.color @ctx.beginPath() - @ctx.arc(0, 0, @strokeWidth, 0, Math.PI*2, true) + @ctx.fillStyle = @options.color + @ctx.arc(0, 0, @strokeWidth, 0, Math.PI*2, false) @ctx.fill() - + @ctx.beginPath() @ctx.moveTo(startX, startY) @ctx.lineTo(x, y) @@ -286,7 +284,7 @@ class Gauge extends BaseGauge displayedValue: 0 lineWidth: 40 paddingTop: 0.1 - paddingBottom: 0.2 + paddingBottom: 0.1 percentColors: null, options: colorStart: "#6fadcf" @@ -318,7 +316,7 @@ class Gauge extends BaseGauge @gp = [new GaugePointer(@)] @setOptions() - @render() + setOptions: (options=null) -> super(options) @@ -331,10 +329,11 @@ class Gauge extends BaseGauge @lineWidth = @availableHeight * @options.lineWidth # .2 - .7 @radius = (@availableHeight - @lineWidth/2) / (1.0 + @extraPadding) @ctx.clearRect(0, 0, @canvas.width, @canvas.height) - # @render() + for gauge in @gp gauge.setOptions(@options.pointer) gauge.render() + @render() return @ configPercentColors: () -> @@ -460,16 +459,9 @@ class Gauge extends BaseGauge @ctx.restore() renderTicks: (ticksOptions, w, h, radius) -> - # ticks = - # {divisions: x (count of big divisions, - # subDivisions: y (count of subDivisions within a division), - # divColor: color, - # subColor: color, - # divLength: 90, - # subLength: 40 } + + #@ctx.save() - @ctx.save() - #@ctx.translate(w, h) divisionCount = ticksOptions.divisions || 0 subdivisionCount = ticksOptions.subDivisions || 0 divColor = ticksOptions.divColor || '#fff' @@ -509,18 +501,18 @@ class Gauge extends BaseGauge @ctx.stroke() currentSubDivision += subDivisions - @ctx.restore() + #@ctx.restore() render: () -> # Draw using canvas w = @canvas.width / 2 - h = @canvas.height*@paddingTop + @availableHeight - (@radius + @lineWidth/2)*@extraPadding + #h = (@canvas.height * @paddingTop + @availableHeight) - ((@radius + @lineWidth / 2) * @extraPadding) + h = (@canvas.height * @paddingTop + @availableHeight) - ((@radius + @lineWidth /2) * @extraPadding) displayedAngle = @getAngle(@displayedValue) if @textField @textField.render(@) @ctx.lineCap = "butt" - radius = @radius * @options.radiusScale if (@options.staticLabels) @renderStaticLabels(@options.staticLabels, w, h, radius) @@ -574,16 +566,21 @@ class Gauge extends BaseGauge @ctx.arc(w, h, radius, displayedAngle, (2 - @options.angle) * Math.PI, false) @ctx.stroke() - if(@options.renderTicks) + if (@options.renderTicks) @renderTicks(@options.renderTicks, w, h, radius) @ctx.restore() # Draw pointers from (w, h) - @ctx.translate(w, h) + + for gauge in @gp + @ctx.translate(w, h) gauge.update(true) + @ctx.translate(-w, -h) + + + - @ctx.translate(-w, -h) class BaseDonut extends BaseGauge lineWidth: 15 diff --git a/dist/gauge.js b/dist/gauge.js index 247a426..2076be0 100644 --- a/dist/gauge.js +++ b/dist/gauge.js @@ -321,7 +321,6 @@ function GaugePointer(gauge1) { this.gauge = gauge1; - GaugePointer.__super__.constructor.call(this); if (this.gauge === void 0) { throw new Error('The element isn\'t defined.'); } @@ -357,10 +356,9 @@ startY = Math.round(this.strokeWidth * Math.sin(angle - Math.PI / 2)); endX = Math.round(this.strokeWidth * Math.cos(angle + Math.PI / 2)); endY = Math.round(this.strokeWidth * Math.sin(angle + Math.PI / 2)); - console.log(this.strokeWidth, startX, startY, this.length, endX, endY, this.img); - this.ctx.fillStyle = this.options.color; this.ctx.beginPath(); - this.ctx.arc(0, 0, this.strokeWidth, 0, Math.PI * 2, true); + this.ctx.fillStyle = this.options.color; + this.ctx.arc(0, 0, this.strokeWidth, 0, Math.PI * 2, false); this.ctx.fill(); this.ctx.beginPath(); this.ctx.moveTo(startX, startY); @@ -435,7 +433,7 @@ Gauge.prototype.paddingTop = 0.1; - Gauge.prototype.paddingBottom = 0.2; + Gauge.prototype.paddingBottom = 0.1; Gauge.prototype.percentColors = null; @@ -472,7 +470,6 @@ this.canvas.width = w; this.gp = [new GaugePointer(this)]; this.setOptions(); - this.render(); } Gauge.prototype.setOptions = function(options) { @@ -497,6 +494,7 @@ gauge.setOptions(this.options.pointer); gauge.render(); } + this.render(); return this; }; @@ -646,8 +644,7 @@ }; Gauge.prototype.renderTicks = function(ticksOptions, w, h, radius) { - var currentDivision, currentSubDivision, divColor, divLength, divWidth, divisionCount, j, k, lineWidth, range, rangeDivisions, ref, ref1, scaleMutate, st, subColor, subDivisions, subLength, subWidth, subdivisionCount, t, tmpRadius; - this.ctx.save(); + var currentDivision, currentSubDivision, divColor, divLength, divWidth, divisionCount, j, lineWidth, range, rangeDivisions, ref, results, scaleMutate, st, subColor, subDivisions, subLength, subWidth, subdivisionCount, t, tmpRadius; divisionCount = ticksOptions.divisions || 0; subdivisionCount = ticksOptions.subDivisions || 0; divColor = ticksOptions.divColor || '#fff'; @@ -662,6 +659,7 @@ lineWidth = range / 400; divWidth = lineWidth * (ticksOptions.divWidth || 1); subWidth = lineWidth * (ticksOptions.subWidth || 1); + results = []; for (t = j = 0, ref = divisionCount + 1; j < ref; t = j += 1) { this.ctx.lineWidth = this.lineWidth * divLength; scaleMutate = (this.lineWidth / 2) * (1 - divLength); @@ -673,25 +671,32 @@ currentSubDivision = currentDivision + subDivisions; currentDivision += rangeDivisions; if (t !== ticksOptions.divisions && subdivisionCount > 0) { - for (st = k = 0, ref1 = subdivisionCount - 1; k < ref1; st = k += 1) { - this.ctx.lineWidth = this.lineWidth * subLength; - scaleMutate = (this.lineWidth / 2) * (1 - subLength); - tmpRadius = (this.radius * this.options.radiusScale) + scaleMutate; - this.ctx.strokeStyle = subColor; - this.ctx.beginPath(); - this.ctx.arc(0, 0, tmpRadius, this.getAngle(currentSubDivision - subWidth), this.getAngle(currentSubDivision + subWidth), false); - this.ctx.stroke(); - currentSubDivision += subDivisions; - } + results.push((function() { + var k, ref1, results1; + results1 = []; + for (st = k = 0, ref1 = subdivisionCount - 1; k < ref1; st = k += 1) { + this.ctx.lineWidth = this.lineWidth * subLength; + scaleMutate = (this.lineWidth / 2) * (1 - subLength); + tmpRadius = (this.radius * this.options.radiusScale) + scaleMutate; + this.ctx.strokeStyle = subColor; + this.ctx.beginPath(); + this.ctx.arc(0, 0, tmpRadius, this.getAngle(currentSubDivision - subWidth), this.getAngle(currentSubDivision + subWidth), false); + this.ctx.stroke(); + results1.push(currentSubDivision += subDivisions); + } + return results1; + }).call(this)); + } else { + results.push(void 0); } } - return this.ctx.restore(); + return results; }; Gauge.prototype.render = function() { - var displayedAngle, fillStyle, gauge, h, j, k, len, len1, max, min, radius, ref, ref1, scaleMutate, tmpRadius, w, zone; + var displayedAngle, fillStyle, gauge, h, j, k, len, len1, max, min, radius, ref, ref1, results, scaleMutate, tmpRadius, w, zone; w = this.canvas.width / 2; - h = this.canvas.height * this.paddingTop + this.availableHeight - (this.radius + this.lineWidth / 2) * this.extraPadding; + h = (this.canvas.height * this.paddingTop + this.availableHeight) - ((this.radius + this.lineWidth / 2) * this.extraPadding); displayedAngle = this.getAngle(this.displayedValue); if (this.textField) { this.textField.render(this); @@ -757,13 +762,15 @@ this.renderTicks(this.options.renderTicks, w, h, radius); } this.ctx.restore(); - this.ctx.translate(w, h); ref1 = this.gp; + results = []; for (k = 0, len1 = ref1.length; k < len1; k++) { gauge = ref1[k]; + this.ctx.translate(w, h); gauge.update(true); + results.push(this.ctx.translate(-w, -h)); } - return this.ctx.translate(-w, -h); + return results; }; return Gauge; diff --git a/dist/gauge.min.js b/dist/gauge.min.js index d9b76bf..710bbfb 100644 --- a/dist/gauge.min.js +++ b/dist/gauge.min.js @@ -1 +1 @@ -(function(){var t,i,e,s,n,o,a,h,r,l,p,c,u,d=[].slice,g={}.hasOwnProperty,m=function(t,i){function e(){this.constructor=t}for(var s in i)g.call(i,s)&&(t[s]=i[s]);return e.prototype=i.prototype,t.prototype=new e,t.__super__=i.prototype,t};!function(){var t,i,e,s,n,o,a;for(a=["ms","moz","webkit","o"],e=0,n=a.length;e1&&(n="."+e[1]),i=/(\d+)(\d{3})/;i.test(s);)s=s.replace(i,"$1,$2");return s+n},l=function(t){return"#"===t.charAt(0)?t.substring(1,7):t},h=function(){function t(t,i){null==t&&(t=!0),this.clear=null==i||i,t&&AnimationUpdater.add(this)}return t.prototype.animationSpeed=32,t.prototype.update=function(t){var i;return null==t&&(t=!1),!(!t&&this.displayedValue===this.value)&&(this.ctx&&this.clear&&this.ctx.clearRect(0,0,this.canvas.width,this.canvas.height),i=this.value-this.displayedValue,Math.abs(i/this.animationSpeed)<=.001?this.displayedValue=this.value:this.displayedValue=this.displayedValue+i/this.animationSpeed,this.render(),!0)},t}(),e=function(t){function i(){return i.__super__.constructor.apply(this,arguments)}return m(i,t),i.prototype.displayScale=1,i.prototype.forceUpdate=!0,i.prototype.setTextField=function(t,i){return this.textField=t instanceof a?t:new a(t,i)},i.prototype.setMinValue=function(t,i){var e,s,n,o,a;if(this.minValue=t,null==i&&(i=!0),i){for(this.displayedValue=this.minValue,o=this.gp||[],a=[],s=0,n=o.length;s.5&&(this.options.angle=.5),this.configDisplayScale(),this},i.prototype.configDisplayScale=function(){var t,i,e,s,n;return s=this.displayScale,!1===this.options.highDpiSupport?delete this.displayScale:(i=window.devicePixelRatio||1,t=this.ctx.webkitBackingStorePixelRatio||this.ctx.mozBackingStorePixelRatio||this.ctx.msBackingStorePixelRatio||this.ctx.oBackingStorePixelRatio||this.ctx.backingStorePixelRatio||1,this.displayScale=i/t),this.displayScale!==s&&(n=this.canvas.G__width||this.canvas.width,e=this.canvas.G__height||this.canvas.height,this.canvas.width=n*this.displayScale,this.canvas.height=e*this.displayScale,this.canvas.style.width=n+"px",this.canvas.style.height=e+"px",this.canvas.G__width=n,this.canvas.G__height=e),this},i.prototype.parseValue=function(t){return t=parseFloat(t)||Number(t),isFinite(t)?t:0},i}(h),a=function(){function t(t,i){this.el=t,this.fractionDigits=i}return t.prototype.render=function(t){return this.el.innerHTML=p(t.displayedValue,this.fractionDigits)},t}(),t=function(t){function i(t,e){if(this.elem=t,this.text=null!=e&&e,i.__super__.constructor.call(this),void 0===this.elem)throw new Error("The element isn't defined.");this.value=1*this.elem.innerHTML,this.text&&(this.value=0)}return m(i,t),i.prototype.displayedValue=0,i.prototype.value=0,i.prototype.setVal=function(t){return this.value=1*t},i.prototype.render=function(){var t;return t=this.text?u(this.displayedValue.toFixed(0)):r(p(this.displayedValue)),this.elem.innerHTML=t},i}(h),o=function(t){function i(t){if(this.gauge=t,i.__super__.constructor.call(this),void 0===this.gauge)throw new Error("The element isn't defined.");this.ctx=this.gauge.ctx,this.canvas=this.gauge.canvas,i.__super__.constructor.call(this,!1,!1),this.setOptions()}return m(i,t),i.prototype.displayedValue=0,i.prototype.value=0,i.prototype.options={strokeWidth:.035,length:.1,color:"#000000",iconPath:null,iconScale:1,iconAngle:0},i.prototype.img=null,i.prototype.setOptions=function(t){if(null==t&&(t=null),this.options=c(this.options,t),this.length=2*this.gauge.radius*this.gauge.options.radiusScale*this.options.length,this.strokeWidth=this.canvas.height*this.options.strokeWidth,this.maxValue=this.gauge.maxValue,this.minValue=this.gauge.minValue,this.animationSpeed=this.gauge.animationSpeed,this.options.angle=this.gauge.options.angle,this.options.iconPath)return this.img=new Image,this.img.src=this.options.iconPath},i.prototype.render=function(){var t,i,e,s,n,o,a,h,r;if(t=this.gauge.getAngle.call(this,this.displayedValue),h=Math.round(this.length*Math.cos(t)),r=Math.round(this.length*Math.sin(t)),o=Math.round(this.strokeWidth*Math.cos(t-Math.PI/2)),a=Math.round(this.strokeWidth*Math.sin(t-Math.PI/2)),i=Math.round(this.strokeWidth*Math.cos(t+Math.PI/2)),e=Math.round(this.strokeWidth*Math.sin(t+Math.PI/2)),console.log(this.strokeWidth,o,a,this.length,i,e,this.img),this.ctx.fillStyle=this.options.color,this.ctx.beginPath(),this.ctx.arc(0,0,this.strokeWidth,0,2*Math.PI,!0),this.ctx.fill(),this.ctx.beginPath(),this.ctx.moveTo(o,a),this.ctx.lineTo(h,r),this.ctx.lineTo(i,e),this.ctx.fill(),this.img)return s=Math.round(this.img.width*this.options.iconScale),n=Math.round(this.img.height*this.options.iconScale),this.ctx.save(),this.ctx.translate(h,r),this.ctx.rotate(t+Math.PI/180*(90+this.options.iconAngle)),this.ctx.drawImage(this.img,-s/2,-n/2,s,n),this.ctx.restore()},i}(h),function(){function t(t){this.elem=t}t.prototype.updateValues=function(t){return this.value=t[0],this.maxValue=t[1],this.avgValue=t[2],this.render()},t.prototype.render=function(){var t,i;return this.textField&&this.textField.text(p(this.value)),0===this.maxValue&&(this.maxValue=2*this.avgValue),i=this.value/this.maxValue*100,t=this.avgValue/this.maxValue*100,$(".bar-value",this.elem).css({width:i+"%"}),$(".typical-value",this.elem).css({width:t+"%"})}}(),n=function(t){function i(t){var e,s;this.canvas=t,i.__super__.constructor.call(this),this.percentColors=null,"undefined"!=typeof G_vmlCanvasManager&&(this.canvas=window.G_vmlCanvasManager.initElement(this.canvas)),this.ctx=this.canvas.getContext("2d"),e=this.canvas.clientHeight,s=this.canvas.clientWidth,this.canvas.height=e,this.canvas.width=s,this.gp=[new o(this)],this.setOptions(),this.render()}return m(i,t),i.prototype.elem=null,i.prototype.value=[20],i.prototype.maxValue=80,i.prototype.minValue=0,i.prototype.displayedAngle=0,i.prototype.displayedValue=0,i.prototype.lineWidth=40,i.prototype.paddingTop=.1,i.prototype.paddingBottom=.2,i.prototype.percentColors=null,i.prototype.options={colorStart:"#6fadcf",colorStop:void 0,gradientType:0,strokeColor:"#e0e0e0",pointer:{length:.8,strokeWidth:.035,iconScale:1},angle:.15,lineWidth:.44,radiusScale:1,fontSize:40,limitMax:!1,limitMin:!1},i.prototype.setOptions=function(t){var e,s,n,o,a;for(null==t&&(t=null),i.__super__.setOptions.call(this,t),this.configPercentColors(),this.extraPadding=0,this.options.angle<0&&(o=Math.PI*(1+this.options.angle),this.extraPadding=Math.sin(o)),this.availableHeight=this.canvas.height*(1-this.paddingTop-this.paddingBottom),this.lineWidth=this.availableHeight*this.options.lineWidth,this.radius=(this.availableHeight-this.lineWidth/2)/(1+this.extraPadding),this.ctx.clearRect(0,0,this.canvas.width,this.canvas.height),a=this.gp,s=0,n=a.length;s=n;e=0<=n?++s:--s)a=parseInt(l(this.options.percentColors[e][1]).substring(0,2),16),i=parseInt(l(this.options.percentColors[e][1]).substring(2,4),16),t=parseInt(l(this.options.percentColors[e][1]).substring(4,6),16),o.push(this.percentColors[e]={pct:this.options.percentColors[e][0],color:{r:a,g:i,b:t}});return o}},i.prototype.set=function(t){var i,e,s,n,a,h,r,l,p;for(t instanceof Array||(t=[t]),e=s=0,r=t.length-1;0<=r?s<=r:s>=r;e=0<=r?++s:--s)t[e]=this.parseValue(t[e]);if(t.length>this.gp.length)for(e=n=0,l=t.length-this.gp.length;0<=l?nl;e=0<=l?++n:--n)i=new o(this),i.setOptions(this.options.pointer),this.gp.push(i);else t.lengththis.maxValue?this.options.limitMax?p=this.maxValue:this.maxValue=p+1:p=h;n=0<=h?++o:--o)if(t<=this.percentColors[n].pct){!0===i?(r=this.percentColors[n-1]||this.percentColors[0],s=this.percentColors[n],a=(t-r.pct)/(s.pct-r.pct),e={r:Math.floor(r.color.r*(1-a)+s.color.r*a),g:Math.floor(r.color.g*(1-a)+s.color.g*a),b:Math.floor(r.color.b*(1-a)+s.color.b*a)}):e=this.percentColors[n].color;break}return"rgb("+[e.r,e.g,e.b].join(",")+")"},i.prototype.getColorForValue=function(t,i){var e;return e=(t-this.minValue)/(this.maxValue-this.minValue),this.getColorForPercentage(e,i)},i.prototype.renderStaticLabels=function(t,i,e,s){var n,o,a,h,r,l,c,u,d,g;for(this.ctx.save(),this.ctx.translate(i,e),n=t.font||"10px Times",l=/\d+\.?\d?/,r=n.match(l)[0],u=n.slice(r.length),o=parseFloat(r)*this.displayScale,this.ctx.font=o+u,this.ctx.fillStyle=t.color||"#000000",this.ctx.textBaseline="bottom",this.ctx.textAlign="center",c=t.labels,a=0,h=c.length;a=this.minValue)&&(!this.options.limitMax||g<=this.maxValue)&&(n=g.font||t.font,r=n.match(l)[0],u=n.slice(r.length),o=parseFloat(r)*this.displayScale,this.ctx.font=o+u,d=this.getAngle(g.label)-3*Math.PI/2,this.ctx.rotate(d),this.ctx.fillText(p(g.label,t.fractionDigits),0,-s-this.lineWidth/2),this.ctx.rotate(-d)):(!this.options.limitMin||g>=this.minValue)&&(!this.options.limitMax||g<=this.maxValue)&&(d=this.getAngle(g)-3*Math.PI/2,this.ctx.rotate(d),this.ctx.fillText(p(g,t.fractionDigits),0,-s-this.lineWidth/2),this.ctx.rotate(-d));return this.ctx.restore()},i.prototype.renderTicks=function(t,i,e,s){var n,o,a,h,r,l,p,c,u,d,g,m,x,f,v,y,V,w,S,M,C;for(this.ctx.save(),l=t.divisions||0,S=t.subDivisions||0,a=t.divColor||"#fff",v=t.subColor||"#fff",h=t.divLength||.7,V=t.subLength||.2,d=parseFloat(this.maxValue)-parseFloat(this.minValue),g=parseFloat(d)/parseFloat(t.divisions),y=parseFloat(g)/parseFloat(t.subDivisions),n=parseFloat(this.minValue),o=0+y,u=d/400,r=u*(t.divWidth||1),w=u*(t.subWidth||1),M=p=0,m=l+1;p0)for(c=0,x=S-1;cthis.maxValue&&(r=this.maxValue),g=this.radius,x.height&&(this.ctx.lineWidth=this.lineWidth*x.height,d=this.lineWidth/2*(x.offset||1-x.height),g=this.radius*this.options.radiusScale+d),this.ctx.strokeStyle=x.strokeStyle,this.ctx.beginPath(),this.ctx.arc(0,0,g,this.getAngle(l),this.getAngle(r),!1),this.ctx.stroke();else void 0!==this.options.customFillStyle?i=this.options.customFillStyle(this):null!==this.percentColors?i=this.getColorForValue(this.displayedValue,this.options.generateGradient):void 0!==this.options.colorStop?(i=0===this.options.gradientType?this.ctx.createRadialGradient(m,s,9,m,s,70):this.ctx.createLinearGradient(0,0,m,0),i.addColorStop(0,this.options.colorStart),i.addColorStop(1,this.options.colorStop)):i=this.options.colorStart,this.ctx.strokeStyle=i,this.ctx.beginPath(),this.ctx.arc(m,s,p,(1+this.options.angle)*Math.PI,t,!1),this.ctx.lineWidth=this.lineWidth,this.ctx.stroke(),this.ctx.strokeStyle=this.options.strokeColor,this.ctx.beginPath(),this.ctx.arc(m,s,p,t,(2-this.options.angle)*Math.PI,!1),this.ctx.stroke();for(this.options.renderTicks&&this.renderTicks(this.options.renderTicks,m,s,p),this.ctx.restore(),this.ctx.translate(m,s),u=this.gp,o=0,h=u.length;othis.maxValue?this.options.limitMax?this.value=this.maxValue:this.maxValue=this.value:this.value1&&(n="."+e[1]),i=/(\d+)(\d{3})/;i.test(s);)s=s.replace(i,"$1,$2");return s+n},l=function(t){return"#"===t.charAt(0)?t.substring(1,7):t},h=function(){function t(t,i){null==t&&(t=!0),this.clear=null==i||i,t&&AnimationUpdater.add(this)}return t.prototype.animationSpeed=32,t.prototype.update=function(t){var i;return null==t&&(t=!1),!(!t&&this.displayedValue===this.value)&&(this.ctx&&this.clear&&this.ctx.clearRect(0,0,this.canvas.width,this.canvas.height),i=this.value-this.displayedValue,Math.abs(i/this.animationSpeed)<=.001?this.displayedValue=this.value:this.displayedValue=this.displayedValue+i/this.animationSpeed,this.render(),!0)},t}(),e=function(t){function i(){return i.__super__.constructor.apply(this,arguments)}return m(i,t),i.prototype.displayScale=1,i.prototype.forceUpdate=!0,i.prototype.setTextField=function(t,i){return this.textField=t instanceof a?t:new a(t,i)},i.prototype.setMinValue=function(t,i){var e,s,n,o,a;if(this.minValue=t,null==i&&(i=!0),i){for(this.displayedValue=this.minValue,o=this.gp||[],a=[],s=0,n=o.length;s.5&&(this.options.angle=.5),this.configDisplayScale(),this},i.prototype.configDisplayScale=function(){var t,i,e,s,n;return s=this.displayScale,!1===this.options.highDpiSupport?delete this.displayScale:(i=window.devicePixelRatio||1,t=this.ctx.webkitBackingStorePixelRatio||this.ctx.mozBackingStorePixelRatio||this.ctx.msBackingStorePixelRatio||this.ctx.oBackingStorePixelRatio||this.ctx.backingStorePixelRatio||1,this.displayScale=i/t),this.displayScale!==s&&(n=this.canvas.G__width||this.canvas.width,e=this.canvas.G__height||this.canvas.height,this.canvas.width=n*this.displayScale,this.canvas.height=e*this.displayScale,this.canvas.style.width=n+"px",this.canvas.style.height=e+"px",this.canvas.G__width=n,this.canvas.G__height=e),this},i.prototype.parseValue=function(t){return t=parseFloat(t)||Number(t),isFinite(t)?t:0},i}(h),a=function(){function t(t,i){this.el=t,this.fractionDigits=i}return t.prototype.render=function(t){return this.el.innerHTML=p(t.displayedValue,this.fractionDigits)},t}(),t=function(t){function i(t,e){if(this.elem=t,this.text=null!=e&&e,i.__super__.constructor.call(this),void 0===this.elem)throw new Error("The element isn't defined.");this.value=1*this.elem.innerHTML,this.text&&(this.value=0)}return m(i,t),i.prototype.displayedValue=0,i.prototype.value=0,i.prototype.setVal=function(t){return this.value=1*t},i.prototype.render=function(){var t;return t=this.text?u(this.displayedValue.toFixed(0)):r(p(this.displayedValue)),this.elem.innerHTML=t},i}(h),o=function(t){function i(t){if(this.gauge=t,void 0===this.gauge)throw new Error("The element isn't defined.");this.ctx=this.gauge.ctx,this.canvas=this.gauge.canvas,i.__super__.constructor.call(this,!1,!1),this.setOptions()}return m(i,t),i.prototype.displayedValue=0,i.prototype.value=0,i.prototype.options={strokeWidth:.035,length:.1,color:"#000000",iconPath:null,iconScale:1,iconAngle:0},i.prototype.img=null,i.prototype.setOptions=function(t){if(null==t&&(t=null),this.options=c(this.options,t),this.length=2*this.gauge.radius*this.gauge.options.radiusScale*this.options.length,this.strokeWidth=this.canvas.height*this.options.strokeWidth,this.maxValue=this.gauge.maxValue,this.minValue=this.gauge.minValue,this.animationSpeed=this.gauge.animationSpeed,this.options.angle=this.gauge.options.angle,this.options.iconPath)return this.img=new Image,this.img.src=this.options.iconPath},i.prototype.render=function(){var t,i,e,s,n,o,a,h,r;if(t=this.gauge.getAngle.call(this,this.displayedValue),h=Math.round(this.length*Math.cos(t)),r=Math.round(this.length*Math.sin(t)),o=Math.round(this.strokeWidth*Math.cos(t-Math.PI/2)),a=Math.round(this.strokeWidth*Math.sin(t-Math.PI/2)),i=Math.round(this.strokeWidth*Math.cos(t+Math.PI/2)),e=Math.round(this.strokeWidth*Math.sin(t+Math.PI/2)),this.ctx.beginPath(),this.ctx.fillStyle=this.options.color,this.ctx.arc(0,0,this.strokeWidth,0,2*Math.PI,!1),this.ctx.fill(),this.ctx.beginPath(),this.ctx.moveTo(o,a),this.ctx.lineTo(h,r),this.ctx.lineTo(i,e),this.ctx.fill(),this.img)return s=Math.round(this.img.width*this.options.iconScale),n=Math.round(this.img.height*this.options.iconScale),this.ctx.save(),this.ctx.translate(h,r),this.ctx.rotate(t+Math.PI/180*(90+this.options.iconAngle)),this.ctx.drawImage(this.img,-s/2,-n/2,s,n),this.ctx.restore()},i}(h),function(){function t(t){this.elem=t}t.prototype.updateValues=function(t){return this.value=t[0],this.maxValue=t[1],this.avgValue=t[2],this.render()},t.prototype.render=function(){var t,i;return this.textField&&this.textField.text(p(this.value)),0===this.maxValue&&(this.maxValue=2*this.avgValue),i=this.value/this.maxValue*100,t=this.avgValue/this.maxValue*100,$(".bar-value",this.elem).css({width:i+"%"}),$(".typical-value",this.elem).css({width:t+"%"})}}(),n=function(t){function i(t){var e,s;this.canvas=t,i.__super__.constructor.call(this),this.percentColors=null,"undefined"!=typeof G_vmlCanvasManager&&(this.canvas=window.G_vmlCanvasManager.initElement(this.canvas)),this.ctx=this.canvas.getContext("2d"),e=this.canvas.clientHeight,s=this.canvas.clientWidth,this.canvas.height=e,this.canvas.width=s,this.gp=[new o(this)],this.setOptions()}return m(i,t),i.prototype.elem=null,i.prototype.value=[20],i.prototype.maxValue=80,i.prototype.minValue=0,i.prototype.displayedAngle=0,i.prototype.displayedValue=0,i.prototype.lineWidth=40,i.prototype.paddingTop=.1,i.prototype.paddingBottom=.1,i.prototype.percentColors=null,i.prototype.options={colorStart:"#6fadcf",colorStop:void 0,gradientType:0,strokeColor:"#e0e0e0",pointer:{length:.8,strokeWidth:.035,iconScale:1},angle:.15,lineWidth:.44,radiusScale:1,fontSize:40,limitMax:!1,limitMin:!1},i.prototype.setOptions=function(t){var e,s,n,o,a;for(null==t&&(t=null),i.__super__.setOptions.call(this,t),this.configPercentColors(),this.extraPadding=0,this.options.angle<0&&(o=Math.PI*(1+this.options.angle),this.extraPadding=Math.sin(o)),this.availableHeight=this.canvas.height*(1-this.paddingTop-this.paddingBottom),this.lineWidth=this.availableHeight*this.options.lineWidth,this.radius=(this.availableHeight-this.lineWidth/2)/(1+this.extraPadding),this.ctx.clearRect(0,0,this.canvas.width,this.canvas.height),a=this.gp,s=0,n=a.length;s=n;e=0<=n?++s:--s)a=parseInt(l(this.options.percentColors[e][1]).substring(0,2),16),i=parseInt(l(this.options.percentColors[e][1]).substring(2,4),16),t=parseInt(l(this.options.percentColors[e][1]).substring(4,6),16),o.push(this.percentColors[e]={pct:this.options.percentColors[e][0],color:{r:a,g:i,b:t}});return o}},i.prototype.set=function(t){var i,e,s,n,a,h,r,l,p;for(t instanceof Array||(t=[t]),e=s=0,r=t.length-1;0<=r?s<=r:s>=r;e=0<=r?++s:--s)t[e]=this.parseValue(t[e]);if(t.length>this.gp.length)for(e=n=0,l=t.length-this.gp.length;0<=l?nl;e=0<=l?++n:--n)i=new o(this),i.setOptions(this.options.pointer),this.gp.push(i);else t.lengththis.maxValue?this.options.limitMax?p=this.maxValue:this.maxValue=p+1:p=h;n=0<=h?++o:--o)if(t<=this.percentColors[n].pct){!0===i?(r=this.percentColors[n-1]||this.percentColors[0],s=this.percentColors[n],a=(t-r.pct)/(s.pct-r.pct),e={r:Math.floor(r.color.r*(1-a)+s.color.r*a),g:Math.floor(r.color.g*(1-a)+s.color.g*a),b:Math.floor(r.color.b*(1-a)+s.color.b*a)}):e=this.percentColors[n].color;break}return"rgb("+[e.r,e.g,e.b].join(",")+")"},i.prototype.getColorForValue=function(t,i){var e;return e=(t-this.minValue)/(this.maxValue-this.minValue),this.getColorForPercentage(e,i)},i.prototype.renderStaticLabels=function(t,i,e,s){var n,o,a,h,r,l,c,u,d,g;for(this.ctx.save(),this.ctx.translate(i,e),n=t.font||"10px Times",l=/\d+\.?\d?/,r=n.match(l)[0],u=n.slice(r.length),o=parseFloat(r)*this.displayScale,this.ctx.font=o+u,this.ctx.fillStyle=t.color||"#000000",this.ctx.textBaseline="bottom",this.ctx.textAlign="center",c=t.labels,a=0,h=c.length;a=this.minValue)&&(!this.options.limitMax||g<=this.maxValue)&&(n=g.font||t.font,r=n.match(l)[0],u=n.slice(r.length),o=parseFloat(r)*this.displayScale,this.ctx.font=o+u,d=this.getAngle(g.label)-3*Math.PI/2,this.ctx.rotate(d),this.ctx.fillText(p(g.label,t.fractionDigits),0,-s-this.lineWidth/2),this.ctx.rotate(-d)):(!this.options.limitMin||g>=this.minValue)&&(!this.options.limitMax||g<=this.maxValue)&&(d=this.getAngle(g)-3*Math.PI/2,this.ctx.rotate(d),this.ctx.fillText(p(g,t.fractionDigits),0,-s-this.lineWidth/2),this.ctx.rotate(-d));return this.ctx.restore()},i.prototype.renderTicks=function(t,i,e,s){var n,o,a,h,r,l,p,c,u,d,g,m,x,f,v,y,V,w,S,M,C;for(l=t.divisions||0,S=t.subDivisions||0,a=t.divColor||"#fff",v=t.subColor||"#fff",h=t.divLength||.7,V=t.subLength||.2,u=parseFloat(this.maxValue)-parseFloat(this.minValue),d=parseFloat(u)/parseFloat(t.divisions),y=parseFloat(d)/parseFloat(t.subDivisions),n=parseFloat(this.minValue),o=0+y,c=u/400,r=c*(t.divWidth||1),w=c*(t.subWidth||1),m=[],M=p=0,g=l+1;p0?m.push(function(){var t,i,e;for(e=[],f=t=0,i=S-1;tthis.maxValue&&(r=this.maxValue),m=this.radius,f.height&&(this.ctx.lineWidth=this.lineWidth*f.height,g=this.lineWidth/2*(f.offset||1-f.height),m=this.radius*this.options.radiusScale+g),this.ctx.strokeStyle=f.strokeStyle,this.ctx.beginPath(),this.ctx.arc(0,0,m,this.getAngle(l),this.getAngle(r),!1),this.ctx.stroke();else void 0!==this.options.customFillStyle?i=this.options.customFillStyle(this):null!==this.percentColors?i=this.getColorForValue(this.displayedValue,this.options.generateGradient):void 0!==this.options.colorStop?(i=0===this.options.gradientType?this.ctx.createRadialGradient(x,s,9,x,s,70):this.ctx.createLinearGradient(0,0,x,0),i.addColorStop(0,this.options.colorStart),i.addColorStop(1,this.options.colorStop)):i=this.options.colorStart,this.ctx.strokeStyle=i,this.ctx.beginPath(),this.ctx.arc(x,s,p,(1+this.options.angle)*Math.PI,t,!1),this.ctx.lineWidth=this.lineWidth,this.ctx.stroke(),this.ctx.strokeStyle=this.options.strokeColor,this.ctx.beginPath(),this.ctx.arc(x,s,p,t,(2-this.options.angle)*Math.PI,!1),this.ctx.stroke();for(this.options.renderTicks&&this.renderTicks(this.options.renderTicks,x,s,p),this.ctx.restore(),u=this.gp,d=[],o=0,h=u.length;othis.maxValue?this.options.limitMax?this.value=this.maxValue:this.maxValue=this.value:this.value Date: Tue, 28 Nov 2017 12:40:34 +0000 Subject: [PATCH 15/24] fixed index fdSlider redraw --- index.html | 1 + 1 file changed, 1 insertion(+) diff --git a/index.html b/index.html index 4f69dae..963f7b6 100644 --- a/index.html +++ b/index.html @@ -371,6 +371,7 @@

Contact

$('#divisionsCbx').click(function(){ $('.subDivisions').toggle(); + fdSlider.redrawAll(); }) function update() { From a5b3396db9802ba26a2e5ecb0e7350284b4a7c21 Mon Sep 17 00:00:00 2001 From: Knight2601 Date: Tue, 28 Nov 2017 16:06:55 +0000 Subject: [PATCH 16/24] update, fix all --- assets/main.css | 15 +++++++ bower.json | 2 +- dist/gauge.coffee | 93 +++++++++++++++++++++--------------------- dist/gauge.js | 100 +++++++++++++++++++++++----------------------- dist/gauge.min.js | 2 +- index.html | 31 +++++++++----- package.json | 2 +- 7 files changed, 135 insertions(+), 110 deletions(-) diff --git a/assets/main.css b/assets/main.css index 0059180..f504116 100755 --- a/assets/main.css +++ b/assets/main.css @@ -46,6 +46,21 @@ ul { bottom: 30px; right: 30px; } +.subDivisions { + background-color: rgba(255,255,255,0.2); + padding: 0.2em; + box-shadow: 0 2px 5px rgba(0,0,0,0.1); +} + +.subDivisions label { + width: 150px !important; +} +.subDivisions > span.fd-slider { + width: 80px !important; +} +.subDivisions > input { + width: 80px !important; +} a { color: #333; } diff --git a/bower.json b/bower.json index f0495f1..7dccd9c 100644 --- a/bower.json +++ b/bower.json @@ -1,6 +1,6 @@ { "name": "gauge.js", - "version": "1.3.5", + "version": "1.3.6", "main": [ "dist/gauge.js", "dist/gauge.min.js", diff --git a/dist/gauge.coffee b/dist/gauge.coffee index 0e3a9e4..22cc126 100644 --- a/dist/gauge.coffee +++ b/dist/gauge.coffee @@ -459,49 +459,47 @@ class Gauge extends BaseGauge @ctx.restore() renderTicks: (ticksOptions, w, h, radius) -> + if ticksOptions != {} + divisionCount = ticksOptions.divisions || 0 + subdivisionCount = ticksOptions.subDivisions || 0 + divColor = ticksOptions.divColor || '#fff' + subColor = ticksOptions.subColor || '#fff' + divLength = ticksOptions.divLength || 0.7; # default + subLength = ticksOptions.subLength || 0.2; # default + range = parseFloat(@maxValue) - parseFloat(@minValue) # total value range + rangeDivisions = parseFloat(range) / parseFloat(ticksOptions.divisions) # get division step + subDivisions = parseFloat(rangeDivisions) / parseFloat(ticksOptions.subDivisions) + currentDivision = parseFloat(@minValue) + currentSubDivision = 0.0 + subDivisions + lineWidth = range / 400 # base + divWidth = lineWidth * (ticksOptions.divWidth || 1) + subWidth = lineWidth * (ticksOptions.subWidth || 1) + + for t in [0...divisionCount + 1] by 1 + @ctx.lineWidth = @lineWidth * divLength + scaleMutate = (@lineWidth / 2) * ( 1 - divLength) + tmpRadius = (@radius * @options.radiusScale) + scaleMutate + + @ctx.strokeStyle = divColor + @ctx.beginPath() + @ctx.arc(0, 0, tmpRadius, @getAngle(currentDivision - divWidth), @getAngle(currentDivision + divWidth), false) + @ctx.stroke() - #@ctx.save() - - divisionCount = ticksOptions.divisions || 0 - subdivisionCount = ticksOptions.subDivisions || 0 - divColor = ticksOptions.divColor || '#fff' - subColor = ticksOptions.subColor || '#fff' - divLength = ticksOptions.divLength || 0.7; # default - subLength = ticksOptions.subLength || 0.2; # default - range = parseFloat(@maxValue) - parseFloat(@minValue) # total value range - rangeDivisions = parseFloat(range) / parseFloat(ticksOptions.divisions) # get division step - subDivisions = parseFloat(rangeDivisions) / parseFloat(ticksOptions.subDivisions) - currentDivision = parseFloat(@minValue) - currentSubDivision = 0.0 + subDivisions - lineWidth = range / 400 # base - divWidth = lineWidth * (ticksOptions.divWidth || 1) - subWidth = lineWidth * (ticksOptions.subWidth || 1) - - for t in [0...divisionCount + 1] by 1 - @ctx.lineWidth = @lineWidth * divLength - scaleMutate = (@lineWidth / 2) * ( 1 - divLength) - tmpRadius = (@radius * @options.radiusScale) + scaleMutate - - @ctx.strokeStyle = divColor - @ctx.beginPath() - @ctx.arc(0, 0, tmpRadius, @getAngle(currentDivision - divWidth), @getAngle(currentDivision + divWidth), false) - @ctx.stroke() - - currentSubDivision = currentDivision + subDivisions - currentDivision += rangeDivisions - if t != ticksOptions.divisions && subdivisionCount > 0 # if its not the last marker then draw subs - for st in [0...subdivisionCount - 1] by 1 - @ctx.lineWidth = @lineWidth * subLength - scaleMutate = (@lineWidth / 2) * ( 1 - subLength) - tmpRadius = (@radius * @options.radiusScale) + scaleMutate - - @ctx.strokeStyle = subColor - @ctx.beginPath() - @ctx.arc(0, 0, tmpRadius, @getAngle(currentSubDivision - subWidth), @getAngle(currentSubDivision + subWidth), false) - @ctx.stroke() - currentSubDivision += subDivisions - - #@ctx.restore() + currentSubDivision = currentDivision + subDivisions + currentDivision += rangeDivisions + if t != ticksOptions.divisions && subdivisionCount > 0 # if its not the last marker then draw subs + for st in [0...subdivisionCount - 1] by 1 + @ctx.lineWidth = @lineWidth * subLength + scaleMutate = (@lineWidth / 2) * ( 1 - subLength) + tmpRadius = (@radius * @options.radiusScale) + scaleMutate + + @ctx.strokeStyle = subColor + @ctx.beginPath() + @ctx.arc(0, 0, tmpRadius, @getAngle(currentSubDivision - subWidth), @getAngle(currentSubDivision + subWidth), false) + @ctx.stroke() + currentSubDivision += subDivisions + + #@ctx.restore() render: () -> # Draw using canvas @@ -565,21 +563,20 @@ class Gauge extends BaseGauge @ctx.beginPath() @ctx.arc(w, h, radius, displayedAngle, (2 - @options.angle) * Math.PI, false) @ctx.stroke() + @ctx.save() + @ctx.translate(w, h) if (@options.renderTicks) @renderTicks(@options.renderTicks, w, h, radius) + @ctx.restore() # Draw pointers from (w, h) - + @ctx.translate(w, h) for gauge in @gp - @ctx.translate(w, h) gauge.update(true) - @ctx.translate(-w, -h) - - - + @ctx.translate(-w, -h) class BaseDonut extends BaseGauge diff --git a/dist/gauge.js b/dist/gauge.js index 2076be0..7295e2d 100644 --- a/dist/gauge.js +++ b/dist/gauge.js @@ -645,56 +645,58 @@ Gauge.prototype.renderTicks = function(ticksOptions, w, h, radius) { var currentDivision, currentSubDivision, divColor, divLength, divWidth, divisionCount, j, lineWidth, range, rangeDivisions, ref, results, scaleMutate, st, subColor, subDivisions, subLength, subWidth, subdivisionCount, t, tmpRadius; - divisionCount = ticksOptions.divisions || 0; - subdivisionCount = ticksOptions.subDivisions || 0; - divColor = ticksOptions.divColor || '#fff'; - subColor = ticksOptions.subColor || '#fff'; - divLength = ticksOptions.divLength || 0.7; - subLength = ticksOptions.subLength || 0.2; - range = parseFloat(this.maxValue) - parseFloat(this.minValue); - rangeDivisions = parseFloat(range) / parseFloat(ticksOptions.divisions); - subDivisions = parseFloat(rangeDivisions) / parseFloat(ticksOptions.subDivisions); - currentDivision = parseFloat(this.minValue); - currentSubDivision = 0.0 + subDivisions; - lineWidth = range / 400; - divWidth = lineWidth * (ticksOptions.divWidth || 1); - subWidth = lineWidth * (ticksOptions.subWidth || 1); - results = []; - for (t = j = 0, ref = divisionCount + 1; j < ref; t = j += 1) { - this.ctx.lineWidth = this.lineWidth * divLength; - scaleMutate = (this.lineWidth / 2) * (1 - divLength); - tmpRadius = (this.radius * this.options.radiusScale) + scaleMutate; - this.ctx.strokeStyle = divColor; - this.ctx.beginPath(); - this.ctx.arc(0, 0, tmpRadius, this.getAngle(currentDivision - divWidth), this.getAngle(currentDivision + divWidth), false); - this.ctx.stroke(); - currentSubDivision = currentDivision + subDivisions; - currentDivision += rangeDivisions; - if (t !== ticksOptions.divisions && subdivisionCount > 0) { - results.push((function() { - var k, ref1, results1; - results1 = []; - for (st = k = 0, ref1 = subdivisionCount - 1; k < ref1; st = k += 1) { - this.ctx.lineWidth = this.lineWidth * subLength; - scaleMutate = (this.lineWidth / 2) * (1 - subLength); - tmpRadius = (this.radius * this.options.radiusScale) + scaleMutate; - this.ctx.strokeStyle = subColor; - this.ctx.beginPath(); - this.ctx.arc(0, 0, tmpRadius, this.getAngle(currentSubDivision - subWidth), this.getAngle(currentSubDivision + subWidth), false); - this.ctx.stroke(); - results1.push(currentSubDivision += subDivisions); - } - return results1; - }).call(this)); - } else { - results.push(void 0); + if (ticksOptions !== {}) { + divisionCount = ticksOptions.divisions || 0; + subdivisionCount = ticksOptions.subDivisions || 0; + divColor = ticksOptions.divColor || '#fff'; + subColor = ticksOptions.subColor || '#fff'; + divLength = ticksOptions.divLength || 0.7; + subLength = ticksOptions.subLength || 0.2; + range = parseFloat(this.maxValue) - parseFloat(this.minValue); + rangeDivisions = parseFloat(range) / parseFloat(ticksOptions.divisions); + subDivisions = parseFloat(rangeDivisions) / parseFloat(ticksOptions.subDivisions); + currentDivision = parseFloat(this.minValue); + currentSubDivision = 0.0 + subDivisions; + lineWidth = range / 400; + divWidth = lineWidth * (ticksOptions.divWidth || 1); + subWidth = lineWidth * (ticksOptions.subWidth || 1); + results = []; + for (t = j = 0, ref = divisionCount + 1; j < ref; t = j += 1) { + this.ctx.lineWidth = this.lineWidth * divLength; + scaleMutate = (this.lineWidth / 2) * (1 - divLength); + tmpRadius = (this.radius * this.options.radiusScale) + scaleMutate; + this.ctx.strokeStyle = divColor; + this.ctx.beginPath(); + this.ctx.arc(0, 0, tmpRadius, this.getAngle(currentDivision - divWidth), this.getAngle(currentDivision + divWidth), false); + this.ctx.stroke(); + currentSubDivision = currentDivision + subDivisions; + currentDivision += rangeDivisions; + if (t !== ticksOptions.divisions && subdivisionCount > 0) { + results.push((function() { + var k, ref1, results1; + results1 = []; + for (st = k = 0, ref1 = subdivisionCount - 1; k < ref1; st = k += 1) { + this.ctx.lineWidth = this.lineWidth * subLength; + scaleMutate = (this.lineWidth / 2) * (1 - subLength); + tmpRadius = (this.radius * this.options.radiusScale) + scaleMutate; + this.ctx.strokeStyle = subColor; + this.ctx.beginPath(); + this.ctx.arc(0, 0, tmpRadius, this.getAngle(currentSubDivision - subWidth), this.getAngle(currentSubDivision + subWidth), false); + this.ctx.stroke(); + results1.push(currentSubDivision += subDivisions); + } + return results1; + }).call(this)); + } else { + results.push(void 0); + } } + return results; } - return results; }; Gauge.prototype.render = function() { - var displayedAngle, fillStyle, gauge, h, j, k, len, len1, max, min, radius, ref, ref1, results, scaleMutate, tmpRadius, w, zone; + var displayedAngle, fillStyle, gauge, h, j, k, len, len1, max, min, radius, ref, ref1, scaleMutate, tmpRadius, w, zone; w = this.canvas.width / 2; h = (this.canvas.height * this.paddingTop + this.availableHeight) - ((this.radius + this.lineWidth / 2) * this.extraPadding); displayedAngle = this.getAngle(this.displayedValue); @@ -757,20 +759,20 @@ this.ctx.beginPath(); this.ctx.arc(w, h, radius, displayedAngle, (2 - this.options.angle) * Math.PI, false); this.ctx.stroke(); + this.ctx.save(); + this.ctx.translate(w, h); } if (this.options.renderTicks) { this.renderTicks(this.options.renderTicks, w, h, radius); } this.ctx.restore(); + this.ctx.translate(w, h); ref1 = this.gp; - results = []; for (k = 0, len1 = ref1.length; k < len1; k++) { gauge = ref1[k]; - this.ctx.translate(w, h); gauge.update(true); - results.push(this.ctx.translate(-w, -h)); } - return results; + return this.ctx.translate(-w, -h); }; return Gauge; diff --git a/dist/gauge.min.js b/dist/gauge.min.js index 710bbfb..ad83c23 100644 --- a/dist/gauge.min.js +++ b/dist/gauge.min.js @@ -1 +1 @@ -(function(){var t,i,e,s,n,o,a,h,r,l,p,c,u,d=[].slice,g={}.hasOwnProperty,m=function(t,i){function e(){this.constructor=t}for(var s in i)g.call(i,s)&&(t[s]=i[s]);return e.prototype=i.prototype,t.prototype=new e,t.__super__=i.prototype,t};!function(){var t,i,e,s,n,o,a;for(a=["ms","moz","webkit","o"],e=0,n=a.length;e1&&(n="."+e[1]),i=/(\d+)(\d{3})/;i.test(s);)s=s.replace(i,"$1,$2");return s+n},l=function(t){return"#"===t.charAt(0)?t.substring(1,7):t},h=function(){function t(t,i){null==t&&(t=!0),this.clear=null==i||i,t&&AnimationUpdater.add(this)}return t.prototype.animationSpeed=32,t.prototype.update=function(t){var i;return null==t&&(t=!1),!(!t&&this.displayedValue===this.value)&&(this.ctx&&this.clear&&this.ctx.clearRect(0,0,this.canvas.width,this.canvas.height),i=this.value-this.displayedValue,Math.abs(i/this.animationSpeed)<=.001?this.displayedValue=this.value:this.displayedValue=this.displayedValue+i/this.animationSpeed,this.render(),!0)},t}(),e=function(t){function i(){return i.__super__.constructor.apply(this,arguments)}return m(i,t),i.prototype.displayScale=1,i.prototype.forceUpdate=!0,i.prototype.setTextField=function(t,i){return this.textField=t instanceof a?t:new a(t,i)},i.prototype.setMinValue=function(t,i){var e,s,n,o,a;if(this.minValue=t,null==i&&(i=!0),i){for(this.displayedValue=this.minValue,o=this.gp||[],a=[],s=0,n=o.length;s.5&&(this.options.angle=.5),this.configDisplayScale(),this},i.prototype.configDisplayScale=function(){var t,i,e,s,n;return s=this.displayScale,!1===this.options.highDpiSupport?delete this.displayScale:(i=window.devicePixelRatio||1,t=this.ctx.webkitBackingStorePixelRatio||this.ctx.mozBackingStorePixelRatio||this.ctx.msBackingStorePixelRatio||this.ctx.oBackingStorePixelRatio||this.ctx.backingStorePixelRatio||1,this.displayScale=i/t),this.displayScale!==s&&(n=this.canvas.G__width||this.canvas.width,e=this.canvas.G__height||this.canvas.height,this.canvas.width=n*this.displayScale,this.canvas.height=e*this.displayScale,this.canvas.style.width=n+"px",this.canvas.style.height=e+"px",this.canvas.G__width=n,this.canvas.G__height=e),this},i.prototype.parseValue=function(t){return t=parseFloat(t)||Number(t),isFinite(t)?t:0},i}(h),a=function(){function t(t,i){this.el=t,this.fractionDigits=i}return t.prototype.render=function(t){return this.el.innerHTML=p(t.displayedValue,this.fractionDigits)},t}(),t=function(t){function i(t,e){if(this.elem=t,this.text=null!=e&&e,i.__super__.constructor.call(this),void 0===this.elem)throw new Error("The element isn't defined.");this.value=1*this.elem.innerHTML,this.text&&(this.value=0)}return m(i,t),i.prototype.displayedValue=0,i.prototype.value=0,i.prototype.setVal=function(t){return this.value=1*t},i.prototype.render=function(){var t;return t=this.text?u(this.displayedValue.toFixed(0)):r(p(this.displayedValue)),this.elem.innerHTML=t},i}(h),o=function(t){function i(t){if(this.gauge=t,void 0===this.gauge)throw new Error("The element isn't defined.");this.ctx=this.gauge.ctx,this.canvas=this.gauge.canvas,i.__super__.constructor.call(this,!1,!1),this.setOptions()}return m(i,t),i.prototype.displayedValue=0,i.prototype.value=0,i.prototype.options={strokeWidth:.035,length:.1,color:"#000000",iconPath:null,iconScale:1,iconAngle:0},i.prototype.img=null,i.prototype.setOptions=function(t){if(null==t&&(t=null),this.options=c(this.options,t),this.length=2*this.gauge.radius*this.gauge.options.radiusScale*this.options.length,this.strokeWidth=this.canvas.height*this.options.strokeWidth,this.maxValue=this.gauge.maxValue,this.minValue=this.gauge.minValue,this.animationSpeed=this.gauge.animationSpeed,this.options.angle=this.gauge.options.angle,this.options.iconPath)return this.img=new Image,this.img.src=this.options.iconPath},i.prototype.render=function(){var t,i,e,s,n,o,a,h,r;if(t=this.gauge.getAngle.call(this,this.displayedValue),h=Math.round(this.length*Math.cos(t)),r=Math.round(this.length*Math.sin(t)),o=Math.round(this.strokeWidth*Math.cos(t-Math.PI/2)),a=Math.round(this.strokeWidth*Math.sin(t-Math.PI/2)),i=Math.round(this.strokeWidth*Math.cos(t+Math.PI/2)),e=Math.round(this.strokeWidth*Math.sin(t+Math.PI/2)),this.ctx.beginPath(),this.ctx.fillStyle=this.options.color,this.ctx.arc(0,0,this.strokeWidth,0,2*Math.PI,!1),this.ctx.fill(),this.ctx.beginPath(),this.ctx.moveTo(o,a),this.ctx.lineTo(h,r),this.ctx.lineTo(i,e),this.ctx.fill(),this.img)return s=Math.round(this.img.width*this.options.iconScale),n=Math.round(this.img.height*this.options.iconScale),this.ctx.save(),this.ctx.translate(h,r),this.ctx.rotate(t+Math.PI/180*(90+this.options.iconAngle)),this.ctx.drawImage(this.img,-s/2,-n/2,s,n),this.ctx.restore()},i}(h),function(){function t(t){this.elem=t}t.prototype.updateValues=function(t){return this.value=t[0],this.maxValue=t[1],this.avgValue=t[2],this.render()},t.prototype.render=function(){var t,i;return this.textField&&this.textField.text(p(this.value)),0===this.maxValue&&(this.maxValue=2*this.avgValue),i=this.value/this.maxValue*100,t=this.avgValue/this.maxValue*100,$(".bar-value",this.elem).css({width:i+"%"}),$(".typical-value",this.elem).css({width:t+"%"})}}(),n=function(t){function i(t){var e,s;this.canvas=t,i.__super__.constructor.call(this),this.percentColors=null,"undefined"!=typeof G_vmlCanvasManager&&(this.canvas=window.G_vmlCanvasManager.initElement(this.canvas)),this.ctx=this.canvas.getContext("2d"),e=this.canvas.clientHeight,s=this.canvas.clientWidth,this.canvas.height=e,this.canvas.width=s,this.gp=[new o(this)],this.setOptions()}return m(i,t),i.prototype.elem=null,i.prototype.value=[20],i.prototype.maxValue=80,i.prototype.minValue=0,i.prototype.displayedAngle=0,i.prototype.displayedValue=0,i.prototype.lineWidth=40,i.prototype.paddingTop=.1,i.prototype.paddingBottom=.1,i.prototype.percentColors=null,i.prototype.options={colorStart:"#6fadcf",colorStop:void 0,gradientType:0,strokeColor:"#e0e0e0",pointer:{length:.8,strokeWidth:.035,iconScale:1},angle:.15,lineWidth:.44,radiusScale:1,fontSize:40,limitMax:!1,limitMin:!1},i.prototype.setOptions=function(t){var e,s,n,o,a;for(null==t&&(t=null),i.__super__.setOptions.call(this,t),this.configPercentColors(),this.extraPadding=0,this.options.angle<0&&(o=Math.PI*(1+this.options.angle),this.extraPadding=Math.sin(o)),this.availableHeight=this.canvas.height*(1-this.paddingTop-this.paddingBottom),this.lineWidth=this.availableHeight*this.options.lineWidth,this.radius=(this.availableHeight-this.lineWidth/2)/(1+this.extraPadding),this.ctx.clearRect(0,0,this.canvas.width,this.canvas.height),a=this.gp,s=0,n=a.length;s=n;e=0<=n?++s:--s)a=parseInt(l(this.options.percentColors[e][1]).substring(0,2),16),i=parseInt(l(this.options.percentColors[e][1]).substring(2,4),16),t=parseInt(l(this.options.percentColors[e][1]).substring(4,6),16),o.push(this.percentColors[e]={pct:this.options.percentColors[e][0],color:{r:a,g:i,b:t}});return o}},i.prototype.set=function(t){var i,e,s,n,a,h,r,l,p;for(t instanceof Array||(t=[t]),e=s=0,r=t.length-1;0<=r?s<=r:s>=r;e=0<=r?++s:--s)t[e]=this.parseValue(t[e]);if(t.length>this.gp.length)for(e=n=0,l=t.length-this.gp.length;0<=l?nl;e=0<=l?++n:--n)i=new o(this),i.setOptions(this.options.pointer),this.gp.push(i);else t.lengththis.maxValue?this.options.limitMax?p=this.maxValue:this.maxValue=p+1:p=h;n=0<=h?++o:--o)if(t<=this.percentColors[n].pct){!0===i?(r=this.percentColors[n-1]||this.percentColors[0],s=this.percentColors[n],a=(t-r.pct)/(s.pct-r.pct),e={r:Math.floor(r.color.r*(1-a)+s.color.r*a),g:Math.floor(r.color.g*(1-a)+s.color.g*a),b:Math.floor(r.color.b*(1-a)+s.color.b*a)}):e=this.percentColors[n].color;break}return"rgb("+[e.r,e.g,e.b].join(",")+")"},i.prototype.getColorForValue=function(t,i){var e;return e=(t-this.minValue)/(this.maxValue-this.minValue),this.getColorForPercentage(e,i)},i.prototype.renderStaticLabels=function(t,i,e,s){var n,o,a,h,r,l,c,u,d,g;for(this.ctx.save(),this.ctx.translate(i,e),n=t.font||"10px Times",l=/\d+\.?\d?/,r=n.match(l)[0],u=n.slice(r.length),o=parseFloat(r)*this.displayScale,this.ctx.font=o+u,this.ctx.fillStyle=t.color||"#000000",this.ctx.textBaseline="bottom",this.ctx.textAlign="center",c=t.labels,a=0,h=c.length;a=this.minValue)&&(!this.options.limitMax||g<=this.maxValue)&&(n=g.font||t.font,r=n.match(l)[0],u=n.slice(r.length),o=parseFloat(r)*this.displayScale,this.ctx.font=o+u,d=this.getAngle(g.label)-3*Math.PI/2,this.ctx.rotate(d),this.ctx.fillText(p(g.label,t.fractionDigits),0,-s-this.lineWidth/2),this.ctx.rotate(-d)):(!this.options.limitMin||g>=this.minValue)&&(!this.options.limitMax||g<=this.maxValue)&&(d=this.getAngle(g)-3*Math.PI/2,this.ctx.rotate(d),this.ctx.fillText(p(g,t.fractionDigits),0,-s-this.lineWidth/2),this.ctx.rotate(-d));return this.ctx.restore()},i.prototype.renderTicks=function(t,i,e,s){var n,o,a,h,r,l,p,c,u,d,g,m,x,f,v,y,V,w,S,M,C;for(l=t.divisions||0,S=t.subDivisions||0,a=t.divColor||"#fff",v=t.subColor||"#fff",h=t.divLength||.7,V=t.subLength||.2,u=parseFloat(this.maxValue)-parseFloat(this.minValue),d=parseFloat(u)/parseFloat(t.divisions),y=parseFloat(d)/parseFloat(t.subDivisions),n=parseFloat(this.minValue),o=0+y,c=u/400,r=c*(t.divWidth||1),w=c*(t.subWidth||1),m=[],M=p=0,g=l+1;p0?m.push(function(){var t,i,e;for(e=[],f=t=0,i=S-1;tthis.maxValue&&(r=this.maxValue),m=this.radius,f.height&&(this.ctx.lineWidth=this.lineWidth*f.height,g=this.lineWidth/2*(f.offset||1-f.height),m=this.radius*this.options.radiusScale+g),this.ctx.strokeStyle=f.strokeStyle,this.ctx.beginPath(),this.ctx.arc(0,0,m,this.getAngle(l),this.getAngle(r),!1),this.ctx.stroke();else void 0!==this.options.customFillStyle?i=this.options.customFillStyle(this):null!==this.percentColors?i=this.getColorForValue(this.displayedValue,this.options.generateGradient):void 0!==this.options.colorStop?(i=0===this.options.gradientType?this.ctx.createRadialGradient(x,s,9,x,s,70):this.ctx.createLinearGradient(0,0,x,0),i.addColorStop(0,this.options.colorStart),i.addColorStop(1,this.options.colorStop)):i=this.options.colorStart,this.ctx.strokeStyle=i,this.ctx.beginPath(),this.ctx.arc(x,s,p,(1+this.options.angle)*Math.PI,t,!1),this.ctx.lineWidth=this.lineWidth,this.ctx.stroke(),this.ctx.strokeStyle=this.options.strokeColor,this.ctx.beginPath(),this.ctx.arc(x,s,p,t,(2-this.options.angle)*Math.PI,!1),this.ctx.stroke();for(this.options.renderTicks&&this.renderTicks(this.options.renderTicks,x,s,p),this.ctx.restore(),u=this.gp,d=[],o=0,h=u.length;othis.maxValue?this.options.limitMax?this.value=this.maxValue:this.maxValue=this.value:this.value1&&(n="."+e[1]),i=/(\d+)(\d{3})/;i.test(s);)s=s.replace(i,"$1,$2");return s+n},l=function(t){return"#"===t.charAt(0)?t.substring(1,7):t},h=function(){function t(t,i){null==t&&(t=!0),this.clear=null==i||i,t&&AnimationUpdater.add(this)}return t.prototype.animationSpeed=32,t.prototype.update=function(t){var i;return null==t&&(t=!1),!(!t&&this.displayedValue===this.value)&&(this.ctx&&this.clear&&this.ctx.clearRect(0,0,this.canvas.width,this.canvas.height),i=this.value-this.displayedValue,Math.abs(i/this.animationSpeed)<=.001?this.displayedValue=this.value:this.displayedValue=this.displayedValue+i/this.animationSpeed,this.render(),!0)},t}(),e=function(t){function i(){return i.__super__.constructor.apply(this,arguments)}return m(i,t),i.prototype.displayScale=1,i.prototype.forceUpdate=!0,i.prototype.setTextField=function(t,i){return this.textField=t instanceof a?t:new a(t,i)},i.prototype.setMinValue=function(t,i){var e,s,n,o,a;if(this.minValue=t,null==i&&(i=!0),i){for(this.displayedValue=this.minValue,o=this.gp||[],a=[],s=0,n=o.length;s.5&&(this.options.angle=.5),this.configDisplayScale(),this},i.prototype.configDisplayScale=function(){var t,i,e,s,n;return s=this.displayScale,!1===this.options.highDpiSupport?delete this.displayScale:(i=window.devicePixelRatio||1,t=this.ctx.webkitBackingStorePixelRatio||this.ctx.mozBackingStorePixelRatio||this.ctx.msBackingStorePixelRatio||this.ctx.oBackingStorePixelRatio||this.ctx.backingStorePixelRatio||1,this.displayScale=i/t),this.displayScale!==s&&(n=this.canvas.G__width||this.canvas.width,e=this.canvas.G__height||this.canvas.height,this.canvas.width=n*this.displayScale,this.canvas.height=e*this.displayScale,this.canvas.style.width=n+"px",this.canvas.style.height=e+"px",this.canvas.G__width=n,this.canvas.G__height=e),this},i.prototype.parseValue=function(t){return t=parseFloat(t)||Number(t),isFinite(t)?t:0},i}(h),a=function(){function t(t,i){this.el=t,this.fractionDigits=i}return t.prototype.render=function(t){return this.el.innerHTML=p(t.displayedValue,this.fractionDigits)},t}(),t=function(t){function i(t,e){if(this.elem=t,this.text=null!=e&&e,i.__super__.constructor.call(this),void 0===this.elem)throw new Error("The element isn't defined.");this.value=1*this.elem.innerHTML,this.text&&(this.value=0)}return m(i,t),i.prototype.displayedValue=0,i.prototype.value=0,i.prototype.setVal=function(t){return this.value=1*t},i.prototype.render=function(){var t;return t=this.text?u(this.displayedValue.toFixed(0)):r(p(this.displayedValue)),this.elem.innerHTML=t},i}(h),o=function(t){function i(t){if(this.gauge=t,void 0===this.gauge)throw new Error("The element isn't defined.");this.ctx=this.gauge.ctx,this.canvas=this.gauge.canvas,i.__super__.constructor.call(this,!1,!1),this.setOptions()}return m(i,t),i.prototype.displayedValue=0,i.prototype.value=0,i.prototype.options={strokeWidth:.035,length:.1,color:"#000000",iconPath:null,iconScale:1,iconAngle:0},i.prototype.img=null,i.prototype.setOptions=function(t){if(null==t&&(t=null),this.options=c(this.options,t),this.length=2*this.gauge.radius*this.gauge.options.radiusScale*this.options.length,this.strokeWidth=this.canvas.height*this.options.strokeWidth,this.maxValue=this.gauge.maxValue,this.minValue=this.gauge.minValue,this.animationSpeed=this.gauge.animationSpeed,this.options.angle=this.gauge.options.angle,this.options.iconPath)return this.img=new Image,this.img.src=this.options.iconPath},i.prototype.render=function(){var t,i,e,s,n,o,a,h,r;if(t=this.gauge.getAngle.call(this,this.displayedValue),h=Math.round(this.length*Math.cos(t)),r=Math.round(this.length*Math.sin(t)),o=Math.round(this.strokeWidth*Math.cos(t-Math.PI/2)),a=Math.round(this.strokeWidth*Math.sin(t-Math.PI/2)),i=Math.round(this.strokeWidth*Math.cos(t+Math.PI/2)),e=Math.round(this.strokeWidth*Math.sin(t+Math.PI/2)),this.ctx.beginPath(),this.ctx.fillStyle=this.options.color,this.ctx.arc(0,0,this.strokeWidth,0,2*Math.PI,!1),this.ctx.fill(),this.ctx.beginPath(),this.ctx.moveTo(o,a),this.ctx.lineTo(h,r),this.ctx.lineTo(i,e),this.ctx.fill(),this.img)return s=Math.round(this.img.width*this.options.iconScale),n=Math.round(this.img.height*this.options.iconScale),this.ctx.save(),this.ctx.translate(h,r),this.ctx.rotate(t+Math.PI/180*(90+this.options.iconAngle)),this.ctx.drawImage(this.img,-s/2,-n/2,s,n),this.ctx.restore()},i}(h),function(){function t(t){this.elem=t}t.prototype.updateValues=function(t){return this.value=t[0],this.maxValue=t[1],this.avgValue=t[2],this.render()},t.prototype.render=function(){var t,i;return this.textField&&this.textField.text(p(this.value)),0===this.maxValue&&(this.maxValue=2*this.avgValue),i=this.value/this.maxValue*100,t=this.avgValue/this.maxValue*100,$(".bar-value",this.elem).css({width:i+"%"}),$(".typical-value",this.elem).css({width:t+"%"})}}(),n=function(t){function i(t){var e,s;this.canvas=t,i.__super__.constructor.call(this),this.percentColors=null,"undefined"!=typeof G_vmlCanvasManager&&(this.canvas=window.G_vmlCanvasManager.initElement(this.canvas)),this.ctx=this.canvas.getContext("2d"),e=this.canvas.clientHeight,s=this.canvas.clientWidth,this.canvas.height=e,this.canvas.width=s,this.gp=[new o(this)],this.setOptions()}return m(i,t),i.prototype.elem=null,i.prototype.value=[20],i.prototype.maxValue=80,i.prototype.minValue=0,i.prototype.displayedAngle=0,i.prototype.displayedValue=0,i.prototype.lineWidth=40,i.prototype.paddingTop=.1,i.prototype.paddingBottom=.1,i.prototype.percentColors=null,i.prototype.options={colorStart:"#6fadcf",colorStop:void 0,gradientType:0,strokeColor:"#e0e0e0",pointer:{length:.8,strokeWidth:.035,iconScale:1},angle:.15,lineWidth:.44,radiusScale:1,fontSize:40,limitMax:!1,limitMin:!1},i.prototype.setOptions=function(t){var e,s,n,o,a;for(null==t&&(t=null),i.__super__.setOptions.call(this,t),this.configPercentColors(),this.extraPadding=0,this.options.angle<0&&(o=Math.PI*(1+this.options.angle),this.extraPadding=Math.sin(o)),this.availableHeight=this.canvas.height*(1-this.paddingTop-this.paddingBottom),this.lineWidth=this.availableHeight*this.options.lineWidth,this.radius=(this.availableHeight-this.lineWidth/2)/(1+this.extraPadding),this.ctx.clearRect(0,0,this.canvas.width,this.canvas.height),a=this.gp,s=0,n=a.length;s=n;e=0<=n?++s:--s)a=parseInt(l(this.options.percentColors[e][1]).substring(0,2),16),i=parseInt(l(this.options.percentColors[e][1]).substring(2,4),16),t=parseInt(l(this.options.percentColors[e][1]).substring(4,6),16),o.push(this.percentColors[e]={pct:this.options.percentColors[e][0],color:{r:a,g:i,b:t}});return o}},i.prototype.set=function(t){var i,e,s,n,a,h,r,l,p;for(t instanceof Array||(t=[t]),e=s=0,r=t.length-1;0<=r?s<=r:s>=r;e=0<=r?++s:--s)t[e]=this.parseValue(t[e]);if(t.length>this.gp.length)for(e=n=0,l=t.length-this.gp.length;0<=l?nl;e=0<=l?++n:--n)i=new o(this),i.setOptions(this.options.pointer),this.gp.push(i);else t.lengththis.maxValue?this.options.limitMax?p=this.maxValue:this.maxValue=p+1:p=h;n=0<=h?++o:--o)if(t<=this.percentColors[n].pct){!0===i?(r=this.percentColors[n-1]||this.percentColors[0],s=this.percentColors[n],a=(t-r.pct)/(s.pct-r.pct),e={r:Math.floor(r.color.r*(1-a)+s.color.r*a),g:Math.floor(r.color.g*(1-a)+s.color.g*a),b:Math.floor(r.color.b*(1-a)+s.color.b*a)}):e=this.percentColors[n].color;break}return"rgb("+[e.r,e.g,e.b].join(",")+")"},i.prototype.getColorForValue=function(t,i){var e;return e=(t-this.minValue)/(this.maxValue-this.minValue),this.getColorForPercentage(e,i)},i.prototype.renderStaticLabels=function(t,i,e,s){var n,o,a,h,r,l,c,u,d,g;for(this.ctx.save(),this.ctx.translate(i,e),n=t.font||"10px Times",l=/\d+\.?\d?/,r=n.match(l)[0],u=n.slice(r.length),o=parseFloat(r)*this.displayScale,this.ctx.font=o+u,this.ctx.fillStyle=t.color||"#000000",this.ctx.textBaseline="bottom",this.ctx.textAlign="center",c=t.labels,a=0,h=c.length;a=this.minValue)&&(!this.options.limitMax||g<=this.maxValue)&&(n=g.font||t.font,r=n.match(l)[0],u=n.slice(r.length),o=parseFloat(r)*this.displayScale,this.ctx.font=o+u,d=this.getAngle(g.label)-3*Math.PI/2,this.ctx.rotate(d),this.ctx.fillText(p(g.label,t.fractionDigits),0,-s-this.lineWidth/2),this.ctx.rotate(-d)):(!this.options.limitMin||g>=this.minValue)&&(!this.options.limitMax||g<=this.maxValue)&&(d=this.getAngle(g)-3*Math.PI/2,this.ctx.rotate(d),this.ctx.fillText(p(g,t.fractionDigits),0,-s-this.lineWidth/2),this.ctx.rotate(-d));return this.ctx.restore()},i.prototype.renderTicks=function(t,i,e,s){var n,o,a,h,r,l,p,c,u,d,g,m,x,f,v,y,V,w,S,M,C;if(t!=={}){for(l=t.divisions||0,S=t.subDivisions||0,a=t.divColor||"#fff",v=t.subColor||"#fff",h=t.divLength||.7,V=t.subLength||.2,u=parseFloat(this.maxValue)-parseFloat(this.minValue),d=parseFloat(u)/parseFloat(t.divisions),y=parseFloat(d)/parseFloat(t.subDivisions),n=parseFloat(this.minValue),o=0+y,c=u/400,r=c*(t.divWidth||1),w=c*(t.subWidth||1),m=[],M=p=0,g=l+1;p0?m.push(function(){var t,i,e;for(e=[],f=t=0,i=S-1;tthis.maxValue&&(r=this.maxValue),g=this.radius,x.height&&(this.ctx.lineWidth=this.lineWidth*x.height,d=this.lineWidth/2*(x.offset||1-x.height),g=this.radius*this.options.radiusScale+d),this.ctx.strokeStyle=x.strokeStyle,this.ctx.beginPath(),this.ctx.arc(0,0,g,this.getAngle(l),this.getAngle(r),!1),this.ctx.stroke();else void 0!==this.options.customFillStyle?i=this.options.customFillStyle(this):null!==this.percentColors?i=this.getColorForValue(this.displayedValue,this.options.generateGradient):void 0!==this.options.colorStop?(i=0===this.options.gradientType?this.ctx.createRadialGradient(m,s,9,m,s,70):this.ctx.createLinearGradient(0,0,m,0),i.addColorStop(0,this.options.colorStart),i.addColorStop(1,this.options.colorStop)):i=this.options.colorStart,this.ctx.strokeStyle=i,this.ctx.beginPath(),this.ctx.arc(m,s,p,(1+this.options.angle)*Math.PI,t,!1),this.ctx.lineWidth=this.lineWidth,this.ctx.stroke(),this.ctx.strokeStyle=this.options.strokeColor,this.ctx.beginPath(),this.ctx.arc(m,s,p,t,(2-this.options.angle)*Math.PI,!1),this.ctx.stroke(),this.ctx.save(),this.ctx.translate(m,s);for(this.options.renderTicks&&this.renderTicks(this.options.renderTicks,m,s,p),this.ctx.restore(),this.ctx.translate(m,s),u=this.gp,o=0,h=u.length;othis.maxValue?this.options.limitMax?this.value=this.maxValue:this.maxValue=this.value:this.valueOptions:

+