Search in sources :

Example 1 with SliceValue

use of org.activityinfo.shared.report.content.PieMapMarker.SliceValue in project activityinfo by bedatadriven.

the class LeafletMarkerFactory method createPieMapMarker.

public static Marker createPieMapMarker(PieMapMarker marker) {
    StringBuilder sb = new StringBuilder();
    sb.append("icon?t=piechart&r=").append(marker.getRadius());
    for (SliceValue slice : marker.getSlices()) {
        sb.append("&value=").append(slice.getValue());
        sb.append("&color=").append(slice.getColor());
    }
    String iconUrl = sb.toString();
    int size = marker.getRadius() * 2;
    IconOptions iconOptions = new IconOptions();
    iconOptions.setIconUrl(iconUrl);
    iconOptions.setIconAnchor(new Point(marker.getRadius(), marker.getRadius()));
    iconOptions.setIconSize(new Point(size, size));
    Options markerOptions = new MarkerOptions();
    markerOptions.setProperty("icon", new Icon(iconOptions));
    return new Marker(toLatLng(marker), markerOptions);
}
Also used : IconOptions(org.discotools.gwt.leaflet.client.types.IconOptions) Options(org.discotools.gwt.leaflet.client.Options) MarkerOptions(org.discotools.gwt.leaflet.client.marker.MarkerOptions) MarkerOptions(org.discotools.gwt.leaflet.client.marker.MarkerOptions) SliceValue(org.activityinfo.shared.report.content.PieMapMarker.SliceValue) Point(org.discotools.gwt.leaflet.client.types.Point) MapIcon(org.activityinfo.shared.report.model.MapIcon) Icon(org.discotools.gwt.leaflet.client.types.Icon) MapMarker(org.activityinfo.shared.report.content.MapMarker) IconMapMarker(org.activityinfo.shared.report.content.IconMapMarker) PieMapMarker(org.activityinfo.shared.report.content.PieMapMarker) CircleMarker(org.discotools.gwt.leaflet.client.marker.CircleMarker) Marker(org.discotools.gwt.leaflet.client.marker.Marker) BubbleMapMarker(org.activityinfo.shared.report.content.BubbleMapMarker) Point(org.discotools.gwt.leaflet.client.types.Point) IconOptions(org.discotools.gwt.leaflet.client.types.IconOptions)

Example 2 with SliceValue

use of org.activityinfo.shared.report.content.PieMapMarker.SliceValue 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());
        }
    }
}
Also used : ServletException(javax.servlet.ServletException) Color(com.google.code.appengine.awt.Color) PieMapMarker(org.activityinfo.shared.report.content.PieMapMarker) SliceValue(org.activityinfo.shared.report.content.PieMapMarker.SliceValue) BufferedImage(com.google.code.appengine.awt.image.BufferedImage) Graphics2D(com.google.code.appengine.awt.Graphics2D)

Example 3 with SliceValue

use of org.activityinfo.shared.report.content.PieMapMarker.SliceValue 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("target/report-tests/pieChart-" + ((int) value) + ".png");
    outputFile.getParentFile().mkdirs();
    FileOutputStream fos = new FileOutputStream(outputFile);
    ImageIO.write(icon, "PNG", fos);
    fos.close();
}
Also used : PieMapMarker(org.activityinfo.shared.report.content.PieMapMarker) Color(com.google.code.appengine.awt.Color) FileOutputStream(java.io.FileOutputStream) SliceValue(org.activityinfo.shared.report.content.PieMapMarker.SliceValue) File(java.io.File) BufferedImage(com.google.code.appengine.awt.image.BufferedImage) Graphics2D(com.google.code.appengine.awt.Graphics2D)

Aggregations

PieMapMarker (org.activityinfo.shared.report.content.PieMapMarker)3 SliceValue (org.activityinfo.shared.report.content.PieMapMarker.SliceValue)3 Color (com.google.code.appengine.awt.Color)2 Graphics2D (com.google.code.appengine.awt.Graphics2D)2 BufferedImage (com.google.code.appengine.awt.image.BufferedImage)2 File (java.io.File)1 FileOutputStream (java.io.FileOutputStream)1 ServletException (javax.servlet.ServletException)1 BubbleMapMarker (org.activityinfo.shared.report.content.BubbleMapMarker)1 IconMapMarker (org.activityinfo.shared.report.content.IconMapMarker)1 MapMarker (org.activityinfo.shared.report.content.MapMarker)1 MapIcon (org.activityinfo.shared.report.model.MapIcon)1 Options (org.discotools.gwt.leaflet.client.Options)1 CircleMarker (org.discotools.gwt.leaflet.client.marker.CircleMarker)1 Marker (org.discotools.gwt.leaflet.client.marker.Marker)1 MarkerOptions (org.discotools.gwt.leaflet.client.marker.MarkerOptions)1 Icon (org.discotools.gwt.leaflet.client.types.Icon)1 IconOptions (org.discotools.gwt.leaflet.client.types.IconOptions)1 Point (org.discotools.gwt.leaflet.client.types.Point)1