use of org.jfree.chart.block.BlockBorder in project CS3243-Project by Kangqing-Qiu.
the class MatlabChart method legend.
public void legend(String position) {
CheckExists();
legend.setItemFont(font);
legend.setBackgroundPaint(Color.WHITE);
legend.setFrame(new BlockBorder(Color.BLACK));
if (position.toLowerCase().equals("northoutside")) {
legend.setPosition(RectangleEdge.TOP);
chart.addLegend(legend);
} else if (position.toLowerCase().equals("eastoutside")) {
legend.setPosition(RectangleEdge.RIGHT);
chart.addLegend(legend);
} else if (position.toLowerCase().equals("southoutside")) {
legend.setPosition(RectangleEdge.BOTTOM);
chart.addLegend(legend);
} else if (position.toLowerCase().equals("westoutside")) {
legend.setPosition(RectangleEdge.LEFT);
chart.addLegend(legend);
} else if (position.toLowerCase().equals("north")) {
legend.setPosition(RectangleEdge.TOP);
XYTitleAnnotation ta = new XYTitleAnnotation(0.50, 0.98, legend, RectangleAnchor.TOP);
chart.getXYPlot().addAnnotation(ta);
} else if (position.toLowerCase().equals("northeast")) {
legend.setPosition(RectangleEdge.TOP);
XYTitleAnnotation ta = new XYTitleAnnotation(0.98, 0.98, legend, RectangleAnchor.TOP_RIGHT);
chart.getXYPlot().addAnnotation(ta);
} else if (position.toLowerCase().equals("east")) {
legend.setPosition(RectangleEdge.RIGHT);
XYTitleAnnotation ta = new XYTitleAnnotation(0.98, 0.50, legend, RectangleAnchor.RIGHT);
chart.getXYPlot().addAnnotation(ta);
} else if (position.toLowerCase().equals("southeast")) {
legend.setPosition(RectangleEdge.BOTTOM);
XYTitleAnnotation ta = new XYTitleAnnotation(0.98, 0.02, legend, RectangleAnchor.BOTTOM_RIGHT);
chart.getXYPlot().addAnnotation(ta);
} else if (position.toLowerCase().equals("south")) {
legend.setPosition(RectangleEdge.BOTTOM);
XYTitleAnnotation ta = new XYTitleAnnotation(0.50, 0.02, legend, RectangleAnchor.BOTTOM);
chart.getXYPlot().addAnnotation(ta);
} else if (position.toLowerCase().equals("southwest")) {
legend.setPosition(RectangleEdge.BOTTOM);
XYTitleAnnotation ta = new XYTitleAnnotation(0.02, 0.02, legend, RectangleAnchor.BOTTOM_LEFT);
chart.getXYPlot().addAnnotation(ta);
} else if (position.toLowerCase().equals("west")) {
legend.setPosition(RectangleEdge.LEFT);
XYTitleAnnotation ta = new XYTitleAnnotation(0.02, 0.50, legend, RectangleAnchor.LEFT);
chart.getXYPlot().addAnnotation(ta);
} else if (position.toLowerCase().equals("northwest")) {
legend.setPosition(RectangleEdge.TOP);
XYTitleAnnotation ta = new XYTitleAnnotation(0.02, 0.98, legend, RectangleAnchor.TOP_LEFT);
chart.getXYPlot().addAnnotation(ta);
}
}
use of org.jfree.chart.block.BlockBorder in project mzmine2 by mzmine.
the class KendrickMassPlotTask method create3DKendrickMassPlot.
/**
* create 3D Kendrick mass plot
*/
private JFreeChart create3DKendrickMassPlot() {
logger.info("Creating new 3D chart instance");
appliedSteps++;
// load dataseta
dataset3D = new KendrickMassPlotXYZDataset(parameterSet);
// copy and sort z-Values for min and max of the paint scale
double[] copyZValues = new double[dataset3D.getItemCount(0)];
for (int i = 0; i < dataset3D.getItemCount(0); i++) {
copyZValues[i] = dataset3D.getZValue(0, i);
}
Arrays.sort(copyZValues);
// get index in accordance to percentile windows
int minScaleIndex = 0;
int maxScaleIndex = copyZValues.length - 1;
double min = 0;
double max = 0;
if (zAxisScaleType.equals("percentile")) {
minScaleIndex = (int) Math.ceil(copyZValues.length * (zScaleRange.lowerEndpoint() / 100));
maxScaleIndex = copyZValues.length - (int) (Math.ceil(copyZValues.length * ((100 - zScaleRange.upperEndpoint()) / 100)));
if (zScaleRange.upperEndpoint() == 100) {
maxScaleIndex = copyZValues.length - 1;
}
if (zScaleRange.lowerEndpoint() == 0) {
minScaleIndex = 0;
}
min = copyZValues[minScaleIndex];
max = copyZValues[maxScaleIndex];
}
if (zAxisScaleType.equals("custom")) {
min = zScaleRange.lowerEndpoint();
max = zScaleRange.upperEndpoint();
}
Paint[] contourColors = XYBlockPixelSizePaintScales.getPaintColors(zAxisScaleType, zScaleRange, paintScaleStyle);
LookupPaintScale scale = null;
scale = new LookupPaintScale(copyZValues[0], copyZValues[copyZValues.length - 1], new Color(0, 0, 0));
double[] scaleValues = new double[contourColors.length];
double delta = (max - min) / (contourColors.length - 1);
double value = min;
for (int i = 0; i < contourColors.length; i++) {
scale.add(value, contourColors[i]);
scaleValues[i] = value;
value = value + delta;
}
// create chart
chart = ChartFactory.createScatterPlot(title, xAxisLabel, yAxisLabel, dataset3D, PlotOrientation.VERTICAL, true, true, true);
XYPlot plot = chart.getXYPlot();
// set axis
NumberAxis domain = (NumberAxis) plot.getDomainAxis();
NumberAxis range = (NumberAxis) plot.getRangeAxis();
range.setRange(0, 1);
if (xAxisLabel.contains("KMD")) {
domain.setRange(0, 1);
}
// set renderer
XYBlockPixelSizeRenderer renderer = new XYBlockPixelSizeRenderer();
appliedSteps++;
// Set paint scale
renderer.setPaintScale(scale);
ScatterPlotToolTipGenerator tooltipGenerator = new ScatterPlotToolTipGenerator(xAxisLabel, yAxisLabel, zAxisLabel, rows);
renderer.setSeriesToolTipGenerator(0, tooltipGenerator);
// set item label generator
NameItemLabelGenerator generator = new NameItemLabelGenerator(rows);
renderer.setDefaultItemLabelGenerator(generator);
renderer.setDefaultItemLabelsVisible(false);
renderer.setDefaultItemLabelFont(legendFont);
renderer.setDefaultPositiveItemLabelPosition(new ItemLabelPosition(ItemLabelAnchor.CENTER, TextAnchor.TOP_RIGHT, TextAnchor.TOP_RIGHT, -45), true);
plot.setRenderer(renderer);
plot.setBackgroundPaint(Color.white);
plot.setRangeGridlinePaint(Color.white);
plot.setAxisOffset(new RectangleInsets(5, 5, 5, 5));
plot.setOutlinePaint(Color.black);
plot.setBackgroundPaint(Color.white);
plot.setDomainCrosshairPaint(Color.GRAY);
plot.setRangeCrosshairPaint(Color.GRAY);
plot.setDomainCrosshairVisible(true);
plot.setRangeCrosshairVisible(true);
// Legend
NumberAxis scaleAxis = new NumberAxis(zAxisLabel);
scaleAxis.setRange(min, max);
scaleAxis.setAxisLinePaint(Color.white);
scaleAxis.setTickMarkPaint(Color.white);
PaintScaleLegend legend = new PaintScaleLegend(scale, scaleAxis);
legend.setStripOutlineVisible(false);
legend.setAxisLocation(AxisLocation.BOTTOM_OR_LEFT);
legend.setAxisOffset(5.0);
legend.setMargin(new RectangleInsets(5, 5, 5, 5));
legend.setFrame(new BlockBorder(Color.white));
legend.setPadding(new RectangleInsets(10, 10, 10, 10));
legend.setStripWidth(10);
legend.setPosition(RectangleEdge.LEFT);
legend.getAxis().setLabelFont(legendFont);
legend.getAxis().setTickLabelFont(legendFont);
chart.addSubtitle(legend);
return chart;
}
use of org.jfree.chart.block.BlockBorder in project SIMVA-SoS by SESoS.
the class CompositeTitleTest method testEquals.
/**
* Check that the equals() method distinguishes all fields.
*/
@Test
public void testEquals() {
CompositeTitle t1 = new CompositeTitle(new BlockContainer());
CompositeTitle t2 = new CompositeTitle(new BlockContainer());
assertEquals(t1, t2);
assertEquals(t2, t1);
// margin
t1.setMargin(new RectangleInsets(1.0, 2.0, 3.0, 4.0));
assertFalse(t1.equals(t2));
t2.setMargin(new RectangleInsets(1.0, 2.0, 3.0, 4.0));
assertTrue(t1.equals(t2));
// border
t1.setBorder(new BlockBorder(Color.red));
assertFalse(t1.equals(t2));
t2.setBorder(new BlockBorder(Color.red));
assertTrue(t1.equals(t2));
// padding
t1.setPadding(new RectangleInsets(1.0, 2.0, 3.0, 4.0));
assertFalse(t1.equals(t2));
t2.setPadding(new RectangleInsets(1.0, 2.0, 3.0, 4.0));
assertTrue(t1.equals(t2));
// contained titles
t1.getContainer().add(new TextTitle("T1"));
assertFalse(t1.equals(t2));
t2.getContainer().add(new TextTitle("T1"));
assertTrue(t1.equals(t2));
t1.setBackgroundPaint(new GradientPaint(1.0f, 2.0f, Color.red, 3.0f, 4.0f, Color.yellow));
assertFalse(t1.equals(t2));
t2.setBackgroundPaint(new GradientPaint(1.0f, 2.0f, Color.red, 3.0f, 4.0f, Color.yellow));
assertTrue(t1.equals(t2));
}
use of org.jfree.chart.block.BlockBorder in project mzmine2 by mzmine.
the class VanKrevelenDiagramTask method create3DVanKrevelenDiagram.
/**
* create 3D Van Krevelen Diagram chart
*/
private JFreeChart create3DVanKrevelenDiagram() {
logger.info("Creating new 3D chart instance");
appliedSteps++;
// load data set
VanKrevelenDiagramXYZDataset dataset3D = new VanKrevelenDiagramXYZDataset(zAxisLabel, filteredRows);
// copy and sort z-Values for min and max of the paint scale
double[] copyZValues = new double[dataset3D.getItemCount(0)];
for (int i = 0; i < dataset3D.getItemCount(0); i++) {
copyZValues[i] = dataset3D.getZValue(0, i);
}
Arrays.sort(copyZValues);
// get index in accordance to percentile windows
int minScaleIndex = 0;
int maxScaleIndex = copyZValues.length - 1;
double min = 0;
double max = 0;
if (zAxisScaleType.equals("percentile")) {
minScaleIndex = (int) Math.floor(copyZValues.length * (zScaleRange.lowerEndpoint() / 100));
maxScaleIndex = copyZValues.length - (int) (Math.ceil(copyZValues.length * ((100 - zScaleRange.upperEndpoint()) / 100)));
if (zScaleRange.upperEndpoint() == 100) {
maxScaleIndex = copyZValues.length - 1;
}
if (zScaleRange.lowerEndpoint() == 0) {
minScaleIndex = 0;
}
min = copyZValues[minScaleIndex];
max = copyZValues[maxScaleIndex];
}
if (zAxisScaleType.equals("custom")) {
min = zScaleRange.lowerEndpoint();
max = zScaleRange.upperEndpoint();
}
// create paint scale for third dimension
Paint[] contourColors = XYBlockPixelSizePaintScales.getPaintColors(zAxisScaleType, zScaleRange, paintScaleStyle);
LookupPaintScale scale = null;
scale = new LookupPaintScale(copyZValues[0], copyZValues[copyZValues.length - 1], new Color(0, 0, 0));
double[] scaleValues = new double[contourColors.length];
double delta = (max - min) / (contourColors.length - 1);
double value = min;
for (int i = 0; i < contourColors.length; i++) {
scale.add(value, contourColors[i]);
scaleValues[i] = value;
value = value + delta;
}
// create chart
chart = ChartFactory.createScatterPlot(title, "O/C", "H/C", dataset3D, PlotOrientation.VERTICAL, true, true, false);
// set renderer
XYBlockPixelSizeRenderer renderer = new XYBlockPixelSizeRenderer();
XYPlot plot = chart.getXYPlot();
appliedSteps++;
renderer.setPaintScale(scale);
double maxX = plot.getDomainAxis().getRange().getUpperBound();
double maxY = plot.getRangeAxis().getRange().getUpperBound();
renderer.setBlockWidth(0.001);
renderer.setBlockHeight(renderer.getBlockWidth() / (maxX / maxY));
// set tooltip generator
ScatterPlotToolTipGenerator tooltipGenerator = new ScatterPlotToolTipGenerator("O/C", "H/C", zAxisLabel, filteredRows);
renderer.setSeriesToolTipGenerator(0, tooltipGenerator);
renderer.setDefaultPositiveItemLabelPosition(new ItemLabelPosition(ItemLabelAnchor.CENTER, TextAnchor.TOP_RIGHT, TextAnchor.TOP_RIGHT, -45), true);
// set item label generator
NameItemLabelGenerator generator = new NameItemLabelGenerator(filteredRows);
renderer.setDefaultItemLabelGenerator(generator);
renderer.setDefaultItemLabelsVisible(false);
renderer.setDefaultItemLabelFont(legendFont);
plot.setRenderer(renderer);
plot.setBackgroundPaint(Color.white);
plot.setRangeGridlinePaint(Color.white);
plot.setAxisOffset(new RectangleInsets(5, 5, 5, 5));
plot.setOutlinePaint(Color.black);
plot.setBackgroundPaint(Color.white);
plot.setDomainCrosshairPaint(Color.GRAY);
plot.setRangeCrosshairPaint(Color.GRAY);
plot.setDomainCrosshairVisible(true);
plot.setRangeCrosshairVisible(true);
// Legend
NumberAxis scaleAxis = new NumberAxis(zAxisLabel);
scaleAxis.setRange(min, max);
scaleAxis.setAxisLinePaint(Color.white);
scaleAxis.setTickMarkPaint(Color.white);
PaintScaleLegend legend = new PaintScaleLegend(scale, scaleAxis);
legend.setStripOutlineVisible(false);
legend.setAxisLocation(AxisLocation.BOTTOM_OR_LEFT);
legend.setAxisOffset(5.0);
legend.setMargin(new RectangleInsets(5, 5, 5, 5));
legend.setFrame(new BlockBorder(Color.white));
legend.setPadding(new RectangleInsets(10, 10, 10, 10));
legend.setStripWidth(10);
legend.setPosition(RectangleEdge.LEFT);
legend.getAxis().setLabelFont(legendFont);
legend.getAxis().setTickLabelFont(legendFont);
chart.addSubtitle(legend);
appliedSteps++;
return chart;
}
Aggregations