1 19 package jcckit.plot; 20 21 import jcckit.graphic.GraphPoint; 22 import jcckit.graphic.GraphicAttributes; 23 import jcckit.graphic.GraphicalComposite; 24 import jcckit.graphic.GraphicalElement; 25 import jcckit.graphic.Rectangle; 26 import jcckit.util.ConfigParameters; 27 import jcckit.util.Factory; 28 29 49 public class ErrorBarFactory implements SymbolFactory { 50 51 public static final String SYMBOL_FACTORY_KEY = "symbolFactory"; 52 53 private final SymbolFactory _symbolFactory; 54 private final GraphicAttributes _attributes; 55 private final double _size; 56 57 76 public ErrorBarFactory(ConfigParameters config) { 77 _symbolFactory = (SymbolFactory) Factory.createOrGet( 78 config.getNode(SYMBOL_FACTORY_KEY), null); 79 _size = config.getDouble(SIZE_KEY, 0); 80 _attributes = (GraphicAttributes) Factory.createOrGet( 81 config.getNode(ATTRIBUTES_KEY), null); 82 } 83 84 88 public GraphicalElement createLegendSymbol(GraphPoint centerPosition, 89 double size) { 90 return _symbolFactory == null ? new GraphicalComposite(null) 91 : _symbolFactory.createLegendSymbol(centerPosition, size); 92 } 93 94 104 public Symbol createSymbol(GraphPoint point, Hint hintFromPreviousPoint, 105 Hint hintFromPreviousCurve) { 106 GraphPoint origin = new GraphPoint(null); 107 GraphPoint position = null; 108 if (hintFromPreviousCurve instanceof PositionHint) { 109 origin = ((PositionHint) hintFromPreviousCurve).getOrigin(); 110 position = ((PositionHint) hintFromPreviousCurve).getPosition(); 111 } 112 if (position == null) { 113 if (_symbolFactory == null) { 114 return new Symbol(new GraphicalComposite(null), hintFromPreviousPoint, 115 new PositionHint(origin, point)); 116 } else { 117 return _symbolFactory.createSymbol(point, hintFromPreviousPoint, 118 new PositionHint(origin, point)); 119 } 120 } else { 121 double xError = point.getX() - origin.getX(); 122 double yError = point.getY() - origin.getY(); 123 GraphicalComposite errorBars = new GraphicalComposite(null); 124 if (xError > 0) { 125 errorBars.addElement(new Rectangle(position, 2 * xError, _size, 126 _attributes)); 127 } 128 if (yError > 0) { 129 errorBars.addElement(new Rectangle(position, _size, 2 * yError, 130 _attributes)); 131 } 132 return new Symbol(errorBars, hintFromPreviousPoint, 133 new PositionHint(origin, null)); 134 } 135 } 136 } 137 | Popular Tags |