Search in sources :

Example 1 with NameItemLabelGenerator

use of net.sf.mzmine.chartbasics.chartutils.NameItemLabelGenerator 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 2 with NameItemLabelGenerator

use of net.sf.mzmine.chartbasics.chartutils.NameItemLabelGenerator 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)

Example 3 with NameItemLabelGenerator

use of net.sf.mzmine.chartbasics.chartutils.NameItemLabelGenerator in project mzmine2 by mzmine.

the class VanKrevelenDiagramTask method create2DVanKrevelenDiagram.

/**
 * create 2D Van Krevelen Diagram chart
 */
private JFreeChart create2DVanKrevelenDiagram() {
    logger.info("Creating new 2D chart instance");
    appliedSteps++;
    // load dataset
    VanKrevelenDiagramXYDataset dataset2D = new VanKrevelenDiagramXYDataset(filteredRows);
    // create chart
    chart = ChartFactory.createScatterPlot(title, "O/C", "H/C", dataset2D, PlotOrientation.VERTICAL, true, true, false);
    XYPlot plot = (XYPlot) chart.getPlot();
    plot.setBackgroundPaint(Color.WHITE);
    plot.setDomainCrosshairPaint(Color.GRAY);
    plot.setRangeCrosshairPaint(Color.GRAY);
    plot.setDomainCrosshairVisible(true);
    plot.setRangeCrosshairVisible(true);
    appliedSteps++;
    // set renderer
    XYBlockPixelSizeRenderer renderer = new XYBlockPixelSizeRenderer();
    // calc block sizes
    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);
    plot.setRenderer(renderer);
    // set item label generator
    NameItemLabelGenerator generator = new NameItemLabelGenerator(filteredRows);
    renderer.setDefaultItemLabelGenerator(generator);
    renderer.setDefaultItemLabelsVisible(false);
    renderer.setDefaultItemLabelFont(legendFont);
    renderer.setDefaultPositiveItemLabelPosition(new ItemLabelPosition(ItemLabelAnchor.CENTER, TextAnchor.TOP_RIGHT, TextAnchor.TOP_RIGHT, -45), true);
    return chart;
}
Also used : XYBlockPixelSizeRenderer(net.sf.mzmine.chartbasics.chartutils.XYBlockPixelSizeRenderer) XYPlot(org.jfree.chart.plot.XYPlot) ItemLabelPosition(org.jfree.chart.labels.ItemLabelPosition) ScatterPlotToolTipGenerator(net.sf.mzmine.chartbasics.chartutils.ScatterPlotToolTipGenerator) NameItemLabelGenerator(net.sf.mzmine.chartbasics.chartutils.NameItemLabelGenerator)

Example 4 with NameItemLabelGenerator

use of net.sf.mzmine.chartbasics.chartutils.NameItemLabelGenerator in project mzmine2 by mzmine.

the class KendrickMassPlotTask method create2DKendrickMassPlot.

/**
 * create 2D Kendrick mass plot
 */
private JFreeChart create2DKendrickMassPlot() {
    if (zAxisLabel.equals("none")) {
        logger.info("Creating new 2D chart instance");
        appliedSteps++;
        // load dataset
        dataset2D = new KendrickMassPlotXYDataset(parameterSet);
        // create chart
        chart = ChartFactory.createScatterPlot(title, xAxisLabel, yAxisLabel, dataset2D, PlotOrientation.VERTICAL, true, true, true);
        XYPlot plot = (XYPlot) chart.getPlot();
        plot.setBackgroundPaint(Color.WHITE);
        plot.setDomainCrosshairPaint(Color.GRAY);
        plot.setRangeCrosshairPaint(Color.GRAY);
        plot.setDomainCrosshairVisible(true);
        plot.setRangeCrosshairVisible(true);
        appliedSteps++;
        // 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();
        // set tooltip generator
        ScatterPlotToolTipGenerator tooltipGenerator = new ScatterPlotToolTipGenerator(xAxisLabel, yAxisLabel, zAxisLabel, rows);
        renderer.setSeriesToolTipGenerator(0, tooltipGenerator);
        plot.setRenderer(renderer);
        // 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);
    }
    return chart;
}
Also used : XYBlockPixelSizeRenderer(net.sf.mzmine.chartbasics.chartutils.XYBlockPixelSizeRenderer) NumberAxis(org.jfree.chart.axis.NumberAxis) XYPlot(org.jfree.chart.plot.XYPlot) ItemLabelPosition(org.jfree.chart.labels.ItemLabelPosition) ScatterPlotToolTipGenerator(net.sf.mzmine.chartbasics.chartutils.ScatterPlotToolTipGenerator) NameItemLabelGenerator(net.sf.mzmine.chartbasics.chartutils.NameItemLabelGenerator)

Aggregations

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