Пример #1
0
        internal void UpdateVisual()
        {
            bool    isMultiColor = fastBarSeries.Palette != ChartColorPalette.None && fastBarSeries.Interior == null;
            float   x1 = 0, x2, y1, y2, diff = 0;
            Color   color;
            SfChart chart = fastBarSeries.Area;

            isSeriesSelected = false;
            Color segmentColor = GetColor(this.Interior);

            //Set SeriesSelectionBrush and Check EnableSeriesSelection
            if (chart.GetEnableSeriesSelection())
            {
                Brush seriesSelectionBrush = chart.GetSeriesSelectionBrush(fastBarSeries);
                if (seriesSelectionBrush != null &&
                    chart.SelectedSeriesCollection.Contains(fastBarSeries))
                {
                    isSeriesSelected     = true;
                    seriesSelectionColor = ((SolidColorBrush)seriesSelectionBrush).Color;
                }
            }
            else if (chart.GetEnableSegmentSelection())//Set SegmentSelectionBrush and Check EnableSegmentSelection
            {
                Brush segmentSelectionBrush = (fastBarSeries as ISegmentSelectable).SegmentSelectionBrush;
                if (segmentSelectionBrush != null)
                {
                    segmentSelectionColor = ((SolidColorBrush)segmentSelectionBrush).Color;
                }
            }

            int dataCount = x1Values.Count;

            if (bitmap != null && x1Values.Count != 0)
            {
                fastBuffer = chart.GetFastBuffer();
                double width  = (int)chart.SeriesClipRect.Width;
                double height = (int)chart.SeriesClipRect.Height;

                for (int i = 0; i < dataCount; i++)
                {
                    if (isSeriesSelected)
                    {
                        color = seriesSelectionColor;
                    }
                    else if (fastBarSeries.SelectedSegmentsIndexes.Contains(startIndex) && (fastBarSeries as ISegmentSelectable).SegmentSelectionBrush != null)
                    {
                        color = segmentSelectionColor;
                    }
                    else if (fastBarSeries.SegmentColorPath != null && fastBarSeries.Interior == null)
                    {
                        if (fastBarSeries.ColorValues.Count > 0 && fastBarSeries.ColorValues[startIndex] != null)
                        {
                            color = GetColor(fastBarSeries.ColorValues[startIndex]);
                        }
                        else if (fastBarSeries.Palette == ChartColorPalette.None)
                        {
                            int serIndex = fastBarSeries.ActualArea.GetSeriesIndex(this.Series);
                            color = GetColor(fastBarSeries.ActualArea.ColorModel.GetBrush(serIndex));
                        }
                        else
                        {
                            Brush brush = fastBarSeries.ColorModel.GetBrush(startIndex);
                            color = GetColor(brush);
                        }
                    }
                    else if (isMultiColor)
                    {
                        Brush brush = fastBarSeries.ColorModel.GetBrush(startIndex);
                        color = GetColor(brush);
                    }
                    else
                    {
                        color = segmentColor;
                    }

                    startIndex++;
                    x1 = x1Values[i];
                    x2 = x2Values[i];
                    y1 = y1ChartVals[i] > 0 ? y1Values[i] : y2Values[i];
                    y2 = y1ChartVals[i] > 0 ? y2Values[i] : y1Values[i];
                    double spacing = (fastBarSeries as ISegmentSpacing).SegmentSpacing;
                    if (spacing > 0 && spacing <= 1)
                    {
                        double leftpos  = (Series as ISegmentSpacing).CalculateSegmentSpacing(spacing, x1, x2);
                        double rightpos = (Series as ISegmentSpacing).CalculateSegmentSpacing(spacing, x2, x1);
                        x2 = (float)leftpos;
                        x1 = (float)rightpos;
                    }
                    diff = x2 - x1;

                    if (y1 < y2)
                    {
                        bitmap.FillRectangle(fastBuffer, (int)width, (int)height, (int)(width - y2), (int)(height - x1 - diff),
                                             (int)(width - y1), (int)(height - x1), color, fastBarSeries.bitmapPixels);

                        Series.bitmapRects.Add(new Rect(new Point((width - y2), (height - x1 - diff)),
                                                        new Point((width - y1), (height - x1))));
                    }
                    else
                    {
                        bitmap.FillRectangle(fastBuffer, (int)width, (int)height, (int)(width - y1), (int)(height - x1 - diff),
                                             (int)(width - y2), (int)(height - x1), color, fastBarSeries.bitmapPixels);

                        Series.bitmapRects.Add(new Rect(new Point((width - y1), (height - x1 - diff)),
                                                        new Point((width - y2), (height - x1))));
                    }
                }
            }
            chart.CanRenderToBuffer = true;

            x1Values.Clear();
            x2Values.Clear();
            y1Values.Clear();
            y2Values.Clear();
        }