use of org.jfree.chart.text.TextAnchor in project ES-LEI-2Sem-2022-Grupo-1 by tmrbo-iscte.
the class PolarPlot method refreshAngleTicks.
/**
* Generates a list of tick values for the angular tick marks.
*
* @return A list of {@link NumberTick} instances.
*/
protected List<ValueTick> refreshAngleTicks() {
List<ValueTick> ticks = new ArrayList<>();
for (double currentTickVal = 0.0; currentTickVal < 360.0; currentTickVal += this.angleTickUnit.getSize()) {
TextAnchor ta = calculateTextAnchor(currentTickVal);
NumberTick tick = new NumberTick(currentTickVal, this.angleTickUnit.valueToString(currentTickVal), ta, TextAnchor.CENTER, 0.0);
ticks.add(tick);
}
return ticks;
}
use of org.jfree.chart.text.TextAnchor in project ES-LEI-2Sem-2022-Grupo-1 by tmrbo-iscte.
the class CategoryTickTest method testHashCode.
/**
* Two objects that are equal are required to return the same hashCode.
*/
@Test
public void testHashCode() {
Comparable<String> c1 = "C1";
TextBlock tb1 = new TextBlock();
tb1.addLine(new TextLine("Block 1"));
tb1.addLine(new TextLine("Block 2"));
TextBlockAnchor tba1 = TextBlockAnchor.CENTER;
TextAnchor ta1 = TextAnchor.CENTER;
CategoryTick t1 = new CategoryTick(c1, tb1, tba1, ta1, 1.0f);
CategoryTick t2 = new CategoryTick(c1, tb1, tba1, ta1, 1.0f);
assertEquals(t1, t2);
int h1 = t1.hashCode();
int h2 = t2.hashCode();
assertEquals(h1, h2);
}
use of org.jfree.chart.text.TextAnchor in project ES-LEI-2Sem-2022-Grupo-1 by tmrbo-iscte.
the class LogAxis method refreshTicksHorizontal.
/**
* Returns a list of ticks for an axis at the top or bottom of the chart.
*
* @param g2 the graphics device ({@code null} not permitted).
* @param dataArea the data area ({@code null} not permitted).
* @param edge the edge ({@code null} not permitted).
*
* @return A list of ticks.
*/
protected List refreshTicksHorizontal(Graphics2D g2, Rectangle2D dataArea, RectangleEdge edge) {
Range range = getRange();
List ticks = new ArrayList();
Font tickLabelFont = getTickLabelFont();
g2.setFont(tickLabelFont);
TextAnchor textAnchor;
if (edge == RectangleEdge.TOP) {
textAnchor = TextAnchor.BOTTOM_CENTER;
} else {
textAnchor = TextAnchor.TOP_CENTER;
}
if (isAutoTickUnitSelection()) {
selectAutoTickUnit(g2, dataArea, edge);
}
int minorTickCount = this.tickUnit.getMinorTickCount();
double unit = getTickUnit().getSize();
double index = Math.ceil(calculateLog(getRange().getLowerBound()) / unit);
double start = index * unit;
double end = calculateLog(getUpperBound());
double current = start;
boolean hasTicks = (this.tickUnit.getSize() > 0.0) && !Double.isInfinite(start);
while (hasTicks && current <= end) {
double v = calculateValueNoINF(current);
if (range.contains(v)) {
ticks.add(new LogTick(TickType.MAJOR, v, createTickLabel(v), textAnchor));
}
// add minor ticks (for gridlines)
double next = Math.pow(this.base, current + this.tickUnit.getSize());
for (int i = 1; i < minorTickCount; i++) {
double minorV = v + i * ((next - v) / minorTickCount);
if (range.contains(minorV)) {
ticks.add(new LogTick(TickType.MINOR, minorV, null, textAnchor));
}
}
current = current + this.tickUnit.getSize();
}
return ticks;
}
use of org.jfree.chart.text.TextAnchor in project ES-LEI-2Sem-2022-Grupo-1 by tmrbo-iscte.
the class LogarithmicAxis method refreshTicksHorizontal.
/**
* Calculates the positions of the tick labels for the axis, storing the
* results in the tick label list (ready for drawing).
*
* @param g2 the graphics device.
* @param dataArea the area in which the plot should be drawn.
* @param edge the location of the axis.
*
* @return A list of ticks.
*/
@Override
protected List refreshTicksHorizontal(Graphics2D g2, Rectangle2D dataArea, RectangleEdge edge) {
List ticks = new java.util.ArrayList();
Range range = getRange();
// get lower bound value:
double lowerBoundVal = range.getLowerBound();
// then set to a small value (don't allow <= 0):
if (this.smallLogFlag && lowerBoundVal < SMALL_LOG_VALUE) {
lowerBoundVal = SMALL_LOG_VALUE;
}
// get upper bound value
double upperBoundVal = range.getUpperBound();
// get log10 version of lower bound and round to integer:
int iBegCount = (int) Math.rint(switchedLog10(lowerBoundVal));
// get log10 version of upper bound and round to integer:
int iEndCount = (int) Math.rint(switchedLog10(upperBoundVal));
if (iBegCount == iEndCount && iBegCount > 0 && Math.pow(10, iBegCount) > lowerBoundVal) {
// only 1 power of 10 value, it's > 0 and its resulting
// tick value will be larger than lower bound of data
// decrement to generate more ticks
--iBegCount;
}
double currentTickValue;
String tickLabel;
boolean zeroTickFlag = false;
for (int i = iBegCount; i <= iEndCount; i++) {
// for each power of 10 value; create ten ticks
for (int j = 0; j < 10; ++j) {
// for each tick to be displayed
if (this.smallLogFlag) {
// small log values in use; create numeric value for tick
currentTickValue = Math.pow(10, i) + (Math.pow(10, i) * j);
if (this.expTickLabelsFlag || (i < 0 && currentTickValue > 0.0 && currentTickValue < 1.0)) {
// generating tick value between 0 & 1; show fewer
if (j == 0 || (i > -4 && j < 2) || currentTickValue >= upperBoundVal) {
// first tick of series, or not too small a value and
// one of first 3 ticks, or last tick to be displayed
// set exact number of fractional digits to be shown
// (no effect if showing "1e#"-style ticks):
this.numberFormatterObj.setMaximumFractionDigits(-i);
// create tick label (force use of fmt obj):
tickLabel = makeTickLabel(currentTickValue, true);
} else {
// no tick label to be shown
tickLabel = "";
}
} else {
// tick value not between 0 & 1
// show tick label if it's the first or last in
// the set, or if it's 1-5; beyond that show
// fewer as the values get larger:
tickLabel = (j < 1 || (i < 1 && j < 5) || (j < 4 - i) || currentTickValue >= upperBoundVal) ? makeTickLabel(currentTickValue) : "";
}
} else {
// not small log values in use; allow for values <= 0
if (zeroTickFlag) {
// if did zero tick last iter then
// decrement to do 1.0 tick now
--j;
}
// calculate power-of-ten value for tick:
currentTickValue = (i >= 0) ? Math.pow(10, i) + (Math.pow(10, i) * j) : -(Math.pow(10, -i) - (Math.pow(10, -i - 1) * j));
if (!zeroTickFlag) {
// did not do zero tick last iteration
if (Math.abs(currentTickValue - 1.0) < 0.0001 && lowerBoundVal <= 0.0 && upperBoundVal >= 0.0) {
// tick value is 1.0 and 0.0 is within data range
// set tick value to zero
currentTickValue = 0.0;
// indicate zero tick
zeroTickFlag = true;
}
} else {
// did zero tick last iteration
// clear flag
zeroTickFlag = false;
}
// create tick label string:
// show tick label if "1e#"-style and it's one
// of the first two, if it's the first or last
// in the set, or if it's 1-5; beyond that
// show fewer as the values get larger:
tickLabel = ((this.expTickLabelsFlag && j < 2) || j < 1 || (i < 1 && j < 5) || (j < 4 - i) || currentTickValue >= upperBoundVal) ? makeTickLabel(currentTickValue) : "";
}
if (currentTickValue > upperBoundVal) {
// if past highest data value then exit
return ticks;
// method
}
if (currentTickValue >= lowerBoundVal - SMALL_LOG_VALUE) {
// tick value not below lowest data value
TextAnchor anchor;
TextAnchor rotationAnchor;
double angle = 0.0;
if (isVerticalTickLabels()) {
anchor = TextAnchor.CENTER_RIGHT;
rotationAnchor = TextAnchor.CENTER_RIGHT;
if (edge == RectangleEdge.TOP) {
angle = Math.PI / 2.0;
} else {
angle = -Math.PI / 2.0;
}
} else {
if (edge == RectangleEdge.TOP) {
anchor = TextAnchor.BOTTOM_CENTER;
rotationAnchor = TextAnchor.BOTTOM_CENTER;
} else {
anchor = TextAnchor.TOP_CENTER;
rotationAnchor = TextAnchor.TOP_CENTER;
}
}
Tick tick = new NumberTick(currentTickValue, tickLabel, anchor, rotationAnchor, angle);
ticks.add(tick);
}
}
}
return ticks;
}
use of org.jfree.chart.text.TextAnchor in project ES-LEI-2Sem-2022-Grupo-1 by tmrbo-iscte.
the class NumberAxis method refreshTicksHorizontal.
/**
* Calculates the positions of the tick labels for the axis, storing the
* results in the tick label list (ready for drawing).
*
* @param g2 the graphics device.
* @param dataArea the area in which the data should be drawn.
* @param edge the location of the axis.
*
* @return A list of ticks.
*/
protected List refreshTicksHorizontal(Graphics2D g2, Rectangle2D dataArea, RectangleEdge edge) {
List result = new java.util.ArrayList();
Font tickLabelFont = getTickLabelFont();
g2.setFont(tickLabelFont);
if (isAutoTickUnitSelection()) {
selectAutoTickUnit(g2, dataArea, edge);
}
TickUnit tu = getTickUnit();
double size = tu.getSize();
int count = calculateVisibleTickCount();
double lowestTickValue = calculateLowestVisibleTickValue();
if (count <= ValueAxis.MAXIMUM_TICK_COUNT) {
int minorTickSpaces = getMinorTickCount();
if (minorTickSpaces <= 0) {
minorTickSpaces = tu.getMinorTickCount();
}
for (int minorTick = 1; minorTick < minorTickSpaces; minorTick++) {
double minorTickValue = lowestTickValue - size * minorTick / minorTickSpaces;
if (getRange().contains(minorTickValue)) {
result.add(new NumberTick(TickType.MINOR, minorTickValue, "", TextAnchor.TOP_CENTER, TextAnchor.CENTER, 0.0));
}
}
for (int i = 0; i < count; i++) {
double currentTickValue = lowestTickValue + (i * size);
String tickLabel;
NumberFormat formatter = getNumberFormatOverride();
if (formatter != null) {
tickLabel = formatter.format(currentTickValue);
} else {
tickLabel = getTickUnit().valueToString(currentTickValue);
}
TextAnchor anchor, rotationAnchor;
double angle = 0.0;
if (isVerticalTickLabels()) {
anchor = TextAnchor.CENTER_RIGHT;
rotationAnchor = TextAnchor.CENTER_RIGHT;
if (edge == RectangleEdge.TOP) {
angle = Math.PI / 2.0;
} else {
angle = -Math.PI / 2.0;
}
} else {
if (edge == RectangleEdge.TOP) {
anchor = TextAnchor.BOTTOM_CENTER;
rotationAnchor = TextAnchor.BOTTOM_CENTER;
} else {
anchor = TextAnchor.TOP_CENTER;
rotationAnchor = TextAnchor.TOP_CENTER;
}
}
Tick tick = new NumberTick(currentTickValue, tickLabel, anchor, rotationAnchor, angle);
result.add(tick);
double nextTickValue = lowestTickValue + ((i + 1) * size);
for (int minorTick = 1; minorTick < minorTickSpaces; minorTick++) {
double minorTickValue = currentTickValue + (nextTickValue - currentTickValue) * minorTick / minorTickSpaces;
if (getRange().contains(minorTickValue)) {
result.add(new NumberTick(TickType.MINOR, minorTickValue, "", TextAnchor.TOP_CENTER, TextAnchor.CENTER, 0.0));
}
}
}
}
return result;
}
Aggregations