public PieSampleDemo() : base( "Code Project Pie Sample", "Pie Sample", DemoType.Pie, DemoType.Tutorial ) { GraphPane myPane = base.GraphPane; // Set the GraphPane title myPane.Title.Text = "2004 ZedGraph Sales by Region\n($M)"; myPane.Title.FontSpec.IsItalic = true; myPane.Title.FontSpec.Size = 24f; myPane.Title.FontSpec.Family = "Times New Roman"; // Fill the pane background with a color gradient myPane.Fill = new Fill( Color.White, Color.Goldenrod, 45.0f ); // No fill for the axis background myPane.Chart.Fill.Type = FillType.None; // Set the legend to an arbitrary location myPane.Legend.Position = LegendPos.Float ; myPane.Legend.Location = new Location( 0.95f, 0.15f, CoordType.PaneFraction, AlignH.Right, AlignV.Top ); myPane.Legend.FontSpec.Size = 10f; myPane.Legend.IsHStack = false; // Add some pie slices PieItem segment1 = myPane.AddPieSlice( 20, Color.Navy, Color.White, 45f, 0, "North" ); PieItem segment3 = myPane.AddPieSlice( 30, Color.Purple, Color.White, 45f, .0, "East" ); PieItem segment4 = myPane.AddPieSlice( 10.21, Color.LimeGreen, Color.White, 45f, 0, "West" ); PieItem segment2 = myPane.AddPieSlice( 40, Color.SandyBrown, Color.White, 45f, 0.2, "South" ); PieItem segment6 = myPane.AddPieSlice( 250, Color.Red, Color.White, 45f, 0, "Europe" ); PieItem segment7 = myPane.AddPieSlice( 50, Color.Blue, Color.White, 45f, 0.2, "Pac Rim" ); PieItem segment8 = myPane.AddPieSlice( 400, Color.Green, Color.White, 45f, 0, "South America" ); PieItem segment9 = myPane.AddPieSlice( 50, Color.Yellow, Color.White, 45f, 0.2, "Africa" ); segment2.LabelDetail.FontSpec.FontColor = Color.Red; // Sum up the pie values CurveList curves = myPane.CurveList ; double total = 0 ; for ( int x = 0 ; x < curves.Count ; x++ ) total += ((PieItem)curves[x]).Value ; // Make a text label to highlight the total value TextObj text = new TextObj( "Total 2004 Sales\n" + "$" + total.ToString () + "M", 0.18F, 0.40F, CoordType.PaneFraction ); text.Location.AlignH = AlignH.Center; text.Location.AlignV = AlignV.Bottom; text.FontSpec.Border.IsVisible = false ; text.FontSpec.Fill = new Fill( Color.White, Color.FromArgb( 255, 100, 100 ), 45F ); text.FontSpec.StringAlignment = StringAlignment.Center ; myPane.GraphObjList.Add( text ); // Create a drop shadow for the total value text item TextObj text2 = new TextObj( text ); text2.FontSpec.Fill = new Fill( Color.Black ); text2.Location.X += 0.008f; text2.Location.Y += 0.01f; myPane.GraphObjList.Add( text2 ); base.ZedGraphControl.AxisChange(); }
private DataSeriesBox() { InitializeComponent(); series = new CurveList(); zedGraphControl.BorderStyle = System.Windows.Forms.BorderStyle.None; zedGraphControl.GraphPane.Border.IsVisible = false; zedGraphControl.GraphPane.Border.Color = Color.White; zedGraphControl.GraphPane.Border.Width = 0; // zedGraphControl.IsAntiAlias = true; zedGraphControl.GraphPane.Fill = new Fill(Color.White); zedGraphControl.GraphPane.Chart.Fill = new Fill(Color.GhostWhite); zedGraphControl.GraphPane.CurveList = series; zedGraphControl.GraphPane.Legend.IsVisible = true; zedGraphControl.GraphPane.Legend.Position = LegendPos.Right; zedGraphControl.GraphPane.Legend.IsShowLegendSymbols = false; zedGraphControl.GraphPane.XAxis.MajorGrid.IsVisible = true; zedGraphControl.GraphPane.XAxis.MinorGrid.IsVisible = false; zedGraphControl.GraphPane.XAxis.MajorGrid.Color = Color.LightGray; zedGraphControl.GraphPane.XAxis.MajorGrid.IsZeroLine = false; zedGraphControl.GraphPane.XAxis.Scale.MaxGrace = 0; zedGraphControl.GraphPane.XAxis.Scale.MinGrace = 0; zedGraphControl.GraphPane.YAxis.MinorGrid.IsVisible = false; zedGraphControl.GraphPane.YAxis.MajorGrid.IsVisible = true; zedGraphControl.GraphPane.YAxis.MajorGrid.Color = Color.LightGray; zedGraphControl.GraphPane.YAxis.MajorGrid.IsZeroLine = false; zedGraphControl.GraphPane.YAxis.Scale.MaxGrace = 0; zedGraphControl.GraphPane.YAxis.Scale.MinGrace = 0; }
//methods public bool Rebuild() { if (cornerpts.Count != 4) { return(false); } CurveList edgecurves = new CurveList(); for (var i = 0; i < cornerpts.Count - 1; i++) { LineCurve edge = new LineCurve(cornerpts[i], cornerpts[(i + 1) % 4]); //modulo gives remainer after divided by set number if (edge.IsValid) { edgecurves.Add(edge); } } if (edgecurves.Count != 4) { return(false); } brep = UsefulFunctions.XCreateBrepFromEdgeCurves(edgecurves); if (brep == null || !brep.IsValid) { return(false); } return(true); }
public void TestComplexData() { string[] labels = { "complex1", "complex2", "complex3" }; double[] x1 = { 4e12, 5e13, 6e14 }; double[] y1 = { 12e-10, 15e-10, 18e-10 }; double[] x2 = { -2, -3, -4, -5, -6, -7, -8, -9, -10, -11 }; double[] y2 = { 0.001, 0.01, 0.1, 1, 10, 100, 1000, 10000, 100000, 1000000 }; double[] z2 = { 1.23453456345345345, 2.6450985347635, 3.45237895638925, 4.42378962387534, 5.4532498734563, 6.429874343, 7.5349857345, 8.5347637634, 9.3764684593453, 10.53948756876345 }; double[] x3 = { 1, 2, 3, 4, 5, 6, 7, 8 }; double[] y3 = new double[x3.Length]; CurveList cl = new CurveList(); cl.Add(new LineItem(labels[0], x1, y1, Color.Black, SymbolType.Circle)); PointPairList ppl = new PointPairList(); for (int i = 0; i < x2.Length; i++) { ppl.Add(x2[i], y2[i], z2[i]); } cl.Add(new LineItem(labels[1], ppl, Color.Black, SymbolType.Circle)); cl.Add(new LineItem(labels[2], x3, y3, Color.Black, SymbolType.Circle)); string filename = folder + labels[0] + ".csv"; Console.WriteLine("Writing for file: " + filename); CsvWriter.ExportToCsv(cl, filename); }
static void WriteDataRow(CurveList curves, int row, StreamWriter writer) { for (int i = 0; i < curves.Count; i++) { WriteDataRow(curves[i], validDimensions[i], row, writer); } }
/// <summary> /// This function selects some curves /// </summary> /// /// public static bool XSelectCurves(string message, out CurveList curves) { curves = new CurveList(); var gc = new GetObject(); gc.SetCommandPrompt(message); gc.GeometryFilter = Rhino.DocObjects.ObjectType.Curve; gc.GetMultiple(1, 0); if (gc.CommandResult() != Result.Success) { return(false); } for (var i = 0; i < gc.ObjectCount; i++) { var curve = gc.Object(i).Curve(); if (null != curve) { curves.Add(curve); } } return(true); }
void OnCheckedItemsChanged(object sender, ListChangedEventArgs e) { foreach (string item in CheckedItems) { if (CurveList.IndexOfTag(item) < 0) { AddItem(item); } } List <string> itemsToRemove = new List <string>(); foreach (LogGraphCurveItem item in CurveList) { if (!CheckedItems.Contains(item.ItemID)) { itemsToRemove.Add(item.ItemID); } } foreach (string item in itemsToRemove) { RemoveItem(item); } }
public void SetSelectedObject(object selectedObject) { if (selectedObject == m_SelectedObject) { return; } if (m_SelectedObject is LogGraphCurveItem oldCurve) { oldCurve.Color = m_SelectedObjectOriginalColor; } m_SelectedObject = selectedObject; if (m_SelectedObject is LogGraphCurveItem curve) { m_SelectedObjectOriginalColor = curve.Color; curve.Color = Color.Red; var index = CurveList.IndexOf(curve); var newIndex = CurveList.Move(index, -index); } OnCurveItemSelected?.Invoke(this, EventArgs.Empty); m_Parent.UpdateGraph(); }
public override void UpdateGraph(bool selectionChanged) { GraphObjList.Clear(); CurveList.Clear(); Legend.IsVisible = false; if (!DetectionPlotData.GetDataCache().TryGet( GraphSummary.DocumentUIContainer.DocumentUI, Settings.QValueCutoff, this.DataCallback, out _detectionData)) { return; } AddLabels(); BarSettings.Type = BarType.SortedOverlay; BarSettings.MinClusterGap = 0.3f; //draw bars var countPoints = new PointPairList(Enumerable.Range(0, _detectionData.ReplicateCount) .Select(i => new PointPair(i, TargetData.Histogram[i] / YScale)).ToList()); CurveList.Insert(0, MakeBarItem(countPoints, Color.FromArgb(180, 220, 255))); //axes formatting XAxis.Scale.Max = _detectionData.ReplicateCount + 1; YAxis.Scale.Max = TargetData.Histogram.Max() / YScale * 1.15; }
public void DoGraphProfit(double[,] finalArray, Portfolio result) { zGC.GraphPane.CurveList.Clear(); GraphPane pane = zGC.GraphPane; pane.Title.Text = "Доходность портфеля по неделям за " + (year + 1) + " год"; zGC.GraphPane.YAxis.Title.Text = "Доходность (%)"; zGC.GraphPane.XAxis.Title.Text = "Неделя"; pane.XAxis.Scale.Min = 0; pane.XAxis.Scale.Max = 53; pane.CurveList.Clear(); zGC.AxisChange(); zGC.Invalidate(); zGC.IsShowPointValues = true; x = new double[finalArray.GetLength(1)]; double[] y = new double[finalArray.GetLength(1)]; for (int i = 0; i < finalArray.GetLength(1); i++) { for (int j = 0; j < finalArray.GetLength(0); j++) { y[i] += finalArray[j, i] * result.ConvertPortfolio()[j] * 100; } x[i] = i + 1; profitYear.Add(x[i], y[i]); } double[] y_profit = new double[y.Length]; y_profit[0] = 0; for (int i = 1; i < y_profit.Length; i++) { y_profit[i] = ((y[i] / y[0]) - 1) * 100; } double t = (y[y.Length - 1] - y[0]) / y[0]; label_profitFact.Text = Math.Round(t * 100, 2).ToString() + "%"; double dd = 0, ddR = 0; dd = Drawdown(profitYear, out ddR); // label_ddMax.Text = dd.ToString(); label_ddRel.Text = Math.Round(ddR, 2).ToString() + "%"; LineItem line = pane.AddCurve("Портфель", x, y_profit, Color.Red); line.Symbol.Fill.Type = FillType.Solid; CurveList cl = pane.CurveList; zGC.AxisChange(); zGC.Invalidate(); }
public void doPlot(IEnumerable <Position> positions) { CurveList.Clear(); var infos = Objects.list(Objects.convert(positions, position => researcher.positionInfo(position))); var totalBars = (int)Objects.max(Objects.convert(infos, pnls => (double)pnls.count())); debug("total bars: " + totalBars); var unconditional = new List <double>(Objects.nCopies(totalBars, 0.0)); var conditional = new List <double>(Objects.nCopies(totalBars, 0.0)); var count = new List <int>(Objects.nCopies(totalBars, 0)); Objects.each(infos, pnls => Objects.zeroTo(totalBars, barNum => { unconditional[barNum] += pnls.pnl(barNum); conditional[barNum] += toEnd ? pnls.pnlFrom(barNum) : pnls.pnlTo(barNum); if (barNum < pnls.count()) { count[barNum]++; } debug("barNum = " + barNum + ", pnls.count() - 1 = " + (pnls.count() - 1) + ", count[barNum] = " + count[barNum]); })); debug("unconditional: " + Objects.toShortString(unconditional)); debug("conditional: " + Objects.toShortString(conditional)); debug("count: " + Objects.toShortString(count)); if (isAverage) { Objects.eachIt(count, (i, c) => unconditional[i] /= c); Objects.eachIt(count, (i, c) => conditional[i] /= toEnd ? c : infos.Count); debug("aa unconditional: " + Objects.toShortString(unconditional)); debug("aa conditional: " + Objects.toShortString(conditional)); } addBars("conditional", new[] { Color.Red, Color.Lime }, points(conditional)); addBars("unconditional", new[] { Color.DarkRed, Color.DarkGreen }, points(unconditional)); }
/// <summary> /// This function creates a brep from planar curves /// </summary> /// /// public static Brep[] XCreateBrepFromPlanarCurves(CurveList curves, RhinoDoc doc) { return(Brep.CreatePlanarBreps(curves, doc.ModelAbsoluteTolerance)); //it's a bit odd for us to create our own method XCreateBrepFromPlanarCurves that //simply calls the RhinoCommon CreatePlanarBreps method, but for the purpose of the //exercise, we'll let it go. }
public Chart(float[,] record, CurveList curveItems, double Nz) { InitializeComponent(); CreateGraph(record); Record = record; GcurveItems = curveItems; NZ = Nz; }
/// <summary> /// This is the method that actually does the work. /// </summary> /// <param name="DA">The DA object is used to retrieve from inputs and store in outputs.</param> protected override void SolveInstance(IGH_DataAccess DA) { GeometryBase Geom = default(GeometryBase); Vector3d Direction = default(Vector3d); bool IsDubleSide = true, IsCape = true; Brep Output = default(Brep); if (!DA.GetData(0, ref Geom)) { return; } if (!DA.GetData(1, ref Direction)) { return; } if (!DA.GetData(2, ref IsDubleSide)) { return; } if (!DA.GetData(3, ref IsCape)) { return; } if (Geom is Curve) { Curve Crv = Geom as Curve; Output = this.ExtrudeCurveBothSide(Crv, Direction, IsDubleSide, IsCape); } else if (Geom is Surface) { Surface Srf = Geom as Surface; // //实现在函数里面书写函数 // // Func <Surface, Curve> CreateBoundary = _Srf => { Brep b = _Srf.ToBrep(); CurveList Crvs = new CurveList(); BrepEdgeList es = b.Edges; foreach (BrepEdge e in es) { Crvs.Add(e.EdgeCurve); } return(Curve.JoinCurves(Crvs)[0]); }; Curve Crv = CreateBoundary(Srf); Output = this.ExtrudeCurveBothSide(Crv, Direction, IsDubleSide, IsCape); } if (Output == null) { this.AddRuntimeMessage(GH_RuntimeMessageLevel.Warning, "输入的几何体不是平面几何体"); } DA.SetData(0, Output); }
protected override Result RunCommand(RhinoDoc doc, RunMode mode) { int i; CurveList selectedcurves = new CurveList(); int divnr = 10; Point3d[] divptarray; //declares variable as a standard array in .NET, for use with the out overload below. // step one, select curves -------------------------- var gc = new GetObject(); gc.SetCommandPrompt("Select curves to divide into 10 sections (start+end points added)"); gc.GeometryFilter = ObjectType.Curve; gc.GetMultiple(1, 0); if (gc.CommandResult() != Result.Success) { return(gc.CommandResult()); } //enter the loop for (i = 0; i < gc.ObjectCount; i++) { var curve = gc.Object(i).Curve(); if (null != curve && !curve.IsShort(RhinoMath.ZeroTolerance)) { selectedcurves.Add(curve); } // ADD THE CURVE TO THE CURVES LIST, expanding dynamically through the loop } if (selectedcurves.Count < 1) { return(Result.Failure); } //step 2, divide curves ---------------------------------- for (i = 0; i < selectedcurves.Count; i++) { double[] parameters = selectedcurves[i].DivideByCount(divnr, true, out divptarray); UsefulFunctions.XDrawPoints(divptarray, doc); UsefulFunctions.XDrawCurveTangents(parameters, selectedcurves[i], doc); } return(Result.Success); }
static void WriteHeaders(CurveList curves, StreamWriter writer) { firstElementInLine = true; for (int i = 0; i < curves.Count; i++) { WriteHeaders(curves[i], validDimensions[i], writer); } writer.WriteLine(); }
public static void ExportToCsv(CurveList curves, string filename) { validDimensions = CalculateValidDimensions(curves); using (StreamWriter writer = new StreamWriter(filename, false, ASCIIEncoding.ASCII)) { WriteHeaders(curves, writer); WriteData(curves, writer); } }
static List <bool[]> CalculateValidDimensions(CurveList curves) { List <bool[]> ret = new List <bool[]>(); foreach (CurveItem curve in curves) { ret.Add(DimensionContainsNonZeroData(curve)); } return(ret); }
private void ItemDatabaseOnInitialReadDone(object sender, EventArgs e) { var itemsIDs = m_ItemDatabase.GetItemsIDs().ToList(); CurveList .Select(x => (string)x.Tag) .Where(x => !itemsIDs.Contains(x)) .ToList() .ForEach(RemoveItem); }
private CurveItem GetCurve(string value) { CurveItem item = CurveList.Find(new Predicate <CurveItem>( delegate(CurveItem line) { return(((LogGraphCurveItem)line).ItemID == value); })); return(item); }
public SeismicProfile(int nt, int nx, int nz, float[,] v, CurveList curveItems) { Nt = nt; Nx = nx; Nz = nz; V = v; Record = new float[nx, nt]; GcurveItems = curveItems; setKLines(); }
static int CalculateMaxPoints(CurveList curves) { int max = 0; foreach (CurveItem curve in curves) { max = Math.Max(max, curve.NPts); } return(max); }
private void checkBox_sp_CheckedChanged(object sender, EventArgs e) { GraphPane pane = zGC.GraphPane; if (checkBox_sp.Checked) { Dictionary <double, double> profit = new Dictionary <double, double>(); double[] y = new double[finalArray.GetLength(1)]; for (int i = 0; i < finalArray.GetLength(1); i++) { for (int j = 0; j < finalArray.GetLength(0); j++) { y[i] += finalArray[j, i]; } y[i] /= finalArray.GetLength(0); y[i] *= 100; profit.Add(x[i], y[i]); } double[] y_profit = new double[y.Length]; y_profit[0] = 0; for (int i = 1; i < y_profit.Length; i++) { y_profit[i] = ((y[i] / y[0]) - 1) * 100; } double t = (y[y.Length - 1] - y[0]) / y[0]; double ddr = 0; Drawdown(profit, out ddr); label_sp.Visible = true; label_spP.Text = Math.Round(t * 100, 2).ToString() + "%"; label_spDD.Text = Math.Round(ddr, 2).ToString() + "%"; sp = pane.AddCurve("ЕП", x, y_profit, Color.Green, SymbolType.Square); sp.Symbol.Fill.Type = FillType.Solid; CurveList cl = pane.CurveList; zGC.AxisChange(); zGC.Invalidate(); } else { label_sp.Visible = false; label_spDD.Text = ""; label_spP.Text = ""; pane.CurveList.Remove(sp); zGC.AxisChange(); zGC.Invalidate(); } }
public static void SaveDataAs(CurveList curves, string filename) { string ext = Path.GetExtension(filename).ToLower(); if (!ExportMethods.ContainsKey(ext)) { MessageBox.Show("Cannot write to file format: " + ext); return; } ExportMethods[ext](curves, filename); }
private void Representacion(ZedGraphControl zedControl, int incompleto, int proceso, int procedente, int improcedente, int totales) { GraphPane grafico = zedGrafico.GraphPane; double[] values = { incompleto, proceso, procedente, improcedente }; string[] labels = { "Incompleto", "En proceso", "Procedente", "No procedente" }; Color[] colors = { Color.Orange, Color.Yellow, Color.Green, Color.Red }; grafico.Title.Text = "Expedientes recibidos"; grafico.Fill = new Fill(Color.White, Color.Gray, 45.0f); grafico.Chart.Fill.Type = FillType.None; grafico.Legend.Position = LegendPos.Float; grafico.Legend.Location = new Location(0.95f, 0.15f, CoordType.PaneFraction, AlignH.Right, AlignV.Top); grafico.Legend.FontSpec.Size = 10f; grafico.Legend.IsHStack = false; grafico.Legend.IsVisible = false; PieItem[] slices = new PieItem[values.Length]; slices = grafico.AddPieSlices(values, labels); ((PieItem)slices[0]).Fill.Color = Color.Orange; ((PieItem)slices[1]).Fill.Color = Color.Yellow; ((PieItem)slices[2]).Fill.Color = Color.Green; ((PieItem)slices[3]).Fill.Color = Color.DarkRed; ((PieItem)slices[0]).LabelType = PieLabelType.Name_Value_Percent; ((PieItem)slices[1]).LabelType = PieLabelType.Name_Value_Percent; ((PieItem)slices[2]).LabelType = PieLabelType.Name_Value_Percent; ((PieItem)slices[3]).LabelType = PieLabelType.Name_Value_Percent; CurveList curves = grafico.CurveList; double total = 0; for (int x = 0; x < curves.Count; x++) { total += ((PieItem)curves[x]).Value; } TextObj text = new TextObj("Expedientes totales: " + total.ToString(), 0.12f, 0.95f, CoordType.XChartFractionYPaneFraction); text.Location.AlignH = AlignH.Center; text.Location.AlignV = AlignV.Bottom; text.FontSpec.Border.IsVisible = false; text.FontSpec.Fill = new Fill(Color.White, Color.Gray, 75.0f); grafico.GraphObjList.Add(text); zedGrafico.AxisChange(); zedGrafico.Invalidate(); }
static void WriteData(CurveList curves, StreamWriter writer) { int maxPoints = CalculateMaxPoints(curves); Console.WriteLine(maxPoints); for (int i = 0; i < maxPoints; i++) { Console.WriteLine("line: " + i); firstElementInLine = true; WriteDataRow(curves, i, writer); writer.WriteLine(); } }
private Curve GetSurfaceBoundary(Surface Srf) { Brep b = Srf.ToBrep(); CurveList Crvs = new CurveList(); BrepEdgeList es = b.Edges; foreach (BrepEdge e in es) { Crvs.Add(e.EdgeCurve); } return(Curve.JoinCurves(Crvs)[0]); }
/// <summary> /// 显示板块所有的品种 /// </summary> public void YesVisualAllStocks() { this.progressBar1.Value = 50; GraphPane mPane2 = zedGraphControl1.GraphPane;//获取索引到GraphPane面板上 CurveList curList2 = mPane2.CurveList; foreach (CurveItem curItem in curList2) { curItem.IsVisible = true; } zedGraphControl1.Refresh(); }
public void DisplayCurves() { CurveList allCurves = new CurveList(mCurveList); allCurves.AddRange(highlightList); graph.GraphPane.CurveList = allCurves; if (ScaleType != AxisScaleType.UserDefined) { this.ScaleAxes(); this.UpdateAxes(); } }
/// <summary> /// Constructs a new instance of the ScatterplotView. /// </summary> public ScatterplotView() { InitializeComponent(); scatterplot = new Scatterplot(); classes = new CurveList(); zedGraphControl.GraphPane.Title.Text = "Scatter Plot"; zedGraphControl.GraphPane.XAxis.Title.Text = "X"; zedGraphControl.GraphPane.YAxis.Title.Text = "Y"; zedGraphControl.GraphPane.Fill = new Fill(Color.WhiteSmoke); zedGraphControl.GraphPane.CurveList = classes; }
// Revision: JCarpenter 10/06 /// <summary> /// Find any objects that exist within the specified (screen) rectangle. This method will search through all of the graph objects, such as /// <see cref="Axis"/>, <see cref="Legend"/>, <see cref="PaneBase.Title"/>, /// <see cref="GraphObj"/>, and <see cref="CurveItem"/>. and see if the objects' bounding boxes are within the specified (screen) rectangle This method /// returns true if any are found. /// </summary> /// <param name="rectF"> /// The rect F. /// </param> /// <param name="g"> /// The g. /// </param> /// <param name="containedObjs"> /// The contained Objs. /// </param> /// <returns> /// The <see cref="bool"/>. /// </returns> public bool FindContainedObjects(RectangleF rectF, Graphics g, out CurveList containedObjs) { containedObjs = new CurveList(); foreach (CurveItem ci in this.CurveList) { for (int i = 0; i < ci.Points.Count; i++) { if (ci.Points[i].X > rectF.Left && ci.Points[i].X < rectF.Right && ci.Points[i].Y > rectF.Bottom && ci.Points[i].Y < rectF.Top) { containedObjs.Add(ci); } } } return containedObjs.Count > 0; }
/// <summary> /// Place a list of <see c_ref="CurveItem" />'s in the selection list, removing all other /// items. /// </summary> /// <param name="master">The <see c_ref="MasterPane" /> that is the "owner" /// of the <see c_ref="CurveItem" />'s.</param> /// <param name="ciList">The list of <see c_ref="CurveItem" /> to be added to the list.</param> public void Select( MasterPane master, CurveList ciList ) { //Clear the selection, but don't send the event, //the event will be sent in "AddToSelection" by calling "UpdateSelection" ClearSelection( master, false ); AddToSelection( master, ciList ); }
/// <summary> /// Add a list of <see c_ref="CurveItem" />'s to the selection list. /// </summary> /// <param name="master">The <see c_ref="MasterPane" /> that is the "owner" /// of the <see c_ref="CurveItem" />'s.</param> /// <param name="ciList">The list of <see c_ref="CurveItem" />'s to be added to the list.</param> public void AddToSelection( MasterPane master, CurveList ciList ) { foreach ( CurveItem ci in ciList ) { if ( Contains( ci ) == false ) Add( ci ); } UpdateSelection( master ); }
/// <summary> /// Initializes a new instance of the <see cref="GraphPane"/> class. /// Constructor for the <see cref="GraphPane"/> object. This routine will initialize all member variables and classes, setting appropriate default /// values as defined in the <see cref="Default"/> class. /// </summary> /// <param name="rect"> /// A rectangular screen area where the graph is to be displayed. This area can be any size, and can be resize at any time using the /// <see cref="PaneBase.Rect"/> property. /// </param> /// <param name="title"> /// The <see cref="PaneBase.Title"/> for this <see cref="GraphPane"/> /// </param> /// <param name="xTitle"> /// The <see cref="Axis.Title"/> for the <see cref="XAxis"/> /// </param> /// <param name="yTitle"> /// The <see cref="Axis.Title"/> for the <see cref="YAxis"/> /// </param> public GraphPane(RectangleF rect, string title, string xTitle, string yTitle) : base(title, rect) { this._xAxis = new XAxis(xTitle); this._x2Axis = new X2Axis(string.Empty); this._yAxisList = new YAxisList(); this._y2AxisList = new Y2AxisList(); this._yAxisList.Add(new YAxis(yTitle)); this._y2AxisList.Add(new Y2Axis(string.Empty)); this._curveList = new CurveList(); this._zoomStack = new ZoomStateStack(); this._isIgnoreInitial = Default.IsIgnoreInitial; this._isBoundedRanges = Default.IsBoundedRanges; this._isAlignGrids = false; this._chart = new Chart(); this._barSettings = new BarSettings(this); this._lineType = Default.LineType; }
/// <summary> /// Perform selection on curves within the drag pane, or under the mouse click. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void HandleSelectionFinish(MouseEventArgs e) { if (e.Button != _selectButtons) { Refresh(); return; } PointF mousePtF = BoundPointToRect(new Point(e.X, e.Y), _dragPane.Chart._rect); PointF mousePt = BoundPointToRect(new Point(e.X, e.Y), _dragPane.Rect); Point curPt = PointToScreen(Point.Round(mousePt)); // Only accept a drag if it covers at least 5 pixels in each direction //Point curPt = ( (Control)sender ).PointToScreen( Point.Round( mousePt ) ); if ((Math.Abs(mousePtF.X - _dragStartPt.X) > 4) && (Math.Abs(mousePtF.Y - _dragStartPt.Y) > 4)) { #region New Code to Select on Rubber Band double x1, x2, xx1, xx2; double[] y1, y2, yy1, yy2; PointF startPoint = PointToClient(new Point(Convert.ToInt32(_dragPane.Rect.X), Convert.ToInt32(_dragPane.Rect.Y))); _dragPane.ReverseTransform(_dragStartPt, out x1, out xx1, out y1, out yy1); _dragPane.ReverseTransform(mousePtF, out x2, out xx2, out y2, out yy2); CurveList objects = new CurveList(); double left = Math.Min(x1, x2); double right = Math.Max(x1, x2); double top = 0; double bottom = 0; for (int i = 0; i < y1.Length; i++) { bottom = Math.Min(y1[i], y2[i]); top = Math.Max(y1[i], y2[i]); } for (int i = 0; i < yy1.Length; i++) { bottom = Math.Min(bottom, yy2[i]); bottom = Math.Min(yy1[i], bottom); top = Math.Max(top, yy2[i]); top = Math.Max(yy1[i], top); } double w = right - left; double h = bottom - top; RectangleF rF = new RectangleF((float) left, (float) top, (float) w, (float) h); _dragPane.FindContainedObjects(rF, CreateGraphics(), out objects); if (ModifierKeys == _selectAppendModifierKeys) _selection.AddToSelection(_masterPane, objects); else _selection.Select(_masterPane, objects); #endregion } else // It's a single-select { #region New Code to Single Select using (Graphics g = CreateGraphics()) { int iPt; GraphPane pane; object nearestObj; if (MasterPane.FindNearestPaneObject(mousePt, g, out pane, out nearestObj, out iPt)) { if (nearestObj is CurveItem && iPt >= 0) { if (ModifierKeys == _selectAppendModifierKeys) _selection.AddToSelection(_masterPane, nearestObj as CurveItem); else _selection.Select(_masterPane, nearestObj as CurveItem); } else _selection.ClearSelection(_masterPane); Refresh(); } else { _selection.ClearSelection(_masterPane); } } #endregion New Code to Single Select } using (Graphics g = CreateGraphics()) { // always AxisChange() the dragPane _dragPane.AxisChange(g); foreach (GraphPane pane in _masterPane._paneList) { if (pane != _dragPane && (_isSynchronizeXAxes || _isSynchronizeYAxes)) pane.AxisChange(g); } } Refresh(); }
/// <summary> /// Find the data point that lies closest to the specified mouse (screen) point for the specified curve. /// </summary> /// <remarks> /// This method will search only through the points for the specified curve to determine which point is nearest the mouse point. It will only consider /// points that are within /// <see cref="Default.NearestTol"/> pixels of the screen point. /// </remarks> /// <param name="mousePt"> /// The screen point, in pixel coordinates. /// </param> /// <param name="targetCurve"> /// A <see cref="CurveItem"/> object containing the data points to be searched. /// </param> /// <param name="nearestCurve"> /// A reference to the <see cref="CurveItem"/> /// instance that contains the closest point. nearestCurve will be null if no data points are available. /// </param> /// <param name="iNearest"> /// The index number of the closest point. The actual data vpoint will then be <see cref="CurveItem.Points">CurveItem.Points[iNearest]</see> /// . iNearest will be -1 if no data points are available. /// </param> /// <returns> /// true if a point was found and that point lies within /// <see cref="Default.NearestTol"/> pixels of the screen point, false otherwise. /// </returns> public bool FindNearestPoint(PointF mousePt, CurveItem targetCurve, out CurveItem nearestCurve, out int iNearest) { CurveList targetCurveList = new CurveList(); targetCurveList.Add(targetCurve); return this.FindNearestPoint(mousePt, targetCurveList, out nearestCurve, out iNearest); }
public override Value Evaluate(FSharpList<Value> args) { CurveList curves = new CurveList(); var input = (args[0] as Value.List).Item; foreach (Value v in input) { Curve c = ((Value.Container)v).Item as Curve; curves.Add(c); } _surface = Surface.by_patch(curves); return Value.NewContainer(_surface); }
/// <summary> /// Initializes a new instance of the <see cref="GraphPane"/> class. /// 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 GraphPane(SerializationInfo info, StreamingContext context) : base(info, 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("schema2"); this._xAxis = (XAxis)info.GetValue("xAxis", typeof(XAxis)); if (sch >= 11) { this._x2Axis = (X2Axis)info.GetValue("x2Axis", typeof(X2Axis)); } else { this._x2Axis = new X2Axis(string.Empty); } this._yAxisList = (YAxisList)info.GetValue("yAxisList", typeof(YAxisList)); this._y2AxisList = (Y2AxisList)info.GetValue("y2AxisList", typeof(Y2AxisList)); this._curveList = (CurveList)info.GetValue("curveList", typeof(CurveList)); this._chart = (Chart)info.GetValue("chart", typeof(Chart)); this._barSettings = (BarSettings)info.GetValue("barSettings", typeof(BarSettings)); this._barSettings._ownerPane = this; this._isIgnoreInitial = info.GetBoolean("isIgnoreInitial"); this._isBoundedRanges = info.GetBoolean("isBoundedRanges"); this._isIgnoreMissing = info.GetBoolean("isIgnoreMissing"); this._isAlignGrids = info.GetBoolean("isAlignGrids"); this._lineType = (LineType)info.GetValue("lineType", typeof(LineType)); this._zoomStack = new ZoomStateStack(); }
/// <summary> /// Initializes a new instance of the <see cref="GraphPane"/> class. /// The Copy Constructor /// </summary> /// <param name="rhs"> /// The GraphPane object from which to copy /// </param> public GraphPane(GraphPane rhs) : base(rhs) { // copy values for all the value types this._isIgnoreInitial = rhs.IsIgnoreInitial; this._isBoundedRanges = rhs._isBoundedRanges; this._isAlignGrids = rhs._isAlignGrids; this._chart = rhs._chart.Clone(); this._barSettings = new BarSettings(rhs._barSettings, this); this._lineType = rhs.LineType; // copy all the reference types with deep copies this._xAxis = new XAxis(rhs.XAxis); this._x2Axis = new X2Axis(rhs.X2Axis); this._yAxisList = new YAxisList(rhs._yAxisList); this._y2AxisList = new Y2AxisList(rhs._y2AxisList); this._curveList = new CurveList(rhs.CurveList); this._zoomStack = new ZoomStateStack(rhs._zoomStack); }
/// <summary> /// Find the data point that lies closest to the specified mouse (screen) point. /// </summary> /// <remarks> /// This method will search through the specified list of curves to find which point is nearest. It will only consider points that are within /// <see cref="Default.NearestTol"/> pixels of the screen point, and it will only consider <see cref="CurveItem"/>'s that are in /// <paramref name="targetCurveList"/>. /// </remarks> /// <param name="mousePt"> /// The screen point, in pixel coordinates. /// </param> /// <param name="targetCurveList"> /// A <see cref="CurveList"/> object containing a subset of <see cref="CurveItem"/>'s to be searched. /// </param> /// <param name="nearestCurve"> /// A reference to the <see cref="CurveItem"/> /// instance that contains the closest point. nearestCurve will be null if no data points are available. /// </param> /// <param name="iNearest"> /// The index number of the closest point. The actual data vpoint will then be <see cref="CurveItem.Points">CurveItem.Points[iNearest]</see> /// . iNearest will be -1 if no data points are available. /// </param> /// <returns> /// true if a point was found and that point lies within /// <see cref="Default.NearestTol"/> pixels of the screen point, false otherwise. /// </returns> public bool FindNearestPoint(PointF mousePt, CurveList targetCurveList, out CurveItem nearestCurve, out int iNearest) { CurveItem nearestBar = null; int iNearestBar = -1; nearestCurve = null; iNearest = -1; // If the point is outside the ChartRect, always return false if (!this._chart._rect.Contains(mousePt)) { return false; } double x, x2; double[] y; double[] y2; // ReverseTransform( mousePt, out x, out y, out y2 ); this.ReverseTransform(mousePt, out x, out x2, out y, out y2); if (!this.AxisRangesValid()) { return false; } ValueHandler valueHandler = new ValueHandler(this, false); // double yPixPerUnit = chartRect.Height / ( yAxis.Max - yAxis.Min ); // double y2PixPerUnit; // = chartRect.Height / ( y2Axis.Max - y2Axis.Min ); double yPixPerUnitAct, yAct, yMinAct, yMaxAct, xAct; double minDist = 1e20; double xVal, yVal, dist = 99999, distX, distY; double tolSquared = Default.NearestTol * Default.NearestTol; int iBar = 0; foreach (CurveItem curve in targetCurveList) { // test for pie first...if it's a pie rest of method superfluous if (curve is PieItem && curve.IsVisible) { if (((PieItem)curve).SlicePath != null && ((PieItem)curve).SlicePath.IsVisible(mousePt)) { nearestBar = curve; iNearestBar = 0; } } else if (curve.IsVisible) { int yIndex = curve.GetYAxisIndex(this); Axis yAxis = curve.GetYAxis(this); Axis xAxis = curve.GetXAxis(this); if (curve.IsY2Axis) { yAct = y2[yIndex]; yMinAct = this._y2AxisList[yIndex]._scale._min; yMaxAct = this._y2AxisList[yIndex]._scale._max; } else { yAct = y[yIndex]; yMinAct = this._yAxisList[yIndex]._scale._min; yMaxAct = this._yAxisList[yIndex]._scale._max; } yPixPerUnitAct = this._chart._rect.Height / (yMaxAct - yMinAct); double xPixPerUnit = this._chart._rect.Width / (xAxis._scale._max - xAxis._scale._min); xAct = xAxis is XAxis ? x : x2; IPointList points = curve.Points; float barWidth = curve.GetBarWidth(this); double barWidthUserHalf; Axis baseAxis = curve.BaseAxis(this); bool isXBaseAxis = baseAxis is XAxis || baseAxis is X2Axis; if (isXBaseAxis) { barWidthUserHalf = barWidth / xPixPerUnit / 2.0; } else { barWidthUserHalf = barWidth / yPixPerUnitAct / 2.0; } if (points != null) { for (int iPt = 0; iPt < curve.NPts; iPt++) { // xVal is the user scale X value of the current point if (xAxis._scale.IsAnyOrdinal && !curve.IsOverrideOrdinal) { xVal = iPt + 1.0; } else { xVal = points[iPt].X; } // yVal is the user scale Y value of the current point if (yAxis._scale.IsAnyOrdinal && !curve.IsOverrideOrdinal) { yVal = iPt + 1.0; } else { yVal = points[iPt].Y; } if (xVal != PointPairBase.Missing && yVal != PointPairBase.Missing) { if (curve.IsBar || curve is ErrorBarItem || curve is HiLowBarItem || curve is OHLCBarItem || curve is JapaneseCandleStickItem) { double baseVal, lowVal, hiVal; valueHandler.GetValues(curve, iPt, out baseVal, out lowVal, out hiVal); if (lowVal > hiVal) { double tmpVal = lowVal; lowVal = hiVal; hiVal = tmpVal; } if (isXBaseAxis) { double centerVal = valueHandler.BarCenterValue(curve, barWidth, iPt, xVal, iBar); if (xAct < centerVal - barWidthUserHalf || xAct > centerVal + barWidthUserHalf || yAct < lowVal || yAct > hiVal) { continue; } } else { double centerVal = valueHandler.BarCenterValue(curve, barWidth, iPt, yVal, iBar); if (yAct < centerVal - barWidthUserHalf || yAct > centerVal + barWidthUserHalf || xAct < lowVal || xAct > hiVal) { continue; } } if (nearestBar == null) { iNearestBar = iPt; nearestBar = curve; } } else if (xVal >= xAxis._scale._min && xVal <= xAxis._scale._max && yVal >= yMinAct && yVal <= yMaxAct) { if (curve is LineItem && this._lineType == LineType.Stack) { double zVal; valueHandler.GetValues(curve, iPt, out xVal, out zVal, out yVal); } distX = (xVal - xAct) * xPixPerUnit; distY = (yVal - yAct) * yPixPerUnitAct; dist = distX * distX + distY * distY; if (dist >= minDist) { continue; } minDist = dist; iNearest = iPt; nearestCurve = curve; } } } if (curve.IsBar) { iBar++; } } } } if (nearestCurve is LineItem) { float halfSymbol = ((LineItem)nearestCurve).Symbol.Size * this.CalcScaleFactor() / 2; minDist -= halfSymbol * halfSymbol; if (minDist < 0) { minDist = 0; } } if (minDist >= tolSquared && nearestBar != null) { // if no point met the tolerance, but a bar was found, use it nearestCurve = nearestBar; iNearest = iNearestBar; return true; } if (minDist < tolSquared) { // Did we find a close point, and is it within the tolerance? // (minDist is the square of the distance in pixel units) return true; } return false; }