void WellView_DataContextChanged(object sender, DependencyPropertyChangedEventArgs e) { if (e.NewValue is WellViewModel) { SelectedPoint.Collection.Clear(); foreach (var g in _obsGraphs) { ObsGraph.Children.Remove(g); } _obsGraphs.Clear(); foreach (var g in _extGraphs) { PumpingGraph.Children.Remove(g); } _extGraphs.Clear(); WellViewModel wm = (WellViewModel)e.NewValue; int Pencount = 0; foreach (var ts in wm.HeadObservations) { ts.Value.SetXMapping(var => dateAxis.ConvertToDouble(var.Time)); ts.Value.SetYMapping(var => var.Value); var g = ObsGraph.AddLineGraph(ts.Value, pens[Pencount], new PenDescription(ts.Key.ToString())); _obsGraphs.Add(g); Pencount++; if (Pencount == pens.Count()) { Pencount = 0; } } Pencount = 0; foreach (var ts in wm.Extractions.Where(var => var.Item2.Count() > 0)) { EnumerableDataSource <Time.Core.TimestampValue> ds = new EnumerableDataSource <TimestampValue>(ts.Item2); ds.SetXMapping(var => dateAxisExt.ConvertToDouble(var.Time)); ds.SetYMapping(var => var.Value); var g = PumpingGraph.AddLineGraph(ds, pens[Pencount], new PenDescription(ts.Item1)); _extGraphs.Add(g); Pencount++; if (Pencount == pens.Count()) { Pencount = 0; } } } ZoomToTimeScale(); }
public void ZoomToTimeScale() { if (SelectionEndTime != DateTime.MinValue) { WellViewModel wm = DataContext as WellViewModel; DataRect visible; double xmin = dateAxis.ConvertToDouble(SelectionStartTime); double xlength = dateAxis.ConvertToDouble(SelectionEndTime) - dateAxis.ConvertToDouble(SelectionStartTime); ObsGraph.FitToView(); visible = new DataRect(xmin, ObsGraph.Visible.Y, xlength, ObsGraph.Visible.Height); //Zoom the observation graph if (wm != null && wm.HeadObservations.Count != 0) { var select = wm.HeadObservations.SelectMany(var => var.Value.Collection.Where(var2 => var2.Time >= SelectionStartTime & var2.Time <= SelectionEndTime)); if (select != null && select.Count() != 0) { double ymin = select.Min(y => y.Value); double yheight = select.Max(y => y.Value) - ymin; ymin = ymin - 0.05 * yheight; yheight *= 1.1; visible = new DataRect(xmin, ymin, xlength, yheight); } } ObsGraph.Visible = visible; DataRect visible2; PumpingGraph.FitToView(); visible2 = new DataRect(xmin, PumpingGraph.Visible.Y, xlength, PumpingGraph.Visible.Height); //Zoom the extraction graph if (wm != null && wm.Extractions.Count != 0) { var select = wm.Extractions.SelectMany(var => var.Item2.Where(var2 => var2.Time >= SelectionStartTime & var2.Time <= SelectionEndTime)); if (select != null && select.Count() != 0) { double ymin = select.Min(y => y.Value); double yheight = select.Max(y => y.Value) - ymin; ymin = ymin - 0.05 * yheight; yheight *= 1.1; visible2 = new DataRect(xmin, ymin, xlength, yheight); } } PumpingGraph.Visible = visible2; } }