public void FinishedAddingChromatograms(IEnumerable <RetentionTimeValues> bestPeaks, bool forceZoom) { var bestPeakList = bestPeaks.Where(peak => null != peak).ToList(); if (!_zoomLocked) { if (forceZoom || !_displayState.ZoomStateValid) { var chromDisplayState = _displayState as ChromDisplayState; if (chromDisplayState != null) { AutoZoomChromatograms(bestPeakList); } } } using (var graphics = GraphControl.CreateGraphics()) { foreach (MSGraphPane graphPane in GraphControl.MasterPane.PaneList) { // This sets the scale, but also gets point annotations. So, it // needs to be called every time, but only once for efficiency. graphPane.SetScale(graphics); } } GraphControl.AxisChange(); GraphControl.Invalidate(); }
public void FinishedAddingChromatograms(double bestStartTime, double bestEndTime, bool forceZoom, double leftPeakWidth = 0, double rightPeakWidth = 0) { if (!_zoomLocked) { if (forceZoom || !_displayState.ZoomStateValid) { var chromDisplayState = _displayState as ChromDisplayState; if (chromDisplayState != null) { AutoZoomChromatograms(bestStartTime, bestEndTime, leftPeakWidth, rightPeakWidth); } } } using (var graphics = GraphControl.CreateGraphics()) { foreach (MSGraphPane graphPane in GraphControl.MasterPane.PaneList) { // This sets the scale, but also gets point annotations. So, it // needs to be called every time, but only once for efficiency. graphPane.SetScale(graphics); } } GraphControl.AxisChange(); GraphControl.Invalidate(); }
private void UpdateCurveForcely(CurveItem curve, Curve crv) { GraphControl.GraphPane.CurveList.Remove(curve); if (!IsBarType) { var newCurve = GraphControl.GraphPane.AddCurve(crv.Name, crv.X, crv.Y, crv.Color, crv.Type); newCurve.Tag = crv.Tag; newCurve.IsVisible = crv.IsVisible; newCurve.Line.Width = crv.Width; newCurve.Line.IsVisible = crv.LineVisible; if (crv.CurveBrush.Count >= 2) { newCurve.Line.Fill = new Fill(crv.CurveBrush.ToArray()); } newCurve.Symbol.Size = crv.SymbSize; newCurve.Symbol.Fill.Color = crv.SymbColor; newCurve.Symbol.Fill.Type = FillType.Solid; } else { var newBar = GraphControl.GraphPane.AddBar(crv.Name, crv.X, crv.Y, crv.Color); newBar.Tag = crv.Tag; newBar.IsVisible = crv.IsVisible; newBar.Bar.Fill = new Fill(crv.Color); newBar.Bar.Fill.Type = FillType.Solid; GraphControl.GraphPane.BarSettings.MinClusterGap = 0.0f; } GraphControl.AxisChange(); GraphControl.Invalidate(); }
private void OnItemChanged(object sender, PropertyChangedEventArgs e) { var crv = (Curve)sender; var curve = GraphControl.GraphPane.CurveList.Single(x => (string)x.Tag == crv.Tag); if (curve == null) { return; } switch (e.PropertyName) { case "Color": curve.Color = crv.Color; break; case "IsVisible": curve.IsVisible = crv.IsVisible; break; case "Type": case "Width": case "CurveBrush": case "LineVisible": case "SymbColor": case "SymbSize": UpdateCurveForcely(curve, crv); break; default: break; } GraphControl.AxisChange(); GraphControl.Invalidate(); }
private void OnCollectionChanged(object sender, NotifyCollectionChangedEventArgs e) { if (e.Action == NotifyCollectionChangedAction.Reset) { // Clear and update entire collection GraphControl.GraphPane.CurveList.Clear(); } if (e.NewItems != null) { foreach (Curve item in e.NewItems) { item.PropertyChanged += OnItemChanged; item.PointsAdded += PointsAdded; item.Refreshed += PointsAdded; if (!IsBarType) { var curve = GraphControl.GraphPane.AddCurve(item.Name, item.X, item.Y, item.Color, SymbolType.None); curve.Tag = item.Tag; } else { BarItem bar = GraphControl.GraphPane.AddBar(item.Name, item.X, item.Y, item.Color); GraphControl.GraphPane.BarSettings.MinClusterGap = 0.0f; bar.Bar.Fill = new Fill(item.Color); bar.Bar.Fill.Type = FillType.Solid; bar.Tag = item.Tag; } } } if (e.OldItems != null) { foreach (Curve item in e.OldItems) { item.PropertyChanged -= OnItemChanged; item.PointsAdded -= PointsAdded; item.Refreshed -= PointsAdded; var crv = GraphControl.GraphPane.CurveList.Single(x => (string)x.Tag == item.Tag); if (crv == null) { return; } GraphControl.GraphPane.CurveList.Remove(crv); } } OnPropertyChanged("CurvesCount"); GraphControl.AxisChange(); GraphControl.Invalidate(); }
public IEnumerable <CurveItem> SetErrorGraphItems(IEnumerable <IMSGraphItemInfo> errorItems) { var curveItems = new List <CurveItem>(); SetDisplayState(new ErrorDisplayState()); var pane = _displayState.GetOrCreateGraphPane(GraphControl, PaneKey.DEFAULT); pane.Legend.IsVisible = false; foreach (var msGraphItem in errorItems) { var curveItem = GraphControl.AddGraphItem(pane, msGraphItem); curveItem.Label.IsVisible = false; curveItems.Add(curveItem); pane.Title.Text = msGraphItem.Title; } GraphControl.AxisChange(); GraphControl.Invalidate(); return(curveItems); }
private void UpdateGraph() { var pane = GraphControl.GraphPane; if (pane.CurveList.Count > 0) { pane.CurveList.Clear(); } if (Block == null) { return; } Block.Execute(); var outputNode = Block.OutputNodes.FirstOrDefault(it => it.Name == ShowOutputList.Text); if (outputNode == null || outputNode.Object == null || outputNode.Object.Count == 0) { NoDataLabel.Visible = true; GraphControl.Invalidate(); GraphControl.Refresh(); return; } NoDataLabel.Visible = false; var index = ShowOutputSignal.SelectedIndex; if (index == -1 || index > outputNode.Object.Count - 1) { index = 0; } var signal = outputNode.Object[index]; var samples = signal.GetSamplesPair().ToList(); var yAxys = new ZedGraph.PointPairList(); yAxys.AddRange(samples.Select(it => new ZedGraph.PointPair(it[1], it[0]))); pane.AddCurve(outputNode.Name, yAxys, Color.Red, ZedGraph.SymbolType.None); if (signal.CustomPlot != null && signal.CustomPlot.Length > 0) { if (signal.CustomPlot.Length == 2) { var minValue = signal.Samples.Min() * 1.1; var maxValue = signal.Samples.Max() * 1.1; var area = new ZedGraph.PointPairList { { signal.CustomPlot[0], minValue }, { signal.CustomPlot[0], maxValue }, { signal.CustomPlot[0], maxValue }, { signal.CustomPlot[1], maxValue }, { signal.CustomPlot[1], maxValue }, { signal.CustomPlot[1], minValue }, { signal.CustomPlot[1], minValue }, { signal.CustomPlot[0], minValue } }; pane.AddCurve(DesignerResources.PreviousSize, area, Color.Orange, ZedGraph.SymbolType.None); } } pane.Legend.IsVisible = false; pane.Title.Text = ApplicationUtils.GetResourceString(outputNode.Name); pane.XAxis.Title.IsVisible = false; pane.YAxis.Title.IsVisible = false; if (!pane.IsZoomed && samples.Count() != 0) { pane.XAxis.Scale.Min = samples.ElementAt(0)[1]; pane.XAxis.Scale.Max = samples.ElementAt(samples.Count() - 1)[1]; } GraphControl.AxisChange(); GraphControl.Invalidate(); GraphControl.Refresh(); }
public void GenerateFrameTypeChart( TSPlaylistFile playlist, ushort PID, int angleIndex, bool isSizes) { IsHoverDisabled = true; GraphControl.GraphPane.XAxis.Title.Text = "Frame Type"; if (isSizes) { UnitText = "KB"; GraphControl.GraphPane.YAxis.Title.Text = "Average / Peak Size (KB)"; } else { UnitText = ""; GraphControl.GraphPane.YAxis.Title.Text = "Count"; } Dictionary <string, double> frameCount = new Dictionary <string, double>(); Dictionary <string, double> frameSizes = new Dictionary <string, double>(); Dictionary <string, double> framePeaks = new Dictionary <string, double>(); foreach (TSStreamClip clip in playlist.StreamClips) { if (clip.AngleIndex != angleIndex || clip.StreamFile == null || clip.StreamFile.StreamDiagnostics == null || !clip.StreamFile.StreamDiagnostics.ContainsKey(PID)) { continue; } List <TSStreamDiagnostics> diagList = clip.StreamFile.StreamDiagnostics[PID]; for (int i = 0; i < diagList.Count; i++) { TSStreamDiagnostics diag = diagList[i]; if (diag.Tag == null) { continue; } string frameType = diag.Tag; double frameSize = diag.Bytes / 1024; if (!framePeaks.ContainsKey(frameType)) { framePeaks[frameType] = frameSize; } else if (frameSize > framePeaks[frameType]) { framePeaks[frameType] = frameSize; } if (!frameCount.ContainsKey(frameType)) { frameCount[frameType] = 0; } frameCount[frameType]++; if (!frameSizes.ContainsKey(frameType)) { frameSizes[frameType] = 0; } frameSizes[frameType] += frameSize; } } string[] labels = new string[frameCount.Keys.Count]; double[] values = new double[frameCount.Keys.Count]; double[] peaks = new double[frameCount.Keys.Count]; Dictionary <string, int> frameTypes = new Dictionary <string, int>(); frameCount.Keys.CopyTo(labels, 0); double totalFrameCount = 0; for (int i = 0; i < labels.Length; i++) { string label = labels[i]; frameTypes[label] = i; if (isSizes) { values[i] = frameSizes[label] / frameCount[label]; peaks[i] = framePeaks[label]; } else { values[i] = frameCount[label]; } totalFrameCount += frameCount[label]; } if (isSizes) { BarItem barItem = GraphControl.GraphPane.AddBar( "Average", null, values, Color.Black); barItem.Bar.Fill.Type = FillType.Solid; BarItem barItemMax = GraphControl.GraphPane.AddBar( "Peak", null, peaks, Color.Black); barItemMax.Bar.Fill.Type = FillType.None; GraphControl.GraphPane.XAxis.MajorTic.IsBetweenLabels = true; GraphControl.GraphPane.XAxis.Scale.TextLabels = labels; GraphControl.GraphPane.XAxis.Type = AxisType.Text; GraphControl.AxisChange(); GraphControl.GraphPane.YAxis.Scale.Max += GraphControl.GraphPane.YAxis.Scale.MajorStep; BarItem.CreateBarLabels(GraphControl.GraphPane, false, "f0"); GraphControl.GraphPane.Legend.IsVisible = true; } else { GraphControl.GraphPane.Chart.Fill.Type = FillType.None; GraphControl.GraphPane.XAxis.IsVisible = false; GraphControl.GraphPane.YAxis.IsVisible = false; int drgb = (int)Math.Truncate(255.0 / labels.Length); int rgb = 0; List <SortableFrameCount> sortedFrameCounts = new List <SortableFrameCount>(); foreach (string frameType in frameCount.Keys) { sortedFrameCounts.Add(new SortableFrameCount(frameType, frameCount[frameType])); } sortedFrameCounts.Sort(); int j = sortedFrameCounts.Count; for (int i = 0; i < j; i++) { AddPieSlice(sortedFrameCounts[i].Name, sortedFrameCounts[i].Count, totalFrameCount, rgb); rgb += drgb; if (--j > i) { AddPieSlice(sortedFrameCounts[j].Name, sortedFrameCounts[j].Count, totalFrameCount, rgb); rgb += drgb; } } GraphControl.GraphPane.AxisChange(); } GraphControl.IsShowHScrollBar = false; GraphControl.IsAutoScrollRange = false; GraphControl.IsEnableHPan = false; GraphControl.IsEnableHZoom = false; GraphControl.IsEnableSelection = false; GraphControl.IsEnableWheelZoom = false; }
public void GenerateFrameSizeChart( TSPlaylistFile playlist, ushort PID, int angleIndex) { UnitText = "KB"; GraphControl.GraphPane.XAxis.Title.Text = "Time (minutes)"; GraphControl.GraphPane.YAxis.Title.Text = "Size (KB)"; PointPairList pointsMin = new PointPairList(); PointPairList pointsMax = new PointPairList(); PointPairList pointsAvg = new PointPairList(); double pointPosition = 0; double pointSeconds = 1.0; double pointMin = double.MaxValue; double pointMax = 0; double pointAvg = 0; int pointCount = 0; double overallMax = 0; foreach (TSStreamClip clip in playlist.StreamClips) { if (clip.AngleIndex != angleIndex || clip.StreamFile == null || clip.StreamFile.StreamDiagnostics == null || !clip.StreamFile.StreamDiagnostics.ContainsKey(PID)) { continue; } List <TSStreamDiagnostics> diagList = clip.StreamFile.StreamDiagnostics[PID]; for (int i = 0; i < diagList.Count; i++) { TSStreamDiagnostics diag = diagList[i]; if (diag.Tag == null) { continue; } string frameType = diag.Tag; double frameSize = diag.Bytes / 1024; pointPosition = diag.Marker - clip.TimeIn + clip.RelativeTimeIn; if (frameSize > overallMax) { overallMax = frameSize; } if (frameSize < pointMin) { pointMin = frameSize; } if (frameSize > pointMax) { pointMax = frameSize; } pointCount++; pointAvg += frameSize; if (pointPosition >= pointSeconds) { for (double x = pointSeconds; x < (pointPosition - 1); x++) { double pointX = (x - 1) / 60; pointsMin.Add(pointX, 0); pointsAvg.Add(pointX, 0); pointsMax.Add(pointX, 0); pointSeconds += 1; } double pointMinutes = (pointSeconds - 1) / 60; pointsMin.Add(pointMinutes, pointMin); pointsAvg.Add(pointMinutes, pointAvg / pointCount); pointsMax.Add(pointMinutes, pointMax); pointMin = double.MaxValue; pointMax = 0; pointAvg = 0; pointCount = 0; pointSeconds += 1; } } } for (double x = pointSeconds; x < playlist.TotalLength; x++) { double pointX = (x - 1) / 60; pointsMin.Add(pointX, 0); pointsAvg.Add(pointX, 0); pointsMax.Add(pointX, 0); } LineItem avgCurve = GraphControl.GraphPane.AddCurve( "Avg", pointsAvg, Color.Gray, SymbolType.None); avgCurve.Line.IsSmooth = true; LineItem minCurve = GraphControl.GraphPane.AddCurve( "Min", pointsMin, Color.LightGray, SymbolType.None); minCurve.Line.IsSmooth = true; minCurve.Line.Fill = new Fill(Color.White); LineItem maxCurve = GraphControl.GraphPane.AddCurve( "Max", pointsMax, Color.LightGray, SymbolType.None); maxCurve.Line.IsSmooth = true; maxCurve.Line.Fill = new Fill(Color.LightGray); GraphControl.GraphPane.XAxis.Scale.Min = 0; GraphControl.GraphPane.XAxis.Scale.Max = playlist.TotalLength / 60; GraphControl.GraphPane.YAxis.Scale.Min = 0; GraphControl.GraphPane.Y2Axis.Scale.Min = 0; GraphControl.GraphPane.Y2Axis.IsVisible = true; GraphControl.AxisChange(); }
public void GenerateWindowChart( TSPlaylistFile playlist, ushort PID, int angleIndex, double windowSize) { UnitText = "Mbps"; GraphControl.GraphPane.XAxis.Title.Text = "Time (minutes)"; GraphControl.GraphPane.YAxis.Title.Text = "Bitrate (Mbps)"; PointPairList pointsMin = new PointPairList(); PointPairList pointsMax = new PointPairList(); PointPairList pointsAvg = new PointPairList(); Queue <double> windowBits = new Queue <double>(); Queue <double> windowSeconds = new Queue <double>(); double windowBitsSum = 0; double windowSecondsSum = 0; double pointPosition = 0; double pointSeconds = 1.0; double pointMin = double.MaxValue; double pointMax = 0; double pointAvg = 0; int pointCount = 0; foreach (TSStreamClip clip in playlist.StreamClips) { if (clip.AngleIndex != angleIndex || clip.StreamFile == null || clip.StreamFile.StreamDiagnostics == null || !clip.StreamFile.StreamDiagnostics.ContainsKey(PID)) { continue; } List <TSStreamDiagnostics> diagList = clip.StreamFile.StreamDiagnostics[PID]; for (int i = 0; i < diagList.Count; i++) { TSStreamDiagnostics diag = diagList[i]; //if (diag.Tag == null) continue; pointPosition = diag.Marker - clip.TimeIn + clip.RelativeTimeIn; double seconds = diag.Interval; double bits = diag.Bytes * 8.0; windowSecondsSum += seconds; windowSeconds.Enqueue(seconds); windowBitsSum += bits; windowBits.Enqueue(bits); if (windowSecondsSum > windowSize) { double bitrate = windowBitsSum / windowSecondsSum / 1000000; if (bitrate < pointMin) { pointMin = bitrate; } if (bitrate > pointMax) { pointMax = bitrate; } pointCount++; pointAvg += bitrate; for (double x = pointSeconds; x < (pointPosition - 1); x++) { double pointX = (x - 1) / 60; pointsMin.Add(pointX, 0); pointsAvg.Add(pointX, 0); pointsMax.Add(pointX, 0); pointSeconds += 1; } if (pointPosition >= pointSeconds) { double pointMinutes = (pointSeconds - 1) / 60; pointsMin.Add(pointMinutes, pointMin); pointsMax.Add(pointMinutes, pointMax); pointsAvg.Add(pointMinutes, pointAvg / pointCount); pointMin = double.MaxValue; pointMax = 0; pointAvg = 0; pointCount = 0; pointSeconds += 1; } windowBitsSum -= windowBits.Dequeue(); windowSecondsSum -= windowSeconds.Dequeue(); } if (pointPosition >= pointSeconds) { for (double x = pointSeconds; x < (pointPosition - 1); x++) { double pointX = (x - 1) / 60; pointsMin.Add(pointX, 0); pointsAvg.Add(pointX, 0); pointsMax.Add(pointX, 0); pointSeconds += 1; } double pointMinutes = (pointSeconds - 1) / 60; pointsMin.Add(pointMinutes, pointMin); pointsAvg.Add(pointMinutes, pointAvg / pointCount); pointsMax.Add(pointMinutes, pointMax); pointMin = double.MaxValue; pointMax = 0; pointAvg = 0; pointCount = 0; pointSeconds += 1; } } } for (double x = pointSeconds; x < playlist.TotalLength; x++) { double pointX = (x - 1) / 60; pointsMin.Add(pointX, 0); pointsAvg.Add(pointX, 0); pointsMax.Add(pointX, 0); } LineItem avgCurve = GraphControl.GraphPane.AddCurve( "Avg", pointsAvg, Color.Gray, SymbolType.None); avgCurve.Line.IsSmooth = true; LineItem minCurve = GraphControl.GraphPane.AddCurve( "Min", pointsMin, Color.LightGray, SymbolType.None); minCurve.Line.IsSmooth = true; minCurve.Line.Fill = new Fill(Color.White); LineItem maxCurve = GraphControl.GraphPane.AddCurve( "Max", pointsMax, Color.LightGray, SymbolType.None); maxCurve.Line.IsSmooth = true; maxCurve.Line.Fill = new Fill(Color.LightGray); GraphControl.GraphPane.XAxis.Scale.Min = 0; GraphControl.GraphPane.XAxis.Scale.Max = playlist.TotalLength / 60; GraphControl.GraphPane.YAxis.Scale.Min = 0; GraphControl.GraphPane.Y2Axis.Scale.Min = 0; GraphControl.GraphPane.Y2Axis.IsVisible = true; GraphControl.AxisChange(); }
/// <summary> /// Plot solution /// </summary> /// <param name="sender">sender object</param> /// <param name="e">Event arguments</param> private void PlotButton_Click(object sender, EventArgs e) { pane.CurveList.Clear(); // Prey population equation Func <double, double, double> preyPop = (x, y) => x * ((double)PreyBirthRate.Value - (double)PreyDeathRate.Value * y); // Predator population equation Func <double, double, double> predatorPop = (x, y) => y * ((double)PredatorBirthRate.Value * x - (double)PredatorDeathRate.Value); // Solution for predator and prey double[,] preyAndPredatorCurves; try { // checking what algorith to use if (RKF45.Checked) { preyAndPredatorCurves = RungeKutta.Rkf45(preyPop, predatorPop, (double)PreyPopulation.Value, (double)PredatorPopulation.Value, (int)TimeSpan.Value, 0.01); } else { preyAndPredatorCurves = RungeKutta.Rk4(preyPop, predatorPop, (double)PreyPopulation.Value, (double)PredatorPopulation.Value, (int)TimeSpan.Value, (double)StepSize.Value); } PointPairList preySolution = new PointPairList(); for (int i = 0; i <= preyAndPredatorCurves.GetUpperBound(1); i++) { preySolution.Add(preyAndPredatorCurves[2, i], preyAndPredatorCurves[0, i]); } PointPairList predatorSolution = new PointPairList(); for (int i = 0; i <= preyAndPredatorCurves.GetUpperBound(1); i++) { predatorSolution.Add(preyAndPredatorCurves[2, i], preyAndPredatorCurves[1, i]); } // Adding prey population curve LineItem preyCurve = pane.AddCurve("Prey population", preySolution, Color.Green, SymbolType.None); preyCurve.Line.Width = 2; preyCurve.Line.IsSmooth = true; // Adding predator population curve LineItem predatorCurve = pane.AddCurve("Predator population", predatorSolution, Color.Red, SymbolType.None); predatorCurve.Line.Width = 2; predatorCurve.Line.IsSmooth = true; } catch (ArgumentException ex) { MessageBox.Show(ex.Message + "\nPlease enter smaller parameters", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } // Changing axis to fit the curves GraphControl.AxisChange(); GraphControl.Invalidate(); }
public void Redraw() { if (GraphControl == null) { return; } GraphControl.GraphPane.CurveList.Clear(); GraphPane pane = GraphControl.GraphPane; pane.YAxisList.Clear(); if (Graphs.Count == 0) { pane.XAxis.Title.Text = ""; return; } var yAxises = new Dictionary <string, int>(); for (int k = 0; k < Graphs.Count; k++) { Graph graph = Graphs[k]; LineItem line = k < GraphSettings.CurveLines.Count ? graph.GetLineItem(GraphSettings.CurveLines[k].LineColor, SymbolType.None, 2.0f) : graph.GetLineItem(); if (GraphSettings.Smooth) { var curList = (IPointList)line.Points.Clone(); var average = new MovingAverage(GraphSettings.SmoothPeriod); switch (GraphSettings.SmoothType) { case SmoothModel.Average: for (int i = 0; i < curList.Count; i++) { average.Push(curList[i].Y); curList[i].Y = average.Average; } break; case SmoothModel.Median: for (int i = 0; i < curList.Count; i++) { average.Push(curList[i].Y); curList[i].Y = average.Median; } break; default: break; } line.Points = curList; } var yAxisLabel = graph.YAxis + (string.IsNullOrEmpty(graph.Y_Unit) ? "" : (", " + graph.Y_Unit)); if (!yAxises.ContainsKey(yAxisLabel)) { yAxises.Add(yAxisLabel, pane.AddYAxis(yAxisLabel)); } line.YAxisIndex = yAxises[yAxisLabel]; pane.CurveList.Add(line); } pane.XAxis.Title.Text = Graphs.Last().XAxis + (string.IsNullOrEmpty(Graphs.Last().X_Unit) ? "" : (", " + Graphs.Last().X_Unit)); pane.Title.Text = ""; GraphControl.AxisChange(); LegendRedraw(GraphSettings.LegendVisible); AxisTitleRedraw(GraphSettings.AxisLabelVisible); #region AxisGrids pane.XAxis.MajorGrid.IsVisible = GraphSettings.MajorGrid; pane.YAxis.MajorGrid.IsVisible = GraphSettings.MajorGrid; pane.XAxis.MinorGrid.IsVisible = GraphSettings.MinorGrid; pane.YAxis.MinorGrid.IsVisible = GraphSettings.MinorGrid; pane.YAxis.MajorGrid.DashOn = 10; pane.YAxis.MajorGrid.DashOff = 5; pane.XAxis.MajorGrid.DashOn = 10; pane.XAxis.MajorGrid.DashOff = 5; pane.YAxis.MajorGrid.DashOn = 10; pane.YAxis.MajorGrid.DashOff = 5; pane.XAxis.MinorGrid.DashOn = 1; pane.XAxis.MinorGrid.DashOff = 2; pane.YAxis.MinorGrid.DashOn = 1; pane.YAxis.MinorGrid.DashOff = 2; #endregion DashOnOff GraphControl.Invalidate(); GraphControl.Refresh(); }
private void Redraw() { if (GraphControl == null) { return; } GraphControl.GraphPane.CurveList.Clear(); GraphPane pane = GraphControl.GraphPane; pane.YAxisList.Clear(); pane.Title.Text = ""; //var graphs = m_Graphs.SelectMany(g => g.Value).ToList(); if (m_Graphs.SelectMany(g => g.Value).Count() == 0) { pane.XAxis.Title.Text = ""; return; } var yAxises = new Dictionary <string, int>(); int color = 0; foreach (var keyValue in m_Graphs) { var lineColor = GraphSettings.CurveLines[color++].LineColor; for (int i = 0; i < keyValue.Value.Count(); i++) { Graph graph = keyValue.Value[i]; var line = graph.GetLineItem(); if (GraphSettings.Smooth) { var curList = (IPointList)line.Points.Clone(); var average = new MovingAverage(GraphSettings.SmoothPeriod); switch (GraphSettings.SmoothType) { case SmoothModel.Average: for (int j = 0; j < curList.Count; j++) { average.Push(curList[j].Y); curList[j].Y = average.Average; } break; case SmoothModel.Median: for (int j = 0; j < curList.Count; j++) { average.Push(curList[i].Y); curList[j].Y = average.Median; } break; default: break; } line.Points = curList; } var yAxisLabel = graph.YAxis + (string.IsNullOrEmpty(graph.Y_Unit) ? "" : (", " + graph.Y_Unit)); if (!yAxises.ContainsKey(yAxisLabel)) { yAxises.Add(yAxisLabel, pane.AddYAxis(yAxisLabel)); } line.YAxisIndex = yAxises[yAxisLabel]; line.Line.Style = (System.Drawing.Drawing2D.DashStyle)i; line.Line.Color = lineColor; pane.CurveList.Add(line); } } pane.XAxis.Title.Text = m_Graphs.First().Value.First().XAxis + (string.IsNullOrEmpty(m_Graphs.First().Value.First().X_Unit) ? "" : (", " + m_Graphs.First().Value.First().X_Unit)); pane.Title.Text = ""; GraphControl.AxisChange(); LegendRedraw(GraphSettings.LegendVisible); AxisTitleRedraw(GraphSettings.AxisLabelVisible); #region AxisGrids pane.XAxis.MajorGrid.IsVisible = GraphSettings.MajorGrid; pane.YAxis.MajorGrid.IsVisible = GraphSettings.MajorGrid; pane.XAxis.MinorGrid.IsVisible = GraphSettings.MinorGrid; pane.YAxis.MinorGrid.IsVisible = GraphSettings.MinorGrid; pane.YAxis.MajorGrid.DashOn = 10; pane.YAxis.MajorGrid.DashOff = 5; pane.XAxis.MajorGrid.DashOn = 10; pane.XAxis.MajorGrid.DashOff = 5; pane.YAxis.MajorGrid.DashOn = 10; pane.YAxis.MajorGrid.DashOff = 5; pane.XAxis.MinorGrid.DashOn = 1; pane.XAxis.MinorGrid.DashOff = 2; pane.YAxis.MinorGrid.DashOn = 1; pane.YAxis.MinorGrid.DashOff = 2; #endregion DashOnOff GraphControl.Invalidate(); GraphControl.Refresh(); }
private void confirmButton_Click(object sender, EventArgs e) { PointPairList list1 = new PointPairList(); list1 = circleCalculate(0, 0, double.Parse(dgvDiameter[3, 0].Value.ToString().Trim()) * 0.5); LineItem myCurve = GraphControl.GraphPane.AddCurve("第一级输入齿轮", list1, Color.Blue, SymbolType.None); myCurve.Line.Width = 2.0F; //设置线宽 //Make the curve smooth myCurve.Line.IsSmooth = true; list1 = circleCalculate(double.Parse(dataGridView[2, 0].Value.ToString().Trim()), 0, double.Parse(dgvDiameter[4, 0].Value.ToString().Trim()) * 0.5); myCurve = GraphControl.GraphPane.AddCurve("第一级输出齿轮", list1, Color.Gold, SymbolType.None); myCurve.Line.Width = 2.0F; //设置线宽 list1 = circleCalculate(double.Parse(dataGridView[2, 0].Value.ToString().Trim()), 0, double.Parse(dgvDiameter[3, 1].Value.ToString().Trim()) * 0.5); myCurve = GraphControl.GraphPane.AddCurve("第二级输入齿轮", list1, Color.Red, SymbolType.None); myCurve.Line.Width = 2.0F; //设置线宽 list1 = circleCalculate(double.Parse(dataGridView[2, 0].Value.ToString().Trim()) + double.Parse(dataGridView[2, 1].Value.ToString().Trim()), 0, double.Parse(dgvDiameter[4, 1].Value.ToString().Trim()) * 0.5); myCurve = GraphControl.GraphPane.AddCurve("第二级输出齿轮", list1, Color.Green, SymbolType.None); myCurve.Line.Width = 2.0F; //设置线宽 list1 = circleCalculate(double.Parse(dataGridView[2, 0].Value.ToString().Trim()) + double.Parse(dataGridView[2, 1].Value.ToString().Trim()), 0, double.Parse(dgvDiameter[3, 2].Value.ToString().Trim()) * 0.5); myCurve = GraphControl.GraphPane.AddCurve("第三级输入齿轮", list1, Color.Pink, SymbolType.None); myCurve.Line.Width = 2.0F; //设置线宽 list1 = circleCalculate(double.Parse(dataGridView[2, 0].Value.ToString().Trim()) + double.Parse(dataGridView[2, 1].Value.ToString().Trim()) + double.Parse(dataGridView[2, 2].Value.ToString().Trim()), 0, double.Parse(dgvDiameter[4, 2].Value.ToString().Trim()) * 0.5); myCurve = GraphControl.GraphPane.AddCurve("第三级输出齿轮", list1, Color.Purple, SymbolType.None); myCurve.Line.Width = 2.0F; //设置线宽 GraphControl.AxisChange(); graphPane_AxisChangeEvent(GraphControl.GraphPane); GraphControl.Show(); /*//齿轮参数定义 * /*int transSeries = int.Parse(transmissionSeriesTextBox.Text);//传动级数赋值 * double[] transRatio = new double[transSeries];//传动比数组定义 * double[] Mn = new double[transSeries];//模数数组定义 * double[] a = new double[transSeries];//中心距数组定义 * double[] a0 = new double[transSeries];//变位中心距数组定义 * double[] Z1 = new double[transSeries];//小齿轮齿数数组定义 * double[] Z2 = new double[transSeries];//大齿轮齿数组定义 * double[] B1 = new double[transSeries];//螺旋角数组定义 * double[] b = new double[transSeries];//齿宽数组定义 * double[] An = new double[transSeries];//压力角数组定义 * double[] at = new double[transSeries];//端面压力角数组定义 * double[] atp = new double[transSeries];//啮合角的cos值数组定义 * double[] atpie = new double[transSeries];//反余弦啮合角数组定义 * double[] invat = new double[transSeries];//端面压力角渐开线函数值数组定义 * double[] invatpie = new double[transSeries];//啮合角渐开线函数值数组定义 * double[] Xn = new double[transSeries];//总变位系数数组定义 * double[] Yn = new double[transSeries];//中心距变动系数数组定义 * double[] dy = new double[transSeries];//齿顶高变动系数数组定义 * double[] x1 = new double[transSeries];//小齿轮变位系数数组定义 * double[] x2 = new double[transSeries]; //大齿轮变位系数数组定义 * double[] hax1 = new double[transSeries];//小齿顶圆变位系数数组定义 * double[] hax2 = new double[transSeries]; //大齿顶圆变位系数数组定义 * double[] ha1 = new double[transSeries];//小齿齿顶高数组定义 * double[] ha2 = new double[transSeries]; //大齿齿顶高数组定义 * double[] da1 = new double[transSeries];//小齿顶圆直径数组定义 * double[] da2 = new double[transSeries]; //大齿顶圆直径数组定义 * double[] d1 = new double[transSeries];//小齿分度圆直径数组定义 * double[] d2 = new double[transSeries]; //大齿分度圆直径数组定义 */ /*double pianYi = 0;//X轴绘图时每次的平移量 * double pianyiYfu = 10;//负Y轴标线多出的部分 * double pianyiYzheng = 80;//正Y轴标线多出的部分 * //绘图 * * //////////////////////////////////////////// * //WGeoClass newGeoClass = new WGeoClass(); * double[] CalResult = new double[52]; * CalResult = WGeoCal(zx, mn2, lb12, zd, hax1, had1, xnx, xnd, cnx, cnd, an2, dpqx, dpqd, bx); * * * //MessageBox.Show(x1[i].ToString()); * // MessageBox.Show(dy[i].ToString());//这个数不一样?????? * // MessageBox.Show(ha1[i].ToString()); * // MessageBox.Show(ha2[i].ToString()); * // MessageBox.Show(da1[i].ToString());//为什么会有误差呢? * * * * //da1[0] = 63.6934368; * //da2[0] = 187.9892985; * // da1[1] = 88.5131932; * // da2[1] = 226.8275775; * // da1[2] = 105.8859505; * // da2[2] = 313.7395377; * double r; * double theta; * double[] x = new double[1001]; * double[] xx = new double[1001]; * double[] y = new double[1001]; * // double[] xx = new double[1001]; * //a[0] = 120; * // a[1] = 150; * // a[2] = 200; * * double aAll = 0; * double xGanshe1 = 0; * double xGanshe2 = 0; * String title = ""; * * for (int i = transSeries - 1; i >= 0; i--) * { * r = 0.5 * da2[i]; * * for (int j = 0; j <= 1000; j++) * { * theta = 2 * Math.PI / 1000 * j; * x[j] = pianYi + r * Math.Cos(theta); * y[j] = r * Math.Sin(theta); * // xx[i] = x[i] + 10; * } * /// * * DrawPic.MyDrawPic1(this.GraphControl, x, y, title, "", ""); * * // pianyiy = pianyiy + 0.5 * da2[transSeries - 1 - i] + 30; * for (int j = 0; j <= 1000; j++) * { * x[j] = pianYi; * y[j] = -0.5 * da2[i] - pianyiYfu + (0.5 * da2[transSeries - 1] + pianyiYzheng + 0.5 * da2[i]) / 1000 * j; * // xx[i] = x[i] + 10; * } * DrawPic.MyDrawPic1(this.GraphControl, x, y, title, "", ""); * * pianYi = pianYi + a[i]; * * r = 0.5 * da1[i]; * for (int j = 0; j <= 1000; j++) * { * theta = 2 * Math.PI / 1000 * j; * x[j] = pianYi + r * Math.Cos(theta); * y[j] = r * Math.Sin(theta); * // xx[i] = x[i] + 10; * * } * * * * DrawPic.MyDrawPic1(this.GraphControl, x, y, title, "", ""); * * * } * * for (int j = 0; j <= 1000; j++) * { * * x[j] = pianYi; * y[j] = -0.5 * da1[0] - pianyiYfu + (0.5 * da1[0] + 0.5 * da2[transSeries - 1] + pianyiYzheng) / 1000 * j; * // xx[i] = x[i] + 10; * * } * DrawPic.MyDrawPic1(this.GraphControl, x, y, title, "", ""); * * * * // 干涉检查线绘制 * for (int i = transSeries - 1; i >= 2; i--) * { * aAll = aAll + a[i]; * * xGanshe1 = aAll + 0.5 * da1[i]; * * xGanshe2 = aAll + a[i - 1] - 0.5 * da2[i - 2]; * MessageBox.Show((xGanshe2 - xGanshe1).ToString()); * * for (int j = 0; j <= 1000; j++) * { * x[j] = xGanshe1; * y[j] = (0.5 * da2[transSeries - 1] + pianyiYzheng - 40) / 1000 * j; * xx[j] = xGanshe2; * } * * * DrawPic.MyDrawPic1(this.GraphControl, x, y, title, "", ""); * DrawPic.MyDrawPic1(this.GraphControl, xx, y, title, "", ""); * * // DrawPic.MyPointValueHandler(this.GraphControl,"" ,"", 2); * * //齿轮距离值输出???? * //Font fnt = new Font("Verdana", 16); * // Graphics g = new Graphics(); * // g.DrawString(((xGanshe2 - xGanshe1).ToString()), fnt, new SolidBrush(Color.Red), x[j], y[j]); * * * } * * * * * //X轴水平线绘制 * * aAll = 0; * for (int i = transSeries - 1; i >= 0; i--) * { * aAll = aAll + a[i]; * } * * for (int j = 0; j <= 1000; j++) * { * * x[j] = -0.5 * da2[transSeries - 1] - 10 + (20 + aAll + 0.5 * da2[transSeries - 1] + 0.5 * da1[0]) / 1000 * j;//这个地方要改 * y[j] = 0; * } * * DrawPic.MyDrawPic1(this.GraphControl, x, y, title, "", ""); */ }
private void SParamListBox_SelectedIndexChanged(object sender, EventArgs e) { try { AllCurvesToggleVisible(false); } catch (NullReferenceException) { if (DrawButton.Enabled) { DrawButton.PerformClick(); } else { MessageBox.Show( "Необходимо ввести все значения и затем нажать кнопку draw", "Предупреждение", MessageBoxButtons.OK, MessageBoxIcon.Information, MessageBoxDefaultButton.Button1, MessageBoxOptions.DefaultDesktopOnly); this.Activate(); } } for (int i = 0; i < SParamListBox.Items.Count; i++) { if (SParamListBox.CheckedIndices.Contains(i)) { switch (i) { case 0: _11Curve.IsVisible = true; _11Curve.Label.IsVisible = true; break; case 1: _12Curve.IsVisible = true; _12Curve.Label.IsVisible = true; break; case 2: _13Curve.IsVisible = true; _13Curve.Label.IsVisible = true; break; case 3: _14Curve.IsVisible = true; _14Curve.Label.IsVisible = true; break; case 4: _22Curve.IsVisible = true; _22CurveMarker.IsVisible = true; _22CurveLabel.Label.IsVisible = true; break; case 5: _23Curve.IsVisible = true; _23CurveMarker.IsVisible = true; _23CurveLabel.Label.IsVisible = true; break; case 6: _24Curve.IsVisible = true; _24CurveMarker.IsVisible = true; _24CurveLabel.Label.IsVisible = true; break; case 7: _33Curve.IsVisible = true; _33CurveMarker.IsVisible = true; _33CurveLabel.Label.IsVisible = true; break; case 8: _34Curve.IsVisible = true; _34CurveMarker.IsVisible = true; _34CurveLabel.Label.IsVisible = true; break; case 9: _44Curve.IsVisible = true; _44CurveMarker.IsVisible = true; _44CurveLabel.Label.IsVisible = true; break; } } } GraphControl.AxisChange(); GraphControl.Invalidate(); }
/// <summary> /// /// </summary> /// <param name="sOrF"></param> /// <param name="sParamMagnitudeOrPhase"> /// фазы или магнитуды 11 = 0, 12 = 1, 13 = 2, 14 = 3, 22 = 4, 23 = 5, 24 = 6, 33 = 7, 34 = 8, 44 = 9. /// </param> private void DrawCurves(string sOrF, double[][] sParamMagnitudeOrPhase) { var fakeX = new double[] { 1 }; var fakeY = new double[] { 1 }; var count = _fi.Count(); double fiMarkerCount = 1; if (_fi.Count() >= 20) { count = _fi.Count() - _fi.Count() % 20; fiMarkerCount = count / 20; } int fiM = int.Parse(Math.Floor(count / fiMarkerCount).ToString()); var marker22data = new double[fiM]; var marker23data = new double[fiM]; var marker24data = new double[fiM]; var marker33data = new double[fiM]; var marker34data = new double[fiM]; var marker44data = new double[fiM]; var markerfidata = new double[fiM]; var k = 0; for (int i = 0; i < count; i++) { if (i % fiMarkerCount == 0) { markerfidata[k] = _fi[i]; marker22data[k] = sParamMagnitudeOrPhase[4][i]; marker23data[k] = sParamMagnitudeOrPhase[5][i]; marker24data[k] = sParamMagnitudeOrPhase[6][i]; marker33data[k] = sParamMagnitudeOrPhase[7][i]; marker34data[k] = sParamMagnitudeOrPhase[8][i]; marker44data[k] = sParamMagnitudeOrPhase[9][i]; k++; } } _11Curve = _graphPane.AddCurve(sOrF + "11", _fi, sParamMagnitudeOrPhase[0], Color.Red, SymbolType.None); _11Curve.Line.Style = DashStyle.Dot; _11Curve.Line.IsSmooth = true; SetLineWidth(_11Curve); _12Curve = _graphPane.AddCurve(sOrF + "12", _fi, sParamMagnitudeOrPhase[1], Color.Blue, SymbolType.None); _12Curve.Line.Style = DashStyle.Dash; _12Curve.Line.IsSmooth = true; SetLineWidth(_12Curve); _13Curve = _graphPane.AddCurve(sOrF + "13", _fi, sParamMagnitudeOrPhase[2], Color.Red, SymbolType.None); SetLineWidth(_13Curve); _14Curve = _graphPane.AddCurve(sOrF + "14", _fi, sParamMagnitudeOrPhase[3], Color.Black, SymbolType.None); _14Curve.Line.Style = DashStyle.DashDot; _14Curve.Line.IsSmooth = true; SetLineWidth(_14Curve); _22Curve = _graphPane.AddCurve(sOrF + "22", _fi, sParamMagnitudeOrPhase[4], Color.Black, SymbolType.None); _22Curve.Line.Style = DashStyle.Dot; _22Curve.Line.IsSmooth = true; SetLineWidth(_22Curve); _22CurveLabel = _graphPane.AddCurve(sOrF + "22", fakeX, fakeY, Color.Black, SymbolType.XCross); _22CurveLabel.Line.Style = DashStyle.Dot; _22CurveLabel.Line.IsSmooth = true; SetLineWidth(_22CurveLabel); _22CurveLabel.IsVisible = false; _23Curve = _graphPane.AddCurve(sOrF + "23", _fi, sParamMagnitudeOrPhase[5], Color.Green, SymbolType.None); _23Curve.Line.Style = DashStyle.DashDot; _23Curve.Line.IsSmooth = true; SetLineWidth(_23Curve); _23CurveLabel = _graphPane.AddCurve(sOrF + "23", fakeX, fakeY, Color.Green, SymbolType.Triangle); SetLineWidth(_23CurveLabel); _23CurveLabel.IsVisible = false; _24Curve = _graphPane.AddCurve(sOrF + "24", _fi, sParamMagnitudeOrPhase[6], Color.Black, SymbolType.None); SetLineWidth(_24Curve); _24CurveLabel = _graphPane.AddCurve(sOrF + "24", fakeX, fakeY, Color.Black, SymbolType.Circle); SetLineWidth(_24CurveLabel); _24CurveLabel.IsVisible = false; _33Curve = _graphPane.AddCurve(sOrF + "33", _fi, sParamMagnitudeOrPhase[7], Color.Blue, SymbolType.None); _33Curve.Line.Style = DashStyle.Dot; _33Curve.Line.IsSmooth = true; SetLineWidth(_33Curve); _33CurveLabel = _graphPane.AddCurve(sOrF + "33", fakeX, fakeY, Color.Blue, SymbolType.Star); _33CurveLabel.Line.Style = DashStyle.Dot; _33CurveLabel.Line.IsSmooth = true; SetLineWidth(_33CurveLabel); _33CurveLabel.IsVisible = false; _34Curve = _graphPane.AddCurve(sOrF + "34", _fi, sParamMagnitudeOrPhase[8], Color.Green, SymbolType.None); _34Curve.Line.Style = DashStyle.Dash; _34Curve.Line.IsSmooth = true; SetLineWidth(_34Curve); _34CurveLabel = _graphPane.AddCurve(sOrF + "34", fakeX, fakeY, Color.Green, SymbolType.Square); _34CurveLabel.Line.Style = DashStyle.Dash; _34CurveLabel.Line.IsSmooth = true; SetLineWidth(_34CurveLabel); _34CurveLabel.IsVisible = false; _44Curve = _graphPane.AddCurve(sOrF + "44", _fi, sParamMagnitudeOrPhase[9], Color.Green, SymbolType.None); _44Curve.Line.Style = DashStyle.Dot; _44Curve.Line.IsSmooth = true; SetLineWidth(_44Curve); _44CurveLabel = _graphPane.AddCurve(sOrF + "44", fakeX, fakeY, Color.Green, SymbolType.Plus); _44CurveLabel.Line.Style = DashStyle.Dot; _44CurveLabel.Line.IsSmooth = true; SetLineWidth(_44CurveLabel); _44CurveLabel.IsVisible = false; _22CurveMarker = _graphPane.AddCurve(sOrF + "m22", markerfidata, marker22data, Color.Black, SymbolType.XCross); _22CurveMarker.Line.IsVisible = false; _22CurveMarker.Label.IsVisible = false; _23CurveMarker = _graphPane.AddCurve(sOrF + "m23", markerfidata, marker23data, Color.Green, SymbolType.Triangle); _23Curve.Symbol.Size = 2.0f; _23CurveMarker.Line.IsVisible = false; _23CurveMarker.Label.IsVisible = false; _24CurveMarker = _graphPane.AddCurve(sOrF + "m24", markerfidata, marker24data, Color.Black, SymbolType.Circle); _24CurveMarker.Line.IsVisible = false; _24CurveMarker.Label.IsVisible = false; _33CurveMarker = _graphPane.AddCurve(sOrF + "m33", markerfidata, marker33data, Color.Blue, SymbolType.Star); _33CurveMarker.Line.IsVisible = false; _33CurveMarker.Label.IsVisible = false; _34CurveMarker = _graphPane.AddCurve(sOrF + "m34", markerfidata, marker34data, Color.Green, SymbolType.Square); _34CurveMarker.Line.IsVisible = false; _34CurveMarker.Label.IsVisible = false; _44CurveMarker = _graphPane.AddCurve(sOrF + "m44", markerfidata, marker44data, Color.Green, SymbolType.Plus); _44CurveMarker.Line.IsVisible = false; _44CurveMarker.Label.IsVisible = false; SParamListBox_SelectedIndexChanged(new object(), new EventArgs()); GraphControl.AxisChange(); GraphControl.Invalidate(); }