Mercurial > dive4elements > river
comparison artifacts/src/main/java/org/dive4elements/river/exports/CrossSectionGenerator.java @ 9555:ef5754ba5573
Implemented legend aggregation based on type of themes.
Added theme-editor style configuration for aggregated legend entries.
Only configured themes get aggregated.
author | gernotbelger |
---|---|
date | Tue, 23 Oct 2018 16:26:48 +0200 |
parents | ee6508687e3f |
children |
comparison
equal
deleted
inserted
replaced
9554:33ce8eba9806 | 9555:ef5754ba5573 |
---|---|
31 import org.dive4elements.river.model.FastCrossSectionLine; | 31 import org.dive4elements.river.model.FastCrossSectionLine; |
32 import org.dive4elements.river.themes.TextStyle; | 32 import org.dive4elements.river.themes.TextStyle; |
33 import org.dive4elements.river.themes.ThemeDocument; | 33 import org.dive4elements.river.themes.ThemeDocument; |
34 import org.dive4elements.river.utils.Formatter; | 34 import org.dive4elements.river.utils.Formatter; |
35 import org.dive4elements.river.utils.RiverUtils; | 35 import org.dive4elements.river.utils.RiverUtils; |
36 import org.jfree.chart.LegendItemCollection; | 36 import org.jfree.chart.LegendItem; |
37 import org.jfree.chart.annotations.XYBoxAnnotation; | 37 import org.jfree.chart.annotations.XYBoxAnnotation; |
38 import org.jfree.chart.annotations.XYTextAnnotation; | 38 import org.jfree.chart.annotations.XYTextAnnotation; |
39 import org.jfree.chart.plot.XYPlot; | 39 import org.jfree.chart.plot.XYPlot; |
40 import org.jfree.data.xy.XYSeries; | 40 import org.jfree.data.xy.XYSeries; |
41 | |
42 | 41 |
43 /** | 42 /** |
44 * An OutGenerator that generates cross section graphs. | 43 * An OutGenerator that generates cross section graphs. |
45 */ | 44 */ |
46 public class CrossSectionGenerator | 45 public class CrossSectionGenerator |
163 return new Color(255, 0, 0); | 162 return new Color(255, 0, 0); |
164 } | 163 } |
165 } | 164 } |
166 | 165 |
167 @Override | 166 @Override |
168 protected void doAddFurtherAnnotations(XYPlot plot, List<RiverAnnotation> annotations) { | 167 protected void doAddFurtherAnnotations(XYPlot plot, LegendAggregator legendBuilder, List<RiverAnnotation> annotations) { |
169 | 168 |
170 // Paints for the boxes/lines. | 169 // Paints for the boxes/lines. |
171 Stroke basicStroke = new BasicStroke(1.0f); | 170 Stroke basicStroke = new BasicStroke(1.0f); |
172 | 171 |
173 // XXX: DEAD CODE // Paint linePaint = new Color(255, 0,0,60); | 172 // XXX: DEAD CODE // Paint linePaint = new Color(255, 0,0,60); |
187 | 186 |
188 // Get Themeing information and add legend item. | 187 // Get Themeing information and add legend item. |
189 if (theme != null) { | 188 if (theme != null) { |
190 textStyle = theme.parseComplexTextStyle(); | 189 textStyle = theme.parseComplexTextStyle(); |
191 if (fa.getLabel() != null) { | 190 if (fa.getLabel() != null) { |
192 LegendItemCollection lic = new LegendItemCollection(); | 191 |
193 LegendItemCollection old = plot.getFixedLegendItems(); | 192 Color color = theme.parseLineColorField(); |
194 lic.add(createLegendItem(theme, fa.getLabel())); | 193 if (color == null) |
195 // (Re-)Add prior legend entries. | 194 color = Color.BLACK; |
196 if (old != null) { | 195 |
197 old.addAll(lic); | 196 final String themeType = null; |
198 } | 197 |
199 else { | 198 legendBuilder.addLegendItem(themeType, new LegendItem(fa.getLabel(), color)); |
200 old = lic; | |
201 } | |
202 plot.setFixedLegendItems(old); | |
203 } | 199 } |
204 } | 200 } |
205 | 201 |
206 // Hyks. | 202 // Hyks. |
207 for (HYKFactory.Zone zone: fa.getBoxes()) { | 203 for (HYKFactory.Zone zone: fa.getBoxes()) { |
280 return; | 276 return; |
281 } | 277 } |
282 | 278 |
283 CallContext context = getContext(); | 279 CallContext context = getContext(); |
284 | 280 |
281 final String facetDescription = artifactFacet.getFacetDescription(); | |
282 final String facetName = artifactFacet.getFacetName(); | |
283 | |
285 if (name.equals(CROSS_SECTION)) { | 284 if (name.equals(CROSS_SECTION)) { |
286 doCrossSectionOut( | 285 doCrossSectionOut(facetName, |
287 artifactFacet.getData(context), | 286 artifactFacet.getData(context), |
288 artifactFacet.getFacetDescription(), | 287 facetDescription, |
289 attr, | 288 attr, |
290 visible); | 289 visible); |
291 } | 290 } |
292 else if (name.endsWith(CROSS_SECTION_WATER_LINE)) { | 291 else if (name.endsWith(CROSS_SECTION_WATER_LINE)) { |
293 doCrossSectionWaterLineOut( | 292 doCrossSectionWaterLineOut(facetName, |
294 artifactFacet.getData(context), | 293 artifactFacet.getData(context), |
295 artifactFacet.getFacetDescription(), | 294 facetDescription, |
296 attr, | 295 attr, |
297 visible); | 296 visible); |
298 } | 297 } |
299 else if (FacetTypes.IS.AREA(name)) { | 298 else if (FacetTypes.IS.AREA(name)) { |
300 doArea(artifactFacet.getData(context), | 299 doArea(artifactFacet.getData(context), |
302 attr, | 301 attr, |
303 visible); | 302 visible); |
304 } | 303 } |
305 else if (name.equals(HYK)) { | 304 else if (name.equals(HYK)) { |
306 doHyk(artifactFacet.getData(context), | 305 doHyk(artifactFacet.getData(context), |
307 artifactFacet.getFacetDescription(), | 306 facetDescription, |
308 attr, | 307 attr, |
309 visible); | 308 visible); |
310 } | 309 } |
311 else if (VegetationZonesCrossSectionProcessor.canHandle(name)) { | 310 else if (VegetationZonesCrossSectionProcessor.canHandle(name)) { |
312 VegetationZonesCrossSectionProcessor.generateSeries(this, artifactFacet, context, attr, visible); | 311 VegetationZonesCrossSectionProcessor.generateSeries(this, artifactFacet, context, attr, visible); |
313 } | 312 } |
314 else if (FacetTypes.IS.MANUALLINE(name)) { | 313 else if (FacetTypes.IS.MANUALLINE(name)) { |
315 doCrossSectionWaterLineOut( | 314 doCrossSectionWaterLineOut(facetName, |
316 artifactFacet.getData(context), | 315 artifactFacet.getData(context), |
317 artifactFacet.getFacetDescription(), | 316 facetDescription, |
318 attr, | 317 attr, |
319 visible); | 318 visible); |
320 } | 319 } |
321 else if (FacetTypes.IS.MANUALPOINTS(name)) { | 320 else if (FacetTypes.IS.MANUALPOINTS(name)) { |
322 doPoints(artifactFacet.getData(context), | 321 doPoints(artifactFacet.getData(context), |
343 * | 342 * |
344 * @param seriesName name of the data (line) to display in legend. | 343 * @param seriesName name of the data (line) to display in legend. |
345 * @param theme Theme for the data series. | 344 * @param theme Theme for the data series. |
346 */ | 345 */ |
347 protected void doCrossSectionWaterLineOut( | 346 protected void doCrossSectionWaterLineOut( |
347 String facetName, | |
348 Object o, | 348 Object o, |
349 String seriesName, | 349 String seriesName, |
350 ThemeDocument theme, | 350 ThemeDocument theme, |
351 boolean visible | 351 boolean visible |
352 ) { | 352 ) { |
353 log.debug("CrossSectionGenerator.doCrossSectionWaterLineOut"); | 353 log.debug("CrossSectionGenerator.doCrossSectionWaterLineOut"); |
354 | 354 |
355 Lines.LineData lines = (Lines.LineData) o; | 355 Lines.LineData lines = (Lines.LineData) o; |
356 // DO NOT SORT DATA! This destroys the gaps indicated by NaNs. | 356 // DO NOT SORT DATA! This destroys the gaps indicated by NaNs. |
357 StyledXYSeries series = new StyledXYSeries(seriesName, false, theme); | 357 StyledXYSeries series = new StyledXYSeries(facetName, seriesName, false, theme); |
358 | 358 |
359 CallContext context = getContext(); | 359 CallContext context = getContext(); |
360 | 360 |
361 if (!theme.parseShowLineLabel()) { | 361 if (!theme.parseShowLineLabel()) { |
362 series.setLabel(""); | 362 series.setLabel(""); |
431 * Do cross sections out. | 431 * Do cross sections out. |
432 * | 432 * |
433 * @param seriesName name of the data (line) to display in legend. | 433 * @param seriesName name of the data (line) to display in legend. |
434 * @param theme Theme for the data series. | 434 * @param theme Theme for the data series. |
435 */ | 435 */ |
436 protected void doCrossSectionOut( | 436 private void doCrossSectionOut( |
437 String facetName, | |
437 Object o, | 438 Object o, |
438 String seriesName, | 439 String seriesName, |
439 ThemeDocument theme, | 440 ThemeDocument theme, |
440 boolean visible | 441 boolean visible |
441 ) { | 442 ) { |
442 log.debug("CrossSectionGenerator.doCrossSectionOut"); | 443 log.debug("CrossSectionGenerator.doCrossSectionOut"); |
443 | 444 |
444 XYSeries series = new StyledXYSeries(seriesName, theme); | 445 XYSeries series = new StyledXYSeries(facetName, seriesName, theme); |
445 | 446 |
446 StyledSeriesBuilder.addPoints(series, (double [][]) o, false); | 447 StyledSeriesBuilder.addPoints(series, (double [][]) o, false); |
447 | 448 |
448 addAxisSeries(series, 0, visible); | 449 addAxisSeries(series, 0, visible); |
449 } | 450 } |