private void mHover(CanvasCandle candle, int index, int type, object data, Vector2 position)
 {
     mOccupiedCandles.Add(candle);
     if (Hover != null)
     {
         Hover(index, type, data, position);
     }
 }
 private void mClick(CanvasCandle candle, int index, int type, object data, Vector2 position)
 {
     mOccupiedCandles.Add(candle);
     if (Click != null)
     {
         Click(index, type, data, position);
     }
 }
 void HookEvents(CanvasCandle candle, bool isUp)
 {
     if (candle == null)
     {
         return;
     }
     candle.Leave += () => mLeave(candle);
     candle.Hover += (index, type, data, position) => { mHover(candle, mParent.MapIndex(index, isUp), type, data, position); };
     candle.Click += (index, type, data, position) => { mClick(candle, mParent.MapIndex(index, isUp), type, data, position); };
 }
 private void mLeave(CanvasCandle candle)
 {
     if (mOccupiedCandles.Remove(candle))
     {
         if (mOccupiedCandles.Count == 0)
         {
             if (Leave != null)
             {
                 Leave();
             }
         }
     }
 }
Пример #5
0
        private CanvasCandle CreateDataObject(CandleChartData.CategoryData data, GameObject rectMask)
        {
            GameObject obj = new GameObject("Candles", typeof(RectTransform));

            ChartCommon.HideObject(obj, hideHierarchy);
            obj.AddComponent <ChartItem>();
            RectTransform t = obj.GetComponent <RectTransform>();

            obj.AddComponent <CanvasRenderer>();
            CanvasCandle candles = obj.AddComponent <CanvasCandle>();

            t.SetParent(rectMask.transform, false);
            t.localScale       = new Vector3(1f, 1f, 1f);
            t.anchorMin        = new Vector2(0f, 0f);
            t.anchorMax        = new Vector2(0f, 0f);
            t.anchoredPosition = Vector3.zero;
            t.localRotation    = Quaternion.identity;
            return(candles);
        }
        public override void InternalGenerateChart()
        {
            if (gameObject.activeInHierarchy == false)
            {
                return;
            }
            base.InternalGenerateChart();

            if (FitToContainer)
            {
                RectTransform trans = GetComponent <RectTransform>();
                widthRatio  = trans.rect.width;
                heightRatio = trans.rect.height;
            }
            ClearChart();

            if (Data == null)
            {
                return;
            }
            GenerateAxis(true);

            double minX = ((IInternalCandleData)Data).GetMinValue(0, false);
            double minY = ((IInternalCandleData)Data).GetMinValue(1, false);
            double maxX = ((IInternalCandleData)Data).GetMaxValue(0, false);
            double maxY = ((IInternalCandleData)Data).GetMaxValue(1, false);

            double xScroll = GetScrollOffset(0);
            double yScroll = GetScrollOffset(1);
            double xSize   = maxX - minX;
            double ySize   = maxY - minY;
            double xOut    = minX + xScroll + xSize;
            double yOut    = minY + yScroll + ySize;

            DoubleVector3 min = new DoubleVector3(xScroll + minX, yScroll + minY);
            DoubleVector3 max = new DoubleVector3(xOut, yOut);

            Rect viewRect = new Rect(0f, 0f, widthRatio, heightRatio);

            int  total = ((IInternalCandleData)Data).TotalCategories + 1;
            bool edit  = false;

            ClearBillboard();
            mActiveTexts.Clear();
            int        index = 0;
            GameObject mask  = CreateRectMask(viewRect);

            foreach (CandleChartData.CategoryData data in ((IInternalCandleData)Data).Categories)
            {
                mClipped.Clear();
                mTransformed.Clear();
                int refrenceIndex = ClipCandles(data.Data, mClipped);

                TransformCandles(mClipped, mTransformed, viewRect, min, max);

                if (data.Data.Count == 0 && ChartCommon.IsInEditMode)
                {
                    int   tmpIndex = total - 1 - index;
                    float low      = (((float)tmpIndex) / (float)total);
                    float high     = (((float)tmpIndex + 1) / (float)total);
                    float y1       = Mathf.Lerp(high, low, 0.6f);
                    float y2       = Mathf.Lerp(high, low, 0.3f);
                    mTransformed.Clear();
                    mTransformed.Add(InterpolateCandleInRect(new CandleChartData.CandleValue(y1, high, low, y2, 0.1, 0.1), viewRect));
                    mTransformed.Add(InterpolateCandleInRect(new CandleChartData.CandleValue(y1, low, high, y2, 0.5, 0.2), viewRect));
                    edit = true;
                    index++;
                }
                CategoryObject categoryObj = new CategoryObject(this);
                CanvasCandle   up          = CreateDataObject(data, mask);
                CanvasCandle   down        = CreateDataObject(data, mask);

                FillCurrentSeries(true, refrenceIndex);
                up.Generate(this, viewRect, mCurrentSeries, data.UpCandle);

                FillCurrentSeries(false, refrenceIndex);
                down.Generate(this, viewRect, mCurrentSeries, data.DownCandle);

                string catName = data.Name;

                categoryObj.mUp   = up;
                categoryObj.mDown = down;
                categoryObj.HookEvents();

                GenerateItemLabels(false, categoryObj, data, viewRect, refrenceIndex, edit);

                categoryObj.Hover        += (idx, t, d, pos) => { Category_Hover(catName, idx, t, d, pos); };
                categoryObj.Click        += (idx, t, d, pos) => { Category_Click(catName, idx, t, d, pos); };
                categoryObj.Leave        += () => { Category_Leave(catName); };
                mCategoryObjects[catName] = categoryObj;
            }
        }