Search in sources :

Example 1 with PropertiesChartGenerator

use of ambit2.db.chart.PropertiesChartGenerator in project ambit-mirror by ideaconsult.

the class ChartResource method createImage.

protected BufferedImage createImage() throws ResourceException {
    BufferedImage image = null;
    Connection connection = null;
    try {
        DBConnection dbc = new DBConnection(getContext());
        connection = dbc.getConnection();
        ambit2.base.data.Template profile = new ambit2.base.data.Template();
        ProfileReader reader = new ProfileReader(getRequest().getRootRef(), profile, getApplication().getContext(), getToken(), getRequest().getCookies(), getRequest().getClientInfo() == null ? null : getRequest().getClientInfo().getAgent(), getRequest().getResourceRef().toString());
        reader.setCloseConnection(false);
        reader.setConnection(connection);
        for (String p : property) reader.process(new Reference(p));
        switch(mode) {
            case pie:
                {
                    Iterator<Property> i = profile.getProperties(true);
                    while (i.hasNext()) {
                        PieChartGenerator<ISourceDataset> chart = new PieChartGenerator<ISourceDataset>();
                        chart.setProperty(i.next());
                        chart.setConnection(connection);
                        chart.setLegend(legend);
                        chart.setThumbnail(thumbnail);
                        chart.setWidth(w);
                        chart.setHeight(h);
                        chart.setLogX(logX);
                        chart.setLogY(logY);
                        image = chart.process(dataset);
                        // ChartUtilities.writeImageMap(writer, name, info, useOverLibForToolTips)
                        break;
                    }
                    break;
                }
            case histogram:
                {
                    Iterator<Property> i = profile.getProperties(true);
                    while (i.hasNext()) {
                        HistogramChartGenerator chart = new HistogramChartGenerator();
                        chart.setLogX(logX);
                        chart.setLogY(logY);
                        chart.setMinX(minX);
                        chart.setMaxX(maxX);
                        chart.setPropertyX(i.next());
                        chart.setConnection(connection);
                        chart.setLegend(legend);
                        chart.setThumbnail(thumbnail);
                        chart.setWidth(w);
                        chart.setHeight(h);
                        image = chart.process(dataset);
                        // ChartUtilities.writeImageMap(writer, name, info, useOverLibForToolTips)
                        break;
                    }
                    break;
                }
            case xy:
                {
                    Property[] p = new Property[2];
                    int i = 0;
                    Iterator<Property> it = profile.getProperties(true);
                    while (it.hasNext()) {
                        p[i] = it.next();
                        i++;
                        if (i >= 2)
                            break;
                    }
                    PropertiesChartGenerator chart = new PropertiesChartGenerator();
                    chart.setLogX(logX);
                    chart.setLogY(logY);
                    chart.setThumbnail(thumbnail);
                    chart.setPropertyX(p[0]);
                    chart.setPropertyY(p.length < 2 ? p[0] : p[1]);
                    chart.setConnection(connection);
                    chart.setWidth(w);
                    chart.setHeight(h);
                    chart.setLegend(legend);
                    image = chart.process(dataset);
                    break;
                }
            case bar:
                {
                    Property[] p = new Property[2];
                    int i = 0;
                    Iterator<Property> it = profile.getProperties(true);
                    while (it.hasNext()) {
                        p[i] = it.next();
                        i++;
                        if (i >= 2)
                            break;
                    }
                    if (i == 0) {
                        FingerprintHistogramDataset chart = new FingerprintHistogramDataset();
                        chart.setLogX(logX);
                        chart.setLogY(logY);
                        chart.setConnection(connection);
                        chart.setLegend(legend);
                        chart.setParam(param);
                        chart.setThumbnail(thumbnail);
                        chart.setWidth(w);
                        chart.setHeight(h);
                        image = chart.process(dataset);
                    } else {
                        BarChartGeneratorDataset chart = new BarChartGeneratorDataset();
                        chart.setLogX(logX);
                        chart.setLogY(logY);
                        chart.setPropertyX(p[0]);
                        chart.setPropertyY(p.length < 2 ? p[0] : p[1]);
                        chart.setConnection(connection);
                        chart.setLegend(legend);
                        chart.setThumbnail(thumbnail);
                        chart.setWidth(w);
                        chart.setHeight(h);
                        image = chart.process(dataset);
                    }
                    break;
                }
            default:
                {
                    image = null;
                }
        }
    } catch (Exception x) {
        throw new ResourceException(Status.CLIENT_ERROR_BAD_REQUEST, x.getMessage(), x);
    } finally {
        try {
            connection.close();
        } catch (Exception x) {
        }
    }
    if (image == null)
        throw new ResourceException(Status.CLIENT_ERROR_BAD_REQUEST);
    return image;
}
Also used : DBConnection(ambit2.rest.DBConnection) ProfileReader(ambit2.rest.property.ProfileReader) Reference(org.restlet.data.Reference) Connection(java.sql.Connection) DBConnection(ambit2.rest.DBConnection) BufferedImage(java.awt.image.BufferedImage) ResourceException(org.restlet.resource.ResourceException) IOException(java.io.IOException) InvalidResourceIDException(ambit2.rest.error.InvalidResourceIDException) Template(org.restlet.routing.Template) PropertiesChartGenerator(ambit2.db.chart.PropertiesChartGenerator) ISourceDataset(ambit2.base.data.ISourceDataset) BarChartGeneratorDataset(ambit2.db.chart.BarChartGeneratorDataset) Iterator(java.util.Iterator) PieChartGenerator(ambit2.db.chart.PieChartGenerator) ResourceException(org.restlet.resource.ResourceException) HistogramChartGenerator(ambit2.db.chart.HistogramChartGenerator) FingerprintHistogramDataset(ambit2.db.chart.FingerprintHistogramDataset)

