/// <summary> /// Workaround for an issue in the WPF toolkit where datapoint columns would be rendered too wide if only /// a few were present in the chart. /// </summary> /// <param name="graphDataCollection"></param> /// <returns></returns> private static ITextGraphDataCollection AddMonthlyZeroesWorkaround(ITextGraphDataCollection graphDataCollection) { List <ITextGraphData> sortedGraphDataCollection = new List <ITextGraphData>(graphDataCollection); sortedGraphDataCollection.Sort(delegate(ITextGraphData tgd1, ITextGraphData tgd2) { return(tgd1.Date.CompareTo(tgd2.Date)); }); TextGraphDataCollection zeroAddedCollection = new TextGraphDataCollection(); DateTime lastDate = DateTime.MinValue; foreach (ITextGraphData currentTextData in sortedGraphDataCollection) { if (lastDate != DateTime.MinValue) { DateTime iteratorDate = lastDate.AddMonths(1); while (iteratorDate < currentTextData.Date) { zeroAddedCollection.Add(new TextGraphData(iteratorDate)); iteratorDate = iteratorDate.AddMonths(1); } } zeroAddedCollection.Add(currentTextData); lastDate = currentTextData.Date; } return(zeroAddedCollection); }
/// <summary> /// Workaround for an issue in the WPF toolkit where datapoint columns would be rendered too wide if only /// a few were present in the chart. /// </summary> /// <param name="graphDataCollection"></param> /// <returns></returns> private static ITextGraphDataCollection AddMonthlyZeroesWorkaround(ITextGraphDataCollection graphDataCollection) { List<ITextGraphData> sortedGraphDataCollection = new List<ITextGraphData>(graphDataCollection); sortedGraphDataCollection.Sort(delegate(ITextGraphData tgd1, ITextGraphData tgd2) { return tgd1.Date.CompareTo(tgd2.Date); }); TextGraphDataCollection zeroAddedCollection = new TextGraphDataCollection(); DateTime lastDate = DateTime.MinValue; foreach (ITextGraphData currentTextData in sortedGraphDataCollection) { if (lastDate != DateTime.MinValue) { DateTime iteratorDate = lastDate.AddMonths(1); while (iteratorDate < currentTextData.Date) { zeroAddedCollection.Add(new TextGraphData(iteratorDate)); iteratorDate = iteratorDate.AddMonths(1); } } zeroAddedCollection.Add(currentTextData); lastDate = currentTextData.Date; } return zeroAddedCollection; }
public void EmptyPerUnitTimeTest() { IConversation conversation = DummyConversationDataGenerator.GetSingleConversation(DummyPhoneNumberId.NeverTexterCell); GraphDataGenerator generator = new GraphDataGenerator(); ITextGraphDataCollection perMonthCollection = generator.MessageCountPerUnitTime(conversation, GraphTimeUnit.Month); Assert.AreEqual(0, perMonthCollection.Count); }
public GraphWindowModel(IDisplayOptions displayOptions, IPhoneSelectOptions phoneSelectOptions) : base(displayOptions, phoneSelectOptions) { SelectedConversationIndex = NoContactSelectedIndex; SelectedGraphType = DefaultGraphType; _graphDataGenerator = new GraphDataGenerator(); _cachedCurrentGraphData = null; }
public void EmptyAggregateTest() { IConversation conversation = DummyConversationDataGenerator.GetSingleConversation(DummyPhoneNumberId.NeverTexterCell); GraphDataGenerator generator = new GraphDataGenerator(); ITextGraphDataCollection hourOfDayCollection = generator.MessageCountAggregate(conversation, GraphAggregateType.HourOfDay); foreach (ITextGraphData graphData in hourOfDayCollection) { Assert.AreEqual(0, graphData.MessagesTotal); } ITextGraphDataCollection dayOfWeekCollection = generator.MessageCountAggregate(conversation, GraphAggregateType.DayOfWeek); foreach (ITextGraphData graphData in dayOfWeekCollection) { Assert.AreEqual(0, graphData.MessagesTotal); } }
private void CalculateMonthAxisMinMax(ITextGraphDataCollection graphDataCollection, out DateTime minDate, out DateTime maxDate) { DateTime min = DateTime.MaxValue; DateTime max = DateTime.MinValue; foreach (TextGraphData graphData in graphDataCollection) { if (graphData.Date < min) { min = graphData.Date; } if (graphData.Date > max) { max = graphData.Date; } } TimeSpan totalSpan = max.Subtract(min); // // Add padding if the total span is less than 180 days. // const int MinDaysWidth = 180; const double MinPadding = 15; double paddingAmount; if (totalSpan.TotalDays < MinDaysWidth) { paddingAmount = Math.Max((MinDaysWidth - totalSpan.TotalDays) / 2, MinPadding); } else { paddingAmount = MinPadding; } min = min.Subtract(TimeSpan.FromDays(paddingAmount)); max = max.Add(TimeSpan.FromDays(paddingAmount)); minDate = min; maxDate = max; }
public void SwitchConversationTest() { GraphWindowModel_Accessor model = GetPopulatedGraphWindowModel(); // // Populate the cache. // ITextGraphDataCollection originalGraphData = model.CurrentGraphDataCollection; Assert.IsNotNull(originalGraphData); Assert.AreEqual(originalGraphData, model._cachedCurrentGraphData); IConversation newConversation = new List <IConversationListItem>(model.ConversationListItems)[2].Conversation; Assert.AreNotEqual(newConversation, model.SelectedGraphType); model.SelectedConversation = newConversation; Assert.IsNull(model._cachedCurrentGraphData); ITextGraphDataCollection newGraphData = model.CurrentGraphDataCollection; Assert.IsNotNull(model._cachedCurrentGraphData); Assert.AreNotEqual(newGraphData, originalGraphData); }
public void SwitchGraphTypeTest() { GraphWindowModel_Accessor model = GetPopulatedGraphWindowModel(); // // Populate the cache. // ITextGraphDataCollection originalGraphData = model.CurrentGraphDataCollection; Assert.IsNotNull(originalGraphData); Assert.AreEqual(originalGraphData, model._cachedCurrentGraphData); GraphType newGraphType = GraphType.PerMonth; Assert.AreNotEqual(newGraphType, model.SelectedGraphType); model.SelectedGraphType = newGraphType; Assert.IsNull(model._cachedCurrentGraphData); ITextGraphDataCollection newGraphData = model.CurrentGraphDataCollection; Assert.IsNotNull(model._cachedCurrentGraphData); Assert.AreNotEqual(newGraphData, originalGraphData); }