Esempio n. 1
0
        public Point DataIndexToPoint(int seriesIndex, int pointIndex)
        {
            PointD     pt = new PointD(double.NaN, double.NaN);
            DataSeries ds = _chart.Data.Children[seriesIndex];

            double[,] values = ds.GetValues();
            if (values != null)
            {
                int length = values.GetLength(0);
                int num2   = values.GetLength(1);
                if ((pointIndex < 0) || (pointIndex >= num2))
                {
                    throw new ArgumentOutOfRangeException("pointIndex");
                }
                pt.Y = values[0, pointIndex];
                pt.X = (length > 1) ? values[1, pointIndex] : ((double)pointIndex);
                pt   = PointFromData(ds, pt);
            }
            return(new Point(pt.X, pt.Y));
        }
Esempio n. 2
0
        public int DataIndexFromPoint(Point pt, int seriesIndex, MeasureOption option, out double distance)
        {
            distance = double.MaxValue;
            if (seriesIndex >= _chart.Data.Children.Count)
            {
                return(-1);
            }
            DataSeries ds = _chart.Data.Children[seriesIndex];

            double[,] values = ds.GetValues();
            if (values == null)
            {
                return(-1);
            }
            PointD td  = PointToData(ds, pt);
            int    num = 0;
            double y   = td.Y;

            if (option == MeasureOption.X)
            {
                num = 1;
                y   = td.X;
            }
            else if (option == MeasureOption.XY)
            {
                num = 2;
            }
            int    num3      = -1;
            int    length    = values.GetLength(0);
            Axis   axisX     = GetAxisX(ds);
            Axis   axisY     = GetAxisY(ds);
            double actualMin = axisX.ActualMin;
            double actualMax = axisX.ActualMax;
            double num7      = axisY.ActualMin;
            double num8      = axisY.ActualMax;

            if (values != null)
            {
                int num9 = values.GetLength(1);
                for (int i = 0; i < num9; i++)
                {
                    double d     = (length > 1) ? values[1, i] : ((double)i);
                    double num12 = values[0, i];
                    if (((d >= actualMin) && (d <= actualMax)) && ((num12 >= num7) && (num12 <= num8)))
                    {
                        if (num == 2)
                        {
                            if (!double.IsNaN(d) && !double.IsNaN(num12))
                            {
                                PointD td2   = PointFromData(ds, new PointD(d, num12));
                                double num13 = td2.X - pt.X;
                                double num14 = td2.Y - pt.Y;
                                double num15 = Math.Sqrt((num13 * num13) + (num14 * num14));
                                if (num15 < distance)
                                {
                                    distance = num15;
                                    num3     = i;
                                }
                            }
                        }
                        else
                        {
                            double num16 = (num == 1) ? d : num12;
                            if (!double.IsNaN(num16))
                            {
                                double num17 = Math.Abs((double)(num16 - y));
                                if (num17 < distance)
                                {
                                    distance = num17;
                                    num3     = i;
                                }
                            }
                        }
                    }
                }
            }
            if (distance != double.MaxValue)
            {
                if (option == MeasureOption.X)
                {
                    distance = _viewport.ConvertX(distance) - _viewport.ConvertX(0.0);
                    return(num3);
                }
                if (option == MeasureOption.Y)
                {
                    distance = _viewport.ConvertY(distance) - _viewport.ConvertY(0.0);
                }
            }
            return(num3);
        }
