Ejemplo n.º 1
0
        private void CalcGridSize()
        {
            var xmax = XValues.Max();
            var ymax = YValues.Max();
            var xmin = XValues.Min();
            var ymin = YValues.Min();

            // Calculate axis range
            var xrange = Math.Abs(xmax - xmin);
            var yrange = Math.Abs(ymax - ymin);

            if (xrange > yrange)
            {
                // Determine spacing with nx points grid
                Nx = 200;
                Dx = xrange / (Nx - 1);

                // Determine number of y grid so that the space is equal
                Ny = Convert.ToInt32(Math.Ceiling(yrange / Dx));
                Dy = yrange / (Ny - 1);
            }
            else
            {
                Ny = 200;
                Dy = yrange / (Ny - 1);

                Nx = Convert.ToInt32(Math.Ceiling(xrange / Dy));
                Dx = xrange / (Nx - 1);
            }
        }
Ejemplo n.º 2
0
        //Constructor generates the values for all the values in the class, including the equation
        public StraightFit(ObservableCollection <CoordPoint> coordinates, ChartBounds CurrentBounds, Canvas currentCanvas)
        {
            this.currentCanvas = currentCanvas;
            this.maxBoundsX    = CurrentBounds.MaxBoundsX;
            this.minBoundsX    = CurrentBounds.MinBoundsX;
            this.maxBoundsY    = CurrentBounds.MaxBoundsY;
            this.minBoundsY    = CurrentBounds.MinBoundsY;

            this.coordinates = coordinates;
            for (int i = 0; i < coordinates.Count; i++)
            {
                XValues.Add(coordinates[i].X);
            }

            for (int i = 0; i < coordinates.Count; i++)
            {
                YValues.Add(coordinates[i].Y);
            }

            xBar = Mean(XValues);
            yBar = Mean(YValues);

            Sxy = Variance(XValues, YValues);

            Sxx = Variance(XValues, XValues);

            Gradient = Sxy / Sxx;

            YIntercept = yBar - (Gradient * xBar);
        }
        public ExponentialIncreaseFit(ObservableCollection <CoordPoint> coordinates, Canvas currentCanvas, ChartBounds CurrentBounds, double C)
        {
            this.currentCanvas = currentCanvas;
            this.maxBoundsX    = CurrentBounds.MaxBoundsX;
            this.minBoundsX    = CurrentBounds.MinBoundsX;
            this.maxBoundsY    = CurrentBounds.MaxBoundsY;
            this.minBoundsY    = CurrentBounds.MinBoundsY;
            this.coordinates   = coordinates;
            this.C             = C;

            // Puts the X and Y values into their on list so they can be calculated on
            for (int i = 0; i < coordinates.Count; i++)
            {
                XValues.Add(coordinates[i].X);
            }

            for (int i = 0; i < coordinates.Count; i++)
            {
                YValues.Add((((coordinates[i].Y / C) - 1) * -1));
            }

            // Sets the curve values
            A = GetA();

            B = GetB();
        }
Ejemplo n.º 4
0
 private void PointAway(out double xMax, out double yMax, out double xMin, out double yMin)
 {
     xMax = XRange.Max();
     yMax = YValues.Max();
     xMin = XRange.Min();
     yMin = YValues.Min();
 }
Ejemplo n.º 5
0
 /// <summary>
 /// Called when DataSource property changed
 /// </summary>
 /// <param name="oldValue"></param>
 /// <param name="newValue"></param>
 protected override void OnDataSourceChanged(IEnumerable oldValue, IEnumerable newValue)
 {
     YValues.Clear();
     sizeValues.Clear();
     GeneratePoints(new string[] { YBindingPath, Size }, YValues, sizeValues);
     this.UpdateArea();
 }
