/// <summary> /// Handles changes to the DataValues property. /// </summary> private static void OnDataValuesChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) { Graph obj = (Graph)d; if (e.NewValue != null && e.OldValue != null) { //if we see a different actual ThreadSafeObservableCollection<GraphDataItem> //we should unhook the old event handler if (!Object.ReferenceEquals(e.OldValue, e.NewValue)) { GraphDataCollection oldDataValues = (GraphDataCollection)e.OldValue; oldDataValues.CollectionChanged -= obj.DataValues_CollectionChanged; GraphDataCollection newDataValues = (GraphDataCollection)e.OldValue; newDataValues.CollectionChanged += obj.DataValues_CollectionChanged; } else { GraphDataCollection newDataValues = (GraphDataCollection)e.NewValue; newDataValues.CollectionChanged += obj.DataValues_CollectionChanged; } } else { GraphDataCollection newDataValues = (GraphDataCollection)e.NewValue; newDataValues.CollectionChanged += obj.DataValues_CollectionChanged; } }
private void UpdateTimer_Tick(object sender, EventArgs e) { lock (chartLock) { if (motionLevel > motionTriggerThreshold) { if (!playOnce && enableBeepOnTrigger) { playOnce = true; PlayBeep(); } if (!captureImageOnce && cbEnableSaveImg.IsChecked == true) { captureImageOnce = true; CaptureAsImage(); } } // update data into collection DateTime currentTime = DateTime.Now; double elapsedTime = (currentTime - startTime).TotalSeconds; motionLevelData = new MotionLevelData(elapsedTime, motionLevel, motionTriggerThreshold, startTime, currentTime, detectedObjectsCount); GraphDataCollection.Add(motionLevelData); if (GraphDataCollection.Count > 10000) { GraphDataCollection.RemoveAt(0); } // update sensitivity bar UpdateSensivityBarUI(); // update graph OxyGraph.InvalidatePlot(true); // autoscroll graph x-axis if ((elapsedTime + 0.001) >= xAxis.Maximum) { double panStep = (xAxis.ActualMaximum - xAxis.DataMaximum) * xAxis.Scale; xAxis.Pan(panStep); } // write to log file if (!customIntervalEnabled) { LogData(motionLevelData); } } }
private void UpdateGraph() { if (IsShowGraph == false) { return; } List <GraphModel> tempCollection = new List <GraphModel>(); GraphDataCollection.Clear(); // Initialize collection tempCollection.Add(new GraphModel(DateHelper.ToStringDate(DateHelper.GetDayOfWeek(_selectedDate, DayOfWeek.Monday)))); tempCollection.Add(new GraphModel(DateHelper.ToStringDate(DateHelper.GetDayOfWeek(_selectedDate, DayOfWeek.Tuesday)))); tempCollection.Add(new GraphModel(DateHelper.ToStringDate(DateHelper.GetDayOfWeek(_selectedDate, DayOfWeek.Wednesday)))); tempCollection.Add(new GraphModel(DateHelper.ToStringDate(DateHelper.GetDayOfWeek(_selectedDate, DayOfWeek.Thursday)))); tempCollection.Add(new GraphModel(DateHelper.ToStringDate(DateHelper.GetDayOfWeek(_selectedDate, DayOfWeek.Friday)))); tempCollection.Add(new GraphModel(DateHelper.ToStringDate(DateHelper.GetDayOfWeek(_selectedDate, DayOfWeek.Saturday)))); tempCollection.Add(new GraphModel(DateHelper.ToStringDate(DateHelper.GetDayOfWeek(_selectedDate, DayOfWeek.Sunday)))); for (int i = 0; i < tempCollection.Count; i++) { var itemList = ItemCollection.Where(x => x.Date.Equals(tempCollection[i].Date)); if (itemList.Count() == 0) { continue; } foreach (var model in itemList) { if (model.Type == ItemType.Income) { continue; } tempCollection[i].AddItem(model.Type, model.Amount); } } // Save to GraphItemCollection GraphItemCollection.Clear(); var sortedCollection = tempCollection.OrderBy(x => x.Date); for (int i = 0; i < sortedCollection.Count(); i++) { GraphItemCollection.Add(sortedCollection.ElementAt(i)); } }