This is what I have come up with:
- Use an expression tag to hold a dataset of the history tag source paths and the friendly names (custom tag prop) via an expression binding that calls a script to get all tags with history enabled (and the custom tag prop).
- Bind this with a script transform to the options array of a dropdown (multi-select enabled).
- Use a change script on the dropdown value prop to populate a custom array prop (
value_pens
) of the pen JSON objects from the dataset.
- Bind the power chart pens prop to the custom dropdown prop.
- Hide the power table's tag browser and pen browser.
- Expression tag and script:
runScript("trendPens.getTrendList()")
def getAllTrendPens():
data = system.db.runNamedQuery("getHistoryTags")
if data is not None:
historyTagPaths = data.getColumnAsList(0)
trendLabelPaths = [historyTag+".Trend_Label" for historyTag in historyTagPaths]
trendLabels_qv = system.tag.readBlocking(trendLabelPaths)
trendLabels = [label.value for label in trendLabels_qv]
colors = ["#66FFFF","#B266FF","#FF3333", "#66FF66", "#000099", "#FF66B2", "#CCCC00", "#000000", "#606060" ]
pens = []
for i, pen in enumerate(trendLabels):
if pen is not None:
color = colors[i % len(colors)]
#print pen
#print historyTagPaths[i]
jsonObject = {
"name": pen,
"visible": True,
"enabled": True,
"selectable": True,
"axis": "",
"plot": 0,
"display": {
"type": "line",
"interpolation": "curveLinear",
"breakLine": True,
"radius": 3,
"styles": {
"normal": {
"stroke": {
"color": color,
"width": 1,
"opacity": 0.8,
"dashArray": 0
},
"fill": {
"color": color,
"opacity": 0.8
}
},
"highlighted": {
"stroke": {
"color": color,
"width": 1,
"opacity": 1,
"dashArray": 0
},
"fill": {
"color": color,
"opacity": 1
}
},
"selected": {
"stroke": {
"color": color,
"width": 1,
"opacity": 1,
"dashArray": 0
},
"fill": {
"color": color,
"opacity": 1
}
},
"muted": {
"stroke": {
"color": color,
"width": 1,
"opacity": 0.4,
"dashArray": 0
},
"fill": {
"color": color,
"opacity": 0.4
}
}
}
},
"data": {
"source": "histprov:MSSQLSERVER1:/drv:ignition-scada-pc:default:/tag:"+historyTagPaths[i],
"aggregateMode": "default"
}
}
pens.append(system.util.jsonEncode(jsonObject))
return pens
def getTrendList():
headers = ["Name", "Pen"]
pens = trendPens.getAllTrendPens()
names = [system.util.jsonDecode(pen)["name"] for pen in pens]
data = [[name,pen] for name, pen in zip(names, pens)]
dataset = system.dataset.toDataSet(headers, data)
return dataset
- Tag binding transform:
def transform(self, value, quality, timestamp):
data = system.dataset.toPyDataSet(value)
options = [{"label":row["Name"], "pen": row["Pen"]} for row in data]
sortedData = sorted(options, key=lambda d: d['label'])
return [dict(item, **{'value':index}) for index, item in enumerate(sortedData)]
- Value change script:
def valueChanged(self, previousValue, currentValue, origin, missedEvents):
if currentValue.value is None:
self.custom.value_pens = None
else:
pens = [system.util.jsonDecode(self.props.options[value.value].pen) for value in currentValue.value]
self.custom.value_pens = pens
Now I just need to figure out why my dropdown modal popup won't allow me to scroll...