Esempio n. 3
0
 protected void AnalyzeData(bool isStacked)
 {
     if (!_analyzed)
     {
         int num = Series.Count;
         _dataInfo.nser = num;
         _dataInfo.npts = 0;
         _dataInfo.ndim = 0;
         _dataInfo.ClearLimits();
         _dataInfo.SymbolMinSize = Size.Empty;
         _dataInfo.SymbolMaxSize = Size.Empty;
         _dataInfo.incX          = false;
         _dataInfo.hasNaN        = false;
         bool flag  = false;
         bool flag2 = IsStacked100;
         if (num > 0)
         {
             AnalyseNDimNPts();
             int        ndim      = _dataInfo.ndim;
             int        npts      = _dataInfo.npts;
             double[]   numArray  = new double[ndim];
             double[]   numArray2 = new double[ndim];
             double[]   numArray3 = new double[num];
             double[]   numArray4 = new double[num];
             int        nsg       = NStackGroups();
             StackedSum sum       = isStacked ? new StackedSum(nsg) : null;
             StackedSum sum2      = isStacked ? new StackedSum(nsg) : null;
             StackedSum sum3      = isStacked ? new StackedSum(nsg) : null;
             StackedSum sum4      = flag2 ? new StackedSum(nsg) : null;
             double     num5      = 0.0;
             double     num6      = 0.0;
             double     naN       = double.NaN;
             Size       size      = new Size();
             for (int i = 0; i < num; i++)
             {
                 DataSeries ds          = (DataSeries)Series[i];
                 bool       flag3       = ds.IsStacked;
                 bool       isClustered = ds.GetIsClustered(true);
                 int        stackGroup  = BarColumnOptions.GetStackGroup(ds);
                 if (ds is BubbleSeries)
                 {
                     Chart chart = _visual as Chart;
                     if (chart != null)
                     {
                         Size maxSize = ((BubbleSeries)ds).GetMaxSize(_dataInfo);
                         if (size.Width < maxSize.Width)
                         {
                             size.Width = maxSize.Width;
                         }
                         if (size.Height < maxSize.Height)
                         {
                             size.Height = maxSize.Height;
                         }
                         if (_dataInfo.SymbolMaxSize.IsEmpty)
                         {
                             _dataInfo.SymbolMaxSize = BubbleOptions.GetMaxSize(chart);
                         }
                         if (_dataInfo.SymbolMinSize.IsEmpty)
                         {
                             _dataInfo.SymbolMinSize = BubbleOptions.GetMinSize(chart);
                         }
                     }
                 }
                 double[,] values = ds.GetValues();
                 if (values != null)
                 {
                     int length = values.GetLength(0);
                     int num11  = values.GetLength(1);
                     if (((num11 >= 2) && (length >= 2)) && isClustered)
                     {
                         double num12 = 0.0;
                         for (int m = 0; m < (num11 - 1); m++)
                         {
                             if (!double.IsNaN(values[1, m]) && !double.IsNaN(values[1, m + 1]))
                             {
                                 num12 = Math.Abs((double)(values[1, m + 1] - values[1, m]));
                                 if (double.IsNaN(naN) || (num12 < naN))
                                 {
                                     naN = num12;
                                 }
                             }
                         }
                     }
                     ValueCoordinate[] valueCoordinates = ds.GetValueCoordinates(false);
                     for (int j = 0; j < valueCoordinates.Length; j++)
                     {
                         if ((valueCoordinates[j] == ValueCoordinate.X) && IsValidAuxAxis(ds.AxisX))
                         {
                             valueCoordinates[j] = ValueCoordinate.None;
                         }
                         else if ((valueCoordinates[j] == ValueCoordinate.Y) && IsValidAuxAxis(ds.AxisY))
                         {
                             valueCoordinates[j] = ValueCoordinate.None;
                         }
                     }
                     for (int k = 0; k < length; k++)
                     {
                         if ((k < valueCoordinates.Length) && (valueCoordinates[k] != ValueCoordinate.None))
                         {
                             for (int n = 0; n < num11; n++)
                             {
                                 double x = (length > 1) ? values[1, n] : ((double)n);
                                 if (double.IsNaN(values[k, n]))
                                 {
                                     _dataInfo.hasNaN = true;
                                 }
                                 else
                                 {
                                     if ((i == 0) && (n == 0))
                                     {
                                         numArray[k] = numArray2[k] = values[k, n];
                                     }
                                     else
                                     {
                                         if (values[k, n] > numArray[k])
                                         {
                                             numArray[k] = values[k, n];
                                         }
                                         if (values[k, n] < numArray2[k])
                                         {
                                             numArray2[k] = values[k, n];
                                         }
                                     }
                                     if (k == 0)
                                     {
                                         numArray3[i] += values[0, n];
                                         numArray4[i] += Math.Abs(values[0, n]);
                                     }
                                     else if ((flag && (k == 1)) && ((n > 0) && ((values[1, n] - values[1, n - 1]) < 0.0)))
                                     {
                                         flag = false;
                                     }
                                     if (((k == 0) && isStacked) && flag3)
                                     {
                                         if (flag2)
                                         {
                                             sum.Add(stackGroup, x, Math.Abs(values[0, n]));
                                             sum4.Add(stackGroup, x, values[0, n]);
                                         }
                                         else
                                         {
                                             sum.Add(stackGroup, x, values[0, n]);
                                             num5 = Math.Min(num5, sum[stackGroup, (double)n]);
                                             num6 = Math.Max(num6, sum[stackGroup, (double)n]);
                                         }
                                         if (values[0, n] > 0.0)
                                         {
                                             sum2.Add(stackGroup, x, values[0, n]);
                                         }
                                         else
                                         {
                                             sum3.Add(stackGroup, (double)n, values[0, n]);
                                         }
                                     }
                                 }
                             }
                             _dataInfo.UpdateLimits(valueCoordinates[k], numArray2[k], numArray[k]);
                         }
                     }
                     if (length < 2)
                     {
                         _dataInfo.UpdateLimits(ValueCoordinate.X, 0.0, (double)(num11 - 1));
                     }
                 }
             }
             if (isStacked && (npts > 0))
             {
                 if (flag2)
                 {
                     numArray2[0] = 0.0;
                     numArray[0]  = 0.0;
                     for (int num18 = 0; num18 < npts; num18++)
                     {
                         for (int num19 = 0; num19 < nsg; num19++)
                         {
                             if (sum[num19, (double)num18] != 0.0)
                             {
                                 double num20 = sum2[num19, (double)num18] / sum[num19, (double)num18];
                                 double num21 = sum3[num19, (double)num18] / sum[num19, (double)num18];
                                 if (num20 > numArray[0])
                                 {
                                     numArray[0] = num20;
                                 }
                                 if (num21 < numArray2[0])
                                 {
                                     numArray2[0] = num21;
                                 }
                             }
                         }
                     }
                 }
                 else
                 {
                     numArray[0]  = 0.0;
                     numArray2[0] = 0.0;
                     for (int num22 = 0; num22 < nsg; num22++)
                     {
                         double[] ys        = sum2.GetYs(num22);
                         double[] numArray7 = sum3.GetYs(num22);
                         for (int num23 = 0; num23 < ys.Length; num23++)
                         {
                             if (ys[num23] > numArray[0])
                             {
                                 numArray[0] = ys[num23];
                             }
                         }
                         for (int num24 = 0; num24 < numArray7.Length; num24++)
                         {
                             if (numArray7[num24] < numArray2[0])
                             {
                                 numArray2[0] = numArray7[num24];
                             }
                         }
                     }
                 }
             }
             _dataInfo.MaxVals    = numArray;
             _dataInfo.MinVals    = numArray2;
             _dataInfo.Sums       = numArray3;
             _dataInfo.SumsAbs    = numArray4;
             _dataInfo.Stacked    = sum;
             _dataInfo.DeltaX     = (double.IsNaN(naN) || (naN == 0.0)) ? 1.0 : naN;
             _dataInfo.SymbolSize = size;
             _dataInfo.incX       = flag;
         }
         _analyzed = true;
     }
 }
