onTrendParamsChange - event of the PmgTrendViewer object
Parameters:
pMe | (Object) Reference to the PmgTrendViewer object where the event rises. |
pEvent | (Object) Reference to object describing detailed information about the specific event.
pEvent.Init - ( Boolean) [ for reading] If this parameter is true, then it signals that this event is called for the first time (on start). |
---|
Connection of trend values from trConnect marameter:
Initialization of trend values acquired from trConnect parameter and refresh of values into the table configured as trend viewer header
JavaScriptVBScriptSelect and copy to clipboard
//#pragma variable sName=Macro("$.text('sys','name')")
//#pragma variable sUnit=Macro("$.text('sys','unit')")
//#pragma variable sMin=Macro("$.text('sys','minimum')")
//#pragma variable sMax=Macro("$.text('sys','maximum')")
//#pragma variable sValue=Macro("$.text('sys','value')")
var oTHead = pMe.Items("../AxTrendsHead");
var oTView = pMe;
var oTrend, nLength, aTr, trConnect, i, nCount;
if (bInit)
{
oTHead.SetCellText(0, 2, sName);
oTHead.SetCellText(0, 3, sUnit);
oTHead.SetCellText(0, 4, sMin);
oTHead.SetCellText(0, 5, sMax);
oTHead.SetCellText(0, 6, sValue);
// start read and connection parameter "trConnect"
trConnect = pMe.GetPar("trConnect");
if (Pm.IsValid(trConnect) && trConnect != "")
{
aTr = Pm.StringSplit(trConnect, ",", "empty:1;");
nLength = aTr.GetSize(1);
for (i = 0; i < nLength; i += 2)
{
oTrend = oTView.AddTrend("t" + i, "$default");
oTrend.Connect(1, "local", aTr.GetItem(i), aTr.GetItem(i + 1), "iniread=name,unit,min,max,color");
}
}
// end read and connection parameter "trConnect"
pMe.Vars("cfgini").Value = oTView.GetCfg("Trends;TimeZoom;", "");
}
nCount = oTView.TrendsCount;
oTHead.Rows = nCount + 1;
for (i = 1; i <= nCount; i++)
{
oTrend = oTView.Trends(i, -1);
oTHead.SetCellText(i, 1, oTrend.Visible ? "" : "X");
oTHead.SetCellText(i, 2, oTrend.Name);
oTHead.SetCellTextAlign(i, 2, 0);
oTHead.SetCellText(i, 3, oTrend.Unit);
oTHead.SetCellText(i, 4, Pm.Round(oTrend.ValueMin, 0.001));
oTHead.SetCellText(i, 5, Pm.Round(oTrend.ValueMax, 0.001));
if (! oTView.Autoscroll)
{
oTHead.SetCellText(i, 6, Pm.Round(oTrend.CursorValue(2), 0.001));
}
oTHead.SetCellBackColor(i, 0, oTrend.GraphDefault.Color);
}
oTHead.SetCellBackColor(oTHead.FocusedRow, -3, "transparent");
oTHead.FocusedRow = oTView.TrendActive + 1;
oTHead.SetCellBackColor(oTView.TrendActive + 1, -3, "#009898");
// text align cols
oTHead.SetCellTextAlign(-3, 1, 1);
// Visible - align center
oTHead.SetCellTextAlign(-3, 2, 0);
// Name - align left
oTHead.SetCellTextAlign(-3, 3, 1);
// Unit - align center
oTHead.SetCellTextAlign(-3, 4, 1);
// Min - align center
oTHead.SetCellTextAlign(-3, 5, 1);
// Max - align center
oTHead.SetCellTextAlign(-3, 6, 2);
// Value - align right
oTHead.Draw();
if (bInit && ! oTView.Autoscroll)
{
oTView.ReadData();
}
'#pragma variable sName=Macro("$.text('sys','name')")
'#pragma variable sUnit=Macro("$.text('sys','unit')")
'#pragma variable sMin=Macro("$.text('sys','minimum')")
'#pragma variable sMax=Macro("$.text('sys','maximum')")
'#pragma variable sValue=Macro("$.text('sys','value')")
Dim oTHead, oTView, oTrend, nLength, aTr, trConnect, i, nCount
Set oTHead = pMe.Items("../AxTrendsHead")
Set oTView = pMe
If bInit Then
oTHead.SetCellText 0, 2, sName
oTHead.SetCellText 0, 3, sUnit
oTHead.SetCellText 0, 4, sMin
oTHead.SetCellText 0, 5, sMax
oTHead.SetCellText 0, 6, sValue
' start read and connection parameter "trConnect"
trConnect = pMe.GetPar("trConnect")
If Pm.IsValid(trConnect) And trConnect <> "" Then
aTr = Pm.StringSplit(trConnect, ",", "empty:1;")
nLength = UBound(aTr) + 1
For i = 0 To nLength - 1 Step 2
Set oTrend = oTView.AddTrend("t" & i, "$default")
oTrend.Connect 1, "local", aTr(i), aTr(i + 1), "iniread=name,unit,min,max,color"
Next
End If
' end read and connection parameter "trConnect"
pMe.Vars("cfgini").Value = oTView.GetCfg("Trends;TimeZoom;", "")
End If
nCount = oTView.TrendsCount
oTHead.Rows = nCount + 1
For i = 1 To nCount
Set oTrend = oTView.Trends(i, -1)
If oTrend.Visible Then
oTHead.SetCellText i, 1, ""
Else
oTHead.SetCellText i, 1, "X"
End If
oTHead.SetCellText i, 2, oTrend.Name
oTHead.SetCellTextAlign i, 2, 0
oTHead.SetCellText i, 3, oTrend.Unit
oTHead.SetCellText i, 4, Pm.Round(oTrend.ValueMin, 0.001)
oTHead.SetCellText i, 5, Pm.Round(oTrend.ValueMax, 0.001)
If Not oTView.Autoscroll Then
oTHead.SetCellText i, 6, Pm.Round(oTrend.CursorValue(2), 0.001)
End If
oTHead.SetCellBackColor i, 0, oTrend.GraphDefault.Color
Next
oTHead.SetCellBackColor oTHead.FocusedRow, -3, "transparent"
oTHead.FocusedRow = oTView.TrendActive + 1
oTHead.SetCellBackColor oTView.TrendActive + 1, -3, "#009898"
' text align cols
oTHead.SetCellTextAlign -3, 1, 1
' Visible - align center
oTHead.SetCellTextAlign -3, 2, 0
' Name - align left
oTHead.SetCellTextAlign -3, 3, 1
' Unit - align center
oTHead.SetCellTextAlign -3, 4, 1
' Min - align center
oTHead.SetCellTextAlign -3, 5, 1
' Max - align center
oTHead.SetCellTextAlign -3, 6, 2
' Value - align right
oTHead.Draw
If bInit And Not oTView.Autoscroll Then
oTView.ReadData
End If