public async Task <Visualization> VisualizeBarplot <R, T>(BarplotRequest <R, T> request)
        {
            var message = string.Empty;
            var json    = JsonConvert.SerializeObject(request);
            var uri     = $"{_baseUrl}/api/common-charts/barplot";

            for (var i = 0; i < MAX_RETRY; i++)
            {
                var client   = GetClient();
                var content  = new StringContent(json, Encoding.UTF8, "application/json");
                var response = await client.PostAsync(uri, content);

                if (response.IsSuccessStatusCode)
                {
                    var svg = await response.Content.ReadAsStringAsync();

                    return(new Visualization
                    {
                        Type = VisualizationType.Barplot,
                        SvgImage = svg
                    });
                }
                else
                {
                    message = await HandleError(response);
                }
            }

            throw new ArgumentException(message);
        }
        private async Task <Visualization> GetVisualizationFromAnalysis(Analysis analysis, VisualizationType type)
        {
            var viz = analysis.Visualizations.FirstOrDefault(a => a.Type == type);

            if (viz is null)
            {
                if (type.IsMultiLayer())
                {
                    if (type == VisualizationType.MultiLayer_Diagonal || type == VisualizationType.MultiLayer_Slices)
                    {
                        viz = analysis.Request.DataSet.Visualizations.FirstOrDefault(v => v.Type == type);

                        if (viz is null)
                        {
                            viz = await VisualizeMultilayer(new MultilayerRequest
                            {
                                EdgeList = analysis.Request.DataSet.EdgeList,
                                Type     = type
                            });

                            analysis.Request.DataSet.Visualizations.Add(viz);
                        }
                    }
                    else
                    {
                        viz = await VisualizeMultilayer(new MultilayerRequest
                        {
                            EdgeList = analysis.Request.DataSet.EdgeList,
                            Type     = type
                        });
                    }
                }
                else if (type.IsMultiLayerCommunities())
                {
                    var request = new MultilayerCommunitiesRequest
                    {
                        EdgeList      = analysis.Request.DataSet.EdgeList,
                        CommunityList = analysis.Result.CommunityList,
                        Type          = type
                    };
                    viz = await VisualizeMultilayerCommunities(request);
                }
                else if (type.IsSingleLayer())
                {
                    viz = await VisualizeSingleLayer(new SingleLayerRequest
                    {
                        EdgeList = analysis.Result.AnalyzedNetworkEdgeList,
                        Type     = type
                    });
                }
                else if (type.IsSingleLayerCommunities())
                {
                    viz = await VisualizeSingleLayerCommunity(new SingleLayerCommunityRequest
                    {
                        EdgeList      = analysis.Result.AnalyzedNetworkEdgeList,
                        CommunityList = analysis.Result.CommunityList,
                        Type          = type
                    });
                }
                else if (type == VisualizationType.Barplot)
                {
                    var communities = analysis.Result.ActorToCommunity.Values
                                      .Distinct()
                                      .OrderBy(c => c);
                    var communitiesCount = communities
                                           .Select(c => analysis.Result.ActorToCommunity.Where(a => a.Value == c).Count());
                    var request = new BarplotRequest <int, int>
                    {
                        X      = communities,
                        Y      = communitiesCount,
                        Labels = communities.Select(c => "C" + c),
                        XLabel = "Community",
                        YLabel = "Actor Count",
                        Params = new BarplotRequestParameters
                        {
                            ColorCommunities = true
                        }
                    };
                    viz = await VisualizeBarplot(request);

                    viz.Title = "Communities Count - Barplot";
                }
                else if (type == VisualizationType.Treemap)
                {
                    var communities = analysis.Result.ActorToCommunity.Values
                                      .Distinct()
                                      .OrderByDescending(c => c);
                    var communitiesCount = communities
                                           .Select(c => analysis.Result.ActorToCommunity.Where(a => a.Value == c)
                                                   .Count());
                    var request = new TreemapRequest <int>
                    {
                        Label = communities.Select(c => "C" + c),
                        Sizes = communitiesCount,
                        Type  = type
                    };
                    viz = await VisualizeTreemap(request);

                    viz.Title = "Communities Count - Treemap";
                }
                else if (type == VisualizationType.MultiLayer_Slices)
                {
                    var request = new MultilayerRequest
                    {
                        EdgeList = analysis.Request.DataSet.EdgeList,
                        Type     = type
                    };
                    viz = await VisualizeMultilayer(request);
                }
                else if (type == VisualizationType.MultiLayer_Slices_Communities)
                {
                    var request = new MultilayerCommunitiesRequest
                    {
                        EdgeList      = analysis.Request.DataSet.EdgeList,
                        CommunityList = analysis.Result.CommunityList,
                        Type          = type
                    };
                    viz = await VisualizeMultilayerCommunities(request);
                }

                if (type != VisualizationType.MultiLayer_Diagonal && type != VisualizationType.MultiLayer_Slices)
                {
                    analysis.Visualizations.Add(viz);
                }

                await _ctx.SaveChangesAsync();
            }
            return(viz);
        }