private void OnColorChanged(object sender, EventArgs eventArgs) { ParameterDisplaySettingsViewModel cbvm = sender as ParameterDisplaySettingsViewModel; if (cbvm == null) { throw new ArgumentException("Wrong sender!"); } PsaParameterDataViewModel vm = cbvm.ParamData as PsaParameterDataViewModel; if (graph.IsDisplayed(vm)) { LineSeries2D series = graph.FindSeries(vm) as LineSeries2D; vm.Color = new SolidColorBrush(cbvm.StrokeColor); series.Brush = new SolidColorBrush(cbvm.StrokeColor); SecondaryAxisY2D secAxs = XYDiagram2D.GetSeriesAxisY(series); if (secAxs != null) { XYDiagram2D.GetSeriesAxisY(series).Brush = new SolidColorBrush(cbvm.StrokeColor); } } UpdateScalesSetView(); UpdateScalesComboboxesView(); }
public void AddGraph(IPsaParameterDataViewModel vm, Color strokeColor) { current.Add(vm, strokeColor); LineSeries2D series = new LineSeries2D(); series.DataContext = vm; series.Brush = new SolidColorBrush(strokeColor); series.ValueScaleType = ScaleType.Numerical; series.ArgumentScaleType = ScaleType.Numerical; series.MarkerVisible = false; series.ShowInLegend = false; series.Label = new SeriesLabel(); series.LabelsVisibility = false; for (int i = 0; i < vm.Values.Count; i++) { SeriesPoint pt; if (!vm.HasTimestamps) { pt = new SeriesPoint(i, vm.Values[i]); } else { pt = new SeriesPoint(vm.Model.Timestamps[i], vm.Values[i]); } series.Points.Add(pt); } if (graphDiagram.Series.Count > 0) { AxisY2D compatibleAxis = FindCompatibleAxis(graphDiagram, series); if (compatibleAxis == null) { SecondaryAxisY2D newAxis = GenerateNewAxis(series); newAxis.Brush = new SolidColorBrush(strokeColor); graphDiagram.SecondaryAxesY.Add(newAxis); XYDiagram2D.SetSeriesAxisY(series, newAxis); } else { if (compatibleAxis is SecondaryAxisY2D) { UpdateAxisByNewSeries( (SecondaryAxisY2D)compatibleAxis, series); XYDiagram2D.SetSeriesAxisY(series, (SecondaryAxisY2D)compatibleAxis); } } } graphDiagram.Series.Add(series); }
private void UpdateAxisRangeToNewSeries(SecondaryAxisY2D axis, LineSeries2D series) { double seriesMax = GetSeriesMaxValue(series); double seriesMin = GetSeriesMinValue(series); double max = Math.Max((double)axis.ActualRange.ActualMaxValue, seriesMax); double min = Math.Min((double)axis.ActualRange.ActualMinValue, seriesMin); axis.ActualRange.MinValue = min - Math.Abs(graphOverhead * min); axis.ActualRange.MaxValue = max + Math.Abs(graphOverhead * max); if (axis.Range != null) { axis.Range.MinValue = min - Math.Abs(graphOverhead * min); axis.Range.MaxValue = max + Math.Abs(graphOverhead * max); } }
public void RemoveGraph(IPsaParameterDataViewModel vm) { current.Remove(vm); Series toDelete = null; foreach (Series s in graphDiagram.Series) { IPsaParameterDataViewModel param = s.DataContext as IPsaParameterDataViewModel; if (param != null) { if (param.Type == vm.Type) { toDelete = s; break; } } } // determine axes to delete AxisY2D axsToDelete = XYDiagram2D. GetSeriesAxisY((XYSeries)toDelete); bool axsUsedSomewhereElse = false; foreach (XYSeries s in graphDiagram.Series) { if (s != null && s == toDelete) { continue; } AxisY2D axs = XYDiagram2D.GetSeriesAxisY(s); if (axs != null && axs == axsToDelete) { axsUsedSomewhereElse = true; } } graphDiagram.Series.Remove(toDelete); SecondaryAxisY2D axsToDeleteCast = axsToDelete as SecondaryAxisY2D; if (!axsUsedSomewhereElse && axsToDeleteCast != null) { graphDiagram.SecondaryAxesY. Remove(axsToDeleteCast); } }
protected SecondaryAxisY2D GenerateNewAxis(LineSeries2D series) { double seriesMin = GetSeriesMinValue(series); double seriesMax = GetSeriesMaxValue(series); SecondaryAxisY2D result = new SecondaryAxisY2D(); result.ActualRange.MinValue = seriesMin - Math.Abs(graphOverhead * seriesMin); result.ActualRange.MaxValue = seriesMax + Math.Abs(graphOverhead * seriesMax); result.Range = new AxisRange(); result.Range.MinValue = seriesMin - Math.Abs(graphOverhead * seriesMin); result.Range.MaxValue = seriesMax + Math.Abs(graphOverhead * seriesMax); return(result); }
private void RemoveGraph(PsaParameterDataViewModel vm) { Series toDelete = null; foreach (Series s in graph.SeriesCollection) { PsaParameterDataViewModel param = s.DataContext as PsaParameterDataViewModel; if (param != null) { if (param == vm) // the same object { toDelete = s; break; } } } // determine axes to delete AxisY2D axsToDelete = XYDiagram2D.GetSeriesAxisY((XYSeries)toDelete); bool axsUsedSomewhereElse = false; foreach (XYSeries s in graph.SeriesCollection) { if (s != null && s == toDelete) { continue; } AxisY2D axs = XYDiagram2D.GetSeriesAxisY(s); if (axs != null && axs == axsToDelete) { axsUsedSomewhereElse = true; } } graph.RemoveSeries(toDelete); SecondaryAxisY2D axsToDeleteCast = axsToDelete as SecondaryAxisY2D; if (!axsUsedSomewhereElse && axsToDeleteCast != null) { graph.graphDiagram.SecondaryAxesY.Remove(axsToDeleteCast); } }
private void ProcessAutoscale(LineSeries2D series, Color color) { AxisY2D compatibleAxis = FindCompatibleAxis(graph.graphDiagram, series); if (compatibleAxis == null) // no compatible axis { SecondaryAxisY2D newAxis = GenerateNewAxis(series); newAxis.Brush = new SolidColorBrush(color); graph.graphDiagram.SecondaryAxesY.Add(newAxis); XYDiagram2D.SetSeriesAxisY(series, newAxis); } else // there is a compatible axis { SecondaryAxisY2D axs = compatibleAxis as SecondaryAxisY2D; if (axs != null) { UpdateAxisRangeToNewSeries(axs, series); XYDiagram2D.SetSeriesAxisY(series, (SecondaryAxisY2D)compatibleAxis); } } UpdateScalesSetView(); UpdateScalesComboboxesView(); }