Search in sources :

Example 1 with LookupPaintScale

use of org.jfree.chart.renderer.LookupPaintScale in project SIMVA-SoS by SESoS.

the class XYBlockRendererTest method testCloning.

/**
 * Confirm that cloning works.
 */
@Test
public void testCloning() throws CloneNotSupportedException {
    XYBlockRenderer r1 = new XYBlockRenderer();
    LookupPaintScale scale1 = new LookupPaintScale();
    r1.setPaintScale(scale1);
    XYBlockRenderer r2 = (XYBlockRenderer) r1.clone();
    assertTrue(r1 != r2);
    assertTrue(r1.getClass() == r2.getClass());
    assertTrue(r1.equals(r2));
    // check independence
    scale1.add(0.5, Color.red);
    assertFalse(r1.equals(r2));
    LookupPaintScale scale2 = (LookupPaintScale) r2.getPaintScale();
    scale2.add(0.5, Color.red);
    assertTrue(r1.equals(r2));
}
Also used : LookupPaintScale(org.jfree.chart.renderer.LookupPaintScale) Test(org.junit.Test)

Example 2 with LookupPaintScale

use of org.jfree.chart.renderer.LookupPaintScale 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;
}
Also used : XYBlockPixelSizeRenderer(net.sf.mzmine.chartbasics.chartutils.XYBlockPixelSizeRenderer) PaintScaleLegend(org.jfree.chart.title.PaintScaleLegend) NumberAxis(org.jfree.chart.axis.NumberAxis) Color(java.awt.Color) BlockBorder(org.jfree.chart.block.BlockBorder) Paint(java.awt.Paint) Paint(java.awt.Paint) XYPlot(org.jfree.chart.plot.XYPlot) RectangleInsets(org.jfree.chart.ui.RectangleInsets) ItemLabelPosition(org.jfree.chart.labels.ItemLabelPosition) LookupPaintScale(org.jfree.chart.renderer.LookupPaintScale) ScatterPlotToolTipGenerator(net.sf.mzmine.chartbasics.chartutils.ScatterPlotToolTipGenerator) NameItemLabelGenerator(net.sf.mzmine.chartbasics.chartutils.NameItemLabelGenerator)

Example 3 with LookupPaintScale

use of org.jfree.chart.renderer.LookupPaintScale in project SIMVA-SoS by SESoS.

the class PaintScaleLegendTest method testEquals.

/**
 * Test that the equals() method distinguishes all fields.
 */
@Test
public void testEquals() {
    // default instances
    PaintScaleLegend l1 = new PaintScaleLegend(new GrayPaintScale(), new NumberAxis("X"));
    PaintScaleLegend l2 = new PaintScaleLegend(new GrayPaintScale(), new NumberAxis("X"));
    assertTrue(l1.equals(l2));
    assertTrue(l2.equals(l1));
    // paintScale
    l1.setScale(new LookupPaintScale());
    assertFalse(l1.equals(l2));
    l2.setScale(new LookupPaintScale());
    assertTrue(l1.equals(l2));
    // axis
    l1.setAxis(new NumberAxis("Axis 2"));
    assertFalse(l1.equals(l2));
    l2.setAxis(new NumberAxis("Axis 2"));
    assertTrue(l1.equals(l2));
    // axisLocation
    l1.setAxisLocation(AxisLocation.BOTTOM_OR_RIGHT);
    assertFalse(l1.equals(l2));
    l2.setAxisLocation(AxisLocation.BOTTOM_OR_RIGHT);
    assertTrue(l1.equals(l2));
    // axisOffset
    l1.setAxisOffset(99.0);
    assertFalse(l1.equals(l2));
    l2.setAxisOffset(99.0);
    assertTrue(l1.equals(l2));
    // stripWidth
    l1.setStripWidth(99.0);
    assertFalse(l1.equals(l2));
    l2.setStripWidth(99.0);
    assertTrue(l1.equals(l2));
    // stripOutlineVisible
    l1.setStripOutlineVisible(!l1.isStripOutlineVisible());
    assertFalse(l1.equals(l2));
    l2.setStripOutlineVisible(l1.isStripOutlineVisible());
    assertTrue(l1.equals(l2));
    // stripOutlinePaint
    l1.setStripOutlinePaint(new GradientPaint(1.0f, 2.0f, Color.red, 3.0f, 4.0f, Color.blue));
    assertFalse(l1.equals(l2));
    l2.setStripOutlinePaint(new GradientPaint(1.0f, 2.0f, Color.red, 3.0f, 4.0f, Color.blue));
    assertTrue(l1.equals(l2));
    // stripOutlineStroke
    l1.setStripOutlineStroke(new BasicStroke(1.1f));
    assertFalse(l1.equals(l2));
    l2.setStripOutlineStroke(new BasicStroke(1.1f));
    assertTrue(l1.equals(l2));
    // backgroundPaint
    l1.setBackgroundPaint(new GradientPaint(1.0f, 2.0f, Color.red, 3.0f, 4.0f, Color.blue));
    assertFalse(l1.equals(l2));
    l2.setBackgroundPaint(new GradientPaint(1.0f, 2.0f, Color.red, 3.0f, 4.0f, Color.blue));
    assertTrue(l1.equals(l2));
    l1.setSubdivisionCount(99);
    assertFalse(l1.equals(l2));
    l2.setSubdivisionCount(99);
    assertTrue(l1.equals(l2));
}
Also used : BasicStroke(java.awt.BasicStroke) NumberAxis(org.jfree.chart.axis.NumberAxis) GradientPaint(java.awt.GradientPaint) LookupPaintScale(org.jfree.chart.renderer.LookupPaintScale) GrayPaintScale(org.jfree.chart.renderer.GrayPaintScale) Test(org.junit.Test)

