Beispiel #1
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();
     }
 }
Beispiel #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);
        }
Beispiel #3
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);
            }
        }
        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();
        }
Beispiel #5
0
        private void AppendXValues()
        {
            var XValues = new XValues();

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

            XValues.NumberReference = numberReferenceBuilder.Build();

            scatterChartSeries.Append(XValues);
        }
Beispiel #6
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);
        }
        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");
            }
        }
Beispiel #8
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);
 }
        private void RegisterObject(int _kind, Guid _xObjectUid)
        {
            ServerXList   list;
            IServerXValue value;

            if (!XValues.TryGetValue(_kind, out value))
            {
                list = new ServerXList();
                XValues.Add(_kind, list);
            }
            else
            {
                list = (ServerXList)value;
            }
            list.AddChildUid(_xObjectUid);
        }
Beispiel #10
0
 void MapObject(XValues xValues, DocumentObjectModel.Shapes.Charts.XValues domXValues)
 {
     foreach (DocumentObjectModel.Shapes.Charts.XSeries domXSeries in domXValues)
     {
         XSeries xSeries = xValues.AddXSeries();
         DocumentObjectModel.Shapes.Charts.XSeriesElements domXSeriesElements = domXSeries.GetValue("XSeriesElements") as DocumentObjectModel.Shapes.Charts.XSeriesElements;
         foreach (DocumentObjectModel.Shapes.Charts.XValue domXValue in domXSeriesElements)
         {
             if (domXValue == null)
             {
                 xSeries.AddBlank();
             }
             else
             {
                 xSeries.Add(domXValue.GetValue("Value").ToString());
             }
         }
     }
 }
Beispiel #11
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;
                }
            }
        }
Beispiel #12
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();
            }
        }
Beispiel #13
0
 public void AddX(List <T> list, string title)
 {
     XValues.AddRange(list);
     XLabel = title;
 }
Beispiel #14
0
 public void ClearAll()
 {
     XValues.Clear();
     YValues.Clear();
     ZValues.Clear();
 }
Beispiel #15
0
 internal void Take(int v)
 {
     XValues = XValues.Take(v).ToList();
     YValues = YValues.Take(v).ToList();
 }
Beispiel #16
0
        private void UpdateSample(TimeSpan sampleTime, TimeSpan sampleBackFor)
        {
            var sampleLimit = DateTimeOffset.Now - sampleBackFor;

            XMinimum = sampleLimit.ToUnixTimeMilliseconds();

            var values = _history.SelectTimeSampleBackwards(
                x => x.Date,
                x => x.Balance,
                sampleTime,
                sampleLimit,
                DateTime.Now);

            XValues.Clear();
            YValues.Clear();

            foreach (var(timestamp, balance) in values.Reverse())
            {
                YValues.Add((double)balance.ToDecimal(MoneyUnit.BTC));
                XValues.Add(timestamp.ToUnixTimeMilliseconds());
            }

            if (YValues.Any())
            {
                var maxY = YValues.Max();
                YLabels = new List <string> {
                    "0", (maxY / 2).ToString("F2"), maxY.ToString("F2")
                };
            }
            else
            {
                YLabels = null;
            }

            if (XValues.Any())
            {
                var minX  = XValues.Min();
                var maxX  = XValues.Max();
                var halfX = minX + ((maxX - minX) / 2);

                var range = DateTimeOffset.FromUnixTimeMilliseconds((long)maxX) -
                            DateTimeOffset.FromUnixTimeMilliseconds((long)minX);

                if (range <= TimeSpan.FromDays(1))
                {
                    XLabels = new List <string>
                    {
                        DateTimeOffset.FromUnixTimeMilliseconds((long)minX).DateTime.ToString("t"),
                        DateTimeOffset.FromUnixTimeMilliseconds((long)halfX).DateTime.ToString("t"),
                        DateTimeOffset.FromUnixTimeMilliseconds((long)maxX).DateTime.ToString("t"),
                    };
                }
                else if (range <= TimeSpan.FromDays(7))
                {
                    XLabels = new List <string>
                    {
                        DateTimeOffset.FromUnixTimeMilliseconds((long)minX).DateTime.ToString("ddd MMM-d"),
                        DateTimeOffset.FromUnixTimeMilliseconds((long)halfX).DateTime.ToString("ddd MMM-d"),
                        DateTimeOffset.FromUnixTimeMilliseconds((long)maxX).DateTime.ToString("ddd MMM-d"),
                    };
                }
                else
                {
                    XLabels = new List <string>
                    {
                        DateTimeOffset.FromUnixTimeMilliseconds((long)minX).DateTime.ToString("MMM-d"),
                        DateTimeOffset.FromUnixTimeMilliseconds((long)halfX).DateTime.ToString("MMM-d"),
                        DateTimeOffset.FromUnixTimeMilliseconds((long)maxX).DateTime.ToString("MMM-d"),
                    };
                }
            }
            else
            {
                XLabels = null;
            }
        }
Beispiel #17
0
        internal static void Map(XValues xValues, DocumentObjectModel.Shapes.Charts.XValues domXValues)
        {
            XValuesMapper mapper = new XValuesMapper();

            mapper.MapObject(xValues, domXValues);
        }
Beispiel #18
0
        /// <inheritdoc />
        /// <summary>
        ///     Main Parse Function for the Lwpolyline Class
        /// </summary>
        /// <param name="list"></param>
        /// <param name="index"></param>
        /// <returns>True or false if the parse was successful</returns>
        public override bool Parse(TaggedDataList list, int index)
        {
            for (var currentIndex = index + 1;
                 currentIndex < list.Length;
                 ++currentIndex)
            {
                var currentData = list.GetPair(currentIndex);

                if (currentData.GroupCode == GroupCodesBase.EntityType)
                {
                    break;
                }

                if (base.Parse(list, currentIndex))
                {
                    continue;
                }

                switch (currentData.GroupCode)
                {
                // Number of Vertices
                case LwPolylineCodes.NumberOfVertices:
                    NumberOfVertices = int.Parse(currentData.Value);
                    continue;

                // Lwpolyline Flag
                case LwPolylineCodes.PolylineFlag:
                    PolyLineFlag = currentData.Value.Contains("1");
                    continue;

                // Constant Width
                case LwPolylineCodes.ConstantWidth:
                    ConstantWidth = double.Parse(currentData.Value);
                    continue;

                // Elevation
                case LwPolylineCodes.Elevation:
                    Elevation = double.Parse(currentData.Value);
                    continue;

                // Thickness
                case LwPolylineCodes.Thickness:
                    Thickness = double.Parse(currentData.Value);
                    continue;

                // X values
                case GroupCodesBase.XPoint:
                    BulgeList.Add(Bulge.BulgeNull);
                    XValues.Add(double.Parse(currentData.Value));
                    continue;

                // Y values
                case GroupCodesBase.YPoint:
                    YValues.Add(double.Parse(currentData.Value));
                    continue;

                // Bulge Values
                case LwPolylineCodes.Bulge:
                    BulgeList.RemoveAt(BulgeList.Count - 1);
                    BulgeList.Add(double.Parse(currentData.Value));
                    continue;

                default:
                    continue;
                }
            }

            return(true);
        }