use of org.jfree.data.category.CategoryDataset in project SIMVA-SoS by SESoS.
the class StackedBarChart3DTest method createChart.
/**
* Create a stacked bar chart with sample data in the range -3 to +3.
*
* @return The chart.
*/
private static JFreeChart createChart() {
Number[][] data = new Integer[][] { { new Integer(-3), new Integer(-2) }, { new Integer(-1), new Integer(1) }, { new Integer(2), new Integer(3) } };
CategoryDataset dataset = DatasetUtilities.createCategoryDataset("S", "C", data);
return ChartFactory.createStackedBarChart3D(// chart title
"Stacked Bar Chart 3D", "Domain", "Range", // data
dataset, PlotOrientation.HORIZONTAL, // include legend
true, true, true);
}
use of org.jfree.data.category.CategoryDataset in project SIMVA-SoS by SESoS.
the class StackedBarChart3DTest method testReplaceDataset.
/**
* Replaces the dataset and checks that it has changed as expected.
*/
@Test
public void testReplaceDataset() {
// create a dataset...
Number[][] data = new Integer[][] { { new Integer(-30), new Integer(-20) }, { new Integer(-10), new Integer(10) }, { new Integer(20), new Integer(30) } };
CategoryDataset newData = DatasetUtilities.createCategoryDataset("S", "C", data);
LocalListener l = new LocalListener();
this.chart.addChangeListener(l);
CategoryPlot plot = (CategoryPlot) this.chart.getPlot();
plot.setDataset(newData);
assertEquals(true, l.flag);
ValueAxis axis = plot.getRangeAxis();
Range range = axis.getRange();
assertTrue("Expecting the lower bound of the range to be around -30: " + range.getLowerBound(), range.getLowerBound() <= -30);
assertTrue("Expecting the upper bound of the range to be around 30: " + range.getUpperBound(), range.getUpperBound() >= 30);
}
use of org.jfree.data.category.CategoryDataset in project SIMVA-SoS by SESoS.
the class SubCategoryAxis method drawSubCategoryLabels.
/**
* Draws the category labels and returns the updated axis state.
*
* @param g2 the graphics device (<code>null</code> not permitted).
* @param plotArea the plot area (<code>null</code> not permitted).
* @param dataArea the area inside the axes (<code>null</code> not
* permitted).
* @param edge the axis location (<code>null</code> not permitted).
* @param state the axis state (<code>null</code> not permitted).
* @param plotState collects information about the plot (<code>null</code>
* permitted).
*
* @return The updated axis state (never <code>null</code>).
*/
protected AxisState drawSubCategoryLabels(Graphics2D g2, Rectangle2D plotArea, Rectangle2D dataArea, RectangleEdge edge, AxisState state, PlotRenderingInfo plotState) {
ParamChecks.nullNotPermitted(state, "state");
g2.setFont(this.subLabelFont);
g2.setPaint(this.subLabelPaint);
CategoryPlot plot = (CategoryPlot) getPlot();
int categoryCount = 0;
CategoryDataset dataset = plot.getDataset();
if (dataset != null) {
categoryCount = dataset.getColumnCount();
}
double maxdim = getMaxDim(g2, edge);
for (int categoryIndex = 0; categoryIndex < categoryCount; categoryIndex++) {
double x0 = 0.0;
double x1 = 0.0;
double y0 = 0.0;
double y1 = 0.0;
if (edge == RectangleEdge.TOP) {
x0 = getCategoryStart(categoryIndex, categoryCount, dataArea, edge);
x1 = getCategoryEnd(categoryIndex, categoryCount, dataArea, edge);
y1 = state.getCursor();
y0 = y1 - maxdim;
} else if (edge == RectangleEdge.BOTTOM) {
x0 = getCategoryStart(categoryIndex, categoryCount, dataArea, edge);
x1 = getCategoryEnd(categoryIndex, categoryCount, dataArea, edge);
y0 = state.getCursor();
y1 = y0 + maxdim;
} else if (edge == RectangleEdge.LEFT) {
y0 = getCategoryStart(categoryIndex, categoryCount, dataArea, edge);
y1 = getCategoryEnd(categoryIndex, categoryCount, dataArea, edge);
x1 = state.getCursor();
x0 = x1 - maxdim;
} else if (edge == RectangleEdge.RIGHT) {
y0 = getCategoryStart(categoryIndex, categoryCount, dataArea, edge);
y1 = getCategoryEnd(categoryIndex, categoryCount, dataArea, edge);
x0 = state.getCursor();
x1 = x0 + maxdim;
}
Rectangle2D area = new Rectangle2D.Double(x0, y0, (x1 - x0), (y1 - y0));
int subCategoryCount = this.subCategories.size();
float width = (float) ((x1 - x0) / subCategoryCount);
float height = (float) ((y1 - y0) / subCategoryCount);
float xx, yy;
for (int i = 0; i < subCategoryCount; i++) {
if (RectangleEdge.isTopOrBottom(edge)) {
xx = (float) (x0 + (i + 0.5) * width);
yy = (float) area.getCenterY();
} else {
xx = (float) area.getCenterX();
yy = (float) (y0 + (i + 0.5) * height);
}
String label = this.subCategories.get(i).toString();
TextUtilities.drawRotatedString(label, g2, xx, yy, TextAnchor.CENTER, 0.0, TextAnchor.CENTER);
}
}
if (edge.equals(RectangleEdge.TOP)) {
double h = maxdim;
state.cursorUp(h);
} else if (edge.equals(RectangleEdge.BOTTOM)) {
double h = maxdim;
state.cursorDown(h);
} else if (edge == RectangleEdge.LEFT) {
double w = maxdim;
state.cursorLeft(w);
} else if (edge == RectangleEdge.RIGHT) {
double w = maxdim;
state.cursorRight(w);
}
return state;
}
use of org.jfree.data.category.CategoryDataset in project SIMVA-SoS by SESoS.
the class CategoryPlot method render.
/**
* Draws a representation of a dataset within the dataArea region using the
* appropriate renderer.
*
* @param g2 the graphics device.
* @param dataArea the region in which the data is to be drawn.
* @param index the dataset and renderer index.
* @param info an optional object for collection dimension information.
* @param crosshairState a state object for tracking crosshair info
* (<code>null</code> permitted).
*
* @return A boolean that indicates whether or not real data was found.
*
* @since 1.0.11
*/
public boolean render(Graphics2D g2, Rectangle2D dataArea, int index, PlotRenderingInfo info, CategoryCrosshairState crosshairState) {
boolean foundData = false;
CategoryDataset currentDataset = getDataset(index);
CategoryItemRenderer renderer = getRenderer(index);
CategoryAxis domainAxis = getDomainAxisForDataset(index);
ValueAxis rangeAxis = getRangeAxisForDataset(index);
boolean hasData = !DatasetUtilities.isEmptyOrNull(currentDataset);
if (hasData && renderer != null) {
foundData = true;
CategoryItemRendererState state = renderer.initialise(g2, dataArea, this, index, info);
state.setCrosshairState(crosshairState);
int columnCount = currentDataset.getColumnCount();
int rowCount = currentDataset.getRowCount();
int passCount = renderer.getPassCount();
for (int pass = 0; pass < passCount; pass++) {
if (this.columnRenderingOrder == SortOrder.ASCENDING) {
for (int column = 0; column < columnCount; column++) {
if (this.rowRenderingOrder == SortOrder.ASCENDING) {
for (int row = 0; row < rowCount; row++) {
renderer.drawItem(g2, state, dataArea, this, domainAxis, rangeAxis, currentDataset, row, column, pass);
}
} else {
for (int row = rowCount - 1; row >= 0; row--) {
renderer.drawItem(g2, state, dataArea, this, domainAxis, rangeAxis, currentDataset, row, column, pass);
}
}
}
} else {
for (int column = columnCount - 1; column >= 0; column--) {
if (this.rowRenderingOrder == SortOrder.ASCENDING) {
for (int row = 0; row < rowCount; row++) {
renderer.drawItem(g2, state, dataArea, this, domainAxis, rangeAxis, currentDataset, row, column, pass);
}
} else {
for (int row = rowCount - 1; row >= 0; row--) {
renderer.drawItem(g2, state, dataArea, this, domainAxis, rangeAxis, currentDataset, row, column, pass);
}
}
}
}
}
}
return foundData;
}
use of org.jfree.data.category.CategoryDataset in project SIMVA-SoS by SESoS.
the class CategoryTextAnnotation method draw.
/**
* Draws the annotation.
*
* @param g2 the graphics device.
* @param plot the plot.
* @param dataArea the data area.
* @param domainAxis the domain axis.
* @param rangeAxis the range axis.
*/
@Override
public void draw(Graphics2D g2, CategoryPlot plot, Rectangle2D dataArea, CategoryAxis domainAxis, ValueAxis rangeAxis) {
CategoryDataset dataset = plot.getDataset();
int catIndex = dataset.getColumnIndex(this.category);
int catCount = dataset.getColumnCount();
float anchorX = 0.0f;
float anchorY = 0.0f;
PlotOrientation orientation = plot.getOrientation();
RectangleEdge domainEdge = Plot.resolveDomainAxisLocation(plot.getDomainAxisLocation(), orientation);
RectangleEdge rangeEdge = Plot.resolveRangeAxisLocation(plot.getRangeAxisLocation(), orientation);
if (orientation == PlotOrientation.HORIZONTAL) {
anchorY = (float) domainAxis.getCategoryJava2DCoordinate(this.categoryAnchor, catIndex, catCount, dataArea, domainEdge);
anchorX = (float) rangeAxis.valueToJava2D(this.value, dataArea, rangeEdge);
} else if (orientation == PlotOrientation.VERTICAL) {
anchorX = (float) domainAxis.getCategoryJava2DCoordinate(this.categoryAnchor, catIndex, catCount, dataArea, domainEdge);
anchorY = (float) rangeAxis.valueToJava2D(this.value, dataArea, rangeEdge);
}
g2.setFont(getFont());
g2.setPaint(getPaint());
TextUtilities.drawRotatedString(getText(), g2, anchorX, anchorY, getTextAnchor(), getRotationAngle(), getRotationAnchor());
}
Aggregations