private int CompareXDimensionsWithSeries(ResultCell[] a, ResultCell[] b)
        {
            ResultSerieValue va = _serieForSort.Values.FirstOrDefault(i => i.XDimensionValues == a);
            ResultSerieValue vb = _serieForSort.Values.FirstOrDefault(i => i.XDimensionValues == b);

            if (va != null && vb != null)
            {
                return((_serieForSort.Element.SerieSortOrder == PointSortOrder.Ascending ? 1 : -1) * CompareResultSerieValues(va, vb));
            }
            return(0);
        }
 private static int CompareResultSerieValues(ResultSerieValue a, ResultSerieValue b)
 {
     if (a.Yvalue.Element.IsNumeric && a.Yvalue.DoubleValue != null && b.Yvalue.DoubleValue != null)
     {
         return(a.Yvalue.DoubleValue.Value.CompareTo(b.Yvalue.DoubleValue.Value));
     }
     if (a.Yvalue.Element.IsDateTime && a.Yvalue.DateTimeValue != null && b.Yvalue.DateTimeValue != null)
     {
         return(a.Yvalue.DateTimeValue.Value.CompareTo(b.Yvalue.DateTimeValue.Value));
     }
     return(0);
 }
        private void buildSeries(ReportModel model)
        {
            foreach (ResultPage page in model.Pages)
            {
                if (Report.Cancel) break;

                foreach (List<ResultData> datas in page.Datas.Values)
                {
                    if (Report.Cancel) break;

                    foreach (ResultData data in datas)
                    {
                        if (Report.Cancel) break;

                        ResultCell[] xPrimaryDimensions = GetXSerieCells(AxisType.Primary, data.Row, data.Column, model);
                        int primaryIndex = FindDimension(xPrimaryDimensions, page.PrimaryXDimensions);
                        xPrimaryDimensions = page.PrimaryXDimensions[primaryIndex];
                        ResultCell[] xSecondaryDimensions = GetXSerieCells(AxisType.Secondary, data.Row, data.Column, model);
                        int secondaryIndex = FindDimension(xSecondaryDimensions, page.SecondaryXDimensions);
                        xSecondaryDimensions = page.SecondaryXDimensions[secondaryIndex];

                        string primarySplitterValues = Helper.ConcatCellValues(GetSplitterSerieCells(AxisType.Primary, data.Row, data.Column, model), ",");
                        string secondarySplitterValues = Helper.ConcatCellValues(GetSplitterSerieCells(AxisType.Secondary, data.Row, data.Column, model), ",");

                        foreach ( var dataCell in data.Data.Where(i => i.Element.IsSerie))
                        {
                            var serieElement = dataCell.Element;
                            ResultCell[] xValues = (serieElement.XAxisType == AxisType.Primary ? xPrimaryDimensions : xSecondaryDimensions);
                            string splitterValue = (serieElement.XAxisType == AxisType.Primary ? primarySplitterValues : secondarySplitterValues);
                            ResultSerie serie = page.Series.FirstOrDefault(i => i.Element == serieElement && i.SplitterValues == splitterValue);
                            if (serie == null)
                            {
                                serie = new ResultSerie() { Element = serieElement, SplitterValues = splitterValue };
                                page.Series.Add(serie);
                            }

                            ResultSerieValue serieValue = serie.Values.FirstOrDefault(i => i.XDimensionValues == xValues);
                            if (serieValue == null)
                            {
                                serieValue = new ResultSerieValue() { XDimensionValues = xValues };
                                serieValue.Yvalue = new ResultTotalCell() { Element = serieElement, IsSerie = true };
                                serie.Values.Add(serieValue);
                            }
                            serieValue.Yvalue.Cells.Add(new ResultCell() { Element = serieElement, Value = dataCell.Value, ContextRow = dataCell.ContextRow, ContextCol = dataCell.ContextCol });
                        }
                    }
                }
            }

            //Calculate the serie values
            foreach (ResultPage page in model.Pages)
            {
                if (Report.Cancel) break;
                foreach (var serie in page.Series)
                {
                    foreach (var serieValue in serie.Values)
                    {
                        //Classic calculation
                        serieValue.Yvalue.Calculate();
                        if (!string.IsNullOrEmpty(serieValue.Yvalue.Element.CellScript))
                        {
                            //Cell script option
                            serieValue.Yvalue.ProcessContext();
                            serieValue.Yvalue.ContextTable = page.DataTable;
                            serieValue.Yvalue.ContextPage = page;
                            serieValue.Yvalue.ContextModel = model;
                            executeCellScript(serieValue.Yvalue);
                        }
                    }
                }
            }
        }
