object ISeries.GetLegendItemImageSource(int index, ref C1.Chart._Size imageSize)
            {
                if (ShowCustomIcons)
                {
                    imageSize.Width  = 60;
                    imageSize.Height = 60;

                    SmartPhoneVendor vendor = ViewModel.SmartPhoneVendors.ElementAt(index);
                    if (vendor.ImageSource is BitmapImage)
                    {
                        // replace the BitmapImage with a new ImageSource wrapped in the legend item color
                        SolidColorBrush brush = new SolidColorBrush(vendor.Color);
                        vendor.ImageSource = makeLegendImageSource(vendor.ImageSource, brush, imageSize);
                    }

                    // Try and keep the original size of the logo bitmaps, but reduce their size if the chart window
                    // is too small to display the bitmaps properly.
                    double boundsHeight = ParentControl.ArrangeBounds.Height - 50;
                    double divadj       = (boundsHeight > 800) ? 13 : 25;
                    double fracHeight   = boundsHeight / divadj;
                    if (fracHeight < imageSize.Height)
                    {
                        imageSize.Width = imageSize.Height = fracHeight;
                    }

                    return(vendor.ImageSource);
                }
                else
                {
                    return(null);
                }
            }
            object ISeries.GetLegendItemImageSource(int index, ref C1.Chart._Size imageSize)
            {
                if (ShowCustomIcons)
                {
                    // Original images/logos are all 50x50 pixels.
                    // Here they are replaced with new images where a 5 pixel border is added
                    // around the logos.

                    imageSize.Height = 60;
                    imageSize.Width  = 60;

                    SmartPhoneVendor vendor = vendors.ElementAt(index);
                    if (vendor.Image != null && vendor.Image.Width != 60)
                    {
                        Bitmap bmp = new Bitmap(60, 60);
                        using (SolidBrush sb = new SolidBrush(vendor.Color))
                        {
                            using (Graphics g = Graphics.FromImage(bmp))
                            {
                                Rectangle r = new Rectangle(0, 0, (int)imageSize.Width, (int)imageSize.Height);
                                using (Pen p = new Pen(sb))
                                {
                                    g.DrawRectangle(p, r);
                                }
                                g.FillRectangle(sb, r);

                                Point ci = new Point((int)(0.5 * (imageSize.Width - vendor.Image.Width)),
                                                     (int)(0.5 * (imageSize.Height - vendor.Image.Height)));
                                g.DrawImage(vendor.Image, ci);
                            }
                        }
                        vendor.Image = bmp;
                    }

                    // Try and keep the original size of the logo bitmaps, but reduce their size if the chart window
                    // is too small to display the bitmaps properly.
                    Size   bounds     = this.Chart.ClientSize;
                    double divadj     = (bounds.Height > 800) ? 12 : 25;
                    double fracHeight = bounds.Height / divadj;
                    if (fracHeight < imageSize.Height)
                    {
                        imageSize.Width = imageSize.Height = fracHeight;
                    }

                    return(vendor.Image);
                }
                return(null);
            }
Exemplo n.º 3
0
 object ISeries.GetLegendItemImageSource(int index, ref C1.Chart._Size imageSize)
 {
     if (ShowCustomIcons)
     {
         var bounds = Windows.UI.ViewManagement.ApplicationView.
                      GetForCurrentView().VisibleBounds;
         double divadj     = bounds.Height > 900 ? 15 : 35;
         double fracHeight = bounds.Height / divadj;
         imageSize.Width = imageSize.Height = fracHeight < 60 ? fracHeight : 60;
         SmartPhoneVendor vendor = SampleViewModel.SmartPhoneVendors.ElementAt(index);
         return(vendor.ImageSource);
     }
     else
     {
         return(null);
     }
 }