private void InitPlotter(Vector.FxVectorF vec, PlotType plotType, Color color) { // init the lists listPlotsGeometry = new List<PlotGeometry>(); // set the position and the size of the element this.Position = new Vector.FxVector2f(0); this.Size = new Vector.FxVector2f(750, 500); // add the vector to the list PlotGeometry plot = new PlotGeometry(); plot.OrigVectorY = vec; plot.Color = color.ToColor4(); plot.Type = plotType; plot.StepType = XStepType.ZeroToMax; // add the plot to the list listPlotsGeometry.Add(plot); // set the origin position { float max = vec.Max(); float min = vec.Min(); float orig_y = Size.Y / 2; if(max >0 && min<0) { orig_y = Size.Y * (min / (max - min)); } if(max >0 && min >= 0) { orig_y = -min; } if(max <=0 && min <0) { orig_y = Size.Y + max; } OriginPosition = new Vector.FxVector2f(5, orig_y); } // allocate scale _scale = new Vector.FxVector2f(1.0f); // fit the plots to the view FitPlots(); // set the x_step base on the size of vec and the width X_Space = this.Size.x / vec.Size; // init format _TextFormat = new TextElementFormat(); _TextFormat.familyName = "Calibri"; _TextFormat.weight = SharpDX.DirectWrite.FontWeight.Black; _TextFormat.fontStyle = SharpDX.DirectWrite.FontStyle.Normal; _TextFormat.fontStretch = SharpDX.DirectWrite.FontStretch.Normal; _TextFormat.fontSize = 8.0f; // init toolstrip InitToolStrips(); }
/// <summary> /// Update the geometry base on the input vector and type /// </summary> /// <param name="vec"></param> void RefreshPlotGeometry( RenderTarget renderTarget , PlotGeometry Geo) { float X_point=0; int X_Index=0; // dispose the old one if ( Geo.Geometry != null ) Geo.Geometry.Dispose(); // init the geometryes Geo.Geometry = new PathGeometry( renderTarget.Factory ); // fill the geometry struct using ( GeometrySink Geo_Sink = Geo.Geometry.Open() ) { switch ( Geo.Type ) { case PlotType.Lines: { //////////////////////////////////////////////////////////////////////////////////////////// Plot Type Lines Boolean IsFigureBegined = false; Boolean IsPointDrawable = true; float Y_Point,X_View_Point,Y_Prev_Point=0,X_Prev_point=0; // pass all the points for ( int i = 0; i < Geo.ScaledVectorY.Size; i++ ) { IsPointDrawable = true; X_View_Point = X_point + OriginPosition.x; // check that we are insite of draw area if ( X_View_Point > 0 ) { // set the y point Y_Point = this.Size.y - Geo.ScaledVectorY[i] - OriginPosition.y; if ( i > 0 ) { Y_Prev_Point = this.Size.y - Geo.ScaledVectorY[i - 1] - OriginPosition.y; switch ( Geo.StepType ) { case XStepType.ZeroToMax: X_Prev_point = X_View_Point - X_Space; break; case XStepType.VectorDefine: X_Prev_point = Geo.ScaledVectorX[X_Index-1]; break; } } else { Y_Prev_Point = this.Size.y - Geo.ScaledVectorY[0] - OriginPosition.y; switch ( Geo.StepType ) { case XStepType.ZeroToMax: X_Prev_point = X_point; break; case XStepType.VectorDefine: X_Prev_point = Geo.ScaledVectorX[0]; break; } } // check the Y point if is insite of the plot area if ( Y_Point > this.Size.y ) { // check if and the prev point was outside of the draw area if ( Y_Prev_Point > this.Size.y ) IsPointDrawable=false; // calc the new x value with linear interpolation X_View_Point = X_Prev_point + ( X_View_Point - X_Prev_point ) * (this.Size.y - Y_Prev_Point) / ( Y_Point - Y_Prev_Point ); Y_Point = this.Size.y; } // check the Y point if is insite of the plot area if ( Y_Point <0 ) { // check if and the prev point was outside of the draw area if ( Y_Prev_Point <0) IsPointDrawable = false; // calc the new x value with linear interpolation X_View_Point = X_Prev_point + ( X_View_Point - X_Prev_point ) * ( Y_Prev_Point ) / ( Y_Prev_Point - Y_Point); Y_Point = 0; } // check if we must draw the point if ( IsPointDrawable ) { // check if this is the first point of the figure if ( IsFigureBegined ) { // add the i'st point of the plot Geo_Sink.AddLine( new Vector2( X_View_Point, Y_Point ) ); } else { // add the start of the plot Geo_Sink.BeginFigure(new Vector2(X_View_Point, Y_Point), FigureBegin.Filled); // set that we have begin the figure IsFigureBegined = true; } } else { if ( IsFigureBegined ) { // close the plot Geo_Sink.EndFigure( FigureEnd.Open ); // and set it for a new figure IsFigureBegined = false; } } } // increese the x position switch ( Geo.StepType ) { case XStepType.ZeroToMax: X_point += X_Space; break; case XStepType.VectorDefine: X_point = Geo.ScaledVectorX[X_Index]; X_Index++; break; } // check if we are out of the view area if ( X_point + OriginPosition.x > this.Size.x ) break; } if ( IsFigureBegined ) { // end the plot Geo_Sink.EndFigure( FigureEnd.Open ); } } break; case PlotType.Stem: { //////////////////////////////////////////////////////////////////////////////////////////// Plot Type Stems float Y_Start,Y_End; // pass all the points for ( int i = 0; i < Geo.ScaledVectorY.Size; i++ ) { // check that we are insite of draw area if ( X_point + OriginPosition.x > 0 ) { Y_Start = this.Size.y - OriginPosition.y; Y_End = this.Size.y - OriginPosition.y - Geo.ScaledVectorY[i]; // check if we are inside of the draw area if ( ( Y_Start > 0 && Y_Start < this.Size.y ) || ( Y_End > 0 && Y_End < this.Size.y ) ) { // correct the Start Point if we are outside of the drawing area if ( OriginPosition.y > this.Size.y ) Y_Start = 0; if ( OriginPosition.y < 0 ) Y_Start = this.Size.y; // correct the End Point if we are outside of the drawing area if ( OriginPosition.y > this.Size.y - Geo.ScaledVectorY[i] ) Y_End = 0; if ( Y_End > this.Size.y ) Y_End = this.Size.y; // add the start of the line that start from x axes Geo_Sink.BeginFigure(new Vector2(X_point + OriginPosition.x, Y_Start), FigureBegin.Filled); // add the i'st point of the plot Geo_Sink.AddLine(new Vector2(X_point + OriginPosition.x, Y_End)); // end the plot Geo_Sink.EndFigure( FigureEnd.Open ); } } // increese the x position switch ( Geo.StepType ) { case XStepType.ZeroToMax: X_point += X_Space; break; case XStepType.VectorDefine: X_point = Geo.ScaledVectorX[X_Index]; X_Index++; break; } // check if we are out of the view area if ( X_point + OriginPosition.x > this.Size.x ) break; } } break; case PlotType.Bars: { //////////////////////////////////////////////////////////////////////////////////////////// Plot Type Bars // pass all the points for ( int i = 0; i < Geo.ScaledVectorY.Size; i++ ) { // check that we are insite of draw area if ( X_point + OriginPosition.x > 0 ) { // add the start of the line that start from x axes Geo_Sink.BeginFigure(new Vector2(X_point + OriginPosition.x, this.Size.y - OriginPosition.y), FigureBegin.Filled); // add the i'st point of the plot Geo_Sink.AddLine(new Vector2(X_point + X_Space + OriginPosition.x, this.Size.y - OriginPosition.y)); Geo_Sink.AddLine(new Vector2(X_point + X_Space + OriginPosition.x, this.Size.y - OriginPosition.y - Geo.ScaledVectorY[i])); Geo_Sink.AddLine(new Vector2(X_point + OriginPosition.x, this.Size.y - OriginPosition.y - Geo.ScaledVectorY[i])); // end the plot Geo_Sink.EndFigure( FigureEnd.Closed ); } // increese the x position switch ( Geo.StepType ) { case XStepType.ZeroToMax: X_point += X_Space; break; case XStepType.VectorDefine: X_point = Geo.ScaledVectorX[X_Index]; X_Index++; break; } // check if we are out of the view area if ( X_point + OriginPosition.x > this.Size.x ) break; } } break; } // close the mesh Geo_Sink.Close(); } // set that we have the latest geometry IsGeomrtryDirty = false; }
public void AddPlot(Vector.FxVectorF vecY, PlotType type, Color4 plotColor) { // add the vector to the list PlotGeometry plot = new PlotGeometry(); // add the vectors plot.OrigVectorY = vecY; // set the color plot.Color = plotColor; // set the plot type plot.Type = type; // because he set vecY and vecX we set the vector define plot.StepType = XStepType.ZeroToMax; // add the plot to the list listPlotsGeometry.Add(plot); // fit the plots to the view FitPlots(); // set the the geometry is dirty IsGeomrtryDirty = true; // check if the load have be called before of add if (Parent != null) // redraw to see the result Parent.ReDraw(); }