use of org.jfree.chart.text.TextAnchor in project ES-LEI-2Sem-2022-Grupo-1 by tmrbo-iscte.
the class LogAxis method refreshTicksVertical.
/**
* Returns a list of ticks for an axis at the left or right 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 that the axis is aligned to ({@code null}
* not permitted).
*
* @return A list of ticks.
*/
protected List refreshTicksVertical(Graphics2D g2, Rectangle2D dataArea, RectangleEdge edge) {
Range range = getRange();
List ticks = new ArrayList();
Font tickLabelFont = getTickLabelFont();
g2.setFont(tickLabelFont);
TextAnchor textAnchor;
if (edge == RectangleEdge.RIGHT) {
textAnchor = TextAnchor.CENTER_LEFT;
} else {
textAnchor = TextAnchor.CENTER_RIGHT;
}
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 refreshTicksVertical.
/**
* 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 refreshTicksVertical(Graphics2D g2, Rectangle2D dataArea, RectangleEdge edge) {
List ticks = new java.util.ArrayList();
// get lower bound value:
double lowerBoundVal = getRange().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 = getRange().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 tickVal;
String tickLabel;
boolean zeroTickFlag = false;
for (int i = iBegCount; i <= iEndCount; i++) {
// for each tick with a label to be displayed
int jEndCount = 10;
if (i == iEndCount) {
jEndCount = 1;
}
for (int j = 0; j < jEndCount; j++) {
// for each tick to be displayed
if (this.smallLogFlag) {
// small log values in use
tickVal = Math.pow(10, i) + (Math.pow(10, i) * j);
if (j == 0) {
// first tick of group; create label text
if (this.log10TickLabelsFlag) {
// if flag then
// create "log10"-type label
tickLabel = "10^" + i;
} else {
// not "log10"-type label
if (this.expTickLabelsFlag) {
// if flag then
// create "1e#"-type label
tickLabel = "1e" + i;
} else {
// not "1e#"-type label
if (i >= 0) {
// if positive exponent then
// make integer
NumberFormat format = getNumberFormatOverride();
if (format != null) {
tickLabel = format.format(tickVal);
} else {
tickLabel = Long.toString((long) Math.rint(tickVal));
}
} else {
// negative exponent; create fractional value
// set exact number of fractional digits to
// be shown:
this.numberFormatterObj.setMaximumFractionDigits(-i);
// create tick label:
tickLabel = this.numberFormatterObj.format(tickVal);
}
}
}
} else {
// not first tick to be displayed
// no tick label
tickLabel = "";
}
} else {
// not small log values in use; allow for values <= 0
if (zeroTickFlag) {
// if did zero tick last iter then
--j;
}
// decrement to do 1.0 tick now
tickVal = (i >= 0) ? Math.pow(10, i) + (Math.pow(10, i) * j) : -(Math.pow(10, -i) - (Math.pow(10, -i - 1) * j));
if (j == 0) {
// first tick of group
if (!zeroTickFlag) {
// iteration
if (i > iBegCount && i < iEndCount && Math.abs(tickVal - 1.0) < 0.0001) {
// not first or last tick on graph and value
// is 1.0
// change value to 0.0
tickVal = 0.0;
// indicate zero tick
zeroTickFlag = true;
// create label for tick
tickLabel = "0";
} else {
// create label for tick:
if (this.log10TickLabelsFlag) {
// create "log10"-type label
tickLabel = (((i < 0) ? "-" : "") + "10^" + Math.abs(i));
} else {
if (this.expTickLabelsFlag) {
// create "1e#"-type label
tickLabel = (((i < 0) ? "-" : "") + "1e" + Math.abs(i));
} else {
NumberFormat format = getNumberFormatOverride();
if (format != null) {
tickLabel = format.format(tickVal);
} else {
tickLabel = Long.toString((long) Math.rint(tickVal));
}
}
}
}
} else {
// did zero tick last iteration
// no label
tickLabel = "";
// clear flag
zeroTickFlag = false;
}
} else {
// not first tick of group
// no label
tickLabel = "";
// make sure flag cleared
zeroTickFlag = false;
}
}
if (tickVal > upperBoundVal) {
// if past highest data value then exit method
return ticks;
}
if (tickVal >= lowerBoundVal - SMALL_LOG_VALUE) {
// tick value not below lowest data value
TextAnchor anchor;
TextAnchor rotationAnchor;
double angle = 0.0;
if (isVerticalTickLabels()) {
if (edge == RectangleEdge.LEFT) {
anchor = TextAnchor.BOTTOM_CENTER;
rotationAnchor = TextAnchor.BOTTOM_CENTER;
angle = -Math.PI / 2.0;
} else {
anchor = TextAnchor.BOTTOM_CENTER;
rotationAnchor = TextAnchor.BOTTOM_CENTER;
angle = Math.PI / 2.0;
}
} else {
if (edge == RectangleEdge.LEFT) {
anchor = TextAnchor.CENTER_RIGHT;
rotationAnchor = TextAnchor.CENTER_RIGHT;
} else {
anchor = TextAnchor.CENTER_LEFT;
rotationAnchor = TextAnchor.CENTER_LEFT;
}
}
// create tick object and add to list:
ticks.add(new NumberTick(tickVal, tickLabel, anchor, rotationAnchor, angle));
}
}
}
return ticks;
}
use of org.jfree.chart.text.TextAnchor in project ES-LEI-2Sem-2022-Grupo-1 by tmrbo-iscte.
the class NumberAxis method refreshTicksVertical.
/**
* 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.
*/
protected List refreshTicksVertical(Graphics2D g2, Rectangle2D dataArea, RectangleEdge edge) {
List result = new java.util.ArrayList();
result.clear();
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;
TextAnchor rotationAnchor;
double angle = 0.0;
if (isVerticalTickLabels()) {
if (edge == RectangleEdge.LEFT) {
anchor = TextAnchor.BOTTOM_CENTER;
rotationAnchor = TextAnchor.BOTTOM_CENTER;
angle = -Math.PI / 2.0;
} else {
anchor = TextAnchor.BOTTOM_CENTER;
rotationAnchor = TextAnchor.BOTTOM_CENTER;
angle = Math.PI / 2.0;
}
} else {
if (edge == RectangleEdge.LEFT) {
anchor = TextAnchor.CENTER_RIGHT;
rotationAnchor = TextAnchor.CENTER_RIGHT;
} else {
anchor = TextAnchor.CENTER_LEFT;
rotationAnchor = TextAnchor.CENTER_LEFT;
}
}
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;
}
use of org.jfree.chart.text.TextAnchor in project ES-LEI-2Sem-2022-Grupo-1 by tmrbo-iscte.
the class DateAxis method refreshTicksHorizontal.
/**
* Recalculates the ticks for the date axis.
*
* @param g2 the graphics device.
* @param dataArea the area in which the data is to be drawn.
* @param edge the location of the axis.
*
* @return A list of ticks.
*/
protected List<? extends Tick> refreshTicksHorizontal(Graphics2D g2, Rectangle2D dataArea, RectangleEdge edge) {
List<DateTick> result = new ArrayList<>();
Font tickLabelFont = getTickLabelFont();
g2.setFont(tickLabelFont);
if (isAutoTickUnitSelection()) {
selectAutoTickUnit(g2, dataArea, edge);
}
DateTickUnit unit = getTickUnit();
Date tickDate = calculateLowestVisibleTickValue(unit);
Date upperDate = getMaximumDate();
boolean hasRolled = false;
while (tickDate.before(upperDate)) {
// could add a flag to make the following correction optional...
if (!hasRolled) {
tickDate = correctTickDateForPosition(tickDate, unit, this.tickMarkPosition);
}
long lowestTickTime = tickDate.getTime();
long distance = unit.addToDate(tickDate, this.timeZone).getTime() - lowestTickTime;
int minorTickSpaces = getMinorTickCount();
if (minorTickSpaces <= 0) {
minorTickSpaces = unit.getMinorTickCount();
}
for (int minorTick = 1; minorTick < minorTickSpaces; minorTick++) {
long minorTickTime = lowestTickTime - distance * minorTick / minorTickSpaces;
if (minorTickTime > 0 && getRange().contains(minorTickTime) && (!isHiddenValue(minorTickTime))) {
result.add(new DateTick(TickType.MINOR, new Date(minorTickTime), "", TextAnchor.TOP_CENTER, TextAnchor.CENTER, 0.0));
}
}
if (!isHiddenValue(tickDate.getTime())) {
// work out the value, label and position
String tickLabel;
DateFormat formatter = getDateFormatOverride();
if (formatter != null) {
tickLabel = formatter.format(tickDate);
} else {
tickLabel = this.tickUnit.dateToString(tickDate);
}
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;
}
}
DateTick tick = new DateTick(tickDate, tickLabel, anchor, rotationAnchor, angle);
result.add(tick);
hasRolled = false;
long currentTickTime = tickDate.getTime();
tickDate = unit.addToDate(tickDate, this.timeZone);
long nextTickTime = tickDate.getTime();
for (int minorTick = 1; minorTick < minorTickSpaces; minorTick++) {
long minorTickTime = currentTickTime + (nextTickTime - currentTickTime) * minorTick / minorTickSpaces;
if (getRange().contains(minorTickTime) && (!isHiddenValue(minorTickTime))) {
result.add(new DateTick(TickType.MINOR, new Date(minorTickTime), "", TextAnchor.TOP_CENTER, TextAnchor.CENTER, 0.0));
}
}
} else {
tickDate = unit.rollDate(tickDate, this.timeZone);
hasRolled = true;
}
}
return result;
}
use of org.jfree.chart.text.TextAnchor in project ES-LEI-2Sem-2022-Grupo-1 by tmrbo-iscte.
the class DateAxis method refreshTicksVertical.
/**
* Recalculates the ticks for the date axis.
*
* @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.
*/
protected List<? extends Tick> refreshTicksVertical(Graphics2D g2, Rectangle2D dataArea, RectangleEdge edge) {
List<DateTick> result = new ArrayList<>();
Font tickLabelFont = getTickLabelFont();
g2.setFont(tickLabelFont);
if (isAutoTickUnitSelection()) {
selectAutoTickUnit(g2, dataArea, edge);
}
DateTickUnit unit = getTickUnit();
Date tickDate = calculateLowestVisibleTickValue(unit);
Date upperDate = getMaximumDate();
boolean hasRolled = false;
while (tickDate.before(upperDate)) {
// could add a flag to make the following correction optional...
if (!hasRolled) {
tickDate = correctTickDateForPosition(tickDate, unit, this.tickMarkPosition);
}
long lowestTickTime = tickDate.getTime();
long distance = unit.addToDate(tickDate, this.timeZone).getTime() - lowestTickTime;
int minorTickSpaces = getMinorTickCount();
if (minorTickSpaces <= 0) {
minorTickSpaces = unit.getMinorTickCount();
}
for (int minorTick = 1; minorTick < minorTickSpaces; minorTick++) {
long minorTickTime = lowestTickTime - distance * minorTick / minorTickSpaces;
if (minorTickTime > 0 && getRange().contains(minorTickTime) && (!isHiddenValue(minorTickTime))) {
result.add(new DateTick(TickType.MINOR, new Date(minorTickTime), "", TextAnchor.TOP_CENTER, TextAnchor.CENTER, 0.0));
}
}
if (!isHiddenValue(tickDate.getTime())) {
// work out the value, label and position
String tickLabel;
DateFormat formatter = getDateFormatOverride();
if (formatter != null) {
tickLabel = formatter.format(tickDate);
} else {
tickLabel = this.tickUnit.dateToString(tickDate);
}
TextAnchor anchor, rotationAnchor;
double angle = 0.0;
if (isVerticalTickLabels()) {
anchor = TextAnchor.BOTTOM_CENTER;
rotationAnchor = TextAnchor.BOTTOM_CENTER;
if (edge == RectangleEdge.LEFT) {
angle = -Math.PI / 2.0;
} else {
angle = Math.PI / 2.0;
}
} else {
if (edge == RectangleEdge.LEFT) {
anchor = TextAnchor.CENTER_RIGHT;
rotationAnchor = TextAnchor.CENTER_RIGHT;
} else {
anchor = TextAnchor.CENTER_LEFT;
rotationAnchor = TextAnchor.CENTER_LEFT;
}
}
DateTick tick = new DateTick(tickDate, tickLabel, anchor, rotationAnchor, angle);
result.add(tick);
hasRolled = false;
long currentTickTime = tickDate.getTime();
tickDate = unit.addToDate(tickDate, this.timeZone);
long nextTickTime = tickDate.getTime();
for (int minorTick = 1; minorTick < minorTickSpaces; minorTick++) {
long minorTickTime = currentTickTime + (nextTickTime - currentTickTime) * minorTick / minorTickSpaces;
if (getRange().contains(minorTickTime) && (!isHiddenValue(minorTickTime))) {
result.add(new DateTick(TickType.MINOR, new Date(minorTickTime), "", TextAnchor.TOP_CENTER, TextAnchor.CENTER, 0.0));
}
}
} else {
tickDate = unit.rollDate(tickDate, this.timeZone);
hasRolled = true;
}
}
return result;
}
Aggregations