1 |
- var VarValue=[];function Cmd(CmdStr){var a;try{eval("a = "+CmdStr+";")}catch(e){a=0;alert("表达式错误: "+CmdStr+"\n请在组态程序中修正后重新发布!")}return a}ht.Chart=function(e,t,a){var i=this,n=i._view=document.createElement("div");n.style.width=t+"px";n.style.height=a+"px";n.style.position="absolute";n.style.setProperty("box-sizing","border-box",null);i._option=e;i._chart=echarts.init(i.getView());if(e)i._chart.setOption(e);i._FIRST=true};function getDateString(e){var t=e.getDate();var a=e.getMonth()+1;var i=e.getFullYear();var n=e.getHours();var s=e.getMinutes();var r=e.getSeconds();var o=i+"/"+a+"/"+t+" "+n+":"+s+":"+r;return o}function GetDital(e,t){if(e==null||e==undefined)return 0;else{var a=e;if(isNaN(a))return 0;else return a.toFixed(t)}}ht.Default.def("ht.Chart",Object,{ms_v:1,ms_fire:1,ms_ac:["chart","option","isFirst","view"],validateImpl:function(){var e=this,t=e._chart;t.resize();if(e._FIRST){e._FIRST=false}},setSize:function(e,t){var a=this._view;a.style.width=e+"px";a.style.height=t+"px"}});ht.DataModel.prototype.isAutoAdjustIndex=function(){return false};function submitAddSingle(e,t,a){var i={TagName:e,Time:a,Value:t};if(i.Time===""){var n=new Date;var s=n.getDate();var r=n.getMonth()+1;var o=n.getFullYear();var l=n.getHours();var d=n.getMinutes();var u=n.getSeconds();var h=o+"/"+r+"/"+s+" "+l+":"+d+":"+u;i.Time=h}var c=JSON.stringify(i);$.ajax({url:"http://"+webServiceIP+":"+webServicePort+"/api/Snapshot/?isSingleData=True",type:"POST",data:c,contentType:"application/json; charset=utf-8",success:function(e){if(typeof e=="string"&&e.constructor==String){if(e!=="True")alert(e)}else{var t=e.ErrorList;if(t!=null&&t.length>0){alert(t[0].ErrorMsg)}}},error:function(e){if(e.responseText==="")alert("网络链接错误");else alert(e.responseText)}})}function getHisData(option,cmdStr,callBack){str="http://"+webServiceIP+":"+webServicePort+"/api/History?tagName="+cmdStr;str=encodeURI(str);$.ajax({url:str,type:"GET",dataType:"json",cache:false,success:function(data){if(data===null)return;var hisValues=eval(data);var k=0;var date=[];var test_data={};if(hisValues!=null){for(tag in hisValues){test_data[tag]=[];option.series[k]={};option.series[k].name=tag;option.series[k].type="line";option.series[k].showSymbol=false;option.series[k].sampling="average";option.legend.data.push(tag);for(var i=0;i<hisValues[tag].length;i++){test_data[tag][i]=[];test_data[tag][i].push(new Date(hisValues[tag][i].Time));test_data[tag][i].push(parseFloat(hisValues[tag][i].Value))}option.series[k].data=test_data[tag];k++}}callBack(option);return test_data},complete:function(e,t){e=null}})}function SetRotatPositionRelative(e,t,a){var i=e.getPosition().x-t.getPosition().x;var n=e.getPosition().y-t.getPosition().y;e.setPosition(Math.cos(a)*i-Math.sin(a)*n+t.getPosition().x,Math.cos(a)*n+Math.sin(a)*i+t.getPosition().y)}function SetRotatPositionAbsolute(e,t,a,i){var n=e.getPosition().x-t;var s=e.getPosition().y-a;e.setPosition(Math.cos(i)*n-Math.sin(i)*s+t,Math.cos(i)*s+Math.sin(i)*n+a)}function initPage(){dataModel=new ht.DataModel;graphView=new ht.graph.GraphView(dataModel);view=graphView.getView();graphView.enableFlow();selectionModel=dataModel.getSelectionModel();view.className="main";document.body.appendChild(view);window.addEventListener("resize",function(e){graphView.fitContent(false,0,true)},false)}function hisRefresh(option,chart){str="http://"+webServiceIP+":"+webServicePort+"/api/Snapshot?tagName="+"demo.demo_ai001,demo.demo_ai002,demo.demo_ai003,demo.demo_ai004";str=encodeURI(str);$.ajax({url:str,type:"GET",dataType:"json",cache:false,success:function(data){if(data===null)return;var snapshots=eval(data);if(snapshots!=null){var newOption={};var varList=testHisOption.legend.data;var dataChanged=false;newOption.series=option.series;for(var i=0;i<snapshots.length;i++){var index=varList.indexOf(snapshots[i].TagName);if(index>=0&&index<varList.length){var tagValue=parseFloat(snapshots[i].Value);var tagTime=new Date(snapshots[i].Time);var len=newOption.series[index].data.length;if(len==undefined||len<=0||newOption.series[index].data[len-1][0].toString()!==tagTime.toString()||newOption.series[index].data[len-1][1]!==tagValue){dataChanged=true;var newData=[];newData.push(tagTime);newData.push(tagValue);newOption.series[index].data.push(newData);if(newOption.series[index].data.length>2e4){newOption.series[index].data.splice(0,newOption.series[index].data.length-2e4)}}}}if(dataChanged){chart.setOption(newOption)}}},complete:function(e,t){e=null}})}function getDivText(e){return $(e).text()}function creatTree(e,t,a){var i=new ht.Data;i.setName(e.name);t.add(i);if(a!==undefined)i.setParent(a);if(e.child!==undefined){for(var n=0;n<e.child.length;n++){creatTree(e.child[n],t,i)}}return i}
|