Exemple #1
0
        protected virtual Shape CreateSymbolShape(ShapeStyle shapeStyle)
        {
            double    num;
            Rectangle sh = new Rectangle();

            sh.RadiusY = num = 3.0;
            sh.RadiusX = num;
            if (shapeStyle != null)
            {
                shapeStyle.Apply(sh);
            }
            return(sh);
        }
Exemple #2
0
        internal static ShapeStyle ParseString(string s)
        {
            ShapeStyle      style  = null;
            ConverterHelper helper = ConverterHelper.ParseString(s);

            if (helper != null)
            {
                style = new ShapeStyle();
                if (helper.ContainsKey("StrokeThickness"))
                {
                    style.StrokeThickness = double.Parse(helper["StrokeThickness"].ToString(), (IFormatProvider)CultureInfo.InvariantCulture);
                }
            }
            return(style);
        }
Exemple #3
0
        static void InitStyle(ShapeStyle ss, Brush brush, bool dark)
        {
            ss.FillAuto = ss.Fill = brush;
            Windows.UI.Color clr    = Colors.Gray;
            SolidColorBrush  brush2 = brush as SolidColorBrush;

            if (brush2 != null)
            {
                clr = brush2.Color;
            }
            else
            {
                GradientBrush brush3 = brush as GradientBrush;
                if (((brush3 != null) && (brush3.GradientStops != null)) && (brush3.GradientStops.Count > 0))
                {
                    clr = brush3.GradientStops[0].Color;
                }
            }
            Windows.UI.Color color2 = dark ? ColorPalette.Darken(clr) : clr;
            ss.StrokeAuto = ss.Stroke = new SolidColorBrush(color2);
        }
