Exemple #1
0
  /**
   * Checks if the tick label is major (...,0.01,0.1,1,10,100,...).
   *
   * @param tickValue the tick label value
   * @return true if the tick label is major
   */
  private boolean isMajorTick(double tickValue) {
    if (!axis.isLogScaleEnabled()) {
      return true;
    }

    if (Math.log10(tickValue) % 1 == 0) {
      return true;
    }

    return false;
  }
Exemple #2
0
  /** Updates the visibility of tick labels. */
  private void updateTickVisibility() {

    // initialize the array of tick label visibility state
    tickVisibilities.clear();
    for (int i = 0; i < tickLabelPositions.size(); i++) {
      tickVisibilities.add(Boolean.TRUE);
    }

    if (tickLabelPositions.size() == 0 || axis.getTick().getTickLabelAngle() != 0) {
      return;
    }

    // set the tick label visibility
    int previousPosition = 0;
    for (int i = 0; i < tickLabelPositions.size(); i++) {

      // check if there is enough space to draw tick label
      boolean hasSpaceToDraw = true;
      if (i != 0) {
        hasSpaceToDraw =
            hasSpaceToDraw(previousPosition, tickLabelPositions.get(i), tickLabels.get(i));
      }

      // check if the tick label value is major
      boolean isMajorTick = true;
      if (!axis.isValidCategoryAxis()) {
        if (axis.isLogScaleEnabled()) {
          isMajorTick = isMajorTick(tickLabelValues.get(i));
        }

        // check if the same tick label is repeated
        String currentLabel = tickLabels.get(i);
        try {
          double value = Double.parseDouble(currentLabel);
          if (value != tickLabelValues.get(i)) {
            isMajorTick = false;
          }
        } catch (NumberFormatException e) {
          // label is not decimal value but string
        }
      }

      if (hasSpaceToDraw && isMajorTick) {
        previousPosition = tickLabelPositions.get(i);
      } else {
        tickVisibilities.set(i, Boolean.FALSE);
      }
    }
  }
Exemple #3
0
  /**
   * Updates the tick labels.
   *
   * @param length the axis length
   */
  protected void update(int length) {
    tickLabelValues.clear();
    tickLabels.clear();
    tickLabelPositions.clear();

    if (axis.isValidCategoryAxis()) {
      updateTickLabelForCategoryAxis(length);
    } else if (axis.isLogScaleEnabled()) {
      updateTickLabelForLogScale(length);
    } else if (axis.isDateEnabled()) {
      updateTickLabelForDateAxis(length);
    } else {
      updateTickLabelForLinearScale(length);
    }

    updateTickVisibility();
    updateTickLabelMaxLength();
  }