<commit_before>/**
 * Copyright 2011 - 2015 Xeiam LLC.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.xeiam.xchart.internal.chartpart;

import java.math.BigDecimal;

import com.xeiam.xchart.StyleManager;
import com.xeiam.xchart.internal.Utils;
import com.xeiam.xchart.internal.chartpart.Axis.Direction;

/**
 * This class encapsulates the logic to generate the axis tick mark and axis tick label data for rendering the axis ticks for logarithmic axes
 *
 * @author timmolter
 */
public class AxisTickLogarithmicCalculator extends AxisTickCalculator {

  NumberFormatter numberFormatter = null;

  /**
   * Constructor
   *
   * @param axisDirection
   * @param workingSpace
   * @param minValue
   * @param maxValue
   * @param styleManager
   */
  public AxisTickLogarithmicCalculator(Direction axisDirection, double workingSpace, double minValue, double maxValue, StyleManager styleManager) {

    super(axisDirection, workingSpace, minValue, maxValue, styleManager);
    numberFormatter = new NumberFormatter(styleManager);
    calculate();
  }

  private void calculate() {

    // a check if all axis data are the exact same values
    if (minValue == maxValue) {
      tickLabels.add(numberFormatter.formatNumber(BigDecimal.valueOf(maxValue), minValue, maxValue, axisDirection));
      tickLocations.add(workingSpace / 2.0);
      return;
    }

    // tick space - a percentage of the working space available for ticks
    double tickSpace = styleManager.getAxisTickSpacePercentage() * workingSpace; // in plot space

    // where the tick should begin in the working space in pixels
    double margin = Utils.getTickStartOffset(workingSpace, tickSpace); // in plot space double gridStep = getGridStepForDecimal(tickSpace);

    // System.out.println("minValue: " + minValue);
    // System.out.println("maxValue: " + maxValue);
    int logMin = (int) Math.floor(Math.log10(minValue));
    int logMax = (int) Math.ceil(Math.log10(maxValue));
    // System.out.println("logMin: " + logMin);
    // System.out.println("logMax: " + logMax);

    if (axisDirection == Direction.Y && styleManager.getYAxisMin() != null) {
      logMin = (int) (Math.log10(styleManager.getYAxisMin())); // no floor
    }
    if (axisDirection == Direction.Y && styleManager.getYAxisMax() != null) {
      logMax = (int) (Math.log10(styleManager.getYAxisMax())); // no floor
    }
    if (axisDirection == Direction.X && styleManager.getXAxisMin() != null) {
      logMin = (int) (Math.log10(styleManager.getXAxisMin())); // no floor
    }
    if (axisDirection == Direction.X && styleManager.getXAxisMax() != null) {
      logMax = (int) (Math.log10(styleManager.getXAxisMax())); // no floor
    }

    // double firstPosition = getFirstPosition(tickStep);
    // System.out.println("firstPosition: " + firstPosition);
    double firstPosition = Utils.pow(10, logMin);
    double tickStep = Utils.pow(10, logMin - 1);

    for (int i = logMin; i <= logMax; i++) { // for each decade

      // System.out.println("tickStep: " + tickStep);
      // System.out.println("firstPosition: " + firstPosition);
      // System.out.println("i: " + i);
      // System.out.println("Utils.pow(10, i): " + Utils.pow(10, i));

      // using the .00000001 factor to deal with double value imprecision
      for (double j = firstPosition; j <= Utils.pow(10, i) + .00000001; j = j + tickStep) {

        // System.out.println("j: " + j);<commit_msg>LogarithmicCalculator abort when really small chart<commit_after>/**
 * Copyright 2011 - 2015 Xeiam LLC.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.xeiam.xchart.internal.chartpart;

import java.math.BigDecimal;

import com.xeiam.xchart.StyleManager;
import com.xeiam.xchart.internal.Utils;
import com.xeiam.xchart.internal.chartpart.Axis.Direction;

/**
 * This class encapsulates the logic to generate the axis tick mark and axis tick label data for rendering the axis ticks for logarithmic axes
 *
 * @author timmolter
 */
public class AxisTickLogarithmicCalculator extends AxisTickCalculator {

  NumberFormatter numberFormatter = null;

  /**
   * Constructor
   *
   * @param axisDirection
   * @param workingSpace
   * @param minValue
   * @param maxValue
   * @param styleManager
   */
  public AxisTickLogarithmicCalculator(Direction axisDirection, double workingSpace, double minValue, double maxValue, StyleManager styleManager) {

    super(axisDirection, workingSpace, minValue, maxValue, styleManager);
    numberFormatter = new NumberFormatter(styleManager);
    calculate();
  }

  private void calculate() {

    // a check if all axis data are the exact same values
    if (minValue == maxValue) {
      tickLabels.add(numberFormatter.formatNumber(BigDecimal.valueOf(maxValue), minValue, maxValue, axisDirection));
      tickLocations.add(workingSpace / 2.0);
      return;
    }

    // tick space - a percentage of the working space available for ticks
    double tickSpace = styleManager.getAxisTickSpacePercentage() * workingSpace; // in plot space

    // this prevents an infinite loop when the plot gets sized really small.
    if (tickSpace < styleManager.getXAxisTickMarkSpacingHint()) {
      return;
    }

    // where the tick should begin in the working space in pixels
    double margin = Utils.getTickStartOffset(workingSpace, tickSpace); // in plot space double gridStep = getGridStepForDecimal(tickSpace);

    // System.out.println("minValue: " + minValue);
    // System.out.println("maxValue: " + maxValue);
    int logMin = (int) Math.floor(Math.log10(minValue));
    int logMax = (int) Math.ceil(Math.log10(maxValue));
    // System.out.println("logMin: " + logMin);
    // System.out.println("logMax: " + logMax);

    if (axisDirection == Direction.Y && styleManager.getYAxisMin() != null) {
      logMin = (int) (Math.log10(styleManager.getYAxisMin())); // no floor
    }
    if (axisDirection == Direction.Y && styleManager.getYAxisMax() != null) {
      logMax = (int) (Math.log10(styleManager.getYAxisMax())); // no floor
    }
    if (axisDirection == Direction.X && styleManager.getXAxisMin() != null) {
      logMin = (int) (Math.log10(styleManager.getXAxisMin())); // no floor
    }
    if (axisDirection == Direction.X && styleManager.getXAxisMax() != null) {
      logMax = (int) (Math.log10(styleManager.getXAxisMax())); // no floor
    }

    double firstPosition = Utils.pow(10, logMin);
    // System.out.println("firstPosition: " + firstPosition);
    double tickStep = Utils.pow(10, logMin - 1);

    for (int i = logMin; i <= logMax; i++) { // for each decade

      // System.out.println("tickStep: " + tickStep);
      // System.out.println("firstPosition: " + firstPosition);
      // System.out.println("i: " + i);
      // System.out.println("Utils.pow(10, i): " + Utils.pow(10, i));

      // using the .00000001 factor to deal with double value imprecision
      for (double j = firstPosition; j <= Utils.pow(10, i) + .00000001; j = j + tickStep) {

        // System.out.println("j: " + j);
{'fraction_non_alphanumeric': 0.11977091633466136, 'fraction_numerical': 0.013197211155378486, 'mean_word_length': 3.4977603583426653, 'pattern_counts': {'":': 0, '<': 8, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 4, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1570681', 'n_tokens_mistral': 2428, 'n_tokens_neox': 2306, 'n_words': 687}