Exemple #1
0
        public void HeatMapTest()
        {
            HeatMapModel heatMap = HeatMapModel.CreateRandom(10, 10, 0, 100);

            folderResults.SaveText(heatMap.GetDataTable("HeatMap_Random", "").textTable(4), "HeatMapData.txt", imbSCI.Data.enums.getWritableFileMode.overwrite, "Values from random heat map");

            HeatMapRender heatMapRender = new HeatMapRender();

            Svg.SvgDocument svg = heatMapRender.RenderAndSave(heatMap, folderResults.pathFor("heatmap_render.svg", imbSCI.Data.enums.getWritableFileMode.overwrite));

            var jpg = folderResults.pathFor("heatmap_render.jpg", imbSCI.Data.enums.getWritableFileMode.overwrite);

            svg.SaveJPEG(jpg);


            heatMapRender = new HeatMapRender();
            heatMapRender.style.LowColor  = Color.Blue;
            heatMapRender.style.HighColor = Color.Red;

            Svg.SvgDocument svgbr = heatMapRender.RenderAndSave(heatMap, folderResults.pathFor("heatmap_render_bluered.svg", imbSCI.Data.enums.getWritableFileMode.overwrite));

            jpg = folderResults.pathFor("heatmap_render_bluered.jpg", imbSCI.Data.enums.getWritableFileMode.overwrite);


            svgbr.SaveJPEG(jpg);
        }
        public HeatMapViewModel(HeatMapModel heatMapModel)
        {
            this.HeatMap = heatMapModel;

            this.RefreshIntervalChoices = new ObservableCollection <int>()
            {
                1, 5, 15, 30, 60, 180
            };
            this.RefreshIntervalSeconds = 30; //Default
        }
        public void Publish(Dictionary <HtmlNode, HtmlSourceAndUrl> documentNodeDictionary, folderNode folderWithResults, List <HtmlNode> reportOn = null)
        {
            if (reportOn == null)
            {
                reportOn = GetDocuments();
            }

            folderWithResults.generateReadmeFiles(null);

            builderForText reporter = new builderForText();

            foreach (var item in items)
            {
                if (item.IsRelatedTo(reportOn))
                {
                    reporter.AppendLine("Pair [" + items.IndexOf(item) + "]");
                    item.Publish(documentNodeDictionary, folderWithResults, reporter);
                }
            }

            Report(StructureSimilarityRange, reporter, "Structure similarity", "SS");
            Report(ContentSimilarityRange, reporter, "Content similarity", "CS");

            String reporterPath = folderWithResults.pathFor("report.txt");

            File.WriteAllText(reporterPath, reporter.GetContent());



            DataSet output = PublishDataSet(documentNodeDictionary, reportOn);

            HeatMapRender hmRender = new HeatMapRender();

            foreach (DataTable table in output.Tables)
            {
                HeatMapModel heatMap = new HeatMapModel(table);


                var heatMapSVG = hmRender.Render(heatMap, folderWithResults.pathFor(table.TableName + ".svg", imbSCI.Data.enums.getWritableFileMode.overwrite, "Headmap render for " + table.TableName));
                heatMapSVG.SaveJPEG(folderWithResults.pathFor(table.TableName + ".jpg", imbSCI.Data.enums.getWritableFileMode.overwrite, "Headmap render for " + table.TableName));
            }

            output.GetReportAndSave(folderWithResults, null, "");
        }
Exemple #4
0
        protected void prepareLabels(HeatMapModel model)
        {
            foreach (String key in model.xKeys)
            {
                String k = key;
                if (style.accronimLength > 0)
                {
                    k = key.imbGetWordAbbrevation(style.accronimLength, true);
                }
                xLabels.Add(k);
            }

            foreach (String key in model.yKeys)
            {
                String k = key;
                if (style.accronimLength > 0)
                {
                    k = key.imbGetWordAbbrevation(style.accronimLength, true);
                }
                yLabels.Add(k);
            }
        }
