/
SoRusV
/
src_xendil
Обзор
Документация
Войти
/
SoRusV
/
src_xendil
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
Аналитика
Безопасность
master
html/src/ChartTime.js
2 030 строк
76 KB
ruslan
Initial commit
29 окт 2024, 11:18
29 окт 2024, 11:18
5c4dcf5
Код
Авторство
О чём код?
/// test line 720 console.log("Hours="+a.getHours()); in android function Sec2Time(S){ /// '23:03' let h=Math.floor(S/3600); let m=Math.floor((S-h*3600)/60); if (m < 10) m = "0" + m; return {'H':h,'M':m}; }; function MChartTime(JParam, AParamL0, AADataL0, AParamR0, AADataR0) { // console.log("");//'AParamL0='+JSON.stringify(AParamL0)); function MPoint() { let th = this; // let svg=svg_; th.Sec=0; th.V=0; /// Value th.Selected=false; th.Color='#000000'; th.Visible=false; th.Circle=GetNode(svg, "circle", {cx: -100, cy: -100, r:0, fill: '#000000', stroke: '#BBBBBB', 'stroke-width': 1}); th.Circle.style.cursor=CircleCursor;//'pointer'; th.Circle.style.display='none'; th.Line=GetNode(svgCrd, "line", {x1: -100, y1: -100, x2: -100, y2: -100, stroke: '#000000', 'stroke-width': 0}); th.Line.style.display='none'; th.Free=function(){ th.Circle.remove(); th.Line.remove(); }; th.Selecte=function (Selected_) { th.Selected = Selected_; if (th.Selected) SetNode(th.Circle, {fill: '#7c3f31'}); else SetNode(th.Circle, {fill: th.Color}); }; th.GetPointToJson=function(bFull){ let T=Sec2Time(th.Sec); T=T.H+":"+T.M; if(bFull) return [T,th.V]; return [T,Number(Number(th.V).toFixed(5))]; }; // th.Refresh=function (RCrd){//x,y){ // let xy = Crd2Crd(RCrd, RSvg, {x: th.Sec, y: th.V}); // SetNode(th.Circle, {cx: xy.x, cy: xy.y}); // }; th.SetColor=function(Color){ th.Color=Color; SetNode(th.Circle,{fill:Color}); SetNode(th.Line,{stroke:Color}); }; th.Show=function (Visible_) { th.Visible=Visible_; SetVisible(th.Circle, th.Visible); SetVisible(th.Line, th.Visible); }; }; function MSeries() { let th = this; // svg=svg_; th.RCrd={x0:0, y0:0, x1:0, y1:0}; /// rect coordinate of axis th.Color='#000000'; th.Visible=false; th.Active=true; th.AP = []; /// array of MPoints th.CircleR=0; th.IndexChanel=-1; th.LineW=1; th.Index=-1; th.GPIO_PWM="-"; th.AS; /// String th.ASR="ASL" or th.ASL="ASR" onSelect=JParam.onSelect; th.JParam={}; /// th.JParam = {"Regime":2,"Name":"Main","Color":16777215,"PWM":-1,"Lm":0,"Lux":0,"W":0} let Line=GetNode(svgCrd, "line", {x1: -100, y1: -100, x2: -100, y2: -100, stroke: th.Color, 'stroke-width': 0}); /// last line Line.style.display='none'; th.Free=function() { for(let iP=0; iP<th.AP.length; iP++){ th.AP[iP].Free(); delete th.AP[iP]; } AP=[]; }; th.FindPoint=function(Sec) { for (let iP = 0; iP < th.AP.length; iP++) if (th.AP[iP].Sec == Sec) return iP; return -1; }; th.SetPointCount=function(Count)//, _Color) { if (Count < th.AP.length) {/// delete elements for(let iP = Count ; iP<th.AP.length; iP++) { th.AP[iP].Free(); delete th.AP[iP]; } th.AP.splice(Count, th.AP.length - Count); } else/// add elements for(let iP = th.AP.length; iP < Count; iP++) th.AP[iP] = new MPoint();//svg); }; th.Data2Series=function(ATimeV, JParam_) /// [[00:00, 0],...] /// JParam_ = {"Regime":2,"Name":"Main","Color":16777215,"PWM":-1,"Lm":0,"Lux":0,"W":0} { //Color=Color_; // console.log('ATimeV='+JSON.stringify(ATimeV)) if(JParam_) th.JParam=JParam_; // th.JParam['%']=100; if (ATimeV.length != th.AP.length) th.SetPointCount(ATimeV.length); // console.log(th.AP.length); for (let iP = 0; iP < ATimeV.length; iP++) { // console.log(ATimeV[iP][0]) th.AP[iP].Sec = Time2Sec(ATimeV[iP][0]); th.AP[iP].V = ATimeV[iP][1]; // console.log(th.AP[iP].Sec); //console.log(th.AP[iP].Circle); // SetNode(th.AP[iP].Circle,{}); } // console.log(th.Color) // console.log(th.CircleR) // console.log(th.LineW) //if(th.Color) th.SetStyle();//-1), th.Color, th.CircleR, th.LineW); //for (let iP = 0; iP < th.AP.length; iP++) // console.log(th.AP[iP].Circle); }; th.GetSeriesToJson=function (bFull) { ///{PWM:3, LP:[['09:03', 0.142], ['21:03', 0.13]]} let J={}; J.GPIO_PWM=th.JParam.GPIO_PWM; J.LP=[]; // let S=th.JParam.GPIO_PWM; for(let iP=0; iP<th.AP.length; iP++) J.LP.push(th.AP[iP].GetPointToJson(bFull)); // J[S]=A; return J; }; th.SetStyle=function(iP, Color, CircleR, LineW){ let iPMin=0; let iPMax=th.AP.length-1; if(iP==undefined) iP=-1; if(iP>=0) { iPMin=iP; iPMax=iP; } if(Color) th.Color=Color; if(CircleR) th.CircleR=CircleR; if(LineW) th.LineW=LineW; for(let iP=iPMin; iP<=iPMax; iP++) { th.AP[iP].SetColor(th.Color); // SetNode(th.AP[iP].Circle, {r:th.CircleR}); // SetNode(th.AP[iP].Line, {'stroke-width':th.LineW}); // th.AP[iP].Circle.style.cursor = 'pointer'; } // if(iP<0) SetNode(Line, {stroke: th.Color});//, 'stroke-width':th.LineW}) }; th.SetActive=function(Active_){ th.Active=Active_; // if(th.Active) // th.SetStyle();//th.Color, th.CircleR, th.LineW); // else{ // for(let iP=0; iP<th.AP.length; iP++) { // SetNode(th.AP[iP].Circle, {r:1}) // SetNode(th.AP[iP].Line, {'stroke-width':0.5}) // th.AP[iP].Circle.style.cursor = 'default'; // } // SetNode(Line, {'stroke-width':0.5}) // } th.Show(th.Visible); // for(let iP = 0; iP < th.AP.length; iP++) // th.AP[iP].SetActive(Active); // if(Active) // Line }; th.Refresh=function() { let SUnit=1; if(Unit && th.JParam[Unit]) SUnit=th.JParam[Unit]; // else // SUnit=SUnit; // console.log("PWM="+th.PWM); if(th.AP.length>0){ let xyLast = {}; for(let iP = 0; iP < th.AP.length; iP++) { // th.AP[iP].Refresh(th.RCrd); // th.Refresh=function (RCrd){//x,y){ let xy = Crd2Crd(th.RCrd, RSvg, {x: th.AP[iP].Sec, y: th.AP[iP].V*SUnit}); // console.log("iP="+iP); // console.log("V="+th.AP[iP].V); // console.log(SUnit) SetNode(th.AP[iP].Circle, {cx: xy.x, cy: xy.y}); // let xy = Crd2Crd(RCrdL, RSvg, {x: AP[i].Sec, y: AP[i].V}) // SetNode(ACircleL[i], {cx: xy.x, cy: xy.y}); // console.log(th.AP[i]); xy = Crd2Crd(th.RCrd, RSvgCrd, {x: th.AP[iP].Sec, y: th.AP[iP].V*SUnit}); // console.log(xy); if (iP > 0) SetNode(th.AP[iP].Line, {x1: xyLast.x, y1: xyLast.y, x2: xy.x, y2: xy.y}); xyLast = xy; } let dx = th.AP[0].Sec + 3600 * 24 - th.AP[th.AP.length - 1].Sec; let xy0 = Crd2Crd(th.RCrd, RSvgCrd, {x: th.AP[0].Sec, y: th.AP[0].V*SUnit}); let xy1 = Crd2Crd(th.RCrd, RSvgCrd, {x: th.AP[0].Sec-dx, y: th.AP[th.AP.length-1].V*SUnit}); SetNode(th.AP[0].Line, {x1: xy0.x, y1: xy0.y, x2: xy1.x, y2: xy1.y}); xy1 = Crd2Crd(th.RCrd, RSvgCrd, {x: th.AP[th.AP.length-1].Sec+dx, y: th.AP[0].V*SUnit}); SetNode(Line, {x1: xyLast.x, y1: xyLast.y, x2: xy1.x, y2: xy1.y}); } }; th.GetClosePoint=function(Sec){ /// return index of close point to Sec let dSecMin=Math.abs(th.AP[0].Sec-Sec); let iMin=0; for(let iP=1; iP<th.AP.length; iP++) if(Math.abs(th.AP[iP].Sec-Sec)<dSecMin) { iMin=iP; dSecMin = Math.abs(th.AP[iP].Sec - Sec); } return iMin; }; th.Show=function(Visible_) { th.Visible=Visible_; // SetNode(Line, {stroke: th.Color});//, 'stroke-width':th.LineW}) // console.log(Visible_) // SetNode(th.AP[iP].Circle, {r:th.CircleR}); // SetNode(th.AP[iP].Line, {'stroke-width':th.LineW}); // } // let a=RegimeEdit; if(th.Visible || th.Active) { for (let iP = 0; iP < th.AP.length; iP++) if (th.Active) { th.AP[iP].Circle.style.cursor = CircleCursor;//'pointer'; SetNode(th.AP[iP].Circle, {r: th.CircleR}); SetNode(th.AP[iP].Line, {'stroke-width': th.LineW}); } else { th.AP[iP].Circle.style.cursor = 'default'; if(th.CircleR>0) SetNode(th.AP[iP].Circle, {r: 1}); SetNode(th.AP[iP].Line, {'stroke-width': 0.5}) } if (th.Active) SetNode(Line, {'stroke-width': th.LineW}); else SetNode(Line, {'stroke-width': 0.5}); } // if(iP<0) SetVisible(Line, ((th.Visible || th.Active) && (th.AS=="ASR" || th.Index==0 || RegimeEdit=="AllCh"))); for(let iP = 0 ; iP<th.AP.length; iP++) th.AP[iP].Show((th.Visible || th.Active) && (th.AS=="ASR" || th.Index==0 || RegimeEdit=="AllCh")); // SetNode(th.AP[iP].Circle, {r:th.CircleR}); // SetNode(th.AP[iP].Line, {'stroke-width':th.LineW}); // th.AP[iP].Circle.style.cursor = 'pointer'; // } // if(iP<0) // SetNode(Line, {stroke: th.Color});//, 'stroke-width':th.LineW}) }; // th.SelectPoint=function(SecMin, SecMax, Selected_) // { // for(let i = 0 ; i<th.AP.length; i++) // if(SecMin<=th.AP[i].Sec && th.AP[i].Sec<=SecMax) // th.AP[i].Selecte(Selected_); // } th.DelPointSelect=function(){ // let AS=th.ASL; // let S=CheckSelectPointCount(AS); // if(S && S!="") // return S; // for(let iS = 0; iS < AS.length; iS++) // if(AS[iS].Active && 1<AS[iS].AP.length) for(let iP = th.AP.length-1; iP >=0 && 1<th.AP.length; iP--) if(th.AP[iP].Selected) { th.DelPoint(iP); // iP++; } // OkrTime(AS); th.Refresh(); return ""; }; th.DelPoint=function(iP){ /// iP - index in th.AP[] if(th.AP.length<2 || iP<0) /// not del last point return false; th.AP[iP].Free(); delete th.AP[iP]; th.AP.splice(iP,1); return true; }; th.AddPoint=function(Sec, Value){ let iP=0; // for(iP=0; iP<th.AP.length; iP++) while(iP<th.AP.length){ if(th.AP[iP].Sec>=Sec) break; iP++; } // iP--; if(iP==th.AP.length || th.AP[iP].Sec!=Sec){ th.AP.splice(iP, 0, new MPoint()); th.AP[iP].Sec=Sec; th.AP[iP].V=Value; th.SetStyle(iP); th.AP[iP].Show(th.Visible && th.Active); } }; th.GetValue=function(Sec){ // console.log("th.GetValue=function"); if(th.AP.length==1) return th.AP[0].V; let Sec0, Sec1, V0, V1; if(Sec<th.AP[0].Sec){ Sec0=th.AP[th.AP.length-1].Sec-DaySec; V0=th.AP[th.AP.length-1].V; Sec1=th.AP[0].Sec; V1=th.AP[0].V; } else if(th.AP[th.AP.length-1].Sec<Sec){ Sec0=th.AP[th.AP.length-1].Sec; V0=th.AP[th.AP.length-1].V; Sec1=th.AP[0].Sec+DaySec; V1=th.AP[0].V; } else for(let iP = 1 ; iP<th.AP.length; iP++) if(th.AP[iP-1].Sec<=Sec && Sec<=th.AP[iP].Sec){ Sec0=th.AP[iP-1].Sec; V0=th.AP[iP-1].V; Sec1=th.AP[iP].Sec; V1=th.AP[iP].V; break; } V0=Number(V0); /// at load data from json V is string V1=Number(V1); let a1=(V1-V0)*(Sec-Sec0)/(Sec1-Sec0)+V0; return a1; // return (V1-V0)*(Sec-Sec0)/(Sec1-Sec0)+V0; }; } let th = this; th.SliderShow = function () { Slider.Rect.style.display = 'block'; Slider.Text.style.display = 'block'; Slider.Line.style.display = 'block'; }; th.SliderHide = function () { Slider.Rect.style.display = 'none'; Slider.Text.style.display = 'none'; Slider.Line.style.display = 'none'; }; function BuildSlider(){ Slider.Rect = GetNode(svg, "rect", {x: RSvg.x0 - 16, width: 54, y: 2, height: 20, rx: 2, ry: 2, fill: '#2c2c2c', stroke: '#00dd00', 'stroke-width': 0.3}); Slider.Line = GetNode(svg, "line", {x1: RSvg.x0, y1: RSvg.y0, x2: RSvg.x0, y2: RSvg.y1, stroke: '#00dd00', 'stroke-width': 0.8, 'stroke-dasharray': "3, 2" }); Slider.Text = GetNode(svg, "text", {x: RSvg.x0 - 7, y: 18, 'font-size': 18, fill: '#bbbbbb'}); // '#10AA10'}); //Slider.Text.style.cursor = 'default'; Slider.Text.textContent = "00:00"; if(AxesVisible.L){ Slider.Text.style.cursor='pointer'; Slider.Rect.style.cursor='pointer'; } else { Slider.Text.style.cursor = 'default'; Slider.Rect.style.cursor='defaultr'; } th.SliderHide(); } function GetAxisMax(AS)//AAxy, K_) /// [[[x, y], ...],...]) /// return{yMax:_, dy:_, yCount:_, p:_} /// here use only y, therefore x can be any: time, sec, x { let yMax = -1; for (let iS = 0; iS < AS.length; iS++){ // for (let iP = 0; iP < AS[iS].AP.length; iP++) { // let V = AS[iS].AP[iP].V; let V=-1; if (AS == th.ASL) V=AS[iS].JParam[Unit]; else { for (let iP = 0; iP < AS[iS].AP.length; iP++) V = Math.max(AS[iS].AP[iP].V); } // if (AS == th.ASL) { // // console.log("AS[iS].JParam="+JSON.stringify(AS[0].JParam)); // // if(Unit=='%') // // V*=100; // // else // V *= AS[iS].JParam[Unit]; // } if (V > yMax) yMax = V; //} } if (yMax<0) return {yMax: 100, dy: 10, yCount: 10, p: 2}; yMax /= K; let p = Math.floor(Log10(yMax)); // console.log('p='+p); let yMax1 = yMax / Math.pow(10, p); // console.log('dy='+dy); let dy = 0; let dp = 1; if (yMax1 < 1.3) dy = 0.1; else if (yMax1 < 2.3) dy = 0.2; else if (yMax1 < 3) { dy = 0.25; dp = 2; } else if (yMax1 < 6) dy = 0.5; else dy = 1; dy = dy * Math.pow(10, p); let yCount = Math.ceil(yMax / dy); yMax1 = yCount * dy; p = Math.max(-p + dp, 0); return {yMax: yMax1, dy: dy, yCount: yCount + 1, p: p}; } function GetAxisMaxCount(AS, yCount)//AAxy, yCount) /// [[[x, y], ...],...] /// return{yMin:_, yMax:_, dy:_, p:_} /// here use only y, therefore x can be any: time, sec, x { let bEmpty = false; yMax = -1; yMin = 1E6; for(let iS = 0; iS < AS.length; iS++) { for (let iP = 0; iP < AS[iS].AP.length; iP++) { // console.log(AS[iS].AP[iP].V); if (AS[iS].AP[iP].V > yMax) yMax = AS[iS].AP[iP].V; if (AS[iS].AP[iP].V < yMin) yMin = AS[iS].AP[iP].V; } } // console.log('yMax='+yMax); if (yMax<0) return {yMin: 0, yMax: (yCount - 1) * 5, dy: 5}; let dy = (yMax - yMin) / (yCount - 1); let p = Math.floor(Log10(dy)); dy = dy / Math.pow(10, p); let dp = 0; if (dy > 5) { dy = 10; dp = -1; } else if (dy > 2.5) dy = 5; else if (dy > 2) { dy = 2.5; dp = 1; } else if (dy > 1) dy = 2; else dy = 1; dy = dy * Math.pow(10, p); yMin = Math.floor(yMin / dy) * dy; yMax1 = yMin + dy * (yCount - 1); if(yMax1<yMax) dy+=1; yMax1 = yMin + dy * (yCount - 1); p = Math.max(-p + dp, 0); return {yMin: yMin, yMax: yMax1, dy: dy, p: p}; } function SetK(K_) { K = K_; th.BuildNet(); th.Refresh(ASL); th.Refresh(ASL); } th.BuildNet=function()//AATimeVL, AATimeTR) /// [[x, y], ...] { // if(AxisR.yMin ==NaN) // AxisR.yMin=0; // console.log('BuildNet'); let AxisL = GetAxisMax(th.ASL);//AATimeVL, K); RCrdL.y1 = AxisL.yMax; let AxisR; if(AxesVisible.R) { AxisR = GetAxisMaxCount(th.ASR, AxisL.yCount);//;AATimeTR, AxisL.yCount); RCrdR.y0 = AxisR.yMin; RCrdR.y1 = AxisR.yMax; } // console.log(AxisL) // console.log(AxisR) let iy; for (iy = 0; iy < AxisL.yCount; iy++) { let yL = iy * (RCrdL.y1 - RCrdL.y0) / (AxisL.yCount - 1) + RCrdL.y0; // console.log(y) let Sxy = Crd2Crd(RCrdL, RSvg, {x: 0, y: yL}); if (iy < ALeft.length) { SetNode(ALeft[iy], {y1: Sxy.y, y2: Sxy.y}); if(iy>0) ALeft[iy].style.display = 'block'; SetNode(ALeftT[iy], {y: Sxy.y}); if(AxesVisible.L) ALeftT[iy].style.display = 'block'; else ALeftT[iy].style.display = 'none'; if(AxisR) { SetNode(ARightT[iy], {y: Sxy.y}); // if(VerFree) // ARightT[iy].style.display = 'none'; // else ARightT[iy].style.display = 'block'; } } else { ALeft.push(GetNode(svg, "line", { x1: RSvg.x0, y1: Sxy.y, x2: RSvg.x1, y2: Sxy.y, stroke: '#ffffff', 'stroke-width': 0.2, 'stroke-dasharray': "2, 3" })); if(iy==0) ALeft[iy].style.display = 'none'; // if(AxesVisible.L) ALeftT.push(GetNode(svg, "text", {x: RSvg.x0 - 5, y: Sxy.y, 'text-anchor': 'end', 'font-size': 11, fill: '#DDDDDD', 'dominant-baseline': 'middle' }));//, unselectable:'on'}); if(!AxesVisible.L) ALeftT[iy].style.display = 'none'; //++ if(AxesVisible.L) // ALeftT[iy].style.cursor = 'pointer'; if(AxisR){ ARightT.push(GetNode(svg, "text", {x: RSvg.x1 + 5, y: Sxy.y, 'text-anchor': 'start', 'font-size': 11, fill: '#DDDDDD', 'dominant-baseline': 'middle' }));//, unselectable:'on'}); // if(!VerFree && AxesVisible.L) ARightT[iy].style.cursor = 'pointer'; // else if(!AxesVisible.L) // ARightT[iy].style.cursor = 'default'; } } if (0.001 <= AxisL.dy && AxisL.yMax < 10000) ALeftT[iy].textContent = yL.toFixed(AxisL.p); else ALeftT[iy].textContent = yL.toExponential(1); if(AxisR){ if(AxisR.yMin==NaN) AxisR.yMin=0; if(AxisR.p>5) AxisR.p=0; ARightT[iy].textContent = (AxisR.yMin + iy * AxisR.dy).toFixed(AxisR.p); } } for (; iy < ALeft.length; iy++) { ALeft[iy].style.display = 'none'; // if(AxesVisible.L) // ALeftT[iy].style.display = 'block'; // else // ALeftT[iy].style.display = 'none'; ALeftT[iy].style.display = 'none'; if(AxisR) ARightT[iy].style.display = 'none'; } if (ABottom.length < 1) for(let ix = 0; ix <= 24; ix += 1) { let Sxy = Crd2Crd(RCrdL, RSvg, {x: ix * (RCrdL.x1 - RCrdL.x0) / 24 + RCrdL.x0, y: 0}); ABottom.push(GetNode(svg, "line", {x1: Sxy.x, y1: RSvg.y0 + 3, x2: Sxy.x, y2: RSvg.y1, stroke: '#ffffff', 'stroke-width': 0.22, 'stroke-dasharray': "2, 3" })); if(ix==0 || ix==24) ABottom[ix].style.display = 'none'; if (ix % 2 == 0) { T = GetNode(null, "text", { x: Sxy.x, y: RSvg.y0 + 3, 'text-anchor': 'middle', 'font-size': 11, fill: '#DDDDDD', 'dominant-baseline': 'text-before-edge' });//, unselectable:'on'}); T.textContent = ix + ':00'; T.style.cursor = 'default'; svg.appendChild(T); ABottomT.push(T); } } if(Unit=="W") { let xy0 = Crd2Crd(RCrdL, RSvgCrd, {x: 0, y: PMax}); SetNode(RectPMax, {x: 0, y: 0, width: RSvg.x1, height: Math.max(0, xy0.y)});//RSvg.y0/2}); RectPMax.style.display="block"; } else RectPMax.style.display='none'; }; function SetASCount(AS, Count){//AATimeV, AColor) /// [[['00:00', Value], ...],...] /// AS - array of series ASL or ASR if(Count < AS.length) { /// delete elements // for(let iS = Count ; iS<AS.length; i++) { for(let iS = AS.length-1; iS>=Count; iS--) { AS[iS].Free(); delete AS[iS]; } AS.splice(Count, AS.length-Count); } else { /// add elements for(let i = AS.length; i < Count; i++) AS[i] = new MSeries(); } for(let i = 0; i<AS.length; i++) { AS[i].Index = i; if(AS==th.ASL) AS[i].AS="ASL"; else if(AS==th.ASR) AS[i].AS="ASR"; } } th.Free=function(){ SetASCount(th.ASR, 0); SetASCount(th.ASL, 0); while (svg.lastChild) { svg.removeChild(svg.lastChild); } removeEventListener('mousedown', OnMouseDown, false); // removeEventListener('dblclick', OnMouseDblClick, false); // removeEventListener('click', OnMouseDblClick, false); MouseM.RemoveOnMouseClick(OnMouseDblClick ); svg.removeEventListener('touchstart', OnMouseDown, false); }; th.Data2AS=function(AS, AATimeV, AParam, RCrd)//Axy) /// [[x, y], ...], /// AS - array of series ASL or ASR /// AATimeV - [[['00:00', Value], ...],...] /// AParam - [{"Regime":2,"Name":"Main","Color":16777215,"PWM":-1,"Lm":0,"Lux":0,"W":0},...] /// rect coordinate of axis { // console.log('AATimeV='+JSON.stringify(AATimeV)) if(!AS) AS=th.ASL; SetASCount(AS, AATimeV.length); /// here th.AAPointL[...].length == AATimeV[...].length for(let iS=0; iS<AS.length; iS++) { // for(let iP=0; iP<th.ASL[iS].AP.length; iP++) if(RCrd) AS[iS].RCrd=RCrd; // console.log(JSON.stringify(AParam)) if(AParam) AS[iS].Data2Series(AATimeV[iS], AParam[iS]); else AS[iS].Data2Series(AATimeV[iS]); if(AS==th.ASL) AS[iS].JParam['%']=100; else AS[iS].Active=false; AS[iS].IndexChanel=AParam.IndexChanel; //console.log("AS[iS].JParam="+JSON.stringify(AS[iS].JParam)); } if(AS==th.ASL){ SetStyle(AS, AParam, 4, 2); } if(AS==th.ASR) { for (let iS = 0; iS < AS.length; iS++) AS[iS].SetActive = false; SetStyle(AS, AParam, 0, 1); } }; function Crd2Crd(CrFrom, CrTo, Jxy) /// {x:1, y:2} { let dx=(Jxy.x-CrFrom.x0)/(CrFrom.x1-CrFrom.x0); let x=dx*(CrTo.x1-CrTo.x0)+CrTo.x0; let dy=(Jxy.y-CrFrom.y0)/(CrFrom.y1-CrFrom.y0); let y=dy*(CrTo.y1-CrTo.y0)+CrTo.y0; return {x:x,y:y}; } th.SetSliderSec=function(Sec_, x){ let Sec=Sec_; if(Sec==undefined) Sec=th.SliderSec; let w=Slider.Rect.getAttributeNS(null, 'width'); if(!x) x=Crd2Crd(RCrdL, RSvg, {'x':Sec, 'y':0}).x; SetNode(Slider.Line, {'x1':x, 'x2':x}); Slider.Rect.setAttributeNS(null, 'x', x-w/2); Slider.Text.setAttributeNS(null, 'x', x-w/2+3); // th.SliderSec=Sec; let HM=Sec2Time(Sec); Slider.Text.textContent=HM['H']+':'+HM['M']; th.SliderSec=Sec; // let S=Sec; if(Sec_ && th.onSliderMove) /// Sec_ - only if position of slider was change th.onSliderMove(Sec); }; th.SetSliderCurrentTime=function (){ let Sec; if(TimeCurrent) { let T = GetTimeCurrent(); Sec=3600 * T.H + 60 * T.M + 1*T.S; } else { let a = new Date(); Sec = 3600 * a.getHours() + 60 * a.getMinutes() + 1*a.getSeconds(); delete a; } th.SetSliderSec(Sec); }; th.CalcSeries0=function(AS)//, CalcTo0=true) /// calc series AS[0] ///-- if(CalcTo0) calc AS[0] from AS[_>0] else calc AS[_>0] from AS[0] { if (!AS) AS = th.ASL; // if(CalcTo0) { /// here begin add points then del points, therefore last point never del even this point not need /// will add points t0 iS=0 for (let iS = 1; iS < AS.length; iS++) if (AS[iS].Active) for (let iP = 0; iP < AS[iS].AP.length; iP++) { let iP0 = AS[0].FindPoint(AS[iS].AP[iP].Sec); if (iP0 < 0) /// not found this point in AS[0] add this point to AS[0] AS[0].AddPoint(AS[iS].AP[iP].Sec, 0); } /// will del points from iS=0 for (let iP0 = 0; iP0 < AS[0].AP.length; iP0++) { let iP = -1; for (let iS = 1; iS < AS.length && iP < 0; iS++) if (AS[iS].Active) iP = AS[iS].FindPoint(AS[0].AP[iP0].Sec); if (iP < 0) /// not found this point in AS[is] del this point to AS[0] { if(AS[0].DelPoint(iP0)) iP0--; } } // for (let iS = 0; iS < AS.length; iS++) // AS[iS].Show(AS[iS].Visible); /// Here AS[0] have correct quantity points /// will calc AS[0] // console.log("----------") // console.log("AS[0].AP.length="+AS[0].AP.length) for (let iP0 = 0; iP0 < AS[0].AP.length; iP0++){ // console.log("iP0="+iP0); // console.log("AS[0].AP[iP0]="+AS[0].AP[iP0]); // console.log("AS[0].AP[iP0].Sec="+AS[0].AP[iP0].Sec); let Sum=0; let CountS=0; for (let iS = 1; iS < AS.length; iS++) if(AS[iS].Active) { // console.log("AS[iS]="+AS[iS]); // Dv++; // if(Dv==218) // Dv=Dv; // console.log("Dv="+Dv); let s=AS[0].AP[iP0].Sec; let t=AS[iS].GetValue(s); Sum += AS[iS].JParam[Unit]*t; // if(Sum==NaN) // Sum=Sum; let S1=AS[iS].JParam[Unit]; let S2=AS[iS].GetValue(AS[0].AP[iP0].Sec); // Sum += AS[iS].GetValue(AS[0].AP[iP0].Sec); CountS++; } Sum/=AS[0].JParam[Unit]; //if(th.Series0Regime=='Sum') // console.log("Sum="+Sum); // console.log("CountS="+CountS); if(Unit=='%') AS[0].AP[iP0].V=Sum/CountS; /// here always CountS>0 else AS[0].AP[iP0].V=Sum; // console.log("AS[0].AP[iP0].V="+AS[0].AP[iP0].V); // else if(th.Series0Regime=='Average') //AS[0].AP[iP0].V=Sum/CountS; /// here always CountS>0 } // BuildNet(); for (let iS = 0; iS < AS.length; iS++) AS[iS].Show(AS[iS].Visible); // AS[iS].Refresh(); th.Refresh(AS); }; function CheckSelectPointCount(AS) { let Count=0; for(let iS = 0; iS < AS.length; iS++) if (AS[iS].Active)//Visible) for(let iP = 0; iP < AS[iS].AP.length; iP++) if (AS[iS].AP[iP].Selected) Count++; if(Count<1) return 'Error, not selected points'; return""; }; function GetSelectPointMoveMinMax(AP, iP){ /// AP=th.ASL[iS].AP /// iP - index point in AP /// return value of maximum move in left (Min:_>=0) and right (Max:_>=0) let VMax=DaySec; if(iP<0 || AP.length<=iP) return {Min:-1, Max:-1}; if(AP.length==1) return{Min:VMax-1, Max:VMax-1}; let MMin, MMax; if(iP==0){ if(AP[AP.length-1].Selected) MMin=VMax; else MMin=AP[0].Sec+VMax-AP[AP.length-1].Sec; } else if(AP[iP-1].Selected) MMin=VMax; else MMin=AP[iP].Sec-AP[iP-1].Sec; if(iP==AP.length-1){ if(AP[0].Selected) MMax=VMax; else MMax=AP[0].Sec+VMax-AP[AP.length-1].Sec; } else if(AP[iP+1].Selected) MMax=VMax; else MMax=AP[iP+1].Sec-AP[iP].Sec; return{Min:MMin, Max:MMax}; } function GetSelectSeriesMoveMinMax(S) { /// S=th.ASL[iS] /// return value of maximum move in left (Min:_>=0) and right (Max:_>=0) let MMin = DaySec+1; /// not correct value, correct = 24*3600-1 let MMax = MMin; for(let iP = 0; iP < S.AP.length; iP++) if (S.AP[iP].Selected) { let M = GetSelectPointMoveMinMax(S.AP, iP); MMin=Math.min(MMin,M.Min); MMax=Math.min(MMax,M.Max); } return{Min:MMin, Max:MMax}; }; function GetSelectSeriesSecMin(S) { /// S=th.ASL[iS] /// return min _.Sec in all select points let SecMin = DaySec+1; /// not correct value, correct = 24*3600-1 for(let iP = 0; iP < S.AP.length; iP++) if (S.AP[iP].Selected && S.AP[iP].Sec<SecMin) SecMin=S.AP[iP].Sec; return SecMin; }; function GetASL(AS){ if(!AS) return th.ASL; return AS; }; th.GetValue=function(AS, Sec){ /// return [V,...] AS=GetASL(AS); let V=[]; // console.log(AS) for(let iS = 0; iS < AS.length; iS++) // for(let iP = 0; iP < AS[iS].AP.length; iP++) V.push(AS[iS].GetValue(Sec)); return V; }; th.SetValue=function(AS, A, Sec) { /// A=[v0,...] /// series must have point in time=Sec else error AS = GetASL(AS); if (!Sec) Sec = th.SliderSec; for (let iS = 0; iS < AS.length; iS++) for (let iP = 0; iP < AS[iS].AP.length; iP++) if (AS[iS].AP[iP].Sec == Sec){ AS[iS].AP[iP].V=Number(A[iS]); break; } th.BuildNet(); th.Refresh(AS); }; th.SetK=function(K_){ K=K_; th.BuildNet(); th.CalcSeries0(); th.Refresh(th.ASL); if(AADataR0) th.Refresh(th.ASR); }; th.SetUnit=function(Unit_){ // console.log('ChartTime::SetUnit(.)_'+Unit); // K=K_; Unit=Unit_; th.BuildNet(); th.CalcSeries0(); th.Refresh(th.ASL); }; th.GetPointExist=function(AS, Sec){ /// return [true, false, ...] AS=GetASL(AS); AR=[]; for(let iS = 0; iS < AS.length; iS++) { AR[iS]=false; for (let iP = 0; iP < AS[iS].AP.length; iP++) if (AS[iS].AP[iP].Sec == Sec) { AR[iS] = true; break; } else if(AS[iS].AP[iP].Sec > Sec) break; } // console.log(AS) // console.log(AR) return AR; }; function SortSeries(S) { /// S=th.ASL[iS] function SortSec(P0, P1) { if (P0.Sec==P1.Sec) return 0; if (P0.Sec>P1.Sec) return 1; return -1; } S.AP.sort(SortSec); }; function OkrTime(AS) { for(let iS = 0; iS < AS.length; iS++) for(let iP = 0; iP < AS[iS].AP.length; iP++) AS[iS].AP[iP].Sec=Math.floor(AS[iS].AP[iP].Sec/60)*60; }; th.MoveSelectBlockX=function(sTime) { let AS=th.ASL; let S=CheckSelectPointCount(AS); if(S && S!="") return S; let VMax=DaySec+1; /// not correct value, correct = 24*3600-1 let SecMin0=VMax; for(let iS = 1; iS < AS.length; iS++) if(AS[iS].Active){//Visible){ let SecM=GetSelectSeriesSecMin(AS[iS]); if(SecM<SecMin0) SecMin0=SecM; } let dSec=Time2Sec(sTime)-SecMin0; let SecMin = VMax; let SecMax = VMax; for(let iS = 1; iS < AS.length; iS++) if(AS[iS].Active){//Visible) { let M = GetSelectSeriesMoveMinMax(AS[iS]); SecMin=Math.min(SecMin,M.Min); SecMax=Math.min(SecMax,M.Max); } if(SecMin<0 || SecMax<0 || SecMin>=VMax || SecMax>=VMax) return 'Error, th.MoveSelectX=function(sTime)'; if( (dSec<0 && dSec<-SecMin) || (0<dSec && SecMax<dSec) ) return 'Error, not correct time'; /// here all checked for(let iS = 1; iS < AS.length; iS++) if(AS[iS].Active){//Visible){ let bNeedSort=false; for(let iP = 0; iP < AS[iS].AP.length; iP++) if(AS[iS].AP[iP].Selected) { AS[iS].AP[iP].Sec=(AS[iS].AP[iP].Sec+dSec+VMax)%VMax; if( (dSec<0 && iP==0) || (0<dSec && iP==AS[iS].AP.length-1) ) bNeedSort=true; } if(bNeedSort) SortSeries(AS[iS]); } th.CalcSeries0(AS); OkrTime(AS); th.Refresh(AS); return ""; }; th.MoveSelectEveryChanelX=function(sTime){ let AS=th.ASL; let S=CheckSelectPointCount(AS); if(S && S!="") return S; let VMax=DaySec; /// not correct value, correct = 24*3600-1 let SecMin0=VMax; for(let iS = 1; iS < AS.length; iS++) if(AS[iS].Active){//Visible){ let SecMin=GetSelectSeriesSecMin(th.ASL[iS]); if(SecMin>DaySec) continue; let dSec=Time2Sec(sTime)-SecMin; let M = GetSelectSeriesMoveMinMax(AS[iS]); if(M.Min>DaySec || M.Max>DaySec) continue; // console.log(M) // if(M.Min<0 || M.Max<0 || M.Min>=VMax || M.Max>=VMax) // return 'Error, th.MoveSelectX=function(sTime)'; // console.log(SecMin); if( (dSec<0 && dSec<-M.Min) || (0<dSec && M.Max<dSec) ) return 'Error, not correct time'; } /// here all checked for(let iS = 1; iS < AS.length; iS++) if(AS[iS].Active){//Visible){ let dSec=Time2Sec(sTime)-GetSelectSeriesSecMin(th.ASL[iS]); let bNeedSort=false; for(let iP = 0; iP < AS[iS].AP.length; iP++) if(AS[iS].AP[iP].Selected) { AS[iS].AP[iP].Sec=(AS[iS].AP[iP].Sec+dSec+VMax)%VMax; if( (dSec<0 && iP==0) || (0<dSec && iP==AS[iS].AP.length-1) ) bNeedSort=true; } if(bNeedSort) SortSeries(AS[iS]); } th.CalcSeries0(); OkrTime(AS); th.Refresh(AS); // th.CalcSeries0(); return ""; }; th.DelPointSelect=function(){ let AS=th.ASL; // let S=CheckSelectPointCount(AS); // if(S && S!="") // return S; for(let iS = 0; iS < AS.length; iS++) if(AS[iS].Active && 1<AS[iS].AP.length) AS[iS].DelPointSelect(); // for(let iP = AS[iS].AP.length-1; iP >=0 && 1<AS[iS].AP.length; iP--) // if(AS[iS].AP[iP].Selected) { // AS[iS].DelPoint(iP); // iP++; // } OkrTime(AS); th.Refresh(AS); return ""; }; let EditSliderTime, Div; function CreateSlider() { // parent = document.body; Div = document.createElement('div'); EditSliderTime = document.createElement('input'); //document.textContent=":"; //EditM = document.createElement('input'); EditSliderTime.type = 'text'; // EditM.type = 'text'; EditSliderTime.class="cTime"; // EditM.class="cMin"; EditSliderTime.style.width = '50px'; // EditM.style.width = '20px'; // Div.style.width = '180px'; // EditH.min = 0; // EditH.max = 23; // EditM.min = 0; // EditM.max = 59; EditSliderTime.style.background = '#c5c5c5'; // EditM.style.background = '#c5c5c5'; EditSliderTime.style.color = '#000'; // EditM.style.color = '#000'; // EditM.style=EditH.style; // Div.style.display = "none" SetVisible(Div, false); // Div.style.position = 'fixed'; // Div.style.zIndex = 200; EditSliderTime.onkeydown=OnKeyDown; // EditSliderTime.onkeydown=onKeyDownEditTime(this, '23:59'); EditSliderTime.onkeyup=function(){return onKeyUpEditTime(EditSliderTime, '23:59')}; // EditH.onkeydown = OnKeyDown; // EditM.onkeydown = OnKeyDown; // Label = document.createElement('label'); // Label.style.background = '#c5c5c5'; // Label.textContent = "%22"; Div.appendChild(EditSliderTime); // let Label = document.createElement('label'); // Label.style.background = '#c5c5c5'; // Label.textContent = ":"; //Div.textContent=":"; // Div.appendChild(Label); // Div.appendChild(EditM); document.body.appendChild(Div); }; function OnKeyDown(event) { // alert("1"); if (event.key == "Enter") { // let Sec=Number(EditH.value)*3600+Number(EditM.value)*60; let Sec=Time2Sec(EditSliderTime.value); th.SetSliderSec(Sec); } if (event.key == "Enter" || event.key == "Escape") { // console.log("event.key == \"Enter\""); SetVisible(Div, false); // Div.style.display = "none"; } else return onKeyDownEditTime(EditSliderTime, '23:59'); }; let bLockMouseDown=false; // function OnMouseClick(event) { // console.log("OnMouseDblClick"); // }; function OnMouseDblClick(event) { // console.log("onDblClick"); let SelectedElement = event.target; if (SelectedElement == Slider.Text || SelectedElement==Slider.Rect) { // console.log("2") let T=Sec2Time(th.SliderSec); EditSliderTime.value=pad(T.H,2)+":"+pad(T.M,2); // EditH.value = Sec2Time(th.SliderSec)['H'];//(th.Position * 100).toFixed(Log10(th.K) + 2); // EditM.value = Sec2Time(th.SliderSec)['M'];//(th.Position * 100).toFixed(Log10(th.K) + 2); let P = SvgToCoordinate(svg, Number(Slider.Text.getAttributeNS(null, 'x')), Number(Slider.Text.getAttributeNS(null, 'y'))); // let P={x:50, y:50} Div.style.left = P.x-10;//Number(Text.getAttributeNS(null, 'x')); //th.H + th.T + 10-20; Div.style.top = P.y - 13; //Number(Text.getAttributeNS(null, 'y')); //th.H + th.T + 10-20; // Div.style.display = "block"; SetVisible(Div,true); // Div.style.position = 'fixed'; // Div.style.zIndex = 200; Div.style.position="absolute"; Div.style.display="block"; EditSliderTime.autofocus = true; Div.focus(); EditSliderTime.focus(); // EditH.select(); // EditH.autofocus = false; // alert("3") bLockMouseDown=true; return false; } if(AxesVisible.L) { /// check right axis if(SelectedElement==RectAxeR) { VisibleR=!VisibleR; th.Show(th.ASR, VisibleR); sSelected = 'AxesR'; } else for(let i=0; i<ARightT.length; i++) if(SelectedElement==ARightT[i]) { VisibleR=!VisibleR; th.Show(th.ASR, VisibleR); sSelected = 'AxesR'; break; } } } OnMouseDown=function (event) { // console.log('OnMouseDown()'); // if(bLockMouseDown){ // bLockMouseDown=false; // return; // } // if(th.onSelectPoint==un) // return; SelectedElement = event.target; if(SelectedElement==RectRange && sSelected == 'Range') /// bug in FFox return; if(SelectedElement != EditSliderTime && SelectedElement!=Div && SelectedElement!=Slider.Text && SelectedElement!=Slider.Rect) { // console.log("OnMouseDown"); // console.log(SelectedElement); SetVisible(Div, false); } sSelected = null; if(event.type=="mousedown") { xyMouseDown.xSvg = event.pageX; xyMouseDown.ySvg = event.pageY; } else if(event.type=="touchstart") { // if(event.changedTouches.length!=1){ // LockTouchMove=false; // return; // } let touchobj = event.changedTouches[0]; // reference first touch point xyMouseDown.xSvg = parseInt(touchobj.clientX); xyMouseDown.ySvg = parseInt(touchobj.clientY); } let a = svg.getScreenCTM(); /// "offset based on svg"+ " x:" + a.e +" y:" + a.f; // console.log(RSvg.y0); // console.log(xyMouseDown.ySvg-a.f); bABottomT=false; for(let i=0; i<ABottomT.length; i++) if(SelectedElement==ABottomT[i]) { bABottomT=true; break; } // ABottomT[0].innerHTML=(xyMouseDown.ySvg-a.f)-0.9*RSvg.y0; if ( th.onSelectPoint && (((SelectedElement==th.Fon || SelectedElement==RectRange) && (xyMouseDown.ySvg-a.f)>=0.8*RSvg.y0) || SelectedElement==AxesLineBottom || bABottomT )) { // if ( th.onSelectPoint && (SelectedElement==th.Fon || SelectedElement==RectRange)) { sSelected = 'Range'; xyMouseDown.xObj = xyMouseDown.xSvg; SetNode(RectRange, {x: xyMouseDown.xSvg-RSvg.x0, width: 0}); RectRange.style.display='block'; if (!event.shiftKey && !th.BtnSelectPointAdd.bDown && !th.BtnSelectPointDel.bDown) { /// deselect old points // SelectePointAll(false); // BtnSelectPointShowHide(); th.onSelectPoint({}, false, true); } } if(!sSelected) { /// check left axis if(SelectedElement==RectAxeL) { VisibleL=!VisibleL; sSelected = 'AxesL'; th.Show(th.ASL, VisibleL); } else for(let i=0; i<ALeftT.length; i++) if(SelectedElement==ALeftT[i]) { VisibleL=!VisibleL; th.Show(th.ASL, VisibleL); sSelected = 'AxesL'; break; } } // if(!sSelected && AxesVisible.L) { /// check right axis // if(SelectedElement==RectAxeR) { // VisibleR=!VisibleR; // th.Show(th.ASR, VisibleR); // sSelected = 'AxesR'; // } // else // for(let i=0; i<ARightT.length; i++) // if(SelectedElement==ARightT[i]) { // VisibleR=!VisibleR; // th.Show(th.ASR, VisibleR); // sSelected = 'AxesR'; // break; // } // } if (!sSelected) { /// check Slider if (SelectedElement == Slider.Text || SelectedElement == Slider.Rect || SelectedElement == Slider.Line) { sSelected = 'Slider'; xyMouseDown.xObj = xyMouseDown.xSvg - Slider.Line.getAttributeNS(null, 'x1'); // console.log(xyMouseDown.xObj); } } if (!sSelected && th.onSelectPoint) { /// check select point // let J={}; for (let iS = 0; iS < th.ASL.length; iS++) /// check select point for (let iP = 0; iP < th.ASL[iS].AP.length; iP++) /// check select point if (th.ASL[iS].AP[iP].Circle == SelectedElement) { /// // if (event.shiftKey) { /// deselect point // // th.ASL[iS].AP[iP].Selecte(!th.ASL[iS].AP[iP].Selected); // // th.AfterSelectPoint(); // // } // else { // // if (!event.shiftKey) { /// deselect old points // // SelectePointAll(false); // // th.ASL[iS].AP[iP].Selecte(true); // //} // //th.AfterSelectPoint(); // } sSelected = 'Point'; let J={}; J[iS.toString()]=[iP]; let b=true; if(event.shiftKey || th.BtnSelectPointAdd.bDown) b=!th.ASL[iS].AP[iP].Selected; b=(b && !th.BtnSelectPointDel.bDown); th.onSelectPoint(J, b, !event.shiftKey && !th.BtnSelectPointAdd.bDown && !th.BtnSelectPointDel.bDown); iS=th.ASL.length; /// break break; } BtnSelectPointShowHide(); } if(onSelect) if(event.target.parentNode==svg) onSelect(th); if(sSelected=='Slider' || sSelected=='Range'){ svg.addEventListener('mousemove', OnMouseMove, false); addEventListener('mouseup', OnMouseUp, false); addEventListener('touchend', OnMouseUp, false); svg.addEventListener('touchmove', OnMouseMove, false); event.preventDefault(); LockTouchMove=true; } }; function OnMouseMove(event) { let xy={};// = GetSvgCoordinates(svg, event); // xy.x = event.pageX; // xy.y = event.pageY; if(event.type=="mousemove") { xy.x = event.pageX; xy.y = event.pageY; } else if(event.type=="touchmove") { // if(event.changedTouches.length!=1){ // // alert(event.changedTouches.length) // LockTouchMove=false; // return; // } let touchobj = event.changedTouches[0]; // reference first touch point xy.x = parseInt(touchobj.clientX); xy.y = parseInt(touchobj.clientY); LockTouchMove=true; } // alert(1) if(!sSelected) { // console.log("sSelected=0"); return; } if(sSelected=='Range') { let x=xyMouseDown.xSvg-RSvg.x0; let w=xy.x - RSvg.x0-x; if(w<0) { w = -w; x=x-w; } SetNode(RectRange, {x: x, width: w}); event.preventDefault(); // event.stopPropagation(); } else if(sSelected=='Slider'){// && Slider.Text.style.cursor=='pointer'){ let x=xy.x-xyMouseDown.xObj; if(x<RSvg.x0) x=RSvg.x0; if(x>RSvg.x1) x=RSvg.x1; let SliderSec=Crd2Crd(RSvg, RCrdL, {'x':x, 'y':0}).x; th.SetSliderSec(SliderSec, x); event.preventDefault(); // event.stopPropagation(); // console.log("move range ok"); } }; function OnMouseUp(event) { let xy={};// = GetSvgCoordinates(svg, event); if(event.type=="mouseup") { xy.x = event.pageX; xy.y = event.pageY; } else if(event.type=="touchend") { let touchobj = event.changedTouches[0]; // reference first touch point xy.x = parseInt(touchobj.clientX); xy.y = parseInt(touchobj.clientY); } if(sSelected=='Range' && th.onSelectPoint) { let J={}; RectRange.style.display = 'none'; let Sec0 = Crd2Crd(RSvg, RCrdL, {'x': xyMouseDown.xSvg, 'y': 0}).x; let Sec1 = Crd2Crd(RSvg, RCrdL, {'x': xy.x, 'y': 0}).x; let SecMin = Math.min(Sec0, Sec1); SecMax = Math.max(Sec0, Sec1); for(let iS=0; iS<th.ASL.length; iS++) if(th.ASL[iS].Active)//Visible) // th.ASL[iS].SelectPoint(Sec0, Sec1, true); for(let iP = 0 ; iP<th.ASL[iS].AP.length; iP++) if(SecMin<=th.ASL[iS].AP[iP].Sec && th.ASL[iS].AP[iP].Sec<=SecMax){ if(!J[iS.toString()]) J[iS.toString()]=[]; J[iS.toString()].push(iP); } sSelected = 'Point'; // th.AfterSelectPoint(); th.onSelectPoint(J, !th.BtnSelectPointDel.bDown, !event.shiftKey && !th.BtnSelectPointAdd.bDown && !th.BtnSelectPointDel.bDown); BtnSelectPointShowHide(); } xyMouseDown={x:-1, y:-1}; svg.removeEventListener('mousemove', OnMouseMove, false); removeEventListener('mouseup', OnMouseUp, false); removeEventListener('touchend', OnMouseUp, false); svg.removeEventListener('touchmove', OnMouseMove, false); LockTouchMove=false; }; th.Show=function(AS, Visible) { if(AS==th.ASL) VisibleL=Visible; else if(AS==th.ASR) { if(!AADataR0 || AADataR0.length==0){ let R=LoadJTmpr(); if(!R) return; AParamR0=R.Param; AADataR0=R.Data; if(AADataR0) th.Data2AS(th.ASR, AADataR0, AParamR0, RCrdR); th.BuildNet(); th.Refresh(th.ASR); } VisibleR = Visible; } for(let iS = 0; iS < AS.length; iS++) AS[iS].Show(Visible ); }; th.Refresh=function(AS){ /// AS - array of series ASL or ASR for(let iS = 0; iS < AS.length; iS++) AS[iS].Refresh(); }; th.GetCTimeToJson = function (Json, bFull, bActiveOnly, i0, JSize0) { /// { "Data": {iPWM: [['01:23', 0.7], ['04:23', 0.14], ['09:03', 0.142], ['21:03', 0.13]], ...} } /// Json - here save this /// bFull - if(true)return Value; else return Value.toFixed(5) /// bActiveOnly - if(true) to json write only series ASL[iS].Active; else to json write all series /// i0 - begin from i0 index /// JSize0 - initial lenght of Json, for compare with JsonMaxSize /// return index of last include element. if was include last element, than return -1; let Count=0; if(i0==undefined) i0=0; if(JSize0==undefined) JSize0=-100000000; Json.Data = {}; JSize0+=9; // let i0=0; for (let iS = i0+1; iS < th.ASL.length; iS++) if(!bActiveOnly || th.ASL[iS].Active){ // Json.Data=th.ASL[iS].GetSeriesToJson(bFull); let J=th.ASL[iS].GetSeriesToJson(bFull); ///{PWM:3, LP:[['09:03', 0.142], ['21:03', 0.13]]} /// {iPWM: [['01:23', 0.7], ...]} //for(p in J) // Json.Data[p]=J[p]; let s=JSON.stringify(J).length; if(JSize0+s <= JsonMaxLength) { Json.Data[i0] = J; JSize0+=(s+2); } else return i0-1; i0++; // console.log(JSON.stringify(Json)); Count++; } Json.Count = Count; /// !!! Json.Count = Count; not write else PWMChanel.Type!=LED wil del // console.log("Json="+JSON.stringify(Json)); return -1; }; function SetStyle(AS, AParam, CircleR, LineW) { /// AS - array of series ASL or ASR for (let iS = 0; iS < AS.length; iS++) { if(iS==0) AS[iS].SetStyle(-1, DEC2Color(AParam[iS].Color), CircleR, 2*LineW); else AS[iS].SetStyle(-1, DEC2Color(AParam[iS].Color), CircleR, LineW); // console.log(AParam[iS].Color); } } th.SetFonColor=function(Color){ if(Color==undefined) Color='#444444'; SetNode(th.Fon, {'fill': Color}); if(RectAxeR) SetNode(RectAxeR, {'fill': Color}); if(RectAxeL) SetNode(RectAxeL, {'fill': Color}); }; th.GetRegimeEdit=function(){ return RegimeEdit; }; th.SetRegimeEdit=function(Value){ RegimeEdit=Value; for (let iS = 0; iS < th.ASL.length; iS++) th.ASL[iS].SetActive(true); th.CalcSeries0(); th.Show(th.ASL, VisibleL); let Cursor; if(RegimeEdit=="MainCh") Cursor="default"; else if(RegimeEdit=="AllCh") Cursor="pointer"; //+++ RectAxeL.style.cursor=Cursor; //+++ if(AxesVisible.L) for (i = 0; i < ALeftT.length; i++) ALeftT[i].style.cursor = "default";//Cursor; }; //----------------------------------------- let RegimeEdit="AllCh"; let LoadJTmpr=JParam.LoadJTmpr; let PMax=JParam.PMax; let svg = JParam.svg; let ALeft = [], ALeftT = []; /// left Axis line and text let ABottom = [], ABottomT = []; /// bottom Axis line and text let ARightT = []; /// right axis text, line is ALeft let Fon; let onSelect; let RFon = {x0: JParam.x0, y0: JParam.y0, x1: JParam.x1, y1: JParam.y1}; th.Series0Regime='Average'; /// 'Max' or 'Average' use in CalcSeries0Point(AS, Sec) th.ASL=[]; /// SeriesLeft =[MSeries,...] th.ASR=[]; /// SeriesLeft =[MSeries,...] let VisibleR=false; /// visible right data or not let VisibleL=false; /// visible left data or not let xyMouseDown={xSvg:-1, ySvg:-1, xObj:0, yObj:0}; /// xSvg in coord_te of svg, xObj shift in target element let sSelected=null; /// = null || 'Slider' || 'Point' th.onSliderMove=JParam.onSliderMove; /// th.onSliderMove(Slider time in millisec) th.onSelectedPoint=JParam.onSelectedPoint; // th.onAfterSelectPoint; th.onSelectPoint=JParam.onSelectPoint; th.SliderSec=0; FonW = RFon.x1 - RFon.x0 + 1; FonH = RFon.y1 - RFon.y0 + 1; r = Math.min(FonH, FonW) / 15; if (r > 10) r = 10; Unit='%'; if(JParam.Unit) Unit=JParam.Unit; let K = 1; if (JParam.K) K = JParam.K; AxesVisible={L:true, R:true}; if(JParam.AxesVisible) AxesVisible=JParam.AxesVisible; let CircleCursor="pointer"; if(JParam.CircleCursor) CircleCursor=JParam.CircleCursor; th.Fon = GetNode(svg, "rect", {x: RFon.x0, y: RFon.y0, width: FonW, height: FonH, rx: r, ry: r}); let RCrdL = {x0: 0, y0: 0, x1: 3600 * 24, y1: 100}; /// plot-rect left in unit coordinates let RCrdR = {x0: 0, y0: 0, x1: 3600 * 24, y1: 100}; /// plot-rect right in unit coordinates let RSvg = {x0: RFon.x0 + 40, y1: RFon.y0 + 25, x1: RFon.x1 - 35, y0: RFon.y1 - 20}; /// y0 - top; plot-rect in svg coordinates let svgCrd = GetNode(svg, "svg", {x: RSvg.x0, y: RSvg.y1, width: RSvg.x1 - RSvg.x0, height: RSvg.y0 - RSvg.y1}); let RSvgCrd = {x0: 0, y0: RSvg.y0 - RSvg.y1, x1: RSvg.x1 - RSvg.x0, y1: 0}; /// y0 - top; plot-rect in svgCrd coordinates let RectAxeR, RectAxeL; if(AxesVisible.R ){//&& !VerFree){ RectAxeR = GetNode(svg, "rect", {x: RSvg.x1, y: r, width: FonW-RSvg.x1, height: FonH-r}); /// for mouse click on right axis if(AxesVisible.L) RectAxeR.style.cursor='pointer'; else RectAxeR.style.cursor='default'; } if(AxesVisible.L){ RectAxeL = GetNode(svg, "rect", {x: 0, y: r, width: RSvg.x0, height: FonH-r}); /// for mouse click on right axis //+++ RectAxeL.style.cursor='pointer'; } th.SetFonColor(); // let RectPMax=GetNode(svgCrd, "rect", {x: 0, y: 0, width: RSvg.x1, height: RSvg.y0/2, fill: '#ff0000', 'fill-opacity':"0.2"}); let RectPMax=GetNode(svgCrd, "rect", {x: 0, y: 0, width: 0, height: 0, fill: '#ff0000', 'fill-opacity':"0.2"}); RectPMax.style.display='none'; let AxesLineBottom=GetNode(svg, "line", {x1: RSvg.x0, y1: RSvg.y0, x2: RSvg.x1, y2: RSvg.y0, stroke: '#ffffff', 'stroke-width': 0.5}); /// bottom axis GetNode(svg, "line", {x1: RSvg.x0, y1: RSvg.y0, x2: RSvg.x0, y2: RSvg.y1, stroke: '#ffffff', 'stroke-width': 0.5}); /// left axis GetNode(svg, "line", {x1: RSvg.x1, y1: RSvg.y0, x2: RSvg.x1, y2: RSvg.y1, stroke: '#ffffff', 'stroke-width': 0.5}); /// right axis // let RectPMax=GetNode(svgCrd, "rect", {x:0, y: 0, width: 200, height: 300, fill: '#ff0000'}); let RectRange = GetNode(svgCrd, "rect", {x: 0, y: 0, width: 1, height: RSvgCrd.y0, fill: '#004400'}); RectRange.style.display='none'; // let AColorR0 = ['#770000', '#777700', '#000077', '#007777', '770077']; // let AColorL0 = ['#ff0000', '#ffff00', '#0000ff', '#00ffff', 'ff00ff']; // let AADataL0 = [[['00:00', 1.7], ['05:03', 1.4], ['09:03', 1.42], ['21:03', 1.3]], // [['01:23', 2.7], ['04:23', 2.2], ['05:23', 2.4], ['09:23', 2.42], ['21:23', 2.3]], // [['01:43', 3.7], ['02:43', 3.2], ['04:43', 3.2], ['05:43', 3.4], ['09:43', 3.42], ['21:43', 3.3]]]; // let AADataR0 = [[['02:23', 51.5], ['04:23', 40.2], ['05:23', 55.2], ['06:23', 50.2], ['11:23', 55.4]], // [['12:23', 49.5], ['14:23', 19.2], ['16:23', 49.2], ['21:23', 51.4]], [['03:23', 49.5], ['16:23', 1.2], ['23:23', 50.4]]]; let Slider={'Text':null, 'Rect':null, 'Line':null, Sec:0}; CreateSlider(); let xSlider = 0; /// in CrdLeft BuildSlider(); // console.log('AADataL0='+JSON.stringify(AADataL0)); if(AADataL0) th.Data2AS(th.ASL, AADataL0, AParamL0, RCrdL); // let R=LoadJTmpr(); // AParamR0=R.Param; // AADataR0=R.Data; if(AADataR0) th.Data2AS(th.ASR, AADataR0, AParamR0, RCrdR); // for(let iS=0; iS<th.ASR.length; iS++) // th.ASR[iS].SetActive=false; // SetStyle(th.ASL, AParamL0, 4, 2); // SetStyle(th.ASR, AParamR0, 0, 1); th.BuildNet(); // th.Show(th.ASR, true); th.Show(th.ASL, true); if(AADataR0) th.Refresh(th.ASR); th.Refresh(th.ASL); let BtnHeight=RFon.y1-Math.max(RSvg.y1,RSvg.y0); th.BtnSelectPointDel = new MButton({"svg": svg, W: RFon.x1-RSvg.x1-3, H: BtnHeight, T: RFon.y1-BtnHeight, Text:'-', L: RSvg.x1+5, onBeforeDown: onBeforeDownBtnSelectPoint}); th.BtnSelectPointDel.Hide(); th.BtnSelectPointAdd = new MButton({"svg": svg, W: RFon.x1-RSvg.x1-3, H: BtnHeight, T: RFon.y1-2*BtnHeight, Text:'+', L: RSvg.x1+5, onBeforeDown: onBeforeDownBtnSelectPoint}); th.BtnSelectPointAdd.Hide(); function onBeforeDownBtnSelectPoint(Bt, bDown) { if(Bt==th.BtnSelectPointAdd && bDown) th.BtnSelectPointDel.Down(false, false); if(Bt==th.BtnSelectPointDel && bDown) th.BtnSelectPointAdd.Down(false, false); return true;//!Bt.bDown; } function BtnSelectPointShowHide(){ let S=CheckSelectPointCount(th.ASL); if(S && S!="") { th.BtnSelectPointAdd.Hide(); th.BtnSelectPointDel.Hide(); th.BtnSelectPointAdd.Down(false, false); th.BtnSelectPointDel.Down(false, false); } else{ th.BtnSelectPointAdd.Show(); th.BtnSelectPointDel.Show(); } } //----------------------------------------- addEventListener('mousedown', OnMouseDown, false); // addEventListener('dblclick', OnMouseDblClick, false); // addEventListener('click', OnMouseDblClick, false); MouseM.AddOnMouseClick(OnMouseDblClick); svg.addEventListener('touchstart', OnMouseDown, false);//OnTouchStart, false); // Slider.Text.addEventListener('touchstart', function(e){ // OnMouseDblClick(e); // }, false); // Slider.Rect.addEventListener('touchstart', function(e){ // OnMouseDblClick(e); // }, false); } //let JPWMParam, let JACTime;//, JPWMValue; let JCTime; //let JACTimeAdd; let ALight=[]; let iSelectCTime=-1; let ASvgCTime=[]; // let ASvgCTimeT=[]; let Edit; function SaveCTime(){ let JCTime={};//JPWMValue={}; // ACBar[0].GetBarValueToJson(JPWMValue, true, true); ACTime[0].GetCTimeToJson(JCTime, false, true); JACTime=GetJACTime(); JACTime.push({"Name":EditCTime.value, "Data":JCTime.Data}); // console.log("JACTime="+JSON.stringify(JACTime)); // if(esp==8266) SaveJSONToFile("GalleryCTime.txt", JACTime); // else // SaveJSONToFile("/GalleryCTime.txt", JACTime); SaveLoadCTime('none'); } function GetACTime(){ if(iSelectCTime<0) { alert("No chart is selected"); return; } let JCTime={}; ACTime[iSelectCTime].GetCTimeToJson(JCTime, false, true); // ACBar[iSelectCTime].GetBarValueToJson(JPWMValue, true, true); Light.SetCTime(JCTime); SaveLoadCTime('none'); } // function DelCTime(){ if(iSelectCTime<0) { alert("No chart is selected"); return; } JACTime.splice(iSelectCTime, 1); SaveJSONToFile("GalleryCTime.txt", JACTime); sleep2(500); /// need sleep else will download older version of gallery file RefreshCTime(); } // // function GetJPWMParam() { // return GetJSONFromServer({"LPWMChanel":{}}); // }; function GetJACTime() { return GetJSONFromFile("GalleryCTime.txt"); } function GetJ(bLoadJACTime){ if(!JPWMParam) JPWMParam=GetJPWMParam(); // console.log("JACTime="+JSON.stringify(JACTime)); // if(JACTime) // console.log("JACTime.length="+JACTime.length); JACTime=[]; if(bLoadJACTime) JACTime=GetJACTime(); // console.log("JACTime="+JSON.stringify(JACTime)); if(JACTime) { // console.log("JACTime.length=" + JACTime.length); } } // // function GetCount(J){ // let Count=0; // for(p in J) // Count++; // return Count; // }; // // function OnChangeBarPosition(CBar){ // // }; // function OnSelectCTime (CTime) { if(JACTimeAdd.Save) return; for(let i=0; i<ACTime.length; i++) if (ACTime[i]==CTime) { ACTime[i].SetFonColor('#2a442d'); //SetNode(ACTime[i].Fon, {'fill': '#2a442d'}); iSelectCTime = i; // ACTime[i].SendPWMValue(); } else ACTime[i].SetFonColor(); // SetNode(ACTime[i].Fon, {'fill': '#444444'}); } function CreateCTime(svg, Edit, iCell, APWMSelect) { let H = Number(svg.getAttributeNS(null, 'height')); let W = Number(svg.getAttributeNS(null, 'width')); let B = 0; let JCTimeGraph= {svg: svg, x0: B, x1: W - 2 * B, y0: B, y1: H - 2 * B, K: 1, AxesVisible:{L:true, R:false}, Unit: JACTimeAdd.Unit, onSelect: OnSelectCTime, CircleCursor:"default", PMax:JLightAll["LLight"]["PMax"] // onSliderMove: OnSliderMove, // onSelectPoint:OnSelectCTimePoint }; /// not svg let APWMParam = [{"Regime": 2, "Name": "Main", "Color": 0xffffff, "GPIO_PWM": -1, "Lm": 0, "Lm": 0, "Lux": 0, "W": 0}]; /// main bar let JPWMParam=GetJPWMParam(); let JPWMTime0;// = JACTime[iCell].Data; // console.log() if(JACTimeAdd.Save) JPWMTime0=JCTime.Data; else JPWMTime0=JACTime[iCell].Data; let AAPWMTime = [[["00:00", 0.9]]]; /// Calc ABar[0].Data = APWMParam[0] - max value for %, Lm, Lux, W let SumLux=0; let SumLm=0; let SumW=0; let IndexChanel=0; for (v in JPWMParam.Data) { // if (JPWMParam.Data[v].Type == "LED" && JPWMParam.Data[v].GPIO_PWM >= 0) { if (JPWMParam.Data[v].GPIO_PWM != "-" && JPWMParam.Data[v]["Regime"]=="Auto"){ let GPIO_PWM = JPWMParam.Data[v].GPIO_PWM; JPWMParam.Data[v].IndexChanel=IndexChanel; APWMParam.push(JPWMParam.Data[v]); SumLux+=JPWMParam.Data[v].Lux; SumLm+=JPWMParam.Data[v].Lm; SumW+=JPWMParam.Data[v].W; // if (JPWMTime0[PWM]) // AAPWMTime.push(JPWMTime0[PWM]); // else /// at part load let bAdd=false; for(vg in JPWMTime0) { // console.log("vg="+JSON.stringify(vg)); if (GetGPIO(JPWMTime0[vg].GPIO_PWM) == GetGPIO(GPIO_PWM)) { AAPWMTime.push(JPWMTime0[vg].LP); bAdd = true; break; } } if(!bAdd) { for(vg in JCTime.Data) { // console.log("vg="+JSON.stringify(vg)); if (GetGPIO(JCTime.Data[vg].GPIO_PWM) == GetGPIO(GPIO_PWM)) { AAPWMTime.push(JCTime.Data[vg].LP); // bAdd = true; break; } } } // AAPWMTime.push(JCTime.Data[PWM]); //AAPWMTime.push([[PWM + 1 + ":00", (PWM + 1) * 0.01]]); } IndexChanel++; } APWMParam[0]['Lux']=SumLux; APWMParam[0]['Lm']=SumLm; APWMParam[0]['W']=SumW; // console.log("APWMParam="+JSON.stringify(APWMParam)); // console.log("AAPWMTime="+JSON.stringify(AAPWMTime)); // Edit.value=JPWMTime0.Name; if(JACTimeAdd.Save) Edit.value=JCTime.Name; else Edit.value=JACTime[iCell].Name; let CTime = new MChartTime(JCTimeGraph, APWMParam, AAPWMTime); ACTime.push(CTime); CTime.SetRegimeEdit(JACTimeAdd.RegimeEdit); // for(iS=0; iS<CTime.ASL.length; iS++) // for(iP=0; iP<CTime.ASL[iS].AP.length; iP++) // CTime.ASL[iS].AP[iP].Circle.style.cursor='default'; // let AV=[0]; // for(let iC=1; iC<APWMParam.length; iC++) { // bFind=false; // for (p in JACBar[iCell].Data) // if (p == APWMParam[iC].PWM) { // console.log("p="+p); // AV.push(JACBar[iCell].Data[p]); // bFind=true; // break; // } // if(!bFind) // AV.push(-1); // } // console.log("AV="+JSON.stringify(AV)); // let SelectCount=0; if(APWMSelect.length>0) for(let iS=1; iS<CTime.ASL.length; iS++) { let GPIO_PWM=CTime.ASL[iS].JParam.GPIO_PWM; // let f=APWMSelect.indexOf(GPIO_PWM); let f=-1; for(i=0; i<APWMSelect.length; i++) if(GetGPIO(APWMSelect[i])==GetGPIO(GPIO_PWM)){ f=i; break; } let bAdd=false; if(f>=0) for(vg in JPWMTime0) { // console.log("vg="+JSON.stringify(vg)); if (GetGPIO(JPWMTime0[vg].GPIO_PWM)==GetGPIO(GPIO_PWM)) { AAPWMTime.push(JPWMTime0[vg].LP); bAdd = true; break; } } if(f<0 || !bAdd) CTime.ASL[iS].SetActive(false); // if(f<0 || JPWMTime0[CTime.ASL[iS].JParam.PWM]==undefined) // CTime.ASL[iS].SetActive(false); } CTime.CalcSeries0(); CTime.Show(CTime.ASL, false); } function BuildTableACTime(APWMSelect){ let CountCell,ColCount; if(JACTimeAdd.Save){ CountCell=1; ColCount=1; } else{ CountCell=GetJCount(JACTime); ColCount=1; } // console.log(CountCell); let RowCount=CountCell/ColCount; let Table=document.getElementById('idTableACTime'); //let Frame=document.getElementById("idFrameACTime"); let iCell=0; let Ch=document.getElementById("idSvgCTime"); let w=Math.min(Ch.getAttributeNS(null, 'width'), document.body.clientWidth*0.9-1); let h=Math.min(Ch.getAttributeNS(null, 'height'), document.body.clientHeight*0.5); // let w=Frame.getAttributeNS(null, 'width')*0.9; // let w=200; // let h=Frame.getAttributeNS(null, 'height')*0.9; // let h=200; for(let iR=0; iR<RowCount && iCell<CountCell; iR++){ let tr = document.createElement('tr'); tr.style.height=h+50; Table.appendChild(tr); for(let iC=0; iC<ColCount && iCell<CountCell; iC++){ let td = document.createElement('td'); // ASvgCTimeB[iC]=document.createElementNS("http://www.w3.org/2000/svg", 'svg'); // SetNode(ASvgCTimeB[iC],{'width': 500, 'height':250}); // td.appendChild(ASvgCTimeB[iC]); ASvgCTime[iC]=document.createElementNS("http://www.w3.org/2000/svg", 'svg'); SetNode(ASvgCTime[iC],{'width': w, 'height':h}); td.appendChild(ASvgCTime[iC]); EditCTime = document.createElement('input'); EditCTime.type = 'text'; EditCTime.style.width = 500; EditCTime.style.background = '#c5c5c5'; EditCTime.style.color = '#000'; EditCTime.style.border=0; // td.appendChild(EditCTime); let Div = document.createElement('div'); Div.appendChild(EditCTime); td.appendChild(Div); tr.appendChild(td); CreateCTime(ASvgCTime[iC], EditCTime, iCell, APWMSelect);//, JPWMValue); iCell++; }; }; }; // let APWMSelectCTime; //let JACBarAdd={"Unit":"%", "Save":true}; function RefreshCTime(APWMSelectCTime_, JCTime_, JACTimeAdd_) { if(APWMSelectCTime_) APWMSelectCTime=APWMSelectCTime_; if(JCTime_) JCTime=JCTime_; if(JACTimeAdd_) JACTimeAdd=JACTimeAdd_; iSelectCTime=-1; JCTime.Name="Name"; /// for save let B=document.getElementById("BtnDelCTime"); SetVisible(B, !JACTimeAdd.Save); B=document.getElementById("BtnGetACTime"); SetVisible(B, !JACTimeAdd.Save); B=document.getElementById("BtnSaveCTime"); SetVisible(B, JACTimeAdd.Save); bLoaded = false; // for(let i=0; i<ALight.length; i++){ // delete ACTime[i]; // delete ASvgCTime[i]; // // delete ASvgCTimeT[i]; // } // ACTime=[]; // ASvgCTimeB=[]; // ASvgCTimeT=[]; // // Table=document.getElementById('idTableACTime'); // for (; Table.getElementsByTagName('tr').length > 0; ) // Table.deleteRow(0); ClearCTime(); GetJ(!JACTimeAdd.Save);// && JACBar==undefined); BuildTableACTime(APWMSelectCTime); bLoaded = true; }; function ClearCTime(){ for(let i=0; i<ALight.length; i++){ ACTime[i].Free(); delete ACTime[i]; delete ASvgCTime[i]; // delete ASvgCTimeT[i]; }; ACTime=[]; ASvgCTimeB=[]; ASvgCTimeT=[]; Table=document.getElementById('idTableACTime'); // console.log("Table.getElementsByTagName('tr').length="+Table.getElementsByTagName('tr').length); for (; Table.getElementsByTagName('tr').length > 0; ){ // console.log("delRow"); Table.deleteRow(0); }; // console.log("Table.getElementsByTagName('tr').length="+Table.getElementsByTagName('tr').length); };