import org.jrobin.core.Util; //导入方法依赖的package包/类
private void initGraphPeriodAndSize(Range range, int width, int height, RrdGraphDef graphDef) {
// ending timestamp is the (current) timestamp in seconds
// starting timestamp will be adjusted for each graph
final long endTime;
final long startTime;
if (range.getPeriod() == null) {
// si endDate à la date du jour, alors on ne dépasse pas l'heure courante
endTime = Math.min(range.getEndDate().getTime() / 1000, Util.getTime());
startTime = range.getStartDate().getTime() / 1000;
} else {
endTime = Util.getTime();
startTime = endTime - range.getPeriod().getDurationSeconds();
}
final String label = getLabel();
final String titleStart;
if (label.length() > 31 && width <= 200) {
// si le label est trop long, on raccourci le titre sinon il ne rentre pas
titleStart = label;
} else {
titleStart = label + " - " + range.getLabel();
}
final String titleEnd;
if (width > 400) {
if (range.getPeriod() == null) {
titleEnd = " - " + I18N.getFormattedString("sur", getApplication());
} else {
titleEnd = " - " + I18N.getCurrentDate() + ' '
+ I18N.getFormattedString("sur", getApplication());
}
} else {
titleEnd = "";
if (range.getPeriod() == null) {
// si période entre 2 dates et si pas de zoom,
// alors on réduit de 2 point la fonte du titre pour qu'il rentre dans le cadre
graphDef.setLargeFont(graphDef.getLargeFont()
.deriveFont(graphDef.getLargeFont().getSize2D() - 2f));
}
}
graphDef.setStartTime(startTime);
graphDef.setEndTime(endTime);
graphDef.setTitle(titleStart + titleEnd);
graphDef.setFirstDayOfWeek(
Calendar.getInstance(I18N.getCurrentLocale()).getFirstDayOfWeek());
// or if the user locale patch is merged we should do:
// (https://sourceforge.net/tracker/?func=detail&aid=3403733&group_id=82668&atid=566807)
//graphDef.setLocale(I18N.getCurrentLocale());
// rq : la largeur et la hauteur de l'image sont plus grandes que celles fournies
// car jrobin ajoute la largeur et la hauteur des textes et autres
graphDef.setWidth(width);
graphDef.setHeight(height);
if (width <= 100) {
graphDef.setNoLegend(true);
graphDef.setUnitsLength(0);
graphDef.setShowSignature(false);
graphDef.setTitle(null);
}
//graphDef.setColor(RrdGraphConstants.COLOR_BACK, new GradientPaint(0, 0,
//RrdGraphConstants.DEFAULT_BACK_COLOR.brighter(), 0, height,
//RrdGraphConstants.DEFAULT_BACK_COLOR));
}