📄 rrdgraphdeftemplate.java
字号:
validateTagsOnlyOnce(spanNode, new String[] {"start", "end"});
String startStr = getChildValue(spanNode, "start");
String endStr = getChildValue(spanNode, "end");
long[] span = Util.getTimestamps(startStr, endStr);
rrdGraphDef.setStartTime(span[0]);
rrdGraphDef.setEndTime(span[1]);
}
private void resolveOptions(Node rootOptionNode) throws RrdException {
validateTagsOnlyOnce(rootOptionNode, new String[] {
"anti_aliasing", "use_pool", "time_grid", "value_grid", "alt_y_grid", "alt_y_mrtg",
"no_minor_grid", "alt_autoscale", "alt_autoscale_max", "units_exponent", "units_length",
"vertical_label", "width", "height", "interlaced", "image_info", "image_format",
"image_quality", "background_image", "overlay_image", "unit", "lazy",
"min_value", "max_value", "rigid", "base", "logarithmic", "colors",
"no_legend", "only_graph", "force_rules_legend", "title", "step", "fonts",
"first_day_of_week", "signature"
});
Node[] optionNodes = getChildNodes(rootOptionNode);
for (Node optionNode : optionNodes) {
String option = optionNode.getNodeName();
if (option.equals("use_pool")) {
rrdGraphDef.setPoolUsed(getValueAsBoolean(optionNode));
}
else if (option.equals("anti_aliasing")) {
rrdGraphDef.setAntiAliasing(getValueAsBoolean(optionNode));
}
else if (option.equals("time_grid")) {
resolveTimeGrid(optionNode);
}
else if (option.equals("value_grid")) {
resolveValueGrid(optionNode);
}
else if (option.equals("no_minor_grid")) {
rrdGraphDef.setNoMinorGrid(getValueAsBoolean(optionNode));
}
else if (option.equals("alt_y_grid")) {
rrdGraphDef.setAltYGrid(getValueAsBoolean(optionNode));
}
else if (option.equals("alt_y_mrtg")) {
rrdGraphDef.setAltYMrtg(getValueAsBoolean(optionNode));
}
else if (option.equals("alt_autoscale")) {
rrdGraphDef.setAltAutoscale(getValueAsBoolean(optionNode));
}
else if (option.equals("alt_autoscale_max")) {
rrdGraphDef.setAltAutoscaleMax(getValueAsBoolean(optionNode));
}
else if (option.equals("units_exponent")) {
rrdGraphDef.setUnitsExponent(getValueAsInt(optionNode));
}
else if (option.equals("units_length")) {
rrdGraphDef.setUnitsLength(getValueAsInt(optionNode));
}
else if (option.equals("vertical_label")) {
rrdGraphDef.setVerticalLabel(getValue(optionNode));
}
else if (option.equals("width")) {
rrdGraphDef.setWidth(getValueAsInt(optionNode));
}
else if (option.equals("height")) {
rrdGraphDef.setHeight(getValueAsInt(optionNode));
}
else if (option.equals("interlaced")) {
rrdGraphDef.setInterlaced(getValueAsBoolean(optionNode));
}
else if (option.equals("image_info")) {
rrdGraphDef.setImageInfo(getValue(optionNode));
}
else if (option.equals("image_format")) {
rrdGraphDef.setImageFormat(getValue(optionNode));
}
else if (option.equals("image_quality")) {
rrdGraphDef.setImageQuality((float) getValueAsDouble(optionNode));
}
else if (option.equals("background_image")) {
rrdGraphDef.setBackgroundImage(getValue(optionNode));
}
else if (option.equals("overlay_image")) {
rrdGraphDef.setOverlayImage(getValue(optionNode));
}
else if (option.equals("unit")) {
rrdGraphDef.setUnit(getValue(optionNode));
}
else if (option.equals("lazy")) {
rrdGraphDef.setLazy(getValueAsBoolean(optionNode));
}
else if (option.equals("min_value")) {
rrdGraphDef.setMinValue(getValueAsDouble(optionNode));
}
else if (option.equals("max_value")) {
rrdGraphDef.setMaxValue(getValueAsDouble(optionNode));
}
else if (option.equals("rigid")) {
rrdGraphDef.setRigid(getValueAsBoolean(optionNode));
}
else if (option.equals("base")) {
rrdGraphDef.setBase(getValueAsDouble(optionNode));
}
else if (option.equals("logarithmic")) {
rrdGraphDef.setLogarithmic(getValueAsBoolean(optionNode));
}
else if (option.equals("colors")) {
resolveColors(optionNode);
}
else if (option.equals("no_legend")) {
rrdGraphDef.setNoLegend(getValueAsBoolean(optionNode));
}
else if (option.equals("only_graph")) {
rrdGraphDef.setOnlyGraph(getValueAsBoolean(optionNode));
}
else if (option.equals("force_rules_legend")) {
rrdGraphDef.setForceRulesLegend(getValueAsBoolean(optionNode));
}
else if (option.equals("title")) {
rrdGraphDef.setTitle(getValue(optionNode));
}
else if (option.equals("step")) {
rrdGraphDef.setStep(getValueAsLong(optionNode));
}
else if (option.equals("fonts")) {
resolveFonts(optionNode);
}
else if (option.equals("first_day_of_week")) {
int dayIndex = resolveFirstDayOfWeek(getValue(optionNode));
rrdGraphDef.setFirstDayOfWeek(dayIndex);
}
else if (option.equals("signature")) {
rrdGraphDef.setShowSignature(getValueAsBoolean(optionNode));
}
}
}
private int resolveFirstDayOfWeek(String firstDayOfWeek) throws RrdException {
if (firstDayOfWeek.equalsIgnoreCase("sunday")) {
return SUNDAY;
}
else if (firstDayOfWeek.equalsIgnoreCase("monday")) {
return MONDAY;
}
else if (firstDayOfWeek.equalsIgnoreCase("tuesday")) {
return TUESDAY;
}
else if (firstDayOfWeek.equalsIgnoreCase("wednesday")) {
return WEDNESDAY;
}
else if (firstDayOfWeek.equalsIgnoreCase("thursday")) {
return THURSDAY;
}
else if (firstDayOfWeek.equalsIgnoreCase("friday")) {
return FRIDAY;
}
else if (firstDayOfWeek.equalsIgnoreCase("saturday")) {
return SATURDAY;
}
throw new RrdException("Never heard for this day of week: " + firstDayOfWeek);
}
private void resolveFonts(Node parentNode) throws RrdException {
validateTagsOnlyOnce(parentNode, new String[] {"small_font", "large_font"});
Node[] childNodes = getChildNodes(parentNode);
for (Node childNode : childNodes) {
String nodeName = childNode.getNodeName();
if (nodeName.equals("small_font")) {
rrdGraphDef.setSmallFont(resolveFont(childNode));
}
else if (nodeName.equals("large_font")) {
rrdGraphDef.setLargeFont(resolveFont(childNode));
}
}
}
private Font resolveFont(Node parentNode) throws RrdException {
validateTagsOnlyOnce(parentNode, new String[] {"name", "style", "size"});
String name = null, style = null;
int size = 0;
Node[] childNodes = getChildNodes(parentNode);
for (Node childNode : childNodes) {
String nodeName = childNode.getNodeName();
if (nodeName.equals("name")) {
name = getValue(childNode);
}
else if (nodeName.equals("style")) {
style = getValue(childNode).toLowerCase();
}
else if (nodeName.equals("size")) {
size = getValueAsInt(childNode);
}
}
if (name != null && style != null && size > 0) {
boolean isItalic = style.contains("italic"), isBold = style.contains("bold");
int fstyle = Font.PLAIN;
if (isItalic && isBold) {
fstyle = Font.BOLD + Font.ITALIC;
}
else if (isItalic) {
fstyle = Font.ITALIC;
}
else if (isBold) {
fstyle = Font.BOLD;
}
return new Font(name, fstyle, size);
}
else {
throw new RrdException("Incomplete font specification");
}
}
private void resolveColors(Node parentNode) throws RrdException {
validateTagsOnlyOnce(parentNode, COLOR_NAMES);
Node[] childNodes = getChildNodes(parentNode);
for (Node childNode : childNodes) {
String colorName = childNode.getNodeName();
rrdGraphDef.setColor(colorName, getValueAsColor(childNode));
}
}
private void resolveValueGrid(Node parentNode) throws RrdException {
validateTagsOnlyOnce(parentNode, new String[] {"show_grid", "grid_step", "label_factor"});
boolean showGrid = true;
double gridStep = Double.NaN;
int NOT_SET = Integer.MIN_VALUE, labelFactor = NOT_SET;
Node[] childNodes = getChildNodes(parentNode);
for (Node childNode : childNodes) {
String nodeName = childNode.getNodeName();
if (nodeName.equals("show_grid")) {
showGrid = getValueAsBoolean(childNode);
}
else if (nodeName.equals("grid_step")) {
gridStep = getValueAsDouble(childNode);
}
else if (nodeName.equals("label_factor")) {
labelFactor = getValueAsInt(childNode);
}
}
rrdGraphDef.setDrawYGrid(showGrid);
if (!Double.isNaN(gridStep) && labelFactor != NOT_SET) {
rrdGraphDef.setValueAxis(gridStep, labelFactor);
}
else if (!Double.isNaN(gridStep) || labelFactor != NOT_SET) {
throw new RrdException("Incomplete value axis settings");
}
}
private void resolveTimeGrid(Node parentNode) throws RrdException {
validateTagsOnlyOnce(parentNode, new String[] {
"show_grid", "minor_grid_unit",
"minor_grid_unit_count", "major_grid_unit",
"major_grid_unit_count", "label_unit", "label_unit_count",
"label_span", "label_format"
});
boolean showGrid = true;
final int NOT_SET = Integer.MIN_VALUE;
int minorGridUnit = NOT_SET, minorGridUnitCount = NOT_SET,
majorGridUnit = NOT_SET, majorGridUnitCount = NOT_SET,
labelUnit = NOT_SET, labelUnitCount = NOT_SET, labelSpan = NOT_SET;
String labelFormat = null;
Node[] childNodes = getChildNodes(parentNode);
for (Node childNode : childNodes) {
String nodeName = childNode.getNodeName();
if (nodeName.equals("show_grid")) {
showGrid = getValueAsBoolean(childNode);
}
else if (nodeName.equals("minor_grid_unit")) {
minorGridUnit = resolveTimeUnit(getValue(childNode));
}
else if (nodeName.equals("minor_grid_unit_count")) {
minorGridUnitCount = getValueAsInt(childNode);
}
else if (nodeName.equals("major_grid_unit")) {
majorGridUnit = resolveTimeUnit(getValue(childNode));
}
else if (nodeName.equals("major_grid_unit_count")) {
majorGridUnitCount = getValueAsInt(childNode);
}
else if (nodeName.equals("label_unit")) {
labelUnit = resolveTimeUnit(getValue(childNode));
}
else if (nodeName.equals("label_unit_count")) {
labelUnitCount = getValueAsInt(childNode);
}
else if (nodeName.equals("label_span")) {
labelSpan = getValueAsInt(childNode);
}
else if (nodeName.equals("label_format")) {
labelFormat = getValue(childNode);
}
}
rrdGraphDef.setDrawXGrid(showGrid);
if (minorGridUnit != NOT_SET && minorGridUnitCount != NOT_SET &&
majorGridUnit != NOT_SET && majorGridUnitCount != NOT_SET &&
labelUnit != NOT_SET && labelUnitCount != NOT_SET && labelSpan != NOT_SET && labelFormat != null) {
rrdGraphDef.setTimeAxis(minorGridUnit, minorGridUnitCount, majorGridUnit, majorGridUnitCount,
labelUnit, labelUnitCount, labelSpan, labelFormat);
}
else if (minorGridUnit != NOT_SET || minorGridUnitCount != NOT_SET ||
majorGridUnit != NOT_SET || majorGridUnitCount != NOT_SET ||
labelUnit != NOT_SET || labelUnitCount != NOT_SET || labelSpan != NOT_SET || labelFormat != null) {
throw new RrdException("Incomplete time axis settings");
}
}
private int resolveTimeUnit(String unit) throws RrdException {
if (unit.equalsIgnoreCase("second")) {
return RrdGraphConstants.SECOND;
}
else if (unit.equalsIgnoreCase("minute")) {
return RrdGraphConstants.MINUTE;
}
else if (unit.equalsIgnoreCase("hour")) {
return RrdGraphConstants.HOUR;
}
else if (unit.equalsIgnoreCase("day")) {
return RrdGraphConstants.DAY;
}
else if (unit.equalsIgnoreCase("week")) {
return RrdGraphConstants.WEEK;
}
else if (unit.equalsIgnoreCase("month")) {
return RrdGraphConstants.MONTH;
}
else if (unit.equalsIgnoreCase("year")) {
return RrdGraphConstants.YEAR;
}
throw new RrdException("Unknown time unit specified: " + unit);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -