Exemplo n.º 1
0
  /**
   * Updates the filters of the filteredDataTableView so that the data is filtered by the user
   * defined ranges (if applicable) of the {@link DimensionConfig}s.
   */
  private void updateFilteredDataTable() {
    cachedSampledDataTable = null;
    List<ValueRange> dimensionRanges = new LinkedList<ValueRange>();
    for (PlotDimension dimension : PlotDimension.values()) {
      DimensionConfig dimConf =
          plotInstance.getCurrentPlotConfigurationClone().getDimensionConfig(dimension);
      if (dimConf != null) {
        if (dimConf.isUsingUserDefinedLowerBound() || dimConf.isUsingUserDefinedUpperBound()) {
          ValueRange dimensionRange =
              dimConf.getUserDefinedRangeClone(filteredDataTableView.getParentTable());
          if (dimensionRange instanceof NumericalValueRange) {
            NumericalValueRange numericalDimensionRange = (NumericalValueRange) dimensionRange;
            if (!dimConf.isUsingUserDefinedLowerBound()) {
              numericalDimensionRange.setLowerBound(Double.NEGATIVE_INFINITY);
            }
            if (!dimConf.isUsingUserDefinedUpperBound()) {
              numericalDimensionRange.setUpperBound(Double.POSITIVE_INFINITY);
            }
          }
          if (dimensionRange != null) {
            dimensionRanges.add(dimensionRange);
          }
        }
      }
    }

    filteredDataTableView.replaceConditions(dimensionRanges);

    dataTableIsValid = true;
  }
  /**
   * @param valueGroups
   * @param valuesAreDates
   *     <p>TODO use param valuesAreDates
   */
  protected void applyAdaptiveVisualRounding(List<ValueRange> valueGroups, boolean valuesAreDates) {
    if (valuesAreDates) {
      DateFormat dateFormat = getDateFormat();
      for (ValueRange range : valueGroups) {
        NumericalValueRange numericalValueRange = (NumericalValueRange) range;
        numericalValueRange.setDateFormat(dateFormat);
      }
    } else {
      // values are not dates

      // first pass
      NumericalValueRange previous = null;
      NumericalValueRange current = null;
      NumericalValueRange next = null;
      for (ValueRange valueGroup : valueGroups) {
        next = (NumericalValueRange) valueGroup;
        if (previous != null) {
          int precisionLower =
              Math.min(
                  DataStructureUtils.getOptimalPrecision(
                      current.getLowerBound(), current.getUpperBound()),
                  DataStructureUtils.getOptimalPrecision(
                      previous.getLowerBound(), current.getLowerBound()));
          int precisionUpper =
              Math.min(
                  DataStructureUtils.getOptimalPrecision(
                      current.getLowerBound(), current.getUpperBound()),
                  DataStructureUtils.getOptimalPrecision(
                      current.getUpperBound(), next.getUpperBound()));
          if (precisionUpper >= Integer.MAX_VALUE) {
            precisionUpper = precisionLower;
          }
          current.setVisualPrecision(precisionLower, precisionUpper);
        } else if (current != null) {
          int precisionLower =
              DataStructureUtils.getOptimalPrecision(
                  current.getLowerBound(), current.getUpperBound());
          int precisionUpper =
              Math.min(
                  DataStructureUtils.getOptimalPrecision(
                      current.getLowerBound(), current.getUpperBound()),
                  DataStructureUtils.getOptimalPrecision(
                      current.getUpperBound(), next.getUpperBound()));
          if (precisionUpper >= Integer.MAX_VALUE) {
            precisionUpper = precisionLower;
          }
          current.setVisualPrecision(precisionLower, precisionUpper);
        }
        previous = current;
        current = next;
      }
      if (previous != null) {
        // even if eclipse states that this code is dead, it is not! (eclipse bug)
        int precisionLower =
            Math.min(
                DataStructureUtils.getOptimalPrecision(
                    current.getLowerBound(), current.getUpperBound()),
                DataStructureUtils.getOptimalPrecision(
                    previous.getLowerBound(), current.getLowerBound()));
        int precisionUpper =
            DataStructureUtils.getOptimalPrecision(
                current.getLowerBound(), current.getUpperBound());
        if (precisionUpper >= Integer.MAX_VALUE) {
          precisionUpper = precisionLower;
        }
        current.setVisualPrecision(precisionLower, precisionUpper);
      } else if (current != null) {
        int precision =
            DataStructureUtils.getOptimalPrecision(
                current.getLowerBound(), current.getUpperBound());
        current.setVisualPrecision(precision, precision);
      }

      //		// second pass
      //		current = null;
      //		next = null;
      //		for (ValueRange valueGroup : valueGroups ) {
      //			next = (NumericalValueRange)valueGroup;
      //			if (current != null) {
      //				int currentPrecision = current.getUpperPrecision();
      //				int nextPrecision = next.getLowerPrecision();
      //				int precision = Math.min(nextPrecision, currentPrecision);
      //				current.setUpperPrecision(precision);
      //				next.setLowerPrecision(precision);
      //			}
      //			current = next;
      //		}
    }
  }