Search in sources :

Example 1 with ColorScheme

use of org.baderlab.csplugins.enrichmentmap.style.ColorScheme in project EnrichmentMapApp by BaderLab.

the class ControlPanelMediator method createStyleOptions.

private EMStyleOptions createStyleOptions(EnrichmentMap map, EMViewControlPanel viewPanel) {
    if (map == null || viewPanel == null)
        return null;
    Set<AbstractDataSet> dataSets = viewPanel.getDataSetSelector().getCheckedItems();
    boolean publicationReady = viewPanel.getPublicationReadyCheck().isSelected();
    boolean postAnalysis = map.hasSignatureDataSets();
    ChartData data = (ChartData) viewPanel.getChartDataCombo().getSelectedItem();
    ChartType type = getChartType(viewPanel);
    ColorScheme colorScheme = (ColorScheme) viewPanel.getChartColorsCombo().getSelectedItem();
    boolean showLabels = viewPanel.getShowChartLabelsCheck().isSelected();
    ChartOptions chartOptions = new ChartOptions(data, type, colorScheme, showLabels);
    return new EMStyleOptions(viewPanel.getNetworkView(), map, dataSets::contains, chartOptions, postAnalysis, publicationReady);
}
Also used : EMStyleOptions(org.baderlab.csplugins.enrichmentmap.style.EMStyleOptions) ChartData(org.baderlab.csplugins.enrichmentmap.style.ChartData) AbstractDataSet(org.baderlab.csplugins.enrichmentmap.model.AbstractDataSet) ColorScheme(org.baderlab.csplugins.enrichmentmap.style.ColorScheme) ChartType(org.baderlab.csplugins.enrichmentmap.style.ChartType) ChartOptions(org.baderlab.csplugins.enrichmentmap.style.ChartOptions)

Example 2 with ColorScheme

use of org.baderlab.csplugins.enrichmentmap.style.ColorScheme in project EnrichmentMapApp by BaderLab.

the class ChartUtil method createHeatStripsLegend.

