use of org.jfree.chart.plot.ValueAxisPlot in project nimbus by nimbus-org.
the class DateAxisTickUnitAdjusterService method adjust.
// AbstractTickUnitAdjusterServiceのJavaDoc
protected void adjust(ValueAxis axis) {
if (!(axis instanceof DateAxis)) {
throw new IllegalArgumentException("axis is not DateAxis.");
}
DateAxis dateAxis = (DateAxis) axis;
DateTickUnit orgTickUnit = dateAxis.getTickUnit();
int unit = orgTickUnit.getUnit();
if (autoRangeMinimumSizeEnabled) {
double autoRangeMinimumSize = Double.NaN;
switch(unit) {
case DateTickUnit.MILLISECOND:
autoRangeMinimumSize = 1d;
break;
case DateTickUnit.SECOND:
autoRangeMinimumSize = 1000d;
break;
case DateTickUnit.MINUTE:
autoRangeMinimumSize = 60d * 1000d;
break;
case DateTickUnit.HOUR:
autoRangeMinimumSize = 60d * 60d * 1000d;
break;
case DateTickUnit.DAY:
autoRangeMinimumSize = 24d * 60d * 60d * 1000d;
break;
case DateTickUnit.MONTH:
autoRangeMinimumSize = 31d * 24d * 60d * 60d * 1000d;
break;
case DateTickUnit.YEAR:
autoRangeMinimumSize = 365d * 24d * 60d * 60d * 1000d;
break;
default:
break;
}
if (!Double.isNaN(autoRangeMinimumSize)) {
Plot plot = dateAxis.getPlot();
if (plot instanceof ValueAxisPlot) {
ValueAxisPlot vap = (ValueAxisPlot) plot;
Range r = vap.getDataRange(dateAxis);
if (r == null) {
if (zeroLength > 0.0d) {
dateAxis.setAutoRangeMinimumSize(zeroLength);
}
} else {
dateAxis.setAutoRangeMinimumSize(autoRangeMinimumSize * (Double.isNaN(unitCountCommonDivisor) ? 1.0d : unitCountCommonDivisor) * 2);
}
} else {
dateAxis.setAutoRangeMinimumSize(autoRangeMinimumSize * (Double.isNaN(unitCountCommonDivisor) ? 1.0d : unitCountCommonDivisor) * 2);
}
}
}
double length = dateAxis.getRange().getLength();
// ミリ秒以外は計算
switch(unit) {
case DateTickUnit.SECOND:
// 秒
length = length / 1000d;
break;
case DateTickUnit.MINUTE:
// 分
length = length / (60d * 1000d);
break;
case DateTickUnit.HOUR:
// 時
length = length / (60d * 60d * 1000d);
break;
case DateTickUnit.DAY:
// 日
length = length / (24d * 60d * 60d * 1000d);
break;
case DateTickUnit.MONTH:
// 月
length = length / (28d * 24d * 60d * 60d * 1000d);
break;
case DateTickUnit.YEAR:
// 年
length = length / (365d * 24d * 60d * 60d * 1000d);
break;
default:
break;
}
double unitCount = length / displayGraduationCount;
if (unitCount <= 0d) {
// 1ずつ表示
unitCount = 1d;
} else {
unitCount = adjustUnitCountByCommonDivisor(axis, unitCount);
}
DateFormat newFormat = null;
if (format != null) {
newFormat = format;
} else {
newFormat = new SimpleDateFormat();
}
int newUnitCount = (int) Math.ceil(unitCount);
// 新しいTickUnitを設定
dateAxis.setTickUnit(new DateTickUnit(unit, newUnitCount, newFormat));
}
Aggregations