@Test public void references20() { ValueScale linearScale = ValueScales.linearScale(); ValueAxis axis = linearScale.references(Ranges.range(-2.644, 3.3689), 2, 3); assertAxisEquals(-2.644, 3.3689, new double[]{-2.0, 0.0, 2.0}, new String[]{"-2", "0", "2"}, axis); }
@Override public ValueAxis references(Range range, int minRefs, int maxRefs) { double minValue = range.getMinimum(); double maxValue = range.getMaximum(); double minIncrement = Double.MIN_VALUE; double increment = incrementForRange(minValue, maxValue, maxRefs, minIncrement); double[] ticks = createTicks(minValue, maxValue, increment); if (ticks.length < 2) { ticks = createSmallerTicks(minValue, maxValue, increment); } int rangeOrder = (int) orderOfMagnitude(minValue, maxValue); int incrementOrder = (int) orderOfMagnitude(increment); int nDigits = rangeOrder - incrementOrder; NumberFormat format = defaultFormat; double normalization = 1.0; String exponent = null; if (rangeOrder >= -3 && rangeOrder <= 3) { if (incrementOrder < 0) { format = NumberFormats.format(-incrementOrder); } else { format = NumberFormats.format(0); } } else if (rangeOrder > 3) { format = NumberFormats.format(nDigits); normalization = Math.pow(10.0, rangeOrder); exponent = Integer.toString(rangeOrder); } else if (rangeOrder < -3) { format = NumberFormats.format(nDigits); normalization = Math.pow(10.0, rangeOrder); exponent = Integer.toString(rangeOrder); } String[] labels = new String[ticks.length]; for (int i = 0; i < ticks.length; i++) { double value = ticks[i]; labels[i] = format(value, format, exponent, normalization); } return new ValueAxis(minValue, maxValue, ticks, labels); }
LinearValueScale implements ValueScale { @Override public ValueAxis references(Range range, int minRefs, int maxRefs) { double minValue = range.getMinimum(); double maxValue = range.getMaximum(); double minIncrement = Double.MIN_VALUE; double increment = incrementForRange(minValue, maxValue, maxRefs, minIncrement); double[] ticks = createTicks(minValue, maxValue, increment); if (ticks.length < 2) { ticks = createSmallerTicks(minValue, maxValue, increment); } int rangeOrder = (int) orderOfMagnitude(minValue, maxValue); int incrementOrder = (int) orderOfMagnitude(increment); int nDigits = rangeOrder - incrementOrder; NumberFormat format = defaultFormat; double normalization = 1.0; String exponent = null; if (rangeOrder >= -3 && rangeOrder <= 3) { if (incrementOrder < 0) { format = NumberFormats.format(-incrementOrder); } else { format = NumberFormats.format(0); } } else if (rangeOrder > 3) { format = NumberFormats.format(nDigits); normalization = Math.pow(10.0, rangeOrder); exponent = Integer.toString(rangeOrder); } else if (rangeOrder < -3) { format = NumberFormats.format(nDigits); normalization = Math.pow(10.0, rangeOrder); exponent = Integer.toString(rangeOrder); } String[] labels = new String[ticks.length]; for (int i = 0; i < ticks.length; i++) { double value = ticks[i]; labels[i] = format(value, format, exponent, normalization); } return new ValueAxis(minValue, maxValue, ticks, labels); } }
LinearValueScale implements ValueScale { @Override public ValueAxis references(Range range, int minRefs, int maxRefs) { double minValue = range.getMinimum(); double maxValue = range.getMaximum(); double minIncrement = Double.MIN_VALUE; double increment = incrementForRange(minValue, maxValue, maxRefs, minIncrement); double[] ticks = createTicks(minValue, maxValue, increment); if (ticks.length < 2) { ticks = createSmallerTicks(minValue, maxValue, increment); } int rangeOrder = (int) orderOfMagnitude(minValue, maxValue); int incrementOrder = (int) orderOfMagnitude(increment); int nDigits = rangeOrder - incrementOrder; NumberFormat format = defaultFormat; double normalization = 1.0; String exponent = null; if (rangeOrder >= -3 && rangeOrder <= 3) { if (incrementOrder < 0) { format = NumberFormats.format(-incrementOrder); } else { format = NumberFormats.format(0); } } else if (rangeOrder > 3) { format = NumberFormats.format(nDigits); normalization = Math.pow(10.0, rangeOrder); exponent = Integer.toString(rangeOrder); } else if (rangeOrder < -3) { format = NumberFormats.format(nDigits); normalization = Math.pow(10.0, rangeOrder); exponent = Integer.toString(rangeOrder); } String[] labels = new String[ticks.length]; for (int i = 0; i < ticks.length; i++) { double value = ticks[i]; labels[i] = format(value, format, exponent, normalization); } return new ValueAxis(minValue, maxValue, ticks, labels); }  }
LinearValueScale implements ValueScale { @Override public ValueAxis references(Range range, int minRefs, int maxRefs) { double minValue = range.getMinimum(); double maxValue = range.getMaximum(); double minIncrement = Double.MIN_VALUE; double increment = incrementForRange(minValue, maxValue, maxRefs, minIncrement); double[] ticks = createTicks(minValue, maxValue, increment); if (ticks.length < 2) { ticks = createSmallerTicks(minValue, maxValue, increment); } int rangeOrder = (int) orderOfMagnitude(minValue, maxValue); int incrementOrder = (int) orderOfMagnitude(increment); int nDigits = rangeOrder - incrementOrder; NumberFormat format = defaultFormat; double normalization = 1.0; String exponent = null; if (rangeOrder >= -3 && rangeOrder <= 3) { if (incrementOrder < 0) { format = NumberFormats.format(-incrementOrder); } else { format = NumberFormats.format(0); } } else if (rangeOrder > 3) { format = NumberFormats.format(nDigits); normalization = Math.pow(10.0, rangeOrder); exponent = Integer.toString(rangeOrder); } else if (rangeOrder < -3) { format = NumberFormats.format(nDigits); normalization = Math.pow(10.0, rangeOrder); exponent = Integer.toString(rangeOrder); } String[] labels = new String[ticks.length]; for (int i = 0; i < ticks.length; i++) { double value = ticks[i]; labels[i] = format(value, format, exponent, normalization); } return new ValueAxis(minValue, maxValue, ticks, labels); }  @Override double scaleValue(double value, double minValue, double maxValue, double newMinValue, double newMaxValue); @Override double invScaleValue(double scaleValue, double minValue, double maxValue, double newMinValue, double newMaxValue); @Override ValueAxis references(Range range, int minRefs, int maxRefs); }
LinearValueScale implements ValueScale { @Override public ValueAxis references(Range range, int minRefs, int maxRefs) { double minValue = range.getMinimum(); double maxValue = range.getMaximum(); double minIncrement = Double.MIN_VALUE; double increment = incrementForRange(minValue, maxValue, maxRefs, minIncrement); double[] ticks = createTicks(minValue, maxValue, increment); if (ticks.length < 2) { ticks = createSmallerTicks(minValue, maxValue, increment); } int rangeOrder = (int) orderOfMagnitude(minValue, maxValue); int incrementOrder = (int) orderOfMagnitude(increment); int nDigits = rangeOrder - incrementOrder; NumberFormat format = defaultFormat; double normalization = 1.0; String exponent = null; if (rangeOrder >= -3 && rangeOrder <= 3) { if (incrementOrder < 0) { format = NumberFormats.format(-incrementOrder); } else { format = NumberFormats.format(0); } } else if (rangeOrder > 3) { format = NumberFormats.format(nDigits); normalization = Math.pow(10.0, rangeOrder); exponent = Integer.toString(rangeOrder); } else if (rangeOrder < -3) { format = NumberFormats.format(nDigits); normalization = Math.pow(10.0, rangeOrder); exponent = Integer.toString(rangeOrder); } String[] labels = new String[ticks.length]; for (int i = 0; i < ticks.length; i++) { double value = ticks[i]; labels[i] = format(value, format, exponent, normalization); } return new ValueAxis(minValue, maxValue, ticks, labels); }  @Override double scaleValue(double value, double minValue, double maxValue, double newMinValue, double newMaxValue); @Override double invScaleValue(double scaleValue, double minValue, double maxValue, double newMinValue, double newMaxValue); @Override ValueAxis references(Range range, int minRefs, int maxRefs);  }