Ejemplo n.º 6
0
 /// <summary>
 /// Handles the CollectionChanged event of the PointsSource control.
 /// </summary>
 /// <param name="sender">The source of the event.</param>
 /// <param name="e">The <see cref="NotifyCollectionChangedEventArgs"/> instance containing the event data.</param>
 void PointsSource_CollectionChanged(object sender, NotifyCollectionChangedEventArgs e)
 {
     if (e.Action == NotifyCollectionChangedAction.Add)
     {
         double xValue = GetReflectionValue(XPath, PointsSource, XValues.Count + 1);
         double yValue = GetReflectionValue(YPath, PointsSource, YValues.Count + 1);
         XValues.Add(xValue);
         YValues.Add(xValue);
         Points.Add(new ChartPoint()
         {
             XValue = xValue, YValue = yValue
         });
     }
     else if (e.Action == NotifyCollectionChangedAction.Remove)
     {
         IList  oldItems  = e.OldItems;
         double oldXValue = GetReflectionValueFromItem(XPath, oldItems[0]);
         int    index     = XValues.IndexOf(oldXValue);
         XValues.RemoveAt(index);
         YValues.RemoveAt(index);
         Points.RemoveAt(index);
     }
     else if (e.Action == NotifyCollectionChangedAction.Reset)
     {
         Points.Clear();
         GeneratePointsFromSource();
     }
 }
Ejemplo n.º 7
0
 protected override void OnBindingPathChanged(DependencyPropertyChangedEventArgs args)
 {
     HorizontalCustomValues.Clear();
     VerticalCustomValues.Clear();
     YValues.Clear();
     base.OnBindingPathChanged(args);
 }
        private void CalculateXOutputValues(Size constraint)
        {
            YValues.Clear();
            double start_width    = constraint.Width - _largestLabelSize.Width / 2;
            double pixelIncrement = CalculatePixelIncrements(constraint, _largestLabelSize);
            double lowPixel       = start_width - (InternalChildren.Count - 1) * pixelIncrement;
            double highPixel      = start_width;

            if (highPixel < lowPixel)
            {
                return;
            }
            for (int i = 0; i < DataValues.Count; i++)
            {
                double output = lowPixel + ((highPixel - lowPixel) / (_highValue - _lowValue)) * (DataValues[i] - _lowValue);
                YValues.Add(output);
            }
            if (_startsAtZero || (!_allNegativeValues && !_allPositiveValues))
            {
                Origin = lowPixel + ((highPixel - lowPixel) / (_highValue - _lowValue)) * (0.0 - _lowValue);
            }
            else if (!_startsAtZero && _allPositiveValues)
            {
                Origin = lowPixel;
            }
            else
            {
                Origin = highPixel;
            }
        }
Ejemplo n.º 9
0
 /// <summary>
 /// Called when DataSource property changed
 /// </summary>
 /// <param name="oldValue"></param>
 /// <param name="newValue"></param>
 protected override void OnDataSourceChanged(IEnumerable oldValue, IEnumerable newValue)
 {
     YValues.Clear();
     Segment = null;
     GeneratePoints(new string[] { YBindingPath }, YValues);
     isPointValidated = false;
     this.UpdateArea();
 }
Ejemplo n.º 10
0
 private void Window_Loaded(object sender, RoutedEventArgs e)
 {
     for (int i = 0; i < logicRef.getBSugarData(SocSecNb).Count; i++)
     {
         YValues.Add(logicRef.getBSugarData(SocSecNb)[i].BloodSugar);
         XValues.Add(Convert.ToString(logicRef.getBSugarData(SocSecNb)[i].Date));
     }
 }
Ejemplo n.º 11
0
        /// <summary>
        /// Creates the segments of FastLineSeries.
        /// </summary>
        public override void CreateSegments()
        {
            if (GroupedSeriesYValues != null && GroupedSeriesYValues[0].Contains(double.NaN))
            {
                List <List <double> > yValList;
                List <List <double> > xValList;
                this.CreateEmptyPointSegments(GroupedSeriesYValues[0], out yValList, out xValList);
            }
            else if (YValues.Contains(double.NaN))
            {
                List <List <double> > yValList;
                List <List <double> > xValList;
                this.CreateEmptyPointSegments(YValues, out yValList, out xValList);
            }
            else
            {
                bool isGrouping = this.ActualXAxis is CategoryAxis ? (this.ActualXAxis as CategoryAxis).IsIndexed : true;
                if (!isGrouping)
                {
                    xValues = GroupedXValuesIndexes;
                }
                else
                {
                    xValues = (ActualXValues is IList <double> && !IsIndexed) ? ActualXValues as IList <double> : GetXValues();
                }
                if (!isGrouping)
                {
                    Segments.Clear();
                    Adornments.Clear();

                    if (Segment == null || Segments.Count == 0)
                    {
                        FastLineSegment segment = new FastLineSegment(xValues, GroupedSeriesYValues[0], this);
                        Segment = segment;
                        Segments.Add(segment);
                    }
                }
                else
                {
                    ClearUnUsedAdornments(this.DataCount);

                    if (Segment == null || Segments.Count == 0)
                    {
                        FastLineSegment segment = new FastLineSegment(xValues, YValues, this);
                        Segment = segment;
                        Segments.Add(segment);
                    }
                    else if (ActualXValues != null)
                    {
                        Segment.SetData(xValues, YValues);
                        (Segment as FastLineSegment).SetRange();
                        Segment.Item = ActualData;
                    }
                }

                isAdornmentPending = true;
            }
        }
