⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 rrdgraphdef.java

📁 jrobin,使用纯java实现的RRD数据库,使用RRD数据库来统计数据.
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
	 * @param rrdPath   Path to RRD file
	 * @param dsName	Datasource name in the specified RRD file
	 * @param consolFun Consolidation function (AVERAGE, MIN, MAX, LAST)
	 */
	public void datasource(String name, String rrdPath, String dsName, String consolFun) {
		sources.add(new Def(name, rrdPath, dsName, consolFun));
	}

	/**
	 * Defines virtual datasource. This datasource can then be used
	 * in other methods like {@link #datasource(String, String)} or
	 * {@link #gprint(String, String, String)}.
	 *
	 * @param name	  Source name
	 * @param rrdPath   Path to RRD file
	 * @param dsName	Datasource name in the specified RRD file
	 * @param consolFun Consolidation function (AVERAGE, MIN, MAX, LAST)
	 * @param backend   Backend to be used while fetching data from a RRD file.
	 */
	public void datasource(String name, String rrdPath, String dsName, String consolFun, String backend) {
		sources.add(new Def(name, rrdPath, dsName, consolFun, backend));
	}

	/**
	 * Create a new virtual datasource by evaluating a mathematical
	 * expression, specified in Reverse Polish Notation (RPN).
	 *
	 * @param name		  Source name
	 * @param rpnExpression RPN expression.
	 */
	public void datasource(String name, String rpnExpression) {
		sources.add(new CDef(name, rpnExpression));
	}

	/**
	 * Creates a new (static) virtual datasouce. The value of the datasource is constant. This value is
	 * evaluated by applying the given consolidation function to another virtual datasource.
	 *
	 * @param name	  Source name
	 * @param defName   Other source name
	 * @param consolFun Consolidation function to be applied to other datasource.
	 */
	public void datasource(String name, String defName, String consolFun) {
		sources.add(new SDef(name, defName, consolFun));
	}

	/**
	 * Creates a new (plottable) datasource. Datasource values are obtained from the given plottable
	 * object.
	 *
	 * @param name	  Source name.
	 * @param plottable Plottable object.
	 */
	public void datasource(String name, Plottable plottable) {
		sources.add(new PDef(name, plottable));
	}

	/**
	 * Calculates the chosen consolidation function CF over the given datasource
	 * and creates the result by using the given format string.  In
	 * the format string there should be a '%[l]f', '%[l]g' or '%[l]e' marker in
	 * the place where the number should be printed.
	 * <p/>
	 * If an additional '%s' is found AFTER the marker, the value will be
	 * scaled and an appropriate SI magnitude unit will be printed in
	 * place of the '%s' marker. The scaling will take the '--base' argu-
	 * ment into consideration!
	 * <p/>
	 * If a '%S' is used instead of a '%s', then instead of calculating
	 * the appropriate SI magnitude unit for this value, the previously
	 * calculated SI magnitude unit will be used.  This is useful if you
	 * want all the values in a print statement to have the same SI magni-
	 * tude unit.  If there was no previous SI magnitude calculation made,
	 * then '%S' behaves like a '%s', unless the value is 0, in which case
	 * it does not remember a SI magnitude unit and a SI magnitude unit
	 * will only be calculated when the next '%s' is seen or the next '%S'
	 * for a non-zero value.
	 * <p/>
	 * Print results are collected in the {@link RrdGraphInfo} object which is retrieved
	 * from the {@link RrdGraph object} once the graph is created.
	 *
	 * @param srcName   Virtual source name
	 * @param consolFun Consolidation function to be applied to the source
	 * @param format	Format string (like "average = %10.3f %s")
	 */
	public void print(String srcName, String consolFun, String format) {
		comments.add(new PrintText(srcName, consolFun, format, false));
	}

	/**
	 * This method does basically the same thing as {@link #print(String, String, String)},
	 * but the result is printed on the graph itself, below the chart area.
	 *
	 * @param srcName   Virtual source name
	 * @param consolFun Consolidation function to be applied to the source
	 * @param format	Format string (like "average = %10.3f %s")
	 */
	public void gprint(String srcName, String consolFun, String format) {
		comments.add(new PrintText(srcName, consolFun, format, true));
	}

	/**
	 * Comment to be printed on the graph.
	 *
	 * @param text Comment text
	 */
	public void comment(String text) {
		comments.add(new CommentText(text));
	}

	/**
	 * Draws a horizontal rule into the graph and optionally adds a legend
	 *
	 * @param value  Position of the rule
	 * @param color  Rule color
	 * @param legend Legend text. If null, legend text will be omitted.
	 */
	public void hrule(double value, Paint color, String legend) {
		hrule(value, color, legend, 1.0F);
	}

	/**
	 * Draws a horizontal rule into the graph and optionally adds a legend
	 *
	 * @param value  Position of the rule
	 * @param color  Rule color
	 * @param legend Legend text. If null, legend text will be omitted.
	 * @param width  Rule width
	 */
	public void hrule(double value, Paint color, String legend, float width) {
		LegendText legendText = new LegendText(color, legend);
		comments.add(legendText);
		plotElements.add(new HRule(value, color, legendText, width));
	}

	/**
	 * Draws a vertical rule into the graph and optionally adds a legend
	 *
	 * @param timestamp Position of the rule (seconds since epoch)
	 * @param color	 Rule color
	 * @param legend	Legend text. Use null to omit the text.
	 */
	public void vrule(long timestamp, Paint color, String legend) {
		vrule(timestamp, color, legend, 1.0F);
	}

	/**
	 * Draws a vertical rule into the graph and optionally adds a legend
	 *
	 * @param timestamp Position of the rule (seconds since epoch)
	 * @param color	 Rule color
	 * @param legend	Legend text. Use null to omit the text.
	 * @param width	 Rule width
	 */
	public void vrule(long timestamp, Paint color, String legend, float width) {
		LegendText legendText = new LegendText(color, legend);
		comments.add(legendText);
		plotElements.add(new VRule(timestamp, color, legendText, width));
	}

	/**
	 * Plots requested data as a line, using the color and the line width specified.
	 *
	 * @param srcName Virtual source name
	 * @param color   Line color
	 * @param legend  Legend text
	 * @param width   Line width (default: 1.0F)
	 */
	public void line(String srcName, Paint color, String legend, float width) {
		LegendText legendText = new LegendText(color, legend);
		comments.add(legendText);
		plotElements.add(new Line(srcName, color, width));
	}

	/**
	 * Plots requested data as a line, using the color specified. Line width is assumed to be
	 * 1.0F.
	 *
	 * @param srcName Virtual source name
	 * @param color   Line color
	 * @param legend  Legend text
	 */
	public void line(String srcName, Paint color, String legend) {
		line(srcName, color, legend, 1F);
	}

	/**
	 * Plots requested data in the form of the filled area starting from zero, using
	 * the color specified.
	 *
	 * @param srcName Virtual source name.
	 * @param color   Color of the filled area.
	 * @param legend  Legend text.
	 */
	public void area(String srcName, Paint color, String legend) {
		LegendText legendText = new LegendText(color, legend);
		comments.add(legendText);
		plotElements.add(new Area(srcName, color));
	}

	/**
	 * Does the same as {@link #line(String, java.awt.Paint, String)},
	 * but the graph gets stacked on top of the
	 * previous LINE, AREA or STACK graph. Depending on the type of the
	 * previous graph, the STACK will be either a LINE or an AREA.  This
	 * obviously implies that the first STACK must be preceded by an AREA
	 * or LINE.
	 * <p/>
	 * Note, that when you STACK onto *UNKNOWN* data, JRobin will not
	 * draw any graphics ... *UNKNOWN* is not zero.
	 *
	 * @param srcName Virtual source name
	 * @param color   Stacked graph color
	 * @param legend  Legend text
	 * @throws RrdException Thrown if this STACK has no previously defined AREA, STACK or LINE
	 *                      graph bellow it.
	 */
	public void stack(String srcName, Paint color, String legend) throws RrdException {
		// find parent AREA or LINE
		SourcedPlotElement parent = null;
		for (int i = plotElements.size() - 1; i >= 0; i--) {
			PlotElement plotElement = plotElements.get(i);
			if (plotElement instanceof SourcedPlotElement) {
				parent = (SourcedPlotElement) plotElement;
				break;
			}
		}
		if (parent == null) {
			throw new RrdException("You have to stack graph onto something (line or area)");
		}
		else {
			LegendText legendText = new LegendText(color, legend);
			comments.add(legendText);
			plotElements.add(new Stack(parent, srcName, color));
		}
	}

	/**
	 * Sets visibility of the X-axis grid.
	 *
	 * @param drawXGrid True if X-axis grid should be created (default), false otherwise.
	 */
	public void setDrawXGrid(boolean drawXGrid) {
		this.drawXGrid = drawXGrid;
	}

	/**
	 * Sets visibility of the Y-axis grid.
	 *
	 * @param drawYGrid True if Y-axis grid should be created (default), false otherwise.
	 */
	public void setDrawYGrid(boolean drawYGrid) {
		this.drawYGrid = drawYGrid;
	}

	/**
	 * Sets image quality. Relevant only for JPEG images.
	 *
	 * @param imageQuality (0F=worst, 1F=best).
	 */
	public void setImageQuality(float imageQuality) {
		this.imageQuality = imageQuality;
	}

	/**
	 * Controls if the chart area of the image should be antialiased or not.
	 *
	 * @param antiAliasing use true to turn antialiasing on, false to turn it off (default)
	 */
	public void setAntiAliasing(boolean antiAliasing) {
		this.antiAliasing = antiAliasing;
	}

	/**
	 * Shows or hides graph signature (gator) in the top right corner of the graph
	 *
	 * @param showSignature true, if signature should be seen (default), false otherwise
	 */
	public void setShowSignature(boolean showSignature) {
		this.showSignature = showSignature;
	}

	/**
	 * Sets first day of the week.
	 *
	 * @param firstDayOfWeek One of the following constants:
	 *                       {@link RrdGraphConstants#MONDAY MONDAY},
	 *                       {@link RrdGraphConstants#TUESDAY TUESDAY},
	 *                       {@link RrdGraphConstants#WEDNESDAY WEDNESDAY},
	 *                       {@link RrdGraphConstants#THURSDAY THURSDAY},
	 *                       {@link RrdGraphConstants#FRIDAY FRIDAY},
	 *                       {@link RrdGraphConstants#SATURDAY SATURDAY},
	 *                       {@link RrdGraphConstants#SUNDAY SUNDAY}
	 */
	public void setFirstDayOfWeek(int firstDayOfWeek) {
		this.firstDayOfWeek = firstDayOfWeek;
	}

	// helper methods

	int printStatementCount() {
		int count = 0;
		for (CommentText comment : comments) {
			if (comment instanceof PrintText) {
				if (comment.isPrint()) {
					count++;
				}
			}
		}
		return count;
	}

	boolean shouldPlot() {
		if (plotElements.size() > 0) {
			return true;
		}
		for (CommentText comment : comments) {
			if (comment.isValidGraphElement()) {
				return true;
			}
		}
		return false;
	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -