private static void createBottomExampleMenu(ExampleOperationViewModel exampleOperationViewModel) { var attachmentViewModel = exampleOperationViewModel.AttachementViewModels.First( avm => avm.AttachmentOrientation == AttachmentOrientation.Bottom); attachmentViewModel.ShowOnAttributeMove = true; var menuViewModel = new MenuViewModel { AttachmentOrientation = attachmentViewModel.AttachmentOrientation, NrColumns = 3, NrRows = 1 }; var addMenuItem = new MenuItemViewModel { MenuViewModel = menuViewModel, Row = 0, ColumnSpan = 1, RowSpan = 1, Column = 0, Size = new Vec(25, 25), TargetSize = new Vec(25, 25), IsAlwaysDisplayed = false, IsWidthBoundToParent = false, IsHeightBoundToParent = false, Position = exampleOperationViewModel.Position }; var attr1 = new AttributeTransformationMenuItemViewModel { Label = "+", TextBrush = new SolidColorBrush(Helpers.GetColorFromString("#171717")), CanDrag = false, CanDrop = true }; attr1.DroppedTriggered = attributeTransformationModel => { exampleOperationViewModel.ExampleOperationModel.AttributeUsageTransformationModels.Add(attributeTransformationModel); }; addMenuItem.MenuItemComponentViewModel = attr1; menuViewModel.MenuItemViewModels.Add(addMenuItem); attachmentViewModel.MenuViewModel = menuViewModel; exampleOperationViewModel.ExampleOperationModel.AttributeUsageTransformationModels.CollectionChanged += (sender, args) => { var coll = sender as ObservableCollection <AttributeTransformationModel>; // remove old ones first if (args.OldItems != null) { foreach (var oldItem in args.OldItems) { var oldAttributeTransformationModel = oldItem as AttributeTransformationModel; var found = menuViewModel.MenuItemViewModels.FirstOrDefault(mvm => (((AttributeTransformationMenuItemViewModel)mvm.MenuItemComponentViewModel).AttributeTransformationViewModel != null) && (((AttributeTransformationMenuItemViewModel)mvm.MenuItemComponentViewModel).AttributeTransformationViewModel.AttributeTransformationModel == oldAttributeTransformationModel)); if (found != null) { menuViewModel.MenuItemViewModels.Remove(found); } } } menuViewModel.NrRows = (int)Math.Ceiling(coll.Count / 3.0) + 1; addMenuItem.Row = menuViewModel.NrRows - 1; // add new ones if (args.NewItems != null) { foreach (var newItem in args.NewItems) { var newAttributeTransformationModel = newItem as AttributeTransformationModel; var newMenuItem = new MenuItemViewModel { MenuViewModel = menuViewModel, Size = new Vec(50, 50), TargetSize = new Vec(50, 50), Position = addMenuItem.Position }; var newAttr = new AttributeTransformationMenuItemViewModel { Label = newAttributeTransformationModel.GetLabel(), AttributeTransformationViewModel = new AttributeTransformationViewModel(exampleOperationViewModel, newAttributeTransformationModel), TextBrush = new SolidColorBrush(Helpers.GetColorFromString("#29aad5")), CanDrag = false, CanDrop = false }; newMenuItem.Deleted += (sender1, args1) => { var atm = ((AttributeTransformationMenuItemViewModel)((MenuItemViewModel)sender1).MenuItemComponentViewModel).AttributeTransformationViewModel.AttributeTransformationModel; exampleOperationViewModel.ExampleOperationModel.AttributeUsageTransformationModels.Remove(atm); }; newMenuItem.MenuItemComponentViewModel = newAttr; menuViewModel.MenuItemViewModels.Add(newMenuItem); } } var count = 0; foreach (var menuItemViewModel in menuViewModel.MenuItemViewModels.Where(mvm => mvm != addMenuItem)) { menuItemViewModel.Column = count % 3; menuItemViewModel.Row = (int)Math.Floor(count / 3.0); count++; } attachmentViewModel.ActiveStopwatch.Restart(); menuViewModel.FireUpdate(); }; }
private static void createAxisMenu(HistogramOperationViewModel histogramOperationViewModel, AttachmentOrientation attachmentOrientation, AttributeUsage axis, Vec size, double textAngle, bool isWidthBoundToParent, bool isHeightBoundToParent) { var attachmentViewModel = histogramOperationViewModel.AttachementViewModels.First( avm => avm.AttachmentOrientation == attachmentOrientation); var menuViewModel = new MenuViewModel { AttachmentOrientation = attachmentViewModel.AttachmentOrientation, NrColumns = attachmentOrientation == AttachmentOrientation.Bottom ? 5 : 2, NrRows = attachmentOrientation == AttachmentOrientation.Bottom ? 2 : 5 }; var menuItem = new MenuItemViewModel { MenuViewModel = menuViewModel, Row = 0, ColumnSpan = attachmentOrientation == AttachmentOrientation.Bottom ? 5 : 1, RowSpan = attachmentOrientation == AttachmentOrientation.Bottom ? 1 : 5, Column = attachmentOrientation == AttachmentOrientation.Bottom ? 0 : 1, Size = size, Position = histogramOperationViewModel.Position, TargetSize = size, IsAlwaysDisplayed = true, IsWidthBoundToParent = isWidthBoundToParent, IsHeightBoundToParent = isHeightBoundToParent }; var attr1 = new AttributeTransformationMenuItemViewModel { TextAngle = textAngle, TextBrush = new SolidColorBrush(Helpers.GetColorFromString("#29aad5")) }; histogramOperationViewModel.HistogramOperationModel.GetAttributeUsageTransformationModel(axis).CollectionChanged += (sender, args) => { var coll = sender as ObservableCollection <AttributeTransformationModel>; var attributeTransformationModel = coll.FirstOrDefault(); attr1.Label = attributeTransformationModel == null ? "" : attributeTransformationModel.GetLabel(); attr1.AttributeTransformationViewModel = new AttributeTransformationViewModel(histogramOperationViewModel, coll.FirstOrDefault()); if (attributeTransformationModel != null) { attributeTransformationModel.PropertyChanged += (sender2, args2) => { attr1.Label = (sender2 as AttributeTransformationModel).GetLabel(); }; } // remove old ones first foreach (var mvm in menuViewModel.MenuItemViewModels.Where(mvm => mvm.MenuItemComponentViewModel is ToggleMenuItemComponentViewModel).ToArray()) { menuViewModel.MenuItemViewModels.Remove(mvm); } var aom = attr1.AttributeTransformationViewModel.AttributeTransformationModel; var aggregateFunctions = new[] { AggregateFunction.None, AggregateFunction.Count }.ToList(); if (aom != null) { if (((AttributeFieldModel)aom.AttributeModel).InputDataType == InputDataTypeConstants.INT || (((AttributeFieldModel)aom.AttributeModel).InputDataType == InputDataTypeConstants.FLOAT)) { aggregateFunctions.Add(AggregateFunction.Avg); aggregateFunctions.Add(AggregateFunction.Sum); if (MainViewController.Instance.MainModel.IsUnknownUnknownEnabled) { aggregateFunctions.Add(AggregateFunction.SumE); } } var toggles = new List <ToggleMenuItemComponentViewModel>(); var items = new List <MenuItemViewModel>(); var count = 0; foreach (var aggregationFunction in aggregateFunctions) { var toggleMenuItem = new MenuItemViewModel { MenuViewModel = menuViewModel, Row = attachmentOrientation == AttachmentOrientation.Bottom ? 1 : count, RowSpan = 0, Position = histogramOperationViewModel.Position, Column = attachmentOrientation == AttachmentOrientation.Bottom ? count : 0, Size = new Vec(32, 32), TargetSize = new Vec(32, 32) }; //toggleMenuItem.Position = attachmentItemViewModel.Position; var toggle = new ToggleMenuItemComponentViewModel { Label = aggregationFunction.ToString(), IsChecked = aom.AggregateFunction == aggregationFunction }; toggles.Add(toggle); toggleMenuItem.MenuItemComponentViewModel = toggle; toggleMenuItem.MenuItemComponentViewModel.PropertyChanged += (sender2, args2) => { var model = sender2 as ToggleMenuItemComponentViewModel; if (args2.PropertyName == model.GetPropertyName(() => model.IsChecked)) { if (model.IsChecked) { aom.AggregateFunction = aggregationFunction; foreach (var tg in model.OtherToggles) { tg.IsChecked = false; } } } }; menuViewModel.MenuItemViewModels.Add(toggleMenuItem); items.Add(toggleMenuItem); count++; } foreach (var mi in items) { (mi.MenuItemComponentViewModel as ToggleMenuItemComponentViewModel).OtherToggles.AddRange(toggles.Where(ti => ti != mi.MenuItemComponentViewModel)); } } }; attr1.TappedTriggered = () => { attachmentViewModel.ActiveStopwatch.Restart(); }; attr1.DroppedTriggered = attributeTransformationModel => { var otherAxis = axis == AttributeUsage.X ? AttributeUsage.Y : AttributeUsage.X; var existingModel = histogramOperationViewModel.HistogramOperationModel.GetAttributeUsageTransformationModel(axis).Any() ? histogramOperationViewModel.HistogramOperationModel.GetAttributeUsageTransformationModel(axis).First() : null; var existingOtherModel = histogramOperationViewModel.HistogramOperationModel.GetAttributeUsageTransformationModel(otherAxis).Any() ? histogramOperationViewModel.HistogramOperationModel.GetAttributeUsageTransformationModel(otherAxis).First() : null; var swapAxes = existingModel != null && existingOtherModel.AttributeModel == attributeTransformationModel.AttributeModel && existingOtherModel.AggregateFunction == attributeTransformationModel.AggregateFunction; if (existingModel != null) { histogramOperationViewModel.HistogramOperationModel.RemoveAttributeUsageTransformationModel(axis, existingModel); } if (!histogramOperationViewModel.HistogramOperationModel.GetAttributeUsageTransformationModel(AttributeUsage.DefaultValue).Any()) { var value = new AttributeTransformationModel(attributeTransformationModel.AttributeModel); value.AggregateFunction = AggregateFunction.Count; histogramOperationViewModel.HistogramOperationModel.AddAttributeUsageTransformationModel(AttributeUsage.DefaultValue, value); } histogramOperationViewModel.HistogramOperationModel.AddAttributeUsageTransformationModel(axis, attributeTransformationModel); attachmentViewModel.ActiveStopwatch.Restart(); if (swapAxes) { histogramOperationViewModel.HistogramOperationModel.RemoveAttributeUsageTransformationModel(otherAxis, existingOtherModel); if (!histogramOperationViewModel.HistogramOperationModel.GetAttributeUsageTransformationModel(AttributeUsage.DefaultValue).Any()) { var value = new AttributeTransformationModel(attributeTransformationModel.AttributeModel); value.AggregateFunction = AggregateFunction.Count; histogramOperationViewModel.HistogramOperationModel.AddAttributeUsageTransformationModel(AttributeUsage.DefaultValue, value); } histogramOperationViewModel.HistogramOperationModel.AddAttributeUsageTransformationModel(otherAxis, existingModel); } }; menuItem.MenuItemComponentViewModel = attr1; menuViewModel.MenuItemViewModels.Add(menuItem); attachmentViewModel.MenuViewModel = menuViewModel; }