Ejemplo n.º 12
0
 public SpectrumData(float res, WaveData wave)
 {
     WaveRpm    = wave.Rpm;
     Resolution = res;
     ChannelId  = wave.ChannelId;
     YValues    = Array.ConvertAll(NadaMath.PositiveFFT(wave.AsyncData), x => (float)x);
     XValues    = YValues.Select((x, i) => (float)i / res).ToArray();
     TimeStamp  = wave.DateTime;
 }
Ejemplo n.º 13
0
        private void AppendYValues()
        {
            var yValues = new YValues();

            var numberReferenceBuilder = new NumberReferenceBuilder(this.Options.YNumberReferenceOptions);

            yValues.NumberReference = numberReferenceBuilder.Build();

            scatterChartSeries.Append(yValues);
        }
Ejemplo n.º 14
0
        private void CalculateError()
        {
            var abs = YValues.Zip(YAproximation, (Yv, Ya) => Math.Abs(Yv - Ya));

            var absError = abs.Sum() / fourierSeries.N;

            fourierSeries.file.Write($"\nсередня абсолютна похибка вимірювань {Math.Round(absError * 0.1, 5)}");

            var relativeError = abs.Zip(YValues, (a, Yv) => a / Yv).Average() * 100;

            fourierSeries.file.Write($"\nсередня відносна похибка вимірювань {Math.Round(relativeError, 5)} %");
        }
Ejemplo n.º 15
0
        public IList <DataPoint> ToChartDataSource()
        {
            if (XValues == null)
            {
                throw new InvalidOperationException("XValues is missing.");
            }
            if (YValues == null)
            {
                throw new InvalidOperationException("XValues is missing");
            }

            // Extract x values from XValues collection.
            var xValueExtractor = new DoubleValueExtractor
            {
                Collection = XValues,
                Culture    = Culture,
                ValuePath  = XValuePath,
            };
            var xValues = xValueExtractor.Extract();

            // Extract y values from YValues collection.
            var yValueExtractor = new DoubleValueExtractor
            {
                Collection = YValues,
                Culture    = Culture,
                ValuePath  = YValuePath,
            };
            var yValues = yValueExtractor.Extract();

            Debug.Assert(xValues.Count == yValues.Count, "Number of x values in data source does not match the number of y values?!");

            var chartDataSource    = new DataPointCollection();
            int index              = 0;
            int numberOfDataPoints = Math.Min(xValues.Count, yValues.Count);
            var xValuesEnumerator  = XValues.GetEnumerator();
            var yValuesEnumerator  = YValues.GetEnumerator();

            while (index < numberOfDataPoints)
            {
                xValuesEnumerator.MoveNext();
                yValuesEnumerator.MoveNext();
                var dataPoint = new DataPoint
                {
                    X           = xValues[index],
                    Y           = yValues[index],
                    DataContext = new CompositeData(xValuesEnumerator.Current, yValuesEnumerator.Current)
                };
                chartDataSource.Add(dataPoint);
                index++;
            }

            return(chartDataSource);
        }
Ejemplo n.º 16
0
        private void XYLineChartNodeModel_PortDisconnected(PortModel port)
        {
            // Clear UI when a input port is disconnected
            if (port.PortType == PortType.Input && this.State == ElementState.Active)
            {
                Labels.Clear();
                XValues.Clear();
                YValues.Clear();
                Colors.Clear();

                RaisePropertyChanged("DataUpdated");
            }
        }
Ejemplo n.º 17
0
 public void AddPoint(double x, double y)
 {
     if (XValues == null)
     {
         XValues = new ScatterPlotValues(new List <double>());
     }
     if (YValues == null)
     {
         YValues = new ScatterPlotValues(new List <double>());
     }
     XValues.AddValue(x);
     YValues.AddValue(y);
     Adjust(x, y);
 }
