Exemplo n.º 1
0
        private static void createTopHistogramMenu(HistogramOperationViewModel histogramOperationViewModel)
        {
            var attachmentViewModel = histogramOperationViewModel.AttachementViewModels.First(avm => avm.AttachmentOrientation == AttachmentOrientation.Top);
            var menuViewModel       = new MenuViewModel
            {
                AttachmentOrientation = attachmentViewModel.AttachmentOrientation,
                NrColumns             = 1,
                NrRows = 1
            };

            var menuItem = new MenuItemViewModel
            {
                MenuViewModel     = menuViewModel,
                Row               = 0,
                ColumnSpan        = 1,
                RowSpan           = 1,
                Column            = 0,
                Size              = new Vec(25, 25),
                Position          = histogramOperationViewModel.Position,
                TargetSize        = new Vec(25, 25),
                IsAlwaysDisplayed = true
            };
            var attr1 = new CreateLinkMenuItemViewModel();

            attr1.CreateLinkEvent += (sender, bounds) =>
            {
                FilterLinkViewController.Instance.CreateFilterLinkViewModel(histogramOperationViewModel, bounds);
            };

            menuItem.MenuItemComponentViewModel = attr1;
            menuViewModel.MenuItemViewModels.Add(menuItem);

            attachmentViewModel.MenuViewModel = menuViewModel;
        }
