use of org.jfree.chart.plot.PlotOrientation in project cytoscape-impl by cytoscape.
the class BoxLayer method createChart.
@Override
protected JFreeChart createChart(final BoxAndWhiskerCategoryDataset dataset) {
final JFreeChart chart = ChartFactory.createBoxAndWhiskerChart(// chart title
null, // domain axis label
null, // range axis label
null, // data
dataset, // include legend
false);
chart.setAntiAlias(true);
chart.setBorderVisible(false);
chart.setBackgroundPaint(TRANSPARENT_COLOR);
chart.setBackgroundImageAlpha(0.0f);
chart.setPadding(new RectangleInsets(0.0, 0.0, 0.0, 0.0));
final CategoryPlot plot = (CategoryPlot) chart.getPlot();
plot.setOutlineVisible(false);
plot.setInsets(new RectangleInsets(0.0, 0.0, 0.0, 0.0));
plot.setAxisOffset(new RectangleInsets(1.0, 1.0, 1.0, 1.0));
plot.setDomainGridlinesVisible(false);
plot.setRangeGridlinesVisible(false);
plot.setBackgroundPaint(TRANSPARENT_COLOR);
plot.setBackgroundAlpha(0.0f);
plot.setRangeAxisLocation(AxisLocation.BOTTOM_OR_LEFT);
if (showRangeZeroBaseline) {
plot.setRangeZeroBaselineVisible(true);
plot.setRangeZeroBaselinePaint(axisColor);
plot.setRangeZeroBaselineStroke(new EqualDashStroke(axisWidth));
}
final PlotOrientation plotOrientation = orientation == Orientation.HORIZONTAL ? PlotOrientation.HORIZONTAL : PlotOrientation.VERTICAL;
plot.setOrientation(plotOrientation);
final BasicStroke axisStroke = new BasicStroke(axisWidth, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND);
final CategoryAxis domainAxis = (CategoryAxis) plot.getDomainAxis();
domainAxis.setVisible(showDomainAxis);
domainAxis.setAxisLineStroke(axisStroke);
domainAxis.setAxisLinePaint(axisColor);
domainAxis.setTickMarksVisible(false);
domainAxis.setTickMarkStroke(axisStroke);
domainAxis.setTickMarkPaint(axisColor);
domainAxis.setTickLabelsVisible(false);
domainAxis.setCategoryMargin(.1);
domainAxis.setLowerMargin(.025);
domainAxis.setUpperMargin(.025);
final NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();
rangeAxis.setVisible(showRangeAxis);
rangeAxis.setAxisLineStroke(axisStroke);
rangeAxis.setAxisLinePaint(axisColor);
rangeAxis.setTickMarkStroke(axisStroke);
rangeAxis.setTickMarkPaint(axisColor);
rangeAxis.setTickLabelFont(rangeAxis.getLabelFont().deriveFont(axisFontSize).deriveFont(Font.PLAIN));
rangeAxis.setTickLabelPaint(axisColor);
rangeAxis.setLowerMargin(0.1);
rangeAxis.setUpperMargin(0.1);
// Set axis range
if (range != null && range.size() >= 2 && range.get(0) != null && range.get(1) != null) {
rangeAxis.setLowerBound(range.get(0));
rangeAxis.setUpperBound(range.get(1));
}
final BoxAndWhiskerRenderer renderer = (BoxAndWhiskerRenderer) plot.getRenderer();
renderer.setFillBox(true);
renderer.setMeanVisible(false);
// Box chart does not support item labels, anyway
renderer.setBaseItemLabelsVisible(false);
final BasicStroke stroke = new BasicStroke(borderWidth, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND);
final List<?> keys = dataset.getRowKeys();
for (int i = 0; i < keys.size(); i++) {
renderer.setSeriesStroke(i, stroke);
renderer.setSeriesOutlineStroke(i, stroke);
renderer.setSeriesOutlinePaint(i, borderWidth > 0 ? borderColor : TRANSPARENT_COLOR);
if (colors != null && colors.size() >= keys.size())
renderer.setSeriesPaint(i, colors.get(i));
}
return chart;
}
use of org.jfree.chart.plot.PlotOrientation in project cytoscape-impl by cytoscape.
the class BarLayer method createChart.
@Override
protected JFreeChart createChart(final CategoryDataset dataset) {
final PlotOrientation plotOrientation = orientation == Orientation.HORIZONTAL ? PlotOrientation.HORIZONTAL : PlotOrientation.VERTICAL;
final JFreeChart chart;
if (type == BarChartType.STACKED)
chart = ChartFactory.createStackedBarChart(// chart title
null, // domain axis label
null, // range axis label
null, // data
dataset, plotOrientation, // include legend
false, // tooltips
false, // urls
false);
else
chart = ChartFactory.createBarChart(// chart title
null, // domain axis label
null, // range axis label
null, // data
dataset, plotOrientation, // include legend
false, // tooltips
false, // urls
false);
chart.setAntiAlias(true);
chart.setBorderVisible(false);
chart.setBackgroundPaint(TRANSPARENT_COLOR);
chart.setBackgroundImageAlpha(0.0f);
chart.setPadding(new RectangleInsets(0.0, 0.0, 0.0, 0.0));
final CategoryPlot plot = (CategoryPlot) chart.getPlot();
plot.setOutlineVisible(false);
plot.setInsets(new RectangleInsets(0.0, 0.0, 0.0, 0.0));
plot.setAxisOffset(new RectangleInsets(1.0, 1.0, 1.0, 1.0));
plot.setDomainGridlinesVisible(false);
plot.setRangeGridlinesVisible(false);
plot.setBackgroundPaint(TRANSPARENT_COLOR);
plot.setBackgroundAlpha(0.0f);
plot.setRangeAxisLocation(AxisLocation.BOTTOM_OR_LEFT);
if (showRangeZeroBaseline) {
plot.setRangeZeroBaselineVisible(true);
plot.setRangeZeroBaselinePaint(axisColor);
plot.setRangeZeroBaselineStroke(new EqualDashStroke(axisWidth));
}
final BasicStroke axisStroke = new BasicStroke(axisWidth, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND);
final CategoryAxis domainAxis = (CategoryAxis) plot.getDomainAxis();
domainAxis.setVisible(showDomainAxis);
domainAxis.setAxisLineStroke(axisStroke);
domainAxis.setAxisLinePaint(axisColor);
domainAxis.setTickMarkStroke(axisStroke);
domainAxis.setTickMarkPaint(axisColor);
domainAxis.setTickMarksVisible(true);
domainAxis.setTickLabelsVisible(true);
domainAxis.setTickLabelFont(domainAxis.getTickLabelFont().deriveFont(axisFontSize));
domainAxis.setTickLabelPaint(axisColor);
domainAxis.setCategoryLabelPositions(getCategoryLabelPosition());
domainAxis.setCategoryMargin((type == BarChartType.STACKED || singleCategory) ? separation : 0.1);
domainAxis.setLowerMargin(.025);
domainAxis.setUpperMargin(.025);
final NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();
rangeAxis.setVisible(showRangeAxis);
rangeAxis.setAxisLineStroke(axisStroke);
rangeAxis.setAxisLinePaint(axisColor);
rangeAxis.setTickMarkStroke(axisStroke);
rangeAxis.setTickMarkPaint(axisColor);
rangeAxis.setTickLabelFont(rangeAxis.getLabelFont().deriveFont(axisFontSize).deriveFont(Font.PLAIN));
rangeAxis.setTickLabelPaint(axisColor);
rangeAxis.setLowerMargin(0.1);
rangeAxis.setUpperMargin(0.1);
// Set axis range
if (range != null && range.size() >= 2 && range.get(0) != null && range.get(1) != null) {
rangeAxis.setLowerBound(range.get(0));
rangeAxis.setUpperBound(range.get(1));
}
if (type != BarChartType.STACKED) {
if (type == BarChartType.HEAT_STRIPS || type == BarChartType.UP_DOWN) {
final Color up = (colors.size() > 0) ? colors.get(0) : Color.LIGHT_GRAY;
final Color zero = (colors.size() > 2) ? colors.get(1) : Color.BLACK;
final Color down = (colors.size() > 2) ? colors.get(2) : (colors.size() > 1 ? colors.get(1) : Color.GRAY);
plot.setRenderer(new UpDownColorBarRenderer(up, zero, down));
} else if (singleCategory) {
plot.setRenderer(new SingleCategoryRenderer());
}
}
final BarRenderer renderer = (BarRenderer) plot.getRenderer();
renderer.setBarPainter(new StandardBarPainter());
renderer.setShadowVisible(false);
renderer.setDrawBarOutline(true);
renderer.setBaseItemLabelGenerator(showItemLabels ? new CustomCategoryItemLabelGenerator(itemLabels) : null);
renderer.setBaseItemLabelsVisible(showItemLabels);
renderer.setBaseItemLabelFont(renderer.getBaseItemLabelFont().deriveFont(itemFontSize));
renderer.setBaseItemLabelPaint(labelColor);
renderer.setItemMargin(separation);
if (type != BarChartType.STACKED && showItemLabels) {
double angle = orientation == Orientation.HORIZONTAL ? 0 : -Math.PI / 2;
renderer.setBasePositiveItemLabelPosition(new ItemLabelPosition(ItemLabelAnchor.CENTER, TextAnchor.CENTER, TextAnchor.CENTER, angle));
renderer.setBaseNegativeItemLabelPosition(new ItemLabelPosition(ItemLabelAnchor.CENTER, TextAnchor.CENTER, TextAnchor.CENTER, angle));
}
final BasicStroke borderStroke = new BasicStroke(borderWidth, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND);
final List<?> keys = dataset.getRowKeys();
for (int i = 0; i < keys.size(); i++) {
renderer.setSeriesOutlineStroke(i, borderStroke);
renderer.setSeriesOutlinePaint(i, borderWidth > 0 ? borderColor : TRANSPARENT_COLOR);
if (type != BarChartType.UP_DOWN && type != BarChartType.HEAT_STRIPS) {
Color c = DEFAULT_ITEM_BG_COLOR;
if (colors != null && colors.size() > i)
c = colors.get(i);
renderer.setSeriesPaint(i, c);
}
}
return chart;
}
use of org.jfree.chart.plot.PlotOrientation in project SIMVA-SoS by SESoS.
the class XYBlockRenderer method drawItem.
/**
* Draws the block representing the specified item.
*
* @param g2 the graphics device.
* @param state the state.
* @param dataArea the data area.
* @param info the plot rendering info.
* @param plot the plot.
* @param domainAxis the x-axis.
* @param rangeAxis the y-axis.
* @param dataset the dataset.
* @param series the series index.
* @param item the item index.
* @param crosshairState the crosshair state.
* @param pass the pass index.
*/
@Override
public void drawItem(Graphics2D g2, XYItemRendererState state, Rectangle2D dataArea, PlotRenderingInfo info, XYPlot plot, ValueAxis domainAxis, ValueAxis rangeAxis, XYDataset dataset, int series, int item, CrosshairState crosshairState, int pass) {
double x = dataset.getXValue(series, item);
double y = dataset.getYValue(series, item);
double z = 0.0;
if (dataset instanceof XYZDataset) {
z = ((XYZDataset) dataset).getZValue(series, item);
}
Paint p = this.paintScale.getPaint(z);
double xx0 = domainAxis.valueToJava2D(x + this.xOffset, dataArea, plot.getDomainAxisEdge());
double yy0 = rangeAxis.valueToJava2D(y + this.yOffset, dataArea, plot.getRangeAxisEdge());
double xx1 = domainAxis.valueToJava2D(x + this.blockWidth + this.xOffset, dataArea, plot.getDomainAxisEdge());
double yy1 = rangeAxis.valueToJava2D(y + this.blockHeight + this.yOffset, dataArea, plot.getRangeAxisEdge());
Rectangle2D block;
PlotOrientation orientation = plot.getOrientation();
if (orientation.equals(PlotOrientation.HORIZONTAL)) {
block = new Rectangle2D.Double(Math.min(yy0, yy1), Math.min(xx0, xx1), Math.abs(yy1 - yy0), Math.abs(xx0 - xx1));
} else {
block = new Rectangle2D.Double(Math.min(xx0, xx1), Math.min(yy0, yy1), Math.abs(xx1 - xx0), Math.abs(yy1 - yy0));
}
g2.setPaint(p);
g2.fill(block);
g2.setStroke(new BasicStroke(1.0f));
g2.draw(block);
EntityCollection entities = state.getEntityCollection();
if (entities != null) {
addEntity(entities, block, dataset, series, item, 0.0, 0.0);
}
}
use of org.jfree.chart.plot.PlotOrientation in project SIMVA-SoS by SESoS.
the class XYBubbleRenderer method drawItem.
/**
* Draws the visual representation of a single data item.
*
* @param g2 the graphics device.
* @param state the renderer state.
* @param dataArea the area within which the data is being drawn.
* @param info collects information about the drawing.
* @param plot the plot (can be used to obtain standard color
* information etc).
* @param domainAxis the domain (horizontal) axis.
* @param rangeAxis the range (vertical) axis.
* @param dataset the dataset (an {@link XYZDataset} is expected).
* @param series the series index (zero-based).
* @param item the item index (zero-based).
* @param crosshairState crosshair information for the plot
* (<code>null</code> permitted).
* @param pass the pass index.
*/
@Override
public void drawItem(Graphics2D g2, XYItemRendererState state, Rectangle2D dataArea, PlotRenderingInfo info, XYPlot plot, ValueAxis domainAxis, ValueAxis rangeAxis, XYDataset dataset, int series, int item, CrosshairState crosshairState, int pass) {
// return straight away if the item is not visible
if (!getItemVisible(series, item)) {
return;
}
PlotOrientation orientation = plot.getOrientation();
// get the data point...
double x = dataset.getXValue(series, item);
double y = dataset.getYValue(series, item);
double z = Double.NaN;
if (dataset instanceof XYZDataset) {
XYZDataset xyzData = (XYZDataset) dataset;
z = xyzData.getZValue(series, item);
}
if (!Double.isNaN(z)) {
RectangleEdge domainAxisLocation = plot.getDomainAxisEdge();
RectangleEdge rangeAxisLocation = plot.getRangeAxisEdge();
double transX = domainAxis.valueToJava2D(x, dataArea, domainAxisLocation);
double transY = rangeAxis.valueToJava2D(y, dataArea, rangeAxisLocation);
double transDomain;
double transRange;
double zero;
switch(getScaleType()) {
case SCALE_ON_DOMAIN_AXIS:
zero = domainAxis.valueToJava2D(0.0, dataArea, domainAxisLocation);
transDomain = domainAxis.valueToJava2D(z, dataArea, domainAxisLocation) - zero;
transRange = transDomain;
break;
case SCALE_ON_RANGE_AXIS:
zero = rangeAxis.valueToJava2D(0.0, dataArea, rangeAxisLocation);
transRange = zero - rangeAxis.valueToJava2D(z, dataArea, rangeAxisLocation);
transDomain = transRange;
break;
default:
double zero1 = domainAxis.valueToJava2D(0.0, dataArea, domainAxisLocation);
double zero2 = rangeAxis.valueToJava2D(0.0, dataArea, rangeAxisLocation);
transDomain = domainAxis.valueToJava2D(z, dataArea, domainAxisLocation) - zero1;
transRange = zero2 - rangeAxis.valueToJava2D(z, dataArea, rangeAxisLocation);
}
transDomain = Math.abs(transDomain);
transRange = Math.abs(transRange);
Ellipse2D circle = null;
if (orientation == PlotOrientation.VERTICAL) {
circle = new Ellipse2D.Double(transX - transDomain / 2.0, transY - transRange / 2.0, transDomain, transRange);
} else if (orientation == PlotOrientation.HORIZONTAL) {
circle = new Ellipse2D.Double(transY - transRange / 2.0, transX - transDomain / 2.0, transRange, transDomain);
} else {
throw new IllegalStateException();
}
g2.setPaint(getItemPaint(series, item));
g2.fill(circle);
g2.setStroke(getItemOutlineStroke(series, item));
g2.setPaint(getItemOutlinePaint(series, item));
g2.draw(circle);
if (isItemLabelVisible(series, item)) {
if (orientation == PlotOrientation.VERTICAL) {
drawItemLabel(g2, orientation, dataset, series, item, transX, transY, false);
} else if (orientation == PlotOrientation.HORIZONTAL) {
drawItemLabel(g2, orientation, dataset, series, item, transY, transX, false);
}
}
// add an entity if this info is being collected
if (info != null) {
EntityCollection entities = info.getOwner().getEntityCollection();
if (entities != null && circle.intersects(dataArea)) {
addEntity(entities, circle, dataset, series, item, circle.getCenterX(), circle.getCenterY());
}
}
int domainAxisIndex = plot.getDomainAxisIndex(domainAxis);
int rangeAxisIndex = plot.getRangeAxisIndex(rangeAxis);
updateCrosshairValues(crosshairState, x, y, domainAxisIndex, rangeAxisIndex, transX, transY, orientation);
}
}
use of org.jfree.chart.plot.PlotOrientation in project SIMVA-SoS by SESoS.
the class XYDifferenceRenderer method createPolygon.
/**
* Draws the visual representation of a polygon
*
* @param x_graphics the graphics device.
* @param x_dataArea the area within which the data is being drawn.
* @param x_plot the plot (can be used to obtain standard color
* information etc).
* @param x_domainAxis the domain (horizontal) axis.
* @param x_rangeAxis the range (vertical) axis.
* @param x_positive indicates if the polygon is positive (true) or
* negative (false).
* @param x_xValues a linked list of the x values (expects values to be
* of type Double).
* @param x_yValues a linked list of the y values (expects values to be
* of type Double).
*/
private void createPolygon(Graphics2D x_graphics, Rectangle2D x_dataArea, XYPlot x_plot, ValueAxis x_domainAxis, ValueAxis x_rangeAxis, boolean x_positive, LinkedList x_xValues, LinkedList x_yValues) {
PlotOrientation l_orientation = x_plot.getOrientation();
RectangleEdge l_domainAxisLocation = x_plot.getDomainAxisEdge();
RectangleEdge l_rangeAxisLocation = x_plot.getRangeAxisEdge();
Object[] l_xValues = x_xValues.toArray();
Object[] l_yValues = x_yValues.toArray();
GeneralPath l_path = new GeneralPath();
if (PlotOrientation.VERTICAL == l_orientation) {
double l_x = x_domainAxis.valueToJava2D(((Double) l_xValues[0]).doubleValue(), x_dataArea, l_domainAxisLocation);
if (this.roundXCoordinates) {
l_x = Math.rint(l_x);
}
double l_y = x_rangeAxis.valueToJava2D(((Double) l_yValues[0]).doubleValue(), x_dataArea, l_rangeAxisLocation);
l_path.moveTo((float) l_x, (float) l_y);
for (int i = 1; i < l_xValues.length; i++) {
l_x = x_domainAxis.valueToJava2D(((Double) l_xValues[i]).doubleValue(), x_dataArea, l_domainAxisLocation);
if (this.roundXCoordinates) {
l_x = Math.rint(l_x);
}
l_y = x_rangeAxis.valueToJava2D(((Double) l_yValues[i]).doubleValue(), x_dataArea, l_rangeAxisLocation);
l_path.lineTo((float) l_x, (float) l_y);
}
l_path.closePath();
} else {
double l_x = x_domainAxis.valueToJava2D(((Double) l_xValues[0]).doubleValue(), x_dataArea, l_domainAxisLocation);
if (this.roundXCoordinates) {
l_x = Math.rint(l_x);
}
double l_y = x_rangeAxis.valueToJava2D(((Double) l_yValues[0]).doubleValue(), x_dataArea, l_rangeAxisLocation);
l_path.moveTo((float) l_y, (float) l_x);
for (int i = 1; i < l_xValues.length; i++) {
l_x = x_domainAxis.valueToJava2D(((Double) l_xValues[i]).doubleValue(), x_dataArea, l_domainAxisLocation);
if (this.roundXCoordinates) {
l_x = Math.rint(l_x);
}
l_y = x_rangeAxis.valueToJava2D(((Double) l_yValues[i]).doubleValue(), x_dataArea, l_rangeAxisLocation);
l_path.lineTo((float) l_y, (float) l_x);
}
l_path.closePath();
}
if (l_path.intersects(x_dataArea)) {
x_graphics.setPaint(x_positive ? getPositivePaint() : getNegativePaint());
x_graphics.fill(l_path);
}
}
Aggregations