Ejemplo n.º 18
0
        /// <summary>
        /// To calculate the segments if the pyramid mode is surface
        /// </summary>
        private void CalculateSurfaceSegments(double sumValues, int count, double gapHeight, List <double> xValues)
        {
            var toggledYValues = YValues.ToList();

            if (ToggledLegendIndex.Count > 0)
            {
                toggledYValues = GetYValues();
            }
            currY = 0;
            double[] y      = new double[count];
            double[] height = new double[count];
            double   preSum = GetSurfaceHeight(0, sumValues);

            for (int i = 0; i < count; i++)
            {
                y[i]      = currY;
                height[i] = GetSurfaceHeight(currY, Math.Abs(double.IsNaN(toggledYValues[i]) ? 0 : toggledYValues[i]));
                currY    += height[i] + gapHeight * preSum;
            }

            double coef = 1 / (currY - gapHeight * preSum);

            for (int i = 0; i < count; i++)
            {
                double currHeight = 0;
                if (!double.IsNaN(YValues[i]))
                {
                    currHeight = coef * y[i];
                    PyramidSegment pyramidSegment = new PyramidSegment(currHeight, coef * height[i], this.ExplodeOffset, this, i == this.ExplodeIndex || this.ExplodeAll ? true : false);
                    pyramidSegment.Item  = ActualData[i];
                    pyramidSegment.XData = xValues[i];
                    pyramidSegment.YData = Math.Abs(YValues[i]);
                    if (ToggledLegendIndex.Contains(i))
                    {
                        pyramidSegment.IsSegmentVisible = false;
                    }
                    else
                    {
                        pyramidSegment.IsSegmentVisible = true;
                    }
                    this.Segments.Add(pyramidSegment);

                    if (AdornmentsInfo != null)
                    {
                        Adornments.Add(this.CreateAdornment(this, xValues[i], toggledYValues[i], 0, double.IsNaN(currHeight) ? 1 - height[i] / 2 : currHeight + coef * height[i] / 2));
                    }
                }
            }
        }
Ejemplo n.º 19
0
        public void ReadyControl()
        {
            ChartArea.Children.Clear();
            Legend.Children.Clear();

            _maxValue     = YValues.Max(x => x.Max) > 0 ? CanvasHelper.GetGridLineMax(YValues.Max(x => x.Max)) : 10;
            _xLabelsCount = XLabels.Count > 0 ? XLabels.Count : 1;
            _helper       = new CanvasHelper(new Point(0, 0), new Point(_margin, ChartGridHeight), new Point(_xLabelsCount, _maxValue), new Point(ChartAreaWidth, 0));

            DrawBackground();
            DrawGridLines();
            DrawDataPoint();
            DrawXAxis();
            DrawYAxis();
            DrawLegend();
        }
Ejemplo n.º 20
0
        /// <summary>
        /// Updates the chart.
        /// </summary>
        /// <param name="chart">The chart.</param>
        /// <param name="sheetName">Name of the sheet.</param>
        protected override void UpdateChart(OpenXmlCompositeElement chart, string sheetName)
        {
            if (chart != null)
            {
                chart.RemoveAllChildren <ScatterChartSeries>();
                ScatterChartSeries scatterChartSeries = chart.AppendChild <ScatterChartSeries>(new ScatterChartSeries());

                Outline outline = new Outline()
                {
                    Width = 28575
                };
                NoFill noFill = new NoFill();
                outline.Append(noFill);
                scatterChartSeries.ChartShapeProperties = new ChartShapeProperties(outline);

                UpdateSeriesText(sheetName, scatterChartSeries, "B", 1, chartData.yColumnName);

                XValues xValues = scatterChartSeries.AppendChild <XValues>(new XValues());
                YValues yValues = scatterChartSeries.AppendChild <YValues>(new YValues());

                NumberReference referenceX = CreateNumberReference(xValues, sheetName + "!$A$2:$A$" + (chartData.Count + 1).ToString());
                NumberReference referenceY = CreateNumberReference(yValues, sheetName + "!$B$2:$B$" + (chartData.Count + 1).ToString());

                NumberingCache ncX;
                PointCount     ptXCount;
                NumberingCache ncY;
                PointCount     ptYCount;

                SetNumberingCache(referenceX, out ncX, out ptXCount);
                SetNumberingCache(referenceY, out ncY, out ptYCount);

                int rowIndex = 0;

                foreach (var xToY in chartData.xValToYValMap)
                {
                    AddNumericPoint(ncX, ptXCount, rowIndex, xToY.Key.ToString());
                    AddNumericPoint(ncY, ptYCount, rowIndex, xToY.Value.ToString());
                    rowIndex += 1;
                }
            }
        }
        private void CalculateYOutputValues(Size constraint)
        {
            YValues.Clear();
            double start_val, lowPixel, highPixel;
            double pixelIncrement = CalculatePixelIncrements(constraint, _largestLabelSize);

            if (Orientation.Equals(Orientation.Vertical))
            {
                start_val = constraint.Height - _largestLabelSize.Height / 2;
                lowPixel  = start_val - (InternalChildren.Count - 1) * pixelIncrement;
                highPixel = start_val;
            }
            else
            {
                start_val = constraint.Width - _largestLabelSize.Width / 2;
                lowPixel  = start_val - (InternalChildren.Count - 1) * pixelIncrement;
                highPixel = start_val;
            }
            if (highPixel < lowPixel)
            {
                return;
            }
            for (int i = 0; i < DataValues.Count; i++)
            {
                double outVal = highPixel - ((highPixel - lowPixel) / (_highValue - _lowValue)) * (DataValues[i] - _lowValue);
                YValues.Add(outVal);
            }
            if (_startsAtZero || (!_allNegativeValues && !_allPositiveValues))
            {
                Origin = highPixel - ((highPixel - lowPixel) / (_highValue - _lowValue)) * (0.0 - _lowValue);
            }
            else if (!_startsAtZero && _allPositiveValues)
            {
                Origin = highPixel;
            }
            else
            {
                Origin = lowPixel;
            }
        }