@SuppressWarnings("serial")
public static JFreeChart createHeatStripsLegend(List<EMDataSet> dataSets, ChartOptions options) {
    final DefaultCategoryDataset dataset = new DefaultCategoryDataset();
    int total = dataSets.size();
    int v = total / -2;
    for (int i = 0; i < total; i++) {
        // Just to make sure there is always a bar for each data set name
        if (v == 0.0)
            v = 1;
        dataset.addValue(v++, options.getData().toString(), dataSets.get(i).getName());
    }
    final JFreeChart chart = ChartFactory.createBarChart(// chart title
    null, // domain axis label
    null, // range axis label
    null, // data
    dataset, PlotOrientation.VERTICAL, // include legend
    false, // tooltips
    true, // urls
    false);
    chart.setAntiAlias(true);
    chart.setBorderVisible(false);
    chart.setBackgroundPaint(UIManager.getColor("Table.background"));
    chart.setBackgroundImageAlpha(0.0f);
    chart.setPadding(new RectangleInsets(0.0, 0.0, 0.0, 0.0));
    final CategoryPlot plot = (CategoryPlot) chart.getPlot();
    plot.setOutlineVisible(false);
    plot.setBackgroundPaint(UIManager.getColor("Table.background"));
    plot.setInsets(new RectangleInsets(0.0, 0.0, 0.0, 0.0));
    plot.setDomainGridlinesVisible(false);
    plot.setRangeGridlinesVisible(false);
    final CategoryAxis domainAxis = (CategoryAxis) plot.getDomainAxis();
    domainAxis.setVisible(true);
    domainAxis.setAxisLineVisible(false);
    domainAxis.setTickMarksVisible(false);
    domainAxis.setTickLabelFont(UIManager.getFont("Label.font").deriveFont(LookAndFeelUtil.getSmallFontSize()));
    domainAxis.setLabelPaint(UIManager.getColor("Label.foreground"));
    domainAxis.setMaximumCategoryLabelLines(1);
    domainAxis.setCategoryMargin(0.0);
    if (total > 4) {
        domainAxis.setCategoryLabelPositions(CategoryLabelPositions.UP_90);
        domainAxis.setMaximumCategoryLabelWidthRatio(0.5f);
    } else {
        domainAxis.setMaximumCategoryLabelLines(2);
    }
    final NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();
    rangeAxis.setVisible(false);
    ColorScheme colorScheme = options != null ? options.getColorScheme() : null;
    List<Color> colors = colorScheme != null ? colorScheme.getColors() : null;
    if (// UP, ZERO, DOWN:
    colors == null || colors.size() < 3)
        colors = Arrays.asList(new Color[] { Color.LIGHT_GRAY, Color.WHITE, Color.DARK_GRAY });
    List<Color> itemColors = new ArrayList<>();
    for (int i = 0; i < total; i++) {
        Number n = dataset.getValue(options.getData().toString(), dataSets.get(i).getName());
        itemColors.add(ColorUtil.getColor(n.doubleValue(), -total, total, colors.get(2), colors.get(1), colors.get(0)));
    }
    final BarRenderer renderer = new BarRenderer() {

        @Override
        public Paint getItemPaint(int row, int column) {
            return column < itemColors.size() ? itemColors.get(column) : Color.LIGHT_GRAY;
        }
    };
    plot.setRenderer(renderer);
    renderer.setBarPainter(new StandardBarPainter());
    renderer.setDrawBarOutline(true);
    renderer.setShadowVisible(false);
    renderer.setItemMargin(0.0);
    renderer.setBaseToolTipGenerator(new StandardCategoryToolTipGenerator("{1}", NumberFormat.getInstance()));
    return chart;
}
Also used : NumberAxis(org.jfree.chart.axis.NumberAxis) Color(java.awt.Color) ColorScheme(org.baderlab.csplugins.enrichmentmap.style.ColorScheme) ArrayList(java.util.ArrayList) BarRenderer(org.jfree.chart.renderer.category.BarRenderer) Paint(java.awt.Paint) JFreeChart(org.jfree.chart.JFreeChart) CategoryPlot(org.jfree.chart.plot.CategoryPlot) CategoryAxis(org.jfree.chart.axis.CategoryAxis) StandardCategoryToolTipGenerator(org.jfree.chart.labels.StandardCategoryToolTipGenerator) StandardBarPainter(org.jfree.chart.renderer.category.StandardBarPainter) RectangleInsets(org.jfree.ui.RectangleInsets) DefaultCategoryDataset(org.jfree.data.category.DefaultCategoryDataset)

Example 3 with ColorScheme

use of org.baderlab.csplugins.enrichmentmap.style.ColorScheme in project EnrichmentMapApp by BaderLab.

the class ChartUtil method createRadialHeatMapLegend.