Exemple #4
0
        UIElement[] IView2DRenderer.Generate()
        {
            int nser = _dataInfo.nser;
            int npts = _dataInfo.npts;

            if ((nser == 0) || (npts == 0))
            {
                return(null);
            }

            List <UIElement> objects    = new List <UIElement>();
            Rect             dataBounds = CoordConverter.DataBounds;
            bool             isStacked  = base.IsStacked;
            StackedSum       sum        = null;
            StackedSum       sum2       = null;
            StackedSum       sum3       = null;
            int nsg = 1;

            if (isStacked)
            {
                nsg  = base.NStackGroups();
                sum  = new StackedSum(nsg);
                sum2 = new StackedSum(nsg);
                sum3 = new StackedSum(nsg);
            }

            double       num4  = GetClusterWidth() * _dataInfo.DeltaX;
            IPlotElement defel = null;

            if (base.Symbol is PlotElement)
            {
                defel = ((PlotElement)base.Symbol).Clone() as IPlotElement;
            }

            bool defval   = (defel != null) ? defel.IsClustered : false;
            bool inverted = base.Inverted;
            int  num5     = 0;

            int[] numArray  = null;
            int[] numArray2 = null;
            if (isStacked)
            {
                num5 = base.NStackGroups();
            }
            else
            {
                numArray  = NClustered(defval);
                numArray2 = new int[numArray.Length];
                num5      = numArray[0];
            }

            double d             = 0.0;
            double origin        = 0.0;
            double seriesOverlap = 0.0;
            Chart  visual        = Chart;
            string xformat       = null;
            string yformat       = null;
            bool   flag4         = false;
            bool   flag5         = false;

            if (visual != null)
            {
                origin        = BarColumnOptions.GetOrigin(visual);
                xformat       = visual.View.AxisX.AnnoFormatInternal;
                yformat       = visual.View.AxisY.AnnoFormatInternal;
                flag4         = !double.IsNaN(visual.View.AxisX.LogBase);
                flag5         = !double.IsNaN(visual.View.AxisY.LogBase);
                seriesOverlap = BarColumnOptions.GetSeriesOverlap(visual);
                if (seriesOverlap > 1.0)
                {
                    seriesOverlap = 1.0;
                }
                else if (seriesOverlap < -1.0)
                {
                    seriesOverlap = -1.0;
                }
            }

            int si    = 0;
            int num10 = 0;

            while (si < nser)
            {
                IDataSeriesInfo ds     = base.Series[si];
                DataSeries      series = (DataSeries)base.Series[si];
                series.Children.Clear();
                objects.Add(series);
                series.SetDefaultFormat(xformat, yformat);
                int stackGroup = 0;
                if (isStacked)
                {
                    stackGroup = BarColumnOptions.GetStackGroup(series);
                }
                if (series.SymbolShape == null)
                {
                    series.SymbolShape = base.StyleGen.Next();
                }
                ShapeStyle symbolShape = series.SymbolShape;
                bool?      nullable    = null;
                double[,] values = ds.GetValues();
                if (values != null)
                {
                    int           length = values.GetLength(1);
                    int           num13  = values.GetLength(0);
                    RenderContext rc     = new RenderContext(this, ds, length)
                    {
                        Bounds = CoordConverter.ViewBounds
                    };
                    Rect clipBounds = rc.ClipBounds;
                    clipBounds = new Rect(clipBounds.X - 1.0, clipBounds.Y - 1.0, clipBounds.Width + 2.0, clipBounds.Height + 2.0);
                    double naN = double.NaN;
                    if ((rc.OptimizationRadiusScope & OptimizationRadiusScope.Symbols) > ((OptimizationRadiusScope)0))
                    {
                        naN = rc.OptimizationRadius;
                    }
                    bool isClustered = defval;
                    bool flag7       = series.IsStacked;
                    int  num15       = 0;
                    int  num16       = length;
                    if (_dataInfo.incX && !inverted)
                    {
                        Rect rect2 = CoordConverter.DataBounds2D;
                        for (int j = 0; j < length; j++)
                        {
                            double num18 = (num13 >= 2) ? values[1, j] : ((double)j);
                            if (num18 >= rect2.Left)
                            {
                                num15 = Math.Max(0, j - 2);
                                break;
                            }
                        }
                        for (int k = num15; k < length; k++)
                        {
                            double num20 = (num13 >= 2) ? values[1, k] : ((double)k);
                            if (num20 > rect2.Right)
                            {
                                num16 = k;
                                break;
                            }
                        }
                        num16 = Math.Min(length, num16 + 2);
                    }
                    Point point = new Point();
                    for (int i = num15; i < num16; i++)
                    {
                        double       num22     = values[0, i];
                        double       x         = (num13 >= 2) ? values[1, i] : ((double)i);
                        double       y         = x;
                        Style        style     = null;
                        IPlotElement pe        = null;
                        bool?        nullable2 = nullable;
                        if (!nullable2.GetValueOrDefault() || !nullable2.HasValue)
                        {
                            if (base.ColorScheme == ColorScheme.Point)
                            {
                                symbolShape = base.StyleGen.GetStyle(i);
                            }
                            style = base.GetStyle(series, si, i);
                            pe    = base.CreateElement(series.Symbol, style);
                            if (pe == null)
                            {
                                pe = PlotElement.SymbolFromMarker(series.SymbolMarker);
                                if ((pe != null) && (style != null))
                                {
                                    pe.Style = style;
                                }
                            }
                            if ((pe == null) && series.ChartType.HasValue)
                            {
                                ChartSubtype subtype = ChartTypes.GetSubtype(series.ChartType.ToString());
                                if (subtype != null)
                                {
                                    pe = base.CreateElement(subtype.Symbol, style);
                                }
                            }
                            else if (pe == null)
                            {
                                if (series.IsDefaultSymbol && (defel != null))
                                {
                                    pe       = defel;
                                    pe.Style = style;
                                    defel    = ((PlotElement)base.Symbol).Clone() as IPlotElement;
                                }
                            }
                            else
                            {
                                isClustered = pe.IsClustered;
                            }
                            if (pe == null)
                            {
                                isClustered = false;
                                if ((series.PointLabelTemplate != null) || (series.PointTooltipTemplate != null))
                                {
                                    DotSymbol symbol = new DotSymbol();
                                    symbol.Fill   = TransparentBrush;
                                    symbol.Size   = new Size(5.0, 5.0);
                                    symbol.Stroke = TransparentBrush;
                                    pe            = symbol;
                                }
                                else
                                {
                                    nullable = true;
                                }
                            }
                            else
                            {
                                isClustered = pe.IsClustered;
                            }
                        }
                        bool flag8 = (flag4 && inverted) || (flag5 && !inverted);
                        if (!flag8)
                        {
                            if (nsg > 1)
                            {
                                if (flag7)
                                {
                                    x += ((-0.5 * num4) + ((0.5 * num4) / ((double)num5))) + ((stackGroup * num4) / ((double)num5));
                                }
                            }
                            else if (isClustered)
                            {
                                int clusterPlotAreaIndex = rc.ClusterPlotAreaIndex;
                                if (clusterPlotAreaIndex == 0)
                                {
                                    if (num5 > 1)
                                    {
                                        x += ((-0.5 * num4) + ((0.5 * num4) / ((double)num5))) + ((num10 * num4) / ((double)num5));
                                    }
                                }
                                else if (numArray[clusterPlotAreaIndex] > 1)
                                {
                                    x += ((-0.5 * num4) + ((0.5 * num4) / ((double)numArray[clusterPlotAreaIndex]))) + ((numArray2[clusterPlotAreaIndex] * num4) / ((double)numArray[clusterPlotAreaIndex]));
                                }
                            }
                        }
                        if (isStacked && flag7)
                        {
                            if (double.IsNaN(num22))
                            {
                                num22 = 0.0;
                            }
                            if (base.IsStacked100)
                            {
                                if (_dataInfo.Stacked[stackGroup, x] != 0.0)
                                {
                                    num22 = ((num22 * 100.0) / _dataInfo.Stacked[stackGroup, x]) + sum[stackGroup, x];
                                }
                            }
                            else
                            {
                                num22 += sum[stackGroup, x];
                            }
                        }
                        double num26 = x;
                        if (inverted)
                        {
                            double num27 = x;
                            x     = num22;
                            num22 = num27;
                        }
                        double num28 = rc.ConvertX(x);
                        double num29 = rc.ConvertY(num22);
                        if (((isStacked && flag7) && (si > 0)) && ((inverted && !double.IsNaN(num29)) || (!inverted && !double.IsNaN(num28))))
                        {
                            rc.SetPrevious(sum[stackGroup, num26]);
                        }
                        nullable2 = nullable;
                        if (!nullable2.GetValueOrDefault() || !nullable2.HasValue)
                        {
                            if (isClustered)
                            {
                                int num30 = num5;
                                if (rc.ClusterPlotAreaIndex > 0)
                                {
                                    num30 = numArray[rc.ClusterPlotAreaIndex];
                                }
                                if (num30 > 0)
                                {
                                    if (inverted)
                                    {
                                        d = Math.Abs((double)(CoordConverter.ConvertY((num4 / ((double)num30)) + num22) - CoordConverter.ConvertY(num22)));
                                    }
                                    else
                                    {
                                        d = Math.Abs((double)(CoordConverter.ConvertX((num4 / ((double)num30)) + x) - CoordConverter.ConvertX(x)));
                                    }
                                }
                            }
                            else if (inverted)
                            {
                                d = Math.Abs((double)(CoordConverter.ConvertY(num4 + num22) - CoordConverter.ConvertY(num22)));
                            }
                            else
                            {
                                d = Math.Abs((double)(CoordConverter.ConvertX(num4 + x) - CoordConverter.ConvertX(x)));
                            }
                            if (double.IsNaN(d))
                            {
                                d = inverted ? (base.SizeY * 20.0) : (base.SizeX * 20.0);
                            }
                        }
                        if (flag8)
                        {
                            double num31 = 0.0;
                            double num32 = d * num5;
                            if (nsg > 1)
                            {
                                if (flag7)
                                {
                                    num31 = ((-0.5 * num32) + ((0.5 * num32) / ((double)num5))) + ((stackGroup * num32) / ((double)num5));
                                }
                            }
                            else if ((num5 > 1) && isClustered)
                            {
                                num31 = ((-0.5 * num32) + ((0.5 * num32) / ((double)num5))) + ((num10 * num32) / ((double)num5));
                            }
                            if (num31 != 0.0)
                            {
                                if (inverted)
                                {
                                    num29 += num31;
                                }
                                else
                                {
                                    num28 += num31;
                                }
                            }
                        }
                        if (isStacked && flag7)
                        {
                            StackedSum sum4;
                            int        num63;
                            double     num64;
                            double     num33 = values[0, i];
                            if (double.IsNaN(num33))
                            {
                                num33 = 0.0;
                            }
                            double num34 = (num33 >= 0.0) ? sum2[stackGroup, num26] : sum3[stackGroup, num26];
                            double num35 = (num33 >= 0.0) ? (sum2[stackGroup, num26] + num33) : (sum3[stackGroup, num26] + num33);
                            if (base.IsStacked100)
                            {
                                num34 = (num34 * 100.0) / _dataInfo.Stacked[stackGroup, num26];
                                num35 = (num35 * 100.0) / _dataInfo.Stacked[stackGroup, num26];
                            }
                            if (inverted)
                            {
                                double num36;
                                double num37;
                                double num38;
                                if (flag4)
                                {
                                    double minX = rc.GetMinX(CoordConverter.DataBounds2D);
                                    num36 = CoordConverter.ConvertX(Math.Max(num35, minX));
                                    num37 = CoordConverter.ConvertX(Math.Max(num34, minX));
                                }
                                else
                                {
                                    num36 = CoordConverter.ConvertX(num35);
                                    num37 = CoordConverter.ConvertX(num34);
                                }
                                if (flag5)
                                {
                                    num38 = base.SizeY * 20.0;
                                }
                                else
                                {
                                    num38 = Math.Abs((double)(CoordConverter.ConvertY(num4 / ((double)nsg)) - CoordConverter.ConvertY(0.0)));
                                }
                                double width = Math.Abs((double)(num37 - num36));
                                rc.Rect = new Rect(Math.Min(num36, num37), num29 - (0.5 * num38), width, num38);
                                sum[stackGroup, num26] = x;
                            }
                            else
                            {
                                double num41;
                                double num42;
                                double num43;
                                if (flag5)
                                {
                                    double minY = rc.GetMinY(CoordConverter.DataBounds2D);
                                    num41 = CoordConverter.ConvertY(Math.Max(num35, minY));
                                    num42 = CoordConverter.ConvertY(Math.Max(num34, minY));
                                }
                                else
                                {
                                    num41 = CoordConverter.ConvertY(num35);
                                    num42 = CoordConverter.ConvertY(num34);
                                }
                                if (flag4)
                                {
                                    num43 = base.SizeX * 20.0;
                                }
                                else
                                {
                                    num43 = Math.Abs((double)(CoordConverter.ConvertX(num4 / ((double)nsg)) - CoordConverter.ConvertX(0.0)));
                                }
                                double height = Math.Abs((double)(num42 - num41));
                                rc.Rect = new Rect(num28 - (0.5 * num43), Math.Min(num41, num42), num43, height);
                                sum[stackGroup, num26] = num22;
                            }
                            if (num33 >= 0.0)
                            {
                                (sum4 = sum2)[num63 = stackGroup, num64 = num26] = sum4[num63, num64] + num33;
                            }
                            else
                            {
                                (sum4 = sum3)[num63 = stackGroup, num64 = num26] = sum4[num63, num64] + num33;
                            }
                        }
                        else
                        {
                            nullable2 = nullable;
                            if (!nullable2.GetValueOrDefault() || !nullable2.HasValue)
                            {
                                double num46 = origin;
                                if (inverted)
                                {
                                    double num47 = rc.GetMinX(CoordConverter.DataBounds2D);
                                    double maxX  = rc.GetMaxX(CoordConverter.DataBounds2D);
                                    if (num46 < num47)
                                    {
                                        num46 = num47;
                                    }
                                    else if (num46 > maxX)
                                    {
                                        num46 = maxX;
                                    }
                                    double num49 = rc.ConvertX(num46);
                                    double num50 = d;
                                    double num51 = Math.Abs((double)(num49 - num28));
                                    if (seriesOverlap != 0.0)
                                    {
                                        double num52 = rc.ConvertY(y);
                                        double num53 = d * num5;
                                        if (seriesOverlap > 0.0)
                                        {
                                            num50 = num53 / ((num5 - (num5 * seriesOverlap)) + seriesOverlap);
                                        }
                                        else
                                        {
                                            num50 *= 1.0 + seriesOverlap;
                                        }
                                        double num54 = (num53 - num50) / ((double)(num5 - 1));
                                        rc.Rect = new Rect(Math.Min(num28, num49), (num52 - (0.5 * num53)) + (((num5 - num10) - 1) * num54), num51, num50);
                                    }
                                    else
                                    {
                                        rc.Rect = new Rect(Math.Min(num28, num49), num29 - (0.5 * num50), num51, num50);
                                    }
                                }
                                else
                                {
                                    double num55 = rc.GetMinY(CoordConverter.DataBounds2D);
                                    double maxY  = rc.GetMaxY(CoordConverter.DataBounds2D);
                                    if (num46 < num55)
                                    {
                                        num46 = num55;
                                    }
                                    else if (num46 > maxY)
                                    {
                                        num46 = maxY;
                                    }
                                    double num57 = rc.ConvertY(num46);
                                    double num58 = d;
                                    double num59 = Math.Abs((double)(num57 - num29));
                                    if (seriesOverlap != 0.0)
                                    {
                                        double num60 = rc.ConvertX(y);
                                        double num61 = d * num5;
                                        if (seriesOverlap > 0.0)
                                        {
                                            num58 = num61 / ((num5 - (num5 * seriesOverlap)) + seriesOverlap);
                                        }
                                        else
                                        {
                                            num58 *= 1.0 + seriesOverlap;
                                        }
                                        double num62 = (num61 - num58) / ((double)(num5 - 1));
                                        rc.Rect = new Rect((num60 - (0.5 * num61)) + (num10 * num62), Math.Min(num29, num57), num58, num59);
                                    }
                                    else
                                    {
                                        rc.Rect = new Rect(num28 - (0.5 * num58), Math.Min(num29, num57), num58, num59);
                                    }
                                }
                            }
                        }
                        rc.SetPoint(i, num28, num29);
                        if (pe != null)
                        {
                            Point point2 = new Point(num28, num29);
                            if ((pe is ICustomClipping) || clipBounds.Contains(point2))
                            {
                                if (double.IsNaN(naN))
                                {
                                    DataPoint dp = series.CreateDataPoint(si, i);
                                    base.RenderElement(objects, pe, series, rc, symbolShape, dp);
                                }
                                else if (((i == 0) || (Math.Abs((double)(point2.X - point.X)) > naN)) || ((Math.Abs((double)(point2.Y - point.Y)) > naN) || (i == (num16 - 1))))
                                {
                                    DataPoint point4 = series.CreateDataPoint(si, i);
                                    base.RenderElement(objects, pe, series, rc, symbolShape, point4);
                                    point = point2;
                                }
                            }
                        }
                    }

                    PlotElement element3 = base.RenderConnection(series, rc, si);
                    if (element3 != null)
                    {
                        series.Children.Insert(0, element3);
                    }

                    if (isClustered)
                    {
                        if (rc.ClusterPlotAreaIndex == 0)
                        {
                            num10++;
                        }
                        else
                        {
                            numArray2[rc.ClusterPlotAreaIndex]++;
                        }
                    }
                }
                si++;
            }
            return(objects.ToArray());
        }
