コード例 #1
0
        protected virtual void OnGetStrokeAndFillForLegendSymbol(double paletteIndex, out Brush stroke, out Brush fill)
        {
            Axis xAxis = XAxis;
            Axis yAxis = YAxis;

            // Check coloring parameters.
            if (PaletteIndex == PaletteIndex.Index && FillMode == AreaFillMode.GradientVertical ||
                PaletteIndex == PaletteIndex.XValue && FillMode == AreaFillMode.GradientVertical)
            {
                throw new NotSupportedException("Vertical gradients are only supported if the palette is indexed by y values.");
            }

            // Set default values for stroke and fill brush.
            stroke = null;
            fill   = null;

            // Try to find colors in palette.
            // We draw from 0 upwards or from a negative value upwards to 0.
            double lower  = Math.Min(0, paletteIndex);
            double higher = Math.Max(0, paletteIndex);

            //if (FillMode == AreaFillMode.Solid)
            //{
            //  // Fill legend symbol with single color.
            //  lower = higher;
            //}

            // Define gradient direction.
            Point startPoint;
            Point endPoint;

            if (PaletteIndex == PaletteIndex.Index || PaletteIndex == PaletteIndex.XValue ||
                FillMode == AreaFillMode.GradientHorizontal || FillMode == AreaFillMode.Solid)
            {
                startPoint = new Point(0, 0);
                endPoint   = new Point(1, 0);
                if (xAxis != null && xAxis.Scale != null && xAxis.Scale.Reversed)
                {
                    ChartHelper.Swap(ref startPoint, ref endPoint);
                }
            }
            else
            {
                startPoint = new Point(0, 1);
                endPoint   = new Point(0, 0);
                if (yAxis != null && yAxis.Scale != null && yAxis.Scale.Reversed)
                {
                    ChartHelper.Swap(ref startPoint, ref endPoint);
                }
            }

            // Get brush for fill and stroke.
            if (FillPalette != null && FillPalette.Count > 0)
            {
                fill = new LinearGradientBrush
                {
                    GradientStops          = FillPalette.GetGradient(lower, higher),
                    StartPoint             = startPoint,
                    EndPoint               = endPoint,
                    ColorInterpolationMode = FillPalette.ColorInterpolationMode
                };
            }

            if (StrokePalette != null && StrokePalette.Count > 0)
            {
                stroke = new LinearGradientBrush
                {
                    GradientStops          = StrokePalette.GetGradient(lower, higher),
                    StartPoint             = startPoint,
                    EndPoint               = endPoint,
                    ColorInterpolationMode = StrokePalette.ColorInterpolationMode
                };
            }
        }
コード例 #2
0
        private void GetBrushes(double paletteIndex, out Brush strokeBrush, out Brush fillBrush)
        {
            Axis xAxis = XAxis;
            Axis yAxis = YAxis;

            strokeBrush = null;
            fillBrush   = null;

            if (FillMode == BarFillMode.Solid)
            {
                // Solid:
                // Get a solid color brush for fill and stroke.
                if (FillPalette != null && FillPalette.Count > 0)
                {
                    fillBrush = new SolidColorBrush(FillPalette.GetColor(paletteIndex));
                }

                if (StrokePalette != null && StrokePalette.Count > 0)
                {
                    strokeBrush = new SolidColorBrush(StrokePalette.GetColor(paletteIndex));
                }
            }
            else
            {
                // Gradient:
                // We draw from 0 upwards or from a negative value upwards to 0.
                double lower  = Math.Min(0, paletteIndex);
                double higher = Math.Max(0, paletteIndex);

                // Define end point for gradient direction.
                Point startPoint;
                Point endPoint;
                if (PaletteIndex == PaletteIndex.XValue)
                {
                    // Horizontal
                    startPoint = new Point(0, 0);
                    endPoint   = new Point(1, 0);
                    if (xAxis != null && xAxis.Scale != null && xAxis.Scale.Reversed)
                    {
                        ChartHelper.Swap(ref startPoint, ref endPoint);
                    }
                }
                else
                {
                    // Vertical
                    startPoint = new Point(0, 1);
                    endPoint   = new Point(0, 0);
                    if (yAxis != null && yAxis.Scale != null && yAxis.Scale.Reversed)
                    {
                        ChartHelper.Swap(ref startPoint, ref endPoint);
                    }
                }

                // Get brush for fill and stroke.
                if (FillPalette != null && FillPalette.Count > 0)
                {
                    fillBrush = new LinearGradientBrush
                    {
                        GradientStops          = FillPalette.GetGradient(lower, higher),
                        StartPoint             = startPoint,
                        EndPoint               = endPoint,
                        ColorInterpolationMode = FillPalette.ColorInterpolationMode
                    };
                }

                if (StrokePalette != null && StrokePalette.Count > 0)
                {
                    strokeBrush = new LinearGradientBrush
                    {
                        GradientStops          = StrokePalette.GetGradient(lower, higher),
                        StartPoint             = startPoint,
                        EndPoint               = endPoint,
                        ColorInterpolationMode = StrokePalette.ColorInterpolationMode
                    };
                }
            }
        }