Exemple #5
0
        /// <summary>
        /// Gets the heat map matrix.
        /// </summary>
        /// <param name="dictionaries">The dictionaries.</param>
        /// <returns></returns>
        public static HeatMapModel GetHeatMapMatrix(this IEnumerable <WeightDictionary> dictionaries)
        {
            OverlapMatrix <WeightDictionaryEntry> matrix = dictionaries.GetOverlapMatrix(); // = new List<List<WeightDictionaryEntry>>();

            List <String> dictnames = dictionaries.Select(x => x.name).ToList();

            HeatMapModel output = new HeatMapModel(dictnames);


            for (int i = 0; i < matrix.width; i++)
            {
                for (int y = 0; y < matrix.height; y++)
                {
                    output[i, y] = matrix[i, y].GetWeightSum();
                }
            }

            output.DetectMinMax();


            return(output);
        }
Exemple #6
0
        /// <summary>
        /// Gets the heat map matrix.
        /// </summary>
        /// <param name="dictionaries">The dictionaries.</param>
        /// <returns></returns>
        public static HeatMapModel GetHeatMapMatrix(this IEnumerable <SpaceDocumentModel> dictionaries)
        {
            OverlapMatrix <String> matrix = dictionaries.Select(x => x.terms).GetOverlapMatrix(); // = new List<List<WeightDictionaryEntry>>();
            var           terms           = dictionaries.Select(x => x.terms).ToList();
            List <String> dictnames       = dictionaries.Select(x => x.name).ToList();

            HeatMapModel output = new HeatMapModel(dictnames);


            for (int i = 0; i < matrix.width; i++)
            {
                for (int y = 0; y < matrix.height; y++)
                {
                    output[i, y] = terms[i].GetTokenFrequencies(matrix[i, y]);
                }
            }

            output.DetectMinMax();


            return(output);
        }
        public MainView()
        {
            this.viewModel   = new MainViewModel();
            this.DataContext = this.viewModel;
            InitializeComponent();

            //Set the default grid height
            asyncOperationTabHeight = new GridLength(1, GridUnitType.Star);

            //Add listener for the generic dialog message
            Messenger.Default.Register <GenericDialogMessage>(this, (m) =>
            {
                Messenger.Default.Register <CloseGenericMessage>(this,
                                                                 (o) =>
                {
                    this.genericPopupWindow.Close();
                    Messenger.Default.Unregister <CloseGenericMessage>(this);
                });

                //Need to use dispatcher.Invoke because this message may be called via a non UI thread, and those threads
                //Cannot create controls/windows.  To work around this, creation of the window is run in the dispacter of the main view (this)
                this.Dispatcher.Invoke(() =>
                {
                    this.genericPopupWindow = new GenericEmptyWindow();

                    this.genericPopupWindow.MinHeight                  = MinWindowHeight;
                    this.genericPopupWindow.MaxHeight                  = MaxWindowHeight;
                    this.genericPopupWindow.MinWidth                   = MinWindowWidth;
                    this.genericPopupWindow.MaxWidth                   = MaxWindowWidth;
                    this.genericPopupWindow.Title                      = "Message";
                    this.genericPopupWindow.Owner                      = this;
                    this.genericPopupWindow.Content                    = new GenericMessageControl(new GenericMessageViewModel(m.MessageString));
                    this.genericPopupWindow.ResizeMode                 = System.Windows.ResizeMode.CanResizeWithGrip;
                    this.genericPopupWindow.SizeToContent              = System.Windows.SizeToContent.WidthAndHeight;
                    this.genericPopupWindow.VerticalContentAlignment   = System.Windows.VerticalAlignment.Top;
                    this.genericPopupWindow.HorizontalContentAlignment = System.Windows.HorizontalAlignment.Center;
                    this.IsEnabled = false;
                    this.genericPopupWindow.ShowDialog();
                    this.IsEnabled          = true;
                    this.genericPopupWindow = null;
                });
            });
            //Add listener for the message to show the delete confirm dialog box
            Messenger.Default.Register <ShowDeleteWarningMessage>(this, (m) =>
            {
                var result =
                    MessageBox.Show(
                        "Are you sure you want to delete this account?",
                        "Confirm Delete",
                        MessageBoxButton.YesNo);

                if (result == MessageBoxResult.Yes)
                {
                    Messenger.Default.Send(new ConfirmAccountDeleteMessage());
                }
                else
                {
                    Messenger.Default.Send(new CloseGenericPopup());
                }
            });

            //Add a listener to trigger the showing of the account dialog box in edit mode
            Messenger.Default.Register <EditAccountMessage>(this,
                                                            (m) =>
            {
                //Make sure we close the popup afterward
                Messenger.Default.Register <CloseGenericPopup>(this,
                                                               (o) =>
                {
                    this.genericEmptyWindow.Close();
                    Messenger.Default.Unregister <CloseGenericPopup>(this);
                });

                this.genericEmptyWindow               = new GenericEmptyWindow();
                this.genericEmptyWindow.Title         = "Edit Account";
                this.genericEmptyWindow.Content       = new AccountManagementControl(m.AccountDialogViewModel);
                this.genericEmptyWindow.ResizeMode    = ResizeMode.NoResize;
                this.genericEmptyWindow.Owner         = this;
                this.genericEmptyWindow.SizeToContent = SizeToContent.WidthAndHeight;
                this.IsEnabled = false;
                this.genericEmptyWindow.ShowDialog();
                this.IsEnabled          = true;
                this.genericEmptyWindow = null;
            });

            //Add a listener to trigger the showing of the account dialog box in add mode
            Messenger.Default.Register <AddAccountMessage>(this,
                                                           (m) =>
            {
                //Make sure we close the popup afterward
                Messenger.Default.Register <CloseGenericPopup>(this,
                                                               (o) =>
                {
                    this.genericEmptyWindow.Close();
                    Messenger.Default.Unregister <CloseGenericPopup>(this);
                });


                this.genericEmptyWindow               = new GenericEmptyWindow();
                this.genericEmptyWindow.Title         = "Add Account";
                this.genericEmptyWindow.Content       = new AccountManagementControl(m.AccountDialogViewModel);
                this.genericEmptyWindow.ResizeMode    = ResizeMode.NoResize;
                this.genericEmptyWindow.Owner         = this;
                this.genericEmptyWindow.SizeToContent = SizeToContent.WidthAndHeight;
                this.IsEnabled = false;
                this.genericEmptyWindow.ShowDialog();
                this.IsEnabled          = true;
                this.genericEmptyWindow = null;
            });

            //Add a listener to trigger the showing of a dialog box with multiple buttons
            Messenger.Default.Register <LaunchMultibuttonDialogMessage>(this, (message) =>
            {
                var result = MessageBox.Show(message.DialogMessage, message.Caption, message.MessageBoxButton,
                                             message.MessageBoxImage);
                Messenger.Default.Send <MultibuttonDialogReturnMessage>(new MultibuttonDialogReturnMessage(result));
            });

            Messenger.Default.Register <RebootComputeNodeMessage>(this, (message) =>
            {
                MessageBoxResult result = MessageBox.Show("Are you sure you want to reboot this Compute Node?", "Compute Node Reboot", MessageBoxButton.YesNo);
                ComputeNodeRebootConfimation confimation = ComputeNodeRebootConfimation.Cancelled;

                if (result == MessageBoxResult.Yes)
                {
                    confimation = ComputeNodeRebootConfimation.Confirmed;
                }

                Messenger.Default.Send <RebootComputeNodeConfirmationMessage>(new RebootComputeNodeConfirmationMessage(confimation));
            });

            Messenger.Default.Register <ReimageComputeNodeMessage>(this, (message) =>
            {
                MessageBoxResult result = MessageBox.Show("Are you sure you want to reimage this Compute Node?", "Compute Node Reimage", MessageBoxButton.YesNo);
                ComputeNodeReimageConfimation confimation = ComputeNodeReimageConfimation.Cancelled;

                if (result == MessageBoxResult.Yes)
                {
                    confimation = ComputeNodeReimageConfimation.Confirmed;
                }

                Messenger.Default.Send <ReimageComputeNodeConfirmationMessage>(new ReimageComputeNodeConfirmationMessage(confimation));
            });

            Messenger.Default.Register <ShowAboutWindow>(this, (message) =>
            {
                this.aboutWindow       = new AboutWindow();
                this.aboutWindow.Owner = this;
                this.IsEnabled         = false;
                this.aboutWindow.ShowDialog();
                this.IsEnabled   = true;
                this.aboutWindow = null;
            });

            Messenger.Default.Register <ShowCreatePoolWindow>(this, (message) =>
            {
                this.genericEmptyWindow               = new GenericEmptyWindow();
                this.genericEmptyWindow.Title         = "Create Pool";
                this.genericEmptyWindow.Content       = new CreateControls.CreatePoolControl(new CreatePoolViewModel(MainViewModel.dataProvider));
                this.genericEmptyWindow.Owner         = this;
                this.genericEmptyWindow.SizeToContent = System.Windows.SizeToContent.WidthAndHeight;
                this.IsEnabled = false;
                this.genericEmptyWindow.ShowDialog();
                this.IsEnabled          = true;
                this.genericEmptyWindow = null;
            });

            Messenger.Default.Register <ShowAsyncOperationDetailWindow>(this,
                                                                        (m) =>
            {
                this.genericEmptyWindow               = new GenericEmptyWindow();
                this.genericEmptyWindow.MinHeight     = MinWindowHeight;
                this.genericEmptyWindow.MaxHeight     = MaxWindowHeight;
                this.genericEmptyWindow.MinWidth      = MinWindowWidth;
                this.genericEmptyWindow.MaxWidth      = MaxWindowWidth;
                this.genericEmptyWindow.Title         = "Operation Details";
                this.genericEmptyWindow.Content       = new AsyncOperationDetailsControl(new AsyncOperationDetailsViewModel(m.AsyncOperation));
                this.genericEmptyWindow.Owner         = this;
                this.genericEmptyWindow.ResizeMode    = System.Windows.ResizeMode.CanResizeWithGrip;
                this.genericEmptyWindow.SizeToContent = System.Windows.SizeToContent.WidthAndHeight;
                this.IsEnabled = false;
                this.genericEmptyWindow.ShowDialog();
                this.IsEnabled          = true;
                this.genericEmptyWindow = null;
            });

            Messenger.Default.Register <ShowOptionsDialogMessage>(this,
                                                                  (m) =>
            {
                //Make sure we close the popup afterward
                Messenger.Default.Register <CloseGenericPopup>(this,
                                                               (o) =>
                {
                    this.genericEmptyWindow.Close();
                    Messenger.Default.Unregister <CloseGenericPopup>(this);
                });

                this.genericEmptyWindow               = new GenericEmptyWindow();
                this.genericEmptyWindow.Title         = "Options";
                this.genericEmptyWindow.Content       = new OptionsControl(new OptionsViewModel());
                this.genericEmptyWindow.Owner         = this;
                this.genericEmptyWindow.SizeToContent = SizeToContent.WidthAndHeight;
                this.IsEnabled = false;
                this.genericEmptyWindow.ShowDialog();
                this.IsEnabled          = true;
                this.genericEmptyWindow = null;
            });

            const int optionsRowLocation = 3;

            //Check if we need to collapse the operation history display on start
            if (!OptionsModel.Instance.DisplayOperationHistory)
            {
                //Store the current height and then hide the control and move the grid to auto
                asyncOperationTabHeight            = this.MainGrid.RowDefinitions[optionsRowLocation].Height;
                this.AsyncOperationGrid.Visibility = Visibility.Collapsed;
                this.MainGrid.RowDefinitions[optionsRowLocation].Height = GridLength.Auto;
            }

            Messenger.Default.Register <ShowAsyncOperationTabMessage>(this,
                                                                      m =>
            {
                if (m.Show)
                {
                    this.AsyncOperationGrid.Visibility = Visibility.Visible;
                    this.MainGrid.RowDefinitions[optionsRowLocation].Height = asyncOperationTabHeight;
                }
                else
                {
                    //Store the current height and then hide the control and move the grid to auto
                    asyncOperationTabHeight            = this.MainGrid.RowDefinitions[optionsRowLocation].Height;
                    this.AsyncOperationGrid.Visibility = Visibility.Collapsed;
                    this.MainGrid.RowDefinitions[optionsRowLocation].Height = GridLength.Auto;
                }
            });

            Messenger.Default.Register <ShowCreateJobScheduleWindow>(this, (message) =>
            {
                this.genericEmptyWindow               = new GenericEmptyWindow();
                this.genericEmptyWindow.Title         = "Create Job Schedule";
                this.genericEmptyWindow.Content       = new CreateControls.CreateJobScheduleControl(new CreateJobScheduleViewModel(MainViewModel.dataProvider));
                this.genericEmptyWindow.Owner         = this;
                this.genericEmptyWindow.SizeToContent = System.Windows.SizeToContent.Height;
                this.IsEnabled = false;
                this.genericEmptyWindow.ShowDialog();
                this.IsEnabled          = true;
                this.genericEmptyWindow = null;
            });

            Messenger.Default.Register <ShowCreateJobWindow>(this, (message) =>
            {
                this.genericEmptyWindow               = new GenericEmptyWindow();
                this.genericEmptyWindow.Title         = "Create Job";
                this.genericEmptyWindow.Content       = new CreateControls.CreateJobControl(new CreateJobViewModel(MainViewModel.dataProvider));
                this.genericEmptyWindow.Owner         = this;
                this.genericEmptyWindow.SizeToContent = System.Windows.SizeToContent.Height;
                this.IsEnabled = false;
                this.genericEmptyWindow.ShowDialog();
                this.IsEnabled          = true;
                this.genericEmptyWindow = null;
            });

            Messenger.Default.Register <ShowAddTaskWindow>(this, (message) =>
            {
                this.genericEmptyWindow               = new GenericEmptyWindow();
                this.genericEmptyWindow.Title         = "Add Task";
                this.genericEmptyWindow.Content       = new CreateControls.AddTaskControl(new AddTaskViewModel(MainViewModel.dataProvider, message.JobId));
                this.genericEmptyWindow.Owner         = this;
                this.genericEmptyWindow.SizeToContent = System.Windows.SizeToContent.Height;
                this.IsEnabled = false;
                this.genericEmptyWindow.ShowDialog();
                this.IsEnabled          = true;
                this.genericEmptyWindow = null;
            });

            Messenger.Default.Register <ShowCreateComputeNodeUserWindow>(this, (message) =>
            {
                //Make sure we close the popup afterward
                Messenger.Default.Register <CloseGenericPopup>(this,
                                                               (o) =>
                {
                    this.genericEmptyWindow.Close();
                    Messenger.Default.Unregister <CloseGenericPopup>(this);
                });

                this.genericEmptyWindow               = new GenericEmptyWindow();
                this.genericEmptyWindow.Title         = "Create Compute Node User";
                this.genericEmptyWindow.Content       = new CreateControls.CreateComputeNodeUserControl(new CreateComputeNodeUserViewModel(MainViewModel.dataProvider, message.PoolId, message.ComputeNodeId));
                this.genericEmptyWindow.Owner         = this;
                this.genericEmptyWindow.SizeToContent = System.Windows.SizeToContent.Height;
                this.IsEnabled = false;
                this.genericEmptyWindow.ShowDialog();
                this.IsEnabled          = true;
                this.genericEmptyWindow = null;
            });

            Messenger.Default.Register <ShowResizePoolWindow>(this, (message) =>
            {
                //Make sure we close the popup afterward
                Messenger.Default.Register <CloseGenericPopup>(this,
                                                               (o) =>
                {
                    this.genericEmptyWindow.Close();
                    Messenger.Default.Unregister <CloseGenericPopup>(this);
                });

                this.genericEmptyWindow               = new GenericEmptyWindow();
                this.genericEmptyWindow.Title         = "Resize Pool";
                this.genericEmptyWindow.Content       = new CreateControls.ResizePoolControl(new ResizePoolViewModel(MainViewModel.dataProvider, message.PoolId, message.CurrentDedicated));
                this.genericEmptyWindow.Owner         = this;
                this.genericEmptyWindow.SizeToContent = System.Windows.SizeToContent.WidthAndHeight;
                this.IsEnabled = false;
                this.genericEmptyWindow.ShowDialog();
                this.IsEnabled          = true;
                this.genericEmptyWindow = null;
            });

            Messenger.Default.Register <ShowHeatMapMessage>(this, (message) =>
            {
                //Need to use dispatcher.Invoke because this message may be called via a non UI thread, and those threads
                //Cannot create controls/windows.  To work around this, creation of the window is run in the dispacter of the main view (this)
                this.Dispatcher.Invoke(() =>
                {
                    //Close the existing window if there is one
                    if (this.heatmapWindow != null)
                    {
                        this.heatmapWindow.Close();
                    }

                    HeatMapModel model     = new HeatMapModel(message.Pool);
                    HeatMapControl control = new HeatMapControl(new HeatMapViewModel(model));

                    this.heatmapWindow               = new GenericEmptyWindow();
                    this.heatmapWindow.Title         = "Heat map"; //TODO: All these strings should be defined in a constant class somewhere
                    this.heatmapWindow.SizeToContent = SizeToContent.WidthAndHeight;
                    this.heatmapWindow.Content       = control;
                    this.heatmapWindow.Closed       += (sender, args) => control.Cancel();
                    this.heatmapWindow.Show();
                });
            });
        }