public static JFreeChart createRadialHeatMapLegend(List<EMDataSet> dataSets, ChartOptions options) {
    // All the slices must have the same size
    final DefaultPieDataset pieDataset = new DefaultPieDataset();
    for (EMDataSet ds : dataSets) pieDataset.setValue(ds.getName(), 1);
    JFreeChart chart = ChartFactory.createPieChart(// chart title
    null, // data
    pieDataset, // include legend
    false, // tooltips
    true, // urls
    false);
    chart.setAntiAlias(true);
    chart.setBorderVisible(false);
    chart.setBackgroundPaint(UIManager.getColor("Table.background"));
    chart.setBackgroundImageAlpha(0.0f);
    chart.setPadding(new RectangleInsets(0.0, 0.0, 0.0, 0.0));
    final PiePlot plot = (PiePlot) chart.getPlot();
    plot.setCircular(true);
    plot.setOutlineVisible(false);
    plot.setBackgroundPaint(UIManager.getColor("Table.background"));
    plot.setInsets(new RectangleInsets(0.0, 0.0, 0.0, 0.0));
    plot.setShadowPaint(TRANSPARENT_COLOR);
    plot.setShadowXOffset(0.0);
    plot.setShadowYOffset(0.0);
    plot.setLabelGenerator(new StandardPieSectionLabelGenerator("{0}"));
    plot.setLabelFont(UIManager.getFont("Label.font").deriveFont(LookAndFeelUtil.getSmallFontSize()));
    plot.setLabelPaint(UIManager.getColor("Label.foreground"));
    plot.setLabelBackgroundPaint(TRANSPARENT_COLOR);
    plot.setLabelOutlinePaint(TRANSPARENT_COLOR);
    plot.setLabelShadowPaint(TRANSPARENT_COLOR);
    plot.setToolTipGenerator(new StandardPieToolTipGenerator("{0}"));
    ColorScheme colorScheme = options != null ? options.getColorScheme() : null;
    List<Color> colors = colorScheme != null ? colorScheme.getColors() : null;
    if (// UP, ZERO, DOWN:
    colors == null || colors.size() < 3)
        colors = Arrays.asList(new Color[] { Color.LIGHT_GRAY, Color.WHITE, Color.DARK_GRAY });
    int total = dataSets.size();
    int v = total / -2;
    for (EMDataSet ds : dataSets) {
        plot.setSectionPaint(ds.getName(), ColorUtil.getColor(v, -total, total, colors.get(2), colors.get(1), colors.get(0)));
        v++;
    }
    return chart;
}
Also used : DefaultPieDataset(org.jfree.data.general.DefaultPieDataset) StandardPieToolTipGenerator(org.jfree.chart.labels.StandardPieToolTipGenerator) Color(java.awt.Color) ColorScheme(org.baderlab.csplugins.enrichmentmap.style.ColorScheme) RectangleInsets(org.jfree.ui.RectangleInsets) PiePlot(org.jfree.chart.plot.PiePlot) EMDataSet(org.baderlab.csplugins.enrichmentmap.model.EMDataSet) StandardPieSectionLabelGenerator(org.jfree.chart.labels.StandardPieSectionLabelGenerator) JFreeChart(org.jfree.chart.JFreeChart) Paint(java.awt.Paint)

Example 4 with ColorScheme

use of org.baderlab.csplugins.enrichmentmap.style.ColorScheme in project EnrichmentMapApp by BaderLab.

the class ChartUtil method createHeatMapLegend.

