UNPKG

@progress/kendo-ui

Version:

This package is part of the [Kendo UI for jQuery](http://www.telerik.com/kendo-ui) suite.

1 lines 7.17 kB
module.exports=function(r){var i={};function n(e){if(i[e])return i[e].exports;var t=i[e]={exports:{},id:e,loaded:!1};return r[e].call(t.exports,t,t.exports,n),t.loaded=!0,t.exports}return n.m=r,n.c=i,n.p="",n(0)}({0:function(e,t,r){e.exports=r(1108)},3:function(e,t){e.exports=function(){throw Error("define cannot be used indirect")}},1055:function(e,t){e.exports=require("./kendo.dataviz")},1108:function(e,t,r){var i;r(3),r=[r(1055),r(1109)],void 0===(t="function"==typeof(i=function(){var t={id:"circularprogressBar",name:"CircularProgressBar",category:"web",description:"The Circular ProgressBar component represents an SVG loader",depends:["core"]},n=window.kendo.jQuery,l=void 0,c=(window.kendo.dataviz=window.kendo.dataviz||{},kendo.dataviz),h=c.interpolateValue,o=kendo.drawing,e=kendo.ui,i=e.Widget,d=o.Surface,s=kendo.geometry,v=o.Animation,f=o.Arc,p=c.limitValue,u=c.round,g=o.Group,m=200,_=180,r=0,a=100,w=5,C=150,y=200,x=800,A='<span aria-live="polite" class="k-sr-only k-progress-announce"></span>',k=v.extend({init:function(e,t){v.fn.init.call(this,e,t);var r=this.options;var i=t.endColor;var n=t.startColor;var a=Math.abs(r.newAngle-r.oldAngle)/r.duration*1e3;r.duration=p(a,C,x);this.element=e;if(n!==i){this.startColor=new kendo.Color(n);this.color=new kendo.Color(i)}},step:function(e){var t=this;var r=t.options;var i=t.startColor;var n=t.color;var a=h(r.oldAngle,r.newAngle,e);this.element.geometry().setEndAngle(a);if(n){var o=u(h(i.r,n.r,e));var s=u(h(i.g,n.g,e));var l=u(h(i.b,n.b,e));this.element.stroke(new kendo.Color(o,s,l).toHex())}}}),b=i.extend({init:function(e,t){var r=this;i.fn.init.call(r,e,t);this.theme=E(this.options);this._value=this.options.value;this.element.addClass("k-gauge");this.redraw();this._centerTemplate();this._aria()},options:{name:"CircularProgressBar",ariaRole:false,theme:"default",centerTemplate:"",color:"",colors:[],transitions:true,pointerWidth:5,indeterminate:false,label:null,labelId:null},events:[],value:function(e){var t=this;if(e===l)return t._value;e=t._restrictValue(e);t._centerSvgElements();t._pointerChange(t._value,e);t._value=e;t._centerTemplate();t._updateProgress()},redraw:function(){this._initSurface();this._buildVisual();this._draw()},resize:function(){var e=this.options.transitions;this.options.transitions=false;this._initSurface();this._buildVisual();this._draw();this._centerTemplate();this.options.transitions=e},destroy:function(){var e=this;if(e.announce)e.announce.remove();i.fn.destroy.call(e)},_aria:function(){var e=this,t=e.options,r=e.value()||0,i=e.element;if(!t.ariaRole)return;i.attr({role:"progressbar"});if(!t.indeterminate)i.attr({"aria-valuemin":0,"aria-valuemax":100});if(!!t.labelId)i.attr("aria-labelledby",t.labelId);else if(!!t.label)i.attr("aria-label",t.label);e.announce=n(A);e.announce.appendTo(n("body"));if(!t.indeterminate){i.attr("aria-valuenow",r);e.announce.text(r+"%")}else e.announce.text("Loading...")},_restrictValue:function(e){if(e<r)return r;if(e>a)return a;return e},_updateProgress:function(){var e=this;var t=e.options;var r=e.value()||0;if(t.ariaRole&&!t.indeterminate){e.element.attr("aria-valuenow",r);if(e.announce)e.announce.text(r+"%")}},_centerSvgElements:function(){var e=this._getCenter();if(this.circle._geometry.center.x!==e.x||this.circle._geometry.center.y!==e.y){this.circle._geometry.center.x=e.x;this.circle._geometry.center.y=e.y;this.arc._geometry.center.x=e.x;this.arc._geometry.center.y=e.y;this.circle.geometryChange();this.arc.geometryChange()}},_centerTemplate:function(){var e;var t;var r;if(this.options.centerTemplate){t=kendo.template(this.options.centerTemplate);r=this._getCenterElement();r.html(t({color:this._getColor(this.value()),value:this.value()}));e=this._centerTemplatePosition(r.width(),r.height());r.css(e)}else if(this._centerElement){this._centerElement.remove();this._centerElement=null}},_getCenterElement:function(){var e=this._centerElement;if(!e){e=this._centerElement=n("<div></div>").addClass("k-arcgauge-label");this.element.append(e)}return e},_pointerChange:function(e,t){var r;if(this.options.transitions){r=new k(this.arc,{oldAngle:this._slotAngle(e),startColor:this._getColor(e),newAngle:this._slotAngle(t),endColor:this._getColor(t)});r.play()}else{this.arc.stroke(this._getColor(t));this.arc.geometry().setEndAngle(this._slotAngle(t))}},_draw:function(){var e;var t;var r;var i=this.surface;i.clear();i.draw(this._visuals);if(this.options.indeterminate){e=i.element.find("path");t=this._getCenter();e[0].innerHTML=kendo.format('<animateTransform attributeName="transform" type="rotate" from="0 {0} {1}" to="360 {0} {1}" dur="1s" repeatCount="indefinite" />',t.x,t.y)}else if(this.options.transitions){r=new k(this.arc,{oldAngle:this._slotAngle(0),startColor:this._getColor(0),newAngle:this._slotAngle(this.value()),endColor:this._getColor(this.value())});r.play()}},_buildVisual:function(){var e=this._visuals=new g;var t=this._getCenter();var r=this._getColor(this.value())||this.theme.pointer.color;var i=Math.min(t.x,t.y)-w-this.options.pointerWidth;var n=new s.Circle([t.x,t.y],i+this.options.pointerWidth/2);var a=this.circle=new o.Circle(n,{fill:{color:"none"},stroke:{color:this.theme.scale.rangePlaceholderColor,width:this.options.pointerWidth}});e.append(a);if(this.options.indeterminate)this.arc=this._createArc(360,i,t,r);else this.arc=this._createArc(this._slotAngle(this.value()),i,t,r);e.append(this.arc)},_slotAngle:function(e){var t;t=(e-r)/a*360+90;return t+_},_getColor:function(e){var t=this.options;var r=t.colors;var i=t.color;var n=c.isNumber(e)?e:0;if(r)for(var a=0;a<r.length;a++){var o=r[a];var s=o.color;var l=o.from;if(l===void 0)l=0;var h=o.to;if(h===void 0)h=100;if(l<=n&&n<=h)return s}return i},_createArc:function(e,t,r,i){var n=this.options.pointerWidth;var a=new s.Arc([r.x,r.y],{radiusX:t+n/2,radiusY:t+n/2,startAngle:270,endAngle:e});return new f(a,{stroke:{width:n,color:this.options.color||i,opacity:this.options.opacity}})},_centerTemplatePosition:function(e,t){var r=this._getSize();var i=this._getCenter();var n=i.x-e/2;var a=i.y-t/2;var o;var s;if(e<r.width){o=n+e;n=Math.max(n,0);if(o>r.width)n-=o-r.width}if(t<r.height){s=a+t;if(s>r.height)a-=s-r.height}return{left:n,top:a}},_getCenter:function(){var e=this._getSize();return new c.Point(e.width/2,e.height/2)},_getSize:function(){var e=this.element;var t={width:y,height:m};var r=e[0].offsetWidth;var i=e[0].offsetHeight;if(!r)r=t.width;if(!i)i=t.height;return{width:r,height:i}},_surfaceElement:function(){if(!this.surfaceElement){this.surfaceElement=document.createElement("div");this.element[0].appendChild(this.surfaceElement)}return this.surfaceElement},_initSurface:function(){var e=this;var t=e.options;var r=e.surface;var i=this._surfaceElement();var n=this._getSize();c.elementSize(i,n);if(!r)this.surface=d.create(i,{type:t.renderAs});else{this.surface.clear();this.surface.resize()}}});function E(e){var t=c.ui.themes||{};var r=e.theme||"";var i=r.toLowerCase();if(c.SASS_THEMES.indexOf(i)!=-1)return c.autoTheme().gauge;return(t[r]||t[i]||{}).gauge}return e.plugin(b),window.kendo})?i.apply(t,r):i)||(e.exports=t)},1109:function(e,t){e.exports=require("./kendo.dataviz.themes")}});