Esempio n. 1
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);
        }
        void GenerateItemLabels(bool realTime, CategoryObject categoryObj, CandleChartData.CategoryData data, Rect viewRect, int refrenceIndex, bool edit)
        {
            if (mItemLabels != null && mItemLabels.isActiveAndEnabled)
            {
                CanvasChartMesh m = null;
                if (realTime)
                {
                    m = categoryObj.mItemLabels;
                    if (m == null)
                    {
                        return;
                    }
                    m.Clear();
                }
                else
                {
                    m                       = new CanvasChartMesh(true);
                    m.RecycleText           = true;
                    categoryObj.mItemLabels = m;
                }

                Rect textRect = viewRect;
                textRect.xMin -= 1f;
                textRect.yMin -= 1f;
                textRect.xMax += 1f;
                textRect.yMax += 1f;

                for (int i = 0; i < mTransformed.Count; i++)
                {
                    Vector2 pointValue = mTransformed[i].MidPoint.ToVector2();

                    if (textRect.Contains(pointValue) == false)
                    {
                        continue;
                    }

                    CandleChartData.CandleValue candleVal = mTransformed[i];
                    int candleIndex = i + refrenceIndex;
                    if (edit == false)
                    {
                        candleVal = data.Data[i + refrenceIndex];
                    }
                    Vector3 labelPos = ((Vector3)pointValue) + new Vector3(mItemLabels.Location.Breadth, mItemLabels.Seperation, mItemLabels.Location.Depth);
                    if (mItemLabels.Alignment == ChartLabelAlignment.Base)
                    {
                        labelPos.y -= (float)mTransformed[i].MidPoint.y;
                    }

                    string toSet;
                    if (realTime == false || categoryObj.mCahced.TryGetValue(candleIndex, out toSet) == false)
                    {
                        string Open     = StringFromAxisFormat(new DoubleVector3(candleVal.Start, candleVal.Open, 0.0), mVerticalAxis, false);
                        string Close    = StringFromAxisFormat(new DoubleVector3(candleVal.Start, candleVal.Close, 0.0), mVerticalAxis, false);
                        string High     = StringFromAxisFormat(new DoubleVector3(candleVal.Start, candleVal.High, 0.0), mVerticalAxis, false);
                        string Low      = StringFromAxisFormat(new DoubleVector3(candleVal.Start, candleVal.Low, 0.0), mVerticalAxis, false);
                        string Start    = StringFromAxisFormat(new DoubleVector3(candleVal.Start, candleVal.Open, 0.0), mHorizontalAxis, true);
                        string Duration = StringFromAxisFormat(new DoubleVector3(candleVal.Duration, candleVal.Open, 0.0), mHorizontalAxis, true);
                        FormatItem(mRealtimeStringBuilder, Open, Close, High, Low, Start, Duration);
                        toSet = mItemLabels.TextFormat.Format(mRealtimeStringBuilder.ToString(), data.Name, "");
                        categoryObj.mCahced[candleIndex] = toSet;
                    }
                    labelPos -= new Vector3(CanvasFitOffset.x * TotalWidth, CanvasFitOffset.y * TotalHeight, 0f);
                    BillboardText billboard = m.AddText(this, mItemLabels.TextPrefab, transform, mItemLabels.FontSize, mItemLabels.FontSharpness, toSet, labelPos.x, labelPos.y, labelPos.z, 0f, null);
                    TextController.AddText(billboard);
                    AddBillboardText(data.Name, i + refrenceIndex, billboard);
                }

                if (realTime)
                {
                    m.DestoryRecycled();
                    if (m.TextObjects != null)
                    {
                        foreach (BillboardText text in m.TextObjects)
                        {
                            ((IInternalUse)this).InternalTextController.AddText(text);
                        }
                    }
                }
            }
        }