@Test @Ignore public void references7() { ValueScale logScale = ValueScales.logScale(); ValueAxis axis = logScale.references(Ranges.range(100, 100.1), 2, 6); assertAxisEquals(100, 100.1, new double[]{100.00,100.02,100.04,100.06,100.08,100.10}, new String[]{"100.00", "100.02", "100.04", "100.06", "100.08", "100.10"}, axis); }
@Override public ValueAxis references(Range range, int minRefs, int maxRefs) { double minValue = range.getMinimum(); double maxValue = range.getMaximum(); if (minValue == 0 || maxValue == 0) { throw new IllegalArgumentException("The range for a log scale can't include 0"); } if (Math.signum(minValue) != Math.signum(maxValue)) { throw new IllegalArgumentException("The range for a log scale must be all positive or all negative"); } int minExp = MathUtil.orderOf(minValue); int maxExp = MathUtil.orderOf(maxValue); int expRange = maxExp - minExp + 1; int maxRefsPerOrder = maxRefs / expRange; int currentFactor = quantize(maxRefsPerOrder); ListDouble references = generateReferenceValues(range, currentFactor); while (references.size() > maxRefs && currentFactor != 1) { currentFactor = decreaseFactor(currentFactor); references = generateReferenceValues(range, currentFactor); } int orderOfIncrement = MathUtil.orderOf(currentFactor); NumberFormat format; boolean useExponentialNotation; if ((minExp - orderOfIncrement) < -3 || maxExp > 3) { useExponentialNotation = true; format = NumberFormats.format(orderOfIncrement); } else { useExponentialNotation = false; format = NumberFormats.format(Math.max(0, orderOfIncrement - minExp)); } String[] labels = new String[references.size()]; for (int i = 0; i < references.size(); i++) { double value = references.getDouble(i); if (useExponentialNotation) { labels[i] = format(value, format, Integer.toString(MathUtil.orderOf(value)), Math.pow(10, MathUtil.orderOf(value))); } else { labels[i] = format(value, format, null, 1); } } return new ValueAxis(minValue, maxValue, CollectionNumbers.doubleArrayCopyOf(references), labels); }
LogValueScale implements ValueScale { @Override public ValueAxis references(Range range, int minRefs, int maxRefs) { double minValue = range.getMinimum(); double maxValue = range.getMaximum(); if (minValue == 0 || maxValue == 0) { throw new IllegalArgumentException("The range for a log scale can't include 0"); } if (Math.signum(minValue) != Math.signum(maxValue)) { throw new IllegalArgumentException("The range for a log scale must be all positive or all negative"); } int minExp = MathUtil.orderOf(minValue); int maxExp = MathUtil.orderOf(maxValue); int expRange = maxExp - minExp + 1; int maxRefsPerOrder = maxRefs / expRange; int currentFactor = quantize(maxRefsPerOrder); ListDouble references = generateReferenceValues(range, currentFactor); while (references.size() > maxRefs && currentFactor != 1) { currentFactor = decreaseFactor(currentFactor); references = generateReferenceValues(range, currentFactor); } int orderOfIncrement = MathUtil.orderOf(currentFactor); NumberFormat format; boolean useExponentialNotation; if ((minExp - orderOfIncrement) < -3 || maxExp > 3) { useExponentialNotation = true; format = NumberFormats.format(orderOfIncrement); } else { useExponentialNotation = false; format = NumberFormats.format(Math.max(0, orderOfIncrement - minExp)); } String[] labels = new String[references.size()]; for (int i = 0; i < references.size(); i++) { double value = references.getDouble(i); if (useExponentialNotation) { labels[i] = format(value, format, Integer.toString(MathUtil.orderOf(value)), Math.pow(10, MathUtil.orderOf(value))); } else { labels[i] = format(value, format, null, 1); } } return new ValueAxis(minValue, maxValue, CollectionNumbers.doubleArrayCopyOf(references), labels); } }
LogValueScale implements ValueScale { @Override public ValueAxis references(Range range, int minRefs, int maxRefs) { double minValue = range.getMinimum(); double maxValue = range.getMaximum(); if (minValue == 0 || maxValue == 0) { throw new IllegalArgumentException("The range for a log scale can't include 0"); } if (Math.signum(minValue) != Math.signum(maxValue)) { throw new IllegalArgumentException("The range for a log scale must be all positive or all negative"); } int minExp = MathUtil.orderOf(minValue); int maxExp = MathUtil.orderOf(maxValue); int expRange = maxExp - minExp + 1; int maxRefsPerOrder = maxRefs / expRange; int currentFactor = quantize(maxRefsPerOrder); ListDouble references = generateReferenceValues(range, currentFactor); while (references.size() > maxRefs && currentFactor != 1) { currentFactor = decreaseFactor(currentFactor); references = generateReferenceValues(range, currentFactor); } int orderOfIncrement = MathUtil.orderOf(currentFactor); NumberFormat format; boolean useExponentialNotation; if ((minExp - orderOfIncrement) < -3 || maxExp > 3) { useExponentialNotation = true; format = NumberFormats.format(orderOfIncrement); } else { useExponentialNotation = false; format = NumberFormats.format(Math.max(0, orderOfIncrement - minExp)); } String[] labels = new String[references.size()]; for (int i = 0; i < references.size(); i++) { double value = references.getDouble(i); if (useExponentialNotation) { labels[i] = format(value, format, Integer.toString(MathUtil.orderOf(value)), Math.pow(10, MathUtil.orderOf(value))); } else { labels[i] = format(value, format, null, 1); } } return new ValueAxis(minValue, maxValue, CollectionNumbers.doubleArrayCopyOf(references), labels); }  }
LogValueScale implements ValueScale { @Override public ValueAxis references(Range range, int minRefs, int maxRefs) { double minValue = range.getMinimum(); double maxValue = range.getMaximum(); if (minValue == 0 || maxValue == 0) { throw new IllegalArgumentException("The range for a log scale can't include 0"); } if (Math.signum(minValue) != Math.signum(maxValue)) { throw new IllegalArgumentException("The range for a log scale must be all positive or all negative"); } int minExp = MathUtil.orderOf(minValue); int maxExp = MathUtil.orderOf(maxValue); int expRange = maxExp - minExp + 1; int maxRefsPerOrder = maxRefs / expRange; int currentFactor = quantize(maxRefsPerOrder); ListDouble references = generateReferenceValues(range, currentFactor); while (references.size() > maxRefs && currentFactor != 1) { currentFactor = decreaseFactor(currentFactor); references = generateReferenceValues(range, currentFactor); } int orderOfIncrement = MathUtil.orderOf(currentFactor); NumberFormat format; boolean useExponentialNotation; if ((minExp - orderOfIncrement) < -3 || maxExp > 3) { useExponentialNotation = true; format = NumberFormats.format(orderOfIncrement); } else { useExponentialNotation = false; format = NumberFormats.format(Math.max(0, orderOfIncrement - minExp)); } String[] labels = new String[references.size()]; for (int i = 0; i < references.size(); i++) { double value = references.getDouble(i); if (useExponentialNotation) { labels[i] = format(value, format, Integer.toString(MathUtil.orderOf(value)), Math.pow(10, MathUtil.orderOf(value))); } else { labels[i] = format(value, format, null, 1); } } return new ValueAxis(minValue, maxValue, CollectionNumbers.doubleArrayCopyOf(references), labels); }  @Override double scaleValue(double value, double minValue, double maxValue, double newMinValue, double newMaxValue); @Override double invScaleValue(double scaleValue, double actualMinValue, double actualMaxValue, double scaleMinValue, double scaleMaxValue); @Override ValueAxis references(Range range, int minRefs, int maxRefs); }
LogValueScale implements ValueScale { @Override public ValueAxis references(Range range, int minRefs, int maxRefs) { double minValue = range.getMinimum(); double maxValue = range.getMaximum(); if (minValue == 0 || maxValue == 0) { throw new IllegalArgumentException("The range for a log scale can't include 0"); } if (Math.signum(minValue) != Math.signum(maxValue)) { throw new IllegalArgumentException("The range for a log scale must be all positive or all negative"); } int minExp = MathUtil.orderOf(minValue); int maxExp = MathUtil.orderOf(maxValue); int expRange = maxExp - minExp + 1; int maxRefsPerOrder = maxRefs / expRange; int currentFactor = quantize(maxRefsPerOrder); ListDouble references = generateReferenceValues(range, currentFactor); while (references.size() > maxRefs && currentFactor != 1) { currentFactor = decreaseFactor(currentFactor); references = generateReferenceValues(range, currentFactor); } int orderOfIncrement = MathUtil.orderOf(currentFactor); NumberFormat format; boolean useExponentialNotation; if ((minExp - orderOfIncrement) < -3 || maxExp > 3) { useExponentialNotation = true; format = NumberFormats.format(orderOfIncrement); } else { useExponentialNotation = false; format = NumberFormats.format(Math.max(0, orderOfIncrement - minExp)); } String[] labels = new String[references.size()]; for (int i = 0; i < references.size(); i++) { double value = references.getDouble(i); if (useExponentialNotation) { labels[i] = format(value, format, Integer.toString(MathUtil.orderOf(value)), Math.pow(10, MathUtil.orderOf(value))); } else { labels[i] = format(value, format, null, 1); } } return new ValueAxis(minValue, maxValue, CollectionNumbers.doubleArrayCopyOf(references), labels); }  @Override double scaleValue(double value, double minValue, double maxValue, double newMinValue, double newMaxValue); @Override double invScaleValue(double scaleValue, double actualMinValue, double actualMaxValue, double scaleMinValue, double scaleMaxValue); @Override ValueAxis references(Range range, int minRefs, int maxRefs);  }