コード例 #1
0
        public override void GenerateRealtime()
        {
            if (SupressRealtimeGeneration)
            {
                return;
            }
            base.GenerateRealtime();

            double minX = ((IInternalGraphData)Data).GetMinValue(0, false);
            double minY = ((IInternalGraphData)Data).GetMinValue(1, false);
            double maxX = ((IInternalGraphData)Data).GetMaxValue(0, false);
            double maxY = ((IInternalGraphData)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);

            Transform parentT = transform;

            if (mFixPosition != null)
            {
                parentT = mFixPosition.transform;
            }

            ClearBillboardCategories();

            foreach (GraphData.CategoryData data in ((IInternalGraphData)Data).Categories)
            {
                CategoryObject obj = null;

                if (mCategoryObjects.TryGetValue(data.Name, out obj) == false)
                {
                    continue;
                }

                mClipped.Clear();
                mTmpData.Clear();

                mTmpData.AddRange(data.getPoints());
                Rect uv;// = new Rect(0f, 0f, 1f, 1f);
                int  refrenceIndex = ClipPoints(mTmpData, mClipped, out uv);
                //mClipped.AddRange(mTmpData);
                TransformPoints(mClipped, mTransformed, viewRect, min, max);
                mTmpToRemove.Clear();
                int range = refrenceIndex + mClipped.Count;
                foreach (int key in obj.mCahced.Keys)
                {
                    if (key < refrenceIndex || key > range)
                    {
                        mTmpToRemove.Add(key);
                    }
                }

                for (int i = 0; i < mTmpToRemove.Count; i++)
                {
                    obj.mCahced.Remove(mTmpToRemove[i]);
                }

                obj.mCahced.Remove(mTmpData.Count - 1); // never store the last point cache , it might be intepolating by the realtime feature

                if (mTmpData.Count == 0)
                {
                    continue;
                }
                if (mItemLabels != null && mItemLabels.isActiveAndEnabled && obj.mItemLabels != null)
                {
                    Rect textRect = viewRect;
                    textRect.xMin -= 1f;
                    textRect.yMin -= 1f;
                    textRect.xMax += 1f;
                    textRect.yMax += 1f;

                    CanvasChartMesh m = obj.mItemLabels;
                    m.Clear();

                    for (int i = 0; i < mTransformed.Count; i++)
                    {
                        if (mTransformed[i].w == 0.0)
                        {
                            continue;
                        }
                        Vector3 labelPos = ((Vector3)mTransformed[i]) + new Vector3(mItemLabels.Location.Breadth, mItemLabels.Seperation, mItemLabels.Location.Depth);
                        if (mItemLabels.Alignment == ChartLabelAlignment.Base)
                        {
                            labelPos.y -= (float)mTransformed[i].y;
                        }
                        if (textRect.Contains((Vector2)(mTransformed[i])) == false)
                        {
                            continue;
                        }
                        string toSet      = null;
                        int    pointIndex = i + refrenceIndex;
                        if (obj.mCahced.TryGetValue(pointIndex, out toSet) == false)
                        {
                            DoubleVector3 pointValue = mTmpData[i + refrenceIndex];
                            string        xFormat    = StringFromAxisFormat(pointValue.x, mHorizontalAxis, mItemLabels.FractionDigits, true);
                            string        yFormat    = StringFromAxisFormat(pointValue.y, mVerticalAxis, mItemLabels.FractionDigits, false);
                            FormatItem(mRealtimeStringBuilder, xFormat, yFormat);
                            string formatted = mRealtimeStringBuilder.ToString();
                            mItemLabels.TextFormat.Format(mRealtimeStringBuilder, formatted, data.Name, "");
                            toSet = mRealtimeStringBuilder.ToString();
                            obj.mCahced[pointIndex] = toSet;
                        }
                        BillboardText billboard = m.AddText(this, mItemLabels.TextPrefab, parentT, mItemLabels.FontSize, mItemLabels.FontSharpness, toSet, labelPos.x, labelPos.y, labelPos.z, 0f, null);
                        AddBillboardText(data.Name, i + refrenceIndex, billboard);
                    }

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

                if (obj.mDots != null)
                {
                    Rect  pickRect = viewRect;
                    float halfSize = (float)(data.PointSize * 0.5f);
                    pickRect.xMin -= halfSize;
                    pickRect.yMin -= halfSize;
                    pickRect.xMax += halfSize;
                    pickRect.yMax += halfSize;
                    obj.mDots.SetViewRect(pickRect, uv);
                    obj.mDots.ModifyLines(mTransformed);
                    obj.mDots.SetRefrenceIndex(refrenceIndex);
                }

                if (obj.mLines != null)
                {
                    float tiling = 1f;
                    if (data.LineTiling.EnableTiling == true && data.LineTiling.TileFactor > 0f)
                    {
                        float length = 0f;
                        for (int i = 1; i < mTransformed.Count; i++)
                        {
                            length += (mTransformed[i - 1] - mTransformed[i]).magnitude;
                        }
                        tiling = length / data.LineTiling.TileFactor;
                    }
                    if (tiling <= 0.0001f)
                    {
                        tiling = 1f;
                    }
                    obj.mLines.Tiling = tiling;
                    obj.mLines.SetViewRect(viewRect, uv);
                    obj.mLines.ModifyLines(mTransformed);
                    obj.mLines.SetRefrenceIndex(refrenceIndex);
                }

                if (obj.mFill != null)
                {
                    obj.mFill.SetViewRect(viewRect, uv);
                    obj.mFill.ModifyLines(mTransformed);
                    obj.mFill.SetRefrenceIndex(refrenceIndex);
                }
            }
        }
        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);
                        }
                    }
                }
            }
        }