Exemple #5
0
 internal virtual void UpdateLegend(IList <LegendItem> litems)
 {
     using (IEnumerator <LegendItem> enumerator = litems.GetEnumerator())
     {
         while (enumerator.MoveNext())
         {
             enumerator.Current.Clear();
         }
     }
     litems.Clear();
     if (ColorScheme == Dt.Charts.ColorScheme.Point)
     {
         AnalyzeData(IsStacked);
         int nser = _dataInfo.nser;
         int npts = _dataInfo.npts;
         if (nser > 0)
         {
             DataSeries series = Series[0] as DataSeries;
             for (int i = 0; i < npts; i++)
             {
                 ShapeStyle shapeStyle = StyleGen.GetStyle(i);
                 string     lbl        = null;
                 object     item       = null;
                 if ((ItemNames != null) && (i < ItemNames.Length))
                 {
                     item = ItemNames[i];
                     if (item != null)
                     {
                         lbl = item.ToString();
                     }
                 }
                 else
                 {
                     lbl = "Item " + ((int)i).ToString((IFormatProvider)CultureInfo.CurrentCulture);
                 }
                 Shape sym = CreateSymbolShape(shapeStyle);
                 if (series.ReadLocalValue(DataSeries.SymbolStrokeProperty) != DependencyProperty.UnsetValue)
                 {
                     sym.Stroke = series.SymbolStroke;
                 }
                 if (series.ReadLocalValue(DataSeries.SymbolStrokeThicknessProperty) != DependencyProperty.UnsetValue)
                 {
                     sym.StrokeThickness = Math.Min(2.0, series.SymbolStrokeThickness);
                 }
                 LegendItem item2 = new LegendItem(sym, null, lbl, item);
                 litems.Add(item2);
             }
         }
     }
     else
     {
         int num4 = Series.Count;
         for (int j = 0; j < num4; j++)
         {
             DataSeries series2 = Series[j] as DataSeries;
             if (series2 != null)
             {
                 if ((series2.SymbolShape == null) || !_stgen.List.Contains(series2.SymbolShape))
                 {
                     series2.SymbolShape = _stgen.Next();
                 }
                 if (series2.ConnectionShape == null)
                 {
                     series2.ConnectionShape = _stgen.List2[_stgen.List.Count - 1];
                 }
                 if (((byte)(series2.Display & SeriesDisplay.HideLegend)) == 0)
                 {
                     LegendItem item3;
                     object     symbol     = Symbol;
                     object     connection = Connection;
                     if (series2.ChartType.HasValue)
                     {
                         ChartSubtype subtype = ChartTypes.GetSubtype(series2.ChartType.ToString());
                         symbol     = subtype.Symbol;
                         connection = subtype.Connection;
                     }
                     bool         flag              = (((symbol != null) && series2.IsDefaultSymbol) || (series2.Symbol != null)) || (series2.SymbolMarker != Marker.None);
                     bool         flag2             = ((connection != null) && series2.IsDefaultConnection) || (series2.Connection != null);
                     IPlotElement connectionElement = series2.GetConnectionElement(this, clear);
                     if ((!flag && flag2) && (connectionElement is Area))
                     {
                         item3 = new LegendItem(flag2 ? CreateLineShape(series2) : null, null, series2.Label, series2);
                     }
                     else
                     {
                         item3 = new LegendItem(flag ? CreateSymbolShape(series2) : null, flag2 ? CreateLineShape(series2) : null, series2.Label, series2);
                     }
                     litems.Add(item3);
                 }
             }
         }
         clear = false;
     }
 }