Example 2 with PropertiesChartGenerator

use of ambit2.db.chart.PropertiesChartGenerator in project ambit-mirror by ideaconsult.

the class PieChartGeneratorTest method testScatterPlot.

public Image testScatterPlot() {
    Connection c = null;
    try {
        initDatasource();
        c = datasource.getConnection();
        SourceDataset q = new SourceDataset();
        q.setId(78);
        PropertiesChartGenerator gen = new PropertiesChartGenerator();
        gen.setConnection(c);
        Property p = Property.getInstance("XLogP", "");
        p.setId(13993);
        gen.setPropertyX(p);
        p = Property.getInstance("LLNA EC3 %", "");
        p.setId(13995);
        gen.setPropertyY(p);
        return gen.process(q);
    } catch (Exception x) {
        x.printStackTrace();
        return null;
    } finally {
        try {
            c.close();
        } catch (Exception x) {
        }
    }
}
Also used : PropertiesChartGenerator(ambit2.db.chart.PropertiesChartGenerator) Connection(java.sql.Connection) SourceDataset(ambit2.base.data.SourceDataset) Property(ambit2.base.data.Property)

Aggregations

PropertiesChartGenerator (ambit2.db.chart.PropertiesChartGenerator)2 Connection (java.sql.Connection)2 ISourceDataset (ambit2.base.data.ISourceDataset)1 Property (ambit2.base.data.Property)1 SourceDataset (ambit2.base.data.SourceDataset)1 BarChartGeneratorDataset (ambit2.db.chart.BarChartGeneratorDataset)1 FingerprintHistogramDataset (ambit2.db.chart.FingerprintHistogramDataset)1 HistogramChartGenerator (ambit2.db.chart.HistogramChartGenerator)1 PieChartGenerator (ambit2.db.chart.PieChartGenerator)1 DBConnection (ambit2.rest.DBConnection)1 InvalidResourceIDException (ambit2.rest.error.InvalidResourceIDException)1 ProfileReader (ambit2.rest.property.ProfileReader)1 BufferedImage (java.awt.image.BufferedImage)1 IOException (java.io.IOException)1 Iterator (java.util.Iterator)1 Reference (org.restlet.data.Reference)1 ResourceException (org.restlet.resource.ResourceException)1 Template (org.restlet.routing.Template)1