// bytran -|- spectral calculations for portable devices using the HITRAN database
//
// Developed by Dzianis Pliutau (Denis Plutov) and Kostya Roslyakov
// www.bytran.org | contact@bytran.org
// Copyright (c) 2016 Dzianis Pliutau
// Distributed under the MIT license
//
// The MIT License (MIT)
// Copyright (c) 2016 Dzianis Pliutau
//
// Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation
// files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy,
// modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software
// is furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR
// IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.



// Object contains parameters responsible for the vertical axis display and scaling
#include "yaxis.h"
#include "math.h"

YAxis::YAxis()
{
    // Setting the default values
    this->minYPlot = 0;
    this->maxYPlot = 100;
    this->yPlotUnits = 0;

    // Saving the vertical axis units
    this->yAxisTitles.resize(4);
    this->yAxisTitles[0] = "Absorption (%)";
    this->yAxisTitles[1] = "Transmission (%)";
    this->yAxisTitles[2] = "Optical depth";
    this->yAxisTitles[3] = "Cross-section, m^2"; // Not used right now, will probably be used later
}

// Methods to get and set the minimum vertical axis value
double YAxis::getMinYPlot() { return this->minYPlot; }
void YAxis::setMinYPlot(double newMinYPlot) { this->minYPlot = newMinYPlot; }

// Methods to get and set the maximum vertical axis value
double YAxis::getMaxYPlot() { return this->maxYPlot; }
void YAxis::setMaxYPlot(double newMaxYPlot) { this->maxYPlot = newMaxYPlot; }

// Methods to get and set the vertical axis plot units
int YAxis::getYPlotUnits() { return this->yPlotUnits; }
void YAxis::setYPlotUnits(int newYPlotUnits) { this->yPlotUnits = newYPlotUnits; }

// Method to get the vertical axis title (current units)
QString YAxis::getYAxisTitle()
{
    return this->yAxisTitles[this->yPlotUnits];
}

// Method to convert the vertical axis units from the default to current
double YAxis::toCurrentFromDefault(double defaultUnitsValue)
{
    if (this->yPlotUnits == 0)  // Absorption
    {
        return 100 * (1 - exp(-defaultUnitsValue));
    }
    else if (this->yPlotUnits == 1)
    {
        return 100 * exp(-defaultUnitsValue);
    }
    else if (this->yPlotUnits == 2)
    {
        return defaultUnitsValue;
    }

    // If none of the above work, return the default
    return defaultUnitsValue;
}
