All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.meteoinfo.chart.axis.LogAxis Maven / Gradle / Ivy

There is a newer version: 3.8
Show newest version
/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package org.meteoinfo.chart.axis;

import org.meteoinfo.chart.ChartText;
import org.meteoinfo.common.DataConvert;
import org.meteoinfo.common.MIMath;

import java.util.ArrayList;
import java.util.List;

/**
 *
 * @author Yaqiang Wang
 */
public class LogAxis extends Axis {
    // 
    // 
    // 
    /**
     * Constructor
     * @param axis Axis
     */
    public LogAxis(Axis axis){
        super(axis);
    }
    // 
    // 
    // 
    // 
    /**
     * Update tick values
     */
    @Override
    public void updateTickValues() {
        double[] r = MIMath.getIntervalValues_Log(this.getMinValue(), this.getMaxValue());
        this.setTickValues((double[]) r);
        this.setTickDeltaValue(1);
    }
    
    @Override
    public void updateTickLabels(){
        List tls = new ArrayList<>();
        String lab;
        if (this.isAutoTick()) {
            if (this.getTickValues() == null) {
                return;
            }
            for (double value : this.getTickValues()) {
                lab = String.valueOf(value);
                lab = DataConvert.removeTailingZeros(lab);
                tls.add(new ChartText(lab));
            }

            List values = new ArrayList<>();
            for (ChartText tl : tls){
                values.add(Double.parseDouble(tl.getText()));
            }
            tls.clear();
            int e;
            for (Double v : values){
                e = (int) Math.floor(Math.log10(v));
                tls.add(new ChartText("$10^{" + String.valueOf(e) + "}$"));
            }
        } else {
            for (int i = 0; i < this.getTickLocations().size(); i++) {
                if (i >= this.getTickLabels().size()) {
                    break;
                }
                double v = this.getTickLocations().get(i);
                if (v >= this.getMinValue() && v <= this.getMaxValue()) {
                    tls.add(this.getTickLabels().get(i));
                }
            }
        }

        this.setTickLabels(tls);
    }
    
    // 
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy