line.js 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  1. function Line(opts){
  2. opts=opts||{};
  3. this.id=null;
  4. this.smpTime=opts.smpTime;
  5. this.color="#000000";
  6. this.title=null;
  7. this.weight=1;
  8. this.type=opts.type||"GT";
  9. this.xUnit=opts.xUnit||"m";
  10. this.yUnit=opts.yUnit||"kN";
  11. this.xMin=null;
  12. this.xMax=null;
  13. this.yMin=null;
  14. this.yMax=null;
  15. this.xProjs=null;
  16. this.yProjs=null;
  17. this.datas=null;
  18. this.yOrigMax=null;
  19. this.yOrigMin=null;
  20. this.turnX=null;
  21. this.turnIndex=null;
  22. this.startUp=true;
  23. this.upColor="#0000ff";
  24. this.downColor="#00ff00";
  25. this.colorAry=[];
  26. this.yUpMaxProj=null;
  27. this.yDownMaxProj=null;
  28. this.balance=null;
  29. this.stroke=null;
  30. }
  31. Line.prototype={
  32. setData:function(xVals,yVals){
  33. this.xProjs=xVals;
  34. this.yProjs=yVals;
  35. this.yMax=yVals[0];
  36. this.yMin=yVals[0];
  37. this.xMax=xVals[0];
  38. this.xMin=xVals[0];
  39. this.datas=[];
  40. this.datas.push([xVals[0],yVals[0]]);
  41. var upIndex,dwnIndex;
  42. for (var i=1,len=xVals.length,len2=yVals.length;i<len&&i<len2;i++ ) {
  43. this.datas.push([xVals[i],yVals[i]]);
  44. if(yVals[i]>this.yMax){
  45. this.yMax=yVals[i];
  46. }
  47. if(yVals[i]<this.yMin){
  48. this.yMin=yVals[i];
  49. }
  50. if(xVals[i]>=this.xMax){ //增加或=,表明停顿区域算入开始方向
  51. this.xMax=xVals[i];
  52. upIndex=i;
  53. }
  54. if(xVals[i]<=this.xMin){
  55. this.xMin=xVals[i];
  56. dwnIndex=i;
  57. }
  58. }
  59. //闭合曲线
  60. this.datas.push([xVals[0],yVals[0]]);
  61. this.stroke=Math.round((this.xMax- this.xMin) * 100) / 100;
  62. var tempStroke=Math.floor(this.stroke);
  63. if(this.stroke-tempStroke<0.05){
  64. this.stroke=tempStroke;
  65. }
  66. var tempXMax=Math.floor(this.xMax);
  67. this.xMax= (this.xMax- tempXMax) >= 0.05?this.xMaxProj:tempXMax;
  68. this.yOrigMax=this.yMax;
  69. this.yOrigMin=this.yMin;
  70. this.parseUpDwnMax(upIndex,dwnIndex);
  71. this.countBalance();
  72. },
  73. parseUpDwnMax:function(upIdx,dwnIdx){
  74. this.startUp = (this.xMax- this.xProjs[0]) > (this.xProjs[0] - this.xMin);
  75. if (this.startUp) {
  76. this.colorAry=[this.upColor,this.downColor];
  77. }
  78. else {
  79. this.colorAry=[this.downColor,this.upColor];
  80. }
  81. this.turnIndex=this.startUp?upIdx:dwnIdx;
  82. if(this.type=="GT"){
  83. return;
  84. }
  85. var tempMax1=-1000;
  86. var tempMax2=-1000;
  87. for(var i=0,len=this.xProjs.length,len2=this.yProjs.length;i<len&&i<len2;i++){
  88. if(i<=this.turnIndex){
  89. tempMax1=tempMax1<this.yProjs[i]?this.yProjs[i]:tempMax1;
  90. }
  91. else{
  92. tempMax2=tempMax2<this.yProjs[i]?this.yProjs[i]:tempMax2;
  93. }
  94. }
  95. this.yUpMaxProj=this.startUp?tempMax1:tempMax2;
  96. this.yDownMaxProj=this.startUp?tempMax2:tempMax1;
  97. },
  98. getDesc:function(){ //曲线描述文本,其它文本由外部传入
  99. var txt=[];
  100. txt.push("冲程:"+this.stroke+this.xUnit)
  101. if(this.type=="GT"){
  102. txt.push("最大载荷:"+this.yMax+this.yUnit);
  103. txt.push("最小载荷:"+this.yMin+this.yUnit);
  104. }
  105. else{
  106. txt.push("上行最大:"+this.yUpMaxProj+this.yUnit);
  107. txt.push("下行最大:"+this.yDownMaxProj+this.yUnit);
  108. txt.push("平衡度:"+this.balance);
  109. }
  110. return txt;
  111. },
  112. countBalance:function(){ //计算平衡度,默认是不计算值为0
  113. this.balance=0;
  114. if(this.type=="DL"){ //电流曲线平衡度计算
  115. this.balance=Math.round(this.yUpMaxProj*100*100/this.yDownMaxProj)/100; //带两位小数
  116. }
  117. else if(this.type=="DGL"){ //功率曲线平衡度计算
  118. var sumArea1=0;
  119. var sumArea2=0;
  120. var i;
  121. var h;
  122. var tempSum;
  123. for(i=0;i<this.xProjs.length-1&&i<this.yProjs.length-1;i++){
  124. h=Math.abs(this.xProjs[i+1]-this.xProjs[i]);
  125. tempSum=(this.yProjs[i+1]+this.yProjs[i])*h/2;
  126. if((i+1)<=this.turnIndex){
  127. sumArea1+=tempSum;
  128. }
  129. else{
  130. sumArea2+=tempSum;
  131. }
  132. }
  133. this.balance=this.startUp?(sumArea1/sumArea2):(sumArea2/sumArea1);
  134. this.balance=Math.round(this.balance*100*100)/100;
  135. }
  136. }
  137. };
  138. export {Line}