use of org.jfree.chart.labels.StandardCategoryToolTipGenerator 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;
}
use of org.jfree.chart.labels.StandardCategoryToolTipGenerator 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;
}
Aggregations