Ejemplo n.º 1
0
        //System.Diagnostics.Stopwatch sw = new System.Diagnostics.Stopwatch();
        private void ScaleChart()
        {
            if (!IsSettingsSet)
            {
                return;
            }


            double highestPriceOnScreen = CoordGrid.FromYAxisToPrice(worldPointInRightUpCorner.y);
            double lowestPriceOnScreen  = CoordGrid.FromYAxisToPrice(worldPointInLeftDownCorner.y);

            double highestPrice = visibleFluctuations.Max(f => f.High);
            double lowestPrice  = visibleFluctuations.Min(f => f.Low);

            double priceRange = highestPrice - lowestPrice;
            float  new_y      = CoordGrid.FromPriceToYAxis((float)(lowestPrice + priceRange / 2));


            if (Math.Abs(new_y / cam.transform.position.y - 1) > 1e-4)
            {
                cam.transform.position = new Vector3(cam.transform.position.x, new_y, cam.transform.position.z);
            }

            if (highestPrice != lowestPrice)
            {
                CoordGrid.Scale *= (1 - chartOffsetFromVerticalBorders) * (float)((highestPriceOnScreen - lowestPriceOnScreen) / priceRange);
            }
        }
Ejemplo n.º 2
0
        public void DrawGrid(IEnumerable <DateTime> dateList, IEnumerable <decimal> pricesList)
        {
            if (!IsSettingsSet)
            {
                return;
            }


            DrawTools.LineColor  = gridColor;
            DrawTools.dashLength = 0.05f;
            DrawTools.gap        = 0.07f;

            priceTextPool.CleanPool();

            float yPoint;

            foreach (var price in pricesList)
            {
                yPoint = CoordGrid.FromPriceToYAxis((float)price);
                yPoint = cam.WorldToScreenPoint(new Vector2(0, yPoint)).y;
                priceTextPool.SetText(
                    price.ToString("F8"),
                    yPoint,
                    TextPoolManager.ShiftBy.Vertical
                    );

                Vector2 pricePoint1 = new Vector2(cam.WorldToScreenPoint(worldPointInLeftDownCorner).x, yPoint);
                Vector2 pricePoint2 = new Vector2(cam.WorldToScreenPoint(worldPointInRightUpCorner).x, yPoint);

                DrawTools.DrawOnePixelLine(pricePoint1, pricePoint2, true);
            }

            dateTextPool.CleanPool();
            foreach (var date in dateList)
            {
                float dateLine = CoordGrid.FromDateToXAxis(date);
                dateLine = cam.WorldToScreenPoint(new Vector2(dateLine, 0)).x;
                dateTextPool.SetText(
                    date.ChartStringFormat(),
                    dateLine,
                    TextPoolManager.ShiftBy.Horizontal
                    );


                Vector2 datePoint1 = new Vector2(dateLine, cam.pixelRect.min.y);
                Vector2 datePoint2 = new Vector2(dateLine, cam.pixelRect.max.y);

                DrawTools.DrawOnePixelLine(datePoint1, datePoint2, true);
            }
        }
            internal Vector3 GetLastPoint()
            {
                if (!IsSettingsSet)
                {
                    return(Vector3.zero);
                }


                float x = CoordGrid.FromDateToXAxis(chartDataManager.WorkEndTime);
                float y;

                if (ChartDrawer.Instance.Autoscale)
                {
                    y = cameraTransform.position.y;
                }
                else
                {
                    y = CoordGrid.FromPriceToYAxis((float)chartDataManager.GetPriceFluctuation(chartDataManager.WorkEndTime).Close);
                }

                return(new Vector3(x, y));
            }
Ejemplo n.º 4
0
        public void DrawPointArray(int id, Color color)
        {
            Vector2 point, point2;

            DrawTools.LineColor = color;
            IEnumerator <PriceFluctuation> it = visibleFluctuations.GetEnumerator();

            while (it.MoveNext() && (!it.Current.ExtraData.ContainsKey(id) || !(it.Current.ExtraData[id] is float)))
            {
                ;
            }

            if (!it.Current.ExtraData.ContainsKey(id))
            {
                return;
            }

            point = cam.WorldToScreenPoint(new Vector2(CoordGrid.FromDateToXAxis(it.Current.PeriodBegin), CoordGrid.FromPriceToYAxis((float)it.Current.ExtraData[id])));

            while (it.MoveNext())
            {
                if (it.Current.ExtraData[id] is float)
                {
                    point2 = cam.WorldToScreenPoint(new Vector2(CoordGrid.FromDateToXAxis(it.Current.PeriodBegin), CoordGrid.FromPriceToYAxis((float)it.Current.ExtraData[id])));
                    DrawTools.DrawLine(point, point2, false);
                    point = point2;
                }
            }
        }