private void PlotCombineGroup(CombineGroup group, StackValueProcessor stackValueProcessor)
        {
            double plotPositionPositiveStack, plotPositionNegativeStack;
            double value, plotOriginOffset, normalizedValue;

            double stackSum;
            double valuesSum;
            double delta = this.actualRange.maximum - this.actualRange.minimum;

            foreach (CombineStack stack in group.Stacks)
            {
                double positiveValuesSum = 0d, negativeValuesSum = 0d;
                valuesSum = 0d;
                plotPositionPositiveStack = plotPositionNegativeStack = this.normalizedOrigin;

                foreach (DataPoint point in stack.Points)
                {
                    if (point.isEmpty)
                    {
                        continue;
                    }

                    value = (double)point.GetValueForAxis(this);

                    if (value >= DefaultOrigin)
                    {
                        valuesSum        = positiveValuesSum;
                        plotOriginOffset = plotPositionPositiveStack;
                    }
                    else
                    {
                        valuesSum        = negativeValuesSum;
                        plotOriginOffset = plotPositionNegativeStack;
                    }

                    valuesSum += double.IsNaN(value) ? 0d : value;

                    // TODO: Remove insignificant datapoints from drawing stack.
                    stackSum = this.TransformValue(stackValueProcessor(stack, valuesSum));

                    if (delta == 0)
                    {
                        normalizedValue = 0;
                    }
                    else
                    {
                        normalizedValue = (stackSum - this.actualRange.minimum) / delta;
                    }

                    NumericalAxisPlotInfo plotInfo;
                    if (this.IsInverse)
                    {
                        plotInfo = NumericalAxisPlotInfo.Create(this, 1 - plotOriginOffset, 1 - normalizedValue, 1 - this.normalizedOrigin);
                    }
                    else
                    {
                        plotInfo = NumericalAxisPlotInfo.Create(this, plotOriginOffset, normalizedValue, this.normalizedOrigin);
                    }

                    plotInfo.SnapTickIndex = this.GetSnapTickIndex(stackSum);
                    point.SetValueFromAxis(this, plotInfo);

                    if (value >= DefaultOrigin)
                    {
                        positiveValuesSum         = valuesSum;
                        plotPositionPositiveStack = normalizedValue;
                    }
                    else
                    {
                        negativeValuesSum         = valuesSum;
                        plotPositionNegativeStack = normalizedValue;
                    }
                }
            }
        }
Exemple #2
0
        private void ProcessSeries(CombinedSeries combinedSeries)
        {
            Dictionary <object, CombineGroup> groupsByKey = new Dictionary <object, CombineGroup>(8);
            Dictionary <CombineStack, double> positiveValuesSumByStack = new Dictionary <CombineStack, double>();
            Dictionary <CombineStack, double> negativeValuesSumByStack = new Dictionary <CombineStack, double>();
            CombineStack stack;
            double       min;
            double       max;
            bool         positive;

            foreach (ChartSeriesModel series in combinedSeries.Series)
            {
                if (!series.presenter.IsVisible)
                {
                    continue;
                }

                AxisModel stackValueAxis = this.valueAxesExtractor(series as IPlotAreaElementModelWithAxes);
                if (!this.MinimumStackSums.ContainsKey(stackValueAxis))
                {
                    this.MinimumStackSums.Set(stackValueAxis, double.PositiveInfinity);
                    this.MaximumStackSums.Set(stackValueAxis, double.NegativeInfinity);
                }

                this.MinimumStackSums.TryGetValue(stackValueAxis, out min);
                this.MaximumStackSums.TryGetValue(stackValueAxis, out max);

                foreach (DataPoint point in series.DataPointsInternal)
                {
                    object key = this.StackAxis.GetCombineGroupKey(point);
                    if (key == null)
                    {
                        continue;
                    }

                    CombineGroup group;
                    if (!groupsByKey.TryGetValue(key, out group))
                    {
                        group            = new CombineGroup();
                        group.Key        = key;
                        groupsByKey[key] = group;
                        combinedSeries.Groups.Add(group);
                    }

                    stack = group.GetStack(series as ISupportCombineMode);
                    stack.Points.Add(point);

                    if (!positiveValuesSumByStack.ContainsKey(stack))
                    {
                        positiveValuesSumByStack[stack] = 0d;
                        negativeValuesSumByStack[stack] = 0d;
                    }

                    double positivesSum = positiveValuesSumByStack[stack];
                    double negativesSum = negativeValuesSumByStack[stack];

                    double stackSumValue;
                    if (!stackValueAxis.TryGetStackSumValue(point, out stackSumValue, out positive, ref positivesSum, ref negativesSum))
                    {
                        continue;
                    }

                    positiveValuesSumByStack[stack] = positivesSum;
                    negativeValuesSumByStack[stack] = negativesSum;

                    if (positive)
                    {
                        stack.PositiveSum = stackSumValue;
                    }
                    else
                    {
                        stack.NegativeSum = stackSumValue;
                    }

                    min = Math.Min(min, stack.NegativeSum);
                    max = Math.Max(max, stack.PositiveSum);
                }

                this.MinimumStackSums.Set(stackValueAxis, min);
                this.MaximumStackSums.Set(stackValueAxis, max);
            }
        }