Example 4 with LookupPaintScale

use of org.jfree.chart.renderer.LookupPaintScale in project SIMVA-SoS by SESoS.

the class XYShapeRendererTest method testEquals.

/**
 * Some checks for the equals() method.
 */
@Test
public void testEquals() {
    XYShapeRenderer r1 = new XYShapeRenderer();
    XYShapeRenderer r2 = new XYShapeRenderer();
    assertTrue(r1.equals(r2));
    assertTrue(r2.equals(r1));
    r1.setPaintScale(new LookupPaintScale(1.0, 2.0, Color.white));
    assertFalse(r1.equals(r2));
    r2.setPaintScale(new LookupPaintScale(1.0, 2.0, Color.white));
    assertTrue(r1.equals(r2));
    r1.setDrawOutlines(true);
    assertFalse(r1.equals(r2));
    r2.setDrawOutlines(true);
    assertTrue(r1.equals(r2));
    r1.setUseOutlinePaint(false);
    assertFalse(r1.equals(r2));
    r2.setUseOutlinePaint(false);
    assertTrue(r1.equals(r2));
    r1.setUseFillPaint(true);
    assertFalse(r1.equals(r2));
    r2.setUseFillPaint(true);
    assertTrue(r1.equals(r2));
    r1.setGuideLinesVisible(true);
    assertFalse(r1.equals(r2));
    r2.setGuideLinesVisible(true);
    assertTrue(r1.equals(r2));
    r1.setGuideLinePaint(Color.red);
    assertFalse(r1.equals(r2));
    r2.setGuideLinePaint(Color.red);
    assertTrue(r1.equals(r2));
}
Also used : LookupPaintScale(org.jfree.chart.renderer.LookupPaintScale) Test(org.junit.Test)

Example 5 with LookupPaintScale

use of org.jfree.chart.renderer.LookupPaintScale 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;
}
Also used : XYBlockPixelSizeRenderer(net.sf.mzmine.chartbasics.chartutils.XYBlockPixelSizeRenderer) PaintScaleLegend(org.jfree.chart.title.PaintScaleLegend) NumberAxis(org.jfree.chart.axis.NumberAxis) Color(java.awt.Color) BlockBorder(org.jfree.chart.block.BlockBorder) Paint(java.awt.Paint) Paint(java.awt.Paint) XYPlot(org.jfree.chart.plot.XYPlot) RectangleInsets(org.jfree.chart.ui.RectangleInsets) ItemLabelPosition(org.jfree.chart.labels.ItemLabelPosition) LookupPaintScale(org.jfree.chart.renderer.LookupPaintScale) ScatterPlotToolTipGenerator(net.sf.mzmine.chartbasics.chartutils.ScatterPlotToolTipGenerator) NameItemLabelGenerator(net.sf.mzmine.chartbasics.chartutils.NameItemLabelGenerator)

Aggregations

LookupPaintScale (org.jfree.chart.renderer.LookupPaintScale)5 NumberAxis (org.jfree.chart.axis.NumberAxis)3 Test (org.junit.Test)3 Color (java.awt.Color)2 Paint (java.awt.Paint)2 NameItemLabelGenerator (net.sf.mzmine.chartbasics.chartutils.NameItemLabelGenerator)2 ScatterPlotToolTipGenerator (net.sf.mzmine.chartbasics.chartutils.ScatterPlotToolTipGenerator)2 XYBlockPixelSizeRenderer (net.sf.mzmine.chartbasics.chartutils.XYBlockPixelSizeRenderer)2 BlockBorder (org.jfree.chart.block.BlockBorder)2 ItemLabelPosition (org.jfree.chart.labels.ItemLabelPosition)2 XYPlot (org.jfree.chart.plot.XYPlot)2 PaintScaleLegend (org.jfree.chart.title.PaintScaleLegend)2 RectangleInsets (org.jfree.chart.ui.RectangleInsets)2 BasicStroke (java.awt.BasicStroke)1 GradientPaint (java.awt.GradientPaint)1 GrayPaintScale (org.jfree.chart.renderer.GrayPaintScale)1