Sectors2DPlacer placer;
Vector<Object> s3d;
Graphics2D g2;
DPoint graphOrigin;
ArrayList<String> labels;
ArrayList<DPoint> labelPoints, valuesOnY, valuesOnX;
// If g is not instance of Graphic2D, aborts method
if (g instanceof Graphics2D) {
g2 = (Graphics2D) g;
} else {
return;
}
g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
RenderingHints.VALUE_ANTIALIAS_ON);
try {
graphOrigin = new DPoint(GRAPH_LEFT_MARGIN,
(getHeight() - GRAPH_BOTTOM_MARGIN));
plane = new CartesianPositivePlane(
g2,
graphOrigin,
(int) (getHeight() - GRAPH_TOP_MARGIN - GRAPH_BOTTOM_MARGIN),
(int) (getHeight() - GRAPH_TOP_MARGIN - GRAPH_BOTTOM_MARGIN),
1, 1);
} catch (Exception e) {
return;
}
s3d = data.getResults().getSaturationSectors();
labels = new ArrayList<String>();
labelPoints = new ArrayList<DPoint>();
valuesOnY = new ArrayList<DPoint>();
valuesOnX = new ArrayList<DPoint>();
for (int i = 0; i < s3d.size(); i++) {
String label;
DPoint sectorBegin, sectorEnd, labelPoint;
FinalSect2D sect;// Current sector
sect = (FinalSect2D) s3d.get(i);
sectorBegin = new DPoint(sect.getBeta1(), sect.getBeta11());
sectorEnd = new DPoint(sect.getBeta2(), sect.getBeta22());
// labelPoint is the mean between sectorBegin and sectorEnd
labelPoint = new DPoint(plane.getTrueX((sectorBegin.getX())
+ ((sectorEnd.getX() - sectorBegin.getX()) / 2)),
plane.getTrueY((sectorEnd.getY())
+ ((sectorBegin.getY() - sectorEnd.getY()) / 2)));
valuesOnY.add(sectorBegin);
valuesOnX.add(sectorBegin);
switch (sect.getstation().size()) {
case 1:
g2.setColor(SINGLE);
break;
case 2:
g2.setColor(DOUBLE);
break;
default:
g2.setColor(MORE);
}
g2.setStroke(SECTORS);
plane.drawSegment(sectorBegin, sectorEnd);
g2.setStroke(DOTTED);
g2.setColor(Color.BLACK);
plane.drawProjectionOnTheXAxis(sectorBegin);
plane.drawProjectionOnTheXAxis(sectorEnd);
plane.drawProjectionOnTheYAxis(sectorEnd);
plane.drawProjectionOnTheYAxis(sectorBegin);
label = labelGenerator(sect.getstation());
labels.add(label);
labelPoints.add(labelPoint);
}
g2.setColor(Color.BLACK);
g2.setStroke(LINES);
// We draw the plane
plane.draw(data.getClassNames()[0] + " %", data.getClassNames()[1]
+ " %");
if (!valuesOnY.contains(new DPoint(0, 1)))
valuesOnY.add(new DPoint(0, 1));
if (!valuesOnX.contains(new DPoint(1, 0)))
valuesOnX.add(new DPoint(1, 0));
if (!valuesOnX.contains(new DPoint(0, 0)))
valuesOnX.add(0, new DPoint(0, 0));
plane.drawValuesOnXAxis(valuesOnX);
plane.drawValuesOnYAxis(valuesOnY);
// We draw the labels
placer = new Sectors2DPlacer(labels, labelPoints);
placer.place(g2, plane.getTrueX(1) + DISTANCE_BETWEEN_GRAPH_AND_LABELS);
if (tooltip != null) {
DPoint graphPoint = plane.getGraphPointFromTruePoint(tooltip);
String content = FORMATTER.format(graphPoint.getX()) + ", "
+ FORMATTER.format(graphPoint.getY());
Rectangle2D bounds = g.getFontMetrics().getStringBounds(content, g);
g.setColor(TOOL_TIP_COLOR);
g.fillRect((int) tooltip.getX(), (int) tooltip.getY()
- (int) bounds.getHeight() + 1, (int) bounds.getWidth(),
(int) bounds.getHeight() + 2);