comparison artifacts/src/main/java/org/dive4elements/river/exports/LongitudinalSectionGenerator2.java @ 8730:cb33de3434a8

(issue1754) Proper subtitle handling for Radius This deduplicates the subtitle and zoom / radius calculation code by moving it out of the processors. Doing this fixes cases where the subtitle would be removed when a the according filtered facet was removed although it should still have shown the Range for example. Range is now also added as a subtitle for the difference diagrams. This adds some tasty hack (with cheese) to determine wether or not the user has set the subtitle. See the comment in getChartSubtitlePure in LongitudinalSectionGenerator2 for details.
author Andre Heinecke <andre.heinecke@intevation.de>
date Thu, 30 Apr 2015 13:06:51 +0200
parents 68827654ea7a
children bccc476e78eb
comparison
equal deleted inserted replaced
8729:88b831b7bead 8730:cb33de3434a8
13 import org.dive4elements.river.artifacts.access.RangeAccess; 13 import org.dive4elements.river.artifacts.access.RangeAccess;
14 import org.dive4elements.river.jfree.Bounds; 14 import org.dive4elements.river.jfree.Bounds;
15 import org.dive4elements.river.jfree.DoubleBounds; 15 import org.dive4elements.river.jfree.DoubleBounds;
16 import org.dive4elements.river.themes.ThemeDocument; 16 import org.dive4elements.river.themes.ThemeDocument;
17 import org.dive4elements.river.artifacts.model.FacetTypes; 17 import org.dive4elements.river.artifacts.model.FacetTypes;
18 import org.dive4elements.river.artifacts.access.RiverAccess;
19 import org.dive4elements.river.artifacts.model.ZoomScale;
20 import org.dive4elements.river.artifacts.context.RiverContext;
21 import org.dive4elements.river.artifacts.resources.Resources;
18 22
19 import org.jfree.data.Range; 23 import org.jfree.data.Range;
20 24
21 import java.util.List; 25 import java.util.List;
22 import java.util.ArrayList; 26 import java.util.ArrayList;
27 import java.util.HashSet;
23 28
24 import org.apache.log4j.Logger; 29 import org.apache.log4j.Logger;
25 30
26 public class LongitudinalSectionGenerator2 extends DiagramGenerator 31 public class LongitudinalSectionGenerator2 extends DiagramGenerator
27 { 32 {
46 "chart.longitudinal.section.shortsubtitle"; 51 "chart.longitudinal.section.shortsubtitle";
47 52
48 public static final String I18N_CHART_LOCATION_SUBTITLE = 53 public static final String I18N_CHART_LOCATION_SUBTITLE =
49 "chart.longitudinal.section.locsubtitle"; 54 "chart.longitudinal.section.locsubtitle";
50 55
56 public static final String I18N_CHART_DISTANCE_SUBTITLE =
57 "chart.longitudinal.section.subtitle";
58
59 public static final String I18N_SUBTITLE_RADIUS =
60 "chart.subtitle.radius";
61
62 @Override
63 protected String getChartSubtitlePure() {
64 ChartSettings chartSettings = getChartSettings();
65
66 String titleBeforeParts = null;
67
68 if (subTitleParts != null && !subTitleParts.isEmpty()) {
69 // This is needed here to determine the initial
70 // subtitle before the processing happens to distinguis
71 // between that subtitle and a subtitle set by the user.
72 //
73 // The underlying problem is that getChartSubtitle is called
74 // to build the chart settings way before the facets are processed.
75 // So we have to figure out somehow if the user modified the title
76 // in the chartsettings or if it was just put there because it
77 // was the default.
78
79 HashSet<String> buf = subTitleParts;
80 subTitleParts = null;
81 titleBeforeParts = getDefaultChartSubtitle();
82 subTitleParts = buf;
83 }
84
85
86 if (chartSettings != null) {
87 String userTitle = getChartSubtitle(chartSettings);
88 if (userTitle != null && !userTitle.equals(titleBeforeParts)) {
89 // set by the user. use this.
90 log.debug("Using user subtitle: " + userTitle);
91 return userTitle;
92 }
93 }
94 log.debug("Using default subtitle: " + getDefaultChartSubtitle());
95 return getDefaultChartSubtitle();
96 }
97
98
51 @Override 99 @Override
52 public String getDefaultChartSubtitle() { 100 public String getDefaultChartSubtitle() {
53 double[] dist = getRange(); 101 double[] dist = getRange();
102
54 String parts = ""; 103 String parts = "";
55 if (subTitleParts != null && !subTitleParts.isEmpty()) { 104 if (subTitleParts != null && !subTitleParts.isEmpty()) {
56 for (String p : subTitleParts) { 105 for (String p : subTitleParts) {
57 parts += ", " + p; 106 parts += " " + p;
58 } 107 }
59 } 108 }
60 if (dist == null || dist.length != 2 || 109 if (dist == null || dist.length != 2 ||
61 Double.isNaN(dist[0]) || Double.isNaN(dist[1])) { 110 Double.isNaN(dist[0]) || Double.isNaN(dist[1])) {
62 Object [] args = new Object[] {getRiverName()}; 111 Object [] args = new Object[] {getRiverName()};
65 114
66 if (Math.abs(dist[0] - dist[1]) < 1E-5) { 115 if (Math.abs(dist[0] - dist[1]) < 1E-5) {
67 Object [] args = new Object[] {getRiverName(), dist[1]}; 116 Object [] args = new Object[] {getRiverName(), dist[1]};
68 return msg(I18N_CHART_LOCATION_SUBTITLE, "", args) + parts; 117 return msg(I18N_CHART_LOCATION_SUBTITLE, "", args) + parts;
69 } 118 }
70 119 Object [] args = new Object[] {getRiverName(), dist[0], dist[1]};
71 return super.getDefaultChartSubtitle(); 120 return msg(I18N_CHART_DISTANCE_SUBTITLE, "", args) + parts;
72 } 121 }
73 122
74 protected void calculateRadius() { 123 protected void calculateRadius() {
75 // Fixed range in settings is preferred 124 // Fixed range in settings is preferred
76 Range candidate = getRangeForAxisFromSettings("X"); 125 Range candidate = getRangeForAxisFromSettings("X");
105 log.debug("Using Full X Range."); 154 log.debug("Using Full X Range.");
106 } 155 }
107 } 156 }
108 log.debug("startkm for Radius is: " + candidate.getLowerBound() + 157 log.debug("startkm for Radius is: " + candidate.getLowerBound() +
109 " endkm: " + candidate.getUpperBound()); 158 " endkm: " + candidate.getUpperBound());
159
160 // This might not be neccessary if every facet uses only the
161 // radius and does not do its own zoomscale calculation.
110 context.putContextValue("startkm", candidate.getLowerBound()); 162 context.putContextValue("startkm", candidate.getLowerBound());
111 context.putContextValue("endkm", candidate.getUpperBound()); 163 context.putContextValue("endkm", candidate.getUpperBound());
112 context.putContextValue("bounds_defined", true); 164 context.putContextValue("bounds_defined", true);
165
166 RiverContext fc = (RiverContext)context.globalContext();
167 ZoomScale scales = (ZoomScale)fc.get("zoomscale");
168 RiverAccess access = new RiverAccess((D4EArtifact)getMaster());
169 String river = access.getRiverName();
170
171 double radius = scales.getRadius(river, candidate.getLowerBound(),
172 candidate.getUpperBound());
173 context.putContextValue("radius", radius);
113 } 174 }
114 175
115 @Override 176 @Override
116 protected void postProcess() { 177 protected void postProcess() {
117 if (postOutAF == null) { 178 if (postOutAF == null) {
128 // in the x axis range. 189 // in the x axis range.
129 super.doOut(superbundle.bundle, superbundle.theme, false); 190 super.doOut(superbundle.bundle, superbundle.theme, false);
130 } 191 }
131 192
132 calculateRadius(); // This calculates the real start and end km's 193 calculateRadius(); // This calculates the real start and end km's
194
195 boolean haveVisibleFiltered = false;
133 for (SuperBundle superbundle: postOutAF) { 196 for (SuperBundle superbundle: postOutAF) {
134 super.doOut(superbundle.bundle, superbundle.theme, superbundle.visible); 197 super.doOut(superbundle.bundle, superbundle.theme, superbundle.visible);
198 if (!haveVisibleFiltered) {
199 haveVisibleFiltered = superbundle.visible;
200 }
201 }
202 if (haveVisibleFiltered) {
203 log.debug("Adding radius subtitle.");
204
205 addSubtitle(Resources.getMsg(
206 getCallContext().getMeta(),
207 I18N_SUBTITLE_RADIUS,
208 new Object[] { "$RADIUS" }));
135 } 209 }
136 } 210 }
137 211
138 /* We override doOut here to save the startkm and endkm in the 212 /* We override doOut here to save the startkm and endkm in the
139 * context. Some facets will deliver different data because of 213 * context. Some facets will deliver different data because of

http://dive4elements.wald.intevation.org