<commit_before>﻿using System;
using System.Collections.Generic;
using System.Diagnostics;

namespace OxyPlot
{
    /// <summary>
    ///   This is a WPF wrapper of OxyPlot.LineSeries
    ///   LineSeries are rendered to polylines.
    ///   Note that property changes are not currently making the plot refresh itself.
    /// </summary>
    public class LineSeries : DataSeries
    {
        private static readonly double M1 = Math.Tan(Math.PI / 6);
        private static readonly double M2 = Math.Sqrt(1 + M1 * M1);
        private static readonly double M3 = Math.Tan(Math.PI / 4);

        /// <summary>
        ///   Initializes a new instance of the <see cref = "LineSeries" /> class.
        /// </summary>
        public LineSeries()
        {
            MinimumSegmentLength = 2;
            StrokeThickness = 2;
            MarkerSize = 3;
            MarkerStrokeThickness = 1;
        }

        /// <summary>
        ///   Initializes a new instance of the <see cref = "LineSeries" /> class.
        /// </summary>
        /// <param name = "title">The title.</param>
        public LineSeries(string title)
            : this()
        {
            Title = title;
        }

        /// <summary>
        ///   Initializes a new instance of the <see cref = "LineSeries" /> class.
        /// </summary>
        /// <param name = "color">The color of the line stroke.</param>
        /// <param name = "strokeThickness">The stroke thickness (optional).</param>
        /// <param name = "title">The title (optional).</param>
        public LineSeries(OxyColor color, double strokeThickness = 1, string title = null)
            : this()
        {
            Color = color;
            StrokeThickness = strokeThickness;
            Title = title;
        }

        /// <summary>
        ///   Gets or sets the background of the series.
        ///   The background area is defined by the x and y axes.
        /// </summary>
        /// <value>The background.</value>
        public OxyColor Background { get; set; }

        /// <summary>
        ///   Gets or sets the color of the curve.
        /// </summary>
        /// <value>The color.</value>
        public OxyColor Color { get; set; }

        /// <summary>
        ///   Gets or sets the thickness of the curve.
        /// </summary>
        /// <value>The stroke thickness.</value>
        public double StrokeThickness { get; set; }

        /// <summary>
        ///   Gets or sets the line style.
        /// </summary>
        /// <value>The line style.</value>
        public LineStyle LineStyle { get; set; }

        /// <summary>
        /// Gets or sets the line join.
        /// </summary>
        /// <value>The line join.</value>
        public OxyPenLineJoin LineJoin { get; set; }

        /// <summary>
        ///   Gets or sets the dashes array. 
        ///   If this is not null it overrides the LineStyle property.
        /// </summary>
        /// <value>The dashes.</value>
        public double[] Dashes { get; set; }

        /// <summary>
        ///   Gets or sets the type of the marker.
        /// </summary>
        /// <value>The type of the marker.</value>
        public MarkerType MarkerType { get; set; }

        /// <summary>
        ///   Gets or sets the size of the marker.
        /// </summary>
        /// <value>The size of the marker.</value>
        public double MarkerSize { get; set; }

        /// <summary>
        ///   Gets or sets the marker stroke.
        /// </summary>
        /// <value>The marker stroke.</value>
        public OxyColor MarkerStroke { get; set; }

        /// <summary>
        ///   Gets or sets the marker stroke thickness.
        /// </summary>
        /// <value>The marker stroke thickness.</value>
        public double MarkerStrokeThickness { get; set; }

        /// <summary>
        ///   Gets or sets the marker fill color.
        /// </summary>
        /// <value>The marker fill.</value>
        public OxyColor MarkerFill { get; set; }

        /// <summary>
        ///   Gets or sets the minimum length of the segment.
        ///   Increasing this number will increase performance, 
        ///   but make the curve less accurate.
        /// </summary>
        /// <value>The minimum length of the segment.</value>
        public double MinimumSegmentLength { get; set; }

