コード例 #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);
            }
        }
コード例 #2
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;
            }
        }