line.js 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196
  1. function Line(opts){
  2. opts=opts||{};
  3. this.id=null;
  4. this.smpTime=opts.smpTime;
  5. this.color=opts.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. initData:function(xVals,yVals,extraObj){
  33. this.xProjs=xVals;
  34. this.yProjs=yVals;
  35. this.yMax=extraObj.glbMax;
  36. this.yMin=extraObj.glbMin;
  37. this.xMax=extraObj.stroke;
  38. this.xMin=0;
  39. this.datas=[];
  40. this.datas.push([xVals[0],yVals[0]]);
  41. for (var i=1,len=xVals.length,len2=yVals.length;i<len&&i<len2;i++ ) {
  42. this.datas.push([xVals[i],yVals[i]]);
  43. }
  44. //闭合曲线
  45. this.datas.push([xVals[0],yVals[0]]);
  46. //确定上下行
  47. this.startUp = (this.xMax- this.xProjs[0]) > (this.xProjs[0] - this.xMin);
  48. if (this.startUp) {
  49. this.colorAry=[this.upColor,this.downColor];
  50. }
  51. else {
  52. this.colorAry=[this.downColor,this.upColor];
  53. }
  54. this.turnIndex=extraObj.turnIndex;
  55. //平衡度
  56. this.balance=extraObj.balance;
  57. //上下行最大
  58. this.yUpMaxProj=extraObj.upMax;
  59. this.yDownMaxProj=extraObj.downMax;
  60. //冲程
  61. this.stroke=extraObj.stroke;
  62. },
  63. setData:function(xVals,yVals){
  64. this.xProjs=xVals;
  65. this.yProjs=yVals;
  66. this.yMax=yVals[0];
  67. this.yMin=yVals[0];
  68. this.xMax=xVals[0];
  69. this.xMin=xVals[0];
  70. this.datas=[];
  71. this.datas.push([xVals[0],yVals[0]]);
  72. var upIndex,dwnIndex;
  73. for (var i=1,len=xVals.length,len2=yVals.length;i<len&&i<len2;i++ ) {
  74. this.datas.push([xVals[i],yVals[i]]);
  75. if(yVals[i]>this.yMax){
  76. this.yMax=yVals[i];
  77. }
  78. if(yVals[i]<this.yMin){
  79. this.yMin=yVals[i];
  80. }
  81. if(xVals[i]>=this.xMax){ //增加或=,表明停顿区域算入开始方向
  82. this.xMax=xVals[i];
  83. upIndex=i;
  84. }
  85. if(xVals[i]<=this.xMin){
  86. this.xMin=xVals[i];
  87. dwnIndex=i;
  88. }
  89. }
  90. //闭合曲线
  91. this.datas.push([xVals[0],yVals[0]]);
  92. this.stroke=Math.round((this.xMax- this.xMin) * 100) / 100;
  93. var tempStroke=Math.floor(this.stroke);
  94. if(this.stroke-tempStroke<0.05){
  95. this.stroke=tempStroke;
  96. }
  97. var tempXMax=Math.floor(this.xMax);
  98. this.xMax= (this.xMax- tempXMax) >= 0.05?Math.ceil(this.xMax):tempXMax;
  99. this.yOrigMax=this.yMax;
  100. this.yOrigMin=this.yMin;
  101. this.parseUpDwnMax(upIndex,dwnIndex);
  102. this.countBalance();
  103. },
  104. parseUpDwnMax:function(upIdx,dwnIdx){
  105. this.startUp = (this.xMax- this.xProjs[0]) > (this.xProjs[0] - this.xMin);
  106. if (this.startUp) {
  107. this.colorAry=[this.upColor,this.downColor];
  108. }
  109. else {
  110. this.colorAry=[this.downColor,this.upColor];
  111. }
  112. this.turnIndex=this.startUp?upIdx:dwnIdx;
  113. if(this.type=="GT"){
  114. return;
  115. }
  116. var tempMax1=-1000;
  117. var tempMax2=-1000;
  118. for(var i=0,len=this.xProjs.length,len2=this.yProjs.length;i<len&&i<len2;i++){
  119. if(i<=this.turnIndex){
  120. tempMax1=tempMax1<this.yProjs[i]?this.yProjs[i]:tempMax1;
  121. }
  122. else{
  123. tempMax2=tempMax2<this.yProjs[i]?this.yProjs[i]:tempMax2;
  124. }
  125. }
  126. this.yUpMaxProj=this.startUp?tempMax1:tempMax2;
  127. this.yDownMaxProj=this.startUp?tempMax2:tempMax1;
  128. },
  129. getDesc:function(){ //曲线描述文本,其它文本由外部传入
  130. var txt=[];
  131. txt.push("冲程:"+this.stroke+this.xUnit)
  132. if(this.type=="GT"){
  133. txt.push("最大载荷:"+this.yMax+this.yUnit);
  134. txt.push("最小载荷:"+this.yMin+this.yUnit);
  135. }
  136. else{
  137. txt.push("上行最大:"+this.yUpMaxProj+this.yUnit);
  138. txt.push("下行最大:"+this.yDownMaxProj+this.yUnit);
  139. txt.push("平衡度:"+this.balance);
  140. }
  141. return txt;
  142. },
  143. countBalance:function(){ //计算平衡度,默认是不计算值为0
  144. this.balance=0;
  145. if(this.type=="DL"){ //电流曲线平衡度计算
  146. this.balance=Math.round(this.yUpMaxProj*100*100/this.yDownMaxProj)/100; //带两位小数
  147. }
  148. else if(this.type=="DGL"){ //功率曲线平衡度计算
  149. var sumArea1=0;
  150. var sumArea2=0;
  151. var i;
  152. var h;
  153. var tempSum;
  154. for(i=0;i<this.xProjs.length-1&&i<this.yProjs.length-1;i++){
  155. h=Math.abs(this.xProjs[i+1]-this.xProjs[i]);
  156. tempSum=(this.yProjs[i+1]+this.yProjs[i])*h/2;
  157. if((i+1)<=this.turnIndex){
  158. sumArea1+=tempSum;
  159. }
  160. else{
  161. sumArea2+=tempSum;
  162. }
  163. }
  164. this.balance=this.startUp?(sumArea1/sumArea2):(sumArea2/sumArea1);
  165. this.balance=Math.round(this.balance*100*100)/100;
  166. }
  167. }
  168. };
  169. export {Line}