// The height of the label... (found by taking cos(angle) of the longest string) public int getMaxLabelWidth(Graphics g) { int ret = Integer.MIN_VALUE; Graphics2D g2D = (Graphics2D) g; g2D.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); FontMetrics fm = g.getFontMetrics(font); for (String[] label1 : labels) { for (int j = 0; j < labels[0].length; j++) { if (visibleLabels[j + 1] && fm.stringWidth(label1[j]) > ret) { ret = fm.stringWidth(label1[j]); } } } int titleHeight = title.getHeight(g); // Font f = title.getFont(); if (ret > 0) { ret = (int) (ret * Math.sin(DEG2RAD * rotation)); } else { ret = 0; } // System.out.print("width: "+(ret*Math.sin(DEG2RAD*rotation))); return ret + offset + fm.getHeight() + titleHeight; // return titleHeight ; }
protected void drawHAxis(Graphics g) { Graphics lg; int i; int j; int x0, y0, x1, y1; int direction; // int tempOffset; double minor_step; if (position == TOP) { direction = 1; } else { direction = -1; } Color c; double val; double minor; if (axiscolor != null) { g.setColor(axiscolor); } g.drawLine(amin.x, amin.y, amax.x, amax.y); // System.out.print("\ndrawing til x: "+amax.x); minor_step = label_step / (minor_tic_count + 1); val = label_start; ylocations = new int[labels.length]; for (i = 0; i < labels.length; i++) { // if( val >= vmin && val <= vmax ) { y0 = amin.y; // x0 = amin.x + (int)( ( val - minimum ) * scale); // x0 = amin.x + (int)(( (amax.x - amin.x - endLength(g))/( labels[0].length-1 ))*i); x0 = amin.x + (int) (((amax.x - amin.x) / (labels.length - 1)) * i); if (paintGrid) { c = g.getColor(); if (gridcolor != null) { g.setColor(gridcolor); } if (transparency != 255) { Graphics2D g2d = (Graphics2D) g; Paint pn = g2d.getPaint(); if (gridcolor != null) { g.setColor( new Color( gridcolor.getRed(), gridcolor.getGreen(), gridcolor.getBlue(), (int) transparency)); } } if ((!(i == 0 && dropFirstGridLine)) && (!(i == labels.length - 1 && dropLastGridLine))) { g.drawLine(x0, y0, x0, y0 + data_window.height * direction); } g.setColor(c); } x1 = x0; y1 = y0 + major_tic_size * direction; g.drawLine(x0, y0, x1, y1); if (TICS_IN_BOTH_ENDS) { g.drawLine( x0, y0 + data_window.height * direction, x0, y0 + data_window.height * direction + major_tic_size); } ylocations[i] = x0; // } minor = val + minor_step; /* * * for(j=0; j<minor_tic_count; j++) { * * //if( minor >= vmin && minor <= vmax ) { * * y0 = amin.y; * * x0 = amin.x + (int)( ( minor - minimum ) * scale); * * if( paintGrid ) { * * c = g.getColor(); * * if(gridcolor != null) g.setColor(gridcolor); * * g.drawLine(x0,y0,x0,y0+data_window.height*direction); * * g.setColor(c); * * } * * x1 = x0; * * y1 = y0 + minor_tic_size*direction; * * g.drawLine(x0,y0,x1,y1); * * if(TICS_IN_BOTH_ENDS) * g.drawLine(x0,y0+data_window.height*direction,x0,y0+data_window.height*direction+minor_tic_size); * * // } * * minor += minor_step; * * } * */ val += label_step; } /* * * if(position == TOP ) { * * tempOffset = - label.getLeading(g) - label.getDescent(g); * * } else { * * tempOffset = + label.getLeading(g) + label.getAscent(g); * * } * */ val = label_start; g.setFont(font); Graphics2D g2D = (Graphics2D) g; g2D.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); FontMetrics fm = g.getFontMetrics(font); int labelWidth = fm.getHeight(); // int labelWidth=16; // System.out.print("\n"+labelWidth); // int additionalSpace = 0; // if(rotation=40) additionalSpace = // double height = Math.sin(DEG2RAD*rotation)*labelWidth; // double additionalSpace = labelWidth/Math.sin(DEG2RAD*(rotation)); double additionalSpace = 0; int height = 0; // int visibleLabs = 0; for (int k = 1; k < labels[0].length; k++) { if (visibleLabels[k]) { visibleLabs++; } } int beg = (visibleLabs * labelWidth) - (4 * (visibleLabs - 1)); beg = beg / 2; Color before = g.getColor(); for (i = 0; i < labels.length; i++) { if (groupColors != null) { g.setColor(groupColors[i]); } else { g.setColor(Color.GRAY); // new Color(180, 180, 180)); } y0 = amin.y + offset; // x0 = amin.x + (int)(( (amax.x - amin.x)/( labels[0].length))*i); x0 = amin.x + (int) (((amax.x - amin.x) / (labels.length - 1)) * i); // x0 = amin.x + (int)(( (amax.x - amin.x - endLength(g))/( labels[0].length-1 ))*i); // int labellength =((int)((amax.x - amin.x)/( labels[0].length)))*labels[0].length ; // int endpoint = amin.x +endLength(g)+labellength; // g.drawLine( endpoint,y0-4,endpoint,y0+4 ); x0 = x0 - beg; // x0=x0-beg; for (j = 0; j < labels[0].length; j++) { if (visibleLabels[j + 1]) { drawRotatedLabel(labels[i][j], g, false, x0, y0, rotation); x0 += (labelWidth); } } } g.setColor(before); // Graphics2D g2=(Graphics2D)g; // g2.rotate(45); if (!title.isNull()) { if (position == TOP) { y0 = amin.y - label.getLeading(g) - label.getDescent(g) - title.getLeading(g) - title.getDescent(g); } else { y0 = amax.y + label.getLeading(g) + label.getAscent(g) + title.getLeading(g) + title.getAscent(g); } x0 = amin.x + (amax.x - amin.x) / 2; // y0=amax.y+width+3; y0 = amax.y + this.getMaxLabelWidth(g) + 6 - (title.getHeight(g)); // Graphics2D g2D = (Graphics2D) g; // g2D.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, // RenderingHints.VALUE_TEXT_ANTIALIAS_ON); // title.setFont(null); if (axiscolor != null) { title.setColor(axiscolor); } title.draw(g, x0, y0, ChartLabel.CENTER); } }