stats display

This commit is contained in:
2016-03-30 01:09:37 +02:00
parent aac5a78974
commit a778eb6d64
19 changed files with 152 additions and 59 deletions
+22 -17
View File
@@ -907,7 +907,7 @@ var Chartist = {
positionalData[axis.counterUnits.len] = axisOffset - 10;
var lblText = labels[index];
//round (!! will brak for non-numeric)
//round (!! will break for non-numeric)
lblText = Math.round(+lblText*100)/100;
if(useForeignObject) {
@@ -2907,7 +2907,8 @@ var Chartist = {
}
function createGridAndLabels(gridGroup, labelGroup, useForeignObject, chartOptions, eventEmitter) {
var axisOptions = chartOptions['axis' + this.units.pos.toUpperCase()];
var xy = this.units.pos.toUpperCase();
var axisOptions = chartOptions['axis' + xy];
var projectedValues = this.ticks.map(this.projectValue.bind(this));
var labelValues = this.ticks.map(axisOptions.labelInterpolationFnc);
@@ -2920,21 +2921,25 @@ var Chartist = {
// TODO: Find better solution for solving this problem
// Calculate how much space we have available for the label
var labelLength=0;/*
if(projectedValues[index + 1]) {
// If we still have one label ahead, we can calculate the distance to the next tick / label
labelLength = projectedValues[index + 1] - projectedValue;
lastWidth = labelLength;
} else if (typeof lastWidth != 'undefined') {
labelLength = lastWidth; // EDIT. added the lastWidth thing
}
// else {
// // If we don't have a label ahead and we have only two labels in total, we just take the remaining distance to
// // on the whole axis length. We limit that to a minimum of 30 pixel, so that labels close to the border will
// // still be visible inside of the chart padding.
// labelLength = Math.max(this.axisLength - projectedValue, 30);
// }
*/
var labelLength=0;
if (xy == 'Y') { // X doesnt use this
if (projectedValues[index + 1]) {
// If we still have one label ahead, we can calculate the distance to the next tick / label
labelLength = projectedValues[index + 1] - projectedValue;
// lastWidth = labelLength;
// } else if (typeof lastWidth != 'undefined') {
// labelLength = lastWidth; // EDIT. added the lastWidth thing
} else {
// If we don't have a label ahead and we have only two labels in total, we just take the remaining distance to
// on the whole axis length. We limit that to a minimum of 30 pixel, so that labels close to the border will
// still be visible inside of the chart padding.
labelLength = Math.max(this.axisLength - projectedValue, 30);
}
}
// Skip grid lines and labels where interpolated label values are falsey (execpt for 0)
if(Chartist.isFalseyButZero(labelValues[index]) && labelValues[index] !== '') {
+24 -11
View File
@@ -3,10 +3,10 @@ var page_waveform = (function () {
var zoomResetFn;
function buildChart(samples, xlabel, ylabel) {
var data = [];
samples.forEach(function (a, i) {
data.push({x: i, y: a});
function buildChart(obj, xlabel, ylabel) {
var points = [];
obj.samples.forEach(function (a, i) {
points.push({x: i, y: a});
});
// Build the chart
@@ -45,11 +45,13 @@ var page_waveform = (function () {
}
}));
var peak = obj.stats.peak;
new Chartist.Line('#chart', {
series: [
{
name: 'a',
data: data
data: points
},
]
}, {
@@ -69,6 +71,8 @@ var page_waveform = (function () {
axisY: {
type: Chartist.AutoScaleAxis,
//onlyInteger: true
high: peak,
low: -peak,
},
plugins: plugins
});
@@ -81,13 +85,21 @@ var page_waveform = (function () {
return;
}
var json = JSON.parse(resp);
if (!json.success) {
var j = JSON.parse(resp);
if (!j.success) {
alert("Sampling failed.");
return;
}
buildChart(json.samples, 'Sample number', 'Current - mA');
j.stats.peak = Math.max(-j.stats.min, j.stats.max);
buildChart(j, 'Sample number', 'Current - mA');
$('#stat-count').html(j.stats.count);
$('#stat-f-s').html(j.stats.freq);
$('#stat-i-peak').html(j.stats.peak);
$('#stat-i-rms').html(j.stats.rms);
$('.stats').removeClass('invis');
}
wfm.init = function() {
@@ -96,7 +108,7 @@ var page_waveform = (function () {
// "success": true
// };
function clickHdl() {
function loadBtnClick() {
var samples = $('#count').val();
var freq = $('#freq').val();
@@ -104,14 +116,15 @@ var page_waveform = (function () {
$().get('/api/raw.json?n='+samples+'&fs='+freq, onRxData, true, true);
}
$('#load').on('click', clickHdl);
$('#load').on('click', loadBtnClick);
$('#count,#freq').on('keyup', function(e) {
if (e.which == 13) {
clickHdl();
loadBtnClick();
}
});
// chart zooming
$('#chart').on('contextmenu', function(e) {
zoomResetFn && zoomResetFn();
zoomResetFn = null;