Exemple #6
0
        protected UIElement RenderElement(List <UIElement> objects, IPlotElement pe, DataSeries ds, RenderContext rc, ShapeStyle shapeStyle, DataPoint dp)
        {
            DataTemplate pointLabelTemplate = ds.PointLabelTemplate;
            PlotElement  element            = pe as PlotElement;

            if (((ItemNames != null) && (dp.PointIndex < ItemNames.Length)) && (ItemNames[dp.PointIndex] != null))
            {
                dp.Name = ItemNames[dp.PointIndex].ToString();
            }
            FrameworkElement lbl  = null;
            Line             line = null;

            if (pointLabelTemplate != null)
            {
                lbl             = pointLabelTemplate.LoadContent() as FrameworkElement;
                lbl.DataContext = dp;
                if (Canvas.GetZIndex(lbl) == 0)
                {
                    Canvas.SetZIndex(lbl, 1);
                }
                if (pe != null)
                {
                    pe.Label = lbl;
                }
                else
                {
                    PlotElement.UpdateLabelPosition(element, lbl);
                }
                line = PlotElement.GetLabelLine(lbl);
            }
            if (pe == null)
            {
                return(null);
            }
            Size size = ds.GetSymbolSize(dp.PointIndex, _dataInfo, rc.Chart);

            if (!size.IsEmpty && (element != null))
            {
                element.Size = size;
            }
            if (!pe.Render(rc))
            {
                return(null);
            }
            if (lbl != null)
            {
                objects.Add(lbl);
                if (line != null)
                {
                    lbl.Loaded += (sender, e) =>
                    {
                        Canvas parent = (Canvas)lbl.Parent;
                        if (parent != null)
                        {
                            parent.Children.Add(line);
                        }
                    };
                }
            }
            if ((element.Center.X == 0.0) && (element.Center.Y == 0.0))
            {
                element.Center = rc.Current;
            }
            element.PlotRect = rc.Bounds;
            PlotElement.UpdateLabelPosition(element, pe.Label as FrameworkElement);
            if (element.DataContext == null)
            {
                element.DataContext = dp;
            }
            element.DataPoint = dp;
            AttachTooltip(ds, element);
            pe.SetShape(shapeStyle);
            ds.Children.Add((UIElement)pe);
            return((UIElement)pe);
        }
