var normalizeValues = function()

in source/web_site/js/dash.js [413:452]


    var normalizeValues = function(labels, times, vals) {
        //make existing and new labels/vals as an array of objects, sort it based on label.
        //if any value is 0, check if label before and after is less than 10 seconds. if so remove it.
        // Constraint: any consecutive non-zero value will be atleast 10 seconds apart.
        n=labels.length;
        if (n>0) {
            var indicesOfLabelsToRemove = range1(n-1).filter(function(key, _) {
                return ((times[key-1] + 10000 < times[key]) || (times[key] + 10000 < times[key+1])) && allzeros(vals.map(function(val) {return val[key]; }));
            });
            console.log('indices to remove ' + indicesOfLabelsToRemove);
            console.log('labels before removing ' + labels);
            console.log('times before removing ' + times);
            for (i=indicesOfLabelsToRemove.length-1; i>=0; i--) {
                x=indicesOfLabelsToRemove[i];
                labels.splice(x,1);
                times.splice(x,1);
                vals.forEach(function(valArray) { valArray.splice(x,1);});
            };

            console.log('labels after removing ' + labels);
        }


        var labelsToAdd = range1(n).filter(function(key) {
            return (times[key]>=times[key-1]+20000)
        });
        //console.log('labels to add ' + labelsToAdd);
        for (i=labelsToAdd.length-1; i>=0; i--) {
            x=labelsToAdd[i];
            noOfLabelsToInsert = (times[x]-times[x-1])/10000 - 1;
            for (j=0;j<noOfLabelsToInsert; j++) {
                timeToInsert = times[x] - 10000;
                labels.splice(x,0, getTimeLabel(getFormattedTime(new Date(timeToInsert))));
                times.splice(x,0, timeToInsert);
                vals.forEach(function(valArray) { valArray.splice(x,0,0);});
            }
        };
        //console.log('final labels ' + labels);
        //console.log('final times' + times);
    };