this.ractive.fire("obtainData");
var template = this;
var model = this.ractive;
var startRange = "";
var endRange = "";
var tpoint = model.queryAll("targetPoint");
if(tpoint.length > 0) tpoint = tpoint[0].pointId;
else tpoint = "undefined";
var query = this.query.replace(/\$id/g, tpoint);
var dataQuery = query+'.hisRead(today)';
function clearTabs(item){
model.set('myStart', "Date Picker");
model.set('myEnd', "Date Picker");
model.set('startPick', "Start");
model.set('endPick', "End");
}
function updateChart(newQuery, buttonInd){
var test = template.view.querySelector("#amChartPoint");
var buttonIds = [
event.result.columns.forEach(function(itm){template.view.querySelector("#day"),
template.view.querySelector("#week"),
var t = /v\d+/.exec(itm.name); template.view.querySelector("#month"),
template.view.querySelector("#datePicker"),
if(t !== null && t[0] == t.input){ template.view.querySelector("#datePickerStart"),
template.view.querySelector("#datePickerEnd")
];
if(itm.metadata) cols.push({dis:
itm.metadata.idDis || itm.metadata.dis || itm.metadata.id, col: itm.name, unit: itm.metadata.unit || null, equipRefDis: itm.metadata.equipRefDisbuttonIds.forEach(function(itm){ itm.style.backgroundColor = "#4f7ab3"; });
buttonIds[buttonInd].style.backgroundColor = "#7093c1";
else cols.push({dis: itm.name, col: itm.name});setTimeout(function() {
finstack.eval(newQuery, function(event){
} var cols = [];
}); event.result.columns.forEach(function(itm){
var grphst = []/v\d+/.exec(itm.name);
var cou = 0; if(t !== null && t[0] == t.input){
cols.forEach(function(itm){ grphsif(itm.metadata) cols.push({dis: itm.metadata.idDis || itm.metadata.dis || itm.metadata.id, col: itm.name, unit: itm.metadata.unit || null, equipRefDis: itm.metadata.equipRefDis});
"id": "g"+cou,
else cols.push({dis: itm.name, col: itm.name});
}
"balloonText": ""+itm.equipRefDis+": [["+itm.col+"]] "+itm.unit+"", });
"lineThickness": 2, var grphs = [];
"title": itm.dis, var cou = 0;
cols.forEach(function(itm){
"unit" : itm.unit, grphs.push({
"valueField": itm.col, "id": "g"+cou,
"fillAlphas": 0.2 //Area "balloonText": ""+itm.equipRefDis+": [["+itm.col+"]] "+itm.unit+"",
}); "lineThickness": 2,
cou++; }); "title": itm.dis,
var myData"unit" =: event.result.toObj();itm.unit,
var chartData =[]; "valueField": itm.col,
var myData2 = []; "fillAlphas": 0.2 //Area
myData.forEach(function(itm){ });
myData2.push({ cou++;
});
"ts": itm.ts,
"tsOffset": itm.tsOffset,
var myData = event.result.toObj();
var chartData =[];
"tsTimezone": itm.tsTimezone, var myData2 = [];
"v0": itm.v0 || 0,
myData.forEach(function(itm){
"v1": itm.v1 || 0, myData2.push({
"v2ts": itm.v2 || 0ts,
"v3tsOffset": itm.v3 || 0tsOffset,
"v4tsTimezone": itm.v4 || 0tsTimezone,
"v5v0": itm.v5v0 || 0,
"v6v1": itm.v6v1 || 0,
"v7v2": itm.v7v2 || 0,
}); "v3": itm.v3 || 0,
}); "v4": itm.v4 || 0,
myData2.forEach(function(itm){ "v5": itm.v5 chartData.push({|| 0,
"tsv6": itm.tsv6 || 0,
"tsOffsetv7": itm.tsOffset,v7 || 0
});
"tsTimezone": itm.tsTimezone, });
"v0": itm.v0.toFixed(1) ||
null, myData2.forEach(function(itm){
"v1": itmchartData.v1.toFixed(1) || null,push({
"v2ts": itm.v2.toFixed(1) || nullts,
"v3tsOffset": itm.v3.toFixed(1) || nulltsOffset,
"v4tsTimezone": itm.v4.toFixed(1) || nulltsTimezone,
"v5v0": itm.v5v0.toFixed(1) || null,
"v6v1": itm.v6v1.toFixed(1) || null,
"v7v2": itm.v7v2.toFixed(1) || null,
});"v3": itm.v3.toFixed(1) || null,
}); "v4": itm.v4.toFixed(1) || null,
var chart = AmCharts.makeChart(test, {"v5": itm.v5.toFixed(1) || null,
"typev6": "serial", itm.v6.toFixed(1) || null,
"themev7": "light", itm.v7.toFixed(1) || null
"marginRight": 80,});
});
"dataProvider": chartData,
"valueAxes": [{ var chart = AmCharts.makeChart(test, {
"axisAlpha "type": 0.1 "serial",
}]"theme": "light",
"graphsmarginRight": grphs80,
"zoomOutButtonRollOverAlphadataProvider": 0.15chartData,
"chartCursorvalueAxes": [{
"categoryBalloonDateFormataxisAlpha": "MMMM D L:NN A",0.1
}],
"cursorPositiongraphs": "mouse"grphs,
"showNextAvailablezoomOutButtonRollOverAlpha": true0.15,
},
"legend"chartCursor": {
"equalWidths": truecategoryBalloonDateFormat": "MMMM D L:NN A",
"positioncursorPosition": "topmouse",
"valueAlignshowNextAvailable": "left",true
},
"valueWidth": 100 "legend": {
}, "autoMarginOffsetequalWidths": 5true,
"columnWidthposition": 1"top",
"categoryFieldvalueAlign": "tsleft",
"categoryAxisvalueWidth": { 100
},
"parseDatesautoMarginOffset": true5,
"columnWidth": 1,
"minPeriod": "mm", "categoryField": "ts",
"dateFormats":[ "categoryAxis": {
{ "parseDates": true,
"periodminPeriod": "fffmm",
"dateFormats":[
"format":"L:NN:SS A"
}, {
"period":"ssfff",
"format":"L:NN:SS A"
},
{
"period":"mmss",
"format":"L:NN:SS A"
},
{
"period":"hhmm",
"format":"L:NN A"
},
{
"period":"DDhh",
"format":"MMML:NN DDA"
},
{
"period":"WWDD",
"format":"MMM DD"
},
{
"period":"MMWW",
"format":"MMM DD"
},
{
"period":"YYYYMM",
"format":"YYYYMMM"
}] },
}, {
"chartScrollbar": { "enabled": true "period":"YYYY",
}, "exportformat":"YYYY"
{ "enabled": true}]
},
}); "chartScrollbar": {
chart.addListener("rendered", zoomChart);"enabled": true,
zoomChart(); },
function zoomChart() { "export": {
chart.zoomToIndexes(chart.dataProvider.length - 40, chart.dataProvider.length - 1);"enabled": true
},
});
}, 200); }
this.ractive.on("day", function(event) { updateChart(dataQuery.replace(/(\.*\hisRead).*$/g,'.hisRead(today)'), 0);
});
this.ractive.on("week", function(event chart.addListener("rendered", zoomChart);
zoomChart();
function zoomChart() {
updateChart(dataQuery.replace(/(\.*\hisRead).*$/g,'.hisRead(thisWeek)'), 1);
});
this.ractive.on("month", function(event) {
updateChart( chart.zoomToIndexes(chart.dataProvider.length - 40, chart.dataProvider.length - 1);
}
});
}, 200);
}
this.ractive.on("day", function(event) {
clearTabs(true);
updateChart(dataQuery.replace(/(\.*\hisRead).*$/g,'.hisRead(today)'), 0);
});
this.ractive.on("week", function(event) {
clearTabs(true);
updateChart(dataQuery.replace(/(\.*\hisRead).*$/g,'.hisRead(thisWeek)'), 1);
});
this.ractive.on("month", function(event) {
clearTabs(true);
updateChart(dataQuery.replace(/(\.*\hisRead).*$/g,'.hisRead(thisMonth)'), 2);
});
this.ractive.on("datePicker", function(event) {
clearTabs(true);
top.app.ShowCalendar(null,function(data){
var start = moment(data.range.start).format("YYYY-MM-DD");
var end = moment(data.range.end).format("YYYY-MM-DD");
var dateStringStart = start;
var startDate = new moment(dateStringStart).format('MM/DD/YYYY');
var dateStringEnd = end;
var endDate = new moment(dateStringEnd).format('MM/DD/YYYY');
model.set('myStart', startDate);
model.set('myEnd', endDate);
var newQuery = "";
if(start == end) newQuery= dataQuery.replace(/(\.*\hisRead).*$/g,'.hisRead('+start+')');
else newQuery= dataQuery.replace(/(\.*\hisRead).*$/g,'.hisRead('+start+'..'+end+')');
updateChart(newQuery, 3);
},
{periods:true});
});
this.ractive.on("datePickerStart", function(event) {
clearTabs(true);
top.app.ShowCalendar(null,function(data){
startRange = moment(data.range.start).format("YYYY-MM-DD");
var dateStringStart = startRange;
var startDate = new moment(dateStringStart).format('MM/DD/YYYY');
model.set('startPick', startDate);
var newQuery = "";
// newQuery = dataQuery.replace(/(\.*\hisRead).*$/g,'.hisRead(thisMonth)'), 2);
});
this.ractive.on("datePicker", function(event) {
top.app.ShowCalendar(null,function(data){g,'.hisRead('+start+')');
var start = moment(data.range.start).format("YYYY-MM-DD"updateChart("", 4);
});
});
this.ractive.on("datePickerEnd", function(event) var{
end = moment(data.range.end).format("YYYY-MM-DDmodel.set('myStart', "Date Picker");
model.set('myEnd', "Date Picker");
var dateStringStart = start;
top.app.ShowCalendar(null,function(data){
var startDateendRange = new moment(dateStringStartdata.range.end).format('"YYYY-MM/-DD/YYYY'");
var dateStringEnd = endendRange;
var endDate = new moment(dateStringEnd).format('MM/DD/YYYY');
;
var newQuery = "" model.set('endPick', endDate);
if(start == end) newQuery= dataQuery.replace(/(\.*\hisRead).*$/g,'.hisRead('+start+')')var newQuery = "";
else newQuery= dataQuery.replace(/(\.*\hisRead).*$/g,'.hisRead('+startstartRange+'..'+endendRange+')');
updateChart(newQuery, 35);
},
{periods:true});
}); |