use of org.jfree.chart.text.TextAnchor in project ES-LEI-2Sem-2022-Grupo-1 by tmrbo-iscte.
the class CategoryTickTest method testEquals.
/**
* Confirm that the equals method can distinguish all the required fields.
*/
@Test
public void testEquals() {
Comparable<String> c1 = "C1";
Comparable<String> c2 = "C2";
TextBlock tb1 = new TextBlock();
tb1.addLine(new TextLine("Block 1"));
TextBlock tb2 = new TextBlock();
tb1.addLine(new TextLine("Block 2"));
TextBlockAnchor tba1 = TextBlockAnchor.CENTER;
TextBlockAnchor tba2 = TextBlockAnchor.BOTTOM_CENTER;
TextAnchor ta1 = TextAnchor.CENTER;
TextAnchor ta2 = TextAnchor.BASELINE_LEFT;
CategoryTick t1 = new CategoryTick(c1, tb1, tba1, ta1, 1.0f);
CategoryTick t2 = new CategoryTick(c1, tb1, tba1, ta1, 1.0f);
assertEquals(t1, t2);
t1 = new CategoryTick(c2, tb1, tba1, ta1, 1.0f);
assertNotEquals(t1, t2);
t2 = new CategoryTick(c2, tb1, tba1, ta1, 1.0f);
assertEquals(t1, t2);
t1 = new CategoryTick(c2, tb2, tba1, ta1, 1.0f);
assertNotEquals(t1, t2);
t2 = new CategoryTick(c2, tb2, tba1, ta1, 1.0f);
assertEquals(t1, t2);
t1 = new CategoryTick(c2, tb2, tba2, ta1, 1.0f);
assertNotEquals(t1, t2);
t2 = new CategoryTick(c2, tb2, tba2, ta1, 1.0f);
assertEquals(t1, t2);
t1 = new CategoryTick(c2, tb2, tba2, ta2, 1.0f);
assertNotEquals(t1, t2);
t2 = new CategoryTick(c2, tb2, tba2, ta2, 1.0f);
assertEquals(t1, t2);
t1 = new CategoryTick(c2, tb2, tba2, ta2, 2.0f);
assertNotEquals(t1, t2);
t2 = new CategoryTick(c2, tb2, tba2, ta2, 2.0f);
assertEquals(t1, t2);
}
use of org.jfree.chart.text.TextAnchor in project ES-LEI-2Sem-2022-Grupo-1 by tmrbo-iscte.
the class PolarPlot method calculateTextAnchor.
/**
* Calculate the text position for the given degrees.
*
* @param angleDegrees the angle in degrees.
*
* @return The optimal text anchor.
*/
protected TextAnchor calculateTextAnchor(double angleDegrees) {
TextAnchor ta = TextAnchor.CENTER;
// normalize angle
double offset = this.angleOffset;
while (offset < 0.0) {
offset += 360.0;
}
double normalizedAngle = (((this.counterClockwise ? -1 : 1) * angleDegrees) + offset) % 360;
while (this.counterClockwise && (normalizedAngle < 0.0)) {
normalizedAngle += 360.0;
}
if (normalizedAngle == 0.0) {
ta = TextAnchor.CENTER_LEFT;
} else if (normalizedAngle > 0.0 && normalizedAngle < 90.0) {
ta = TextAnchor.TOP_LEFT;
} else if (normalizedAngle == 90.0) {
ta = TextAnchor.TOP_CENTER;
} else if (normalizedAngle > 90.0 && normalizedAngle < 180.0) {
ta = TextAnchor.TOP_RIGHT;
} else if (normalizedAngle == 180) {
ta = TextAnchor.CENTER_RIGHT;
} else if (normalizedAngle > 180.0 && normalizedAngle < 270.0) {
ta = TextAnchor.BOTTOM_RIGHT;
} else if (normalizedAngle == 270) {
ta = TextAnchor.BOTTOM_CENTER;
} else if (normalizedAngle > 270.0 && normalizedAngle < 360.0) {
ta = TextAnchor.BOTTOM_LEFT;
}
return ta;
}
use of org.jfree.chart.text.TextAnchor in project ES-LEI-2Sem-2022-Grupo-1 by tmrbo-iscte.
the class CrosshairOverlay method drawVerticalCrosshair.
/**
* Draws a crosshair vertically on the plot.
*
* @param g2 the graphics target.
* @param dataArea the data area.
* @param x the x-value in Java2D space.
* @param crosshair the crosshair.
*/
protected void drawVerticalCrosshair(Graphics2D g2, Rectangle2D dataArea, double x, Crosshair crosshair) {
if (x >= dataArea.getMinX() && x <= dataArea.getMaxX()) {
Line2D line = new Line2D.Double(x, dataArea.getMinY(), x, dataArea.getMaxY());
Paint savedPaint = g2.getPaint();
Stroke savedStroke = g2.getStroke();
g2.setPaint(crosshair.getPaint());
g2.setStroke(crosshair.getStroke());
g2.draw(line);
if (crosshair.isLabelVisible()) {
String label = crosshair.getLabelGenerator().generateLabel(crosshair);
if (label != null && !label.isEmpty()) {
Font savedFont = g2.getFont();
g2.setFont(crosshair.getLabelFont());
RectangleAnchor anchor = crosshair.getLabelAnchor();
Point2D pt = calculateLabelPoint(line, anchor, crosshair.getLabelXOffset(), crosshair.getLabelYOffset());
float xx = (float) pt.getX();
float yy = (float) pt.getY();
TextAnchor alignPt = textAlignPtForLabelAnchorV(anchor);
Shape hotspot = TextUtils.calculateRotatedStringBounds(label, g2, xx, yy, alignPt, 0.0, TextAnchor.CENTER);
if (!dataArea.contains(hotspot.getBounds2D())) {
anchor = flipAnchorH(anchor);
pt = calculateLabelPoint(line, anchor, crosshair.getLabelXOffset(), crosshair.getLabelYOffset());
xx = (float) pt.getX();
yy = (float) pt.getY();
alignPt = textAlignPtForLabelAnchorV(anchor);
hotspot = TextUtils.calculateRotatedStringBounds(label, g2, xx, yy, alignPt, 0.0, TextAnchor.CENTER);
}
g2.setPaint(crosshair.getLabelBackgroundPaint());
g2.fill(hotspot);
if (crosshair.isLabelOutlineVisible()) {
g2.setPaint(crosshair.getLabelOutlinePaint());
g2.setStroke(crosshair.getLabelOutlineStroke());
g2.draw(hotspot);
}
g2.setPaint(crosshair.getLabelPaint());
TextUtils.drawAlignedString(label, g2, xx, yy, alignPt);
g2.setFont(savedFont);
}
}
g2.setPaint(savedPaint);
g2.setStroke(savedStroke);
}
}
Aggregations