/// <summary>
        /// Translates a collection of <see cref="GradientStop" /> to an <see cref="OxyPalette" />.
        /// </summary>
        /// <param name="stops">
        /// The gradient stops collection to convert.
        /// </param>
        /// <param name="paletteSize">
        /// The palette size.
        /// </param>
        /// <returns>
        /// The interpolated <see cref="OxyPalette"/>.
        /// </returns>
        private static OxyPalette Interpolate(List <GradientStop> stops, int paletteSize)
        {
            Debug.Assert(stops.Count >= 2, "Can't interpolate less than 2 gradient stops.");
            Debug.Assert(paletteSize > 0, "Palette size must be non-zero positive number.");

            var palette = new List <OxyColor>();

            stops.Sort((x1, x2) => x1.Offset.CompareTo(x2.Offset));

            var palettePositions = stops[0].Offset;
            var step             = (double)stops.Count / paletteSize;

            for (int i = 0; i < stops.Count - 1; i++)
            {
                var start = stops[i];
                var end   = stops[i + 1];

                while (palettePositions <= end.Offset)
                {
                    palette.Add(
                        OxyColor.Interpolate(
                            start.Color.ToOxyColor(),
                            end.Color.ToOxyColor(),
                            (palettePositions - start.Offset) / (end.Offset - start.Offset)));
                    palettePositions += step;
                }
            }

            return(new OxyPalette(palette));
        }
        public ScatterSeries GetNegativePointsSeriers()
        {
            var clusterPoints = new ScatterSeries {
                MarkerFill = OxyColor.Interpolate(Color, OxyColor.FromRgb(0, 0, 0), 0.5)
            };

            clusterPoints.Points.AddRange(
                Solution.Cluster.Points.Where(p => !p.Label).Select(
                    p => new ScatterPoint(p[XIndex], p[YIndex], 2)));

            return(clusterPoints);
        }
        private Contour[] GenerateContours(double min, double max, OxyColor minColor, OxyColor maxColor, int nrOfContours)
        {
            double delta         = max - min;
            double stepSize      = delta / nrOfContours;
            double colorStepSize = 1 / (double)nrOfContours;
            var    contours      = new Contour[nrOfContours];

            for (int i = 1; i <= nrOfContours; i++)
            {
                contours[i - 1] = new Contour(min + i * stepSize, OxyColor.Interpolate(minColor, maxColor, i * colorStepSize));
            }
            return(contours);
        }
        OxyColor InterpolateColour(System.Drawing.Color start, System.Drawing.Color end, int index, int count)
        {
            double range = 0;

            if (count > 1)
            {
                range = (double)index / (double)(count - 1);
            }

            return(OxyColor.Interpolate(
                       OxyColor.FromArgb(start.A, start.R, start.G, start.B),
                       OxyColor.FromArgb(end.A, end.R, end.G, end.B),
                       range));
        }
示例#5
0
        private OxyImage GetGradientImage(OxyColor color1, OxyColor color2)
        {
            int n         = 256;
            var imageData = new OxyColor[1, n];

            for (int i = 0; i < n; i++)
            {
                imageData[0, i] = OxyColor.Interpolate(color1, color2, i / (n - 1.0));
            }

            var encoder = new PngEncoder(new PngEncoderOptions());

            return(new OxyImage(encoder.Encode(imageData)));
        }
示例#6
0
        private void AddSeries(string title)
        {
            switch (_modelName)
            {
            case AnalisisConstants.AGENT_INPUT_OUTPUT_NAME:
                _model.Series.Add(new LineSeries(title)
                {
                    Smooth = true
                });
                break;

            case AnalisisConstants.SPECTRAL_DENSITY_NAME:
                _model.Series.Add(new ScatterSeries(title, OxyColor.Interpolate(OxyColors.Blue, OxyColors.Black, 1)));
                break;

            default:
                _model.Series.Add(new LineSeries(title));
                break;
            }
        }
        public static PlotModel ImageAnnotationAsBackgroundGradient()
        {
            // http://en.wikipedia.org/wiki/Chartjunk
            var model = new PlotModel {
                Title = "Using ImageAnnotations to draw a gradient backgrounds", Subtitle = "But do you really want this? This is called 'chartjunk'!", PlotMargins = new OxyThickness(60, 4, 4, 60)
            };

            model.Axes.Add(new LinearAxis {
                Position = AxisPosition.Bottom
            });
            model.Axes.Add(new LinearAxis {
                Position = AxisPosition.Left
            });

            // create a gradient image of height n
            int n          = 256;
            var imageData1 = new OxyColor[1, n];

            for (int i = 0; i < n; i++)
            {
                imageData1[0, i] = OxyColor.Interpolate(OxyColors.Blue, OxyColors.Red, i / (n - 1.0));
            }

            var image1 = OxyImage.Create(imageData1, ImageFormat.Png); // png is required for silverlight

            // or create a gradient image of height 2 (requires bitmap interpolation to be supported)
            var imageData2 = new OxyColor[1, 2];

            imageData2[0, 0] = OxyColors.Yellow;                       // top color
            imageData2[0, 1] = OxyColors.Gray;                         // bottom color

            var image2 = OxyImage.Create(imageData2, ImageFormat.Png); // png is required for silverlight

            // gradient filling the viewport
            model.Annotations.Add(new ImageAnnotation
            {
                ImageSource         = image2,
                Interpolate         = true,
                Layer               = AnnotationLayer.BelowAxes,
                X                   = new PlotLength(0, PlotLengthUnit.RelativeToViewport),
                Y                   = new PlotLength(0, PlotLengthUnit.RelativeToViewport),
                Width               = new PlotLength(1, PlotLengthUnit.RelativeToViewport),
                Height              = new PlotLength(1, PlotLengthUnit.RelativeToViewport),
                HorizontalAlignment = HorizontalAlignment.Left,
                VerticalAlignment   = VerticalAlignment.Top
            });

            // gradient filling the plot area
            model.Annotations.Add(new ImageAnnotation
            {
                ImageSource         = image1,
                Interpolate         = true,
                Layer               = AnnotationLayer.BelowAxes,
                X                   = new PlotLength(0, PlotLengthUnit.RelativeToPlotArea),
                Y                   = new PlotLength(0, PlotLengthUnit.RelativeToPlotArea),
                Width               = new PlotLength(1, PlotLengthUnit.RelativeToPlotArea),
                Height              = new PlotLength(1, PlotLengthUnit.RelativeToPlotArea),
                HorizontalAlignment = HorizontalAlignment.Left,
                VerticalAlignment   = VerticalAlignment.Top
            });

            // verify that a series is rendered above the gradients
            model.Series.Add(new FunctionSeries(Math.Sin, 0, 7, 0.01));

            return(model);
        }