use of org.jfree.data.general.PieDataset in project cytoscape-impl by cytoscape.
the class PieLayer method createDataset.
// ==[ PRIVATE METHODS ]============================================================================================
@Override
protected PieDataset createDataset() {
final List<Double> values = data.isEmpty() ? null : data.values().iterator().next();
final PieDataset dataset = createPieDataset(values);
if (showItemLabels && itemLabels != null) {
final List<?> keys = dataset.getKeys();
for (int i = 0; i < keys.size(); i++) {
final String k = (String) keys.get(i);
final String label = itemLabels.size() > i ? itemLabels.get(i) : null;
labels.put(k, label);
}
}
return dataset;
}
use of org.jfree.data.general.PieDataset in project cytoscape-impl by cytoscape.
the class RingLayer method getChart.
@Override
@SuppressWarnings("unchecked")
protected JFreeChart getChart() {
if (datasetList == null || chartList == null) {
createDataset();
final int total = datasetList.size();
chartList = new ArrayList<JFreeChart>(total);
if (total > 0) {
int count = 0;
for (final PieDataset ds : datasetList) {
double sectionDepth = ((1.0 - hole) / (double) total) * (total - count);
final JFreeChart chart = createChart(ds, sectionDepth, PieLayer.INTERIOR_GAP);
chartList.add(chart);
count++;
}
} else {
// Just to show the "no data" text
final JFreeChart chart = createChart(createPieDataset(Collections.EMPTY_LIST), 1.0, 0.0);
chartList.add(chart);
}
}
return chartList == null || chartList.isEmpty() ? null : chartList.get(0);
}
use of org.jfree.data.general.PieDataset in project MassBank-web by MassBank.
the class Contents method init.
public void init() throws ServletException {
try {
result = new SearchExecution(null).exec(new RecordIndexCount());
// construct and show pie charts
int MAX_DISP_DATA = 10;
PieDataset siteGraphData = createDataset(result.mapSiteToRecordCount, MAX_DISP_DATA);
PieDataset instGraphData = createDataset(result.mapInstrumentToRecordCount, MAX_DISP_DATA);
PieDataset msGraphData = createDataset(result.mapMsTypeToRecordCount, MAX_DISP_DATA);
int siteTopNum = (siteGraphData.getItemCount() < MAX_DISP_DATA) ? siteGraphData.getItemCount() : MAX_DISP_DATA;
int instTopNum = (instGraphData.getItemCount() < MAX_DISP_DATA) ? instGraphData.getItemCount() : MAX_DISP_DATA;
int msTopNum = (msGraphData.getItemCount() < MAX_DISP_DATA) ? msGraphData.getItemCount() : MAX_DISP_DATA;
JFreeChart sitechart = drawDataset(siteGraphData, "Contributor top " + siteTopNum);
JFreeChart instchart = drawDataset(instGraphData, "Instrument Type top " + instTopNum);
JFreeChart mschart = drawDataset(msGraphData, "MS Type top " + msTopNum);
SVGGraphics2D g2 = new SVGGraphics2D(900, 350);
Rectangle r = new Rectangle(0, 0, 900, 350);
sitechart.draw(g2, r);
sitechartSVG = g2.getSVGElement();
instchart.draw(g2, r);
instchartSVG = g2.getSVGElement();
mschart.draw(g2, r);
mschartSVG = g2.getSVGElement();
// get the current database timestamp
timestamp = new DatabaseTimestamp();
} catch (SQLException | ConfigurationException e) {
logger.error(e.getMessage());
}
}
use of org.jfree.data.general.PieDataset in project SIMVA-SoS by SESoS.
the class MultiplePiePlot method draw.
/**
* Draws the plot on a Java 2D graphics device (such as the screen or a
* printer).
*
* @param g2 the graphics device.
* @param area the area within which the plot should be drawn.
* @param anchor the anchor point (<code>null</code> permitted).
* @param parentState the state from the parent plot, if there is one.
* @param info collects info about the drawing.
*/
@Override
public void draw(Graphics2D g2, Rectangle2D area, Point2D anchor, PlotState parentState, PlotRenderingInfo info) {
// adjust the drawing area for the plot insets (if any)...
RectangleInsets insets = getInsets();
insets.trim(area);
drawBackground(g2, area);
drawOutline(g2, area);
// check that there is some data to display...
if (DatasetUtilities.isEmptyOrNull(this.dataset)) {
drawNoDataMessage(g2, area);
return;
}
int pieCount;
if (this.dataExtractOrder == TableOrder.BY_ROW) {
pieCount = this.dataset.getRowCount();
} else {
pieCount = this.dataset.getColumnCount();
}
// the columns variable is always >= rows
int displayCols = (int) Math.ceil(Math.sqrt(pieCount));
int displayRows = (int) Math.ceil((double) pieCount / (double) displayCols);
// swap rows and columns to match plotArea shape
if (displayCols > displayRows && area.getWidth() < area.getHeight()) {
int temp = displayCols;
displayCols = displayRows;
displayRows = temp;
}
prefetchSectionPaints();
int x = (int) area.getX();
int y = (int) area.getY();
int width = ((int) area.getWidth()) / displayCols;
int height = ((int) area.getHeight()) / displayRows;
int row = 0;
int column = 0;
int diff = (displayRows * displayCols) - pieCount;
int xoffset = 0;
Rectangle rect = new Rectangle();
for (int pieIndex = 0; pieIndex < pieCount; pieIndex++) {
rect.setBounds(x + xoffset + (width * column), y + (height * row), width, height);
String title;
if (this.dataExtractOrder == TableOrder.BY_ROW) {
title = this.dataset.getRowKey(pieIndex).toString();
} else {
title = this.dataset.getColumnKey(pieIndex).toString();
}
this.pieChart.setTitle(title);
PieDataset piedataset;
PieDataset dd = new CategoryToPieDataset(this.dataset, this.dataExtractOrder, pieIndex);
if (this.limit > 0.0) {
piedataset = DatasetUtilities.createConsolidatedPieDataset(dd, this.aggregatedItemsKey, this.limit);
} else {
piedataset = dd;
}
PiePlot piePlot = (PiePlot) this.pieChart.getPlot();
piePlot.setDataset(piedataset);
piePlot.setPieIndex(pieIndex);
// update the section colors to match the global colors...
for (int i = 0; i < piedataset.getItemCount(); i++) {
Comparable key = piedataset.getKey(i);
Paint p;
if (key.equals(this.aggregatedItemsKey)) {
p = this.aggregatedItemsPaint;
} else {
p = (Paint) this.sectionPaints.get(key);
}
piePlot.setSectionPaint(key, p);
}
ChartRenderingInfo subinfo = null;
if (info != null) {
subinfo = new ChartRenderingInfo();
}
this.pieChart.draw(g2, rect, subinfo);
if (info != null) {
assert subinfo != null;
info.getOwner().getEntityCollection().addAll(subinfo.getEntityCollection());
info.addSubplotInfo(subinfo.getPlotInfo());
}
++column;
if (column == displayCols) {
column = 0;
++row;
if (row == displayRows - 1 && diff != 0) {
xoffset = (diff * width) / 2;
}
}
}
}
use of org.jfree.data.general.PieDataset in project SIMVA-SoS by SESoS.
the class CategoryToPieDataset method equals.
/**
* Tests this dataset for equality with an arbitrary object, returning
* <code>true</code> if <code>obj</code> is a dataset containing the same
* keys and values in the same order as this dataset.
*
* @param obj the object to test (<code>null</code> permitted).
*
* @return A boolean.
*/
@Override
public boolean equals(Object obj) {
if (obj == this) {
return true;
}
if (!(obj instanceof PieDataset)) {
return false;
}
PieDataset that = (PieDataset) obj;
int count = getItemCount();
if (that.getItemCount() != count) {
return false;
}
for (int i = 0; i < count; i++) {
Comparable k1 = getKey(i);
Comparable k2 = that.getKey(i);
if (!k1.equals(k2)) {
return false;
}
Number v1 = getValue(i);
Number v2 = that.getValue(i);
if (v1 == null) {
if (v2 != null) {
return false;
}
} else {
if (!v1.equals(v2)) {
return false;
}
}
}
return true;
}
Aggregations