/**
* Copyright 2012-2019, Plotly, Inc.
* All rights reserved.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/

'use strict';

// var Lib = require('../../lib');

function calc(gd, trace) {
    var cd = [];

    var lastReading = trace.value;
    var secondLastReading = trace._lastValue || trace.value;
    var deltaRef = trace._hasDelta ? trace.delta.reference || secondLastReading : secondLastReading;
    cd[0] = {
        y: lastReading,
        lastY: secondLastReading,

        delta: lastReading - deltaRef,
        relativeDelta: (lastReading - deltaRef) / deltaRef,
    };
    return cd;
}

module.exports = {
    calc: calc
};

/**
* Copyright 2012-2019, Plotly, Inc.
* All rights reserved.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/

'use strict';

// var Lib = require('../../lib');

function calc(gd, trace) {
    var cd = [];

    var lastReading = trace.value;
    var secondLastReading = trace._lastValue || trace.value;
    var deltaRef = secondLastReading;
    if(trace._hasDelta && typeof trace.delta.reference === 'number') {
        deltaRef = trace.delta.reference;
    }
    cd[0] = {
        y: lastReading,
        lastY: secondLastReading,

        delta: lastReading - deltaRef,
        relativeDelta: (lastReading - deltaRef) / deltaRef,
    };
    return cd;
}

module.exports = {
    calc: calc
};

fix for delta.reference equal to zero