js.dataplotter.livePlotterController.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', '$q', '$interval', '$translate', '$stateParams', 'ChannelsService', 'ChannelDataService'];
var LivePlotterController = function ($scope, $q, $interval, $translate, $stateParams, ChannelsService, ChannelDataService) {
$scope.channels = [];
$scope.selectedChannels = [];
$scope.plotting = false;
$scope.paused = false;
$scope.advanced = false;
$scope.enableAutoRange = true;
$scope.yMinValue = null;
$scope.yMaxValue = null;
var data = [];
var nowText;
var secondsText;
var minutesText;
var hoursText;
var noData;
var maxValuesToDisplay;
if ($stateParams.name) {
$scope.livePlotter = $scope.getPlotter($stateParams.name);
}
if ($scope.livePlotter && $scope.livePlotter.timePeriod) {
$scope.timePeriod = $scope.livePlotter.timePeriod;
} else {
$scope.timePeriod = 60;
}
if ($scope.livePlotter && $scope.livePlotter.timePeriodUnit) {
$scope.timePeriodUnit = $scope.livePlotter.timePeriodUnit;
} else {
$scope.timePeriodUnit = 'seconds';
}
var computeNewRefreshrate = function () {
var timePeriod = $scope.timePeriod;
var tu = $scope.timePeriodUnit;
if (tu === 'seconds') {
timePeriod *= 1e3;
} else if (tu === 'minutes') {
timePeriod *= 60 * 1e3;
} else {
timePeriod *= 60 * 60 * 1e3;
}
var r = Math.round(timePeriod / 60);
if (r < 500) {
r = 500;
} else if (r > 10e3) {
r = 10e3;
}
$scope.refresh = r;
};
if ($scope.livePlotter && $scope.livePlotter.refresh) {
$scope.refresh = $scope.livePlotter.refresh;
} else {
computeNewRefreshrate();
}
$translate('NOW').then((text) => nowText = text);
$translate('SECONDS').then((text) => secondsText = text);
$translate('MINUTES').then((text) => minutesText = text);
$translate('HOURS').then((text) => hoursText = text);
$translate('NO_DATA_TO_DISPLAY').then(text => noData = text);
ChannelsService.getAllChannels().then(async function(channels) {
channels = channels.records;
var allConfigChannelsDefined = false;
if ($scope.livePlotter && $scope.livePlotter.channels) {
allConfigChannelsDefined = true;
$scope.livePlotter.channels.forEach(c => {
if (channels.find(ch => ch.id === c.id) === undefined) {
console.log('ERROR : No channel with id \'' + c.id + '\'');
allConfigChannelsDefined = false;
}
//console.log(channel.id + ", " + channel.label + ", " + allConfigChannelsDefined);
});
}
if (allConfigChannelsDefined) {
//console.log("All Channels defined")
$scope.channels = $scope.livePlotter.channels;
} else {
$scope.channels = channels.map(channel => ({
id: channel.id,
label: channel.id,
preselect: false,
valueType: channel.valueType
}));
}
//console.log($scope.channels);
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;
}
}
});
var buildChart = function (data) {
var chart = nv.models.lineChart()
.margin({left: 50, right: 10}) //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)
.defined((d, i) => typeof(d.y) === 'number' && !isNaN(d.y) && d.y !== null);
chart.legend.maxKeyLength(100);
if ($scope.yMinValue != null && $scope.yMaxValue != null){
if ((isNaN(parseInt($scope.yMinValue)) === true || isNaN(parseInt($scope.yMaxValue))) || $scope.enableAutoRange == true){
console.log(parseInt($scope.yMinValue));
console.log(parseInt($scope.yMaxValue));
}
else {
chart.yDomain([$scope.yMinValue,$scope.yMaxValue]);
}
}
chart.interactiveLayer.tooltip.contentGenerator(function (d) {
var header = d.value;
var headerhtml = "" + header + " ";
var bodyhtml = "";
var series = d.series;
series.forEach((c) => {
var unit;
let channel = data.find(o => o.id === c.key);
if (channel.unit == undefined) {
unit = '';
} else {
unit = ' ' + channel.unit;
}
var valueUnit;
if (c.value == undefined) {
valueUnit = 'undefined';
} else {
valueUnit = c.value + unit;
}
bodyhtml = bodyhtml + '' + c.key
+ ' ' + valueUnit
+ ' ';
});
bodyhtml = bodyhtml + '';
return "" + headerhtml + '' + bodyhtml + "
";
});
chart.yAxis //Chart y-axis settings
.tickFormat(d3.format('.03f'));
chart.xAxis //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