use of org.jfree.chart.renderer.xy.XYDotRenderer in project pentaho-platform by pentaho.
the class JFreeChartEngine method createTimeSeriesCollectionChart.
private static JFreeChart createTimeSeriesCollectionChart(final TimeSeriesCollectionChartDefinition chartDefinition) {
JFreeChart chart = null;
// TODO Make the following accessible from the chartDefinition
String domainAxisLabel = null;
String rangeAxisLabel = null;
boolean tooltips = true;
boolean urls = true;
// -----------------------------------------------------------
String title = chartDefinition.getTitle();
boolean legend = chartDefinition.isLegendIncluded();
DateAxis domainAxis = new DateAxis(domainAxisLabel, TimeZone.getDefault());
ValueAxis rangeAxis = new NumberAxis(rangeAxisLabel);
XYItemRenderer renderer = null;
switch(chartDefinition.getChartType()) {
case LINE_CHART_TYPE:
renderer = chartDefinition.isThreeD() ? new XYLine3DRenderer() : new XYLineAndShapeRenderer(true, false);
((XYLineAndShapeRenderer) renderer).setShapesVisible(chartDefinition.isMarkersVisible());
((XYLineAndShapeRenderer) renderer).setBaseShapesFilled(chartDefinition.isMarkersVisible());
break;
case AREA_CHART_TYPE:
renderer = new XYAreaRenderer();
break;
case STEP_CHART_TYPE:
renderer = new XYStepRenderer();
break;
case STEP_AREA_CHART_TYPE:
renderer = new XYStepAreaRenderer();
break;
case DIFFERENCE_CHART_TYPE:
renderer = new XYDifferenceRenderer();
break;
case DOT_CHART_TYPE:
renderer = new XYDotRenderer();
((XYDotRenderer) renderer).setDotHeight(chartDefinition.getDotHeight());
((XYDotRenderer) renderer).setDotWidth(chartDefinition.getDotWidth());
break;
default:
// should log an error if invalid chart type passed in - at least return null for no renderer
return null;
}
if (tooltips) {
XYToolTipGenerator generator = new StandardXYToolTipGenerator(chartDefinition.getTooltipContent(), new SimpleDateFormat(chartDefinition.getTooltipXFormat()), new DecimalFormat(chartDefinition.getTooltipYFormat()));
renderer.setToolTipGenerator(generator);
}
if (urls) {
renderer.setURLGenerator(new StandardXYURLGenerator());
}
renderer.setStroke(JFreeChartEngine.getLineStyleStroke(chartDefinition.getLineStyle(), chartDefinition.getLineWidth()));
XYPlot plot = new XYPlot(chartDefinition, domainAxis, rangeAxis, renderer);
JFreeChartEngine.updatePlot(plot, chartDefinition);
chart = new JFreeChart(title, JFreeChart.DEFAULT_TITLE_FONT, plot, legend);
return chart;
}
use of org.jfree.chart.renderer.xy.XYDotRenderer in project dkpro-tc by dkpro.
the class ScatterplotRenderer method write.
@Override
public void write(OutputStream aStream) throws IOException {
JFreeChart chart = ChartFactory.createXYLineChart("Scatterplot", "Gold", "Prediction", aDataset, PlotOrientation.VERTICAL, false, false, false);
XYDotRenderer renderer = new XYDotRenderer();
renderer.setDotHeight(2);
renderer.setDotWidth(2);
double padding = (max - min) / 10;
chart.getXYPlot().setRenderer(renderer);
chart.getXYPlot().getRangeAxis().setRange(min - padding, max + padding);
chart.getXYPlot().getDomainAxis().setRange(min - padding, max + padding);
ChartUtil.writeChartAsPDF(aStream, chart, 400, 400);
}
use of org.jfree.chart.renderer.xy.XYDotRenderer in project mafscaling by vimsh.
the class ACompCalc method createChart.
protected void createChart(JPanel plotPanel, String xAxisName, String yAxisName) {
JFreeChart chart = ChartFactory.createScatterPlot(null, null, null, null, PlotOrientation.VERTICAL, false, true, false);
chart.setBorderVisible(true);
chartPanel = new ChartPanel(chart, true, true, true, true, true);
chartPanel.setAutoscrolls(true);
chartPanel.setMouseZoomable(false);
GridBagConstraints gbl_chartPanel = new GridBagConstraints();
gbl_chartPanel.anchor = GridBagConstraints.CENTER;
gbl_chartPanel.insets = new Insets(3, 3, 3, 3);
gbl_chartPanel.weightx = 1.0;
gbl_chartPanel.weighty = 1.0;
gbl_chartPanel.fill = GridBagConstraints.BOTH;
gbl_chartPanel.gridx = 0;
gbl_chartPanel.gridy = 1;
plotPanel.add(chartPanel, gbl_chartPanel);
XYDotRenderer dotRenderer = new XYDotRenderer();
dotRenderer.setSeriesPaint(0, new Color(0, 51, 102));
dotRenderer.setDotHeight(3);
dotRenderer.setDotWidth(3);
XYLineAndShapeRenderer lineRenderer = new XYLineAndShapeRenderer();
lineRenderer.setUseFillPaint(true);
lineRenderer.setBaseToolTipGenerator(new StandardXYToolTipGenerator(StandardXYToolTipGenerator.DEFAULT_TOOL_TIP_FORMAT, new DecimalFormat("0.00"), new DecimalFormat("0.00")));
Stroke stroke = new BasicStroke(2.0f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND, 1.0f, null, 0.0f);
lineRenderer.setSeriesStroke(0, stroke);
lineRenderer.setSeriesPaint(0, Color.RED);
lineRenderer.setSeriesShape(0, ShapeUtilities.createDiamond((float) 2.5));
lineRenderer.setLegendItemLabelGenerator(new StandardXYSeriesLabelGenerator() {
private static final long serialVersionUID = 7593430826693873496L;
public String generateLabel(XYDataset dataset, int series) {
XYSeries xys = ((XYSeriesCollection) dataset).getSeries(series);
return xys.getDescription();
}
});
NumberAxis xAxis = new NumberAxis(xAxisName);
xAxis.setAutoRangeIncludesZero(false);
NumberAxis yAxis = new NumberAxis(yAxisName);
yAxis.setAutoRangeIncludesZero(false);
XYSeriesCollection scatterDataset = new XYSeriesCollection(runData);
XYSeriesCollection lineDataset = new XYSeriesCollection();
trendData.setDescription(trendDataName);
lineDataset.addSeries(trendData);
XYPlot plot = chart.getXYPlot();
plot.setRangePannable(true);
plot.setDomainPannable(true);
plot.setDomainGridlinePaint(Color.DARK_GRAY);
plot.setRangeGridlinePaint(Color.DARK_GRAY);
plot.setBackgroundPaint(new Color(224, 224, 224));
plot.setDataset(0, lineDataset);
plot.setRenderer(0, lineRenderer);
plot.setDomainAxis(0, xAxis);
plot.setRangeAxis(0, yAxis);
plot.mapDatasetToDomainAxis(0, 0);
plot.mapDatasetToRangeAxis(0, 0);
plot.setDataset(1, scatterDataset);
plot.setRenderer(1, dotRenderer);
plot.mapDatasetToDomainAxis(1, 0);
plot.mapDatasetToRangeAxis(1, 0);
LegendTitle legend = new LegendTitle(plot.getRenderer());
legend.setItemFont(new Font("Arial", 0, 10));
legend.setPosition(RectangleEdge.TOP);
chart.addLegend(legend);
}
use of org.jfree.chart.renderer.xy.XYDotRenderer in project Gemma by PavlidisLab.
the class ExpressionExperimentQCController method writeDetailedFactorAnalysis.
private boolean writeDetailedFactorAnalysis(ExpressionExperiment ee, OutputStream os) throws Exception {
SVDValueObject svdo = svdService.getSvdFactorAnalysis(ee.getId());
if (svdo == null)
return false;
if (svdo.getFactors().isEmpty() && svdo.getDates().isEmpty()) {
return false;
}
Map<Integer, Map<Long, Double>> factorCorrelations = svdo.getFactorCorrelations();
// Map<Integer, Map<Long, Double>> factorPvalues = svdo.getFactorPvalues();
Map<Integer, Double> dateCorrelations = svdo.getDateCorrelations();
assert ee.getId().equals(svdo.getId());
// need the experimental design
ee = expressionExperimentService.thawLite(ee);
int maxWidth = 30;
Map<Long, String> efs = this.getFactorNames(ee, maxWidth);
Map<Long, ExperimentalFactor> efIdMap = EntityUtils.getIdMap(ee.getExperimentalDesign().getExperimentalFactors());
Collection<Long> continuousFactors = new HashSet<>();
for (ExperimentalFactor ef : ee.getExperimentalDesign().getExperimentalFactors()) {
boolean isContinous = ExperimentalDesignUtils.isContinuous(ef);
if (isContinous) {
continuousFactors.add(ef.getId());
}
}
/*
* Make plots of the dates vs. PCs, factors vs. PCs.
*/
int MAX_COMP = 3;
Map<Long, List<JFreeChart>> charts = new LinkedHashMap<>();
ChartFactory.setChartTheme(StandardChartTheme.createLegacyTheme());
/*
* FACTORS
*/
String componentShorthand = "PC";
for (Integer component : factorCorrelations.keySet()) {
if (component >= MAX_COMP)
break;
String xaxisLabel = componentShorthand + (component + 1);
for (Long efId : factorCorrelations.get(component).keySet()) {
/*
* Should not happen.
*/
if (!efs.containsKey(efId)) {
log.warn("No experimental factor with id " + efId);
continue;
}
if (!svdo.getFactors().containsKey(efId)) {
// this should not happen.
continue;
}
boolean isCategorical = !continuousFactors.contains(efId);
Map<Long, String> categories = new HashMap<>();
if (isCategorical) {
this.getCategories(efIdMap, efId, categories);
}
if (!charts.containsKey(efId)) {
charts.put(efId, new ArrayList<JFreeChart>());
}
Double a = factorCorrelations.get(component).get(efId);
// unique?
String plotname = (efs.get(efId) == null ? "?" : efs.get(efId)) + " " + xaxisLabel;
if (a != null && !Double.isNaN(a)) {
String title = plotname + " " + String.format("%.2f", a);
List<Double> values = svdo.getFactors().get(efId);
Double[] eigenGene = this.getEigenGene(svdo, component);
assert values.size() == eigenGene.length;
/*
* Plot eigengene vs values, add correlation to the plot
*/
JFreeChart chart;
if (isCategorical) {
/*
* Categorical factor
*/
// use the absolute value of the correlation, since direction is arbitrary.
title = plotname + " " + String.format("r=%.2f", Math.abs(a));
DefaultMultiValueCategoryDataset dataset = new DefaultMultiValueCategoryDataset();
/*
* What this code does is organize the factor values by the groups.
*/
Map<String, List<Double>> groupedValues = new TreeMap<>();
for (int i = 0; i < values.size(); i++) {
Long fvId = values.get(i).longValue();
String fvValue = categories.get(fvId);
if (fvValue == null) {
// is this all we need to do?
continue;
}
if (!groupedValues.containsKey(fvValue)) {
groupedValues.put(fvValue, new ArrayList<Double>());
}
groupedValues.get(fvValue).add(eigenGene[i]);
if (log.isDebugEnabled())
log.debug(fvValue + " " + values.get(i));
}
for (String key : groupedValues.keySet()) {
dataset.add(groupedValues.get(key), plotname, key);
}
// don't show the name of the X axis: it's redundant with the title.
NumberAxis rangeAxis = new NumberAxis(xaxisLabel);
rangeAxis.setAutoRangeIncludesZero(false);
// rangeAxis.setAutoRange( false );
rangeAxis.setAutoRangeMinimumSize(4.0);
// rangeAxis.setRange( new Range( -2, 2 ) );
CategoryPlot plot = new CategoryPlot(dataset, new CategoryAxis(null), rangeAxis, new ScatterRenderer());
plot.setRangeGridlinesVisible(false);
plot.setDomainGridlinesVisible(false);
chart = new JFreeChart(title, new Font("SansSerif", Font.BOLD, 12), plot, false);
ScatterRenderer renderer = (ScatterRenderer) plot.getRenderer();
float saturationDrop = (float) Math.min(1.0, component * 0.8f / MAX_COMP);
renderer.setSeriesFillPaint(0, Color.getHSBColor(0.0f, 1.0f - saturationDrop, 0.7f));
renderer.setSeriesShape(0, new Ellipse2D.Double(0, 0, 3, 3));
renderer.setUseOutlinePaint(false);
renderer.setUseFillPaint(true);
renderer.setBaseFillPaint(Color.white);
CategoryAxis domainAxis = plot.getDomainAxis();
domainAxis.setCategoryLabelPositions(CategoryLabelPositions.UP_45);
} else {
/*
* Continuous value factor
*/
DefaultXYDataset series = new DefaultXYDataset();
series.addSeries(plotname, new double[][] { ArrayUtils.toPrimitive(values.toArray(new Double[] {})), ArrayUtils.toPrimitive(eigenGene) });
// don't show x-axis label, which would otherwise be efs.get( efId )
chart = ChartFactory.createScatterPlot(title, null, xaxisLabel, series, PlotOrientation.VERTICAL, false, false, false);
XYPlot plot = chart.getXYPlot();
plot.setRangeGridlinesVisible(false);
plot.setDomainGridlinesVisible(false);
XYItemRenderer renderer = plot.getRenderer();
renderer.setBasePaint(Color.white);
renderer.setSeriesShape(0, new Ellipse2D.Double(0, 0, 3, 3));
float saturationDrop = (float) Math.min(1.0, component * 0.8f / MAX_COMP);
renderer.setSeriesPaint(0, Color.getHSBColor(0.0f, 1.0f - saturationDrop, 0.7f));
plot.setRenderer(renderer);
}
chart.getTitle().setFont(new Font("SansSerif", Font.BOLD, 12));
charts.get(efId).add(chart);
}
}
}
/*
* DATES
*/
charts.put(-1L, new ArrayList<JFreeChart>());
for (Integer component : dateCorrelations.keySet()) {
String xaxisLabel = componentShorthand + (component + 1);
List<Date> dates = svdo.getDates();
if (dates.isEmpty())
break;
long secspan = ubic.basecode.util.DateUtil.numberOfSecondsBetweenDates(dates);
if (component >= MAX_COMP)
break;
Double a = dateCorrelations.get(component);
if (a != null && !Double.isNaN(a)) {
Double[] eigenGene = svdo.getvMatrix().getColObj(component);
/*
* Plot eigengene vs values, add correlation to the plot
*/
TimeSeries series = new TimeSeries("Dates vs. eigen" + (component + 1));
int i = 0;
for (Date d : dates) {
// if span is less than an hour, retain the minute.
if (secspan < 60 * 60) {
series.addOrUpdate(new Minute(d), eigenGene[i++]);
} else {
series.addOrUpdate(new Hour(d), eigenGene[i++]);
}
}
TimeSeriesCollection dataset = new TimeSeriesCollection();
dataset.addSeries(series);
JFreeChart chart = ChartFactory.createTimeSeriesChart("Dates: " + xaxisLabel + " " + String.format("r=%.2f", a), null, xaxisLabel, dataset, false, false, false);
XYPlot xyPlot = chart.getXYPlot();
chart.getTitle().setFont(new Font("SansSerif", Font.BOLD, 12));
// standard renderer makes lines.
XYDotRenderer renderer = new XYDotRenderer();
renderer.setBaseFillPaint(Color.white);
renderer.setDotHeight(3);
renderer.setDotWidth(3);
// has no effect, need dotheight.
renderer.setSeriesShape(0, new Ellipse2D.Double(0, 0, 3, 3));
float saturationDrop = (float) Math.min(1.0, component * 0.8f / MAX_COMP);
renderer.setSeriesPaint(0, Color.getHSBColor(0.0f, 1.0f - saturationDrop, 0.7f));
ValueAxis domainAxis = xyPlot.getDomainAxis();
domainAxis.setVerticalTickLabels(true);
xyPlot.setRenderer(renderer);
xyPlot.setRangeGridlinesVisible(false);
xyPlot.setDomainGridlinesVisible(false);
charts.get(-1L).add(chart);
}
}
/*
* Plot in a grid, with each factor as a column. FIXME What if we have too many factors to fit on the screen?
*/
int columns = (int) Math.ceil(charts.size());
int perChartSize = ExpressionExperimentQCController.DEFAULT_QC_IMAGE_SIZE_PX;
BufferedImage image = new BufferedImage(columns * perChartSize, MAX_COMP * perChartSize, BufferedImage.TYPE_INT_ARGB);
Graphics2D g2 = image.createGraphics();
int currentX = 0;
int currentY = 0;
for (Long id : charts.keySet()) {
for (JFreeChart chart : charts.get(id)) {
this.addChartToGraphics(chart, g2, currentX, currentY, perChartSize, perChartSize);
if (currentY + perChartSize < MAX_COMP * perChartSize) {
currentY += perChartSize;
} else {
currentY = 0;
currentX += perChartSize;
}
}
}
os.write(ChartUtilities.encodeAsPNG(image));
return true;
}
use of org.jfree.chart.renderer.xy.XYDotRenderer in project n2a by frothga.
the class Raster method createChart.
public JFreeChart createChart(final XYDataset dataset) {
final JFreeChart chart = ChartFactory.createScatterPlot(// chart title
null, // x axis label
null, // y axis label
null, // data
dataset, PlotOrientation.VERTICAL, // include legend
false, // tooltips
true, // urls
false);
XYPlot plot = chart.getXYPlot();
plot.setBackgroundPaint(Color.white);
plot.setRangeGridlinePaint(Color.lightGray);
plot.setDomainPannable(true);
plot.setRangePannable(true);
plot.setRenderer(new XYDotRenderer() {
public void drawItem(java.awt.Graphics2D g2, XYItemRendererState state, java.awt.geom.Rectangle2D dataArea, PlotRenderingInfo info, XYPlot plot, ValueAxis domainAxis, ValueAxis rangeAxis, XYDataset dataset, int series, int item, CrosshairState crosshairState, int pass) {
if (!getItemVisible(series, item))
return;
int dotWidth = 1;
double rasterLines = rangeAxis.getRange().getLength();
int pixels = g2.getClipBounds().height;
double height = pixels / rasterLines;
if (height > 10)
height -= 2;
else if (height > 2)
height -= 1;
int dotHeight = (int) Math.min(20, Math.max(1, Math.floor(height)));
double x = dataset.getXValue(series, item);
double y = dataset.getYValue(series, item);
if (Double.isNaN(y))
return;
double adjx = (dotWidth - 1) / 2.0;
double adjy = (dotHeight - 1) / 2.0;
RectangleEdge xAxisLocation = plot.getDomainAxisEdge();
RectangleEdge yAxisLocation = plot.getRangeAxisEdge();
double transX = domainAxis.valueToJava2D(x, dataArea, xAxisLocation) - adjx;
double transY = rangeAxis.valueToJava2D(y, dataArea, yAxisLocation) - adjy;
g2.setPaint(Color.black);
PlotOrientation orientation = plot.getOrientation();
if (orientation == PlotOrientation.HORIZONTAL)
g2.fillRect((int) transY, (int) transX, dotHeight, dotWidth);
else
g2.fillRect((int) transX, (int) transY, dotWidth, dotHeight);
int datasetIndex = plot.indexOf(dataset);
updateCrosshairValues(crosshairState, x, y, datasetIndex, transX, transY, orientation);
}
});
NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();
// Integer units only
rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
return chart;
}
Aggregations