comparison flys-artifacts/src/main/java/de/intevation/flys/exports/XYChartGenerator.java @ 2047:0318fa6f0844

Make use of first attributes specified in the ChartSettings. NOTE: work is still in progress. flys-artifacts/trunk@3535 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Ingo Weinzierl <ingo.weinzierl@intevation.de>
date Fri, 23 Dec 2011 08:57:25 +0000
parents 7bc9293de4e6
children 3157a78e6494
comparison
equal deleted inserted replaced
2046:2ae0627f956e 2047:0318fa6f0844
203 } 203 }
204 204
205 205
206 /** 206 /**
207 * This method is used to determine, if the chart's legend is visible or 207 * This method is used to determine, if the chart's legend is visible or
208 * not. <b>Note: this method always returns true.</b> 208 * not. If a <i>settings</i> instance is set, this instance determines the
209 * visibility otherwise, this method returns true as default if no
210 * <i>settings</i> is set.
209 * 211 *
210 * @return true, if the legend should be visible, otherwise false. 212 * @return true, if the legend should be visible, otherwise false.
211 */ 213 */
212 protected boolean isLegendVisible() { 214 protected boolean isLegendVisible() {
215 ChartSettings chartSettings = getChartSettings();
216 if (chartSettings != null) {
217 return isLegendVisible(chartSettings);
218 }
219
213 return true; 220 return true;
214 } 221 }
215 222
216 223
217 /** 224 /**
218 * This method is used to determine the font size of the chart's legend. 225 * This method is used to determine the font size of the chart's legend. If
219 * <b>Note: this method always returns 12.</b> 226 * a <i>settings</i> instance is set, this instance determines the font
220 * 227 * size, otherwise this method returns 12 as default if no <i>settings</i>
221 * @return 12. 228 * is set or if it doesn't provide a legend font size.
229 *
230 * @return a legend font size.
222 */ 231 */
223 protected int getLegendFontSize() { 232 protected int getLegendFontSize() {
224 return 12; 233 Integer fontSize = null;
234
235 ChartSettings chartSettings = getChartSettings();
236 if (chartSettings != null) {
237 fontSize = getLegendFontSize(chartSettings);
238 }
239
240 return fontSize != null ? fontSize : 12;
225 } 241 }
226 242
227 243
228 /** 244 /**
229 * This method is used to determine if the resulting chart should display 245 * This method is used to determine if the resulting chart should display
322 getChartTitle(), 338 getChartTitle(),
323 getXAxisLabel(), 339 getXAxisLabel(),
324 getYAxisLabel(), 340 getYAxisLabel(),
325 null, 341 null,
326 PlotOrientation.VERTICAL, 342 PlotOrientation.VERTICAL,
327 true, 343 isLegendVisible(),
328 false, 344 false,
329 false); 345 false);
330 346
331 XYPlot plot = (XYPlot) chart.getPlot(); 347 XYPlot plot = (XYPlot) chart.getPlot();
332 chart.setBackgroundPaint(Color.WHITE); 348 chart.setBackgroundPaint(Color.WHITE);
703 if (annotations == null) { 719 if (annotations == null) {
704 logger.debug("No Annotations given."); 720 logger.debug("No Annotations given.");
705 return; 721 return;
706 } 722 }
707 723
724 int fontSize = getLegendFontSize();
725
708 LegendItemCollection lic = new LegendItemCollection(); 726 LegendItemCollection lic = new LegendItemCollection();
709 LegendItemCollection old = plot.getFixedLegendItems(); 727 LegendItemCollection old = plot.getFixedLegendItems();
710 728
711 XYItemRenderer renderer = plot.getRenderer(0); 729 XYItemRenderer renderer = plot.getRenderer(0);
712 730
715 733
716 ThemeAccess themeAccess = new ThemeAccess(theme); 734 ThemeAccess themeAccess = new ThemeAccess(theme);
717 735
718 Color color = themeAccess.parseLineColorField(); 736 Color color = themeAccess.parseLineColorField();
719 int lineWidth = themeAccess.parseLineWidth(); 737 int lineWidth = themeAccess.parseLineWidth();
738
720 lic.add(new LegendItem(fa.getLabel(), color)); 739 lic.add(new LegendItem(fa.getLabel(), color));
721 740
722 for (XYTextAnnotation ta: fa.getAnnotations()) { 741 for (XYTextAnnotation ta: fa.getAnnotations()) {
723 if(ta instanceof StickyAxisAnnotation) { 742 if(ta instanceof StickyAxisAnnotation) {
724 StickyAxisAnnotation sta = (StickyAxisAnnotation)ta; 743 StickyAxisAnnotation sta = (StickyAxisAnnotation)ta;
774 BasicStroke.JOIN_MITER, 793 BasicStroke.JOIN_MITER,
775 3.0f, 794 3.0f,
776 new float[] { 3.0f }, 795 new float[] { 3.0f },
777 0.0f); 796 0.0f);
778 797
798 ChartSettings cs = getChartSettings();
799 boolean isGridVisible = cs != null ? isGridVisible(cs) : true;
800
779 plot.setDomainGridlineStroke(gridStroke); 801 plot.setDomainGridlineStroke(gridStroke);
780 plot.setDomainGridlinePaint(DEFAULT_GRID_COLOR); 802 plot.setDomainGridlinePaint(DEFAULT_GRID_COLOR);
781 plot.setDomainGridlinesVisible(true); 803 plot.setDomainGridlinesVisible(isGridVisible);
782 804
783 plot.setRangeGridlineStroke(gridStroke); 805 plot.setRangeGridlineStroke(gridStroke);
784 plot.setRangeGridlinePaint(DEFAULT_GRID_COLOR); 806 plot.setRangeGridlinePaint(DEFAULT_GRID_COLOR);
785 plot.setRangeGridlinesVisible(true); 807 plot.setRangeGridlinesVisible(isGridVisible);
786 808
787 plot.setAxisOffset(new RectangleInsets(0d, 0d, 0d, 0d)); 809 plot.setAxisOffset(new RectangleInsets(0d, 0d, 0d, 0d));
788 } 810 }
789 811
790 812
1016 * but with no axes settings. 1038 * but with no axes settings.
1017 * 1039 *
1018 * @return an instance of <i>ChartSettings</i>. 1040 * @return an instance of <i>ChartSettings</i>.
1019 */ 1041 */
1020 public Settings getSettings() { 1042 public Settings getSettings() {
1043 if (this.settings != null) {
1044 return this.settings;
1045 }
1046
1021 ChartSettings settings = new ChartSettings(); 1047 ChartSettings settings = new ChartSettings();
1022 1048
1023 Section chartSection = buildChartSection(); 1049 ChartSection chartSection = buildChartSection();
1024 Section legendSection = buildLegendSection(); 1050 LegendSection legendSection = buildLegendSection();
1025 1051
1026 settings.setChartSection(chartSection); 1052 settings.setChartSection(chartSection);
1027 settings.setLegendSection(legendSection); 1053 settings.setLegendSection(legendSection);
1028 1054
1029 List<Section> axisSections = buildAxisSections(); 1055 List<Section> axisSections = buildAxisSections();
1038 /** 1064 /**
1039 * Creates a new <i>ChartSection</i>. 1065 * Creates a new <i>ChartSection</i>.
1040 * 1066 *
1041 * @return a new <i>ChartSection</i>. 1067 * @return a new <i>ChartSection</i>.
1042 */ 1068 */
1043 protected Section buildChartSection() { 1069 protected ChartSection buildChartSection() {
1044 ChartSection chartSection = new ChartSection(); 1070 ChartSection chartSection = new ChartSection();
1045 chartSection.setTitle(getChartTitle()); 1071 chartSection.setTitle(getChartTitle());
1046 chartSection.setSubtitle(getChartSubtitle()); 1072 chartSection.setSubtitle(getChartSubtitle());
1047 chartSection.setDisplayGird(isGridVisible()); 1073 chartSection.setDisplayGird(isGridVisible());
1048 return chartSection; 1074 return chartSection;
1052 /** 1078 /**
1053 * Creates a new <i>LegendSection</i>. 1079 * Creates a new <i>LegendSection</i>.
1054 * 1080 *
1055 * @return a new <i>LegendSection</i>. 1081 * @return a new <i>LegendSection</i>.
1056 */ 1082 */
1057 protected Section buildLegendSection() { 1083 protected LegendSection buildLegendSection() {
1058 LegendSection legendSection = new LegendSection(); 1084 LegendSection legendSection = new LegendSection();
1059 legendSection.setVisibility(isLegendVisible()); 1085 legendSection.setVisibility(isLegendVisible());
1060 legendSection.setFontSize(getLegendFontSize()); 1086 legendSection.setFontSize(getLegendFontSize());
1061 return legendSection; 1087 return legendSection;
1062 } 1088 }

http://dive4elements.wald.intevation.org