All Downloads are FREE. Search and download functionalities are using the official Maven repository.

eqtlmappingpipeline.graphics.ScatterPlot Maven / Gradle / Ivy

The newest version!
/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package eqtlmappingpipeline.graphics;

import java.awt.Color;
import java.awt.Dimension;
import java.awt.Font;
import java.awt.FontMetrics;
import java.awt.Graphics2D;
import java.awt.Polygon;
import java.awt.RenderingHints;
import java.awt.geom.AffineTransform;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import java.text.DecimalFormat;
import umcg.genetica.util.Primitives;

/**
 *
 * @author harm-jan
 */
public class ScatterPlot {
    private Color[] colors = new Color[10];

    public ScatterPlot(){
        colors[0] = new Color(122,217,76,200);
        colors[1] = new Color(72,199,207,200);
        colors[2] = new Color(194,161,77,200);
        colors[3] = new Color(190,190,190,130);
        colors[4] = new Color(250,38,207,200);
        colors[5] = new Color(0,0,0,200);
    }

//    private void drawPlot(String outDir, int i, int j, HashMap groupPC1T, HashMap groupPC1W, HashMap groupPC2T, HashMap groupPC2W, HashMap> groupValuesPC1, HashMap> groupValuesPC2, double maleTPC1, double maleTPC2, Vector maleValsPC1, Vector maleValsPC2, double maleWPC1, double maleWPC2, HashMap> genders, double maxXVal, double minXVal, double maxYVal, double minYVal) {
//
//        int width = 1000;
//        int height = 1000;
//        int margin = 100;
//
//        int x0 = margin;
//        int x1 = width - margin;
//
//        int innerWidth = x1 - x0;
//
//        int y0 = margin;
//        int y1 = height - margin;
//
//        int innerHeight = y1 - y0;
//
//        BufferedImage bimage = new BufferedImage(width, height + 100, BufferedImage.TYPE_INT_RGB);
//        Graphics2D g2d = bimage.createGraphics();
//
//        g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
//        g2d.setColor(new Color(255, 255, 255));
//        g2d.fillRect(0, 0, width, height+100);
//        g2d.setColor(new Color(128,128,128));
//
//        g2d.drawLine(x0, (int) Math.floor((double)height/2), innerWidth+x0, (int) Math.floor((double)height/2));       // PC1-axis
//
//        g2d.drawString("PC "+(i), x0, (int) Math.floor((double)height/2) + 15);
//
//        g2d.drawLine((int) Math.floor((double) width / 2), y0, (int) Math.floor((double) width / 2), height-y0);       // PC2-axis
//
//        int strWidth = getStringWidth("BMI", g2d, g2d.getFont());
//        drawText((int) Math.floor((double) width / 2) + 12, y0 + strWidth, -90, "BMI", g2d, g2d.getFont());
//
//        DecimalFormat df = new DecimalFormat("#.###");
//        DecimalFormat df2 = new DecimalFormat("0.##E0");
//
//        for(int g=0; g val1 = groupValuesPC1.get(group);
//            Vector val2 = groupValuesPC2.get(group);
//            Vector gen = genders.get(group);
//
//            g2d.setStroke(new BasicStroke(1.0f));
//            g2d.setPaint(new Color(190,190,190,190));
//
//            int x = 580;
//
//            for (int v=0; v= 0){
            g2d.drawLine(x0, y1, innerWidth+x0, y1);       // x-axis
            g2d.drawString(xDesc, x0, y1 - 12);
            g2d.drawString(df.format(minX), x0, y1 + 20);
            g2d.drawString(df.format(maxX), x1 - getStringWidth(df.format(maxX), g2d, g2d.getFont()), y1 + 20);
            g2d.drawString("0", distToYAxis + 10, y1 + 20); // plot 0;
            g2d.drawString(df.format(minY), distToYAxis + 10, y1 - 12); // plot 0;
            minY = 0;
        } else {
            g2d.drawLine(x0, (int) Math.floor((double)height/2), innerWidth+x0, (int) Math.floor((double)height/2));       // x-axis
            g2d.drawString(xDesc, x0, (int) Math.floor((double)height/2) - 15);
            g2d.drawString(df.format(minX), x0, (int) Math.floor((double)height/2) + 20);
            g2d.drawString("0", distToYAxis + 10, (int) Math.floor((double)height/2) + 20); // plot 0;
            g2d.drawString(df.format(minY), distToYAxis + 10, (int) Math.floor((double)height/2) - 20); // plot 0;
        }
    
        g2d.drawLine(distToYAxis, y0, distToYAxis, y1 );       // y-axis
        

        int strWidth = getStringWidth(yDesc, g2d, g2d.getFont());
        drawText(distToYAxis - 12, y0 + strWidth, -90, yDesc, g2d, g2d.getFont());

        Font f = g2d.getFont();

        Font font = new Font("Calibri", Font.BOLD, 30);
        g2d.setFont(font);
        String title = xDesc + " - " + yDesc;
        int theight = getStringHeight(title, g2d, font);
        g2d.drawString(title, x0, 0 + 10 + theight);

        font = new Font("Georgia", Font.BOLD, 20);
        g2d.setFont(font);
        g2d.drawString(subtitle, x0, 0 + 10 + theight + 30);


        g2d.setFont(f);
        //        DecimalFormat df = new DecimalFormat("#.###");