Exemple #8
0
        public void TrafficViewEnableDisableQuerySizeScope()
        {
            using (MockContext context = MockContext.Start(this.GetType().FullName))
            {
                TrafficManagerManagementClient trafficManagerClient = this.GetTrafficManagerManagementClient(context);

                string        resourceGroupName = TrafficManagerHelper.GetPersistentResourceGroupName();
                string        profileName       = TrafficManagerHelper.GetPersistentTrafficViewProfile();
                ResourceGroup resourceGroup     = this.CreateResourceGroup(context, resourceGroupName);

                Profile profile = TrafficManagerHelper.CreateOrUpdateDefaultProfileWithExternalEndpoint(
                    trafficManagerClient,
                    resourceGroup.Name,
                    profileName);

                bool authorized = true;
                bool found      = true;
                try
                {
                    trafficManagerClient.HeatMap.Get(resourceGroupName, profileName);
                }
                catch (Microsoft.Rest.Azure.CloudException e)
                {
                    authorized = !e.Body.Code.Contains("NotAuthorized");

                    // 'NotFound' can happen if there were no queries to the endpoint since it was provisioned.
                    found = !(authorized && e.Body.Code.Contains("NotFound")); // Let's hope you were paying attention in that math logic class.
                }

                if (!found)
                {
                    // Pause, then retry once.
                    System.Threading.Thread.Sleep(TimeSpan.FromSeconds(120));
                    try
                    {
                        trafficManagerClient.HeatMap.Get(resourceGroupName, profileName);
                    }
                    catch (Microsoft.Rest.Azure.CloudException e)
                    {
                        authorized = !e.Body.Code.Contains("NotAuthorized");
                    }
                }

                Assert.False(authorized);

                // Change the enrollment status and update the profile.
                // Clear the endpoints first; those are not serializable as child objects because they have their own resource info.
                profile.TrafficViewEnrollmentStatus = "Enabled";
                profile.Endpoints = null;
                trafficManagerClient.Profiles.CreateOrUpdate(
                    resourceGroupName,
                    profileName,
                    profile);

                HeatMapModel heatMapModel = trafficManagerClient.HeatMap.Get(resourceGroupName, profileName);

                Assert.True(heatMapModel.StartTime.Value.CompareTo(System.DateTime.MinValue) > 0, "Invalid start time");
                Assert.True(heatMapModel.StartTime.Value.CompareTo(heatMapModel.EndTime.Value) <= 0, "Start time smaller than end time");
                Assert.True(heatMapModel.Endpoints.Count > 0, "Endpoint list empty, Not really an error but can not run test with no heatmap data.");
                foreach (HeatMapEndpoint ep in heatMapModel.Endpoints)
                {
                    Assert.True((ep.EndpointId ?? -1) >= 0, "Endpoint id null or out of range");
                    Assert.False(string.IsNullOrWhiteSpace(ep.ResourceId), "Resource Id undefined");
                }
                foreach (TrafficFlow tf in heatMapModel.TrafficFlows)
                {
                    Assert.False(string.IsNullOrWhiteSpace(tf.SourceIp), "SourceIp is undefined");
                    foreach (QueryExperience qe in tf.QueryExperiences)
                    {
                        Assert.True(heatMapModel.Endpoints.Where(ep => ep.EndpointId == qe.EndpointId).Count() > 0, "Query Experience does not match an existing endpoint");
                    }
                }

                IList <TrafficFlow> trafficFlowList = heatMapModel.TrafficFlows;


                foreach (TrafficFlow tf in trafficFlowList)
                {
                    if ((tf.Latitude - .1 >= -90.0) && (tf.Latitude + .1 <= 90.0) && (tf.Longitude - .1 >= -180.0) && (tf.Longitude + .1 <= 180.0))
                    {
                        heatMapModel = trafficManagerClient.HeatMap.Get(resourceGroupName, profileName, new List <double?>()
                        {
                            (tf.Latitude + .10), (tf.Longitude - .10)
                        }, new List <double?>()
                        {
                            (tf.Latitude - 0.10), (tf.Longitude + 0.10)
                        });
                        Assert.True(heatMapModel.TrafficFlows.Where(currentTF => (currentTF.Latitude == tf.Latitude && currentTF.Longitude == tf.Longitude)).Count() > 0, "Subset of coordinates not found");

                        heatMapModel = trafficManagerClient.HeatMap.Get(resourceGroupName, profileName, new List <double?>()
                        {
                            (tf.Latitude + .10), (tf.Longitude - .10)
                        }, new List <double?>()
                        {
                            (tf.Latitude + 0.05), (tf.Longitude - 0.05)
                        });
                        Assert.True(heatMapModel.TrafficFlows.Where(currentTF => (currentTF.Latitude == tf.Latitude && currentTF.Longitude == tf.Longitude)).Count() == 0, "Subset of coordinates not expected");
                    }
                }
            }
        }
