Search in sources :

Example 1 with PieChartGenerator

use of ambit2.db.chart.PieChartGenerator 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 PieChartGenerator

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

the class PieChartGeneratorTest method test.

public Image test() {
    Connection c = null;
    try {
        initDatasource();
        c = datasource.getConnection();
        // IStoredQuery q = new StoredQuery(6);
        SourceDataset dataset = new SourceDataset();
        dataset.setId(6);
        PieChartGenerator gen = new PieChartGenerator();
        gen.setConnection(c);
        Property p = Property.getInstance("toxTree.tree.cramer.CramerRules", "");
        p.setId(12361);
        gen.setProperty(p);
        return gen.process(dataset);
    } catch (Exception x) {
        x.printStackTrace();
        return null;
    } finally {
        try {
            c.close();
        } catch (Exception x) {
        }
    }
}
Also used : Connection(java.sql.Connection) SourceDataset(ambit2.base.data.SourceDataset) PieChartGenerator(ambit2.db.chart.PieChartGenerator) Property(ambit2.base.data.Property)

Aggregations

PieChartGenerator (ambit2.db.chart.PieChartGenerator)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 PropertiesChartGenerator (ambit2.db.chart.PropertiesChartGenerator)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