comparison flys-artifacts/src/main/java/de/intevation/flys/exports/XYChartGenerator.java @ 4620:4a30d1d62caf

Extracted method to calculate the zoomed bound of a chart.
author Raimund Renkert <rrenkert@intevation.de>
date Mon, 03 Dec 2012 16:55:45 +0100
parents 0eca080fc162
children 31327b3b2455
comparison
equal deleted inserted replaced
4619:05c9902c761d 4620:4a30d1d62caf
779 if (bounds == null) { 779 if (bounds == null) {
780 return false; 780 return false;
781 } 781 }
782 782
783 if (x != null) { 783 if (x != null) {
784 double min = bounds.getLower().doubleValue(); 784 Bounds computed = calculateZoom(bounds, x);
785 double max = bounds.getUpper().doubleValue();
786
787 if (logger.isDebugEnabled()) {
788 logger.debug("Minimum is: " + min);
789 logger.debug("Maximum is: " + max);
790 logger.debug("Lower zoom is: " + x.getLowerBound());
791 logger.debug("Upper zoom is: " + x.getUpperBound());
792 }
793
794 double diff = max > min ? max - min : min - max;
795
796 DoubleBounds computed = new DoubleBounds(
797 min + x.getLowerBound() * diff,
798 min + x.getUpperBound() * diff);
799
800 computed.applyBounds(axis, AXIS_SPACE); 785 computed.applyBounds(axis, AXIS_SPACE);
801 786
802 logger.debug("Zoom axis to: " + computed); 787 logger.debug("Zoom axis to: " + computed);
803 788
804 return true; 789 return true;
806 791
807 bounds.applyBounds(axis, AXIS_SPACE); 792 bounds.applyBounds(axis, AXIS_SPACE);
808 return false; 793 return false;
809 } 794 }
810 795
796 /**
797 * Calculates the start and end km for zoomed charts.
798 * @param bounds The given total bounds (unzoomed).
799 * @param range The range specifying the zoom.
800 *
801 * @return The start and end km for the zoomed chart.
802 */
803 protected Bounds calculateZoom(Bounds bounds, Range range) {
804 double min = bounds.getLower().doubleValue();
805 double max = bounds.getUpper().doubleValue();
806
807 if (logger.isDebugEnabled()) {
808 logger.debug("Minimum is: " + min);
809 logger.debug("Maximum is: " + max);
810 logger.debug("Lower zoom is: " + range.getLowerBound());
811 logger.debug("Upper zoom is: " + range.getUpperBound());
812 }
813
814 double diff = max > min ? max - min : min - max;
815
816 DoubleBounds computed = new DoubleBounds(
817 min + range.getLowerBound() * diff,
818 min + range.getUpperBound() * diff);
819 return computed;
820 }
811 821
812 /** 822 /**
813 * Extract the minimum and maximum values for x and y axes 823 * Extract the minimum and maximum values for x and y axes
814 * which are stored in <i>xRanges</i> and <i>yRanges</i>. 824 * which are stored in <i>xRanges</i> and <i>yRanges</i>.
815 * 825 *

http://dive4elements.wald.intevation.org