private GraphXAxisRootDto GetRoot(DimensionTree allDimensionsTree, DimensionDto xDimension, Measure measure,
                                          IEnumerable <DimensionValueDto> filteredXValues, List <FlatDimensionDto> filters,
                                          DimensionValueDto xValue = null, DimensionDto legendDimension = null)
        {
            GraphXAxisRootDto xAxisRoot;

            if (legendDimension == null)
            {
                xAxisRoot = new DrilldownGraphXAxisRootDto
                {
                    Id          = xValue?.Id ?? 0,
                    Name        = xValue?.Value ?? string.Empty,
                    XAxisLeaves = new List <GraphXAxisLeafDto>()
                };
                var leaf = GetLeaf(allDimensionsTree, xDimension, xValue, measure, filters);
                xAxisRoot.XAxisLeaves.Add(leaf);
            }
            else
            {
                xAxisRoot = new GroupedGraphXAxisRootDto
                {
                    Id          = xValue?.Id ?? 0,
                    Name        = xValue?.Value ?? string.Empty,
                    XAxisLeaves = new List <GraphXAxisLeafDto>()
                };
                foreach (var dimValue in filteredXValues)
                {
                    var leaf = GetLeaf(allDimensionsTree, xDimension, dimValue, measure, filters, legendDimension);
                    xAxisRoot.XAxisLeaves.Add(leaf);
                }
            }

            return(xAxisRoot);
        }
        private GraphXAxisRootDto GetParentRoot(DimensionTree allDimensionsTree, TreeDimensionDto childDimension,
                                                Measure measure, DimensionValueDto xValue, List <FlatDimensionDto> filters, DimensionDto legendDimension = null)
        {
            GraphXAxisRootDto xAxisRoot;

            if (legendDimension == null)
            {
                xAxisRoot = new DrilldownGraphXAxisRootDto
                {
                    Id          = xValue.Id,
                    Name        = xValue.Value,
                    XAxisLeaves = new List <GraphXAxisLeafDto>()
                };
            }
            else
            {
                xAxisRoot = new GroupedGraphXAxisRootDto
                {
                    Id          = xValue.Id,
                    Name        = xValue.Value,
                    XAxisLeaves = new List <GraphXAxisLeafDto>()
                };
            }
            var parentDimension = allDimensionsTree.GetDimensionDto((int)childDimension.ParentId);
            var xDimValues      = _querier.GetValuesOfDimension(
                parentDimension, new Column {
                Name = childDimension.IdName, Value = xValue.Id.ToString()
            });
            var filteredValues = GetFilteredValues(allDimensionsTree, parentDimension, filters, xDimValues);

            foreach (var dimValue in filteredValues)
            {
                var leaf = GetLeaf(allDimensionsTree, allDimensionsTree.GetDimensionDto((int)childDimension.ParentId), dimValue, measure, filters, legendDimension);
                xAxisRoot.XAxisLeaves.Add(leaf);
            }
            return(xAxisRoot);
        }
        private GraphXAxisLeafDto GetLeaf(DimensionTree allDimensionsTree, DimensionDto xDimension, DimensionValueDto xValue, Measure measure,
                                          List <FlatDimensionDto> filters, DimensionDto legendDimension = null)
        {
            if (legendDimension == null)
            {
                var conditionDto = new FlatDimensionDto
                {
                    Id              = xDimension.Id,
                    DatasetName     = xDimension.DatasetName,
                    Name            = xDimension.Name,
                    DimensionValues = new List <DimensionValueDto> {
                        new DimensionValueDto {
                            Id = xValue.Id
                        }
                    }
                };
                return(new DrilldownGraphXAxisLeafDto
                {
                    Id = xValue.Id,
                    Name = xValue.Value,
                    Value = _querier.GetFactTableSum(allDimensionsTree,
                                                     filters, new[] { conditionDto }.ToList(), measure)
                });
            }
            var leaf = new GroupedGraphXAxisLeafDto
            {
                Id           = xValue.Id,
                Name         = xValue.Value,
                LegendValues = new List <GraphLegendValueDto>()
            };
            var legendFilteredValues = GetFilteredValues(allDimensionsTree, legendDimension, filters, legendDimension.DimensionValues);

            foreach (var legendValue in legendFilteredValues)
            {
                var xDimensionDto = new FlatDimensionDto
                {
                    Id              = xDimension.Id,
                    DatasetName     = xDimension.DatasetName,
                    Name            = xDimension.Name,
                    DimensionValues = new[] { new DimensionValueDto {
                                                  Id = xValue.Id
                                              } }.ToList()
                };
                var legendDimensionDto = new FlatDimensionDto
                {
                    Id              = legendDimension.Id,
                    DatasetName     = legendDimension.DatasetName,
                    Name            = legendDimension.Name,
                    DimensionValues = new[] { new DimensionValueDto {
                                                  Id = legendValue.Id
                                              } }.ToList()
                };
                leaf.LegendValues.Add(new GraphLegendValueDto
                {
                    Legend = new GraphLegendDto
                    {
                        Id   = legendValue.Id,
                        Name = legendValue.Value
                    },
                    Value = _querier.GetFactTableSum(allDimensionsTree, filters, new[] { xDimensionDto, legendDimensionDto }.ToList(), measure)
                });
            }
            return(leaf);
        }