1 19 package jcckit.plot; 20 21 import jcckit.graphic.GraphPoint; 22 import jcckit.graphic.GraphicAttributes; 23 import jcckit.graphic.GraphicalElement; 24 import jcckit.graphic.Rectangle; 25 import jcckit.util.ConfigParameters; 26 27 42 public class BarFactory extends AbstractSymbolFactory { 43 44 public static final String STACKED_KEY = "stacked", 45 HORIZONTAL_BARS_KEY = "horizontalBars"; 46 47 private final boolean _stacked; 48 private final boolean _horizontalBars; 49 50 68 public BarFactory(ConfigParameters config) { 69 super(config); 70 _horizontalBars = config.getBoolean(HORIZONTAL_BARS_KEY, false); 71 _stacked = config.getBoolean(STACKED_KEY, false); 72 } 73 74 82 protected Symbol createSymbol(GraphPoint point, GraphicAttributes attributes, 83 Hint hintForNextPoint, 84 Hint hintFromPreviousCurve) { 85 GraphPoint origin = new GraphPoint(null); 86 GraphPoint position = origin; 87 if (hintFromPreviousCurve instanceof PositionHint) { 88 origin = ((PositionHint) hintFromPreviousCurve).getOrigin(); 89 position = ((PositionHint) hintFromPreviousCurve).getPosition(); 90 } 91 double px = position.getX(); 92 double py = position.getY(); 93 double x = point.getX() - origin.getX(); 94 double y = point.getY() - origin.getY(); 95 if (_horizontalBars) { 96 y = _size; 97 position = new GraphPoint(px + 0.5 * x, point.getY() + py); 98 px += _stacked ? x : 0; 99 py += _stacked ? 0 : _size; 100 } else { 101 x = _size; 102 position = new GraphPoint(point.getX() + px, py + 0.5 * y); 103 px += _stacked ? 0 : _size; 104 py += _stacked ? y : 0; 105 } 106 Hint hintForNextCurve = new PositionHint(origin, new GraphPoint(px, py)); 107 return new Symbol(new Rectangle(position, Math.abs(x), Math.abs(y), 108 attributes), 109 hintForNextPoint, hintForNextCurve); 110 } 111 112 117 public GraphicalElement createLegendSymbol(GraphPoint centerPosition, 118 double size) { 119 return new Rectangle(centerPosition, size, size, _attributes); 120 } 121 122 126 protected GraphicalElement createPlainSymbol( 127 GraphPoint centerPosition, double size, GraphicAttributes attributes) { 128 return null; 129 } 130 } 131 | Popular Tags |