@SuppressWarnings("serial")
public static JFreeChart createHeatMapLegend(List<EMDataSet> dataSets, ChartOptions options) {
    final DefaultCategoryDataset dataset = new DefaultCategoryDataset();
    for (EMDataSet ds : dataSets) dataset.addValue(1, options.getData().toString(), ds.getName());
    final JFreeChart chart = ChartFactory.createBarChart(// chart title
    null, // domain axis label
    null, // range axis label
    null, // data
    dataset, PlotOrientation.HORIZONTAL, // include legend
    false, // tooltips
    true, // urls
    false);
    chart.setAntiAlias(true);
    chart.setBorderVisible(false);
    chart.setBackgroundPaint(UIManager.getColor("Table.background"));
    chart.setBackgroundImageAlpha(0.0f);
    chart.setPadding(new RectangleInsets(0.0, 0.0, 0.0, 20.0));
    final CategoryPlot plot = (CategoryPlot) chart.getPlot();
    plot.setOutlineVisible(false);
    plot.setBackgroundPaint(UIManager.getColor("Table.background"));
    plot.setInsets(new RectangleInsets(0.0, 0.0, 0.0, 0.0));
    plot.setDomainGridlinesVisible(false);
    plot.setRangeGridlinesVisible(false);
    final CategoryAxis domainAxis = (CategoryAxis) plot.getDomainAxis();
    domainAxis.setVisible(true);
    domainAxis.setAxisLineVisible(false);
    domainAxis.setTickMarksVisible(false);
    domainAxis.setTickLabelFont(UIManager.getFont("Label.font").deriveFont(LookAndFeelUtil.getSmallFontSize()));
    domainAxis.setTickLabelPaint(UIManager.getColor("Label.foreground"));
    domainAxis.setTickLabelInsets(new RectangleInsets(0.0, 0.0, 0.0, 15.0));
    domainAxis.setCategoryMargin(0.0);
    final NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();
    rangeAxis.setVisible(false);
    ColorScheme colorScheme = options != null ? options.getColorScheme() : null;
    List<Color> colors = colorScheme != null ? colorScheme.getColors() : null;
    if (// UP, ZERO, DOWN:
    colors == null || colors.size() < 3)
        colors = Arrays.asList(new Color[] { Color.LIGHT_GRAY, Color.WHITE, Color.DARK_GRAY });
    List<Color> itemColors = new ArrayList<>();
    int total = dataSets.size();
    int v = total / 2;
    for (int i = 0; i < total; i++) itemColors.add(ColorUtil.getColor(v--, -total, total, colors.get(2), colors.get(1), colors.get(0)));
    final BarRenderer renderer = new BarRenderer() {

        @Override
        public Paint getItemPaint(int row, int column) {
            return column < itemColors.size() ? itemColors.get(column) : Color.LIGHT_GRAY;
        }
    };
    plot.setRenderer(renderer);
    renderer.setBarPainter(new StandardBarPainter());
    renderer.setDrawBarOutline(true);
    renderer.setShadowVisible(false);
    renderer.setItemMargin(0.0);
    renderer.setBaseToolTipGenerator(new StandardCategoryToolTipGenerator("{1}", NumberFormat.getInstance()));
    return chart;
}
Also used : NumberAxis(org.jfree.chart.axis.NumberAxis) Color(java.awt.Color) ColorScheme(org.baderlab.csplugins.enrichmentmap.style.ColorScheme) ArrayList(java.util.ArrayList) BarRenderer(org.jfree.chart.renderer.category.BarRenderer) JFreeChart(org.jfree.chart.JFreeChart) CategoryPlot(org.jfree.chart.plot.CategoryPlot) Paint(java.awt.Paint) CategoryAxis(org.jfree.chart.axis.CategoryAxis) StandardCategoryToolTipGenerator(org.jfree.chart.labels.StandardCategoryToolTipGenerator) StandardBarPainter(org.jfree.chart.renderer.category.StandardBarPainter) RectangleInsets(org.jfree.ui.RectangleInsets) EMDataSet(org.baderlab.csplugins.enrichmentmap.model.EMDataSet) DefaultCategoryDataset(org.jfree.data.category.DefaultCategoryDataset)

Aggregations

ColorScheme (org.baderlab.csplugins.enrichmentmap.style.ColorScheme)4 Color (java.awt.Color)3 Paint (java.awt.Paint)3 JFreeChart (org.jfree.chart.JFreeChart)3 RectangleInsets (org.jfree.ui.RectangleInsets)3 ArrayList (java.util.ArrayList)2 EMDataSet (org.baderlab.csplugins.enrichmentmap.model.EMDataSet)2 CategoryAxis (org.jfree.chart.axis.CategoryAxis)2 NumberAxis (org.jfree.chart.axis.NumberAxis)2 StandardCategoryToolTipGenerator (org.jfree.chart.labels.StandardCategoryToolTipGenerator)2 CategoryPlot (org.jfree.chart.plot.CategoryPlot)2 BarRenderer (org.jfree.chart.renderer.category.BarRenderer)2 StandardBarPainter (org.jfree.chart.renderer.category.StandardBarPainter)2 DefaultCategoryDataset (org.jfree.data.category.DefaultCategoryDataset)2 AbstractDataSet (org.baderlab.csplugins.enrichmentmap.model.AbstractDataSet)1 ChartData (org.baderlab.csplugins.enrichmentmap.style.ChartData)1 ChartOptions (org.baderlab.csplugins.enrichmentmap.style.ChartOptions)1 ChartType (org.baderlab.csplugins.enrichmentmap.style.ChartType)1 EMStyleOptions (org.baderlab.csplugins.enrichmentmap.style.EMStyleOptions)1 StandardPieSectionLabelGenerator (org.jfree.chart.labels.StandardPieSectionLabelGenerator)1