Exemplo n.º 2
0
        private static void createRightHistogramMenu(HistogramOperationViewModel histogramOperationViewModel)
        {
            var attachmentViewModel = histogramOperationViewModel.AttachementViewModels.First(avm => avm.AttachmentOrientation == AttachmentOrientation.Right);
            var menuViewModel       = new MenuViewModel
            {
                AttachmentOrientation = attachmentViewModel.AttachmentOrientation,
                NrColumns             = 2,
                NrRows = 2
            };

            histogramOperationViewModel.HistogramOperationModel.PropertyChanged += (sender, args) =>
            {
                var model = histogramOperationViewModel.HistogramOperationModel;
                if (args.PropertyName == model.GetPropertyName(() => model.StatisticalComparisonOperationModel))
                {
                    if (model.StatisticalComparisonOperationModel == null)
                    {
                        foreach (var mvm in menuViewModel.MenuItemViewModels.ToArray())
                        {
                            menuViewModel.MenuItemViewModels.Remove(mvm);
                        }
                    }
                    else
                    {
                        var menuItem = new MenuItemViewModel
                        {
                            MenuViewModel     = menuViewModel,
                            Row               = 0,
                            ColumnSpan        = 1,
                            RowSpan           = 2,
                            Column            = 0,
                            Size              = new Vec(54, 54),
                            Position          = histogramOperationViewModel.Position,
                            TargetSize        = new Vec(54, 54),
                            IsAlwaysDisplayed = true
                        };
                        var attr1 = new StatisticalComparisonMenuItemViewModel
                        {
                            StatisticalComparisonOperationModel = model.StatisticalComparisonOperationModel
                        };

                        menuItem.MenuItemComponentViewModel = attr1;
                        menuViewModel.MenuItemViewModels.Add(menuItem);

                        var        toggles = new List <ToggleMenuItemComponentViewModel>();
                        var        items   = new List <MenuItemViewModel>();
                        TestType[] types   = new TestType[] { TestType.chi2, TestType.ttest };
                        int        count   = 0;
                        foreach (var type in types)
                        {
                            var toggleMenuItem = new MenuItemViewModel
                            {
                                MenuViewModel     = menuViewModel,
                                Row               = count,
                                RowSpan           = 0,
                                Position          = histogramOperationViewModel.Position,
                                Column            = 1,
                                Size              = new Vec(54, 25),
                                TargetSize        = new Vec(54, 25),
                                IsAlwaysDisplayed = true
                            };
                            //toggleMenuItem.Position = attachmentItemViewModel.Position;
                            var toggle = new ToggleMenuItemComponentViewModel
                            {
                                Label     = type.ToString(),
                                IsChecked = model.StatisticalComparisonOperationModel.TestType == type
                            };
                            toggles.Add(toggle);
                            toggleMenuItem.MenuItemComponentViewModel = toggle;
                            toggleMenuItem.MenuItemComponentViewModel.PropertyChanged += (sender2, args2) =>
                            {
                                var toogleModel = sender2 as ToggleMenuItemComponentViewModel;
                                if (args2.PropertyName == model.GetPropertyName(() => toogleModel.IsChecked))
                                {
                                    if (toogleModel.IsChecked)
                                    {
                                        model.StatisticalComparisonOperationModel.TestType = type;
                                        model.StatisticalComparisonOperationModel.FireOperationModelUpdated(new OperationModelUpdatedEventArgs());
                                        foreach (var tg in toogleModel.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));
                        }
                    }
                }
            };

            attachmentViewModel.MenuViewModel = menuViewModel;
        }
Exemplo n.º 3
0
        public static HistogramOperationViewModel CreateDefaultHistogramOperationViewModel(SchemaModel schemaModel, AttributeModel attributeModel, Pt position)
        {
            var histogramOperationModel     = new HistogramOperationModel(schemaModel);
            var histogramOperationViewModel = new HistogramOperationViewModel(histogramOperationModel);

            histogramOperationViewModel.Position = position;
            addAttachmentViewModels(histogramOperationViewModel);

            // axis attachment view models
            createAxisMenu(histogramOperationViewModel, AttachmentOrientation.Bottom, AttributeUsage.X, new Vec(200, 50), 0, true, false);
            createAxisMenu(histogramOperationViewModel, AttachmentOrientation.Left, AttributeUsage.Y, new Vec(50, 200), 270, false, true);
            createRightHistogramMenu(histogramOperationViewModel);
            createTopHistogramMenu(histogramOperationViewModel);


            if ((attributeModel != null) && attributeModel is AttributeFieldModel)
            {
                var inputFieldModel = attributeModel as AttributeFieldModel;
                if (inputFieldModel.InputVisualizationType == InputVisualizationTypeConstants.ENUM)
                {
                    histogramOperationModel.VisualizationType = VisualizationType.plot;

                    var x = new AttributeTransformationModel(inputFieldModel);
                    x.AggregateFunction = AggregateFunction.None;

                    var value = new AttributeTransformationModel(inputFieldModel);
                    value.AggregateFunction = AggregateFunction.Count;

                    var y = new AttributeTransformationModel(inputFieldModel);
                    y.AggregateFunction = AggregateFunction.Count;

                    if (attributeModel.VisualizationHints.Contains(VisualizationHint.DefaultFlipAxis))
                    {
                        histogramOperationModel.AddAttributeUsageTransformationModel(AttributeUsage.X, y);
                        histogramOperationModel.AddAttributeUsageTransformationModel(AttributeUsage.Y, x);
                    }
                    else
                    {
                        histogramOperationModel.AddAttributeUsageTransformationModel(AttributeUsage.X, x);
                        histogramOperationModel.AddAttributeUsageTransformationModel(AttributeUsage.Y, y);
                    }
                    histogramOperationModel.AddAttributeUsageTransformationModel(AttributeUsage.DefaultValue, value);
                }
                else if (inputFieldModel.InputVisualizationType == InputVisualizationTypeConstants.NUMERIC)
                {
                    histogramOperationModel.VisualizationType = VisualizationType.plot;

                    var x = new AttributeTransformationModel(inputFieldModel);
                    x.AggregateFunction = AggregateFunction.None;

                    var value = new AttributeTransformationModel(inputFieldModel);
                    value.AggregateFunction = AggregateFunction.Count;

                    var y = new AttributeTransformationModel(inputFieldModel);
                    y.AggregateFunction = AggregateFunction.Count;

                    if (attributeModel.VisualizationHints.Contains(VisualizationHint.DefaultFlipAxis))
                    {
                        histogramOperationModel.AddAttributeUsageTransformationModel(AttributeUsage.X, y);
                        histogramOperationModel.AddAttributeUsageTransformationModel(AttributeUsage.Y, x);
                    }
                    else
                    {
                        histogramOperationModel.AddAttributeUsageTransformationModel(AttributeUsage.X, x);
                        histogramOperationModel.AddAttributeUsageTransformationModel(AttributeUsage.Y, y);
                    }
                    histogramOperationModel.AddAttributeUsageTransformationModel(AttributeUsage.DefaultValue, value);
                }
                else if (inputFieldModel.InputVisualizationType == InputVisualizationTypeConstants.GEOGRAPHY)
                {
                }
                else
                {
                    histogramOperationModel.VisualizationType = VisualizationType.table;
                    var x = new AttributeTransformationModel(inputFieldModel);
                    histogramOperationModel.AddAttributeUsageTransformationModel(AttributeUsage.X, x);
                }
            }
            else
            {
                histogramOperationModel.VisualizationType = VisualizationType.plot;
            }

            return(histogramOperationViewModel);
        }
Exemplo n.º 4
0
        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;
        }