Beispiel #1
0
        private void CalculateStackingValues()
        {
            Area.StackedValues = new Dictionary <object, StackingValues>();
            var stackingSeries = from series in Area.VisibleSeries
                                 where series is StackingSeriesBase && series.ActualYAxis != null && series.ActualXAxis != null
                                 select series;

            foreach (var series in stackingSeries)
            {
                // To split the series into groups according to their labels.
                var seriesGroups =
                    from seriesGroup in series.ActualYAxis.RegisteredSeries.Intersect(series.ActualXAxis.RegisteredSeries).ToList()
                    where seriesGroup is StackingSeriesBase
                    group seriesGroup by(seriesGroup as StackingSeriesBase).GroupingLabel into groups
                    select new { GroupingPath = groups.Key, Series = groups };

                foreach (var label in seriesGroups)
                {
                    int  i             = 0;
                    var  lastValPos    = new List <double>();
                    var  lastXValPos   = new List <double>();
                    var  lastValNeg    = new List <double>();
                    bool reCalculation = true;

                    foreach (ChartSeriesBase chartSeries in label.Series)
                    {
                        if (!(chartSeries is StackingSeriesBase))
                        {
                            continue;
                        }
                        if (!chartSeries.IsSeriesVisible)
                        {
                            continue;
                        }
                        if (((StackingSeriesBase)chartSeries).stackValueCalculated)
                        {
                            break;
                        }

                        var values = new StackingValues();
                        values.StartValues = new List <double>();
                        values.EndValues   = new List <double>();
                        IList <double> yValues;
                        yValues = ((XyDataSeries)chartSeries).YValues;
                        List <double> xValues = ((XyDataSeries)chartSeries).GetXValues();
                        if (chartSeries.ActualXAxis is CategoryAxis && !(chartSeries.ActualXAxis as CategoryAxis).IsIndexed)
                        {
                            if (!(chartSeries is StackingColumn100Series) && !(chartSeries is StackingBar100Series) &&
                                !(chartSeries is StackingAreaSeries) && !(chartSeries is StackingArea100Series))
                            {
                                chartSeries.GroupedActualData.Clear();
                                List <double> seriesYValues = new List <double>();
                                for (int m = 0; m < chartSeries.DistinctValuesIndexes.Count; m++)
                                {
                                    if (chartSeries.DistinctValuesIndexes[m].Count > 0)
                                    {
                                        var list = (from index in chartSeries.DistinctValuesIndexes[m]
                                                    where chartSeries.GroupedSeriesYValues[0].Count > index
                                                    select new List <double> {
                                            chartSeries.GroupedSeriesYValues[0][index], index
                                        }).
                                                   OrderByDescending(val => val[0]).ToList();
                                        for (int n = 0; n < list.Count; n++)
                                        {
                                            var yValue = list[n][0];
                                            seriesYValues.Add(yValue);
                                            chartSeries.DistinctValuesIndexes[m][n] = (int)list[n][1];
                                            chartSeries.GroupedActualData.Add(chartSeries.ActualData[(int)list[n][1]]);
                                        }
                                    }
                                }

                                yValues = seriesYValues;
                            }
                            else
                            {
                                yValues = chartSeries.GroupedSeriesYValues[0];
                                chartSeries.GroupedActualData.AddRange(chartSeries.ActualData);
                            }
                        }

                        double origin = ActualXAxis != null ? ActualXAxis.Origin : 0; // Setting origin value for stacking segment

                        int j = 0;
                        if (ActualXAxis != null && ActualXAxis.Origin == 0 && ActualYAxis is LogarithmicAxis &&
                            (ActualYAxis as LogarithmicAxis).Minimum != null)
                        {
                            origin = (double)(ActualYAxis as LogarithmicAxis).Minimum;
                        }

                        foreach (double yValue in yValues)
                        {
                            double lastValue    = 0;
                            double currentValue = yValue;

                            if (lastValPos.Count <= j)
                            {
                                lastValPos.Add(0);
                            }
                            if (lastValNeg.Count <= j)
                            {
                                lastValNeg.Add(0);
                            }
                            if (lastXValPos.Count <= j)
                            {
                                lastXValPos.Add(0);
                            }

                            if (values.StartValues.Count <= j)
                            {
                                values.StartValues.Add(0);
                                values.EndValues.Add(0);
                            }

                            bool checkXValues = false;
                            int  xPlotIndex   = 0;

                            for (int k = 0; k < lastXValPos.Count; k++)
                            {
                                if (xValues.Count > j)
                                {
                                    if (lastXValPos[k] == xValues[j])
                                    {
                                        xPlotIndex   = k;
                                        checkXValues = true;
                                        break;
                                    }
                                }
                            }

                            if (checkXValues)
                            {
                                if (currentValue >= 0)
                                {
                                    lastValue = lastValPos[xPlotIndex];
                                    if (chartSeries.GetType().Name.Contains("Stacking") && chartSeries.GetType().Name.Contains("100Series"))
                                    {
                                        currentValue = Area.GetPercentage((label.Series as IList <ISupportAxes>), currentValue, j, reCalculation);
                                    }
                                    if (!double.IsNaN(lastValPos[xPlotIndex]))
                                    {
                                        lastValPos[xPlotIndex] += currentValue;
                                    }
                                    else
                                    {
                                        lastValPos[xPlotIndex] = currentValue;
                                    }
                                }
                                else
                                {
                                    lastValue = lastValNeg[xPlotIndex];
                                    if (chartSeries.GetType().Name.Contains("Stacking") && chartSeries.GetType().Name.Contains("100Series"))
                                    {
                                        currentValue = Area.GetPercentage((label.Series as IList <ISupportAxes>), currentValue, j, reCalculation);
                                    }
                                    if (!double.IsNaN(lastValPos[xPlotIndex]))
                                    {
                                        if (!double.IsNaN(currentValue))
                                        {
                                            lastValNeg[xPlotIndex] += currentValue;
                                        }
                                    }
                                    else
                                    {
                                        lastValNeg[xPlotIndex] = currentValue;
                                    }
                                }
                            }
                            else
                            {
                                if (currentValue >= 0)
                                {
                                    if (chartSeries.GetType().Name.Contains("Stacking") && chartSeries.GetType().Name.Contains("100Series"))
                                    {
                                        currentValue = Area.GetPercentage((label.Series as IList <ISupportAxes>), currentValue, j, reCalculation);
                                    }
                                    lastValPos.Add(currentValue);
                                    lastValNeg.Add(0);
                                }
                                else
                                {
                                    if (chartSeries.GetType().Name.Contains("Stacking") && chartSeries.GetType().Name.Contains("100Series"))
                                    {
                                        currentValue = Area.GetPercentage((label.Series as IList <ISupportAxes>), currentValue, j, reCalculation);
                                    }
                                    lastValPos.Add(double.IsNaN(currentValue) ? currentValue : 0);
                                    lastValNeg.Add(currentValue);
                                }

                                if (xValues.Count > j)
                                {
                                    lastXValPos.Add(xValues[j]);
                                }
                            }

                            values.StartValues[j] = (i == 0 || lastValue < origin) ? origin : lastValue;           // Setting origin value for stacking segment
                            values.EndValues[j]   = currentValue + (double.IsNaN(lastValue) ? origin : lastValue); // Included condition for Empty point support

                            if (values.EndValues[j] < lastValue)
                            {
                                values.StartValues[j] = lastValue + origin;
                            }

                            if (chartSeries.GetType().Name.Contains("Stacking") && chartSeries.GetType().Name.Contains("100Series") && values.EndValues[j] > 100)
                            {
                                values.EndValues[j] = 100;
                            }
                            j++;
                        }

                        i++;

                        // WP-824 - We add Stacked Values when both start & end values are calculated
                        if (values.StartValues.Count > 0 && values.EndValues.Count > 0)
                        {
                            Area.StackedValues.Add(chartSeries, values);
                            ((StackingSeriesBase)chartSeries).stackValueCalculated = true;
                        }

                        reCalculation = false;
                    }
                }
            }

            foreach (ChartSeriesBase chartSeries in stackingSeries)
            {
                var stackingSeriesBase = chartSeries as StackingSeriesBase;

                if (stackingSeriesBase != null)
                {
                    stackingSeriesBase.stackValueCalculated = false;
                }
            }
        }
