123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157 |
- function Line(opts){
- opts=opts||{};
- this.id=null;
- this.smpTime=opts.smpTime;
- this.color="#000000";
- this.title=null;
- this.weight=1;
- this.type=opts.type||"GT";
- this.xUnit=opts.xUnit||"m";
- this.yUnit=opts.yUnit||"kN";
- this.xMin=null;
- this.xMax=null;
- this.yMin=null;
- this.yMax=null;
- this.xProjs=null;
- this.yProjs=null;
- this.datas=null;
- this.yOrigMax=null;
- this.yOrigMin=null;
- this.turnX=null;
- this.turnIndex=null;
- this.startUp=true;
- this.upColor="#0000ff";
- this.downColor="#00ff00";
- this.colorAry=[];
- this.yUpMaxProj=null;
- this.yDownMaxProj=null;
- this.balance=null;
- this.stroke=null;
- }
- Line.prototype={
- setData:function(xVals,yVals){
- this.xProjs=xVals;
- this.yProjs=yVals;
-
- this.yMax=yVals[0];
- this.yMin=yVals[0];
- this.xMax=xVals[0];
- this.xMin=xVals[0];
- this.datas=[];
- this.datas.push([xVals[0],yVals[0]]);
- var upIndex,dwnIndex;
- for (var i=1,len=xVals.length,len2=yVals.length;i<len&&i<len2;i++ ) {
- this.datas.push([xVals[i],yVals[i]]);
- if(yVals[i]>this.yMax){
- this.yMax=yVals[i];
- }
- if(yVals[i]<this.yMin){
- this.yMin=yVals[i];
- }
- if(xVals[i]>=this.xMax){ //增加或=,表明停顿区域算入开始方向
- this.xMax=xVals[i];
- upIndex=i;
- }
- if(xVals[i]<=this.xMin){
- this.xMin=xVals[i];
- dwnIndex=i;
- }
- }
-
- //闭合曲线
- this.datas.push([xVals[0],yVals[0]]);
-
- this.stroke=Math.round((this.xMax- this.xMin) * 100) / 100;
- var tempStroke=Math.floor(this.stroke);
- if(this.stroke-tempStroke<0.05){
- this.stroke=tempStroke;
- }
-
- var tempXMax=Math.floor(this.xMax);
- this.xMax= (this.xMax- tempXMax) >= 0.05?this.xMaxProj:tempXMax;
- this.yOrigMax=this.yMax;
- this.yOrigMin=this.yMin;
- this.parseUpDwnMax(upIndex,dwnIndex);
- this.countBalance();
- },
-
- parseUpDwnMax:function(upIdx,dwnIdx){
-
- this.startUp = (this.xMax- this.xProjs[0]) > (this.xProjs[0] - this.xMin);
- if (this.startUp) {
- this.colorAry=[this.upColor,this.downColor];
- }
- else {
- this.colorAry=[this.downColor,this.upColor];
- }
- this.turnIndex=this.startUp?upIdx:dwnIdx;
-
- if(this.type=="GT"){
- return;
- }
- var tempMax1=-1000;
- var tempMax2=-1000;
- for(var i=0,len=this.xProjs.length,len2=this.yProjs.length;i<len&&i<len2;i++){
- if(i<=this.turnIndex){
- tempMax1=tempMax1<this.yProjs[i]?this.yProjs[i]:tempMax1;
- }
- else{
- tempMax2=tempMax2<this.yProjs[i]?this.yProjs[i]:tempMax2;
- }
-
- }
- this.yUpMaxProj=this.startUp?tempMax1:tempMax2;
- this.yDownMaxProj=this.startUp?tempMax2:tempMax1;
-
- },
-
- getDesc:function(){ //曲线描述文本,其它文本由外部传入
- var txt=[];
-
- txt.push("冲程:"+this.stroke+this.xUnit)
- if(this.type=="GT"){
- txt.push("最大载荷:"+this.yMax+this.yUnit);
- txt.push("最小载荷:"+this.yMin+this.yUnit);
- }
- else{
- txt.push("上行最大:"+this.yUpMaxProj+this.yUnit);
- txt.push("下行最大:"+this.yDownMaxProj+this.yUnit);
- txt.push("平衡度:"+this.balance);
- }
-
- return txt;
- },
-
- countBalance:function(){ //计算平衡度,默认是不计算值为0
- this.balance=0;
- if(this.type=="DL"){ //电流曲线平衡度计算
- this.balance=Math.round(this.yUpMaxProj*100*100/this.yDownMaxProj)/100; //带两位小数
- }
- else if(this.type=="DGL"){ //功率曲线平衡度计算
- var sumArea1=0;
- var sumArea2=0;
- var i;
- var h;
- var tempSum;
- for(i=0;i<this.xProjs.length-1&&i<this.yProjs.length-1;i++){
- h=Math.abs(this.xProjs[i+1]-this.xProjs[i]);
- tempSum=(this.yProjs[i+1]+this.yProjs[i])*h/2;
- if((i+1)<=this.turnIndex){
- sumArea1+=tempSum;
- }
- else{
- sumArea2+=tempSum;
- }
- }
-
- this.balance=this.startUp?(sumArea1/sumArea2):(sumArea2/sumArea1);
- this.balance=Math.round(this.balance*100*100)/100;
- }
-
-
-
- }
- };
- export {Line}
|