Esempio n. 4
0
        private void Recalculate()
        {
            if (!CanRecalculate)
            {
                return;
            }

            var seriesVariables = new List <SeriesVariable>();

            foreach (var selectedVariable in SelectedVariables)
            {
                seriesVariables.Add(
                    new SeriesVariable(
                        DataSeries.GetValues(_selectedEntities[0], selectedVariable.Name).ToArray(),
                        DataSeries.GetValues(_selectedEntities[1], selectedVariable.Name).ToArray(),
                        selectedVariable.Name,
                        selectedVariable.Preprocessor,
                        selectedVariable.Weight));
            }

            var seriesVariablesArray = seriesVariables.ToArray();

            var dtw = new Dtw(
                seriesVariablesArray,
                SelectedDistanceMeasure.Value,
                UseBoundaryConstraintStart,
                UseBoundaryConstraintEnd,
                UseSlopeConstraint ? SlopeConstraintDiagonal : (int?)null,
                UseSlopeConstraint ? SlopeConstraintAside : (int?)null,
                UseSakoeChibaMaxShift ? SakoeChibaMaxShift : (int?)null);

            if (MeasurePerformance)
            {
                var swDtwPerformance = new Stopwatch();
                swDtwPerformance.Start();

                for (int i = 0; i < 250; i++)
                {
                    var tempDtw = new Dtw(
                        seriesVariablesArray,
                        SelectedDistanceMeasure.Value,
                        UseBoundaryConstraintStart,
                        UseBoundaryConstraintEnd,
                        UseSlopeConstraint ? SlopeConstraintDiagonal : (int?)null,
                        UseSlopeConstraint ? SlopeConstraintAside : (int?)null,
                        UseSakoeChibaMaxShift ? SakoeChibaMaxShift : (int?)null);
                    var tempDtwPath = tempDtw.GetCost();
                }
                swDtwPerformance.Stop();
                OperationDuration = swDtwPerformance.Elapsed;
            }

            Dtw = dtw;

            //Dtw = new Dtw(
            //    new[] { 4.0, 4.0, 4.5, 4.5, 5.0, 5.0, 5.0, 4.5, 4.5, 4.0, 4.0, 3.5 },
            //    new[] { 1.0, 1.5, 2.0, 2.5, 3.5, 4.0, 3.0, 2.5, 2.0, 2.0, 2.0, 1.5 },
            //    SelectedDistanceMeasure.Value,
            //    UseBoundaryConstraintStart,
            //    UseBoundaryConstraintEnd,
            //    UseSlopeConstraint ? SlopeConstraintDiagonal : (int?)null,
            //    UseSlopeConstraint ? SlopeConstraintAside : (int?)null,
            //    UseSakoeChibaMaxShift ? SakoeChibaMaxShift : (int?)null);
        }
