comparison flys-artifacts/src/main/java/de/intevation/flys/exports/XYChartGenerator.java @ 2050:c4e0e433f825

Use axes ranges specified in ChartSettings for zooming in charts. flys-artifacts/trunk@3540 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Ingo Weinzierl <ingo.weinzierl@intevation.de>
date Tue, 27 Dec 2011 07:17:07 +0000
parents 2d5f2bc68cc6
children 4ba5036109d2
comparison
equal deleted inserted replaced
2049:2d5f2bc68cc6 2050:c4e0e433f825
661 logger.debug("Zoom to specified ranges."); 661 logger.debug("Zoom to specified ranges.");
662 662
663 Range xrange = getDomainAxisRange(); 663 Range xrange = getDomainAxisRange();
664 Range yrange = getValueAxisRange(); 664 Range yrange = getValueAxisRange();
665 665
666 zoomX(plot, plot.getDomainAxis(), xRanges.get(0), xrange); 666 ValueAxis xAxis = plot.getDomainAxis();
667
668 Range fixedXRange = getRangeForAxisFromSettings("X");
669 if (fixedXRange != null) {
670 xAxis.setRange(fixedXRange);
671 }
672 else {
673 zoomX(plot, xAxis, xRanges.get(0), xrange);
674 }
667 675
668 for (int i = 0, num = plot.getRangeAxisCount(); i < num; i++) { 676 for (int i = 0, num = plot.getRangeAxisCount(); i < num; i++) {
669 ValueAxis yaxis = plot.getRangeAxis(i); 677 ValueAxis yaxis = plot.getRangeAxis(i);
670 678
671 if (yaxis instanceof IdentifiableNumberAxis) { 679 if (yaxis instanceof IdentifiableNumberAxis) {
672 logger.info("!!! IdentifiableNumberAxis found !!!"); 680 IdentifiableNumberAxis idAxis = (IdentifiableNumberAxis) yaxis;
673 // TODO Watch for fixed axes and the specified range 681
682 Range fixedRange = getRangeForAxisFromSettings(idAxis.getId());
683 if (fixedRange != null) {
684 yaxis.setRange(fixedRange);
685 continue;
686 }
674 } 687 }
675 688
676 if (yaxis == null) { 689 if (yaxis == null) {
677 logger.debug("Zoom problem: no Y Axis for index: " + i); 690 logger.debug("Zoom problem: no Y Axis for index: " + i);
678 continue; 691 continue;
743 logger.debug("getRangesForAxis " + index); 756 logger.debug("getRangesForAxis " + index);
744 return new Range[] { 757 return new Range[] {
745 xRanges.get(Integer.valueOf(0)), 758 xRanges.get(Integer.valueOf(0)),
746 yRanges.get(Integer.valueOf(index)) 759 yRanges.get(Integer.valueOf(index))
747 }; 760 };
761 }
762
763
764 /**
765 * This method searches for a specific axis in the <i>settings</i> if
766 * <i>settings</i> is set. If the axis was found, this method returns the
767 * specified axis range if the axis range is fixed. Otherwise, this method
768 * returns null.
769 *
770 * @param axisId The identifier of an axis.
771 *
772 * @return the specified axis range from <i>settings</i> if the axis is
773 * fixed, otherwise null.
774 */
775 public Range getRangeForAxisFromSettings(String axisId) {
776 ChartSettings chartSettings = getChartSettings();
777 if (chartSettings == null) {
778 return null;
779 }
780
781 AxisSection as = chartSettings.getAxisSection(axisId);
782 Boolean fixed = as.isFixed();
783
784 if (fixed != null && fixed) {
785 Double upper = as.getUpperRange();
786 Double lower = as.getLowerRange();
787
788 if (upper != null && lower != null) {
789 return lower < upper
790 ? new Range(lower, upper)
791 : new Range(upper, lower);
792 }
793 }
794
795 return null;
748 } 796 }
749 797
750 798
751 /** 799 /**
752 * Add annotations to Renderer. 800 * Add annotations to Renderer.
1103 LegendSection legendSection = buildLegendSection(); 1151 LegendSection legendSection = buildLegendSection();
1104 1152
1105 settings.setChartSection(chartSection); 1153 settings.setChartSection(chartSection);
1106 settings.setLegendSection(legendSection); 1154 settings.setLegendSection(legendSection);
1107 1155
1108 List<Section> axisSections = buildAxisSections(); 1156 List<AxisSection> axisSections = buildAxisSections();
1109 for (Section axisSection: axisSections) { 1157 for (AxisSection axisSection: axisSections) {
1110 settings.addAxisSection(axisSection); 1158 settings.addAxisSection(axisSection);
1111 } 1159 }
1112 1160
1113 return settings; 1161 return settings;
1114 } 1162 }
1145 * Creates a list of Sections that contains all axes of the chart (including 1193 * Creates a list of Sections that contains all axes of the chart (including
1146 * X and Y axes). 1194 * X and Y axes).
1147 * 1195 *
1148 * @return a list of Sections for each axis in this chart. 1196 * @return a list of Sections for each axis in this chart.
1149 */ 1197 */
1150 protected List<Section> buildAxisSections() { 1198 protected List<AxisSection> buildAxisSections() {
1151 List<Section> axisSections = new ArrayList<Section>(); 1199 List<AxisSection> axisSections = new ArrayList<AxisSection>();
1152 1200
1153 axisSections.addAll(buildXAxisSections()); 1201 axisSections.addAll(buildXAxisSections());
1154 axisSections.addAll(buildYAxisSections()); 1202 axisSections.addAll(buildYAxisSections());
1155 1203
1156 return axisSections; 1204 return axisSections;
1160 /** 1208 /**
1161 * Creates a new Section for chart's X axis. 1209 * Creates a new Section for chart's X axis.
1162 * 1210 *
1163 * @return a List that contains a Section for the X axis. 1211 * @return a List that contains a Section for the X axis.
1164 */ 1212 */
1165 protected List<Section> buildXAxisSections() { 1213 protected List<AxisSection> buildXAxisSections() {
1166 List<Section> axisSections = new ArrayList<Section>(); 1214 List<AxisSection> axisSections = new ArrayList<AxisSection>();
1167 1215
1168 String identifier = "X"; 1216 String identifier = "X";
1169 1217
1170 AxisSection axisSection = new AxisSection(); 1218 AxisSection axisSection = new AxisSection();
1171 axisSection.setIdentifier(identifier); 1219 axisSection.setIdentifier(identifier);
1189 * of <i>getYAxisWalker</i> to be able to access all Y axes defined in 1237 * of <i>getYAxisWalker</i> to be able to access all Y axes defined in
1190 * subclasses. 1238 * subclasses.
1191 * 1239 *
1192 * @return a list of Y axis sections. 1240 * @return a list of Y axis sections.
1193 */ 1241 */
1194 protected List<Section> buildYAxisSections() { 1242 protected List<AxisSection> buildYAxisSections() {
1195 List<Section> axisSections = new ArrayList<Section>(); 1243 List<AxisSection> axisSections = new ArrayList<AxisSection>();
1196 1244
1197 YAxisWalker walker = getYAxisWalker(); 1245 YAxisWalker walker = getYAxisWalker();
1198 for (int i = 0, n = walker.length(); i < n; i++) { 1246 for (int i = 0, n = walker.length(); i < n; i++) {
1199 AxisSection ySection = new AxisSection(); 1247 AxisSection ySection = new AxisSection();
1200 ySection.setIdentifier(walker.getId(i)); 1248 ySection.setIdentifier(walker.getId(i));

http://dive4elements.wald.intevation.org