Example #1
0
        public void DrawChart()
        {
            if (!IsSettingsSet)
            {
                return;
            }

            TimeFrame timeFrame = chartDataManager.TFrame;
            DateTime  startDate = visibleStartDate;
            DateTime  endDate   = visibleEndDate;

            if (chartDataManager.WorkEndTime < endDate)
            {
                endDate = chartDataManager.WorkEndTime;
            }
            if (chartDataManager.WorkBeginTime > startDate)
            {
                startDate = chartDataManager.WorkBeginTime;
            }

            var candlesInScreen = candles.Where(candle => candle.PeriodBegin >= startDate && candle.PeriodBegin <= endDate);
            var existDatePoints = candlesInScreen.Select(c => c.PeriodBegin);

            IEnumerable <PriceFluctuation> flucToLoad = new List <PriceFluctuation>();

            if (startDate <= endDate)
            {
                if (existDatePoints.NotNullOrEmpty())
                {
                    DateTime point1 = existDatePoints.Min();
                    DateTime point2 = existDatePoints.Max();

                    if (point1.FloorToTimeFrame(timeFrame) != startDate)
                    {
                        flucToLoad = ChartDataManager.GetPriceFluctuationsByTimeFrame(startDate, point1);
                    }

                    if (point2.UpToNextFrame(timeFrame) <= endDate)
                    {
                        flucToLoad = flucToLoad.Union(ChartDataManager.GetPriceFluctuationsByTimeFrame(point2.UpToNextFrame(timeFrame), endDate));
                    }
                }

                else
                {
                    flucToLoad = visibleFluctuations;
                }

                foreach (PriceFluctuation priceFluctuation in flucToLoad)
                {
                    Candle newCandle = Instantiate(candleDummy, candlesParent);
                    newCandle.Grid = CoordGrid;
                    newCandle.Set(priceFluctuation);
                    candles.Add(newCandle);
                }
            }
        }
            public void Update()
            {
                Vector3 pointerWorldPos;
                Vector2 pointerScreenPos;

                ChartDrawer.Instance.GetWorldPointerPosition(out pointerScreenPos, out pointerWorldPos);
                if (cachedXPos != Mathf.Round(pointerWorldPos.x))
                {
                    cachedXPos = Mathf.Round(pointerWorldPos.x);
                    DateTime fluctuationDate = CoordGrid.FromXAxisToDate(cachedXPos);
                    if (OnFluctuationSelect != null)
                    {
                        OnFluctuationSelect(ChartDataManager.GetPriceFluctuation(fluctuationDate));
                    }
                }
            }