58 private final Paint paint; 59 private final int minOutlineHeight; 60 private final IXDataRenderer content; 61 private final String text; 62 private final String description; 63 64 public QuantitySpanRenderer(IQuantitySeries<?> ranges, IXDataRenderer content, Paint paint, int minOutlineHeight, 65 String text, String description) { 66 this.ranges = ranges; 67 this.content = content; 68 this.paint = paint; 69 this.minOutlineHeight = minOutlineHeight; 70 this.text = text; 71 this.description = description; 72 } 73 74 private static int calcMargin(int height) { 75 return Math.min(5, (height + 10) / 20); 76 } 77 78 @Override 79 public IRenderedRow render(Graphics2D context, SubdividedQuantityRange xRange, int height) { 80 int margin = calcMargin(height); 81 int innerHeight = height - 2 * margin; 82 context.translate(0, margin); 83 context.setPaint(paint); 84 XYQuantities<?> quantities = ranges.getQuantities(xRange); 85 // Need to set y range to same as x range to be able to draw ranges (and eliminate creation of quantities). 86 quantities.setYRange(xRange); 87 AWTChartToolkit.drawRanges(context, quantities, innerHeight, true); 88 IRenderedRow renderedContent = content.render(context, xRange, innerHeight); 89 if (innerHeight >= minOutlineHeight) { 90 context.setPaint(Color.BLACK); 91 AWTChartToolkit.drawRanges(context, quantities, innerHeight, false); 92 } 93 context.translate(0, -margin); 94 return new QuantitySpanRendering(margin, quantities, renderedContent, paint, text, description); 95 } 96 97 private static class QuantitySpanRendering extends RenderedRowBase { 98 99 private final XYQuantities<?> points; 100 private final IRenderedRow content; 101 private final Paint paint; 102 private final int margin; 103 private String description; 104 105 public QuantitySpanRendering(int margin, XYQuantities<?> points, IRenderedRow content, Paint paint, String text, 106 String description) { 107 super(Arrays.asList(new RenderedRowBase(margin), content, new RenderedRowBase(margin)), 108 content.getHeight() + 2 * margin, text, description, null); 109 this.margin = margin; 110 this.points = points; 111 this.content = content; 112 this.paint = paint; 113 this.description = description; 114 } 115 116 @Override 117 public void infoAt(IChartInfoVisitor visitor, int x, int y, Point offset) { 118 offset = new Point(offset.x, offset.y + margin); 119 content.infoAt(visitor, x, y, offset); 120 121 // FIXME: Only output this if near the boundaries? At least handle infinite lengths. 122 if (points != null) { 123 int bucket = points.floorIndexAtX(x); 124 if (bucket < points.getSize()) { 125 Span span = new Span(bucket, offset); 126 while (bucket >= 0) { 127 double x2 = points.getPixelY(bucket); 128 if (x < x2) { 129 span.setIndex(bucket); 130 visitor.visit(span); 131 // Break now, or can there be more to collect? 132 break; 133 } 134 bucket--; 135 } 136 } 137 } 138 } 139 154 155 @Override 156 public Color getColor() { 157 return (paint instanceof Color) ? (Color) paint : null; 158 } 159 160 private void setIndex(int index) { 161 this.index = index; 162 } 163 164 @Override 165 public IQuantity getStartX() { 166 IQuantity org = super.getStartX(); 167 return (org == MISSING_START) ? null : org; 168 } 169 170 @Override 171 public IQuantity getEndX() { 172 IQuantity org = super.getEndX(); 173 return (org == MISSING_END) ? null : org; 174 } 175 176 @Override 177 public String getDescription() { 178 return description; 179 } 180 } 181 182 } 183 184 } | 58 private final Paint paint; 59 private final int minOutlineHeight; 60 private final IXDataRenderer content; 61 private final String text; 62 private final String description; 63 64 public QuantitySpanRenderer(IQuantitySeries<?> ranges, IXDataRenderer content, Paint paint, int minOutlineHeight, 65 String text, String description) { 66 this.ranges = ranges; 67 this.content = content; 68 this.paint = paint; 69 this.minOutlineHeight = minOutlineHeight; 70 this.text = text; 71 this.description = description; 72 } 73 74 private static int calcMargin(int height) { 75 return Math.min(5, (height + 10) / 20); 76 } 77 78 public String getName() { 79 return text; 80 } 81 82 @Override 83 public IRenderedRow render(Graphics2D context, SubdividedQuantityRange xRange, int height) { 84 int margin = calcMargin(height); 85 int innerHeight = height - 2 * margin; 86 context.translate(0, margin); 87 context.setPaint(paint); 88 XYQuantities<?> quantities = ranges.getQuantities(xRange); 89 // Need to set y range to same as x range to be able to draw ranges (and eliminate creation of quantities). 90 quantities.setYRange(xRange); 91 AWTChartToolkit.drawRanges(context, quantities, innerHeight, true); 92 IRenderedRow renderedContent = content.render(context, xRange, innerHeight); 93 if (innerHeight >= minOutlineHeight) { 94 context.setPaint(Color.BLACK); 95 AWTChartToolkit.drawRanges(context, quantities, innerHeight, false); 96 } 97 context.translate(0, -margin); 98 return new QuantitySpanRendering(margin, quantities, renderedContent, paint, text, description); 99 } 100 101 private static class QuantitySpanRendering extends RenderedRowBase { 102 103 private final XYQuantities<?> points; 104 private final IRenderedRow content; 105 private final Paint paint; 106 private final int margin; 107 private String description; 108 private String text; 109 110 public QuantitySpanRendering(int margin, XYQuantities<?> points, IRenderedRow content, Paint paint, String text, 111 String description) { 112 super(Arrays.asList(new RenderedRowBase(margin), content, new RenderedRowBase(margin)), 113 content.getHeight() + 2 * margin, text, description, null); 114 this.margin = margin; 115 this.points = points; 116 this.content = content; 117 this.paint = paint; 118 this.description = description; 119 this.text = text; 120 } 121 122 @Override 123 public void infoAt(IChartInfoVisitor visitor, int x, int y, Point offset) { 124 offset = new Point(offset.x, offset.y + margin); 125 content.infoAt(visitor, x, y, offset); 126 visitor.enterScope(text, true); 127 128 // FIXME: Only output this if near the boundaries? At least handle infinite lengths. 129 if (points != null) { 130 int bucket = points.floorIndexAtX(x); 131 if (bucket < points.getSize()) { 132 Span span = new Span(bucket, offset); 133 while (bucket >= 0) { 134 double x2 = points.getPixelY(bucket); 135 if (x < x2) { 136 span.setIndex(bucket); 137 visitor.visit(span); 138 // Break now, or can there be more to collect? 139 break; 140 } 141 bucket--; 142 } 143 } 144 } 145 } 146 161 162 @Override 163 public Color getColor() { 164 return (paint instanceof Color) ? (Color) paint : null; 165 } 166 167 private void setIndex(int index) { 168 this.index = index; 169 } 170 171 @Override 172 public IQuantity getStartX() { 173 IQuantity org = super.getStartX(); 174 return (org == MISSING_START) ? null : org; 175 } 176 177 @Override 178 public IQuantity getEndX() { 179 IQuantity org = super.getEndX(); 180 return (org == MISSING_END) ? null : org; 181 } 182 183 @Override 184 public String getName() { 185 return text; 186 } 187 188 @Override 189 public String getDescription() { 190 return description; 191 } 192 } 193 194 } 195 196 } |