コード例 #3
0
        protected virtual void OnGetStrokeAndFillForSegment(int index, out Brush stroke, out Brush fill)
        {
            Axis xAxis = XAxis;
            Axis yAxis = YAxis;

            // Check coloring parameters.
            if (PaletteIndex == PaletteIndex.Index && FillMode == AreaFillMode.GradientVertical ||
                PaletteIndex == PaletteIndex.XValue && FillMode == AreaFillMode.GradientVertical)
            {
                throw new NotSupportedException("Vertical gradients are only supported if the palette is indexed by y values.");
            }

            // Find palette index.
            double paletteIndex = 0;

            switch (PaletteIndex)
            {
            case PaletteIndex.Index:
                paletteIndex = index;
                break;

            case PaletteIndex.XValue:
                paletteIndex = Data[index].X;
                break;

            case PaletteIndex.YValue:
                paletteIndex = Data[index].Y;
                break;

            default:
                throw new NotSupportedException("PaletteIndex type is not supported.");
            }

            // Set default values for stroke and fill brush.
            stroke = null;
            fill   = null;

            // Try to find colors in palette.
            if (FillMode == AreaFillMode.Solid)
            {
                // Solid:
                // Get a solid color fill for fill and stroke.
                if (FillPalette != null && FillPalette.Count > 0)
                {
                    fill = new SolidColorBrush(FillPalette.GetColor(paletteIndex));
                }

                if (StrokePalette != null && StrokePalette.Count > 0)
                {
                    stroke = new SolidColorBrush(StrokePalette.GetColor(paletteIndex));
                }
            }
            else
            {
                // Get data values.
                DataPoint data             = Data[index];
                DataPoint dataBase         = new DataPoint(data.X, 0, null);                  // The base is currently always y = 0.
                DataPoint previousData     = (index > 0) ? Data[index - 1] : data;
                DataPoint previousDataBase = new DataPoint(previousData.X, 0, null);          // The base is currently always y = 0.
                DataPoint nextData         = (index < Data.Count - 1) ? Data[index + 1] : data;
                DataPoint nextDataBase     = new DataPoint(nextData.X, 0, null);              // The base is currently always y = 0.

                // Gradient:
                double fillStart;
                double fillEnd;
                double strokeStart;
                double strokeEnd;

                // Define palette index values.
                ChartInterpolation interpolation = EffectiveInterpolation;
                if (PaletteIndex == PaletteIndex.Index)
                {
                    // Index-based
                    if (interpolation == ChartInterpolation.CenteredSteps)
                    {
                        fillStart = strokeStart = Math.Max(index - 0.5, 0);
                        fillEnd   = strokeEnd = Math.Min(index + 0.5, Data.Count - 1);
                    }
                    else if (interpolation == ChartInterpolation.LeftSteps)
                    {
                        fillStart = strokeStart = Math.Max(index - 1, 0);
                        fillEnd   = strokeEnd = index;
                    }
                    else
                    {
                        fillStart = strokeStart = index;
                        fillEnd   = strokeEnd = index + 1;
                    }
                }
                else if (PaletteIndex == PaletteIndex.XValue)
                {
                    // x value based
                    if (interpolation == ChartInterpolation.CenteredSteps)
                    {
                        fillStart = strokeStart = (previousData.X + data.X) / 2;
                        fillEnd   = strokeEnd = (data.X + nextData.X) / 2;
                    }
                    else if (interpolation == ChartInterpolation.LeftSteps)
                    {
                        fillStart = strokeStart = previousData.X;
                        fillEnd   = strokeEnd = data.X;
                    }
                    else
                    {
                        fillStart = strokeStart = data.X;
                        fillEnd   = strokeEnd = nextData.X;
                    }
                }
                else
                {
                    // y value based
                    if (FillMode == AreaFillMode.GradientHorizontal)
                    {
                        if (interpolation == ChartInterpolation.CenteredSteps)
                        {
                            fillStart = strokeStart = (previousData.Y + data.Y) / 2;
                            fillEnd   = strokeEnd = (data.Y + nextData.Y) / 2;
                        }
                        else if (interpolation == ChartInterpolation.LeftSteps)
                        {
                            fillStart = strokeStart = previousData.Y;
                            fillEnd   = strokeEnd = data.Y;
                        }
                        else
                        {
                            fillStart = strokeStart = data.Y;
                            fillEnd   = strokeEnd = nextData.Y;
                        }
                    }
                    else
                    {
                        fillStart = Math.Min(0, Math.Min(data.Y, dataBase.Y));
                        fillEnd   = Math.Max(0, Math.Max(data.Y, dataBase.Y));
                        if (interpolation == ChartInterpolation.Linear)
                        {
                            fillStart = Math.Min(fillStart, Math.Min(nextData.Y, nextDataBase.Y));
                            fillEnd   = Math.Max(fillEnd, Math.Max(nextData.Y, nextDataBase.Y));
                        }

                        // This is the only case where the stroke has a different start and end value than the fill.
                        // (Because the fill starts at y=0, but the line starts at the data point.)
                        strokeStart = data.Y;
                        strokeEnd   = nextData.Y;
                        if (strokeStart > strokeEnd)
                        {
                            ChartHelper.Swap(ref strokeStart, ref strokeEnd);
                        }
                    }
                }

                // Define gradient direction.
                Point startPoint;
                Point endPoint;
                if (PaletteIndex == PaletteIndex.Index || PaletteIndex == PaletteIndex.XValue || FillMode == AreaFillMode.GradientHorizontal)
                {
                    startPoint = new Point(0, 0);
                    endPoint   = new Point(1, 0);
                    if (xAxis != null && xAxis.Scale != null && xAxis.Scale.Reversed)
                    {
                        ChartHelper.Swap(ref startPoint, ref endPoint);
                    }
                }
                else
                {
                    startPoint = new Point(0, 1);
                    endPoint   = new Point(0, 0);
                    if (yAxis != null && yAxis.Scale != null && yAxis.Scale.Reversed)
                    {
                        ChartHelper.Swap(ref startPoint, ref endPoint);
                    }
                }

                // Get brush for fill and stroke.
                if (FillPalette != null && FillPalette.Count > 0)
                {
                    fill = new LinearGradientBrush
                    {
                        GradientStops          = FillPalette.GetGradient(fillStart, fillEnd),
                        StartPoint             = startPoint,
                        EndPoint               = endPoint,
                        ColorInterpolationMode = FillPalette.ColorInterpolationMode
                    };
                }

                if (StrokePalette != null && StrokePalette.Count > 0)
                {
                    stroke = new LinearGradientBrush
                    {
                        GradientStops          = StrokePalette.GetGradient(strokeStart, strokeEnd),
                        StartPoint             = startPoint,
                        EndPoint               = endPoint,
                        ColorInterpolationMode = StrokePalette.ColorInterpolationMode
                    };
                }
            }
        }