Exemple #7
0
        UIElement[] IView2DRenderer.Generate()
        {
            int nser = _dataInfo.nser;
            int npts = _dataInfo.npts;

            if ((nser == 0) || (npts == 0))
            {
                return(null);
            }
            List <UIElement> objects     = new List <UIElement>();
            int            num3          = 0;
            int            num4          = 0;
            double         width         = _sz.Width;
            double         height        = _sz.Height;
            double         num7          = width / ((double)_ncols);
            double         num8          = height / ((double)_nrows);
            double         num9          = 0.5 * Math.Min((double)(width / ((double)_ncols)), (double)(height / ((double)_nrows)));
            double         naN           = double.NaN;
            double         startingAngle = 0.0;
            SweepDirection clockwise     = SweepDirection.Clockwise;
            bool           flag          = false;
            Chart          chart         = base.Chart;
            double         d             = 0.0;

            if (chart != null)
            {
                startingAngle = PieOptions.GetStartingAngle(chart);
                clockwise     = PieOptions.GetDirection(chart);
                flag          = base.Chart.ChartType == ChartType.PieStacked;
                naN           = PieOptions.GetOffset(chart);
                d             = PieOptions.GetInnerRadius(chart);
            }
            if (double.IsNaN(naN))
            {
                naN = base.Offset;
            }
            if (double.IsNaN(d) || (d == 0.0))
            {
                d = base.InnerRadius;
            }
            for (int i = 0; i < nser; i++)
            {
                Point  point   = new Point();
                double radiusX = num9 * base.Radius;
                double inner   = d;
                if (flag)
                {
                    inner    = (((double)i) / ((double)nser)) * radiusX;
                    radiusX *= ((double)(i + 1)) / ((double)nser);
                    inner   /= radiusX;
                }
                point = new Point((num4 - (0.5 * _ncols)) + 0.5, (num3 - (0.5 * _nrows)) + 0.5)
                {
                    X = (num7 * point.X) + (0.5 * width),
                    Y = (num8 * point.Y) + (0.5 * height)
                };
                IDataSeriesInfo info   = Series[i];
                DataSeries      series = info as DataSeries;
                series.Children.Clear();
                objects.Add(series);
                double num16 = _dataInfo.SumsAbs[i];
                double[,] values = info.GetValues();
                if (!string.IsNullOrEmpty(series.Label))
                {
                    DataTemplate seriesLabelTemplate = null;
                    if (chart != null)
                    {
                        seriesLabelTemplate = PieOptions.GetSeriesLabelTemplate(chart);
                    }
                    UIElement el = null;
                    if (seriesLabelTemplate != null)
                    {
                        el = seriesLabelTemplate.LoadContent() as UIElement;
                        FrameworkElement element2 = el as FrameworkElement;
                        if (element2 != null)
                        {
                            element2.DataContext = series;
                        }
                    }
                    if (el == null)
                    {
                        TextBlock block = new TextBlock();
                        block.Text = series.Label;
                        IRenderer renderer = this;
                        Control   visual   = renderer.Visual as Control;
                        if (visual != null)
                        {
                            block.FontFamily  = visual.FontFamily;
                            block.FontSize    = visual.FontSize;
                            block.FontStretch = visual.FontStretch;
                            block.FontStyle   = visual.FontStyle;
                            block.FontWeight  = visual.FontWeight;
                        }
                        el = block;
                    }
                    Size size = Utils.GetSize(el);
                    Canvas.SetLeft(el, point.X - (0.5 * size.Width));
                    if ((size.Height + radiusX) > (0.5 * num8))
                    {
                        radiusX = (0.5 * num8) - size.Height;
                    }
                    if (flag)
                    {
                        Canvas.SetTop(el, (point.Y - (radiusX * inner)) - size.Height);
                    }
                    else
                    {
                        Canvas.SetTop(el, (point.Y - radiusX) - size.Height);
                    }
                    objects.Add(el);
                }
                double angle = startingAngle;
                double num18 = 0.0;
                if (naN > 0.0)
                {
                    num18    = naN * radiusX;
                    radiusX *= 1.0 - naN;
                }
                int num19 = (values != null) ? values.GetLength(1) : 0;
                for (int j = 0; j < num19; j++)
                {
                    double num21 = values[0, j];
                    if (!double.IsNaN(num21) && (num21 != 0.0))
                    {
                        ShapeStyle shapeStyle = StyleGen.GetStyle(j);
                        double     sweep      = (Math.Abs(num21) / num16) * 360.0;
                        if (sweep != 0.0)
                        {
                            if (clockwise == SweepDirection.Counterclockwise)
                            {
                                sweep = -sweep;
                            }
                            Point center = point;
                            if ((num18 > 0.0) && (sweep != 360.0))
                            {
                                double num23 = 0.017453292519943295 * (angle + (0.5 * sweep));
                                center.X += num18 * Math.Cos(num23);
                                center.Y += num18 * Math.Sin(num23);
                            }
                            PieRenderContext rc = new PieRenderContext();
                            if (sweep < 0.0)
                            {
                                rc.PieInfo = new PieInfo(center, radiusX, radiusX, inner, angle + sweep, -sweep, 0.0, 0.0);
                            }
                            else
                            {
                                rc.PieInfo = new PieInfo(center, radiusX, radiusX, inner, angle, sweep, 0.0, 0.0);
                            }
                            DataPoint    dp = series.CreateDataPoint(i, j);
                            IPlotElement pe = null;
                            if ((series.Symbol is PlotElement) && ((IPlotElement)series.Symbol).IsCompatible(this))
                            {
                                pe = ((PlotElement)series.Symbol).Clone() as IPlotElement;
                            }
                            if ((pe == null) && (Symbol is PlotElement))
                            {
                                pe = ((PlotElement)Symbol).Clone() as IPlotElement;
                            }
                            RenderElement(objects, pe, series, rc, shapeStyle, dp);
                            if (series.ReadLocalValue(DataSeries.SymbolStrokeProperty) != DependencyProperty.UnsetValue)
                            {
                                ((PlotElement)pe).Stroke = series.SymbolStroke;
                            }
                            if (series.ReadLocalValue(DataSeries.SymbolStrokeThicknessProperty) != DependencyProperty.UnsetValue)
                            {
                                ((PlotElement)pe).StrokeThickness = series.SymbolStrokeThickness;
                            }
                            angle += sweep;
                        }
                    }
                }
                if (!flag)
                {
                    num4++;
                    if (num4 >= _ncols)
                    {
                        num4 = 0;
                        num3++;
                    }
                }
            }
            return(objects.ToArray());
        }
