redline
Version:
Customizable html gauge
2 lines • 4.94 kB
JavaScript
!function(t,e){"object"==typeof module&&"object"==typeof module.exports?module.exports=t.document?e(t,!0):function(t){if(!t.document)throw new Error("Redline.js requires a window with a document");return e(t)}:e(t)}("undefined"!=typeof window?window:this,function(t,e){function n(e,n){var r={aperture:260,marks:[0,1,2,3,4,5,6],innerMarks:!1,position:0};this.el=e,t.jQuery&&(this.$el=t.jQuery(this.el)),this.attributes=r,this._extend(n)._processMarks()._calculateAngle()._init()}!function(t){"use strict";function e(){}function n(t){function n(e){e.prototype.option||(e.prototype.option=function(e){t.isPlainObject(e)&&(this.options=t.extend(!0,this.options,e))})}function i(e,n){t.fn[e]=function(i){if("string"==typeof i){for(var a=r.call(arguments,1),s=0,l=this.length;l>s;s++){var p=this[s],d=t.data(p,e);if(d)if(t.isFunction(d[i])&&"_"!==i.charAt(0)){var u=d[i].apply(d,a);if(void 0!==u)return u}else o("no such method '"+i+"' for "+e+" instance");else o("cannot call methods on "+e+" prior to initialization; attempted to call '"+i+"'")}return this}return this.each(function(){var r=t.data(this,e);r?(r.option(i),r._init()):(r=new n(this,i),t.data(this,e,r))})}}if(t){var o="undefined"==typeof console?e:function(t){console.error(t)};return t.bridget=function(t,e){n(e),i(t,e)},t.bridget}}var r=Array.prototype.slice;"function"==typeof define&&define.amd?define(["jquery"],n):n("object"==typeof exports?require("jquery"):t.jQuery)}(t);var r=function(){var e=t.getComputedStyle(document.documentElement,""),n=(Array.prototype.slice.call(e).join("").match(/-(moz|webkit|ms)-/)||""===e.OLink&&["","o"])[1],r="WebKit|Moz|MS|O".match(new RegExp("("+n+")","i"))[1];return{dom:r,lowercase:n,css:"-"+n+"-",js:n[0].toUpperCase()+n.substr(1)}}(),i={nodify:function(e,n,r,o){function a(e,n){var r=t.document.createElement(e.tagName);return e.className.length>0&&(r.className="string"==typeof n?n+"-"+e.className:e.className),r}function s(t){var e=t.split(".");return 1==e.length?{tagName:"div",className:e[0]}:{tagName:e[0],className:e[1]}}function l(t){return"object"==typeof t&&typeof t.appendChild==typeof Function}var p,d=s(n);if(l(r)?(p=a(d,o),r.appendChild(p)):p=a(d),"object"==typeof e)for(node in e)i.nodify(e[node],node,p,o||n);else i.nodify(null,e,p,o||n);return p},byClass:function(e,n){var n=n||t.document;return n.getElementsByClassName(e)[0]||!1},rotate:function(t,e){t.style.transform=t.style[r.lowercase+"Transform"]="rotate("+e+"deg)"},addClass:function(t,e){var n=t.className.split(" ");-1==n.indexOf(e)&&n.push(e),t.className=n.join(" ")}};return n.prototype.get=function(t){return this.attributes[t]},n.prototype.set=function(t,e){return"object"==typeof t?this._extend(t):(this.attributes[t]=e,this)},n.prototype._extend=function(t){var e=0;if("object"==typeof t)for(e in t)this.set(e,t[e]);return this},n.prototype._processMarks=function(t){var t=t||this.get("marks");for(var e in t)"object"!=typeof t[e]&&(t[e]={caption:t[e].toString()});var n=t.length;return t[n-2].type||(t[n-2].type="warning"),t[n-1].type||(t[n-1].type="danger"),this},n.prototype._createSegment=function(t,e,n,r){var t=t||0,e=e||0,o="redline-dial-segment",a={wrap:{"wrap-wrap":"line"},mark:{"mark-wrap":"span."}},s=i.nodify(a,o),l=this.get("marks")[n];i.rotate(s,e),"undefined"!=typeof l.type&&i.addClass(s,o+"-"+l.type);var p=i.byClass(o+"-wrap",s),d=i.byClass(o+"-wrap-wrap",p),u=i.byClass(o+"-mark-wrap",s);return 0!=n&&n!=this.get("marks").length-1||r?i.rotate(d,-t):i.rotate(d,-t/2),n!=this.get("marks").length-1||r?i.rotate(p,t/2):i.rotate(p,0),i.rotate(u,-e),console.log(u),l.caption.toString().length>1&&(n<this.get("marks").length/2?i.addClass(u,o+"-mark-left-fit"):i.addClass(u,o+"-mark-right-fit")),u.getElementsByTagName("span")[0].innerHTML=l.caption,s},n.prototype._calculateAngle=function(t,e,n){var r=t||this.get("aperture"),e=e||this.get("position"),i=1*(360!=r),o=e/(this.get("marks").length-i);return handAngle=(360-r)/2+r*o,n?handAngle:this.set("handAngle",handAngle)},n.prototype.moveHand=function(t){var t=t||this.get("handAngle");return i.rotate(this.handEl,t),this},n.prototype.render=function(){var t=this.get("aperture"),e=this.get("marks"),n=1*(360!=t),r=t/(e.length-n);prefix="redline",map={dial:null,hand:{"hand-wrap":{"hand-arrow":null,"hand-center":null}}},redline=i.nodify(map,prefix),this.el.innerHTML="",this.el.appendChild(redline),this.el=redline,this.handEl=i.byClass("redline-hand-wrap",this.el);var o=i.byClass("redline-dial",this.el);for(var a in e)angle=this._calculateAngle(null,a,!0),segment=this._createSegment(r,angle,a,360==t),console.log(a),o.appendChild(segment);return this.get("innerMarks")&&i.addClass(this.el,"redline-inner-marks"),this},n.prototype._init=n.prototype.render,n.prototype.point=function(t){return this.set("position",t)._calculateAngle().moveHand()},"undefined"==typeof e&&(t.Redline=n),t.jQuery&&t.jQuery.bridget&&jQuery.bridget("redline",n),n});
//# sourceMappingURL=redline.min.js.map