Ejemplo n.º 22
0
 /// <summary>
 /// Method for Generate Points for XYDataSeries
 /// </summary>
 protected internal override void GeneratePoints()
 {
     HorizontalCustomValues.Clear();
     VerticalCustomValues.Clear();
     YValues.Clear();
     if (YBindingPath != null && HorizontalErrorPath != null && VerticalErrorPath != null)
     {
         GeneratePoints(new[] { YBindingPath, HorizontalErrorPath, VerticalErrorPath }, YValues, HorizontalCustomValues, VerticalCustomValues);
     }
     else if (YBindingPath != null && HorizontalErrorPath != null)
     {
         GeneratePoints(new[] { YBindingPath, HorizontalErrorPath }, YValues, HorizontalCustomValues);
     }
     else if (YBindingPath != null && VerticalErrorPath != null)
     {
         GeneratePoints(new[] { YBindingPath, VerticalErrorPath }, YValues, VerticalCustomValues);
     }
     else if (YBindingPath != null)
     {
         GeneratePoints(new[] { YBindingPath }, YValues);
     }
 }
Ejemplo n.º 23
0
        /// <summary>
        /// To calculate the segments if the pyramid mode is linear
        /// </summary>
        private void CalculateLinearSegments(double sumValues, double gapRatio, int count, List <double> xValues)
        {
            var toggledYValues = YValues.ToList();

            if (ToggledLegendIndex.Count > 0)
            {
                toggledYValues = GetYValues();
            }
            currY = 0;
            double coef = 1d / (sumValues * (1 + gapRatio / (1 - gapRatio)));

            for (int i = 0; i < count; i++)
            {
                double height = 0;
                if (!double.IsNaN(YValues[i]))
                {
                    height = coef * Math.Abs(double.IsNaN(toggledYValues[i]) ? 0 : toggledYValues[i]);
                    PyramidSegment pyramidSegment = new PyramidSegment(currY, height, this.ExplodeOffset, this, i == ExplodeIndex || this.ExplodeAll ? true : false);
                    pyramidSegment.Item  = ActualData[i];
                    pyramidSegment.XData = xValues[i];
                    pyramidSegment.YData = Math.Abs(YValues[i]);
                    if (ToggledLegendIndex.Contains(i))
                    {
                        pyramidSegment.IsSegmentVisible = false;
                    }
                    else
                    {
                        pyramidSegment.IsSegmentVisible = true;
                    }
                    this.Segments.Add(pyramidSegment);
                    currY += (gapRatio / (count - 1)) + height;
                    if (AdornmentsInfo != null)
                    {
                        Adornments.Add(this.CreateAdornment(this, xValues[i], toggledYValues[i], 0, double.IsNaN(currY) ? 1 - height / 2 : currY - height / 2));
                        Adornments[Segments.Count - 1].Item = ActualData[i];
                    }
                }
            }
        }