Exemple #8
0
        UIElement[] IView2DRenderer.Generate()
        {
            int nser = _dataInfo.nser;
            int npts = _dataInfo.npts;

            if ((nser == 0) || (npts == 0))
            {
                return(null);
            }
            IPlotElement element = null;

            if (base.Symbol is PlotElement)
            {
                element = ((PlotElement)base.Symbol).Clone() as IPlotElement;
            }
            List <UIElement> objects = new List <UIElement>();

            for (int i = 0; i < nser; i++)
            {
                DataSeries ds = (DataSeries)base.Series[i];
                ds.Children.Clear();
                objects.Add(ds);
                if (ds.SymbolShape == null)
                {
                    ds.SymbolShape = base.StyleGen.Next();
                }
                ShapeStyle symbolShape = ds.SymbolShape;
                double[,] values = ds.GetValues();
                if (values != null)
                {
                    int           length = values.GetLength(1);
                    int           num5   = values.GetLength(0);
                    RenderContext rc     = new RenderContext(this, ds, length)
                    {
                        Bounds = CoordConverter.ViewBounds
                    };
                    for (int j = 0; j < length; j++)
                    {
                        if (base.ColorScheme == ColorScheme.Point)
                        {
                            symbolShape = base.StyleGen.GetStyle(j);
                        }
                        double       y     = values[0, j];
                        double       x     = (num5 >= 2) ? values[1, j] : ((double)j);
                        bool         flag  = false;
                        Style        style = base.GetStyle(ds, i, j);
                        IPlotElement pe    = base.CreateElement(ds.Symbol, style);
                        if (pe == null)
                        {
                            pe = PlotElement.SymbolFromMarker(ds.SymbolMarker);
                            if ((pe != null) && (style != null))
                            {
                                pe.Style = style;
                            }
                        }
                        if ((pe == null) && ds.ChartType.HasValue)
                        {
                            ChartSubtype subtype = ChartTypes.GetSubtype(ds.ChartType.ToString());
                            if (subtype != null)
                            {
                                pe = base.CreateElement(subtype.Symbol, style);
                            }
                        }
                        else if (((pe == null) && ds.IsDefaultSymbol) && (element != null))
                        {
                            pe       = element;
                            pe.Style = style;
                            element  = ((PlotElement)base.Symbol).Clone() as IPlotElement;
                        }
                        if ((pe == null) && ((ds.PointLabelTemplate != null) || (ds.PointTooltipTemplate != null)))
                        {
                            DotSymbol symbol = new DotSymbol();
                            symbol.Fill   = TransparentBrush;
                            symbol.Size   = new Size(5.0, 5.0);
                            symbol.Stroke = TransparentBrush;
                            pe            = symbol;
                            flag          = true;
                        }
                        Point point   = CoordConverter.ConvertPoint(new Point(x, y));
                        Axis  auxAxis = GetAuxAxis(j);
                        if (auxAxis != null)
                        {
                            ChartViewport2D coordConverter = CoordConverter as ChartViewport2D;
                            if (coordConverter != null)
                            {
                                point = coordConverter.ConvertPoint(new Point(x, y), base.Chart.View.AxisX, auxAxis);
                            }
                        }
                        rc.SetPoint(j, point.X, point.Y);
                        if (!double.IsNaN(point.X) && !double.IsNaN(point.Y))
                        {
                            DataPoint dp       = ds.CreateDataPoint(i, j);
                            UIElement element3 = base.RenderElement(objects, pe, ds, rc, symbolShape, dp);
                            if ((element3 != null) && flag)
                            {
                                Canvas.SetZIndex(element3, 2);
                            }
                        }
                    }
                    PlotElement element4 = base.RenderConnection(ds, rc, i);
                    if (element4 != null)
                    {
                        element4.DataPoint = ds.CreateDataPoint(i, -1);
                        ds.Children.Insert(0, element4);
                    }
                }
            }
            return(objects.ToArray());
        }