private void OnTimeDataSourceChanged() { var source = TimeDataSource as NotifingCollection <DateTime>; TimeLineSource.Clear(); if (source != null) { source.CollectionChangedObservable. Where(eve => eve.EventArgs.Action == NotifyCollectionChangedAction.Add) .Select(eve => eve.EventArgs.NewItems.Cast <DateTime>()) .Subscribe(dateTimeCollection => { dateTimeCollection.ToObservable() .Select(date => date.Subtract(TimeSpan.FromSeconds(date.Second))) .Where(date => !TimeLineSource.Any() || TimeLineSource.LastOrDefault().Date.Equals(date) == false) .Subscribe(date => { TimeLineSource.Add(new ChartTimeBlock() { Date = date }); }); }); if (source.Any()) { var startingTime = source.Min(); var endTime = source.Max(); int timeDiffernce = (int)endTime.Subtract(startingTime).TotalMinutes + 1; // Set the timeline TimeLineSource = new TimeAxisSource( Enumerable.Range(0, timeDiffernce) .Select(index => new ChartTimeBlock() { Date = new DateTime(startingTime.Year, startingTime.Month, startingTime.Day, startingTime.Hour, startingTime.Minute, 0) .AddMinutes(index), CanShowDate = index == 0 })); } } }
private void OnSourceChanged(IEnumerable newSource) { var source = newSource as ChartLineCollection; if (source == null) { return; } HorizontalAxisSource.Clear(); source.CollectionChangedObservable .Where(eve => eve.EventArgs.Action == NotifyCollectionChangedAction.Add) .SelectMany(eve => eve.EventArgs.NewItems.Cast <IChartLine>()) .Where(line => line != null && line.Any() && TimeLineSource.Any()) .Subscribe(line => { HorizontalAxisSource.Add(new ChartLine( line.PinName, line.Select(point => new ChartPoint( point.Value, point.TimeStamp, GetDisplayPoint(point)) { PinName = point.PinName, PinType = point.PinType }), line.LineColor)); }); source.CollectionChangedObservable .Where(eve => eve.EventArgs.Action == NotifyCollectionChangedAction.Remove && HorizontalAxisSource.Any()) .Select(eve => eve.EventArgs.OldStartingIndex) .Subscribe(index => { var element = HorizontalAxisSource.ElementAt(index); if (element != null) { HorizontalAxisSource.Remove(element); } }); }