Ejemplo n.º 24
0
        public void addData(double x, double y, double z)
        {
            lock (_lockObj)
            {
                XValues.Add(new DataPoint(XValues.Count, x));
                YValues.Add(new DataPoint(YValues.Count, y));
                ZValues.Add(new DataPoint(ZValues.Count, z));

                if (MaxCount == ZValues.Count)
                {
                    XValues.RemoveAt(0);
                    reNumbering(XValues);

                    YValues.RemoveAt(0);
                    reNumbering(YValues);

                    ZValues.RemoveAt(0);
                    reNumbering(ZValues);
                }

                parseData();
            }
        }
Ejemplo n.º 25
0
        /// <summary>
        /// Called when DataSource property changed
        /// </summary>
        /// <param name="oldValue"></param>
        /// <param name="newValue"></param>
        protected override void OnDataSourceChanged(IEnumerable oldValue, IEnumerable newValue)
        {
            HorizontalCustomValues.Clear();
            VerticalCustomValues.Clear();
            YValues.Clear();
            if (YBindingPath != null && HorizontalErrorPath != null && VerticalErrorPath != null)
            {
                GeneratePoints(new[] { YBindingPath, HorizontalErrorPath, VerticalErrorPath }, YValues, HorizontalCustomValues, VerticalCustomValues);
            }
            else if (YBindingPath != null && HorizontalErrorPath != null)
            {
                GeneratePoints(new[] { YBindingPath, HorizontalErrorPath }, YValues, HorizontalCustomValues);
            }
            else if (YBindingPath != null && VerticalErrorPath != null)
            {
                GeneratePoints(new[] { YBindingPath, VerticalErrorPath }, YValues, VerticalCustomValues);
            }
            else if (YBindingPath != null)
            {
                GeneratePoints(new[] { YBindingPath }, YValues);
            }

            this.UpdateArea();
        }
Ejemplo n.º 26
0
 protected override void OnBindingPathChanged(DependencyPropertyChangedEventArgs args)
 {
     YValues.Clear();
     Segment = null;
     base.OnBindingPathChanged(args);
 }