Exemple #4
0
 private static int CompareResultSerieValues(ResultSerieValue a, ResultSerieValue b)
 {
     if (a.Yvalue.Element.IsNumeric && a.Yvalue.DoubleValue != null && b.Yvalue.DoubleValue != null) return a.Yvalue.DoubleValue.Value.CompareTo(b.Yvalue.DoubleValue.Value);
     if (a.Yvalue.Element.IsDateTime && a.Yvalue.DateTimeValue != null && b.Yvalue.DateTimeValue != null) return a.Yvalue.DateTimeValue.Value.CompareTo(b.Yvalue.DateTimeValue.Value);
     return 0;
 }
        private void buildChartSeries(ResultPage page)
        {
            if (page.ChartInitDone)
            {
                return;
            }

            initAxisProperties(page, page.PrimaryXDimensions);
            //Sort series if necessary, only one serie is used for sorting...
            if (!Model.ExecChartIsNumericAxis && !Model.ExecChartIsDateTimeAxis)
            {
                _serieForSort = page.Series.FirstOrDefault(i => i.Element.SerieSortType != SerieSortType.None);
                if (_serieForSort != null)
                {
                    if (_serieForSort.Element.SerieSortType == SerieSortType.Y)
                    {
                        page.PrimaryXDimensions.Sort(CompareXDimensionsWithSeries);
                    }
                    else
                    {
                        page.PrimaryXDimensions.Sort(CompareXDimensionsWithAxis);
                    }
                }
            }
            initChartXValues(page);

            page.AxisXLabelMaxLen     = 10;
            page.AxisYPrimaryMaxLen   = 6;
            page.AxisYSecondaryMaxLen = 6;

            StringBuilder result = new StringBuilder(), navs = new StringBuilder();

            // TOCHECK ?    if (!Model.ExecChartIsNumericAxis && !Model.ExecChartIsDateTimeAxis)
            //     {
            //Build X labels
            foreach (var key in page.PrimaryXValues.Keys)
            {
                ResultCell[] dimensions = key as ResultCell[];
                if (result.Length != 0)
                {
                    result.Append(",");
                }
                var xval = (dimensions.Length == 1 ? dimensions[0].DisplayValue : page.PrimaryXValues[key].ToString());
                result.Append(Helper.QuoteSingle(HttpUtility.JavaScriptStringEncode(xval)));
                if (xval.Length > page.AxisXLabelMaxLen)
                {
                    page.AxisXLabelMaxLen = xval.Length;
                }

                var navigation = Model.GetNavigation(((ResultCell[])key)[0]);
                if (!string.IsNullOrEmpty(navigation))
                {
                    if (navs.Length != 0)
                    {
                        navs.Append(",");
                    }
                    navs.Append(navigation);
                }
            }

            page.ChartXLabels     = result.ToString();
            page.ChartNavigations = navs.ToString();
            //   }

            foreach (ResultSerie resultSerie in page.Series)
            {
                if (Report.Cancel)
                {
                    break;
                }

                if (string.IsNullOrEmpty(Model.ExecD3PrimaryYAxisFormat) && resultSerie.Element.YAxisType == AxisType.Primary)
                {
                    Model.ExecD3PrimaryYAxisFormat   = resultSerie.Element.GetD3Format(CultureInfo, Model.ExecNVD3ChartType);
                    Model.ExecAxisPrimaryYIsDateTime = resultSerie.Element.IsDateTime;
                }
                else if (string.IsNullOrEmpty(Model.ExecD3SecondaryYAxisFormat) && resultSerie.Element.YAxisType == AxisType.Secondary)
                {
                    Model.ExecD3SecondaryYAxisFormat   = resultSerie.Element.GetD3Format(CultureInfo, Model.ExecNVD3ChartType);
                    Model.ExecAxisSecondaryYIsDateTime = resultSerie.Element.IsDateTime;
                }
                //Fill Serie
                StringBuilder chartXResult = new StringBuilder(), chartXDateTimeResult = new StringBuilder(), chartYResult = new StringBuilder();
                StringBuilder chartXYResult = new StringBuilder(), chartYDisplayResult = new StringBuilder();
                int           index = 0;
                foreach (var xDimensionKey in page.PrimaryXValues.Keys)
                {
                    string   xValue   = (index++).ToString(CultureInfo.InvariantCulture.NumberFormat);
                    DateTime xValueDT = DateTime.MinValue;

                    //Find the corresponding serie value...
                    ResultSerieValue value  = resultSerie.Values.FirstOrDefault(i => i.XDimensionValues == xDimensionKey);
                    object           yValue = (value != null ? value.Yvalue.Value : null);
                    if (resultSerie.Element.YAxisType == AxisType.Primary && value != null && value.Yvalue.DisplayValue.Length > page.AxisYPrimaryMaxLen)
                    {
                        page.AxisYPrimaryMaxLen = value.Yvalue.DisplayValue.Length;
                    }
                    if (resultSerie.Element.YAxisType == AxisType.Secondary && value != null && value.Yvalue.DisplayValue.Length > page.AxisYSecondaryMaxLen)
                    {
                        page.AxisYSecondaryMaxLen = value.Yvalue.DisplayValue.Length;
                    }

                    if (Model.ExecChartIsNumericAxis)
                    {
                        Double db = 0;
                        if (value == null)
                        {
                            Double.TryParse(page.PrimaryXValues[xDimensionKey].ToString(), out db);
                        }
                        else if (value.XDimensionValues[0].DoubleValue != null)
                        {
                            db = value.XDimensionValues[0].DoubleValue.Value;
                        }
                        xValue = db.ToString(CultureInfo.InvariantCulture.NumberFormat);
                    }
                    else if (Model.ExecChartIsDateTimeAxis)
                    {
                        DateTime dt = new DateTime(1970, 1, 1, 0, 0, 0, 0);
                        if (value == null)
                        {
                            dt = ((DateTime)page.PrimaryXValues[xDimensionKey]);
                        }
                        else if (value.XDimensionValues[0].DateTimeValue != null)
                        {
                            dt = value.XDimensionValues[0].DateTimeValue.Value;
                        }
                        xValueDT = dt;
                        TimeSpan diff = dt.ToUniversalTime() - (new DateTime(1970, 1, 1, 0, 0, 0, 0));
                        xValue = string.Format("{0}000", Math.Floor(diff.TotalSeconds));
                    }

                    if (yValue is DateTime)
                    {
                        TimeSpan diff = ((DateTime)yValue).ToUniversalTime() - (new DateTime(1970, 1, 1, 0, 0, 0, 0));
                        yValue = string.Format("{0}000", Math.Floor(diff.TotalSeconds));
                    }
                    else if (yValue is Double)
                    {
                        yValue = ((Double)yValue).ToString(CultureInfo.InvariantCulture.NumberFormat);
                    }

                    if (yValue == null && GetBoolValue(Parameter.NVD3AddNullPointParameter))
                    {
                        yValue = "0";
                    }
                    if (yValue != null)
                    {
                        if (chartXYResult.Length != 0)
                        {
                            chartXYResult.Append(",");
                        }
                        chartXYResult.AppendFormat("{{x:{0},y:{1}}}", xValue, yValue);

                        if (chartXResult.Length != 0)
                        {
                            chartXResult.Append(",");
                        }
                        chartXResult.AppendFormat("{0}", xValue);

                        if (Model.ExecChartIsDateTimeAxis)
                        {
                            if (chartXDateTimeResult.Length != 0)
                            {
                                chartXDateTimeResult.Append(",");
                            }
                            chartXDateTimeResult.AppendFormat("\"{0:yyyy-MM-dd HH:mm:ss}\"", xValueDT);
                        }

                        if (chartYResult.Length != 0)
                        {
                            chartYResult.Append(",");
                        }
                        chartYResult.AppendFormat("{0}", yValue);

                        //? if (chartYDisplayResult.Length != 0) chartYDisplayResult.Append(",");
                        //? chartYDisplayResult.AppendFormat("'{0}'", Helper.ToJS(value.Yvalue.DisplayValue));
                    }
                }
                resultSerie.ChartXYSerieValues        = chartXYResult.ToString();
                resultSerie.ChartXSerieValues         = chartXResult.ToString();
                resultSerie.ChartXDateTimeSerieValues = chartXDateTimeResult.ToString();
                resultSerie.ChartYSerieValues         = chartYResult.ToString();
                //?resultSerie.ChartYSerieDisplayValues = chartYDisplayResult.ToString();
            }
            page.ChartInitDone = true;
        }