js.dataplotter.dataPlotterController.js Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of openmuc-webui-dataplotter Show documentation
Show all versions of openmuc-webui-dataplotter Show documentation
Data Plotter plug-in for the WebUI of the OpenMUC framework.
The newest version!
(function () {
var injectParams = ['$scope', '$stateParams', '$state', '$q', '$translate', 'ChannelsService', 'notify', 'ChannelDataService'];
var noData;
var DataPlotterController = function ($scope, $stateParams, $state, $q, $translate, ChannelsService, notify, ChannelDataService) {
$scope.mstep = 1;
$scope.options = {mstep: [1, 5, 10, 15]}
if ($stateParams.name) {
$scope.dataPlotter = $scope.getPlotter($stateParams.name);
}
if ($scope.dataPlotter && $scope.dataPlotter.startDate) {
$scope.startDate = new Date(parseInt($scope.dataPlotter.startDate));
} else {
//default start time of plot interval 16 hours in the past (rounded to full hrs)
var now = new Date();
$scope.startDate = new Date(now.setHours(now.getHours() - 16, 0, 0, 0));
}
if ($scope.dataPlotter && $scope.dataPlotter.endDate) {
$scope.endDate = new Date(parseInt($scope.dataPlotter.endDate));
} else {
//default final time of plot interval next full hour in the future
var now = new Date();
$scope.endDate = new Date(now.setHours(now.getHours() + 1, 0, 0, 0));
}
$scope.isTS = $scope.dataPlotter && $scope.dataPlotter.isTS;
$translate('NO_DATA_TO_DISPLAY').then(text => noData = text);
$scope.channels = [];
$scope.selectedChannels = [];
ChannelsService.getAllChannels().then(async function (channels) {
channels = channels.records;
var allConfigChannelsDefined = false;
if ($scope.dataPlotter && $scope.dataPlotter.channels) {
var cIndex = $scope.dataPlotter.channels.findIndex((channel) => channels.indexOf(channel.id) === -1);
allConfigChannelsDefined = cIndex === -1;
}
if (allConfigChannelsDefined) {
//console.log("All Channels defined")
$scope.channels = $scope.dataPlotter.channels;
$scope.selectedChannels = $scope.channels.filter((channel) => channel.preselect === 'true');
} else {
$scope.channels = channels.map((channel) => {
return {id: channel.id, label: channel.id, preselect: false, valueType: channel.valueType};
});
for (let channel of $scope.channels){
var config = await ChannelDataService.channelHasHistoricValues(channel);
if (config != false) {
channel.historic = await config;
var logging = await ChannelDataService.getChannelConfig(channel, 'loggingInterval');
channel.loggingInterval = await logging.loggingInterval;
}
}
for (let channel of $scope.channels){
//console.log(channel.preselect);
if (channel.preselect === 'true') {
$scope.selectedChannels.push(channel);
}
var config = await ChannelDataService.getChannelConfig(channel, 'unit');
if (config === true) {}
else{
channel.unit = await config.unit;
}
}
}
//console.log($scope.channels);
});
var buildChart = function (data) {
var chart = nv.models.lineWithFocusChart()
.margin({left: 55, right: 25}) //Adjust chart margins to give the x-axis some breathing room.
.interactive(true)
.useInteractiveGuideline(true) //We want nice looking tooltips and a guideline!
.showLegend(true) //Show the legend, allowing users to turn on/off line series.
.showYAxis(true) //Show the y-axis
.showXAxis(true) //Show the x-axis
.forceY(plotRange())
.noData(noData)
.width(450)
.height(300);
chart.legend.maxKeyLength(100);
if (data == undefined){
console.log(data);
chart.useInteractiveGuideline(false);
chart.showXAxis(false);
}
chart.interactiveLayer.tooltip.contentGenerator(function (d) {
var unixDate = new Date(d.value+1000);
var month = unixDate.getMonth() + 1;
var date = ('0'+unixDate.getDate()).slice(-2);
var hour = unixDate.getHours();
var min = ('0'+unixDate.getMinutes()).slice(-2);
var time = date + '.' + month + '. ' + hour + ':' + min;
var header = time;
var headerhtml = "" + header + " ";
var bodyhtml = "";
var series = d.series;
series.forEach((c, i) => {
var unit;
let channel = data.find(o => o.key === c.key);
if (channel.unit == undefined) {
unit = '';
} else {
unit = ' ' + channel.unit;
}
var valueUnit;
if (c.value == undefined) {
valueUnit = 'undefined';
} else {
valueUnit = c.value.toFixed(3) + unit;
}
bodyhtml = bodyhtml + '' + c.key
+ ' ' + valueUnit
+ ' ';
});
bodyhtml = bodyhtml + '';
return "" + headerhtml + '' + bodyhtml + "
";
});
data.forEach((c, i) => {
let channel = data.find(o => o.key === c.key);
position = data.indexOf(channel);
channel.values.forEach(function(value){
valuePosition = channel.values.indexOf(value);
if (value.x !== channel.values[valuePosition+1].x - channel.loggingInterval && value.y !== null){
data[position].values.splice(valuePosition+1, 0, {x: value.x+channel.loggingInterval, y: null, series: 0});
}
});
});
chart.xAxis //Chart x-axis settings
.tickFormat(xAxisTickFormat());
chart.yAxis //Chart y-axis settings
.tickFormat(d3.format('.03f'));
chart.x2Axis //Chart x-axis settings
.tickFormat(xAxisTickFormat());
/* Done setting the chart up? Time to render it!*/
// d3.select('#graph svg') //Select the
© 2015 - 2025 Weber Informatics LLC | Privacy Policy