Ejemplo n.º 27
0
        internal override void UpdateTooltip(object originalSource)
        {
            if (ShowTooltip)
            {
                FrameworkElement element      = originalSource as FrameworkElement;
                object           chartSegment = null;
                int index = -1;
                if (element != null)
                {
                    if (element.Tag is ChartSegment)
                    {
                        chartSegment = element.Tag;
                    }
                    else if (Segments.Count > 0)
                    {
                        chartSegment = Segments[0];
                    }
                    else
                    {
                        // WPF-28526- Tooltip not shown when set the single data point with adornments for continuous series.
                        index        = ChartExtensionUtils.GetAdornmentIndex(element);
                        chartSegment = index != -1 ? new StackingAreaSegment() : null;
                    }
                }

                if (chartSegment == null)
                {
                    return;
                }

                SetTooltipDuration();
                var    canvas        = this.Area.GetAdorningCanvas();
                double xVal          = 0;
                double yVal          = 0;
                double stackedYValue = double.NaN;
                object data          = null;
                index = 0;

                if (this.Area.SeriesClipRect.Contains(mousePos))
                {
                    var point = new Point(
                        mousePos.X - this.Area.SeriesClipRect.Left,
                        mousePos.Y - this.Area.SeriesClipRect.Top);

                    this.FindNearestChartPoint(point, out xVal, out yVal, out stackedYValue);
                    if (double.IsNaN(xVal))
                    {
                        return;
                    }
                    if (ActualXAxis is CategoryAxis && (ActualXAxis as CategoryAxis).IsIndexed)
                    {
                        index = YValues.IndexOf(yVal);
                    }
                    else
                    {
                        index = this.GetXValues().IndexOf(xVal);
                    }
                    foreach (var series in Area.Series)
                    {
                        if (series == this)
                        {
                            data = this.ActualData[index];
                        }
                    }
                }

                if (data == null)
                {
                    return;               // To ignore tooltip when mousePos is not inside the SeriesClipRect.
                }
                if (this.Area.Tooltip == null)
                {
                    this.Area.Tooltip = new ChartTooltip();
                }
                var chartTooltip = this.Area.Tooltip as ChartTooltip;

                var stackingAreaSegment = chartSegment as StackingAreaSegment;
                stackingAreaSegment.Item  = data;
                stackingAreaSegment.XData = xVal;
                stackingAreaSegment.YData = yVal;
                if (chartTooltip != null)
                {
                    if (canvas.Children.Count == 0 || (canvas.Children.Count > 0 && !IsTooltipAvailable(canvas)))
                    {
                        chartTooltip.Content = chartSegment;
                        if (chartTooltip.Content == null)
                        {
                            return;
                        }

                        if (ChartTooltip.GetInitialShowDelay(this) == 0)
                        {
                            canvas.Children.Add(chartTooltip);
                        }

                        chartTooltip.ContentTemplate = this.GetTooltipTemplate();
                        AddTooltip();

                        if (ChartTooltip.GetEnableAnimation(this))
                        {
                            SetDoubleAnimation(chartTooltip);
                            storyBoard.Children.Add(leftDoubleAnimation);
                            storyBoard.Children.Add(topDoubleAnimation);
                            Canvas.SetLeft(chartTooltip, chartTooltip.LeftOffset);
                            Canvas.SetTop(chartTooltip, chartTooltip.TopOffset);

                            _stopwatch.Start();
                        }
                        else
                        {
                            Canvas.SetLeft(chartTooltip, chartTooltip.LeftOffset);
                            Canvas.SetTop(chartTooltip, chartTooltip.TopOffset);

                            _stopwatch.Start();
                        }
                    }
                    else
                    {
                        foreach (var child in canvas.Children)
                        {
                            var tooltip = child as ChartTooltip;
                            if (tooltip != null)
                            {
                                chartTooltip = tooltip;
                            }
                        }

                        chartTooltip.Content = chartSegment;

                        if (chartTooltip.Content == null)
                        {
                            RemoveTooltip();
                            return;
                        }

                        AddTooltip();
#if NETFX_CORE
                        if (_stopwatch.ElapsedMilliseconds > 100)
                        {
#endif
                        if (ChartTooltip.GetEnableAnimation(this))
                        {
                            _stopwatch.Restart();

                            if (leftDoubleAnimation == null || topDoubleAnimation == null || storyBoard == null)
                            {
                                SetDoubleAnimation(chartTooltip);
                            }
                            else
                            {
                                leftDoubleAnimation.To = chartTooltip.LeftOffset;
                                topDoubleAnimation.To  = chartTooltip.TopOffset;
                                storyBoard.Begin();
                            }
                        }
                        else
                        {
                            _stopwatch.Restart();

                            Canvas.SetLeft(chartTooltip, chartTooltip.LeftOffset);
                            Canvas.SetTop(chartTooltip, chartTooltip.TopOffset);
                        }
#if NETFX_CORE
                    }
                    else if (EnableAnimation == false)
                    {
                        Canvas.SetLeft(chartTooltip, chartTooltip.LeftOffset);
                        Canvas.SetTop(chartTooltip, chartTooltip.TopOffset);
                    }
#endif
                    }
                }
            }
        }
Ejemplo n.º 28
0
 public void ClearAll()
 {
     XValues.Clear();
     YValues.Clear();
     ZValues.Clear();
 }