Esempio n. 5
0
        UIElement[] IView2DRenderer.Generate()
        {
            int nser = _dataInfo.nser;
            int npts = _dataInfo.npts;

            if ((nser == 0) || (npts == 0))
            {
                return(null);
            }
            IPlotElement element = null;

            if (base.Symbol is PlotElement)
            {
                element = ((PlotElement)base.Symbol).Clone() as IPlotElement;
            }
            List <UIElement> objects = new List <UIElement>();

            for (int i = 0; i < nser; i++)
            {
                DataSeries ds = (DataSeries)base.Series[i];
                ds.Children.Clear();
                objects.Add(ds);
                if (ds.SymbolShape == null)
                {
                    ds.SymbolShape = base.StyleGen.Next();
                }
                ShapeStyle symbolShape = ds.SymbolShape;
                double[,] values = ds.GetValues();
                if (values != null)
                {
                    int           length = values.GetLength(1);
                    int           num5   = values.GetLength(0);
                    RenderContext rc     = new RenderContext(this, ds, length)
                    {
                        Bounds = CoordConverter.ViewBounds
                    };
                    for (int j = 0; j < length; j++)
                    {
                        if (base.ColorScheme == ColorScheme.Point)
                        {
                            symbolShape = base.StyleGen.GetStyle(j);
                        }
                        double       y     = values[0, j];
                        double       x     = (num5 >= 2) ? values[1, j] : ((double)j);
                        bool         flag  = false;
                        Style        style = base.GetStyle(ds, i, j);
                        IPlotElement pe    = base.CreateElement(ds.Symbol, style);
                        if (pe == null)
                        {
                            pe = PlotElement.SymbolFromMarker(ds.SymbolMarker);
                            if ((pe != null) && (style != null))
                            {
                                pe.Style = style;
                            }
                        }
                        if ((pe == null) && ds.ChartType.HasValue)
                        {
                            ChartSubtype subtype = ChartTypes.GetSubtype(ds.ChartType.ToString());
                            if (subtype != null)
                            {
                                pe = base.CreateElement(subtype.Symbol, style);
                            }
                        }
                        else if (((pe == null) && ds.IsDefaultSymbol) && (element != null))
                        {
                            pe       = element;
                            pe.Style = style;
                            element  = ((PlotElement)base.Symbol).Clone() as IPlotElement;
                        }
                        if ((pe == null) && ((ds.PointLabelTemplate != null) || (ds.PointTooltipTemplate != null)))
                        {
                            DotSymbol symbol = new DotSymbol();
                            symbol.Fill   = TransparentBrush;
                            symbol.Size   = new Size(5.0, 5.0);
                            symbol.Stroke = TransparentBrush;
                            pe            = symbol;
                            flag          = true;
                        }
                        Point point   = CoordConverter.ConvertPoint(new Point(x, y));
                        Axis  auxAxis = GetAuxAxis(j);
                        if (auxAxis != null)
                        {
                            ChartViewport2D coordConverter = CoordConverter as ChartViewport2D;
                            if (coordConverter != null)
                            {
                                point = coordConverter.ConvertPoint(new Point(x, y), base.Chart.View.AxisX, auxAxis);
                            }
                        }
                        rc.SetPoint(j, point.X, point.Y);
                        if (!double.IsNaN(point.X) && !double.IsNaN(point.Y))
                        {
                            DataPoint dp       = ds.CreateDataPoint(i, j);
                            UIElement element3 = base.RenderElement(objects, pe, ds, rc, symbolShape, dp);
                            if ((element3 != null) && flag)
                            {
                                Canvas.SetZIndex(element3, 2);
                            }
                        }
                    }
                    PlotElement element4 = base.RenderConnection(ds, rc, i);
                    if (element4 != null)
                    {
                        element4.DataPoint = ds.CreateDataPoint(i, -1);
                        ds.Children.Insert(0, element4);
                    }
                }
            }
            return(objects.ToArray());
        }