//        DecimalFormat df2 = new DecimalFormat("0.###E0");

        for(int i=0; i= 0){
            minY = 0;
            g2d.drawLine(x0, y1, innerWidth+x0, y1);       // x-axis
            g2d.drawString(xDesc, x0, y1 - 12);
            g2d.drawString(df.format(minX), x0, y1 + 20);
            g2d.drawString(df.format(maxX), x1 - getStringWidth(df.format(maxX), g2d, g2d.getFont()), y1 + 20);
            g2d.drawString("0", distToYAxis + 10, y1 + 20); // plot 0;
            g2d.drawString(df.format(minY), distToYAxis + 10, y1 - 12); // plot 0;
        } else {
            g2d.drawLine(x0, (int) Math.floor((double)height/2), innerWidth+x0, (int) Math.floor((double)height/2));       // x-axis
            g2d.drawString(xDesc, x0, (int) Math.floor((double)height/2) - 15);
            g2d.drawString(df.format(minX), x0, (int) Math.floor((double)height/2) + 20);
            g2d.drawString("0", distToYAxis + 10, (int) Math.floor((double)height/2) + 20); // plot 0;
            g2d.drawString(df.format(minY), distToYAxis + 10, (int) Math.floor((double)height/2) - 20); // plot 0;
        }

        g2d.drawLine(distToYAxis, y0, distToYAxis, y1 );       // y-axis

        int strWidth = getStringWidth(yDesc, g2d, g2d.getFont());
        drawText(distToYAxis - 12, y0 + strWidth, -90, yDesc, g2d, g2d.getFont());
        drawText(distToYAxis + 10, y0 + 10, 0, df.format(maxY), g2d, g2d.getFont());

        Font f = g2d.getFont();

        Font font = new Font("Calibri", Font.BOLD, 30);
        g2d.setFont(font);
        String title = xDesc + " - " + yDesc;
        int theight = getStringHeight(title, g2d, font);
        g2d.drawString(title, x0, 0 + 10 + theight);

        font = new Font("Georgia", Font.BOLD, 20);
        g2d.setFont(font);
        g2d.drawString(subtitle, x0, 0 + 10 + theight + 30);


        g2d.setFont(f);
        //        DecimalFormat df = new DecimalFormat("#.###");
//        DecimalFormat df2 = new DecimalFormat("0.###E0");

        for(int i=0; i




© 2015 - 2025 Weber Informatics LLC | Privacy Policy