Ejemplo n.º 29
0
        /// <summary>
        /// Creates the segments of LineSeries3D.
        /// </summary>
        public override void CreateSegments()
        {
            List <double> xValues    = null;
            bool          isGrouping = this.ActualXAxis is CategoryAxis3D && !(this.ActualXAxis as CategoryAxis3D).IsIndexed;

            if (isGrouping)
            {
                xValues = this.GroupedXValuesIndexes;
            }
            else
            {
                xValues = this.GetXValues();
            }

            if (xValues == null)
            {
                return;
            }

            var depthInfo = GetSegmentDepth(this.Area.Depth);

            if (isGrouping)
            {
                Segments.Clear();
                Adornments.Clear();
                if (this.GroupedSeriesYValues != null && GroupedSeriesYValues[0].Contains(double.NaN))
                {
                    List <List <double> > yValList;
                    List <List <double> > xValList;
                    this.CreateEmptyPointSegments(this.GroupedSeriesYValues[0], out yValList, out xValList);
                }
                else if (xValues != null)
                {
                    if (this.Segment == null || Segments.Count == 0)
                    {
                        this.Segment = new LineSegment3D(xValues, GroupedSeriesYValues[0], depthInfo.Start, depthInfo.End, this);
                        this.Segment.SetData(xValues, this.GroupedSeriesYValues[0], depthInfo.Start, depthInfo.End);
                        Segments.Add(this.Segment);
                    }
                }

                for (var i = 0; i < xValues.Count; i++)
                {
                    if (this.AdornmentsInfo != null)
                    {
                        this.AddAdornments(xValues[i], this.GroupedSeriesYValues[0][i], i, depthInfo.Start);
                    }
                }
            }
            else
            {
                this.ClearUnUsedSegments(this.DataCount);
                this.ClearUnUsedAdornments(this.DataCount);
                if (YValues.Contains(double.NaN))
                {
                    List <List <double> > yValList;
                    List <List <double> > xValList;
                    this.CreateEmptyPointSegments(this.YValues, out yValList, out xValList);
                }
                else if (xValues != null)
                {
                    if (this.Segment == null || Segments.Count == 0)
                    {
                        this.Segment = new LineSegment3D(xValues, YValues, depthInfo.Start, depthInfo.End, this);
                        this.Segment.SetData(xValues, this.YValues, depthInfo.Start, depthInfo.End);
                        Segments.Add(this.Segment);
                    }
                    else
                    {
                        this.Segment.SetData(xValues, this.YValues, depthInfo.Start, depthInfo.End);
                    }
                }

                for (var i = 0; i < this.DataCount; i++)
                {
                    if (this.AdornmentsInfo != null)
                    {
                        this.AddAdornments(xValues[i], this.YValues[i], i, depthInfo.Start);
                    }
                }
            }
        }
Ejemplo n.º 30
0
        /// <summary>
        /// Animates the series.
        /// </summary>
        internal override void Animate()
        {
            int i = 0;

            // WPF-25124 Animation not working properly when resize the window.
            if (this.AnimationStoryboard != null)
            {
                AnimationStoryboard.Stop();
                if (!this.canAnimate)
                {
                    this.ResetAdornmentAnimationState();
                    return;
                }
            }

            this.AnimationStoryboard = new Storyboard();
            foreach (LineSegment3D segment in this.Segments)
            {
                var dblAnimationKeyFrames = new DoubleAnimationUsingKeyFrames();
                var min      = YValues.Min();
                var keyFrame = new SplineDoubleKeyFrame
                {
                    KeyTime = KeyTime.FromTimeSpan(TimeSpan.FromSeconds(0)),
                    Value   = double.IsNaN(min) ? YValues.Where(e => !double.IsNaN(e)).Min() : min
                };
                dblAnimationKeyFrames.KeyFrames.Add(keyFrame);
                keyFrame = new SplineDoubleKeyFrame
                {
                    KeyTime = KeyTime.FromTimeSpan(AnimationDuration),
                    Value   = YValues.Max()
                };
                var keySpline = new KeySpline
                {
                    ControlPoint1 = new Point(0.64, 0.84),
                    ControlPoint2 = new Point(0.67, 0.95)
                };
                keyFrame.KeySpline = keySpline;
                dblAnimationKeyFrames.KeyFrames.Add(keyFrame);
                Storyboard.SetTargetProperty(dblAnimationKeyFrames, "LineSegment3D.Y");
                dblAnimationKeyFrames.EnableDependentAnimation = true;
                Storyboard.SetTarget(dblAnimationKeyFrames, segment);
                AnimationStoryboard.Children.Add(dblAnimationKeyFrames);

                if (this.AdornmentsInfo != null)
                {
                    double secondsPerPoint = AnimationDuration.TotalSeconds / YValues.Count;
                    secondsPerPoint *= 2;

                    foreach (FrameworkElement label in this.AdornmentsInfo.LabelPresenters)
                    {
                        DoubleAnimation keyFrames1 = new DoubleAnimation()
                        {
                            From      = 0.5,
                            To        = 1,
                            Duration  = TimeSpan.FromSeconds(AnimationDuration.TotalSeconds / 2),
                            BeginTime = TimeSpan.FromSeconds(i * secondsPerPoint)
                        };

                        Storyboard.SetTargetProperty(keyFrames1, "(UIElement.Opacity)");
                        Storyboard.SetTarget(keyFrames1, label);
                        AnimationStoryboard.Children.Add(keyFrames1);

                        i++;
                    }
                }
            }

            AnimationStoryboard.Begin();
        }