Exemple #9
0
        /// <summary>
        /// Renders the specified <see cref="HeatMapModel"/>, optionally saves the output SVG
        /// </summary>
        /// <param name="model">The model.</param>
        /// <param name="filePath">The file path.</param>
        /// <returns></returns>
        public Svg.SvgDocument Render(HeatMapModel model, String filePath = "")
        {
            rangeFinder valueRange = model.DetectMinMax();

            var lColor = style.LowColor.GetColorVersionWithAlpha(style.MinOpacity);  //.ColorToHex();
            var hColor = style.HighColor.GetColorVersionWithAlpha(style.MaxOpacity); //.ColorToHex();



            ColorGradient colorGradient = new ColorGradient(lColor, hColor, ColorGradientFunction.AllAToB);


            cursorZoneSpatialSettings format = style.fieldContainer.GetFormatSetup();

            format.spatialUnit       = 8;
            format.spatialUnitHeight = 10;

            Int32 width  = (model.weight * format.width) + format.margin.right;
            Int32 height = (model.height * format.height) + format.margin.bottom;

            Svg.SvgDocument output = new Svg.SvgDocument
            {
                Width  = width,
                Height = height,
                Ppi    = 100
            };

            var mainContainer = new SvgGroup();

            output.Children.Add(mainContainer);

            //(new SvgLength(width), new SvgLength(height));

            // output.ViewBox = new SvgViewBox(-100, -100, width+100, height+100);

            var group = new SvgGroup();

            mainContainer.Children.Add(group);

            var layerTwo = new SvgGroup();

            mainContainer.Children.Add(layerTwo);

            prepareLabels(model);

            var hor = new SvgGroup();

            if (style.options.HasFlag(HeatMapRenderOptions.addHorizontalLabels))
            {
                layerTwo.Children.Add(hor);
            }

            for (int x = 0; x < model.weight; x++)
            {
                Int32 xStart = x * format.width;

                Svg.SvgText label = xLabels[x].GetSvgText(format, x, -1);

                //Svg.SvgText label = new SvgText(xLabels[x])
                //{
                //    X = (xStart + (format.width / 2) - format.margin.right).Get_px(),
                //    Y = (-format.height / 2).Get_px(),
                //    Color = new SvgColourServer(Color.Black),
                //    Font = "Gulliver"

                //};

                hor.Children.Add(label);

                var vert = new SvgGroup();
                layerTwo.Children.Add(vert);

                var vertLabels = new SvgGroup();
                var vertValues = new SvgGroup();
                var vertScale  = new SvgGroup();

                if (style.options.HasFlag(HeatMapRenderOptions.addVerticalLabels))
                {
                    vert.Children.Add(vertLabels);
                }
                if (style.options.HasFlag(HeatMapRenderOptions.addVerticalValueScale))
                {
                    vert.Children.Add(vertScale);
                }
                if (style.options.HasFlag(HeatMapRenderOptions.addVerticalValueScale))
                {
                    vert.Children.Add(vertValues);
                }

                for (int y = 0; y < model.height; y++)
                {
                    Int32 yStart = y * format.height;

                    if (x == 0)
                    {
                        Double ratio        = valueRange.GetPositionInRange(y); //model.GetRatioForScale(y, style.minimalOpacity, model.height); //(1+ style.minimalOpacity).GetRatio(y+1);
                        Double scaleFactor2 = ratio;
                        if (!style.options.HasFlag(HeatMapRenderOptions.resizeFields))
                        {
                            scaleFactor2 = 1;
                        }

                        if (ratio > 1)
                        {
                            ratio = 1;
                        }
                        var lbl2 = format.GetRectangle((-format.width * 2), yStart, colorGradient.GetColor(ratio), Convert.ToSingle(ratio), scaleFactor2);
                        vertScale.Children.Add(lbl2);

                        Svg.SvgText label2 = yLabels[y].GetSvgText(format, -1, y);
                        vertLabels.Children.Add(label2);

                        //Svg.SvgText label = xLabels[x].GetSvgText(format, x, -1);

                        //Svg.SvgText label2 = new SvgText(yLabels[y])
                        //{
                        //    X = (format.margin.left - format.width).Get_px(),
                        //    Y = (yStart+(format.height / 2)).Get_px(),
                        //    Color = new SvgColourServer(Color.Black),

                        //    Font = "Gulliver"
                        //};

                        Int32 xp = Convert.ToInt32((-Convert.ToDouble(format.width) * 2.5) + format.margin.left);

                        //Double vl = (1.GetRatio(y + 1)) * model.ranger.Maximum;

                        Double vl = model.GetValueForScaleY(y);

                        Svg.SvgText value = vl.ToString(style.valueFormat).GetSvgText(format, -3, y);

                        //Svg.SvgText value = new SvgText()
                        //{
                        //    X = (xp- format.margin.right).Get_px(),
                        //    Y = (yStart + (format.height / 2) ).Get_px(),
                        //    Fill = new SvgColourServer(Color.Black),
                        //   // Color = new SvgColourServer(Color.White),
                        //    Font = "Gulliver"
                        //};

                        vertValues.Children.Add(value);
                    }

                    Double val  = valueRange.GetPositionInRange(model[x, y]); // model.GetRatioValue(x, y, style.minimalOpacity);
                    Color  valC = colorGradient.GetColor(val);


                    Double scaleFactor = val;

                    if (!style.options.HasFlag(HeatMapRenderOptions.resizeFields))
                    {
                        scaleFactor = 1;
                    }
                    var rct = format.GetRectangle(xStart, yStart, valC, Convert.ToSingle(val), scaleFactor);

                    group.Children.Add(rct);
                }
            }

            if (!filePath.isNullOrEmpty())
            {
                if (!filePath.EndsWith(".svg", true, CultureInfo.CurrentCulture))
                {
                    filePath += ".svg";
                }


                output.Save(filePath);

                //  throw new NotImplementedException();

                /* var code = output.GetXML();  //Encoding.UTF8.GetString(stream.GetBuffer());
                 *
                 */
            }

            return(output);
        }
Exemple #10
0
        /// <summary>
        /// Renders the heat map and saves the output to <c>filePath</c>. This is void alias to <see cref="Render"/>
        /// </summary>
        /// <param name="model">The model.</param>
        /// <param name="filePath">The file path.</param>
        public Svg.SvgDocument RenderAndSave(HeatMapModel model, String filePath)
        {
            Svg.SvgDocument output = Render(model, filePath);

            return(output);
        }