/// <summary> /// Adds a line with the specified line information. /// </summary> /// <param name="points">the values</param> /// <param name="line">the design</param> /// <param name="lineMarkers">marker above the line; (point index, image)</param> /// <returns>this Builder for chaining</returns> /// <exception cref="ArgumentException">if any arguments is null or points contain less than 2 values</exception> public Builder AddLine(List <float> points, LineInfo line, List <Tuple <int, Bitmap> > lineMarkers) { ValidationUtil.RequireNonNull(points); ValidationUtil.RequireNonNull(line); ValidationUtil.RequirePositive(points.Count - 1, "There must be at least two values in points."); ValidationUtil.RequireNonNull(lineMarkers); if (lineMarkers.Any(t => t == null)) { throw new ArgumentException("No line marker can be null."); } if (lineMarkers.Any(t => t.Item2 == null)) { throw new ArgumentException("No line marker image can be null."); } if (lineMarkers.Select(t => t.Item1).Any(i => i >= points.Count || i < 0)) { throw new ArgumentException("No line marker can have an index outside of the points."); } lines.Add(new Tuple <List <float>, LineInfo, List <Tuple <int, Bitmap> > >(points, line, lineMarkers)); return(this); }
/// <inheritdoc cref="ICanvas"/> public ICanvas SetFont(FontType fontType, FontStyle fontStyle, float fontSize) { currentFontType = fontType; currentFontStyle = fontStyle; currentFontSize = ValidationUtil.RequirePositive(fontSize, $"fontSize({fontSize}) has to be positive."); return(this); }
/// <summary> /// Returns a new Builder instance. /// </summary> /// <param name="lineWidth">the width of the line</param> /// <param name="subtitle">the subtitle below</param> /// <returns>new Builder instance</returns> public static Builder NewInstance(float lineWidth, string subtitle) { ValidationUtil.RequireBetween(lineWidth, 0, 1, $"lineWidth({lineWidth}) must be in the interval [0, 1]"); ValidationUtil.RequirePositive(lineWidth, $"lineWidth({lineWidth}) must be greater than 0."); ValidationUtil.RequireNonNull(subtitle); return(new Builder(lineWidth, subtitle)); }
/// <summary> /// Fills the rectangle in the graph as specified by the two y-values. /// </summary> /// <param name="fromYValue">the lower y value</param> /// <param name="toYValue">the upper y value</param> /// <param name="color">the color</param> /// <returns>this Builder for chaining</returns> /// <exception cref="ArgumentException">if color is null or fromYValue is equal or greater than toYValue</exception> public Builder SetHorizontalFill(float fromYValue, float toYValue, Color color) { ValidationUtil.RequireNonNull(color); ValidationUtil.RequirePositive(toYValue - fromYValue, $"toYValue({toYValue}) cannot be less than or equal to fromYValue({fromYValue})."); HorizontalFill = Tuple.Create(fromYValue, toYValue, color); return(this); }
/// <summary> /// Returns a new Builder instance with the title to the left of the comment lines. One lineSpacing will be /// added under the title before the first line. /// </summary> /// <param name="lineSpacing">the space between the lines</param> /// <param name="title">the title; if empty no title is used</param> /// <param name="textInfo">the font information of the title</param> /// <returns>new Builder instance</returns> public static Builder NewInstance(float lineSpacing, string title, TextInfo textInfo) { ValidationUtil.RequireBetween(lineSpacing, 0, 1, $"lineSpacing({lineSpacing}) must be in the interval [0, 1]"); ValidationUtil.RequirePositive(lineSpacing, $"lineSpacing({lineSpacing}) must be greater than 0."); ValidationUtil.RequireNonNull(title); ValidationUtil.RequireNonNull(textInfo); return(new Builder(lineSpacing, title, textInfo)); }
/// <summary> /// Sets a grid in the graph with automatic number of horizontal lines to make a grid of squares. /// <para> /// Note that the last call to any AddGrid method is applied, rest is ignored. /// </para> /// </summary> /// <param name="grid">the grid lines information</param> /// <param name="numVertical">number of vertical lines</param> /// <returns>this Builder for chaining</returns> /// <exception cref="ArgumentException">if grid is null</exception> public Builder SetGrid(LineInfo grid, int numVertical) { Grid = ValidationUtil.RequireNonNull(grid); NumVertical = ValidationUtil.RequirePositive(numVertical, $"numVertical({numVertical}) must be positive.."); NumHorizontal = -1; AgainstMarkersX = false; AgainstMarkersY = false; return(this); }
/// <inheritdoc cref="ICanvas"/> public ICanvas DrawLine(PointPair line, float thickness, float unitsOn) { ValidationUtil.RequireNonNull(line); ValidationUtil.RequirePositive(thickness, $"thickness({thickness}) must be positive (>0)."); ValidationUtil.RequireBetween(unitsOn, 0, 1, $"unitsOn({unitsOn}) must be in the range [0, 1]."); // Draws the line with the pen. var pen = GetPen(thickness); if (unitsOn.CompareTo(1f) == 0) { pen.DashStyle = XDashStyle.Solid; } else { pen.DashStyle = XDashStyle.Dash; var lineLength = line.ConvertLineLength(currentDrawingSpace); var numUnits = lineLength / thickness; var numOnUnits = unitsOn * numUnits; var numOffUnits = numUnits - numOnUnits; //pen.DashPattern = new double[] {numOnUnits, numOffUnits}; pen.DashPattern = new double[] { Math.Max(1, numOnUnits / numOffUnits), Math.Max(1, numOffUnits / numOnUnits) }; } var fromX = line.ConvertFromX(currentDrawingSpace); var fromY = line.ConvertFromY(currentDrawingSpace); var toX = line.ConvertToX(currentDrawingSpace); var toY = line.ConvertToY(currentDrawingSpace); var from = BindPoint( fromX, fromY, thickness / 2, currentDrawingSpace); var to = BindPoint( toX, toY, thickness / 2, currentDrawingSpace); //currentGfx.DrawLine(pen, fromX, fromY, toX, toY); currentGfx.DrawLine(pen, from.Item1, from.Item2, to.Item1, to.Item2); return(this); }
/// <summary> /// Adds axis limits to the graph and thus to all lines added. Note that the xAxis is indexes that acts as a "valid" /// index window for all lines. /// </summary> /// <param name="xAxis">the limits on the x-axis; defaults to null, meaning to fit the lines</param> /// <param name="yAxis">the limits on the y-axis; defaults to null, meaning to fit the lines</param> /// <returns>this Builder for chaining</returns> /// <exception cref="ArgumentException">if any lower limit is equal or greater than the upper limit or lower x axis limit is negative</exception> public Builder SetAxisLimits(Tuple <int, int> xAxis, Tuple <float, float> yAxis) { if (xAxis != null) { ValidationUtil.RequireNonNegative(xAxis.Item1, $"Lower x-axis limit({xAxis.Item1}) cannot be negative."); ValidationUtil.RequirePositive(xAxis.Item2 - xAxis.Item1, $"Upper x-axis limit({xAxis.Item2}) must be greater than lower x-axis limit({xAxis.Item1})."); } if (yAxis != null) { ValidationUtil.RequirePositive(yAxis.Item2 - yAxis.Item1, $"Upper y-axis limit({yAxis.Item2}) must be greater than lower y-axis limit({yAxis.Item1})."); } AxisLimitX = xAxis; AxisLimitY = yAxis; return(this); }
/// <summary> /// Returns a new <see cref="GraphPlottable"/> instance from this Builder. /// </summary> /// <returns>new GraphPlottable instance</returns> public GraphPlottable Build() { ValidationUtil.RequirePositive(Lines.Count, "There must be at least one line given to plot."); return(new GraphPlottable(this)); }
public void Test_RequirePositive_Double_3() { double val = -1; ValidationUtil.RequirePositive(val, ""); }
public void Test_RequirePositive_Int_3() { int val = -1; ValidationUtil.RequirePositive(val, ""); }