use of org.jfree.chart.title.PaintScaleLegend in project SIMVA-SoS by SESoS.
the class StandardChartTheme method applyToTitle.
/**
* Applies the attributes of this theme to the specified title.
*
* @param title the title.
*/
protected void applyToTitle(Title title) {
if (title instanceof TextTitle) {
TextTitle tt = (TextTitle) title;
tt.setFont(this.largeFont);
tt.setPaint(this.subtitlePaint);
} else if (title instanceof LegendTitle) {
LegendTitle lt = (LegendTitle) title;
if (lt.getBackgroundPaint() != null) {
lt.setBackgroundPaint(this.legendBackgroundPaint);
}
lt.setItemFont(this.regularFont);
lt.setItemPaint(this.legendItemPaint);
if (lt.getWrapper() != null) {
applyToBlockContainer(lt.getWrapper());
}
} else if (title instanceof PaintScaleLegend) {
PaintScaleLegend psl = (PaintScaleLegend) title;
psl.setBackgroundPaint(this.legendBackgroundPaint);
ValueAxis axis = psl.getAxis();
if (axis != null) {
applyToValueAxis(axis);
}
} else if (title instanceof CompositeTitle) {
CompositeTitle ct = (CompositeTitle) title;
BlockContainer bc = ct.getContainer();
List blocks = bc.getBlocks();
Iterator iterator = blocks.iterator();
while (iterator.hasNext()) {
Block b = (Block) iterator.next();
if (b instanceof Title) {
applyToTitle((Title) b);
}
}
}
}
use of org.jfree.chart.title.PaintScaleLegend 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.title.PaintScaleLegend in project mzmine2 by mzmine.
the class KendrickMassPlotWindow method actionPerformed.
@Override
public void actionPerformed(ActionEvent event) {
String command = event.getActionCommand();
if (command.equals("TOGGLE_BLOCK_SIZE")) {
XYPlot plot = chart.getXYPlot();
XYBlockPixelSizeRenderer renderer = (XYBlockPixelSizeRenderer) plot.getRenderer();
int height = (int) renderer.getBlockHeightPixel();
if (height == 1) {
height++;
} else if (height == 5) {
height = 1;
} else if (height < 5 && height != 1) {
height++;
}
renderer.setBlockHeightPixel(height);
renderer.setBlockWidthPixel(height);
}
if (command.equals("TOGGLE_BACK_COLOR")) {
XYPlot plot = chart.getXYPlot();
if (plot.getBackgroundPaint() == Color.WHITE) {
plot.setBackgroundPaint(Color.BLACK);
} else {
plot.setBackgroundPaint(Color.WHITE);
}
}
if (command.equals("TOGGLE_GRID")) {
XYPlot plot = chart.getXYPlot();
if (plot.getDomainGridlinePaint() == Color.BLACK) {
plot.setDomainGridlinePaint(Color.WHITE);
plot.setRangeGridlinePaint(Color.WHITE);
} else {
plot.setDomainGridlinePaint(Color.BLACK);
plot.setRangeGridlinePaint(Color.BLACK);
}
}
if (command.equals("TOGGLE_ANNOTATIONS")) {
XYPlot plot = chart.getXYPlot();
XYBlockPixelSizeRenderer renderer = (XYBlockPixelSizeRenderer) plot.getRenderer();
Boolean itemNameVisible = renderer.getDefaultItemLabelsVisible();
if (itemNameVisible == false) {
renderer.setDefaultItemLabelsVisible(true);
} else {
renderer.setDefaultItemLabelsVisible(false);
}
if (plot.getBackgroundPaint() == Color.BLACK) {
renderer.setDefaultItemLabelPaint(Color.WHITE);
} else {
renderer.setDefaultItemLabelPaint(Color.BLACK);
}
}
// y axis commands
if (command.equals("SHIFT_KMD_UP_Y")) {
Double shiftValue = 0.01;
yAxisShift = yAxisShift + shiftValue;
XYPlot plot = chart.getXYPlot();
kendrickVariableChanged(plot);
}
if (command.equals("SHIFT_KMD_DOWN_Y")) {
Double shiftValue = -0.01;
yAxisShift = yAxisShift + shiftValue;
XYPlot plot = chart.getXYPlot();
kendrickVariableChanged(plot);
}
if (command.equals("CHANGE_CHARGE_UP_Y")) {
yAxisCharge = yAxisCharge + 1;
XYPlot plot = chart.getXYPlot();
kendrickVariableChanged(plot);
}
if (command.equals("CHANGE_CHARGE_DOWN_Y")) {
if (yAxisCharge > 1) {
yAxisCharge = yAxisCharge - 1;
} else
yAxisCharge = 1;
XYPlot plot = chart.getXYPlot();
kendrickVariableChanged(plot);
}
if (command.equals("CHANGE_DIVISOR_UP_Y")) {
int minDivisor = getMinimumRecommendedDivisor(customYAxisKMBase);
int maxDivisor = getMaximumRecommendedDivisor(customYAxisKMBase);
if (yAxisDivisor >= minDivisor && yAxisDivisor < maxDivisor) {
yAxisDivisor++;
yAxisDivisor = checkDivisor(yAxisDivisor, useRKM_Y, customYAxisKMBase, true);
}
XYPlot plot = chart.getXYPlot();
kendrickVariableChanged(plot);
}
if (command.equals("CHANGE_DIVISOR_DOWN_Y")) {
int minDivisor = getMinimumRecommendedDivisor(customYAxisKMBase);
int maxDivisor = getMaximumRecommendedDivisor(customYAxisKMBase);
if (yAxisDivisor > minDivisor && yAxisDivisor <= maxDivisor) {
yAxisDivisor--;
yAxisDivisor = checkDivisor(yAxisDivisor, useRKM_Y, customYAxisKMBase, false);
}
XYPlot plot = chart.getXYPlot();
kendrickVariableChanged(plot);
}
if (command.equals("TOGGLE_RKM_KMD_Y")) {
XYPlot plot = chart.getXYPlot();
if (useRKM_Y) {
useRKM_Y = false;
plot.getRangeAxis().setLabel("KMD(" + customYAxisKMBase + ")");
} else {
useRKM_Y = true;
// if the divisor is round(R) switch to round(R)-1 for RKM plot
yAxisDivisor = checkDivisor(yAxisDivisor, useRKM_Y, customYAxisKMBase, false);
plot.getRangeAxis().setLabel("RKM(" + customYAxisKMBase + ")");
}
kendrickVariableChanged(plot);
}
// x axis commands
if (command.equals("SHIFT_KMD_UP_X")) {
Double shiftValue = 0.01;
xAxisShift = xAxisShift + shiftValue;
XYPlot plot = chart.getXYPlot();
kendrickVariableChanged(plot);
}
if (command.equals("SHIFT_KMD_DOWN_X")) {
Double shiftValue = -0.01;
xAxisShift = xAxisShift + shiftValue;
XYPlot plot = chart.getXYPlot();
kendrickVariableChanged(plot);
}
if (command.equals("CHANGE_CHARGE_UP_X")) {
xAxisCharge = xAxisCharge + 1;
XYPlot plot = chart.getXYPlot();
kendrickVariableChanged(plot);
}
if (command.equals("CHANGE_CHARGE_DOWN_X")) {
if (xAxisCharge > 1) {
xAxisCharge = xAxisCharge - 1;
} else
xAxisCharge = 1;
XYPlot plot = chart.getXYPlot();
kendrickVariableChanged(plot);
}
if (command.equals("CHANGE_DIVISOR_UP_X")) {
int minDivisor = getMinimumRecommendedDivisor(customXAxisKMBase);
int maxDivisor = getMaximumRecommendedDivisor(customXAxisKMBase);
if (xAxisDivisor >= minDivisor && xAxisDivisor < maxDivisor) {
xAxisDivisor++;
xAxisDivisor = checkDivisor(xAxisDivisor, useRKM_X, customXAxisKMBase, true);
}
XYPlot plot = chart.getXYPlot();
kendrickVariableChanged(plot);
}
if (command.equals("CHANGE_DIVISOR_DOWN_X")) {
int minDivisor = getMinimumRecommendedDivisor(customXAxisKMBase);
int maxDivisor = getMaximumRecommendedDivisor(customXAxisKMBase);
if (xAxisDivisor > minDivisor && xAxisDivisor <= maxDivisor) {
xAxisDivisor--;
xAxisDivisor = checkDivisor(xAxisDivisor, useRKM_X, customXAxisKMBase, false);
}
XYPlot plot = chart.getXYPlot();
kendrickVariableChanged(plot);
}
if (command.equals("TOGGLE_RKM_KMD_X")) {
XYPlot plot = chart.getXYPlot();
if (useRKM_X) {
useRKM_X = false;
plot.getDomainAxis().setLabel("KMD(" + customXAxisKMBase + ")");
} else {
useRKM_X = true;
// if the divisor is round(R) switch to round(R)-1 for RKM plot
xAxisDivisor = checkDivisor(xAxisDivisor, useRKM_X, customXAxisKMBase, false);
plot.getDomainAxis().setLabel("RKM(" + customXAxisKMBase + ")");
}
kendrickVariableChanged(plot);
}
// z axis commands
if (command.equals("SHIFT_KMD_UP_Z")) {
Double shiftValue = 0.01;
zAxisShift = zAxisShift + shiftValue;
XYPlot plot = chart.getXYPlot();
kendrickVariableChanged(plot);
}
if (command.equals("SHIFT_KMD_DOWN_Z")) {
Double shiftValue = -0.01;
zAxisShift = zAxisShift + shiftValue;
XYPlot plot = chart.getXYPlot();
kendrickVariableChanged(plot);
}
if (command.equals("CHANGE_CHARGE_UP_Z")) {
zAxisCharge = zAxisCharge + 1;
XYPlot plot = chart.getXYPlot();
kendrickVariableChanged(plot);
}
if (command.equals("CHANGE_CHARGE_DOWN_Z")) {
if (zAxisCharge > 1) {
zAxisCharge = zAxisCharge - 1;
} else
zAxisCharge = 1;
XYPlot plot = chart.getXYPlot();
kendrickVariableChanged(plot);
}
if (command.equals("CHANGE_DIVISOR_UP_Z")) {
int minDivisor = getMinimumRecommendedDivisor(customZAxisKMBase);
int maxDivisor = getMaximumRecommendedDivisor(customZAxisKMBase);
if (zAxisDivisor >= minDivisor && zAxisDivisor < maxDivisor) {
zAxisDivisor++;
zAxisDivisor = checkDivisor(zAxisDivisor, useRKM_Z, customZAxisKMBase, true);
}
XYPlot plot = chart.getXYPlot();
kendrickVariableChanged(plot);
}
if (command.equals("CHANGE_DIVISOR_DOWN_Z")) {
int minDivisor = getMinimumRecommendedDivisor(customZAxisKMBase);
int maxDivisor = getMaximumRecommendedDivisor(customZAxisKMBase);
if (zAxisDivisor > minDivisor && zAxisDivisor <= maxDivisor) {
zAxisDivisor--;
zAxisDivisor = checkDivisor(zAxisDivisor, useRKM_Z, customZAxisKMBase, false);
}
XYPlot plot = chart.getXYPlot();
kendrickVariableChanged(plot);
}
if (command.equals("TOGGLE_RKM_KMD_Z")) {
XYPlot plot = chart.getXYPlot();
if (plot.getDataset() instanceof KendrickMassPlotXYZDataset) {
if (useRKM_Z) {
useRKM_Z = false;
PaintScaleLegend legend = (PaintScaleLegend) chart.getSubtitle(1);
legend.getAxis().setLabel("KMD(" + customZAxisKMBase + ")");
} else {
useRKM_Z = true;
// if the divisor is round(R) switch to round(R)-1 for RKM plot
zAxisDivisor = checkDivisor(zAxisDivisor, useRKM_Z, customZAxisKMBase, false);
PaintScaleLegend legend = (PaintScaleLegend) chart.getSubtitle(1);
legend.getAxis().setLabel("RKM(" + customZAxisKMBase + ")");
}
kendrickVariableChanged(plot);
}
}
}
use of org.jfree.chart.title.PaintScaleLegend in project spf4j by zolyfarkas.
the class Charts method createHeatJFreeChart.
@SuppressFBWarnings("CE_CLASS_ENVY")
public static JFreeChart createHeatJFreeChart(final String[] dsNames, final double[][] values, final long startTimeMillis, final long stepMillis, final String uom, final String chartName) {
final QuantizedXYZDatasetImpl dataSet = new QuantizedXYZDatasetImpl(dsNames, values, startTimeMillis, stepMillis);
NumberAxis xAxis = new NumberAxis("Time");
xAxis.setStandardTickUnits(dataSet.createXTickUnits());
xAxis.setLowerMargin(0);
xAxis.setUpperMargin(0);
xAxis.setVerticalTickLabels(true);
NumberAxis yAxis = new NumberAxis(uom);
yAxis.setStandardTickUnits(dataSet.createYTickUnits());
yAxis.setLowerMargin(0);
yAxis.setUpperMargin(0);
XYBlockRenderer renderer = new XYBlockRenderer();
PaintScale scale;
if (dataSet.getMinValue() >= dataSet.getMaxValue()) {
if (dataSet.getMinValue() == Double.POSITIVE_INFINITY) {
scale = new InverseGrayScale(0, 1);
} else {
scale = new InverseGrayScale(dataSet.getMinValue(), dataSet.getMaxValue() + 1);
}
} else {
scale = new InverseGrayScale(dataSet.getMinValue(), dataSet.getMaxValue());
}
renderer.setPaintScale(scale);
renderer.setBlockWidth(1);
renderer.setBlockHeight(1);
XYPlot plot = new XYPlot(dataSet, xAxis, yAxis, renderer);
plot.setBackgroundPaint(Color.white);
plot.setDomainGridlinesVisible(false);
plot.setRangeGridlinesVisible(false);
plot.setRangeMinorGridlinesVisible(false);
JFreeChart chart = new JFreeChart(chartName, plot);
PaintScaleLegend legend = new PaintScaleLegend(scale, new NumberAxis("Count"));
legend.setMargin(0, 5, 0, 5);
chart.addSubtitle(legend);
chart.removeLegend();
chart.setBackgroundPaint(Color.white);
return chart;
}
use of org.jfree.chart.title.PaintScaleLegend in project mzmine2 by mzmine.
the class ChartExportUtil method writeChartToJPEG.
public static void writeChartToJPEG(JFreeChart chart, ChartRenderingInfo info, int width, int height, File fileName, int resolution) throws IOException {
// Background color
Paint saved = chart.getBackgroundPaint();
if (((Color) saved).getAlpha() == 0) {
chart.setBackgroundPaint(Color.WHITE);
chart.setBackgroundImageAlpha(255);
if (chart.getLegend() != null)
chart.getLegend().setBackgroundPaint(Color.WHITE);
// legends and stuff
for (int i = 0; i < chart.getSubtitleCount(); i++) if (PaintScaleLegend.class.isAssignableFrom(chart.getSubtitle(i).getClass()))
((PaintScaleLegend) chart.getSubtitle(i)).setBackgroundPaint(Color.WHITE);
// apply bg
chart.getPlot().setBackgroundPaint(Color.WHITE);
}
//
if (resolution == 72)
writeChartToJPEG(chart, width, height, fileName);
else {
OutputStream out = new BufferedOutputStream(new FileOutputStream(fileName));
try {
BufferedImage image = paintScaledChartToBufferedImage(chart, info, out, width, height, resolution, BufferedImage.TYPE_INT_RGB);
EncoderUtil.writeBufferedImage(image, ImageFormat.JPEG, out, 1.f);
} finally {
out.close();
}
}
}
Aggregations