www-thermferm/jqwidgets/jqxbulletchart.js

Sun, 07 Jul 2019 14:31:10 +0200

author
Michiel Broek <mbroek@mbse.eu>
date
Sun, 07 Jul 2019 14:31:10 +0200
branch
stable
changeset 603
fcff55324b84
parent 511
2d1d43c3a2c2
child 617
b216f9d4b917
permissions
-rw-r--r--

Merged fix from default

/*
jQWidgets v4.5.2 (2017-May)
Copyright (c) 2011-2017 jQWidgets.
License: http://jqwidgets.com/license/
*/
!function(a){a.jqx.jqxWidget("jqxBulletChart","",{}),a.extend(a.jqx._jqxBulletChart.prototype,{defineInstance:function(){var b={width:500,height:100,barSize:"50%",ranges:[{startValue:0,endValue:50,color:"#000000",opacity:.7},{startValue:50,endValue:80,color:"#000000",opacity:.5},{startValue:80,endValue:100,color:"#000000",opacity:.3}],pointer:{value:65,label:"Value",size:"25%",color:""},target:{value:85,label:"Target",size:4,color:""},ticks:{position:"far",interval:20,size:10},title:"Title",description:"Description",orientation:"horizontal",labelsFormat:null,labelsFormatFunction:null,animationDuration:400,showTooltip:!0,tooltipFormatFunction:null,disabled:!1,rtl:!1,events:["change"]};return this===a.jqx._jqxBulletChart.prototype?b:(a.extend(!0,this,b),b)},createInstance:function(b){if(!a.jqx.dataAdapter)throw new Error("jqxBulletChart: Missing reference to the following module: 'jqxdata.js'.");this._setDefaultValues(),this.render();var c=this;a.jqx.utilities.resize(this.host,function(){c._timer&&clearTimeout(c._timer),c._timer=setTimeout(function(){var a=c.animationDuration;c.animationDuration=0,c.render(),setTimeout(function(){c.animationDuration=a},0)},10)},!1,!0)},render:function(){this.host.children().length>0&&(this._removeHandlers(),1==this.showTooltip&&this.host.jqxTooltip("destroy"),this.host.empty()),this.host.addClass(this.toThemeProperty("jqx-widget")),this.host.addClass(this.toThemeProperty("jqx-bulletchart")),this.host.width(this.width),this.host.height(this.height);var b,c=this.host.width(),d=this.host.height(),e=this.rtl?"rtl":"ltr";"horizontal"==this.orientation?b=a("<div style='position: absolute; visibility: hidden; padding: 5px;'><div class='"+this.toThemeProperty("jqx-bulletchart-title")+"' style='direction: "+e+";'>"+this.title+"</div><div class='"+this.toThemeProperty("jqx-bulletchart-description")+"' style='direction: "+e+";'>"+this.description+"</div></div>"):"vertical"==this.orientation&&(b=a("<div style='position: absolute; visibility: hidden; padding-bottom: 15px;'><div class='"+this.toThemeProperty("jqx-bulletchart-title")+"' style='width: "+c+"px; direction: "+e+";'>"+this.title+"</div><div class='"+this.toThemeProperty("jqx-bulletchart-description")+"' style='direction: "+e+";'>"+this.description+"</div></div>")),this.host.append(b);var f=b.outerWidth(),g=b.outerHeight();b.remove();var h,i,j,k,l,m,n,o;if("horizontal"==this.orientation){if(h="jqx-bulletchart-title-container-horizontal",i="jqx-bulletchart-chart-container-horizontal",j=this._checkPercentage(this.barSize,this.host),k=f,l=this.barSize,m=0,n=c-k,o=l,this.width&&this.width.toString().indexOf("%")>=0){var n=parseFloat(parseFloat(100*n)/c).toString()+"%",k=parseFloat(parseFloat(100*k)/c).toString()+"%";this._percentageWidth=!0}}else"vertical"==this.orientation&&(h="jqx-bulletchart-title-container-vertical",i="jqx-bulletchart-chart-container-vertical",j=0,k="100%",l=g,m=this._checkPercentage(this.barSize,this.host),n=this.barSize,o=d-l);if((0==this.rtl||1==this.rtl&&"vertical"==this.orientation)&&this.host.append("<div id='"+this.element.id+"titleContainer' class='"+h+"' style='top: "+j+";'></div>"),this.host.append("<div id='"+this.element.id+"ChartContainer' class='"+i+"' style='top: "+j+"; left: "+m+";'></div>"),1==this.rtl&&"horizontal"==this.orientation&&this.host.append("<div id='"+this.element.id+"titleContainer' class='"+h+"' style='top: "+j+";'></div>"),this._titleContainer=a("#"+this.element.id+"titleContainer"),this._chartContainer=a("#"+this.element.id+"ChartContainer"),this._titleContainer.css({width:k,height:l}),this._chartContainer.css({width:n,height:o}),this._min=this.ranges[0].startValue,this._max=this.ranges[this.ranges.length-1].endValue,this._interval=this._max-this._min,this._valueToPixelsHorizontal=this._chartContainer.width()/this._interval,this._valueToPixelsVertical=this._chartContainer.height()/this._interval,this._checkValues(),this._appendRanges(),this._appendPointerAndTarget(),this._appendTitleAndDescription(),"none"!=this.ticks.position&&this._appendTicksAndLabels(),1==this.disabled&&this.host.addClass(this.toThemeProperty("jqx-fill-state-disabled")),1==this.showTooltip){if(void 0==this.host.jqxTooltip)throw new Error("jqxBulletChart: Missing reference to the following module: 'jqxtooltip.js'.");this._initializeTooltip(),this.host.data().jqxWidget=this}this._updateValue(this.pointer.value,0,!0)},refresh:function(a){a||this.render()},val:function(a){return 0==arguments.length||null!=a&&"object"==typeof a?this.pointer.value:(a>this._max?a=this._max:a<this._min&&(a=this._min),void(a!=this.pointer.value&&(this._updateValue(a,this.pointer.value),this.pointer.value=a,1==this.showTooltip&&this._updateTooltip())))},destroy:function(){a.jqx.utilities.resize(this.host,null,!0),this._removeHandlers(),1==this.showTooltip&&this.host.jqxTooltip("destroy"),this.host.remove()},propertyChangedHandler:function(b,c,d,e){if(d!=e||e instanceof Object){var f=!0,g=function(){a.each(d,function(a,d){void 0==e[a]&&(b[c][a]=d)})};switch(c){case"barSize":break;case"ranges":a.each(d,function(d,f){a.each(f,function(a,f){void 0!==e[d]&&void 0==e[d][a]&&(b[c][d][a]=f)})}),this._setDefaultValues();break;case"pointer":return g(),void this._updatePointer(e,d);case"target":return g(),void this._updateTarget(e,d);case"ticks":f=!1,g(),a.each(d,function(a,e){d[a]!=b[c][a]&&(f=!0)});break;case"showTooltip":if(1==e){if(void 0==this.host.jqxTooltip)throw new Error("jqxBulletChart: Missing reference to the following module: 'jqxtooltip.js'.");this._initializeTooltip()}else this._removeHandlers(),this.host.jqxTooltip("destroy");break;case"animationDuration":return;case"tooltipFormatFunction":return void this._updateTooltip();case"disabled":return void(1==e?this.host.addClass(this.toThemeProperty("jqx-fill-state-disabled")):this.host.removeClass(this.toThemeProperty("jqx-fill-state-disabled")))}1==f&&this.render()}},_raiseEvent:function(b,c){var d=this.events[b],e=new a.Event(d);e.owner=this,e.args=c;try{var f=this.host.trigger(e)}catch(a){}return f},_removeHandlers:function(){var b=a("#"+this.element.id+"Pointer, #"+this.element.id+"Target");this.removeHandler(b,"mouseenter.bulletchart"+this.element.id),this.removeHandler(b,"mouseleave.bulletchart"+this.element.id)},_setDefaultValues:function(){for(var a=this.ranges,b=this.ranges.length,c=0;c<b;c++){if(void 0==a[c].startValue||void 0==a[c].endValue)throw new Error("jqxBulletChart: Each range must have its startValue and endValue set.");void 0==a[c].color&&(this.ranges[c].color="#000000"),void 0==a[c].opacity&&(this.ranges[c].opacity=1-1/b*c)}var d=this.pointer;void 0==d.value&&(this.pointer.value=65),void 0==d.label&&(this.pointer.label="Value"),void 0==d.size&&(this.pointer.size="25%"),void 0==d.color&&(this.pointer.color="");var e=this.target;void 0==e.value&&(this.target.value=85),void 0==e.label&&(this.target.label="Target"),void 0==e.size&&(this.target.size=5),void 0==e.color&&(this.target.color="");var f=this.ticks;void 0==f.position&&(this.ticks.position="near"),void 0==f.interval&&(this.ticks.interval=20),void 0==f.size&&(this.ticks.size=10)},_checkValues:function(){this.pointer.value>this._max?this.pointer.value=this._max:this.pointer.value<this._min&&(this.pointer.value=this._min),this.target.value>this._max?this.target.value=this._max:this.target.value<this._min&&(this.target.value=this._min)},_appendRanges:function(){for(var a="",b=this.ranges.length,c=0;c<b;c++){var d,e=this.ranges[c];if("horizontal"==this.orientation){var f=this.rtl?"right":"left",g=(e.startValue-this._min)*this._valueToPixelsHorizontal,h=(e.endValue-e.startValue)*this._valueToPixelsHorizontal;d="<div class='"+this.toThemeProperty("jqx-bulletchart-range")+" "+this.toThemeProperty("jqx-bulletchart-range-horizontal")+"' style='"+f+": "+g+"px; width: "+h+"px; background-color: "+e.color+"; opacity: "+e.opacity+"'></div>"}else if("vertical"==this.orientation){var i=(e.startValue-this._min)*this._valueToPixelsVertical,j=(e.endValue-e.startValue)*this._valueToPixelsVertical;d="<div class='"+this.toThemeProperty("jqx-bulletchart-range")+" "+this.toThemeProperty("jqx-bulletchart-range-vertical")+"' style='bottom: "+i+"px; height: "+j+"px; background-color: "+e.color+"; opacity: "+e.opacity+"'></div>"}a+=d}this._chartContainer.append(a)},_appendPointerAndTarget:function(){var a="",b=this.element.id+"Pointer",c=this.element.id+"Target",d=this.pointer.size,e=this.target.value,f=this.target.size,g=e>0?0:parseInt(f),h=this.pointer.color.length>0?"":this.toThemeProperty("jqx-fill-state-pressed"),i=this.target.color.length>0?"":this.toThemeProperty("jqx-fill-state-pressed");if("horizontal"==this.orientation){var j=this._normaliseValue(d),k=this._checkPercentage(d,this._chartContainer),l=this.rtl?"right":"left",m=(e-this._min)*this._valueToPixelsHorizontal-g,n=m+parseInt(f)-this._chartContainer.width();m<0?m=0:n>0&&(m-=n);var o=this._normaliseValue(f);a+="<div class='"+i+" "+this.toThemeProperty("jqx-bulletchart-target")+" "+this.toThemeProperty("jqx-bulletchart-target-horizontal")+"' id='"+c+"' style='"+l+": "+m+"px; width: "+o+"; background-color: "+this.target.color+"'></div>",a+="<div class='"+h+" "+this.toThemeProperty("jqx-bulletchart-pointer")+"' id='"+b+"' style='top: "+k+"; height: "+j+"; background-color: "+this.pointer.color+"'></div>"}else if("vertical"==this.orientation){var p=(this._chartContainer.width(),this._normaliseValue(d)),q=this._checkPercentage(d,this._chartContainer),r=(e-this._min)*this._valueToPixelsVertical-g,n=r+parseInt(f)-this._chartContainer.height();r<0?r=0:n>0&&(r-=n);var s=this._normaliseValue(f);a+="<div class='"+i+" "+this.toThemeProperty("jqx-bulletchart-target")+" "+this.toThemeProperty("jqx-bulletchart-target-vertical")+"' id='"+c+"' style='bottom: "+r+"px; height: "+s+"; background-color: "+this.target.color+"'></div>",a+="<div class='"+h+" "+this.toThemeProperty("jqx-bulletchart-pointer")+"' id='"+b+"' style='left: "+q+"; width: "+p+"; background-color: "+this.pointer.color+"'></div>"}this._chartContainer.append(a)},_updatePointer:function(b,c){var d=a("#"+this.element.id+"Pointer");if(b.value>this._max?this.pointer.value=this._max:b.value<this._min&&(this.pointer.value=this._min),b.value!=c.value&&(this._updateValue(b.value,c.value),1==this.showTooltip&&this._updateTooltip()),b.label!=c.label&&1==this.showTooltip&&this._updateTooltip(),b.size!=c.size){var e=b.size;if("horizontal"==this.orientation){var f=this._checkPercentage(e,this._chartContainer),g=this._normaliseValue(e);d.css({top:f,height:g})}else if("vertical"==this.orientation){var h=this._checkPercentage(e,this._chartContainer),i=this._normaliseValue(e);d.css({left:h,width:i})}}b.color!=c.color&&(""==b.color?(d.css("background-color",""),d.addClass(this.toThemeProperty("jqx-fill-state-pressed"))):(d.removeClass(this.toThemeProperty("jqx-fill-state-pressed")),d.css("background-color",b.color)))},_updateTarget:function(b,c){var d=a("#"+this.element.id+"Target");if(b.value>this._max?this.target.value=this._max:b.value<this._min&&(this.target.value=this._min),b.value!=c.value||b.size!=c.size){var e=b.value,f=parseInt(b.size),g=e>0?0:f;if("horizontal"==this.orientation){var h=(this.rtl?"right":"left",(e-this._min)*this._valueToPixelsHorizontal-g),i=h+f-this._chartContainer.width();h<0?h=0:i>0&&(h-=i),0==this.rtl?d.css("left",h):d.css("right",h),d.width(f)}else if("vertical"==this.orientation){var j=(e-this._min)*this._valueToPixelsVertical-g,i=j+f-this._chartContainer.height();j<0?j=0:i>0&&(j-=i),d.css({bottom:j,height:f})}1==this.showTooltip&&this._updateTooltip()}b.label!=c.label&&1==this.showTooltip&&this._updateTooltip(),b.color!=c.color&&(""==b.color?(d.css("background-color",""),d.addClass(this.toThemeProperty("jqx-fill-state-pressed"))):(d.removeClass(this.toThemeProperty("jqx-fill-state-pressed")),d.css("background-color",b.color)))},_appendTitleAndDescription:function(){var b;b="horizontal"==this.orientation?1==this.rtl?this.toThemeProperty("jqx-bulletchart-title-description-rtl"):this.toThemeProperty("jqx-bulletchart-title-description-ltr"):this.toThemeProperty("jqx-bulletchart-title-description-vertical");var c=this.rtl?"rtl":"ltr",d="<div id='"+this.element.id+"Title' class='"+this.toThemeProperty("jqx-bulletchart-title")+" "+b+"' style='direction: "+c+";'>"+this.title+"</div><div id='"+this.element.id+"Description' class='"+this.toThemeProperty("jqx-bulletchart-description")+" "+b+"' style='direction: "+c+";'>"+this.description+"</div>",e=a("<div style='position: absolute; visibility: hidden;'>"+d+"</div>");this._titleContainer.append(e);var f=e.children(),g=a(f[0]).height()+a(f[1]).height();e.remove();var h;h="horizontal"==this.orientation?0==this.rtl?this.toThemeProperty("jqx-bulletchart-title-inner-container")+" "+this.toThemeProperty("jqx-bulletchart-title-inner-container-ltr"):this.toThemeProperty("jqx-bulletchart-title-inner-container")+" "+this.toThemeProperty("jqx-bulletchart-title-inner-container-rtl"):"",this._titleContainer.append("<div class='"+h+"' style='height: "+g+"px;'>"+d+"</div>")},_appendTicksAndLabels:function(){var b=a("<div style='position: absolute; visibility: hidden;'></div>");this._chartContainer.append(b);var c="",d=this._min<0,e=this.ticks.size;if("horizontal"==this.orientation){var f=this._titleContainer.width(),g=this._chartContainer.offset().top-this.host.offset().top;if("both"==this.ticks.position||"far"==this.ticks.position)var h=this._chartContainer.height()+g;for(var i=0;i<=this._interval;i+=this.ticks.interval){var j=i*this._valueToPixelsHorizontal+f;if(i+this.ticks.interval>this._interval&&(j-=1),d){var k=i+this._min==0;k&&(c+="<div class='"+this.toThemeProperty("jqx-bulletchart-ticks")+" "+this.toThemeProperty("jqx-bulletchart-ticks-horizontal")+" "+this.toThemeProperty("jqx-bulletchart-zero-tick")+"' style='top: "+g+"px; "+n+": "+j+"px; height: "+this._chartContainer.height()+"px;'></div>",d=!1)}var l=this._labelValue(i);b.html(l);var m=j-b.width()/2,n=this.rtl?"right":"left";"both"!=this.ticks.position&&"far"!=this.ticks.position||(c+="<div class='"+this.toThemeProperty("jqx-bulletchart-ticks")+" "+this.toThemeProperty("jqx-bulletchart-ticks-horizontal")+"' style='top: "+h+"px; "+n+": "+j+"px; height: "+e+"px;'></div>",c+="<div class='"+this.toThemeProperty("jqx-bulletchart-labels")+"' style='top: "+(h+e+2)+"px; "+n+": "+m+"px;'>"+l+"</div>"),"both"!=this.ticks.position&&"near"!=this.ticks.position||(c+="<div class='"+this.toThemeProperty("jqx-bulletchart-ticks")+" "+this.toThemeProperty("jqx-bulletchart-ticks-horizontal")+"' style='top: "+(g-e)+"px; "+n+": "+j+"px; height: "+e+"px;'></div>",c+="<div class='"+this.toThemeProperty("jqx-bulletchart-labels")+"' style='top: "+(g-(e+b.height()+2))+"px; "+n+": "+m+"px;'>"+l+"</div>")}}else if("vertical"==this.orientation){var o=this._chartContainer.offset().left-this.host.offset().left;if("both"==this.ticks.position||"far"==this.ticks.position)var p=this._chartContainer.width();for(var i=0;i<=this._interval;i+=this.ticks.interval){var q=i*this._valueToPixelsVertical;if(i+this.ticks.interval>this._interval&&(q-=1),d){var k=i+this._min==0;k&&(c+="<div class='"+this.toThemeProperty("jqx-bulletchart-ticks")+" "+this.toThemeProperty("jqx-bulletchart-ticks-vertical")+" "+this.toThemeProperty("jqx-bulletchart-zero-tick")+"' style='left: "+o+"px; bottom: "+q+"px; width: "+p+"px;'></div>",d=!1)}if("both"==this.ticks.position||"near"==this.ticks.position){c+="<div class='"+this.toThemeProperty("jqx-bulletchart-ticks")+" "+this.toThemeProperty("jqx-bulletchart-ticks-vertical")+"' style='left: "+(o-e)+"px; bottom: "+q+"px; width: "+e+"px;'></div>";var l=this._labelValue(i,"near");b.html(l);var m=b.height()/2-1;c+="<div class='"+this.toThemeProperty("jqx-bulletchart-labels")+"' style='left: "+(o-(e+b.width()+2))+"px; bottom: "+(q-m)+"px;'>"+l+"</div>"}if("both"==this.ticks.position||"far"==this.ticks.position){c+="<div class='"+this.toThemeProperty("jqx-bulletchart-ticks")+" "+this.toThemeProperty("jqx-bulletchart-ticks-vertical")+"' style='left: "+(p+o)+"px; bottom: "+q+"px; width: "+e+"px;'></div>";var l=this._labelValue(i,"far");b.html(l);var m=b.height()/2-1;c+="<div class='"+this.toThemeProperty("jqx-bulletchart-labels")+"' style='left: "+(p+o+e+2)+"px; bottom: "+(q-m)+"px;'>"+l+"</div>"}}}this.host.append(c),b.remove()},_labelValue:function(b,c){var d,e=b+this._min;return d=this.labelsFormatFunction?this.labelsFormatFunction(e,c):a.jqx.dataFormat.formatnumber(e,this.labelsFormat)},_initializeTooltip:function(){var b=this,c=this._tooltipContent();this.host.jqxTooltip({theme:this.theme,position:"mouse",content:c,trigger:"none",autoHide:!1,rtl:this.rtl}),this.host.jqxTooltip("getInstance").val=a.proxy(this.val,this);var d=a("#"+this.element.id+"Pointer, #"+this.element.id+"Target");this.addHandler(d,"mouseenter.bulletchart"+this.element.id,function(c){0==b.disabled&&(b.host.jqxTooltip("open",c.pageX,c.pageY),(c.target.id==b.element.id+"Pointer"&&""==b.pointer.color||c.target.id==b.element.id+"Target"&&""==b.target.color)&&(a(c.target).removeClass(b.toThemeProperty("jqx-fill-state-pressed")),a(c.target).addClass(b.toThemeProperty("jqx-fill-state-hover"))))}),this.addHandler(d,"mouseleave.bulletchart"+this.element.id,function(c){0==b.disabled&&(b.host.jqxTooltip("close"),(c.target.id==b.element.id+"Pointer"&&""==b.pointer.color||c.target.id==b.element.id+"Target"&&""==b.target.color)&&(a(c.target).removeClass(b.toThemeProperty("jqx-fill-state-hover")),a(c.target).addClass(b.toThemeProperty("jqx-fill-state-pressed"))))})},_updateTooltip:function(){this.host.jqxTooltip({content:this._tooltipContent()})},_tooltipContent:function(){var b;if(this.tooltipFormatFunction)b=this.tooltipFormatFunction(this.pointer.value,this.target.value);else{var c=a.jqx.dataFormat.formatnumber(this.pointer.value,this.labelsFormat),d=a.jqx.dataFormat.formatnumber(this.target.value,this.labelsFormat);b="<div>"+this.pointer.label+": "+c+"</div><div>"+this.target.label+": "+d+"</div>"}return b},_updateValue:function(b,c,d){var e,f,g,h=this,i=a("#"+this.element.id+"Pointer"),j=function(a,d,j){if(h._min>=0)"vertical"==a?i.css("bottom",0):1==h.rtl&&"horizontal"==a&&i.css("right",0),e=(b-h._min)*d;else{if(b>=0){"horizontal"==a?1==h.rtl?(f="right",g="left"):f="left":"vertical"==a&&(f="bottom",g="top");var k=-h._min*d}else{"horizontal"==a?1==h.rtl?f="left":(f="right",g="left"):"vertical"==a&&(f="top");var k=j+h._min*d}i.css(f,k),g&&i.css(g,""),b*c<0&&("horizontal"==a?i.width(0):"vertical"==a&&i.height(0)),e=Math.abs(b*d)}return e},k=function(){d||h._raiseEvent("0")};if("horizontal"==this.orientation){var l=j("horizontal",this._valueToPixelsHorizontal,this._chartContainer.width());setTimeout(function(){i.animate({width:l},h.animationDuration,k)},0)}else if("vertical"==this.orientation){var m=j("vertical",this._valueToPixelsVertical,this._chartContainer.height());setTimeout(function(){i.animate({height:m},h.animationDuration,k)},0)}},_checkPercentage:function(a,b){var c=-1;a.indexOf&&(c=a.indexOf("%"));var d=function(b){return a.indexOf&&a.indexOf("px")!=-1?parseFloat(b.slice(0,a.indexOf("px"))):b},e=function(a){return parseFloat(a.slice(0,c))};if(c==-1){var f;return"horizontal"==this.orientation?f=b.height():"vertical"==this.orientation&&(f=b.width()),(f-d(a))/2+"px"}return(100-e(a))/2+"%"},_normaliseValue:function(a){return!a.indexOf||a.indexOf("px")==-1&&a.indexOf("%")==-1?a+"px":a}})}(jqxBaseFramework);

mercurial