use of com.google.code.appengine.awt.Color in project activityinfo by bedatadriven.
the class ItextMapRenderer method renderLegend.
private void renderLegend(MapReportElement element, Document doc) throws DocumentException, IOException {
Table table = new Table(2);
table.setBorderWidth(1);
table.setWidth(100f);
table.setBorderColor(new Color(100, 100, 100));
table.setPadding(5);
table.setSpacing(0);
table.setCellsFitPage(true);
table.setTableFitsPage(true);
table.setWidths(new int[] { 1, 3 });
Cell cell = new Cell(I18N.CONSTANTS.legend());
cell.setHeader(true);
cell.setColspan(2);
table.addCell(cell);
table.endHeaders();
for (MapLayerLegend legend : element.getContent().getLegends()) {
Cell symbolCell = new Cell();
symbolCell.setHorizontalAlignment(Element.ALIGN_CENTER);
symbolCell.setVerticalAlignment(Element.ALIGN_MIDDLE);
Image symbol = createLegendSymbol(legend, imageCreator);
symbolCell.addElement(symbol);
Cell descriptionCell = new Cell();
addLegendDescription(element, legend.getDefinition(), descriptionCell);
table.addCell(symbolCell);
table.addCell(descriptionCell);
}
doc.add(table);
}
use of com.google.code.appengine.awt.Color in project activityinfo by bedatadriven.
the class ItextMapRenderer method addPieChartDescription.
private void addPieChartDescription(MapReportElement element, Cell descriptionCell, PiechartMapLayer layer) throws BadElementException {
for (Slice slice : layer.getSlices()) {
IndicatorDTO indicator = element.getContent().getIndicatorById(slice.getIndicatorId());
Color color = ColorUtil.colorFromString(slice.getColor());
ItextGraphic sliceImage = renderSlice(imageCreator, color, 10);
Chunk box = new Chunk(sliceImage.toItextImage(), 0, 0);
Chunk description = new Chunk(indicator.getName());
Phrase phrase = new Phrase();
phrase.add(box);
phrase.add(description);
Paragraph paragraph = new Paragraph(phrase);
descriptionCell.add(paragraph);
}
}
use of com.google.code.appengine.awt.Color in project activityinfo by bedatadriven.
the class MapIconServlet method doGet.
@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
// Cache forever
resp.setHeader("Cache-Control", "max-age=31556926, public");
if (req.getParameter("t").equals("bubble")) {
int radius = Integer.parseInt(req.getParameter("r"));
Color color = ColorUtil.colorFromString(req.getParameter("c"));
BufferedImage icon = new BufferedImage(radius * 2, radius * 2, BufferedImage.TYPE_INT_ARGB);
Graphics2D g2d = icon.createGraphics();
g2d.setPaint(new Color(255, 255, 255, 0));
g2d.fillRect(0, 0, radius * 2, radius * 2);
renderer.drawBubble(g2d, color, radius, radius, radius);
resp.setContentType("image/png");
ImageIO.write(icon, "PNG", resp.getOutputStream());
} else {
if (req.getParameter("t").equals("piechart")) {
int radius = Integer.parseInt(req.getParameter("r"));
BufferedImage icon = new BufferedImage(radius * 2, radius * 2, BufferedImage.TYPE_INT_ARGB);
Graphics2D g2d = icon.createGraphics();
PieMapMarker pmm = new PieMapMarker();
pmm.setRadius(radius);
pmm.setX(radius);
pmm.setY(radius);
String[] values = req.getParameterValues("value");
String[] colors = req.getParameterValues("color");
if (colors.length != values.length) {
String error = "Expected same amount of colors & values. Amount of Colors: [{0}]. Amount of " + "values: [{1}].";
error = String.format(error, colors.length, values.length);
throw new ServletException(error);
}
for (int i = 0; i < colors.length; i++) {
String color;
double value = 0.0;
color = colors[i];
try {
value = Double.parseDouble(values[i]);
} catch (NumberFormatException e) {
// color = Color.decode(colors[i]).getRGB();
}
SliceValue slice = new SliceValue();
slice.setColor(color);
slice.setValue(value);
pmm.getSlices().add(slice);
}
g2d.setPaint(new Color(255, 255, 255, 0));
g2d.fillRect(0, 0, radius * 2, radius * 2);
renderer.drawPieMarker(g2d, pmm);
resp.setContentType("image/png");
ImageIO.write(icon, "PNG", resp.getOutputStream());
}
}
}
use of com.google.code.appengine.awt.Color in project activityinfo by bedatadriven.
the class ImageMapRendererTest method renderPieChart.
private void renderPieChart(double value) throws FileNotFoundException, IOException {
int radius = 21;
SliceValue s1 = new SliceValue();
s1.setColor("4169E1");
s1.setValue(value);
SliceValue s2 = new SliceValue();
s2.setColor("EEEE00");
s2.setValue(360d - value);
PieMapMarker pmm = new PieMapMarker();
pmm.setRadius(21);
pmm.setColor("FF0000");
pmm.getSlices().add(s1);
pmm.getSlices().add(s2);
pmm.setX(radius);
pmm.setY(radius);
BufferedImage icon = new BufferedImage(radius * 2, radius * 2, BufferedImage.TYPE_INT_ARGB);
Graphics2D g2d = icon.createGraphics();
g2d.setPaint(new Color(255, 255, 255, 0));
g2d.fillRect(0, 0, radius * 2, radius * 2);
ImageMapRenderer.drawPieMarker(g2d, pmm);
File outputFile = new File("build/report-tests/pieChart-" + ((int) value) + ".png");
outputFile.getParentFile().mkdirs();
FileOutputStream fos = new FileOutputStream(outputFile);
ImageIO.write(icon, "PNG", fos);
fos.close();
}
Aggregations