comparison artifacts/src/main/java/org/dive4elements/river/exports/DiagramAttributes.java @ 8889:f87f435df856

Allow to configure lower and upper margin of a chart axis
author gernotbelger
date Wed, 14 Feb 2018 18:45:01 +0100
parents 32db4f89b65f
children 87a242425467
comparison
equal deleted inserted replaced
8888:caa52aec08c0 8889:f87f435df856
107 return DiagramAttributes.this.getAxesAttributes(); 107 return DiagramAttributes.this.getAxesAttributes();
108 } 108 }
109 } // class Instance 109 } // class Instance
110 110
111 public static class AxisAttributes { 111 public static class AxisAttributes {
112 private String name; 112 private final String name;
113 private boolean isLeftAlign; // TODO: Remove! 113 private final boolean isLeftAlign; // TODO: Remove!
114 private boolean forceAlign; // TODO: Remove! 114 private final boolean forceAlign; // TODO: Remove!
115 private boolean includeZero; // TODO: Use Evaluator 115 private final boolean includeZero; // TODO: Use Evaluator
116 116
117 private Evaluator isInverted; 117 private final Evaluator isInverted;
118 private Evaluator isLog; 118 private final Evaluator isLog;
119 119 private final double lowerMargin;
120 public AxisAttributes() { 120 private final double upperMargin;
121 }
122 121
123 public AxisAttributes( 122 public AxisAttributes(
124 String name, 123 String name,
125 boolean isLeftAlign, 124 boolean isLeftAlign,
126 boolean forceAlign, 125 boolean forceAlign,
127 boolean includeZero, 126 boolean includeZero,
128 Evaluator isInverted, 127 Evaluator isInverted,
129 Evaluator isLog 128 Evaluator isLog,
129 double lowerMargin,
130 double upperMargin
130 ) { 131 ) {
131 this.name = name; 132 this.name = name;
132 this.isLeftAlign = isLeftAlign; 133 this.isLeftAlign = isLeftAlign;
133 this.forceAlign = forceAlign; 134 this.forceAlign = forceAlign;
134 this.includeZero = includeZero; 135 this.includeZero = includeZero;
135 this.isInverted = isInverted; 136 this.isInverted = isInverted;
136 this.isLog = isLog; 137 this.isLog = isLog;
138 this.lowerMargin = lowerMargin;
139 this.upperMargin = upperMargin;
137 } 140 }
138 141
139 public String getName() { 142 public String getName() {
140 return name; 143 return name;
141 } 144 }
157 } 160 }
158 161
159 public Evaluator isLog() { 162 public Evaluator isLog() {
160 return isLog; 163 return isLog;
161 } 164 }
165
166 public double getLowerMargin() {
167 return this.lowerMargin;
168 }
169
170 public double getUpperMargin() {
171 return this.upperMargin;
172 }
162 } // class AxisAttributes 173 } // class AxisAttributes
163 174
164 public class DomainAxisAttributes extends AxisAttributes { 175 public class DomainAxisAttributes extends AxisAttributes {
165 176
166 private Title title; 177 private Title title;
167
168 public DomainAxisAttributes() {
169 }
170 178
171 public DomainAxisAttributes( 179 public DomainAxisAttributes(
172 String name, 180 String name,
173 boolean isLeftAlign, 181 boolean isLeftAlign,
174 boolean forceAlign, 182 boolean forceAlign,
176 Evaluator isInverted, 184 Evaluator isInverted,
177 Evaluator isLog, 185 Evaluator isLog,
178 Title title 186 Title title
179 ) { 187 ) {
180 super(name, isLeftAlign, forceAlign, includeZero, isInverted, 188 super(name, isLeftAlign, forceAlign, includeZero, isInverted,
181 isLog); 189 isLog, 0.0, 0.0);
182 this.title = title; 190 this.title = title;
183 } 191 }
184 192
185 public Title getTitle() { 193 public Title getTitle() {
186 return title; 194 return title;
373 axisElement.getAttribute("include-zero").trim(); 381 axisElement.getAttribute("include-zero").trim();
374 382
375 String isInverted = axisElement.getAttribute("inverted"); 383 String isInverted = axisElement.getAttribute("inverted");
376 String isLog = axisElement.getAttribute("logarithmic"); 384 String isLog = axisElement.getAttribute("logarithmic");
377 385
386 final double lowerMargin = parseDouble( axisElement.getAttribute("lowerMargin"), 0.0 );
387 final double upperMargin = parseDouble( axisElement.getAttribute("upperMargin"), 0.0 );
388
378 if (name.isEmpty()) { 389 if (name.isEmpty()) {
379 continue; 390 continue;
380 } 391 }
381 boolean isleftAlign = false; 392 boolean isleftAlign = false;
382 boolean forceAlign = false; 393 boolean forceAlign = false;
392 Evaluator isLogE = parseEvaluator(isLog, FALSE); 403 Evaluator isLogE = parseEvaluator(isLog, FALSE);
393 404
394 axesAttrs.add(new AxisAttributes( 405 axesAttrs.add(new AxisAttributes(
395 name, isleftAlign, forceAlign, 406 name, isleftAlign, forceAlign,
396 includeZero.equals("true"), 407 includeZero.equals("true"),
397 isInvertedE, isLogE)); 408 isInvertedE, isLogE,
409 lowerMargin,upperMargin));
410 }
411 }
412
413 private static double parseDouble( final String text, final double defaultValue ) {
414 if( text == null || text.isEmpty() )
415 return defaultValue;
416
417 try {
418 return Double.parseDouble(text);
419 }
420 catch (final NumberFormatException e) {
421 e.printStackTrace();
422 log.error(String.format("Invalid double attribute: ", text), e);
423 return defaultValue;
398 } 424 }
399 } 425 }
400 426
401 private static Evaluator createDynamicEvaluator( 427 private static Evaluator createDynamicEvaluator(
402 String className, 428 String className,

http://dive4elements.wald.intevation.org