public static IEnumerable<PointPair> AsEnumerable(IPointList pointList) { for (int i = 0; i < pointList.Count; i++) { yield return pointList[i]; } }
public DataPointTableForm(GraphItem graphItem) { InitializeComponent(); item = graphItem; pointList = item.Points; dataGridView.Rows.Insert( 0, pointList.Count ); }
/// <summary> /// Constructor to initialize the PointPairList from an IPointList /// </summary> public PointPairList( IPointList list ) { int count = list.Count; for ( int i = 0; i < count; i++ ) Add( list[i] ); _sorted = false; }
/// <summary> /// Create a new <see cref="FilledLineItem"/> using the specified properties. /// </summary> /// <param name="label">The _label that will appear in the legend.</param> /// <param name="upperPoints">A <see cref="IPointList"/> of double precision value pairs that define /// the X and upper Y values for this curve</param> /// <param name="lowerPoints">A <see cref="IPointList"/> of double precision value pairs that define /// the X and lower Y values for this curve</param> /// <param name="color">A <see cref="System.Drawing.Color"/> value that will be applied to /// the <see cref="Line"/> and <see cref="Symbol"/> properties. /// </param> /// <param name="symbolType">A <see cref="SymbolType"/> enum specifying the /// type of symbol to use for this <see cref="LineItem"/>. Use <see cref="SymbolType.None"/> /// to hide the symbols.</param> /// <param name="lineWidth">The width (in points) to be used for the <see cref="Line"/>. This /// width is scaled based on <see cref="PaneBase.CalcScaleFactor"/>. Use a value of zero to /// hide the line (see <see cref="ZedGraph.LineBase.IsVisible"/>).</param> public FilledLineItem( string label, IPointList upperPoints, IPointList lowerPoints, System.Drawing.Color color, SymbolType symbolType, float lineWidth ) : base(label) { Points = upperPoints ?? new PointPairList(); LowerPoints = lowerPoints ?? new PointPairList(); _line = new FilledLine( color ); if ( lineWidth == 0 ) _line.IsVisible = false; else _line.Width = lineWidth; _symbol = new Symbol( symbolType, color ); }
/// <summary> /// Use linear regression to form a least squares fit of an existing /// <see cref="IPointList"/> instance. /// </summary> /// <param name="points">An <see cref="IPointList" /> instance containing /// the data to be regressed.</param> /// <param name="pointCount">The number of desired points to be included /// in the resultant <see cref="PointPairList" />. /// </param> /// <param name="minX">The minimum X value of the resultant /// <see cref="PointPairList" />.</param> /// <param name="maxX">The maximum X value of the resultant /// <see cref="PointPairList" />.</param> /// <returns>A new <see cref="PointPairList" /> containing the resultant /// data fit. /// </returns> /// <author> Brian Chappell - lazarusds /// modified by John Champion</author> public PointPairList LinearRegression(IPointList points, int pointCount, double minX, double maxX) { double x = 0, y = 0, xx = 0, xy = 0, count = 0; for (int i = 0; i < points.Count; i++) { PointPair pt = points[i]; if (!pt.IsInvalid) { x += points[i].X; y += points[i].Y; xx += points[i].X * points[i].X; xy += points[i].X * points[i].Y; count++; } } if (count < 2 || maxX - minX < 1e-20) { return(null); } double slope = (count * xy - x * y) / (count * xx - x * x); double intercept = (y - slope * x) / count; PointPairList newPoints = new PointPairList(); double stepSize = (maxX - minX) / pointCount; double value = minX; for (int i = 0; i < pointCount; i++) { newPoints.Add(new PointPair(value, value * slope + intercept)); value += stepSize; } return(newPoints); }
/// <summary> /// Writes a linestring without the preceding type information. /// </summary> /// <param name="linestring"></param> /// <param name="ordinates"></param> /// <param name="reversePointOrder"></param> protected void WriteLinestringCore([NotNull] IPointList linestring, Ordinates ordinates, bool reversePointOrder = false) { int pointCount = linestring.PointCount; Writer.Write(pointCount); if (reversePointOrder) { for (int i = pointCount - 1; i >= 0; i--) { WritePointCore(linestring, i, ordinates); } } else { for (int i = 0; i < pointCount; i++) { WritePointCore(linestring, i, ordinates); } } }
/// <summary> /// The Copy Constructor /// </summary> /// <param name="rhs">The CurveItem object from which to copy</param> public CurveItem(CurveItem rhs) : base(rhs) { _label = rhs._label.Clone(); //_isY2Axis = rhs.IsY2Axis; //_isX2Axis = rhs.IsX2Axis; _isVisible = rhs.IsVisible; _isOverrideOrdinal = rhs._isOverrideOrdinal; _yAxisIndex = rhs._yAxisIndex; if (rhs.Tag is ICloneable) { this.Tag = ((ICloneable)rhs.Tag).Clone(); } else { this.Tag = rhs.Tag; } _points = (IPointList)rhs.Points.Clone(); //_link = rhs._link.Clone(); }
LineF2D ILineList.this[int idx] { get { IPointList pointList = (IPointList)this; switch (idx) { case 0: return(new LineF2D(pointList[0], pointList[1])); case 1: return(new LineF2D(pointList[1], pointList[2])); case 2: return(new LineF2D(pointList[2], pointList[3])); case 3: return(new LineF2D(pointList[3], pointList[0])); default: throw new ArgumentOutOfRangeException(); } } }
public override void Draw(Graphics g, GraphPane pane, int pos, float scaleFactor) { IPointList points = Points; if (points != null) { Scale xScale = GetXAxis(pane).Scale; Scale yScale = GetYAxis(pane).Scale; // Loop over each defined point for (int i = 0; i < points.Count; i++) { var point = points[i]; Color backColor = (Color)point.Tag; var brush = new SolidBrush(backColor); double x1 = xScale.Transform(point.X - .5); double x2 = xScale.Transform(point.X + .5); double y1 = yScale.Transform(point.Y - .5); double y2 = yScale.Transform(point.Y + .5); g.FillRectangle(brush, (float)Math.Min(x1, x2), (float)Math.Min(y1, y2), (float)Math.Abs(x2 - x1), (float)Math.Abs((y2 - y1))); } } }
/// <summary> /// Create a <see cref="TextObj" /> for each bar in the <see cref="GraphPane" />. /// </summary> /// <remarks> /// This method will go through the bars, create a label that corresponds to the bar value, /// and place it on the graph depending on user preferences. This works for horizontal or /// vertical bars in clusters or stacks, but only for <see cref="BarItem" /> types. This method /// does not apply to <see cref="ErrorBarItem" /> or <see cref="HiLowBarItem" /> objects. /// Call this method only after calling <see cref="GraphPane.AxisChange()" />. /// </remarks> /// <param name="pane">The GraphPane in which to place the text labels.</param> /// <param name="isBarCenter">true to center the labels inside the bars, false to /// place the labels just above the top of the bar.</param> /// <param name="valueFormat">The double.ToString string format to use for creating /// the labels. /// </param> /// <param name="fontColor">The color in which to draw the labels</param> /// <param name="fontFamily">The string name of the font family to use for the labels</param> /// <param name="fontSize">The floating point size of the font, in scaled points</param> /// <param name="isBold">true for a bold font type, false otherwise</param> /// <param name="isItalic">true for an italic font type, false otherwise</param> /// <param name="isUnderline">true for an underline font type, false otherwise</param> public static void CreateBarLabels(GraphPane pane, bool isBarCenter, string valueFormat, string fontFamily, float fontSize, Color fontColor, bool isBold, bool isItalic, bool isUnderline) { bool isVertical = pane.BarSettings.Base == BarBase.X; // keep a count of the number of BarItems int curveIndex = 0; // Get a valuehandler to do some calculations for us ValueHandler valueHandler = new ValueHandler(pane, true); // Loop through each curve in the list foreach (CurveItem curve in pane.CurveList) { // work with BarItems only BarItem bar = curve as BarItem; if (bar != null) { IPointList points = curve.Points; // ADD JKB 9/21/07 // The labelOffset should depend on whether the curve is YAxis or Y2Axis. // JHC - Generalize to any value axis // Make the gap between the bars and the labels = 1.5% of the axis range float labelOffset; Scale scale = curve.ValueAxis(pane).Scale; labelOffset = (float)(scale._max - scale._min) * 0.015f; // Loop through each point in the BarItem for (int i = 0; i < points.Count; i++) { // Get the high, low and base values for the current bar // note that this method will automatically calculate the "effective" // values if the bar is stacked double baseVal, lowVal, hiVal; valueHandler.GetValues(curve, i, out baseVal, out lowVal, out hiVal); // Get the value that corresponds to the center of the bar base // This method figures out how the bars are positioned within a cluster float centerVal = (float)valueHandler.BarCenterValue(bar, bar.GetBarWidth(pane), i, baseVal, curveIndex); // Create a text label -- note that we have to go back to the original point // data for this, since hiVal and lowVal could be "effective" values from a bar stack string barLabelText = (isVertical ? points[i].Y : points[i].X).ToString(valueFormat); // Calculate the position of the label -- this is either the X or the Y coordinate // depending on whether they are horizontal or vertical bars, respectively float position; if (isBarCenter) { position = (float)(hiVal + lowVal) / 2.0f; } else if (hiVal >= 0) { position = (float)hiVal + labelOffset; } else { position = (float)hiVal - labelOffset; } // Create the new TextObj TextObj label; if (isVertical) { label = new TextObj(barLabelText, centerVal, position); } else { label = new TextObj(barLabelText, position, centerVal); } label.FontSpec.Family = fontFamily; // Configure the TextObj // CHANGE JKB 9/21/07 // CoordinateFrame should depend on whether curve is YAxis or Y2Axis. label.Location.CoordinateFrame = (isVertical && curve.IsY2Axis) ? CoordType.AxisXY2Scale : CoordType.AxisXYScale; label.FontSpec.Size = fontSize; label.FontSpec.FontColor = fontColor; label.FontSpec.IsItalic = isItalic; label.FontSpec.IsBold = isBold; label.FontSpec.IsUnderline = isUnderline; label.FontSpec.Angle = isVertical ? 90 : 0; label.Location.AlignH = isBarCenter ? AlignH.Center : (hiVal >= 0 ? AlignH.Left : AlignH.Right); label.Location.AlignV = AlignV.Center; label.FontSpec.Border.IsVisible = false; label.FontSpec.Fill.IsVisible = false; // Add the TextObj to the GraphPane pane.GraphObjList.Add(label); } curveIndex++; } } }
/// <summary> /// Get the user scale values associate with a particular point of a /// particular curve.</summary> /// <remarks>The main purpose of this method is to handle /// stacked bars and lines, in which case the stacked values are returned rather /// than the individual data values. However, this method works generically for any /// curve type. /// </remarks> /// <param name="pane">The parent <see cref="GraphPane"/> object.</param> /// <param name="curve">A <see cref="CurveItem"/> object of interest.</param> /// <param name="iPt">The zero-based point index for the point of interest.</param> /// <param name="baseVal">A <see cref="Double"/> value representing the value /// for the independent axis.</param> /// <param name="lowVal">A <see cref="Double"/> value representing the lower /// value for the dependent axis.</param> /// <param name="hiVal">A <see cref="Double"/> value representing the upper /// value for the dependent axis.</param> /// <returns>true if the data point is value, false for /// <see cref="PointPairBase.Missing"/>, invalid, etc. data.</returns> public static bool GetValues(GraphPane pane, CurveItem curve, int iPt, out double baseVal, out double lowVal, out double hiVal) { hiVal = PointPair.Missing; lowVal = PointPair.Missing; baseVal = PointPair.Missing; if (curve == null || curve.Points.Count <= iPt || !curve.IsVisible) { return(false); } Axis baseAxis = curve.BaseAxis(pane); Axis valueAxis = curve.ValueAxis(pane); if (baseAxis is XAxis || baseAxis is X2Axis) { baseVal = curve.Points[iPt].X; } else { baseVal = curve.Points[iPt].Y; } // is it a stacked bar type? if (curve is BarItem && (pane._barSettings.Type == BarType.Stack || pane._barSettings.Type == BarType.PercentStack)) { double positiveStack = 0; double negativeStack = 0; double curVal; // loop through all the curves, summing up the values to get a total (only // for the current ordinal position iPt) foreach (CurveItem tmpCurve in pane.CurveList) { // Sum the value for the current curve only if it is a bar if (tmpCurve.IsBar && tmpCurve.IsVisible) { curVal = PointPair.Missing; // For non-ordinal curves, find a matching base value (must match exactly) if (curve.IsOverrideOrdinal || !baseAxis._scale.IsAnyOrdinal) { IPointList points = tmpCurve.Points; for (int i = 0; i < points.Count; i++) { if ((baseAxis is XAxis || baseAxis is X2Axis) && points[i].X == baseVal) { curVal = points[i].Y; break; } else if (!(baseAxis is XAxis || baseAxis is X2Axis) && points[i].Y == baseVal) { curVal = points[i].X; break; } } } // otherwise, it's an ordinal type so use the value at the same ordinal position else if (iPt < tmpCurve.Points.Count) { // Get the value for the appropriate value axis if (baseAxis is XAxis || baseAxis is X2Axis) { curVal = tmpCurve.Points[iPt].Y; } else { curVal = tmpCurve.Points[iPt].X; } } // If it's a missing value, skip it if (curVal == PointPair.Missing) { positiveStack = PointPair.Missing; negativeStack = PointPair.Missing; } // the current curve is the target curve, save the summed values for later if (tmpCurve == curve) { // if the value is positive, use the positive stack if (curVal >= 0) { lowVal = positiveStack; hiVal = (curVal == PointPair.Missing || positiveStack == PointPair.Missing) ? PointPair.Missing : positiveStack + curVal; } // otherwise, use the negative stack else { hiVal = negativeStack; lowVal = (curVal == PointPair.Missing || negativeStack == PointPair.Missing) ? PointPair.Missing : negativeStack + curVal; } } // Add all positive values to the positive stack, and negative values to the // negative stack if (curVal >= 0) { positiveStack = (curVal == PointPair.Missing || positiveStack == PointPair.Missing) ? PointPair.Missing : positiveStack + curVal; } else { negativeStack = (curVal == PointPair.Missing || negativeStack == PointPair.Missing) ? PointPair.Missing : negativeStack + curVal; } } } // if the curve is a PercentStack type, then calculate the percent for this bar // based on the total height of the stack if (pane._barSettings.Type == BarType.PercentStack && hiVal != PointPair.Missing && lowVal != PointPair.Missing) { // Use the total magnitude of the positive plus negative bar stacks to determine // the percentage value positiveStack += Math.Abs(negativeStack); // just to avoid dividing by zero... if (positiveStack != 0) { // calculate the percentage values lowVal = lowVal / positiveStack * 100.0; hiVal = hiVal / positiveStack * 100.0; } else { lowVal = 0; hiVal = 0; } } if (baseVal == PointPair.Missing || lowVal == PointPair.Missing || hiVal == PointPair.Missing) { return(false); } else { return(true); } } // If the curve is a stacked line type, then sum up the values similar to the stacked bar type else if (curve is LineItem && pane.LineType == LineType.Stack) { double stack = 0; double curVal; // loop through all the curves, summing up the values to get a total (only // for the current ordinal position iPt) foreach (CurveItem tmpCurve in pane.CurveList) { // make sure the curve is a Line type if (tmpCurve is LineItem && tmpCurve.IsVisible) { curVal = PointPair.Missing; // For non-ordinal curves, find a matching base value (must match exactly) if (curve.IsOverrideOrdinal || !baseAxis._scale.IsAnyOrdinal) { IPointList points = tmpCurve.Points; for (int i = 0; i < points.Count; i++) { if (points[i].X == baseVal) { curVal = points[i].Y; break; } } } // otherwise, it's an ordinal type so use the value at the same ordinal position else if (iPt < tmpCurve.Points.Count) { // For line types, the Y axis is always the value axis curVal = tmpCurve.Points[iPt].Y; } // if the current value is missing, then the rest of the stack is missing if (curVal == PointPair.Missing) { stack = PointPair.Missing; } // if the current curve is the target curve, save the values if (tmpCurve == curve) { lowVal = stack; // if ( curVal < 0 && stack == 0 ) // { // stack = curVal; // lowVal = curVal; // hiVal = curVal; // } // else hiVal = (curVal == PointPair.Missing || stack == PointPair.Missing) ? PointPair.Missing : stack + curVal; } // sum all the curves to a single total. This includes both positive and // negative values (unlike the bar stack type). stack = (curVal == PointPair.Missing || stack == PointPair.Missing) ? PointPair.Missing : stack + curVal; } } if (baseVal == PointPair.Missing || lowVal == PointPair.Missing || hiVal == PointPair.Missing) { return(false); } else { return(true); } } // otherwise, the curve is not a stacked type (not a stacked bar or stacked line) else { if ((!(curve is HiLowBarItem)) && (!(curve is ErrorBarItem))) { lowVal = 0; } else { lowVal = curve.Points[iPt].LowValue; } if (baseAxis is XAxis || baseAxis is X2Axis) { hiVal = curve.Points[iPt].Y; } else { hiVal = curve.Points[iPt].X; } } // Special Exception: Bars on log scales should always plot from the Min value upwards, // since they can never be zero if (curve is BarItem && valueAxis._scale.IsLog && lowVal == 0) { lowVal = valueAxis._scale._min; } if (baseVal == PointPair.Missing || hiVal == PointPair.Missing || (lowVal == PointPair.Missing && (curve is ErrorBarItem || curve is HiLowBarItem))) { return(false); } else { return(true); } }
/// <summary> /// Adds annotations from the matchedPoints to the Graph Pane /// Plot Options specify how much of the top % of annotations to display, along with size and color. /// </summary> /// <param name="pointsList"></param> /// <param name="myPane"></param> private void AddAnnotations(IPointList pointsList, GraphPane myPane) { //add the annotations for the matched items double offset = 5; double minIntensityToDisplay = FindMinIntensityToDisplay(pointsList); LadderInstance currentInstance = m_manager.GetCurrentInstance(); for (int i = 0; i < pointsList.Count; i++) { bool usingCustomAnnotation = false; TextObj text = new TextObj(); //look for if the user has defined a custom annotation if they have we deal with that instead of making a new one for (int j = 0; j < currentInstance.annotations.Count; j++) { if ((currentInstance.annotations[j].m_point.X == pointsList[i].X) && (currentInstance.annotations[j].m_point.Y == pointsList[i].Y)) { usingCustomAnnotation = true; Annotation customAnnotation = currentInstance.annotations[j]; PointPair pt = pointsList[i]; // Create a text label from the Y data value text = new TextObj(customAnnotation.m_text, pt.X, pt.Y + offset, CoordType.AxisXYScale, AlignH.Left, AlignV.Center); // Store the point into the text object's tag text.Tag = (object)pt; if (customAnnotation.m_showHideAuto > 0) { // Always show this annotation text.IsVisible = true; } else if (customAnnotation.m_showHideAuto < 0) { // Always hide this annotation text.IsVisible = false; } else if (pt.Y <= minIntensityToDisplay) { // Auto Determine if we are going to show the annotation for this point text.IsVisible = false; } break; } } if (!usingCustomAnnotation) { // Get the pointpair PointPair pt = pointsList[i]; // Create a text label from the Y data value string tagText; if (pt.Tag != null) { tagText = pt.Tag as string; } else { tagText = string.Empty; } text = new TextObj(tagText, pt.X, pt.Y + offset, CoordType.AxisXYScale, AlignH.Left, AlignV.Center); // Store the point into the text object's tag text.Tag = (object)pt; // Determine if we are going to show the annotation for this point if (pt.Y <= minIntensityToDisplay) { text.IsVisible = false; } } text.IsClippedToChartRect = true; //set true because we want the annotations to hide when they go off the borders of the graph text.FontSpec.Size = m_options.annotationTextSize; text.FontSpec.FontColor = m_options.annotationColor; text.ZOrder = ZOrder.C_BehindChartBorder; // Hide the border and the fill text.FontSpec.Border.IsVisible = false; text.FontSpec.Fill.IsVisible = false; // Rotate the text to 90 degrees text.FontSpec.Angle = 90; myPane.GraphObjList.Add(text); } }
public HiLowMiddleErrorBarItem(String label, IPointList pointPairList, Color color, Color middleColor) : base(label, pointPairList, color) { _bar = new HiLowMiddleErrorBar(color, middleColor); }
/// <summary> /// Add a candlestick graph (<see cref="OHLCBarItem"/> object) to the plot with /// the given data points (<see cref="IPointList"/>) and properties. /// </summary> /// <remarks> /// This is simplified way to add curves without knowledge of the /// <see cref="CurveList"/> class. An alternative is to use /// the <see cref="ZedGraph.CurveList" /> Add() method. /// Note that the <see cref="IPointList" /> /// should contain <see cref="StockPt" /> objects instead of <see cref="PointPair" /> /// objects in order to contain all the data values required for this curve type. /// </remarks> /// <param name="label">The text label (string) for the curve that will be /// used as a <see cref="Legend"/> entry.</param> /// <param name="points">A <see cref="IPointList"/> of double precision value pairs that define /// the X and Y values for this curve</param> /// <param name="color">The color to used for the curve line, /// symbols, etc.</param> /// <returns>A <see cref="CurveItem"/> class for the newly created curve. /// This can then be used to access all of the curve properties that /// are not defined as arguments to the /// <see cref="AddOHLCBar(string,IPointList,Color)"/> method.</returns> public OHLCBarItem AddOHLCBar( string label, IPointList points, Color color ) { OHLCBarItem curve = new OHLCBarItem( label, points, color ); _curveList.Add( curve ); return curve; }
/// <summary> /// updates the list of data points and then refreshes the form /// </summary> public override void Refresh() { pointList = item.Points; base.Refresh(); }
/// <summary> /// Create a new <see cref="CandleStickItem"/> using the specified properties. /// </summary> /// <param name="label">The _label that will appear in the legend.</param> /// <param name="points">An <see cref="IPointList"/> of double precision values that define /// the Date, Close, Open, High, and Low values for the curve. Note that this /// <see cref="IPointList" /> should contain <see cref="StockPt" /> items rather /// than <see cref="PointPair" /> items. /// </param> /// <param name="color"> /// The <see cref="System.Drawing.Color" /> to use for drawing the candlesticks.</param> public CandleStickItem(string label, IPointList points, Color color) : base(label, points) { _stick = new CandleStick(color); }
public SpectrumShadeItem(IPointList points, Color color) : base(points, color) { }
public SpectrumItem(IPointList points, Color color, float width = 1) { _points = points; _color = color; LineWidth = Settings.Default.SpectrumLineWidth * width; }
/// <summary> /// Create a new <see cref="ErrorBarItem"/> using the specified properties. /// </summary> /// <param name="label">The label that will appear in the legend.</param> /// <param name="points">A <see cref="IPointList"/> of double precision values that define /// the X, Y and lower dependent values for this curve</param> /// <param name="color">A <see cref="Color"/> value that will be applied to /// the <see cref="Line"/> properties. /// </param> public ErrorBarItem(string label, IPointList points, Color color) : base(label, points) { base._objPrefix = "Error Bar Item"; _bar = new ErrorBar(color); }
/// <summary> /// Create a new <see cref="HiLowBarItem"/> using the specified properties. /// </summary> /// <param name="label">The label that will appear in the legend.</param> /// <param name="points">A <see cref="IPointList"/> of double precision value trio's that define /// the X, Y, and lower dependent values for this curve</param> /// <param name="color">A <see cref="Color"/> value that will be applied to /// the <see cref="Bar.Fill"/> and <see cref="Bar.Border"/> properties. /// </param> public HiLowBarItem(string label, IPointList points, Color color) : base(label, points, color) { base._objPrefix = "HiLow Bar Item"; }
/// <summary> /// Create a new <see cref="JapaneseCandleStickItem" /> using the specified properties. /// </summary> /// <param name="label">The label that will appear in the legend.</param> /// <param name="points"> /// An <see cref="IPointList" /> of double precision values that define /// the Date, Close, Open, High, and Low values for the curve. Note that this /// <see cref="IPointList" /> should contain <see cref="StockPt" /> items rather /// than <see cref="PointPair" /> items. /// </param> public JapaneseCandleStickItem(string label, IPointList points, int zOrder = -1) : base(label, points, LineBase.Default.Color, zOrder) { }
/// <summary> /// Add a curve (<see cref="CurveItem"/> object) to the plot with /// the given data points (<see cref="IPointList"/>) and properties. /// This is simplified way to add curves without knowledge of the /// <see cref="CurveList"/> class. An alternative is to use /// the <see cref="ZedGraph.CurveList" /> Add() method. /// </summary> /// <param name="label">The text label (string) for the curve that will be /// used as a <see cref="Legend"/> entry.</param> /// <param name="points">A <see cref="IPointList"/> of double precision value pairs that define /// the X and Y values for this curve</param> /// <param name="color">The color to used for the curve line, /// symbols, etc.</param> /// <param name="symbolType">A symbol type (<see cref="SymbolType"/>) /// that will be used for this curve.</param> /// <returns>A <see cref="CurveItem"/> class for the newly created curve. /// This can then be used to access all of the curve properties that /// are not defined as arguments to the /// <see cref="AddCurve(string,IPointList,Color,SymbolType)"/> method.</returns> public LineItem AddCurve( string label, IPointList points, Color color, SymbolType symbolType ) { LineItem curve = new LineItem( label, points, color, symbolType ); _curveList.Add( curve ); return curve; }
/// <summary> /// Add a hi-low bar type curve (<see cref="CurveItem"/> object) to the plot with /// the given data points (<see cref="IPointList"/>) and properties. /// This is simplified way to add curves without knowledge of the /// <see cref="CurveList"/> class. An alternative is to use /// the <see cref="ZedGraph.CurveList" /> Add() method. /// </summary> /// <param name="label">The text label (string) for the curve that will be /// used as a <see cref="Legend"/> entry.</param> /// <param name="points">A <see cref="IPointList"/> of double precision value Trio's that define /// the X, Y, and lower dependent values for this curve</param> /// <param name="color">The color to used to fill the bars</param> /// <returns>A <see cref="HiLowBarItem"/> class for the newly created bar curve. /// This can then be used to access all of the curve properties that /// are not defined as arguments to the /// <see cref="AddHiLowBar(string,IPointList,Color)"/> method.</returns> public HiLowBarItem AddHiLowBar( string label, IPointList points, Color color ) { HiLowBarItem curve = new HiLowBarItem( label, points, color ); _curveList.Add( curve ); return curve; }
/// <summary> /// Create a TextLabel for each bar in the GraphPane. /// Call this method only after calling AxisChange() /// </summary> /// <remarks> /// This method will go through the bars, create a label that corresponds to the bar value, /// and place it on the graph depending on user preferences. This works for horizontal or /// vertical bars in clusters or stacks.</remarks> /// <param name="pane">The GraphPane in which to place the text labels.</param> /// <param name="isBarCenter">true to center the labels inside the bars, false to /// place the labels just above the top of the bar.</param> /// <param name="valueFormat">The double.ToString string format to use for creating /// the labels /// </param> private void CreateBarLabels(GraphPane pane, bool isBarCenter, string valueFormat) { bool isVertical = pane.BarSettings.Base == BarBase.X; // Make the gap between the bars and the labels = 2% of the axis range float labelOffset; if (isVertical) { labelOffset = (float)(pane.YAxis.Scale.Max - pane.YAxis.Scale.Min) * 0.02f; } else { labelOffset = (float)(pane.XAxis.Scale.Max - pane.XAxis.Scale.Min) * 0.02f; } // keep a count of the number of BarItems int curveIndex = 0; // Get a valuehandler to do some calculations for us ValueHandler valueHandler = new ValueHandler(pane, true); // Loop through each curve in the list foreach (CurveItem curve in pane.CurveList) { // work with BarItems only BarItem bar = curve as BarItem; if (bar != null) { IPointList points = curve.Points; // Loop through each point in the BarItem for (int i = 0; i < points.Count; i++) { // Get the high, low and base values for the current bar // note that this method will automatically calculate the "effective" // values if the bar is stacked double baseVal, lowVal, hiVal; valueHandler.GetValues(curve, i, out baseVal, out lowVal, out hiVal); // Get the value that corresponds to the center of the bar base // This method figures out how the bars are positioned within a cluster float centerVal = (float)valueHandler.BarCenterValue(bar, bar.GetBarWidth(pane), i, baseVal, curveIndex); // Create a text label -- note that we have to go back to the original point // data for this, since hiVal and lowVal could be "effective" values from a bar stack string barLabelText = (isVertical ? points[i].Y : points[i].X).ToString(valueFormat); // Calculate the position of the label -- this is either the X or the Y coordinate // depending on whether they are horizontal or vertical bars, respectively float position; if (isBarCenter) { position = (float)(hiVal + lowVal) / 2.0f; } else { position = (float)hiVal + labelOffset; } // Create the new TextObj TextObj label; if (isVertical) { label = new TextObj(barLabelText, centerVal, position); } else { label = new TextObj(barLabelText, position, centerVal); } // Configure the TextObj label.Location.CoordinateFrame = CoordType.AxisXYScale; label.FontSpec.Size = 12; label.FontSpec.FontColor = Color.Black; label.FontSpec.Angle = isVertical ? 90 : 0; label.Location.AlignH = isBarCenter ? AlignH.Center : AlignH.Left; label.Location.AlignV = AlignV.Center; label.FontSpec.Border.IsVisible = false; label.FontSpec.Fill.IsVisible = false; // Add the TextObj to the GraphPane pane.GraphObjList.Add(label); } } curveIndex++; } }
/// <summary> /// Initializes a new instance of the <see cref="LineItem"/> class. /// Create a new <see cref="LineItem"/> using the specified properties. /// </summary> /// <param name="label"> /// The _label that will appear in the legend. /// </param> /// <param name="points"> /// A <see cref="IPointList"/> of double precision value pairs that define the X and Y values for this curve /// </param> /// <param name="color"> /// A <see cref="Color"/> value that will be applied to the <see cref="Line"/> and <see cref="Symbol"/> properties. /// </param> /// <param name="symbolType"> /// A <see cref="SymbolType"/> enum specifying the type of symbol to use for this <see cref="LineItem"/>. Use <see cref="SymbolType.None"/> /// to hide the symbols. /// </param> /// <param name="lineWidth"> /// The width (in points) to be used for the <see cref="Line"/>. This width is scaled based on <see cref="PaneBase.CalcScaleFactor"/>. Use a value of /// zero to hide the line (see <see cref="LineBase.IsVisible"/>). /// </param> public LineItem(string label, IPointList points, Color color, SymbolType symbolType, float lineWidth) : base(label, points) { this._line = new Line(color); if (lineWidth == 0) { this._line.IsVisible = false; } else { this._line.Width = lineWidth; } this._symbol = new Symbol(symbolType, color); }
/// <summary> /// Create a new <see cref="LineItem"/> using the specified properties. /// </summary> /// <param name="label">The _label that will appear in the legend.</param> /// <param name="points">A <see cref="IPointList"/> of double precision value pairs that define /// the X and Y values for this curve</param> /// <param name="color">A <see cref="Color"/> value that will be applied to /// the <see cref="Line"/> and <see cref="Symbol"/> properties. /// </param> /// <param name="symbolType">A <see cref="SymbolType"/> enum specifying the /// type of symbol to use for this <see cref="LineItem"/>. Use <see cref="SymbolType.None"/> /// to hide the symbols.</param> public LineItem(string label, IPointList points, Color color, SymbolType symbolType) : this(label, points, color, symbolType, Line.Default.Width) { }
/// <summary> /// Create a new <see cref="BarItem"/> using the specified properties. /// </summary> /// <param name="label">The label that will appear in the legend.</param> /// <param name="points">A <see cref="IPointList"/> of double precision value pairs that define /// the X and Y values for this curve</param> /// <param name="color">A <see cref="Color"/> value that will be applied to /// the <see cref="ZedGraph.Bar.Fill"/> and <see cref="ZedGraph.Bar.Border"/> properties. /// </param> public BarItem( string label, IPointList points, Color color ) : base(label, points) { _bar = new Bar( color ); }
/// <summary> /// Creates a new enumerator. /// </summary> /// <param name="enumerable"></param> public PointEnumerator(IPointList enumerable) { _enumerable = enumerable; }
/// <summary> /// Add an <see cref="IPointList"/> object to the head of the queue. /// </summary> /// <param name="pointList">A reference to the <see cref="IPointList"/> object to /// be added</param> public void Add( IPointList pointList ) { // A slightly more efficient approach would be to determine where the new points should placed within // the buffer and to then copy them in directly - updating the head and tail indexes appropriately. for ( int i = 0; i < pointList.Count; i++ ) Add( pointList[i] ); }
/// <summary> /// Create a new <see cref="StickItem"/> using the specified properties. /// </summary> /// <param name="label">The label that will appear in the legend.</param> /// <param name="points">A <see cref="IPointList"/> of double precision value pairs that define /// the X and Y values for this curve</param> /// <param name="color">A <see cref="Color"/> value that will be applied to /// the <see cref="Line"/> and <see cref="Symbol"/> properties. /// </param> public StickItem( string label, IPointList points, Color color ) : this(label, points, color, LineBase.Default.Width) { }
/// <summary> /// Create a new <see cref="FilledLineItem"/> using the specified properties. /// </summary> /// <param name="label">The _label that will appear in the legend.</param> /// <param name="upperPoints">A <see cref="IPointList"/> of double precision value pairs that define /// the X and upper Y values for this curve</param> /// <param name="lowerPoints">A <see cref="IPointList"/> of double precision value pairs that define /// the X and lower Y values for this curve</param> /// <param name="color">A <see cref="System.Drawing.Color"/> value that will be applied to /// the <see cref="Line"/> and <see cref="Symbol"/> properties. /// </param> /// <param name="symbolType">A <see cref="SymbolType"/> enum specifying the /// type of symbol to use for this <see cref="LineItem"/>. Use <see cref="SymbolType.None"/> /// to hide the symbols.</param> public FilledLineItem( string label, IPointList upperPoints, IPointList lowerPoints, System.Drawing.Color color, SymbolType symbolType ) : this(label, upperPoints, lowerPoints, color, symbolType, ZedGraph.LineBase.Default.Width) { }
/// <summary> /// Create a new <see cref="OHLCBarItem"/> using the specified properties. /// </summary> /// <param name="label">The _label that will appear in the legend.</param> /// <param name="points">An <see cref="IPointList"/> of double precision values that define /// the Date, Close, Open, High, and Low values for the curve. Note that this /// <see cref="IPointList" /> should contain <see cref="StockPt" /> items rather /// than <see cref="PointPair" /> items. /// </param> /// <param name="color"> /// The <see cref="System.Drawing.Color" /> to use for drawing the candlesticks.</param> public OHLCBarItem(string label, IPointList points, Color color, int zOrder = -1) : base(label, points, zOrder) { Bar = MakeBar(color); DotSize = 3; }
/// <summary> /// Create a new <see cref="StickItem"/> using the specified properties. /// </summary> /// <param name="label">The label that will appear in the legend.</param> /// <param name="points">A <see cref="IPointList"/> of double precision value pairs that define /// the X and Y values for this curve</param> /// <param name="color">A <see cref="Color"/> value that will be applied to /// the <see cref="Line"/> and <see cref="Symbol"/> properties. /// </param> /// <param name="lineWidth">The width (in points) to be used for the <see cref="Line"/>. This /// width is scaled based on <see cref="PaneBase.CalcScaleFactor"/>. Use a value of zero to /// hide the line (see <see cref="LineBase.IsVisible"/>).</param> public StickItem( string label, IPointList points, Color color, float lineWidth ) : base(label, points, color, Symbol.Default.Type, lineWidth) { _symbol.IsVisible = false; }
public DataFrameBuilder SetPoints(IPointList newPoints) { return new DataFrameBuilder(this) {Points = newPoints}; }
/// <summary> /// Create a new <see cref="BarItem"/> using the specified properties. /// </summary> /// <param name="label">The label that will appear in the legend.</param> /// <param name="points">A <see cref="IPointList"/> of double precision value pairs that define /// the X and Y values for this curve</param> /// <param name="color">A <see cref="Color"/> value that will be applied to /// the <see cref="ZedGraph.Bar.Fill"/> and <see cref="ZedGraph.Bar.Border"/> properties. /// </param> public BarItem(string label, IPointList points, Color color) : base(label, points) { _bar = new Bar(color); }
public MSPointList(IPointList sourcePointList) { _fullPointList = new PointPairList(sourcePointList); _scaledPointList = new PointPairList(); _scaledMaxIndexList = new List <int>(); }
/// <summary> /// Create a new <see cref="HiLowBarItem"/> using the specified properties. /// </summary> /// <param name="label">The label that will appear in the legend.</param> /// <param name="points">A <see cref="IPointList"/> of double precision value trio's that define /// the X, Y, and lower dependent values for this curve</param> /// <param name="color">A <see cref="Color"/> value that will be applied to /// the <see cref="ZedGraph.Bar.Fill"/> and <see cref="ZedGraph.Bar.Border"/> properties. /// </param> public HiLowBarItem(string label, IPointList points, Color color) : base(label, points, color) { }
public SpectrumItem(IPointList points, Color color, float width = 1) { _points = points; _color = color; LineWidth = Settings.Default.SpectrumLineWidth*width; }
/// <summary> /// Draw this <see c_ref="CurveItem"/> to the specified <see c_ref="Graphics"/> /// device as a symbol at each defined point. The routine /// only draws the symbols; the lines are draw by the /// <see c_ref="Line.DrawCurve"/> method. This method /// is normally only called by the Draw method of the /// <see c_ref="CurveItem"/> object /// </summary> /// <param name="g"> /// A graphic device object to be drawn into. This is normally e.Graphics from the /// PaintEventArgs argument to the Paint() method. /// </param> /// <param name="pane"> /// A reference to the <see c_ref="GraphPane"/> object that is the parent or /// owner of this object. /// </param> /// <param name="curve">A <see c_ref="LineItem"/> representing this /// curve.</param> /// <param name="scaleFactor"> /// The scaling factor to be used for rendering objects. This is calculated and /// passed down by the parent <see c_ref="GraphPane"/> object using the /// <see c_ref="PaneBase.CalcScaleFactor"/> method, and is used to proportionally adjust /// font sizes, etc. according to the actual size of the graph. /// </param> /// <param name="isSelected">Indicates that the <see c_ref="Symbol" /> should be drawn /// with attributes from the <see c_ref="Selection" /> class. /// </param> public void Draw(Graphics g, GraphPane pane, LineItem curve, float scaleFactor, bool isSelected) { Symbol source = this; if (isSelected) { source = Selection.Symbol; } int tmpX, tmpY; int minX = (int)pane.Chart.Rect.Left; int maxX = (int)pane.Chart.Rect.Right; int minY = (int)pane.Chart.Rect.Top; int maxY = (int)pane.Chart.Rect.Bottom; // (Dale-a-b) we'll set an element to true when it has been drawn bool[,] isPixelDrawn = new bool[maxX + 1, maxY + 1]; double curX, curY, lowVal; IPointList points = curve.Points; if (points != null && (_border.IsVisible || _fill.IsVisible)) { SmoothingMode sModeSave = g.SmoothingMode; if (_isAntiAlias) { g.SmoothingMode = SmoothingMode.HighQuality; } // For the sake of speed, go ahead and create a solid brush and a pen // If it's a gradient fill, it will be created on the fly for each symbol //SolidBrush brush = new SolidBrush( this.fill.Color ); using (Pen pen = source._border.GetPen(pane, scaleFactor)) using (GraphicsPath path = MakePath(g, scaleFactor)) { RectangleF rect = path.GetBounds(); using (Brush brush = source.Fill.MakeBrush(rect)) { ValueHandler valueHandler = new ValueHandler(pane, false); Scale xScale = curve.GetXAxis(pane).Scale; Scale yScale = curve.GetYAxis(pane).Scale; bool xIsLog = xScale.IsLog; bool yIsLog = yScale.IsLog; bool xIsOrdinal = xScale.IsAnyOrdinal; double xMin = xScale.Min; double xMax = xScale.Max; // Loop over each defined point for (int i = 0; i < points.Count; i++) { // Get the user scale values for the current point // use the valueHandler only for stacked types if (pane.LineType == LineType.Stack) { valueHandler.GetValues(curve, i, out curX, out lowVal, out curY); } // otherwise, just access the values directly. Avoiding the valueHandler for // non-stacked types is an optimization to minimize overhead in case there are // a large number of points. else { curX = points[i].X; if (curve is StickItem) { curY = points[i].Z; } else { curY = points[i].Y; } } // Any value set to double max is invalid and should be skipped // This is used for calculated values that are out of range, divide // by zero, etc. // Also, any value <= zero on a log scale is invalid if (curX != PointPair.Missing && curY != PointPair.Missing && !Double.IsNaN(curX) && !Double.IsNaN(curY) && !Double.IsInfinity(curX) && !Double.IsInfinity(curY) && (curX > 0 || !xIsLog) && (!yIsLog || curY > 0.0) && (xIsOrdinal || (curX >= xMin && curX <= xMax))) { // Transform the user scale values to pixel locations tmpX = (int)xScale.Transform(curve.IsOverrideOrdinal, i, curX); tmpY = (int)yScale.Transform(curve.IsOverrideOrdinal, i, curY); // Maintain an array of "used" pixel locations to avoid duplicate drawing operations if (tmpX >= minX && tmpX <= maxX && tmpY >= minY && tmpY <= maxY) // guard against the zoom-in case { if (isPixelDrawn[tmpX, tmpY]) { continue; } isPixelDrawn[tmpX, tmpY] = true; } // If the fill type for this symbol is a Gradient by value type, // the make a brush corresponding to the appropriate current value if (_fill.IsGradientValueType || _border._gradientFill.IsGradientValueType) { using (Brush tBrush = _fill.MakeBrush(rect, points[i])) using (Pen tPen = _border.GetPen(pane, scaleFactor, points[i])) DrawSymbol(g, tmpX, tmpY, path, tPen, tBrush); } else { // Otherwise, the brush is already defined // Draw the symbol at the specified pixel location DrawSymbol(g, tmpX, tmpY, path, pen, brush); } } } } } g.SmoothingMode = sModeSave; } }
/// <summary> /// Create a new <see cref="StickItem"/> using the specified properties. /// </summary> /// <param name="label">The label that will appear in the legend.</param> /// <param name="points">A <see cref="IPointList"/> of double precision value pairs that define /// the X and Y values for this curve</param> /// <param name="color">A <see cref="Color"/> value that will be applied to /// the <see cref="Line"/> and <see cref="Symbol"/> properties. /// </param> public StickItem(string label, IPointList points, Color color) : this(label, points, color, ZedGraph.LineBase.Default.Width) { }
/// <summary> /// Create a new <see cref="StickItem"/> using the specified properties. /// </summary> /// <param name="label">The label that will appear in the legend.</param> /// <param name="points">A <see cref="IPointList"/> of double precision value pairs that define /// the X and Y values for this curve</param> /// <param name="color">A <see cref="Color"/> value that will be applied to /// the <see cref="Line"/> and <see cref="Symbol"/> properties. /// </param> /// <param name="lineWidth">The width (in points) to be used for the <see cref="Line"/>. This /// width is scaled based on <see cref="PaneBase.CalcScaleFactor"/>. Use a value of zero to /// hide the line (see <see cref="ZedGraph.LineBase.IsVisible"/>).</param> public StickItem(string label, IPointList points, Color color, float lineWidth) : base(label, points, color, Symbol.Default.Type, lineWidth) { _symbol.IsVisible = false; }
/// <summary> /// Draw this <see cref="CurveItem"/> to the specified <see cref="Graphics"/> /// device as a symbol at each defined point. The routine /// only draws the symbols; the lines are draw by the /// <see cref="Line.DrawCurve"/> method. This method /// is normally only called by the Draw method of the /// <see cref="CurveItem"/> object /// </summary> /// <param name="g"> /// A graphic device object to be drawn into. This is normally e.Graphics from the /// PaintEventArgs argument to the Paint() method. /// </param> /// <param name="pane"> /// A reference to the <see cref="GraphPane"/> object that is the parent or /// owner of this object. /// </param> /// <param name="curve">A <see cref="LineItem"/> representing this /// curve.</param> /// <param name="scaleFactor"> /// The scaling factor to be used for rendering objects. This is calculated and /// passed down by the parent <see cref="GraphPane"/> object using the /// <see cref="PaneBase.CalcScaleFactor"/> method, and is used to proportionally adjust /// font sizes, etc. according to the actual size of the graph. /// </param> public void Draw(Graphics g, GraphPane pane, LineItem curve, float scaleFactor) { float tmpX, tmpY; double curX, curY, lowVal; IPointList points = curve.Points; if (points != null && (_border.IsVisible || _fill.IsVisible)) { SmoothingMode sModeSave = g.SmoothingMode; if (_isAntiAlias) { g.SmoothingMode = SmoothingMode.HighQuality; } // For the sake of speed, go ahead and create a solid brush and a pen // If it's a gradient fill, it will be created on the fly for each symbol //SolidBrush brush = new SolidBrush( this.fill.Color ); Pen pen = _border.MakePen(pane.IsPenWidthScaled, scaleFactor); if (curve.IsHighlighted) { pen.Width *= 3; } //Pen pen = new Pen( this.border.Color, pane.ScaledPenWidth(_border.PenWidth * scaleFactor) ); GraphicsPath path = MakePath(g, scaleFactor, curve.IsHighlighted, pen.Width); RectangleF rect = path.GetBounds(); Brush brush = this.Fill.MakeBrush(rect); ValueHandler valueHandler = new ValueHandler(pane, false); Scale xScale = pane.XAxis.Scale; Scale yScale = curve.GetYAxis(pane).Scale; bool xIsLog = xScale.IsLog; bool yIsLog = yScale.IsLog; // If it's highlighted, draw a black "border" first. Actually not a border but rather the shape // drawn with a thicker pen, over which the thinner pen will be used to draw the same shape in the // main color. if (curve.IsHighlighted) { const int highlightWidthIncrement = 4; pen.Width += highlightWidthIncrement; Color oldColor = pen.Color; pen.Color = Color.Black; GraphicsPath borderPath = MakePath(g, scaleFactor, curve.IsHighlighted, pen.Width); for (int i = 0; i < points.Count; i++) { // Get the user scale values for the current point // use the valueHandler only for stacked types if (pane.LineType == LineType.Stack) { valueHandler.GetValues(curve, i, out curX, out lowVal, out curY); } // otherwise, just access the values directly. Avoiding the valueHandler for // non-stacked types is an optimization to minimize overhead in case there are // a large number of points. else { curX = points[i].X; if (curve is StickItem) { curY = points[i].Z; } else { curY = points[i].Y; } } // Any value set to double max is invalid and should be skipped // This is used for calculated values that are out of range, divide // by zero, etc. // Also, any value <= zero on a log scale is invalid if (curX != PointPair.Missing && curY != PointPair.Missing && !System.Double.IsNaN(curX) && !System.Double.IsNaN(curY) && !System.Double.IsInfinity(curX) && !System.Double.IsInfinity(curY) && (curX > 0 || !xIsLog) && (!yIsLog || curY > 0.0)) { // Transform the user scale values to pixel locations tmpX = xScale.Transform(curve.IsOverrideOrdinal, i, curX); tmpY = yScale.Transform(curve.IsOverrideOrdinal, i, curY); // If the fill type for this symbol is a Gradient by value type, // the make a brush corresponding to the appropriate current value if (_fill.IsGradientValueType) { brush = _fill.MakeBrush(rect, points[i]); } // Otherwise, the brush is already defined // Draw the symbol at the specified pixel location this.DrawSymbol(g, tmpX, tmpY, borderPath, pen, Brushes.Black); } } pen.Width -= highlightWidthIncrement; pen.Color = oldColor; } // Loop over each defined point for (int i = 0; i < points.Count; i++) { // Get the user scale values for the current point // use the valueHandler only for stacked types if (pane.LineType == LineType.Stack) { valueHandler.GetValues(curve, i, out curX, out lowVal, out curY); } // otherwise, just access the values directly. Avoiding the valueHandler for // non-stacked types is an optimization to minimize overhead in case there are // a large number of points. else { curX = points[i].X; if (curve is StickItem) { curY = points[i].Z; } else { curY = points[i].Y; } } // Any value set to double max is invalid and should be skipped // This is used for calculated values that are out of range, divide // by zero, etc. // Also, any value <= zero on a log scale is invalid if (curX != PointPair.Missing && curY != PointPair.Missing && !System.Double.IsNaN(curX) && !System.Double.IsNaN(curY) && !System.Double.IsInfinity(curX) && !System.Double.IsInfinity(curY) && (curX > 0 || !xIsLog) && (!yIsLog || curY > 0.0)) { // Transform the user scale values to pixel locations tmpX = xScale.Transform(curve.IsOverrideOrdinal, i, curX); tmpY = yScale.Transform(curve.IsOverrideOrdinal, i, curY); // If the fill type for this symbol is a Gradient by value type, // the make a brush corresponding to the appropriate current value if (_fill.IsGradientValueType) { brush = _fill.MakeBrush(rect, points[i]); } // Otherwise, the brush is already defined // Draw the symbol at the specified pixel location this.DrawSymbol(g, tmpX, tmpY, path, pen, brush); } } g.SmoothingMode = sModeSave; } }
protected bool detectLabelCurveOverlap(GraphPane pane, IPointList points, int pointIndex, bool pointsAreSticks, RectangleF labelBounds) { double rL = labelBounds.Left; // pane.XAxis.Scale.ReverseTransform( labelBounds.Left ); //double rT = pane.YAxis.Scale.ReverseTransform( labelBounds.Top ); double rR = labelBounds.Right; //pane.XAxis.Scale.ReverseTransform( labelBounds.Right ); double rB = labelBounds.Bottom; //pane.YAxis.Scale.ReverseTransform( labelBounds.Bottom ); // labels cannot overlap the Y axis if (rL < pane.XAxis.Scale.Min) { return(true); } if (pointsAreSticks) { for (int k = 0; k < points.Count; ++k) { PointPair p = points[k]; if (p.X > rR) { break; } if (p.X < rL) { continue; } if (p.Y > rB) { return(true); } } } else { // find all points in the X range of the rectangle // also add the points immediately to the left and right // of these points, find the local maximum // an overlap happens if maximum > rB for (int k = pointIndex; k > 0; --k) { PointPair p = points[k]; if (k + 1 < points.Count && points[k + 1].X < rL) { break; } if (p.Y > rB) { return(true); } } // accessing points.Count in the loop condition showed up in a profiler for (int k = pointIndex + 1, len = points.Count; k < len; ++k) { PointPair p = points[k]; if (points[k - 1].X > rR) { break; } if (p.Y > rB) { return(true); } } } return(false); }
/// <summary> /// Add an error bar set (<see cref="ErrorBarItem"/> object) to the plot with /// the given data points (<see cref="IPointList"/>) and properties. /// This is simplified way to add curves without knowledge of the /// <see cref="CurveList"/> class. An alternative is to use /// the <see cref="ZedGraph.CurveList" /> Add() method. /// </summary> /// <param name="label">The text label (string) for the curve that will be /// used as a <see cref="Legend"/> entry.</param> /// <param name="points">A <see cref="IPointList"/> of double precision value pairs that define /// the X and Y values for this curve</param> /// <param name="color">The color to used for the curve line, /// symbols, etc.</param> /// <returns>An <see cref="ErrorBarItem"/> class for the newly created curve. /// This can then be used to access all of the curve properties that /// are not defined as arguments to the /// <see cref="AddErrorBar(string,IPointList,Color)"/> method.</returns> public ErrorBarItem AddErrorBar( string label, IPointList points, Color color ) { ErrorBarItem curve = new ErrorBarItem( label, points, color ); _curveList.Add( curve ); return curve; }
/// <summary> /// Подготавливает данные для их отображения на графике. /// </summary> private static IPointList[] PrepareData(IEnumerable<MergedNarrowPeak> peaks, int maxPeaksPerBar, ref int minPos, ref int maxPos, out int maxValue) { maxValue = 0; var minPos2 = int.MaxValue; var maxPos2 = int.MinValue; var data = new List<KeyValuePair<int, int>>[maxPeaksPerBar]; for (int i = 0; i < data.Length; i++) data[i] = new List<KeyValuePair<int, int>>(); foreach (var peak in peaks) { if(peak.StartPos < minPos) continue; if (peak.EndPos > maxPos) break; if (peak.StartPosMin < minPos2) minPos2 = peak.StartPosMin; if (peak.EndPosMax > maxPos2) maxPos2 = peak.EndPosMax; int id = 0; foreach (var p in peak.Values1.OrderByDescending(p => p).Take(maxPeaksPerBar)) { if (p > maxValue) maxValue = (int)p; data[id++].Add(new KeyValuePair<int, int>((peak.EndPos + peak.StartPos)/2, (int) Math.Round(p))); } } int cnt = data.Count(p => p.Count > 0); var ret = new IPointList[cnt]; for (int i = 0; i < cnt; i++) { ret[i] = new PointPairList(data[i].Select(p => (double)p.Key).ToArray(), data[i].Select(p => (double)p.Value).ToArray()); } minPos = minPos2; maxPos = maxPos2; return ret; }
/// <summary> /// Add a japanesecandlestick graph (<see cref="JapaneseCandleStickItem"/> object) to the plot with /// the given data points (<see cref="IPointList"/>) and properties. /// </summary> /// <remarks> /// This is simplified way to add curves without knowledge of the /// <see cref="CurveList"/> class. An alternative is to use /// the <see cref="ZedGraph.CurveList" /> Add() method. /// Note that the <see cref="IPointList" /> /// should contain <see cref="StockPt" /> objects instead of <see cref="PointPair" /> /// objects in order to contain all the data values required for this curve type. /// </remarks> /// <param name="label">The text label (string) for the curve that will be /// used as a <see cref="Legend"/> entry.</param> /// <param name="points">A <see cref="IPointList"/> of double precision value pairs that define /// the X and Y values for this curve</param> /// <returns>A <see cref="CurveItem"/> class for the newly created curve. /// This can then be used to access all of the curve properties that /// are not defined as arguments to the /// <see cref="AddJapaneseCandleStick(string,IPointList)"/> method.</returns> public JapaneseCandleStickItem AddJapaneseCandleStick( string label, IPointList points ) { JapaneseCandleStickItem curve = new JapaneseCandleStickItem( label, points ); _curveList.Add( curve ); return curve; }
/// <summary> /// Create a new <see cref="JapaneseCandleStickItem"/> using the specified properties. /// </summary> /// <param name="label">The label that will appear in the legend.</param> /// <param name="points">An <see cref="IPointList"/> of double precision values that define /// the Date, Close, Open, High, and Low values for the curve. Note that this /// <see cref="IPointList" /> should contain <see cref="StockPt" /> items rather /// than <see cref="PointPair" /> items. /// </param> public JapaneseCandleStickItem(string label, IPointList points) : base(label, points) { _stick = new JapaneseCandleStick(); }
/// <summary> /// Add a stick graph (<see cref="StickItem"/> object) to the plot with /// the given data points (<see cref="IPointList"/>) and properties. /// This is simplified way to add curves without knowledge of the /// <see cref="CurveList"/> class. An alternative is to use /// the <see cref="ZedGraph.CurveList" /> Add() method. /// </summary> /// <param name="label">The text label (string) for the curve that will be /// used as a <see cref="Legend"/> entry.</param> /// <param name="points">A <see cref="IPointList"/> of double precision value pairs that define /// the X and Y values for this curve</param> /// <param name="color">The color to used for the curve line, /// symbols, etc.</param> /// <returns>A <see cref="CurveItem"/> class for the newly created curve. /// This can then be used to access all of the curve properties that /// are not defined as arguments to the /// <see cref="AddStick(string,IPointList,Color)"/> method.</returns> public StickItem AddStick( string label, IPointList points, Color color ) { StickItem curve = new StickItem( label, points, color ); _curveList.Add( curve ); return curve; }
public Curve(IPointList points) { Points = new PointPairList(points); LibraryReferenceName = string.Empty; }
/// <summary> /// Initializes a new instance of the <see cref="LineItem"/> class. /// Create a new <see cref="LineItem"/> using the specified properties. /// </summary> /// <param name="label"> /// The _label that will appear in the legend. /// </param> /// <param name="points"> /// A <see cref="IPointList"/> of double precision value pairs that define the X and Y values for this curve /// </param> /// <param name="color"> /// A <see cref="Color"/> value that will be applied to the <see cref="Line"/> and <see cref="Symbol"/> properties. /// </param> /// <param name="symbolType"> /// A <see cref="SymbolType"/> enum specifying the type of symbol to use for this <see cref="LineItem"/>. Use <see cref="SymbolType.None"/> /// to hide the symbols. /// </param> public LineItem(string label, IPointList points, Color color, SymbolType symbolType) : this(label, points, color, symbolType, LineBase.Default.Width) { }
/* public CurveItem( string _label, int y ) : this( _label, new IPointList( ) ) { } */ /// <summary> /// <see cref="CurveItem"/> constructor the pre-specifies the curve label, the /// x and y data values as a <see cref="IPointList"/>, the curve /// type (Bar or Line/Symbol), the <see cref="Color"/>, and the /// <see cref="SymbolType"/>. Other properties of the curve are /// defaulted to the values in the <see cref="GraphPane.Default"/> class. /// </summary> /// <param name="label">A string label (legend entry) for this curve</param> /// <param name="points">A <see cref="IPointList"/> of double precision value pairs that define /// the X and Y values for this curve</param> public CurveItem( string label, IPointList points ) { Init( label ); if ( points == null ) _points = new PointPairList(); else //this.points = (IPointList) _points.Clone(); _points = points; }
/// <summary> /// Create a new <see cref="HiLowBarItem"/> using the specified properties. /// </summary> /// <param name="label">The label that will appear in the legend.</param> /// <param name="points">A <see cref="IPointList"/> of double precision value trio's that define /// the X, Y, and lower dependent values for this curve</param> /// <param name="color">A <see cref="Color"/> value that will be applied to /// the <see cref="ZedGraph.Bar.Fill"/> and <see cref="ZedGraph.Bar.Border"/> properties. /// </param> public HiLowBarItem( string label, IPointList points, Color color ) : base(label, points, color) { }
/// <summary> /// The Copy Constructor /// </summary> /// <param name="rhs">The CurveItem object from which to copy</param> public CurveItem( CurveItem rhs ) { _label = rhs._label.Clone(); _isY2Axis = rhs.IsY2Axis; _isX2Axis = rhs.IsX2Axis; _isVisible = rhs.IsVisible; _isOverrideOrdinal = rhs._isOverrideOrdinal; _yAxisIndex = rhs._yAxisIndex; if ( rhs.Tag is ICloneable ) this.Tag = ((ICloneable) rhs.Tag).Clone(); else this.Tag = rhs.Tag; _points = (IPointList) rhs.Points.Clone(); _link = rhs._link.Clone(); }
/// <summary> /// Create a new <see cref="JapaneseCandleStickItem"/> using the specified properties. /// </summary> /// <param name="label">The label that will appear in the legend.</param> /// <param name="points">An <see cref="IPointList"/> of double precision values that define /// the Date, Close, Open, High, and Low values for the curve. Note that this /// <see cref="IPointList" /> should contain <see cref="StockPt" /> items rather /// than <see cref="PointPair" /> items. /// </param> public JapaneseCandleStickItem( string label, IPointList points ) : base(label, points) { _stick = new JapaneseCandleStick(); }
/// <summary> /// Constructor for deserializing objects /// </summary> /// <param name="info">A <see cref="SerializationInfo"/> instance that defines the serialized data /// </param> /// <param name="context">A <see cref="StreamingContext"/> instance that contains the serialized data /// </param> protected CurveItem( SerializationInfo info, StreamingContext context ) { // The schema value is just a file version parameter. You can use it to make future versions // backwards compatible as new member variables are added to classes int sch = info.GetInt32( "schema" ); _label = (Label) info.GetValue( "label", typeof(Label) ); _isY2Axis = info.GetBoolean( "isY2Axis" ); if ( sch >= 11 ) _isX2Axis = info.GetBoolean( "isX2Axis" ); else _isX2Axis = false; _isVisible = info.GetBoolean( "isVisible" ); _isOverrideOrdinal = info.GetBoolean( "isOverrideOrdinal" ); // Data Points are always stored as a PointPairList, regardless of the // actual original type (which could be anything that supports IPointList). _points = (PointPairList) info.GetValue( "points", typeof(PointPairList) ); Tag = info.GetValue( "Tag", typeof(object) ); _yAxisIndex = info.GetInt32( "yAxisIndex" ); _link = (Link) info.GetValue( "link", typeof(Link) ); }
/// <summary> /// Constructs a buffer with a copy of the items within the provided /// <see cref="IPointList" />. /// The <see cref="Capacity" /> is set to the length of the provided list. /// </summary> /// <param name="rhs">The <see cref="IPointList" /> to be copied.</param> public RollingPointPairList( IPointList rhs ) { _mBuffer = new PointPair[rhs.Count]; for ( int i = 0; i < rhs.Count; i++ ) { _mBuffer[i] = new PointPair( rhs[i] ); } _headIdx = rhs.Count - 1; _tailIdx = 0; }
/// <summary> /// If any of the <see cref="PointPair.Tag"/> properties on the point is a string, /// then this method returns a <see cref="DataColumn"/> containing those string values. /// If none of the tags are strings, then this method returns null. /// /// A <see cref="ZedGraphControl"/> will show the tag as a tooltip if it is /// a string and <see cref="ZedGraphControl.IsShowPointValues"/> is true. /// </summary> protected virtual DataColumn GetTagColumn(IPointList points) { var values = AsEnumerable(points).Select(point => point.Tag as string).ToArray(); if (values.All(value=>null == value)) { return null; } return new DataColumn<string>("Label", values); // Not L10N }
/// <summary> /// Returns a column with the data values in <see cref="PointPair.Z"/>. /// </summary> protected virtual DataColumn GetZAxisColumn(IPointList points) { var values = new double?[points.Count]; for (int i = 0; i < points.Count; i++) { var point = points[i]; if (point.IsMissing) { values[i] = null; } else { values[i] = point.Z; } } if (values.Contains(null)) { return new DataColumn<double?>("Z", values); // Not L10N } return new DataColumn<double>("Z", values.Cast<double>()); // Not L10N }