Beispiel #2
0
        private void CalculateStackingValues()
        {
            Area.StackedValues = new Dictionary <object, StackingValues>();
            var stackingSeries = from series in Area.VisibleSeries
                                 where series is StackingSeriesBase3D
                                 select series;

            var enumerable = stackingSeries as ChartSeriesBase[] ?? stackingSeries.ToArray();
            var i          = 0;

            foreach (var series in enumerable)
            {
                // To split the series into groups according to their labels.
                var seriesGroups =
                    from seriesGroup in series.ActualYAxis.RegisteredSeries
                    where seriesGroup is StackingSeriesBase3D && (seriesGroup as StackingSeriesBase3D).IsSeriesVisible
                    group seriesGroup by(seriesGroup as StackingSeriesBase3D).GroupingLabel into groups
                    select new { GroupingPath = groups.Key, Series = groups };
                foreach (var label in seriesGroups)
                {
                    bool reCalculation   = true;
                    var  lastValPosition = new List <double>();
                    var  lastValNeg      = new List <double>();
                    bool isFirstSeries   = true;
                    foreach (ChartSeriesBase chartSeries in label.Series)
                    {
                        if (!(chartSeries is StackingSeriesBase3D))
                        {
                            continue;
                        }

                        if (!chartSeries.IsSeriesVisible)
                        {
                            continue;
                        }

                        if (((StackingSeriesBase3D)chartSeries).StackValueCalculated)
                        {
                            break;
                        }

                        IList <double> yValues;
                        var            values = new StackingValues {
                            StartValues = new List <double>(), EndValues = new List <double>()
                        };
                        yValues = ((XyDataSeries3D)chartSeries).YValues;
                        if (chartSeries.ActualXAxis is CategoryAxis3D && !(chartSeries.ActualXAxis as CategoryAxis3D).IsIndexed)
                        {
                            if (!(chartSeries is StackingColumn100Series3D) && !(chartSeries is StackingBar100Series3D))
                            {
                                chartSeries.GroupedActualData.Clear();
                                List <double> seriesYValues = new List <double>();

                                for (int m = 0; m < chartSeries.DistinctValuesIndexes.Count; m++)
                                {
                                    var list = (from index in chartSeries.DistinctValuesIndexes[m]
                                                select new List <double> {
                                        chartSeries.GroupedSeriesYValues[0][index], index
                                    }).ToList();

                                    for (int n = 0; n < chartSeries.DistinctValuesIndexes[m].Count; n++)
                                    {
                                        var yValue = list[n][0];
                                        seriesYValues.Add(yValue);
                                        chartSeries.GroupedActualData.Add(this.ActualData[(int)list[n][1]]);
                                    }
                                }

                                yValues = seriesYValues;
                            }
                            else
                            {
                                yValues = chartSeries.GroupedSeriesYValues[0];
                                chartSeries.GroupedActualData.AddRange(chartSeries.ActualData);
                            }
                        }

                        double origin = ActualXAxis != null ? ActualXAxis.Origin : 0; // setting origin value for stacking segment

                        var j = 0;
                        if (this.ActualXAxis != null && ActualXAxis.Origin == 0 && ActualYAxis is LogarithmicAxis &&
                            (ActualYAxis as LogarithmicAxis).Minimum != null)
                        {
                            origin = (double)(ActualYAxis as LogarithmicAxis).Minimum;
                        }

                        foreach (var yValue in yValues)
                        {
                            double lastValue;
                            var    currentValue = yValue;

                            if (lastValPosition.Count <= j)
                            {
                                lastValPosition.Add(0);
                            }

                            if (lastValNeg.Count <= j)
                            {
                                lastValNeg.Add(0);
                            }

                            if (values.StartValues.Count <= j)
                            {
                                values.StartValues.Add(0);
                                values.EndValues.Add(0);
                            }

                            if (currentValue >= 0)
                            {
                                lastValue = lastValPosition[j];
                                if (chartSeries.GetType().Name.Contains("100Series"))
                                {
                                    currentValue =
                                        Area.GetPercentByIndex(
                                            (label.Series as IList <ISupportAxes>).OfType <StackingSeriesBase3D>().ToList(),
                                            j,
                                            currentValue,
                                            reCalculation);
                                }

                                lastValPosition[j] += currentValue;
                            }
                            else
                            {
                                lastValue = lastValNeg[j];
                                if (chartSeries.GetType().Name.Contains("100Series"))
                                {
                                    currentValue =
                                        Area.GetPercentByIndex(
                                            (label.Series as IList <ISupportAxes>).OfType <StackingSeriesBase3D>().ToList(),
                                            j,
                                            currentValue,
                                            reCalculation);
                                }

                                lastValNeg[j] += currentValue;
                            }

                            values.StartValues[j] = isFirstSeries ? origin : lastValue;                            // Applying first series starting point from the origin
                            values.EndValues[j]   = currentValue + (double.IsNaN(lastValue) ? origin : lastValue); // Included condition for Empty point support
                            j++;
                        }

                        isFirstSeries = false;
                        i++;
                        Area.StackedValues.Add(chartSeries, values);
                        ((StackingSeriesBase3D)chartSeries).StackValueCalculated = true;
                        reCalculation = false;
                    }
                }
            }

            foreach (var chartSeries in enumerable.OfType <StackingSeriesBase3D>())
            {
                (chartSeries).StackValueCalculated = false;
            }
        }