use of java.awt.BasicStroke in project polyGembler by c-zhou.
the class JfreeChart method plotLineChart2.
private void plotLineChart2(String file_in, Dimension dim, Color color, String position) {
JPanel collinearChart = new JPanel();
collinearChart.setSize(dim);
collinearChart.setMinimumSize(dim);
collinearChart.setPreferredSize(dim);
collinearChart.setBackground(color);
final XYSeriesCollection lineSeries = new XYSeriesCollection();
int n1 = 0;
try {
BufferedReader br = Utils.getBufferedReader(file_in);
String line = br.readLine();
String[] s;
int series = 0;
while ((line = br.readLine()) != null && line.length() > 0) {
s = line.split("\\s+");
series = Integer.parseInt(s[2]);
if (lineSeries.getSeriesCount() < series) {
lineSeries.addSeries(new XYSeries(series));
n1 = 0;
}
lineSeries.getSeries(series - 1).add(Double.parseDouble(s[1]) / 1000, Double.parseDouble(s[0]));
n1++;
}
br.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
final int n = n1;
final int m = lineSeries.getSeriesCount();
// create error bars
final XYSeriesCollection errorBarSeries2 = new XYSeriesCollection();
for (int i = 0; i < n; i++) {
double[] f = new double[m];
for (int j = 0; j < m; j++) f[j] = lineSeries.getSeries(j).getY(i).doubleValue();
double mean = StatUtils.mean(f), sd = Math.sqrt(StatUtils.variance(f));
double x = lineSeries.getSeries(0).getX(i).doubleValue();
errorBarSeries2.addSeries(new XYSeries(i));
errorBarSeries2.getSeries(i).add(x, mean - sd);
errorBarSeries2.getSeries(i).add(x, mean);
errorBarSeries2.getSeries(i).add(x, mean + sd);
}
final XYSeriesCollection errorBarSeries = new XYSeriesCollection();
final XYSeriesCollection upperBoundSeries = new XYSeriesCollection();
final XYSeriesCollection upperQ3Series = new XYSeriesCollection();
final XYSeriesCollection boxSeries = new XYSeriesCollection();
final XYSeriesCollection q2Series = new XYSeriesCollection();
final XYSeriesCollection lowerQ2Series = new XYSeriesCollection();
final XYSeriesCollection lowerBoundSeries = new XYSeriesCollection();
final XYSeriesCollection boxplotSeries = new XYSeriesCollection();
final XYSeriesCollection meanDotSeries = new XYSeriesCollection();
final double half_width = 1;
final double thres = 0.05;
final int stroke = 2;
for (int i = 0; i < n; i++) {
double[] f = new double[m];
for (int j = 0; j < m; j++) f[j] = lineSeries.getSeries(j).getY(i).doubleValue();
double q1 = StatUtils.percentile(f, 25), q2 = StatUtils.percentile(f, 50), q3 = StatUtils.percentile(f, 75);
double IQR = q3 - q1;
double[] boundary = new double[] { q1 - 1.5 * IQR, q3 + 1.5 * IQR };
final Set<Integer> outliers = new HashSet<Integer>();
for (int k = 0; k < m; k++) if (f[k] < boundary[0] || f[k] > boundary[1])
outliers.add(k);
double lower_bound = Double.POSITIVE_INFINITY, upper_bound = Double.NEGATIVE_INFINITY;
for (int k = 0; k < m; k++) {
if (outliers.contains(k))
continue;
if (f[k] < lower_bound)
lower_bound = f[k];
if (f[k] > upper_bound)
upper_bound = f[k];
}
double x = lineSeries.getSeries(0).getX(i).doubleValue();
double mean = StatUtils.mean(f);
if (mean >= thres) {
int w = upperBoundSeries.getSeriesCount();
upperBoundSeries.addSeries(new XYSeries(i));
upperBoundSeries.getSeries(w).add(x - half_width, upper_bound);
upperBoundSeries.getSeries(w).add(x + half_width, upper_bound);
upperQ3Series.addSeries(new XYSeries(i));
upperQ3Series.getSeries(w).add(x, upper_bound);
upperQ3Series.getSeries(w).add(x, q3);
boxSeries.addSeries(new XYSeries(i));
boxSeries.getSeries(w).add(x - half_width, q1);
boxSeries.getSeries(w).add(x - half_width, q3);
boxSeries.getSeries(w).add(x + half_width, q3);
boxSeries.getSeries(w).add(x + half_width, q1);
q2Series.addSeries(new XYSeries(i));
q2Series.getSeries(w).add(x - half_width, q2);
q2Series.getSeries(w).add(x + half_width, q2);
lowerQ2Series.addSeries(new XYSeries(i));
lowerQ2Series.getSeries(w).add(x, q1);
lowerQ2Series.getSeries(w).add(x, lower_bound);
lowerBoundSeries.addSeries(new XYSeries(i));
lowerBoundSeries.getSeries(w).add(x - half_width, lower_bound);
lowerBoundSeries.getSeries(w).add(x + half_width, lower_bound);
}
meanDotSeries.addSeries(new XYSeries(i));
meanDotSeries.getSeries(i).add(x, mean);
}
final XYSeriesCollection seriesCollection = new XYSeriesCollection();
final int[] N = new int[10];
N[0] += addSeries(seriesCollection, meanDotSeries);
N[1] = N[0];
N[1] += addSeries(seriesCollection, boxplotSeries);
N[2] = N[1];
N[2] += addSeries(seriesCollection, upperBoundSeries);
N[2] += addSeries(seriesCollection, boxSeries);
N[2] += addSeries(seriesCollection, q2Series);
N[2] += addSeries(seriesCollection, lowerBoundSeries);
N[3] = N[2];
N[3] += addSeries(seriesCollection, upperQ3Series);
N[3] += addSeries(seriesCollection, lowerQ2Series);
addSeries(seriesCollection, lineSeries);
final JFreeChart chart = ChartFactory.createXYLineChart(null, // domain axis label
null, // range axis label
null, // data
seriesCollection, PlotOrientation.VERTICAL, // include legend
false, // tooltips?
true, // URL generator? Not required...
false);
final NumberAxis domainAxis = new NumberAxis("SNP Physical Position (Kb) [" + n + " SNPs]");
final NumberAxis rangeAxis = new NumberAxis("Estimated RF");
domainAxis.setTickUnit(new NumberTickUnit(50));
rangeAxis.setRange(-0.02, 0.48);
chart.getXYPlot().setDomainAxis(domainAxis);
chart.getXYPlot().setRangeAxis(rangeAxis);
final ChartPanel cp = new ChartPanel(chart, collinearChart.getWidth(), collinearChart.getHeight(), collinearChart.getWidth(), collinearChart.getHeight(), collinearChart.getWidth(), collinearChart.getHeight(), ChartPanel.DEFAULT_BUFFER_USED, true, true, true, true, true);
XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer() {
Stroke soild = new BasicStroke(2.0f);
Stroke dashed = new BasicStroke(1.0f, BasicStroke.CAP_BUTT, BasicStroke.JOIN_MITER, 10.0f, new float[] { 10.0f }, 0.0f);
@Override
public Stroke getItemStroke(int row, int column) {
if (row >= N[0] && row < N[1]) {
return new BasicStroke(stroke * 2);
} else if (row >= N[1] && row < N[2]) {
return new BasicStroke(stroke * 2);
} else {
return new BasicStroke(stroke / 2);
}
}
};
final Shape shape = new Ellipse2D.Double(-3.0, -3.0, 6.0, 6.0);
final String[] hex_str = new String[] { "#F8766D", "#7CAE00", "#00BFC4", "#C77CFF", "#B55D60", "#857AAA", "#5F9E6E", "#5975A4" };
// XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer();
for (int i = 0; i < seriesCollection.getSeriesCount(); i++) {
if (i >= N[3]) {
renderer.setSeriesPaint(i, Color.gray);
} else if (i >= N[2]) {
renderer.setSeriesPaint(i, Color.decode(hex_str[0]));
} else if (i >= N[1]) {
renderer.setSeriesPaint(i, Color.decode(hex_str[0]));
} else if (i >= N[0]) {
renderer.setSeriesPaint(i, Color.black);
} else {
renderer.setSeriesPaint(i, Color.decode(hex_str[4]));
renderer.setSeriesShapesVisible(i, true);
renderer.setSeriesShapesFilled(i, true);
renderer.setSeriesShape(i, shape);
}
}
renderer.setBaseShapesVisible(false);
renderer.setBaseShapesFilled(false);
chart.getXYPlot().setRenderer(renderer);
// chart.getXYPlot().setDatasetRenderingOrder(DatasetRenderingOrder.FORWARD);
chart.setBackgroundPaint(Color.WHITE);
chart.setBorderPaint(Color.WHITE);
cp.setPreferredSize(dim);
cp.setBorder(null);
collinearChart.add(cp);
jframe.add(collinearChart, position);
}
use of java.awt.BasicStroke in project Course_Generator by patrovite.
the class frmEditCurve method CreateChartProfile.
/**
* Creates the chart
* @param dataset Dataset to display
* @return Return a JFreeChart object
*/
private JFreeChart CreateChartProfile(XYDataset dataset) {
JFreeChart chart = ChartFactory.createXYAreaChart("", // "Slope" x axis label
bundle.getString("frmEditCurve.chart.slope"), // "speed" y axis label
bundle.getString("frmEditCurve.chart.speed") + " (" + Utils.uSpeed2String(settings.Unit, settings.isPace) + ")", // data
dataset, // include legend
PlotOrientation.VERTICAL, // include legend
false, // tooltips
true, // urls
false);
// Panel background color
chart.setBackgroundPaint(Color.white);
XYPlot plot = chart.getXYPlot();
plot.setBackgroundPaint(Color.white);
plot.setDomainGridlinePaint(Color.gray);
plot.setRangeGridlinePaint(Color.gray);
// XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer();
XYAreaRenderer renderer = new XYAreaRenderer();
// Green (safe color)
renderer.setSeriesPaint(0, new Color(0x99, 0xff, 0x00));
renderer.setOutline(true);
// Width of the outline
renderer.setSeriesOutlineStroke(0, new BasicStroke(2.0f));
plot.setRenderer(renderer);
return chart;
}
use of java.awt.BasicStroke in project abstools by abstools.
the class Figure method renderActor.
private void renderActor(Graphics2D g, int from, int to, int axis, int width) {
int ofs = 4;
int thickness = 4;
int left = axis - width / 2;
int right = axis + width / 2;
int height = to - from;
int arms = (int) (height * 0.4F);
int headDiameter = (int) (height * 0.3F);
int legs = (int) (height * 0.6F);
g.setColor(Color.BLACK);
// the head shadow
g.fillOval(axis - headDiameter / 2 + ofs, from + ofs, headDiameter, headDiameter);
g.setStroke(new BasicStroke(thickness));
// the body shadow
g.drawLine(axis + ofs, from + headDiameter, axis + ofs, from + legs);
// the arms shadow
g.drawLine(left + ofs, from + arms + ofs, right + ofs, from + arms + ofs);
// the left leg shadow
g.drawLine(axis + ofs, from + legs + ofs, left + ofs, to + ofs);
// the right leg shadow
g.drawLine(axis + (int) (1.5 * ofs), from + legs + ofs, right + (int) (1.5 * ofs) - 1, to + 1);
g.setStroke(solid);
g.setColor(Color.WHITE);
g.fillOval(axis - headDiameter / 2, from, headDiameter, headDiameter);
g.setColor(Color.BLACK);
g.drawOval(axis - headDiameter / 2, from, headDiameter, headDiameter);
Polygon poly = new Polygon();
poly.addPoint(axis - thickness / 2, from + headDiameter);
poly.addPoint(axis - thickness / 2, from + arms);
poly.addPoint(left, from + arms);
poly.addPoint(left, from + arms + thickness);
poly.addPoint(axis - thickness / 2, from + arms + thickness);
poly.addPoint(axis - thickness / 2, from + legs);
poly.addPoint(left, to);
poly.addPoint(left + thickness, to + thickness);
poly.addPoint(axis, from + legs + thickness);
poly.addPoint(right, to + thickness);
poly.addPoint(right + thickness, to);
poly.addPoint(axis + thickness / 2, from + legs);
poly.addPoint(axis + thickness / 2, from + arms + thickness);
poly.addPoint(right + thickness, from + arms + thickness);
poly.addPoint(right + thickness, from + arms);
poly.addPoint(axis + thickness / 2, from + arms);
poly.addPoint(axis + thickness / 2, from + headDiameter);
g.setColor(Color.WHITE);
g.fillPolygon(poly);
g.setColor(Color.BLACK);
g.drawPolygon(poly);
}
use of java.awt.BasicStroke in project Course_Generator by patrovite.
the class JPanelAnalysisTimeDist method CreateChart.
private JFreeChart CreateChart(XYDataset dataset1, XYDataset dataset2) {
JFreeChart chart = ChartFactory.createXYAreaChart("", // "Distance"
bundle.getString("JPanelAnalysisTimeDist.labelX"), // "Elevation"
bundle.getString("JPanelAnalysisTimeDist.labelY1"), // data
dataset1, // include legend
PlotOrientation.VERTICAL, // include legend
false, // tooltips
true, // urls
false);
// -- Background color
chart.setBackgroundPaint(Color.white);
chart.setAntiAlias(true);
XYPlot plot = (XYPlot) chart.getPlot();
plot.setBackgroundPaint(Color.white);
plot.setDomainGridlinePaint(Color.gray);
plot.setRangeGridlinePaint(Color.gray);
plot.setDomainAxisLocation(AxisLocation.BOTTOM_OR_RIGHT);
XYAreaRenderer renderer = new XYAreaRenderer();
renderer.setSeriesPaint(0, new Color(0x99, 0xff, 0x00));
renderer.setOutline(true);
renderer.setSeriesOutlineStroke(0, new BasicStroke(2.0f));
plot.setRenderer(0, renderer);
// "Time"
NumberAxis rangeAxis2 = new NumberAxis(bundle.getString("JPanelAnalysisTimeDist.labelY2"));
plot.setRangeAxis(1, rangeAxis2);
plot.setDataset(1, dataset2);
plot.setRangeAxis(1, rangeAxis2);
plot.mapDatasetToRangeAxis(1, 1);
StandardXYItemRenderer renderer2 = new StandardXYItemRenderer();
renderer2.setSeriesPaint(0, Color.red);
plot.setRenderer(1, renderer2);
// -- Select the display order
plot.setDatasetRenderingOrder(DatasetRenderingOrder.FORWARD);
return chart;
}
use of java.awt.BasicStroke in project pdfbox by apache.
the class PDFPrintable method print.
@Override
public int print(Graphics graphics, PageFormat pageFormat, int pageIndex) throws PrinterException {
if (pageIndex < 0 || pageIndex >= document.getNumberOfPages()) {
return NO_SUCH_PAGE;
}
try {
Graphics2D graphics2D = (Graphics2D) graphics;
PDPage page = document.getPage(pageIndex);
PDRectangle cropBox = getRotatedCropBox(page);
// the imageable area is the area within the page margins
final double imageableWidth = pageFormat.getImageableWidth();
final double imageableHeight = pageFormat.getImageableHeight();
double scale = 1;
if (scaling != Scaling.ACTUAL_SIZE) {
// scale to fit
double scaleX = imageableWidth / cropBox.getWidth();
double scaleY = imageableHeight / cropBox.getHeight();
scale = Math.min(scaleX, scaleY);
// only shrink to fit when enabled
if (scale > 1 && scaling == Scaling.SHRINK_TO_FIT) {
scale = 1;
}
// only stretch to fit when enabled
if (scale < 1 && scaling == Scaling.STRETCH_TO_FIT) {
scale = 1;
}
}
// set the graphics origin to the origin of the imageable area (i.e the margins)
graphics2D.translate(pageFormat.getImageableX(), pageFormat.getImageableY());
// center on page
if (center) {
graphics2D.translate((imageableWidth - cropBox.getWidth() * scale) / 2, (imageableHeight - cropBox.getHeight() * scale) / 2);
}
// rasterize to bitmap (optional)
Graphics2D printerGraphics = null;
BufferedImage image = null;
if (dpi > 0) {
float dpiScale = dpi / 72;
image = new BufferedImage((int) (imageableWidth * dpiScale / scale), (int) (imageableHeight * dpiScale / scale), BufferedImage.TYPE_INT_ARGB);
printerGraphics = graphics2D;
graphics2D = image.createGraphics();
// rescale
printerGraphics.scale(scale / dpiScale, scale / dpiScale);
scale = dpiScale;
}
// draw to graphics using PDFRender
AffineTransform transform = (AffineTransform) graphics2D.getTransform().clone();
graphics2D.setBackground(Color.WHITE);
renderer.setSubsamplingAllowed(subsamplingAllowed);
renderer.renderPageToGraphics(pageIndex, graphics2D, (float) scale);
// draw crop box
if (showPageBorder) {
graphics2D.setTransform(transform);
graphics2D.setClip(0, 0, (int) imageableWidth, (int) imageableHeight);
graphics2D.scale(scale, scale);
graphics2D.setColor(Color.GRAY);
graphics2D.setStroke(new BasicStroke(0.5f));
graphics.drawRect(0, 0, (int) cropBox.getWidth(), (int) cropBox.getHeight());
}
// draw rasterized bitmap (optional)
if (printerGraphics != null) {
printerGraphics.setBackground(Color.WHITE);
printerGraphics.clearRect(0, 0, image.getWidth(), image.getHeight());
printerGraphics.drawImage(image, 0, 0, null);
graphics2D.dispose();
}
return PAGE_EXISTS;
} catch (IOException e) {
throw new PrinterIOException(e);
}
}
Aggregations