private void DrawOrUpdateAcLabel(ChartTriangle leftTriangle, ChartTriangle rightTriangle, ChartTrendLine line, long id, ChartText label = null) { var labelTime = line.GetLineCenterTime(); var labelY = line.GetLineCenterY(); var acLength = rightTriangle.Y2 - leftTriangle.Y2; var xaLength = leftTriangle.Y2 - leftTriangle.Y1; var ratio = Math.Round(1 + acLength / xaLength, 3); if (label == null) { DrawLabelText(ratio.ToString(), labelTime, labelY, id, objectNameKey: "AC"); } else { label.Text = ratio.ToString(); label.Time = labelTime; label.Y = labelY; } }
internal void CommonFunctionality(SimpleDataset3D[] arrSimpleDS) { int iCount = 0; Background objCBGND = null; ChartAttribute objWallAttribute = null; Wall3D objxyMinZWall = null; Wall3D objyzMinXWall = null; Wall3D objxzMinYWall = null; LinearAxis xAxis = null; LinearAxis yAxis = null; AxisTitle objXAxisTitle = null; AxisTitle objYAxisTitle = null; NumericAxisLabels XAxisLabel = null; NumericAxisLabels YAxisLabel = null; Grid xGrid = null; Grid yGrid = null; ChartAttribute objAttribute = null; try { iCount = arrSimpleDS.Length; m_objChartView = m_obj3DGraphControl; if (m_obj3DGraphControl != null) { m_objChartView = m_obj3DGraphControl; } string[] sarrLabels = m_sUnits.Split(new char[] { ',' }); m_objFont = new Font("Microsoft Sans Serif", 5, FontStyle.Regular); m_objCartesianCordinates = new CartesianCoordinates(); m_objCartesianCordinates.AutoScale(arrSimpleDS, ChartObj.AUTOAXES_EXACT, ChartObj.AUTOAXES_EXACT); m_objCartesianCordinates.AbsRotateCoordinateSystem(new Point3D(5, 3, 0)); m_objChartView.SetFractionalZViewportDepth(4); objCBGND = new Background(m_objCartesianCordinates, ChartObj.GRAPH_BACKGROUND, Color.FromArgb(241, 241, 247)); m_objChartView.AddChartObject(objCBGND); objWallAttribute = new ChartAttribute(Color.Beige, 0.5, DashStyle.Solid, Color.LightGray); objxyMinZWall = new Wall3D(m_objCartesianCordinates, ChartObj.XY_MAXZ_PLANE, 0, objWallAttribute); m_objChartView.AddChartObject(objxyMinZWall); objyzMinXWall = new Wall3D(m_objCartesianCordinates, ChartObj.YZ_MINX_PLANE, 0, objWallAttribute); m_objChartView.AddChartObject(objyzMinXWall); objxzMinYWall = new Wall3D(m_objCartesianCordinates, ChartObj.XZ_MINY_PLANE, 0, objWallAttribute); m_objChartView.AddChartObject(objxzMinYWall); m_objCartesianCordinates.SetGraphBorderDiagonal(0.15, .15, .90, 0.75); xAxis = new LinearAxis(m_objCartesianCordinates, ChartObj.X_AXIS); xAxis.CalcAutoAxis(); m_objChartView.AddChartObject(xAxis); XAxisLabel = new NumericAxisLabels(xAxis); XAxisLabel.SetTextFont(m_objFont); m_objChartView.AddChartObject(XAxisLabel); switch (m_sTimeAxis) { case "Sec": objXAxisTitle = new AxisTitle(xAxis, m_objFont, "Sec"); m_objChartView.AddChartObject(objXAxisTitle); break; case "Others": objXAxisTitle = new AxisTitle(xAxis, m_objFont, sarrLabels[0]); m_objChartView.AddChartObject(objXAxisTitle); break; } yAxis = new LinearAxis(m_objCartesianCordinates, ChartObj.Y_AXIS); yAxis.CalcAutoAxis(); m_objChartView.AddChartObject(yAxis); YAxisLabel = new NumericAxisLabels(yAxis); YAxisLabel.SetTextFont(m_objFont); m_objChartView.AddChartObject(YAxisLabel); objYAxisTitle = new AxisTitle(yAxis, m_objFont, sarrLabels[1]); m_objChartView.AddChartObject(objYAxisTitle); switch (iCount) { case 1: objAttribute = new ChartAttribute(Color.DarkRed, 0.5, DashStyle.Solid); m_objFirstLinePlot = new SimpleLinePlot(m_objCartesianCordinates, arrSimpleDS[0], objAttribute); m_objChartView.AddChartObject(m_objFirstLinePlot); ChartText objFirstText = new ChartText(m_objCartesianCordinates, m_objFont, (string)m_arlstDates[0], m_objFirstLinePlot.DisplayDataset.XData[m_objFirstLinePlot.DisplayDataset.XData.Length - 60], m_objFirstLinePlot.DisplayDataset.YData[m_objFirstLinePlot.DisplayDataset.YData.Length - 60], ChartObj.PHYS_POS); m_objChartView.AddChartObject(objFirstText); break; case 2: objAttribute = new ChartAttribute(Color.DarkRed, 0.5, DashStyle.Solid); m_objFirstLinePlot = new SimpleLinePlot(m_objCartesianCordinates, arrSimpleDS[0], objAttribute); m_objChartView.AddChartObject(m_objFirstLinePlot); ChartText objNewFirstText = new ChartText(m_objCartesianCordinates, m_objFont, (string)m_arlstDates[1], m_objFirstLinePlot.DisplayDataset.XData[m_objFirstLinePlot.DisplayDataset.XData.Length - 60], m_objFirstLinePlot.DisplayDataset.YData[m_objFirstLinePlot.DisplayDataset.YData.Length - 60], 0.002, ChartObj.PHYS_POS); m_objChartView.AddChartObject(objNewFirstText); objAttribute = new ChartAttribute(Color.DarkGreen, 0.5, DashStyle.Solid); m_objSecondLinePlot = new SimpleLinePlot(m_objCartesianCordinates, arrSimpleDS[1], objAttribute); m_objChartView.AddChartObject(m_objSecondLinePlot); ChartText objSecondText = new ChartText(m_objCartesianCordinates, m_objFont, (string)m_arlstDates[0], m_objSecondLinePlot.DisplayDataset.XData[m_objSecondLinePlot.DisplayDataset.XData.Length - 60], m_objSecondLinePlot.DisplayDataset.YData[m_objSecondLinePlot.DisplayDataset.YData.Length - 60], 0, ChartObj.PHYS_POS); m_objChartView.AddChartObject(objSecondText); break; case 3: objAttribute = new ChartAttribute(Color.DarkRed, 0.5, DashStyle.Solid); m_objFirstLinePlot = new SimpleLinePlot(m_objCartesianCordinates, arrSimpleDS[0], objAttribute); m_objChartView.AddChartObject(m_objFirstLinePlot); ChartText objThirdFirstText = new ChartText(m_objCartesianCordinates, m_objFont, (string)m_arlstDates[2], m_objFirstLinePlot.DisplayDataset.XData[m_objFirstLinePlot.DisplayDataset.XData.Length - 60], m_objFirstLinePlot.DisplayDataset.YData[m_objFirstLinePlot.DisplayDataset.YData.Length - 60], 0.0045, ChartObj.PHYS_POS); m_objChartView.AddChartObject(objThirdFirstText); objAttribute = new ChartAttribute(Color.DarkGreen, 0.5, DashStyle.Solid); m_objSecondLinePlot = new SimpleLinePlot(m_objCartesianCordinates, arrSimpleDS[1], objAttribute); m_objChartView.AddChartObject(m_objSecondLinePlot); ChartText objThirdSecondText = new ChartText(m_objCartesianCordinates, m_objFont, (string)m_arlstDates[1], m_objSecondLinePlot.DisplayDataset.XData[m_objSecondLinePlot.DisplayDataset.XData.Length - 60], m_objSecondLinePlot.DisplayDataset.YData[m_objSecondLinePlot.DisplayDataset.YData.Length - 60], 0.0025, ChartObj.PHYS_POS); m_objChartView.AddChartObject(objThirdSecondText); objAttribute = new ChartAttribute(Color.DarkGoldenrod, 0.5, DashStyle.Solid); m_objThirdLinePlot = new SimpleLinePlot(m_objCartesianCordinates, arrSimpleDS[2], objAttribute); m_objChartView.AddChartObject(m_objThirdLinePlot); ChartText objThirdThirdText = new ChartText(m_objCartesianCordinates, m_objFont, (string)m_arlstDates[0], m_objThirdLinePlot.DisplayDataset.XData[m_objThirdLinePlot.DisplayDataset.XData.Length - 60], m_objThirdLinePlot.DisplayDataset.YData[m_objThirdLinePlot.DisplayDataset.YData.Length - 60], 0, ChartObj.PHYS_POS); m_objChartView.AddChartObject(objThirdThirdText); break; case 4: objAttribute = new ChartAttribute(Color.DarkRed, 0.5, DashStyle.Solid); m_objFirstLinePlot = new SimpleLinePlot(m_objCartesianCordinates, arrSimpleDS[0], objAttribute); m_objChartView.AddChartObject(m_objFirstLinePlot); ChartText objFourthFirstText = new ChartText(m_objCartesianCordinates, m_objFont, (string)m_arlstDates[3], m_objFirstLinePlot.DisplayDataset.XData[m_objFirstLinePlot.DisplayDataset.XData.Length - 60], m_objFirstLinePlot.DisplayDataset.YData[m_objFirstLinePlot.DisplayDataset.YData.Length - 60], 0.0075, ChartObj.PHYS_POS); m_objChartView.AddChartObject(objFourthFirstText); objAttribute = new ChartAttribute(Color.DarkGreen, 0.5, DashStyle.Solid); m_objSecondLinePlot = new SimpleLinePlot(m_objCartesianCordinates, arrSimpleDS[1], objAttribute); m_objChartView.AddChartObject(m_objSecondLinePlot); ChartText objFourthSecondText = new ChartText(m_objCartesianCordinates, m_objFont, (string)m_arlstDates[2], m_objSecondLinePlot.DisplayDataset.XData[m_objSecondLinePlot.DisplayDataset.XData.Length - 60], m_objSecondLinePlot.DisplayDataset.YData[m_objSecondLinePlot.DisplayDataset.YData.Length - 60], 0.0045, ChartObj.PHYS_POS); m_objChartView.AddChartObject(objFourthSecondText); objAttribute = new ChartAttribute(Color.DarkGoldenrod, 0.5, DashStyle.Solid); m_objThirdLinePlot = new SimpleLinePlot(m_objCartesianCordinates, arrSimpleDS[2], objAttribute); m_objChartView.AddChartObject(m_objThirdLinePlot); ChartText objFourthThirdText = new ChartText(m_objCartesianCordinates, m_objFont, (string)m_arlstDates[1], m_objThirdLinePlot.DisplayDataset.XData[m_objThirdLinePlot.DisplayDataset.XData.Length - 60], m_objThirdLinePlot.DisplayDataset.YData[m_objThirdLinePlot.DisplayDataset.YData.Length - 60], 0.002, ChartObj.PHYS_POS); m_objChartView.AddChartObject(objFourthThirdText); objAttribute = new ChartAttribute(Color.DarkViolet, 0.5, DashStyle.Solid); m_objFourthLinePlot = new SimpleLinePlot(m_objCartesianCordinates, arrSimpleDS[3], objAttribute); m_objChartView.AddChartObject(m_objFourthLinePlot); ChartText objFourthFourthText = new ChartText(m_objCartesianCordinates, m_objFont, (string)m_arlstDates[0], m_objFourthLinePlot.DisplayDataset.XData[m_objFourthLinePlot.DisplayDataset.XData.Length - 60], m_objFourthLinePlot.DisplayDataset.YData[m_objFourthLinePlot.DisplayDataset.YData.Length - 60], 0, ChartObj.PHYS_POS); m_objChartView.AddChartObject(objFourthFourthText); break; } } catch { throw; } }
protected override void OnTick() { if (RunInfo.Active) { RunInfo.EnsureAllClosed(); } // Put your core logic here if (c.EntryParameters.EntryMode == EntryMode.Continuous) { } else if (c.EntryParameters.EntryMode == EntryMode.Volume) { if (!RunInfo.Active && LastTempValue != MarketSeries.TickVolume.Last(1)) { LastTempValue = MarketSeries.TickVolume.Last(1); Print("TickVolume.Last(1): {0} - VolumeThreshold.Max: {1}", LastTempValue.ToString(), c.EntryParameters.TickVolumeThreshold.Max.ToString()); } if (!RunInfo.Active && MarketSeries.TickVolume.Maximum(3) <= c.EntryParameters.TickVolumeThreshold.Max.FallbackIfZero(TickVolumeThresholdMax)) { RunInfo.InitializeGrids(); Print("Grids: {0}", String.Join("-", RunInfo.Grids.Select(x => x.EstimatedPricing.ToString()).ToArray())); Print("OriginalAsk: {0}", RunInfo.OriginalAsk.ToString()); Print("UpperGroundStartingPoint: {0}", RunInfo.UpperGroundStartingPoint.ToString()); Print("OriginalBid: {0}", RunInfo.OriginalBid.ToString()); Print("UnderGroundStartingPoint: {0}", RunInfo.UnderGroundStartingPoint.ToString()); RunInfo.PlaceGridOrders(); } else if (RunInfo.Active) { if (TextTotalNetProfit == null) { TextTotalNetProfit = Chart.DrawText("TotalNetProfit", "Total Net Profit: " + RunInfo.TotalNetProfit.ToString("#0.00"), MarketSeries.OpenTime.LastValue, MarketSeries.High.LastValue, Color.White); } else { TextTotalNetProfit.Text = "Total Net Profit: " + RunInfo.TotalNetProfit.ToString("#0.00"); } RunInfo.AnalyzeConditionalClosure(); } } else if (c.EntryParameters.EntryMode == EntryMode.BollingerBandsDistance && RunInfo.Active) { if (TextTotalNetProfit == null) { TextTotalNetProfit = Chart.DrawText("TotalNetProfit", "Total Net Profit: " + RunInfo.TotalNetProfit.ToString("#0.00"), MarketSeries.OpenTime.LastValue, MarketSeries.High.LastValue, Color.White); } else { TextTotalNetProfit.Text = "Total Net Profit: " + RunInfo.TotalNetProfit.ToString("#0.00"); } RunInfo.AnalyzeConditionalClosure(); } else if (c.EntryParameters.EntryMode == EntryMode.TimeRangeOfTheDay) { var CurrentTime = c.EntryParameters.TimeOfTheDay.TimeMode == DateTimeMode.Local ? Time.ToLocalTime() : Time; var IsCycleOkay = c.EntryParameters.TimeOfTheDay.MaximumCycle > 0 ? RunInfo.RunningCycle < c.EntryParameters.TimeOfTheDay.MaximumCycle : true; if (!RunInfo.Active) { if (CurrentTime > CurrentTime.Date.Add(c.EntryParameters.TimeOfTheDay.StartTimeSpan) && CurrentTime < CurrentTime.Date.Add(c.EntryParameters.TimeOfTheDay.EndTimeSpan)) { RunInfo.InitializeCycle(); RunInfo.InitializeGrids(); Print("Grids: {0}", String.Join("-", RunInfo.Grids.Select(x => x.EstimatedPricing.ToString()).ToArray())); Print("OriginalAsk: {0}", RunInfo.OriginalAsk.ToString()); Print("UpperGroundStartingPoint: {0}", RunInfo.UpperGroundStartingPoint.ToString()); Print("OriginalBid: {0}", RunInfo.OriginalBid.ToString()); Print("UnderGroundStartingPoint: {0}", RunInfo.UnderGroundStartingPoint.ToString()); RunInfo.PlaceGridOrders(); } } else { if (TextTotalNetProfit == null) { TextTotalNetProfit = Chart.DrawText("TotalNetProfit", "Total Net Profit: " + RunInfo.TotalNetProfit.ToString("#0.00"), MarketSeries.OpenTime.LastValue, MarketSeries.High.LastValue, Color.White); } else { TextTotalNetProfit.Text = "Total Net Profit: " + RunInfo.TotalNetProfit.ToString("#0.00"); } RunInfo.AnalyzeConditionalClosure(); } } }
private void DrawOrUpdateSecondConnectionLineLabel(ChartTrendLine fifthLine, ChartTrendLine thirdLine, ChartTrendLine secondConnectionLine, long id, ChartText label = null) { var fifthLineLength = fifthLine.Y2 - fifthLine.Y1; var diffLength = thirdLine.Y2 - fifthLine.Y2; var ratio = Math.Round(diffLength / fifthLineLength, 3); var labelTime = secondConnectionLine.GetLineCenterTime(); var labelY = secondConnectionLine.GetLineCenterY(); if (label == null) { DrawLabelText(ratio.ToString(), labelTime, labelY, id, objectNameKey: "SecondConnection"); } else { label.Text = ratio.ToString(); label.Time = labelTime; label.Y = labelY; } }
private void GenerateBarsInChart() { LengthForXAxis = 1; //reset variable to zero if it is not 1 (which is the standard offset from the Y-Axis to not overlap) double SpaceAvailablePerBar = ((double)ChartWidth - 200) / (double)DataList.DataPoints.Count; // the 2 here should be "assignable" BarHeightModifier = (ChartHeight - 250) / (HigestTickMarkValue - LowestTickMarkValue); // space available per bar gives us the amount of pixels we are allowed to spend, then we add in emtpy spaces with BarGapModifier // if anything other than a number between 0 and 1, don't show any gaps between bars if (AddWhiteSpacePerBar < 0 || AddWhiteSpacePerBar > 1) { AddWhiteSpacePerBar = 0; } double BarWidthWhitespace = SpaceAvailablePerBar * AddWhiteSpacePerBar; //calculate whitespace per bar BarWidth = SpaceAvailablePerBar - BarWidthWhitespace; //leftover amounts go to the bar itself for (int LoopCounter = 0; LoopCounter < DataList.DataPoints.Count; LoopCounter++)//using loopcounter since we need to know on which bar we are for positioning { var CurrentBar = new ChartBar(); CurrentBar.Name = "BarInChart"; //Identifier for canvas collection if (!DataList.TargetLine.Equals(null)) { if (DataList.DataPoints[LoopCounter].Value < DataList.TargetLine) { CurrentBar.Fill = DataList.WorseThanTargetColor; } else { CurrentBar.Fill = DataList.BetterThanTargetColor; } } else { CurrentBar.Fill = DataList.Color; } CurrentBar.Width = BarWidth; //set the bar width to represent the data if (ForceYStartAtZero) { CurrentBar.Height = BarHeightModifier * DataList.DataPoints[LoopCounter].Value; CurrentBar.YPosition = (ChartHeight - 150) - DataList.DataPoints[LoopCounter].Value * BarHeightModifier - 2; //Canvas.SetTop(CurrentBar, (ChartHeight-150) - DataList.DataPoints[LoopCounter].Value * BarHeightModifier - 2); } else { CurrentBar.Height = BarHeightModifier * (DataList.DataPoints[LoopCounter].Value - LowestTickMarkValue); CurrentBar.YPosition = (ChartHeight - 150) - (DataList.DataPoints[LoopCounter].Value - LowestTickMarkValue) * BarHeightModifier - 2; //Canvas.SetTop(CurrentBar, (ChartHeight-150) - (DataList.DataPoints[LoopCounter].Value - LowestTickMarkValue) * BarHeightModifier - 2); } //now we need to position the bar correctly on the graph, how many pixels to the right? // 3 is the standard offset to not hit the Y-Axis // BarWidth is the width of the bar itself, barWidthWhitespace is the gaps between the bars // the last bit ensures the first bar also has half a whitespace in front of it // add a bit of whitespace before the first bar, makes it look better in the chart if (LoopCounter == 0) { LengthForXAxis += BarWidthWhitespace / 2 + 100; } CurrentBar.XPosition = LengthForXAxis; //Canvas.SetLeft(CurrentBar, LengthForXAxis); ChartNodesCollection.Add(CurrentBar); //ShapeCollection.Children.Add(CurrentBar); // if the datapoint has a name, it should display below the bar if (!string.IsNullOrWhiteSpace(DataList.DataPoints[LoopCounter].Name)) { var BarName = new ChartText(); BarName.Name = "BarInChartNameBox"; BarName.Text = DataList.DataPoints[LoopCounter].Name; BarName.YPosition = ChartHeight - 150; BarName.XPosition = LengthForXAxis + SpaceAvailablePerBar / 2; BarName.Width = 200; //Canvas.SetTop(BarName, ChartHeight-150); //Canvas.SetLeft(BarName, LengthForXAxis+SpaceAvailablePerBar/2); BarName.RenderTransform = new RotateTransform(30); ChartNodesCollection.Add(BarName); //ShapeCollection.Children.Add(BarName); } LengthForXAxis += (BarWidth) + (BarWidthWhitespace); //prepare for adding the next bar in the chart :) } }
public void LoadGraph() { ChartEngine tempChartEngine = new ChartEngine(); tempChartEngine.Size = GraphPictureBox.Size; tempChartEngine.ShowXValues = true; tempChartEngine.ShowYValues = true; // tempChartEngine.Padding = 40; tempChartEngine.BottomChartPadding = 30; tempChartEngine.LeftChartPadding = 40; ChartText tempChartText = new ChartText(); tempChartText.Text = "Hourly Sales"; tempChartEngine.Title = tempChartText; CPaymentManager tempPaymentManager = new CPaymentManager(); CResult oResult = tempPaymentManager.GetSortedPayment(DateTime.Now); double MaxAmount = 0.0; if (oResult.IsSuccess && oResult.Data != null) { MaxAmount = (double)oResult.Data; } // tempChartEngine.YValuesInterval = (int)Math.Floor(MaxAmount / 20); tempChartEngine.YValuesInterval = GetInterVal(MaxAmount); tempChartEngine.YCustomEnd = GetCustomEnd(GetInterVal(MaxAmount), MaxAmount); ChartCollection tempChartCollection = new ChartCollection(tempChartEngine); tempChartEngine.Charts = tempChartCollection; DateTime inCurrentDate = DateTime.Now; GetTimeSpan(inCurrentDate); //Data Access try { CPcInfoManager tempPcInfoManager = new CPcInfoManager(); IPHostEntry ipEntry = System.Net.Dns.GetHostByName(Dns.GetHostName()); CPcInfo tempPcInfo = (CPcInfo)tempPcInfoManager.PcInfoByPcIP(ipEntry.AddressList[0].ToString()).Data; DataSet tempHourlySaleDataSet = new DataSet(); CCommonConstants oConstants = ConfigManager.GetConfig<CCommonConstants>(); String sSql = String.Format("select 'NewTime' as \"NewTime\",bill_print_time.payment_time as \"Time\",payment.total_amount as \"Amount\" from payment,bill_print_time where payment.order_id=bill_print_time.order_id and bill_print_time.payment_time>={0} and bill_print_time.payment_time<{1} and payment.pc_id={2}", m_oStartTime, m_oEndTime, tempPcInfo.PcID); SqlDataAdapter tempSqlDataAdapter = new SqlDataAdapter(sSql, oConstants.DBConnection); tempSqlDataAdapter.Fill(tempHourlySaleDataSet); sSql = String.Format("select 'NewTime' as \"NewTime\",deposit_time as \"Time\",total_amount as \"Amount\" from deposit where deposit_time >= {0} and deposit_time < {1} and deposit.pc_id={2}", m_oStartTime, m_oEndTime, tempPcInfo.PcID); tempSqlDataAdapter = new SqlDataAdapter(sSql, oConstants.DBConnection); tempSqlDataAdapter.Fill(tempHourlySaleDataSet); ConvertTime(ref tempHourlySaleDataSet); //start dummy time DataRow row1 = tempHourlySaleDataSet.Tables[0].NewRow(); row1["NewTime"] = "0:00"; row1["Amount"] = "0.000"; //end dummy time DataRow row2 = tempHourlySaleDataSet.Tables[0].NewRow(); row2["NewTime"] = "23:59"; row2["Amount"] = "0.000"; tempHourlySaleDataSet.Tables[0].Rows.Add(row1); tempHourlySaleDataSet.Tables[0].Rows.Add(row2); Chart tempLineChart = new LineChart(); tempLineChart.Line.Color = Color.Red; tempLineChart.ShowLineMarkers = false; tempLineChart.Line.Width = (float)2.0; DataTableReader oReader = tempHourlySaleDataSet.Tables[0].CreateDataReader(); tempLineChart.DataSource = oReader; tempLineChart.DataXValueField = "NewTime"; tempLineChart.DataYValueField = "Amount"; tempLineChart.DataBind(); tempChartCollection.Add(tempLineChart); Image image = tempChartEngine.GetBitmap(); GraphPictureBox.Image = image; GraphPictureBox.Update(); } catch (Exception exp) { throw exp; } }
private void DrawLabelBd(ChartTriangle leftTriangle, ChartTriangle rightTriangle, long id, ChartText label = null) { var abLength = leftTriangle.Y2 - leftTriangle.Y1; var bdLength = rightTriangle.Y3 - rightTriangle.Y2; var ratio = Math.Round(1 + bdLength / abLength, 3); var labelTime = rightTriangle.Time2.AddMilliseconds((rightTriangle.Time3 - rightTriangle.Time2).TotalMilliseconds * 0.7); var labelY = rightTriangle.Y2 + ((rightTriangle.Y3 - rightTriangle.Y2) / 2); if (label == null) { DrawLabelText(ratio.ToString(), labelTime, labelY, id, objectNameKey: "BD"); } else { label.Text = ratio.ToString(); label.Time = labelTime; label.Y = labelY; } }
/// <summary> /// Draws the graph /// </summary> private void DrawGraph() { if (CanvasHeight == 0 || CanvasWidth == 0) { return; } //clear the containers RectangleItems.Clear(); LineItems.Clear(); TextItems.Clear(); PointCollection points = new PointCollection(); //set some stuff int numPoints = 100; int ticks = 8; //get the max an min of the efficieny points double maxOrd = EfficiencyMeasurements.Max(e => e.Efficiency); double minOrd = EfficiencyMeasurements.Min(e => e.Efficiency); //get ordinate graph bounds that look nice double ordTickRange = GetTickRange(maxOrd - minOrd, ticks); double ordTickMag = Math.Log10(ordTickRange) > 0 ? Math.Ceiling(Math.Log10(ordTickRange)) : Math.Floor(Math.Log10(ordTickRange)); maxOrd = ordTickRange * Math.Round(1 + maxOrd / ordTickRange); minOrd = ordTickRange * (Math.Round(minOrd / ordTickRange - 1)); double minAbsc = 0;// Properties.Settings.Default.LOWERELIMT * 0.75; double maxAbsc = Properties.Settings.Default.UPPERENERGY; //get abscissa graph bounds that look nice double abscTickRange = GetTickRange(maxAbsc - minAbsc, ticks); double abscTickMag = Math.Log10(abscTickRange) > 0 ? Math.Ceiling(Math.Log10(abscTickRange)) : Math.Floor(Math.Log10(abscTickRange)); maxAbsc = abscTickRange * Math.Round(maxAbsc / abscTickRange); minAbsc = abscTickRange * (Math.Round(minAbsc / abscTickRange)); int seperation = 20; Rectangle chart = new Rectangle(0.2 * CanvasWidth - seperation, seperation, (int)(0.8F * CanvasWidth), (int)(0.8F * CanvasHeight)); //Rectangle chart = new Rectangle(); RectangleItems.Add(chart); //get the energy limit double lowE = minAbsc;// Properties.Settings.Default.LOWERELIMT * 0.75; double highE = maxAbsc; //get the position converstion factors. double xconv = chart.Width / (highE - lowE); double xoff = chart.Right - (xconv * highE); double yconv = chart.Height / (minOrd - maxOrd); double yoff = chart.Bottom - (yconv * minOrd); //build a formatting string StringBuilder format = new StringBuilder("0"); format.Append(ordTickMag >= 0 ? "" : "."); for (int j = 0; j < Math.Abs(ordTickMag); j++) { format.Append(0); } //loop through and add lables int tickLength = 10; double ord = minOrd, absc = minAbsc; while (Math.Round(ord, (int)Math.Abs(ordTickMag)) <= maxOrd) { //draw the y-axis double y;// = (yconv * (ord) + yoff); if (Math.Abs(ord - minOrd) < 1e-6) { y = chart.Bottom - chart.StrokeWeight / 2; } else if (Math.Abs(ord - maxOrd) < 1e-6) { y = chart.Top + chart.StrokeWeight / 2; } else { y = (yconv * (ord) + yoff); LineItems.Add(new Line(chart.Left, y, chart.Right, y) { LineDashArray = { 2, 1 }, }); } LineItems.Add(new Line(chart.Left - tickLength, y, chart.Left + tickLength, y)); //create the label string label = (ord).ToString(format.ToString()); ChartText labelText = new ChartText(label) { //position the label //X = chart.Left - 2 - 0.2*CanvasWidth, X = 0, Y = y + (ordTickRange * yconv) / 2, Width = chart.Left - tickLength - 2, Height = Math.Abs(ordTickRange * yconv), TextHorizontalAlignment = HorizontalAlignment.Right, TextVerticalAlignment = VerticalAlignment.Center }; TextItems.Add(labelText); ord += ordTickRange; } while (Math.Round(absc, (int)Math.Abs(abscTickMag)) <= maxAbsc) { //draw the x-axis double x;// = (xconv * (absc) + xoff); if (Math.Abs(absc - minAbsc) < 1e-6) { x = chart.Left + chart.StrokeWeight / 2; } else if (Math.Abs(absc - maxAbsc) < 1e-6) { x = chart.Right - chart.StrokeWeight / 2; } else { x = (xconv * (absc) + xoff); LineItems.Add(new Line(x, chart.Bottom, x, chart.Top) { LineDashArray = { 2, 1 }, }); } LineItems.Add(new Line(x, chart.Bottom + tickLength, x, chart.Bottom - tickLength)); string label = (absc).ToString(); ChartText labelText = new ChartText(label) { Width = abscTickRange * xconv, Height = 0.2 * CanvasHeight - tickLength - 2 - seperation, //position the label X = x - (abscTickRange * xconv) / 2, Y = chart.Bottom + tickLength + 2, TextHorizontalAlignment = HorizontalAlignment.Center, TextVerticalAlignment = VerticalAlignment.Top }; TextItems.Add(labelText); absc += abscTickRange; } //fill the an array of points that represents the curve double eJump = (highE - lowE) / numPoints; //CurvePoints = new Point[numPoints]; double ene = lowE; for (int i = 0; i < numPoints; i++) { ene += eJump; double eff = data.GetEfficiency(ene); int x = Convert.ToInt32(ene * xconv + xoff); double y = yoff + eff * yconv; if (y > chart.Bottom || double.IsNaN(y)) { y = chart.Bottom; } else if (y < chart.Top || double.IsInfinity(y)) { y = chart.Top; } points.Add(new Point(x, y)); } this.CurvePoints = points; //make the graph thick //put the efficiency points on the chart for (int i = 0; i < EfficiencyMeasurements.Count; i++) { int x = Convert.ToInt32(EfficiencyMeasurements[i].Energy * xconv + xoff); int y = Convert.ToInt32(yoff + EfficiencyMeasurements[i].Efficiency * yconv); int ptSize = 2; RectangleItems.Add(new Rectangle(x - ptSize, y - ptSize, 2 * ptSize, 2 * ptSize)); //add the error bars LineItems.Add(new Line(x, y - EfficiencyMeasurements[i].EfficiencyUncertainty * yconv, x, y + EfficiencyMeasurements[i].EfficiencyUncertainty * yconv)); } WriteEfficiencyEquation(); }