/** * ************************************************************************************ Initialize * the canvas, and render all the vertical lines of the parallel coordinates * * @param g - the graphic2D object * ************************************************************************************ */ public void initializeCanvas(Graphics2D g) { // set the color gradients using the selected column default is the first column i.e. 0) this.setLineColors(); int x = init_x, y = init_y, miny = init_miny, maxy = init_maxy; // set background of the canvas to white g.setBackground(new Color(255, 240, 240)); g.clearRect(0, 0, CANVAS_WIDTH, CANVAS_HEIGHT); g.setStroke(new BasicStroke(0.3f)); // set the thickness of the stroke // render all vertical lines for (int i = 0; i < colCount; i++) { g.setColor(vertLinesColor); // set the color // render vertical lines line_height pixels high g.drawLine(x, miny, x, maxy); // draw small horizontal lines to mark the dimensions of the data on the vertical lines g.drawLine(x - 3, y, x + 3, y); g.drawLine(x - 3, y + line_height, x + 3, y + line_height); // render 2 vertical lines on the sides of the main vertical lines to form boxes around them. g.setColor(new Color(170, 150, 140, 100)); g.drawLine(x - 2, miny, x - 2, maxy); g.drawLine(x + 2, miny, x + 2, maxy); /** ************ Printing the Headings ************************ */ // set color used to print the headings g.setColor(new Color(0, 0, 0)); AffineTransform orig = g.getTransform(); // get the current transform double rotateRadian = 0, offset = 0, labelX, halfRotAngle = 0; rotateRadian = (headerAngle) * Math.PI / 180; // radians = degrees * pi/180 halfRotAngle = (headerAngle / 2.0) * Math.PI / 180; // compute the offset offset = 2 * Math.sin((halfRotAngle)) * (x - 10); // 2 * SOH to find the base of the isocelles triangle found labelX = (x - 10); // the 5 is to move the text a 5pixels to the left when it is rotated offset = Math.abs(offset); // rotateRadian = angle * Math.PI/180 ; //radians = degrees * pi/180 g.rotate(-rotateRadian); double xtrans = 0, ytrans = 0; double xrad = 0; /*find the distance of the x after the rotation. : i.e. find the distance where the base of the isoceles triangle * formed during the rotation forms a right-angle with the header of the rotated figure */ int isoAngle = (180 - headerAngle) / 2; xrad = (isoAngle) * Math.PI / 180; ytrans = Math.sin(xrad) * offset; xtrans = Math.sqrt(Math.pow(offset, 2) - Math.pow(ytrans, 2)); labelX = (x - 10) - xtrans; // (x-5) because we want the label to start a few pixels before the vertical // line g.drawString( tab.getColumnName(i), (int) labelX, (int) ((miny - 10) + ytrans)); // write the header on top of the line. Note the 10 is because we // wanted the text to be 30 pixels above the vertical line. // after writing the rotated text, continue with the normal rotation. g.setTransform(orig); /* Set the field dimensions. these dimensions represent the box around the vertical lines*/ verticalFields[i] = new VerticalFields( x - (verticalFieldWidth / 2), y - 20, line_height + 40, verticalFieldWidth); /*Filling of selection*/ if (verticalFieldsDragged[i] .getDragged()) { // if the column has been dragged, then fill the drag area verticalFieldsDragged[i].setX(verticalFields[i].getX()); verticalFieldsDragged[i].setFill(true); verticalFieldsDragged[i].draw(g); } else if (i == selectedColumn) { // if the whole column has been selected then fill the whole column verticalFields[i].setFill(true); verticalFields[i].draw(g); } x += separation; } // render top and bottom ovals at the endpoints of the vertical lines x = init_x; for (int i = 0; i < colCount; i++) { bottomOvals[i] = new SmallOvals(x - OVAL_WIDTH / 2, y + line_height + 20, OVAL_WIDTH, OVAL_HEIGHT); topOvals[i] = new SmallOvals(x - OVAL_WIDTH / 2, y - 20 - OVAL_HEIGHT, OVAL_WIDTH, OVAL_HEIGHT); topOvals[i].setLabel(tab.getColumnName(i)); bottomOvals[i].setLabel(tab.getColumnName(i)); topOvals[i].draw(g); bottomOvals[i].draw(g); x += separation; // the horizontal separation of the vertical lines. } }