int nVerticalAxes = 0;
List<Double> hTicks = null;
List<Double> vTicks = null;
IAxis hAxis = null;
IAxis vAxis = null;
for (int axis = 0; axis < getAxesCount(); axis++) {
if (getDimensionForAxis(axis) == 0) {
nHorizontalAxes++;
}
if (getDimensionForAxis(axis) == 1) {
nVerticalAxes++;
}
}
for (int axis = 0; axis < getAxesCount(); axis++) {
if (getDimensionForAxis(axis) == 0) {
// X-AXIS
// get the extension of left axes
int startX = x + getWidthLeftAxes(g);
// get the extension of right axes
int endX = x + width - getWidthRightAxes(g);
// draw axis from startX to endX horizontal
int y1 = y + height - getHeightLowerAxes(g, axis);
drawHorizontalAxis(g, axis, startX, endX, y1,
getHeightLowerAxes(g, axis));
if (nHorizontalAxes == 1) {
hTicks =
renderer.getTicksForAxis(g, getAxis(axis), startX, y, endX
- startX, getHeightLowerAxes(g, axis), true, false);
hAxis = getAxis(axis);
}
}
if (getDimensionForAxis(axis) == 1) {
// Y-AXIS
// left if axis % 2 == 0 right otherwise
boolean leftAxis = axis % 2 != 0;
int startY = 10; // margin
int endY = y + height - getHeightLowerAxes(g, axis);
if (leftAxis) {
int w = getWidthLeftAxis(g, axis);
leftAxisPos += w;
int startX = x + widthLeftAxes - leftAxisPos;
leftAxisPos += marginX;
drawLeftAxis(g, axis, startX, w + startX, startY, endY);
if (nVerticalAxes == 1) {
vTicks =
renderer.getTicksForAxis(g, getAxis(axis), startX, startY, w,
endY - startY, false, true);
vAxis = getAxis(axis);
}
} else {
int w = getWidthRightAxis(g, axis);
int startX = x + width - widthRightAxes + rightAxisPos;
rightAxisPos += w + marginX;
drawRightAxis(g, axis, startX, w + startX, startY, endY);
}
}
}
// GradientPaint paint =
// new GradientPaint(new Point(x, y + height), Color.LIGHT_GRAY,
// new Point(x, y), Color.white);
// g.setPaint(paint);
g.setColor(Color.WHITE);
Point plotOrigin = getPlotOrigin(g, x, y, width, height);
Dimension plotDimension = getPlotDimension(g, x, y, width, height);
g.fillRect(plotOrigin.x, plotOrigin.y, plotDimension.width,
plotDimension.height);
// g.setPaint(null);
// draw grid
if (hTicks != null && hAxis != null) {
g.setColor(Color.LIGHT_GRAY);
g.setStroke(new BasicStroke(1f, BasicStroke.CAP_BUTT,
BasicStroke.JOIN_BEVEL, 0, new float[] { 3, 3 }, 0));
for (Double d : hTicks) {
double v = hAxis.transform(d) * plotDimension.getWidth();
g.drawLine((int) (plotOrigin.x + v), plotOrigin.y,
(int) (plotOrigin.x + v), plotDimension.height + plotOrigin.y);
}
}
if (vTicks != null && vAxis != null) {
g.setColor(Color.LIGHT_GRAY);
g.setStroke(new BasicStroke(1f, BasicStroke.CAP_BUTT,
BasicStroke.JOIN_BEVEL, 0, new float[] { 3, 3 }, 0));
for (Double d : vTicks) {
double v = vAxis.transform(d) * plotDimension.getHeight();
g.drawLine(plotOrigin.x,
(int) (plotOrigin.y + plotDimension.height - v), plotOrigin.x
+ plotDimension.width, (int) (plotOrigin.y
+ plotDimension.height - v));
}