Search in sources :

Example 1 with BarChartColorRenderer

use of no.uib.jsparklines.renderers.util.BarChartColorRenderer in project peptide-shaker by compomics.

the class GOEAPanel method updateGoPlots.

/**
 * Update the GO plots.
 */
private void updateGoPlots() {
    this.setCursor(new java.awt.Cursor(java.awt.Cursor.WAIT_CURSOR));
    DefaultCategoryDataset frquencyPlotDataset = new DefaultCategoryDataset();
    DefaultCategoryDataset significancePlotDataset = new DefaultCategoryDataset();
    ArrayList<Color> significanceColors = new ArrayList<>();
    Double maxLog2Diff = 0.0;
    for (int i = 0; i < goMappingsTable.getRowCount(); i++) {
        boolean selected = (Boolean) goMappingsTable.getValueAt(i, goMappingsTable.getColumn("  ").getModelIndex());
        boolean significant = ((ValueAndBooleanDataPoint) goMappingsTable.getValueAt(i, goMappingsTable.getColumn("Log2 Diff").getModelIndex())).isSignificant();
        if (selected) {
            String goTerm = (String) goMappingsTable.getValueAt(i, goMappingsTable.getColumn("GO Term").getModelIndex());
            Double percentAll = (Double) goMappingsTable.getValueAt(i, goMappingsTable.getColumn("Frequency All (%)").getModelIndex());
            Double percentDataset = (Double) goMappingsTable.getValueAt(i, goMappingsTable.getColumn("Frequency Dataset (%)").getModelIndex());
            Double log2Diff = ((ValueAndBooleanDataPoint) goMappingsTable.getValueAt(i, goMappingsTable.getColumn("Log2 Diff").getModelIndex())).getValue();
            frquencyPlotDataset.addValue(percentAll, "All", goTerm);
            frquencyPlotDataset.addValue(percentDataset, "Dataset", goTerm);
            if (!log2Diff.isInfinite()) {
                significancePlotDataset.addValue(log2Diff, "Difference", goTerm);
            } else {
                significancePlotDataset.addValue(0, "Difference", goTerm);
            }
            if (significant) {
                if (log2Diff > 0) {
                    significanceColors.add(peptideShakerGUI.getSparklineColor());
                } else {
                    significanceColors.add(new Color(255, 51, 51));
                }
            } else {
                significanceColors.add(Color.lightGray);
            }
            if (!log2Diff.isInfinite() && Math.abs(log2Diff) > maxLog2Diff) {
                maxLog2Diff = Math.abs(log2Diff);
            }
        }
    }
    maxLog2Diff = Math.ceil(maxLog2Diff);
    JFreeChart distributionChart = ChartFactory.createBarChart(null, "GO Terms", "Frequency (%)", frquencyPlotDataset, PlotOrientation.VERTICAL, false, true, true);
    distributionChartPanel = new ChartPanel(distributionChart);
    ((CategoryPlot) distributionChartPanel.getChart().getPlot()).getDomainAxis().setCategoryLabelPositions(CategoryLabelPositions.UP_90);
    BarRenderer3D renderer = new BarRenderer3D(0, 0);
    renderer.setBaseToolTipGenerator(new StandardCategoryToolTipGenerator());
    renderer.setSeriesPaint(0, Color.RED);
    renderer.setSeriesPaint(1, peptideShakerGUI.getSparklineColor());
    distributionChart.getCategoryPlot().setRenderer(renderer);
    // add mouse listener
    distributionChartPanel.addChartMouseListener(new ChartMouseListener() {

        @Override
        public void chartMouseClicked(ChartMouseEvent cme) {
            if (cme.getEntity() instanceof CategoryItemEntity) {
                CategoryItemEntity categoryItem = (CategoryItemEntity) cme.getEntity();
                String columnKey = (String) categoryItem.getColumnKey();
                // select and highlight category
                boolean categoryFound = false;
                for (int i = 0; i < goMappingsTable.getRowCount() && !categoryFound; i++) {
                    if (((String) goMappingsTable.getValueAt(i, goMappingsTable.getColumn("GO Term").getModelIndex())).equalsIgnoreCase(columnKey)) {
                        goMappingsTable.setRowSelectionInterval(i, i);
                        goMappingsTable.scrollRectToVisible(goMappingsTable.getCellRect(i, 0, false));
                        goMappingsTableMouseReleased(null);
                    }
                }
            }
        }

        @Override
        public void chartMouseMoved(ChartMouseEvent cme) {
        // do nothing
        }
    });
    // set background color
    distributionChart.getPlot().setBackgroundPaint(Color.WHITE);
    distributionChart.setBackgroundPaint(Color.WHITE);
    distributionChartPanel.setBackground(Color.WHITE);
    // hide the outline
    distributionChart.getPlot().setOutlineVisible(false);
    goFrequencyPlotPanel.removeAll();
    goFrequencyPlotPanel.add(distributionChartPanel);
    goFrequencyPlotPanel.revalidate();
    goFrequencyPlotPanel.repaint();
    JFreeChart significanceChart = ChartFactory.createBarChart(null, "GO Terms", "Log2 Difference", significancePlotDataset, PlotOrientation.VERTICAL, false, true, true);
    signChartPanel = new ChartPanel(significanceChart);
    ((CategoryPlot) signChartPanel.getChart().getPlot()).getDomainAxis().setCategoryLabelPositions(CategoryLabelPositions.UP_90);
    ((CategoryPlot) signChartPanel.getChart().getPlot()).getRangeAxis().setUpperBound(maxLog2Diff);
    ((CategoryPlot) signChartPanel.getChart().getPlot()).getRangeAxis().setLowerBound(-maxLog2Diff);
    BarChartColorRenderer signRenderer = new BarChartColorRenderer(significanceColors);
    signRenderer.setBaseToolTipGenerator(new StandardCategoryToolTipGenerator());
    significanceChart.getCategoryPlot().setRenderer(signRenderer);
    // add mouse listener
    signChartPanel.addChartMouseListener(new ChartMouseListener() {

        @Override
        public void chartMouseClicked(ChartMouseEvent cme) {
            if (cme.getEntity() instanceof CategoryItemEntity) {
                CategoryItemEntity categoryItem = (CategoryItemEntity) cme.getEntity();
                String columnKey = (String) categoryItem.getColumnKey();
                // select and highlight category
                boolean categoryFound = false;
                for (int i = 0; i < goMappingsTable.getRowCount() && !categoryFound; i++) {
                    if (((String) goMappingsTable.getValueAt(i, goMappingsTable.getColumn("GO Term").getModelIndex())).equalsIgnoreCase(columnKey)) {
                        goMappingsTable.setRowSelectionInterval(i, i);
                        goMappingsTable.scrollRectToVisible(goMappingsTable.getCellRect(i, 0, false));
                        goMappingsTableMouseReleased(null);
                    }
                }
            }
        }

        @Override
        public void chartMouseMoved(ChartMouseEvent cme) {
        // do nothing
        }
    });
    // set background color
    significanceChart.getPlot().setBackgroundPaint(Color.WHITE);
    significanceChart.setBackgroundPaint(Color.WHITE);
    signChartPanel.setBackground(Color.WHITE);
    // hide the outline
    significanceChart.getPlot().setOutlineVisible(false);
    goSignificancePlotPanel.removeAll();
    goSignificancePlotPanel.add(signChartPanel);
    goSignificancePlotPanel.revalidate();
    goSignificancePlotPanel.repaint();
    updatePlotMarkers();
    this.setCursor(new java.awt.Cursor(java.awt.Cursor.DEFAULT_CURSOR));
}
Also used : ChartPanel(org.jfree.chart.ChartPanel) Color(java.awt.Color) ChartMouseEvent(org.jfree.chart.ChartMouseEvent) ValueAndBooleanDataPoint(no.uib.jsparklines.data.ValueAndBooleanDataPoint) XYDataPoint(no.uib.jsparklines.data.XYDataPoint) JFreeChart(org.jfree.chart.JFreeChart) ChartMouseListener(org.jfree.chart.ChartMouseListener) BarRenderer3D(org.jfree.chart.renderer.category.BarRenderer3D) StandardCategoryToolTipGenerator(org.jfree.chart.labels.StandardCategoryToolTipGenerator) DefaultCategoryDataset(org.jfree.data.category.DefaultCategoryDataset) CategoryItemEntity(org.jfree.chart.entity.CategoryItemEntity) ValueAndBooleanDataPoint(no.uib.jsparklines.data.ValueAndBooleanDataPoint) BarChartColorRenderer(no.uib.jsparklines.renderers.util.BarChartColorRenderer)

Aggregations

Color (java.awt.Color)1 ValueAndBooleanDataPoint (no.uib.jsparklines.data.ValueAndBooleanDataPoint)1 XYDataPoint (no.uib.jsparklines.data.XYDataPoint)1 BarChartColorRenderer (no.uib.jsparklines.renderers.util.BarChartColorRenderer)1 ChartMouseEvent (org.jfree.chart.ChartMouseEvent)1 ChartMouseListener (org.jfree.chart.ChartMouseListener)1 ChartPanel (org.jfree.chart.ChartPanel)1 JFreeChart (org.jfree.chart.JFreeChart)1 CategoryItemEntity (org.jfree.chart.entity.CategoryItemEntity)1 StandardCategoryToolTipGenerator (org.jfree.chart.labels.StandardCategoryToolTipGenerator)1 BarRenderer3D (org.jfree.chart.renderer.category.BarRenderer3D)1 DefaultCategoryDataset (org.jfree.data.category.DefaultCategoryDataset)1