use of org.jfree.data.category.CategoryDataset in project SIMVA-SoS by SESoS.
the class AreaChartTest method testReplaceDataset.
/**
* Replaces the chart's dataset and then checks that the new dataset is OK.
*/
@Test
public void testReplaceDataset() {
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 AreaChartTest method createAreaChart.
/**
* Create an area chart with sample data in the range -3 to +3.
*
* @return The chart.
*/
private static JFreeChart createAreaChart() {
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.createAreaChart("Area Chart", "Domain", "Range", dataset, PlotOrientation.HORIZONTAL, true, true, true);
}
use of org.jfree.data.category.CategoryDataset in project SIMVA-SoS by SESoS.
the class LayeredBarRenderer method calculateBarWidth.
/**
* Calculates the bar width and stores it in the renderer state.
*
* @param plot the plot.
* @param dataArea the data area.
* @param rendererIndex the renderer index.
* @param state the renderer state.
*/
@Override
protected void calculateBarWidth(CategoryPlot plot, Rectangle2D dataArea, int rendererIndex, CategoryItemRendererState state) {
// calculate the bar width - this calculation differs from the
// BarRenderer calculation because the bars are layered on top of one
// another, so there is effectively only one bar per category for
// the purpose of the bar width calculation
CategoryAxis domainAxis = getDomainAxis(plot, rendererIndex);
CategoryDataset dataset = plot.getDataset(rendererIndex);
if (dataset != null) {
int columns = dataset.getColumnCount();
int rows = dataset.getRowCount();
double space = 0.0;
PlotOrientation orientation = plot.getOrientation();
if (orientation == PlotOrientation.HORIZONTAL) {
space = dataArea.getHeight();
} else if (orientation == PlotOrientation.VERTICAL) {
space = dataArea.getWidth();
}
double maxWidth = space * getMaximumBarWidth();
double categoryMargin = 0.0;
if (columns > 1) {
categoryMargin = domainAxis.getCategoryMargin();
}
double used = space * (1 - domainAxis.getLowerMargin() - domainAxis.getUpperMargin() - categoryMargin);
if ((rows * columns) > 0) {
state.setBarWidth(Math.min(used / (dataset.getColumnCount()), maxWidth));
} else {
state.setBarWidth(Math.min(used, maxWidth));
}
}
}
use of org.jfree.data.category.CategoryDataset in project SIMVA-SoS by SESoS.
the class LineAndShapeRenderer method getLegendItem.
/**
* Returns a legend item for a series.
*
* @param datasetIndex the dataset index (zero-based).
* @param series the series index (zero-based).
*
* @return The legend item.
*/
@Override
public LegendItem getLegendItem(int datasetIndex, int series) {
CategoryPlot cp = getPlot();
if (cp == null) {
return null;
}
if (isSeriesVisible(series) && isSeriesVisibleInLegend(series)) {
CategoryDataset dataset = cp.getDataset(datasetIndex);
String label = getLegendItemLabelGenerator().generateLabel(dataset, series);
String description = label;
String toolTipText = null;
if (getLegendItemToolTipGenerator() != null) {
toolTipText = getLegendItemToolTipGenerator().generateLabel(dataset, series);
}
String urlText = null;
if (getLegendItemURLGenerator() != null) {
urlText = getLegendItemURLGenerator().generateLabel(dataset, series);
}
Shape shape = lookupLegendShape(series);
Paint paint = lookupSeriesPaint(series);
Paint fillPaint = (this.useFillPaint ? getItemFillPaint(series, 0) : paint);
boolean shapeOutlineVisible = this.drawOutlines;
Paint outlinePaint = (this.useOutlinePaint ? getItemOutlinePaint(series, 0) : paint);
Stroke outlineStroke = lookupSeriesOutlineStroke(series);
boolean lineVisible = getItemLineVisible(series, 0);
boolean shapeVisible = getItemShapeVisible(series, 0);
LegendItem result = new LegendItem(label, description, toolTipText, urlText, shapeVisible, shape, getItemShapeFilled(series, 0), fillPaint, shapeOutlineVisible, outlinePaint, outlineStroke, lineVisible, new Line2D.Double(-7.0, 0.0, 7.0, 0.0), getItemStroke(series, 0), getItemPaint(series, 0));
result.setLabelFont(lookupLegendTextFont(series));
Paint labelPaint = lookupLegendTextPaint(series);
if (labelPaint != null) {
result.setLabelPaint(labelPaint);
}
result.setDataset(dataset);
result.setDatasetIndex(datasetIndex);
result.setSeriesKey(dataset.getRowKey(series));
result.setSeriesIndex(series);
return result;
}
return null;
}
use of org.jfree.data.category.CategoryDataset in project SIMVA-SoS by SESoS.
the class StackedBarRenderer3D method calculateBarWidth.
/**
* Calculates the bar width and stores it in the renderer state.
*
* @param plot the plot.
* @param dataArea the data area.
* @param rendererIndex the renderer index.
* @param state the renderer state.
*/
@Override
protected void calculateBarWidth(CategoryPlot plot, Rectangle2D dataArea, int rendererIndex, CategoryItemRendererState state) {
// calculate the bar width
CategoryAxis domainAxis = getDomainAxis(plot, rendererIndex);
CategoryDataset data = plot.getDataset(rendererIndex);
if (data != null) {
PlotOrientation orientation = plot.getOrientation();
double space = 0.0;
if (orientation == PlotOrientation.HORIZONTAL) {
space = dataArea.getHeight();
} else if (orientation == PlotOrientation.VERTICAL) {
space = dataArea.getWidth();
}
double maxWidth = space * getMaximumBarWidth();
int columns = data.getColumnCount();
double categoryMargin = 0.0;
if (columns > 1) {
categoryMargin = domainAxis.getCategoryMargin();
}
double used = space * (1 - domainAxis.getLowerMargin() - domainAxis.getUpperMargin() - categoryMargin);
if (columns > 0) {
state.setBarWidth(Math.min(used / columns, maxWidth));
} else {
state.setBarWidth(Math.min(used, maxWidth));
}
}
}
Aggregations