        /// <summary>
        ///   Renders the LineSeries on the specified rendering context.
        /// </summary>
        /// <param name = "rc">The rendering context.</param>
        /// <param name = "model">The owner plot model.</param>
        public override void Render(IRenderContext rc, PlotModel model)
        {
            base.Render(rc, model);

            if (InternalPoints.Count == 0)
            {
                return;
            }

            Debug.Assert(XAxis != null && YAxis != null);

            double minDistSquared = MinimumSegmentLength * MinimumSegmentLength;

            var clipping = new CohenSutherlandClipping(
                XAxis.ScreenMin.X, XAxis.ScreenMax.X,
                YAxis.ScreenMin.Y, YAxis.ScreenMax.Y);

            int n = InternalPoints.Count;

            // Transform all points to screen coordinates
            var markerPoints = new ScreenPoint[n];
            for (int i = 0; i < n; i++)
            {
                markerPoints[i] = XAxis.Transform(new DataPoint(InternalPoints[i].x, InternalPoints[i].y), YAxis);
            }

            // spline smoothing (should only be used on small datasets)
            // todo: could do spline smoothing only on the visible part of the curve... more difficult...<commit_msg>Corrected bug in LineSeries when axis is reversed<commit_after>﻿using System;
using System.Collections.Generic;
using System.Diagnostics;

namespace OxyPlot
{
    /// <summary>
    ///   This is a WPF wrapper of OxyPlot.LineSeries
    ///   LineSeries are rendered to polylines.
    ///   Note that property changes are not currently making the plot refresh itself.
    /// </summary>
    public class LineSeries : DataSeries
    {
        private static readonly double M1 = Math.Tan(Math.PI / 6);
        private static readonly double M2 = Math.Sqrt(1 + M1 * M1);
        private static readonly double M3 = Math.Tan(Math.PI / 4);

        /// <summary>
        ///   Initializes a new instance of the <see cref = "LineSeries" /> class.
        /// </summary>
        public LineSeries()
        {
            MinimumSegmentLength = 2;
            StrokeThickness = 2;
            MarkerSize = 3;
            MarkerStrokeThickness = 1;
        }

        /// <summary>
        ///   Initializes a new instance of the <see cref = "LineSeries" /> class.
        /// </summary>
        /// <param name = "title">The title.</param>
        public LineSeries(string title)
            : this()
        {
            Title = title;
        }

        /// <summary>
        ///   Initializes a new instance of the <see cref = "LineSeries" /> class.
        /// </summary>
        /// <param name = "color">The color of the line stroke.</param>
        /// <param name = "strokeThickness">The stroke thickness (optional).</param>
        /// <param name = "title">The title (optional).</param>
        public LineSeries(OxyColor color, double strokeThickness = 1, string title = null)
            : this()
        {
            Color = color;
            StrokeThickness = strokeThickness;
            Title = title;
        }

        /// <summary>
        ///   Gets or sets the background of the series.
        ///   The background area is defined by the x and y axes.
        /// </summary>
        /// <value>The background.</value>
        public OxyColor Background { get; set; }

        /// <summary>
        ///   Gets or sets the color of the curve.
        /// </summary>
        /// <value>The color.</value>
        public OxyColor Color { get; set; }

        /// <summary>
        ///   Gets or sets the thickness of the curve.
        /// </summary>
        /// <value>The stroke thickness.</value>
        public double StrokeThickness { get; set; }

        /// <summary>
        ///   Gets or sets the line style.
        /// </summary>
        /// <value>The line style.</value>
        public LineStyle LineStyle { get; set; }

        /// <summary>
        /// Gets or sets the line join.
        /// </summary>
        /// <value>The line join.</value>
        public OxyPenLineJoin LineJoin { get; set; }

        /// <summary>
        ///   Gets or sets the dashes array. 
        ///   If this is not null it overrides the LineStyle property.
        /// </summary>
        /// <value>The dashes.</value>
        public double[] Dashes { get; set; }

        /// <summary>
        ///   Gets or sets the type of the marker.
        /// </summary>
        /// <value>The type of the marker.</value>
        public MarkerType MarkerType { get; set; }

        /// <summary>
        ///   Gets or sets the size of the marker.
        /// </summary>
        /// <value>The size of the marker.</value>
        public double MarkerSize { get; set; }

        /// <summary>
        ///   Gets or sets the marker stroke.
        /// </summary>
        /// <value>The marker stroke.</value>
        public OxyColor MarkerStroke { get; set; }

        /// <summary>
        ///   Gets or sets the marker stroke thickness.
        /// </summary>
        /// <value>The marker stroke thickness.</value>
        public double MarkerStrokeThickness { get; set; }

        /// <summary>
        ///   Gets or sets the marker fill color.
        /// </summary>
        /// <value>The marker fill.</value>
        public OxyColor MarkerFill { get; set; }

        /// <summary>
        ///   Gets or sets the minimum length of the segment.
        ///   Increasing this number will increase performance, 
        ///   but make the curve less accurate.
        /// </summary>
        /// <value>The minimum length of the segment.</value>
        public double MinimumSegmentLength { get; set; }

        /// <summary>
        ///   Renders the LineSeries on the specified rendering context.
        /// </summary>
        /// <param name = "rc">The rendering context.</param>
        /// <param name = "model">The owner plot model.</param>
        public override void Render(IRenderContext rc, PlotModel model)
        {
            base.Render(rc, model);

            if (InternalPoints.Count == 0)
            {
                return;
            }

            Debug.Assert(XAxis != null && YAxis != null);

            double minDistSquared = MinimumSegmentLength * MinimumSegmentLength;

            var clipping = new CohenSutherlandClipping(
                Math.Min(XAxis.ScreenMin.X, XAxis.ScreenMax.X),
                Math.Max(XAxis.ScreenMin.X, XAxis.ScreenMax.X),
                Math.Min(YAxis.ScreenMin.Y, YAxis.ScreenMax.Y),
                Math.Max(YAxis.ScreenMin.Y, YAxis.ScreenMax.Y));

            int n = InternalPoints.Count;

            // Transform all points to screen coordinates
            var markerPoints = new ScreenPoint[n];
            for (int i = 0; i < n; i++)
            {
                markerPoints[i] = XAxis.Transform(new DataPoint(InternalPoints[i].x, InternalPoints[i].y), YAxis);
            }

            // spline smoothing (should only be used on small datasets)
            // todo: could do spline smoothing only on the visible part of the curve... more difficult...
{'fraction_non_alphanumeric': 0.12358375457556214, 'fraction_numerical': 0.0026146069374237404, 'mean_word_length': 1.5488671701466015, 'pattern_counts': {'":': 0, '<': 151, '<?xml version=': 0, '>': 149, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '109573', 'n_tokens_mistral': 3096, 'n_tokens_neox': 2989, 'n_words': 1000}