use of ambit2.db.chart.FingerprintHistogramDataset 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;
}
Aggregations