Exemple #1
0
 /// <summary>
 /// format a candle value to the parameter strings
 /// </summary>
 /// <param name="candleVal"></param>
 /// <param name="fractionDigits"></param>
 /// <param name="open"></param>
 /// <param name="high"></param>
 /// <param name="low"></param>
 /// <param name="close"></param>
 public void FormatCandleValue(CandleChartData.CandleValue candleVal, int fractionDigits, out string open, out string high, out string low, out string close)
 {
     open  = StringFromAxisFormat(new DoubleVector3(candleVal.Start, candleVal.Open, 0.0), mVerticalAxis, false);
     close = StringFromAxisFormat(new DoubleVector3(candleVal.Start, candleVal.Close, 0.0), mVerticalAxis, false);
     high  = StringFromAxisFormat(new DoubleVector3(candleVal.Start, candleVal.High, 0.0), mVerticalAxis, false);
     low   = StringFromAxisFormat(new DoubleVector3(candleVal.Start, candleVal.Low, 0.0), mVerticalAxis, false);
 }
Exemple #2
0
        CandleChartData.CandleValue NormalizeCandle(CandleChartData.CandleValue candle, DoubleVector3 min, DoubleVector3 range)
        {
            CandleChartData.CandleValue res = new CandleChartData.CandleValue();
            res.Open  = ChartCommon.normalizeInRangeY(candle.Open, min, range);
            res.Close = ChartCommon.normalizeInRangeY(candle.Close, min, range);
            res.High  = ChartCommon.normalizeInRangeY(candle.High, min, range);
            res.Low   = ChartCommon.normalizeInRangeY(candle.Low, min, range);

            double duration = candle.Duration;
            double start    = candle.Start;

            if (ThicknessMode == CandleThicknessMode.Fill)
            {
                Deflate(ref start, ref duration, ThicknessConstant);
            }
            else if (thicknessMode == CandleThicknessMode.Proportional)
            {
                Deflate(ref start, ref duration, ThicknessConstant / duration);
            }
            double candleEnd = start + duration;

            candleEnd = ChartCommon.normalizeInRangeX(candleEnd, min, range);

            res.Start    = ChartCommon.normalizeInRangeX(start, min, range);
            res.Duration = candleEnd - res.Start;
            return(res);
        }
Exemple #3
0
        protected int ClipCandles(IList <CandleChartData.CandleValue> candles, List <CandleChartData.CandleValue> result)
        {
            result.Clear();

            double minX, minY, maxX, maxY, xScroll, yScroll, xSize, ySize, xOut;

            GetScrollParams(out minX, out minY, out maxX, out maxY, out xScroll, out yScroll, out xSize, out ySize, out xOut);

            bool prevOut       = true;
            int  refrenceIndex = 0;

            for (int i = 0; i < candles.Count; i++)
            {
                CandleChartData.CandleValue candle = candles[i];
                double candleEnd = candle.Duration + candle.Start;

                if (candleEnd >= xScroll && candle.Start <= xOut) // if the candle is within range
                {
                    if (prevOut)
                    {
                        refrenceIndex = i;
                        prevOut       = false;
                    }
                    result.Add(candle);
                }
            }
            return(refrenceIndex);
        }
        protected void PickLine(Vector3 mouse, out int pickedIndex, out int pickedType, out object selectionData)
        {
            pickedIndex   = -1;
            pickedType    = -1;
            selectionData = null;

            for (int i = 0; i < mCandles.Count; i++)
            {
                CandleChartData.CandleValue candle = mCandles[i];

                float max   = (float)candle.Max;
                float min   = (float)candle.Min;
                float start = (float)candle.Start;
                float end   = (float)(candle.Start + candle.Duration);
                float mid   = (start + end) * 0.5f;

                Rect high = ChartCommon.RectFromCenter(mid, (float)mCandleSettings.LineThickness, max, (float)candle.High);
                Rect low  = ChartCommon.RectFromCenter(mid, (float)mCandleSettings.LineThickness, (float)candle.Low, min);
                if (high.Contains(mouse))
                {
                    selectionData = high;
                    pickedType    = 0;
                    pickedIndex   = i;
                    return;
                }

                if (low.Contains(mouse))
                {
                    selectionData = low;
                    pickedType    = 2;
                    pickedIndex   = i;
                    return;
                }
            }
        }
Exemple #5
0
 public CandleEventArgs(int index, int type, Rect selectionRect, Vector3 position, CandleChartData.CandleValue value, string category)
 {
     mType         = type;
     Position      = position;
     SelectionRect = selectionRect;
     CandleValue   = value;
     Category      = category;
 }
 bool UpPredicate(CandleChartData.CandleValue x)
 {
     if (x.isUp)
     {
         mUpToIndex.Add(mTmpCurrentIndex);
     }
     mTmpCurrentIndex++;
     return(x.isUp);
 }
 bool DownPredicate(CandleChartData.CandleValue x)
 {
     if (x.isUp == false)
     {
         mDownToIndex.Add(mTmpCurrentIndex);
     }
     mTmpCurrentIndex++;
     return(!x.isUp);
 }
        IEnumerable <UIVertex> getLine()
        {
            UIVertex v = new UIVertex();

            if (mCandles == null)
            {
                yield break;
            }
            for (int i = 0; i < mCandles.Count; i++)
            {
                CandleChartData.CandleValue candle = mCandles[i];
                float max = (float)Math.Max(candle.Open, candle.Close);
                float min = (float)Math.Min(candle.Open, candle.Close);

                float start = (float)candle.Start;
                float end   = (float)(candle.Start + candle.Duration);
                float mid   = (start + end) * 0.5f;

                v.position = new Vector3(mid - (float)mCandleSettings.LineThickness, (float)candle.High, 0f);
                v.uv0      = new Vector2(0f, 0f);
                yield return(v);

                v.position = new Vector3(mid + (float)mCandleSettings.LineThickness, (float)candle.High, 0f);
                v.uv0      = new Vector2(1f, 0f);
                yield return(v);

                v.position = new Vector3(mid - (float)mCandleSettings.LineThickness, max, 0f);
                v.uv0      = new Vector2(0f, 1f);
                yield return(v);

                v.position = new Vector3(mid + (float)mCandleSettings.LineThickness, max, 0f);
                v.uv0      = new Vector2(1f, 1f);
                yield return(v);



                v.position = new Vector3(mid - (float)mCandleSettings.LineThickness, min, 0f);
                v.uv0      = new Vector2(0f, 0f);
                yield return(v);

                v.position = new Vector3(mid + (float)mCandleSettings.LineThickness, min, 0f);
                v.uv0      = new Vector2(1f, 0f);
                yield return(v);

                v.position = new Vector3(mid - (float)mCandleSettings.LineThickness, (float)candle.Low, 0f);
                v.uv0      = new Vector2(0f, 1f);
                yield return(v);

                v.position = new Vector3(mid + (float)mCandleSettings.LineThickness, (float)candle.Low, 0f);
                v.uv0      = new Vector2(1f, 1f);
                yield return(v);
            }
        }
Exemple #9
0
        protected void TransformCandles(IList <CandleChartData.CandleValue> candles, List <CandleChartData.CandleValue> output, Rect viewRect, DoubleVector3 min, DoubleVector3 max)
        {
            DoubleVector3 range = max - min;

            if (range.x <= 0.0001f || range.y < 0.0001f)
            {
                return;
            }
            output.Clear();
            for (int i = 0; i < candles.Count; i++)
            {
                CandleChartData.CandleValue candle = candles[i];
                candle = InterpolateCandleInRect(NormalizeCandle(candle, min, range), viewRect);
                output.Add(candle);
            }
        }
        void Category_Hover(string category, int index, int type, object data, Vector2 position)
        {
            CandleChartData.CandleValue     candle = Data.GetCandle(category, index);
            Dictionary <int, BillboardText> catgoryTexts;
            BillboardText b;

            if (mTexts.TryGetValue(category, out catgoryTexts))
            {
                if (catgoryTexts.TryGetValue(index, out b))
                {
                    SelectActiveText(b);
                }
            }
            Rect selection = new Rect();

            if (data != null && data is Rect)
            {
                selection = (Rect)data;
            }
            OnItemHoverted(new CandleEventArgs(index, type, selection, position, candle, category));
        }
Exemple #11
0
        public CandleChartData.CandleValue InterpolateCandleInRect(CandleChartData.CandleValue candle, Rect viewRect)
        {
            CandleChartData.CandleValue res = new CandleChartData.CandleValue();
            res.Open  = ChartCommon.interpolateInRectY(viewRect, candle.Open);
            res.Close = ChartCommon.interpolateInRectY(viewRect, candle.Close);
            res.High  = ChartCommon.interpolateInRectY(viewRect, candle.High);
            res.Low   = ChartCommon.interpolateInRectY(viewRect, candle.Low);

            if (res.High < res.Low)
            {
                double tmp = res.High;
                res.High  = res.Low;
                res.Low   = tmp;
                tmp       = res.Open;
                res.Open  = res.Close;
                res.Close = tmp;
            }
            double candleEnd = candle.Start + candle.Duration;

            candleEnd = ChartCommon.interpolateInRectX(viewRect, candleEnd);
            double start    = ChartCommon.interpolateInRectX(viewRect, candle.Start);
            double duration = candleEnd - start;

            if (start > candleEnd)
            {
                double tmp = start;
                start     = candleEnd;
                candleEnd = tmp;
            }
            if (ThicknessMode == CandleThicknessMode.Constant)
            {
                Deflate(ref start, ref duration, ThicknessConstant / duration);
            }

            res.Start    = start;
            res.Duration = duration;

            return(res);
        }
        protected Rect RectFromIndex(int index, int type, Rect Default)
        {
            if (index >= mCandles.Count)
            {
                return(Default);
            }
            CandleChartData.CandleValue candle = mCandles[index];
            float max   = (float)candle.Max;
            float min   = (float)candle.Min;
            float start = (float)candle.Start;
            float end   = (float)(candle.Start + candle.Duration);
            float mid   = (start + end) * 0.5f;

            if (type == 0)
            {
                return(ChartCommon.RectFromCenter(mid, (float)mCandleSettings.LineThickness, max, (float)candle.High));
            }
            if (type == 2)
            {
                return(ChartCommon.RectFromCenter(mid, (float)mCandleSettings.LineThickness, (float)candle.Low, min));
            }
            return(ChartCommon.RectFromCenter(mid, (float)(mCandleSettings.CandleThicknessMultiplier * candle.Duration), min, max));
        }
        protected void PickBody(Vector3 mouse, out int pickedIndex, out int pickedType, out object selectionData)
        {
            pickedIndex   = -1;
            pickedType    = -1;
            selectionData = null;
            for (int i = 0; i < mCandles.Count; i++)
            {
                CandleChartData.CandleValue candle = mCandles[i];
                float max   = (float)candle.Max;
                float min   = (float)candle.Min;
                float start = (float)candle.Start;
                float end   = (float)(candle.Start + candle.Duration);
                float mid   = (start + end) * 0.5f;
                Rect  Body  = ChartCommon.RectFromCenter(mid, (float)(mCandleSettings.CandleThicknessMultiplier * candle.Duration), min, max);

                if (Body.Contains(mouse))
                {
                    selectionData = Body;
                    pickedType    = 1;
                    pickedIndex   = i;
                    return;
                }
            }
        }
Exemple #14
0
 /// <summary>
 /// format a candle value to the parameter strings
 /// </summary>
 /// <param name="candleVal"></param>
 /// <param name="fractionDigits"></param>
 /// <param name="start"></param>
 /// <param name="duration"></param>
 public void FormatCandleValue(CandleChartData.CandleValue candleVal, int fractionDigits, out string start, out string duration)
 {
     start    = StringFromAxisFormat(new DoubleVector3(candleVal.Start, candleVal.Open, 0.0), mHorizontalAxis, true);
     duration = StringFromAxisFormat(new DoubleVector3(candleVal.Duration, candleVal.Open, 0.0), mHorizontalAxis, true);
 }
        IEnumerable <UIVertex> getOutline()
        {
            UIVertex v = new UIVertex();

            if (mCandles == null)
            {
                yield break;
            }

            float outlineThickness = (float)mCandleSettings.OutlineThickness * 0.5f;

            for (int i = 0; i < mCandles.Count; i++)
            {
                CandleChartData.CandleValue candle = mCandles[i];
                float max       = (float)Math.Max(candle.Open, candle.Close);
                float min       = (float)Math.Min(candle.Open, candle.Close);
                float start     = (float)candle.Start;
                float end       = (float)(candle.Start + candle.Duration);
                float mid       = (start + end) * 0.5f;
                float thickness = (float)(mCandleSettings.CandleThicknessMultiplier * candle.Duration * 0.5);

                //long and dirty part the defines all the verices of the candle outline

                //outline of the body
                v.position = new Vector3(mid - thickness - outlineThickness, max, 0f);
                v.uv0      = new Vector2(0f, 0f);
                yield return(v);

                v.position = new Vector3(mid - thickness + outlineThickness, max, 0f);
                v.uv0      = new Vector2(1f, 0f);
                yield return(v);

                v.position = new Vector3(mid - thickness - outlineThickness, min, 0f);
                v.uv0      = new Vector2(0f, 1f);
                yield return(v);

                v.position = new Vector3(mid - thickness + outlineThickness, min, 0f);
                v.uv0      = new Vector2(1f, 1f);
                yield return(v);

                //outline of the body
                v.position = new Vector3(mid + thickness - outlineThickness, max, 0f);
                v.uv0      = new Vector2(0f, 0f);
                yield return(v);

                v.position = new Vector3(mid + thickness + outlineThickness, max, 0f);
                v.uv0      = new Vector2(1f, 0f);
                yield return(v);

                v.position = new Vector3(mid + thickness - outlineThickness, min, 0f);
                v.uv0      = new Vector2(0f, 1f);
                yield return(v);

                v.position = new Vector3(mid + thickness + outlineThickness, min, 0f);
                v.uv0      = new Vector2(1f, 1f);
                yield return(v);


                //outline of the high line
                v.position = new Vector3(mid - (float)mCandleSettings.LineThickness - outlineThickness, (float)candle.High, 0f);
                v.uv0      = new Vector2(0f, 0f);
                yield return(v);

                v.position = new Vector3(mid - (float)mCandleSettings.LineThickness + outlineThickness, (float)candle.High, 0f);
                v.uv0      = new Vector2(1f, 0f);
                yield return(v);

                v.position = new Vector3(mid - (float)mCandleSettings.LineThickness - outlineThickness, max, 0f);
                v.uv0      = new Vector2(0f, 1f);
                yield return(v);

                v.position = new Vector3(mid - (float)mCandleSettings.LineThickness + outlineThickness, max, 0f);
                v.uv0      = new Vector2(1f, 1f);
                yield return(v);

                //outline of the high line
                v.position = new Vector3(mid + (float)mCandleSettings.LineThickness - outlineThickness, (float)candle.High, 0f);
                v.uv0      = new Vector2(0f, 0f);
                yield return(v);

                v.position = new Vector3(mid + (float)mCandleSettings.LineThickness + outlineThickness, (float)candle.High, 0f);
                v.uv0      = new Vector2(1f, 0f);
                yield return(v);

                v.position = new Vector3(mid + (float)mCandleSettings.LineThickness - outlineThickness, max, 0f);
                v.uv0      = new Vector2(0f, 1f);
                yield return(v);

                v.position = new Vector3(mid + (float)mCandleSettings.LineThickness + outlineThickness, max, 0f);
                v.uv0      = new Vector2(1f, 1f);
                yield return(v);


                //outline of the low line
                v.position = new Vector3(mid - (float)mCandleSettings.LineThickness - outlineThickness, min, 0f);
                v.uv0      = new Vector2(0f, 0f);
                yield return(v);

                v.position = new Vector3(mid - (float)mCandleSettings.LineThickness + outlineThickness, min, 0f);
                v.uv0      = new Vector2(1f, 0f);
                yield return(v);

                v.position = new Vector3(mid - (float)mCandleSettings.LineThickness - outlineThickness, (float)candle.Low, 0f);
                v.uv0      = new Vector2(0f, 1f);
                yield return(v);

                v.position = new Vector3(mid - (float)mCandleSettings.LineThickness + outlineThickness, (float)candle.Low, 0f);
                v.uv0      = new Vector2(1f, 1f);
                yield return(v);


                //outline of the low line
                v.position = new Vector3(mid + (float)mCandleSettings.LineThickness - outlineThickness, min, 0f);
                v.uv0      = new Vector2(0f, 0f);
                yield return(v);

                v.position = new Vector3(mid + (float)mCandleSettings.LineThickness + outlineThickness, min, 0f);
                v.uv0      = new Vector2(1f, 0f);
                yield return(v);

                v.position = new Vector3(mid + (float)mCandleSettings.LineThickness - outlineThickness, (float)candle.Low, 0f);
                v.uv0      = new Vector2(0f, 1f);
                yield return(v);

                v.position = new Vector3(mid + (float)mCandleSettings.LineThickness + outlineThickness, (float)candle.Low, 0f);
                v.uv0      = new Vector2(1f, 1f);
                yield return(v);


                //outline of the low line connection with body
                v.position = new Vector3(mid - thickness - outlineThickness, min + outlineThickness, 0f);
                v.uv0      = new Vector2(0f, 0f);
                yield return(v);

                v.position = new Vector3(mid - (float)mCandleSettings.LineThickness, min + outlineThickness, 0f);
                v.uv0      = new Vector2(1f, 0f);
                yield return(v);

                v.position = new Vector3(mid - thickness - outlineThickness, min - outlineThickness, 0f);
                v.uv0      = new Vector2(0f, 1f);
                yield return(v);

                v.position = new Vector3(mid - (float)mCandleSettings.LineThickness, min - outlineThickness, 0f);
                v.uv0      = new Vector2(1f, 1f);
                yield return(v);

                //outline of the low line connection with body
                v.position = new Vector3(mid + thickness + outlineThickness, min + outlineThickness, 0f);
                v.uv0      = new Vector2(0f, 0f);
                yield return(v);

                v.position = new Vector3(mid + (float)mCandleSettings.LineThickness, min + outlineThickness, 0f);
                v.uv0      = new Vector2(1f, 0f);
                yield return(v);

                v.position = new Vector3(mid + thickness + outlineThickness, min - outlineThickness, 0f);
                v.uv0      = new Vector2(0f, 1f);
                yield return(v);

                v.position = new Vector3(mid + (float)mCandleSettings.LineThickness, min - outlineThickness, 0f);
                v.uv0      = new Vector2(1f, 1f);
                yield return(v);

                //outline of the high line connection with body
                v.position = new Vector3(mid - thickness - outlineThickness, max - outlineThickness, 0f);
                v.uv0      = new Vector2(0f, 0f);
                yield return(v);

                v.position = new Vector3(mid - (float)mCandleSettings.LineThickness, max - outlineThickness, 0f);
                v.uv0      = new Vector2(1f, 0f);
                yield return(v);

                v.position = new Vector3(mid - thickness - outlineThickness, max + outlineThickness, 0f);
                v.uv0      = new Vector2(0f, 1f);
                yield return(v);

                v.position = new Vector3(mid - (float)mCandleSettings.LineThickness, max + outlineThickness, 0f);
                v.uv0      = new Vector2(1f, 1f);
                yield return(v);

                //outline of the high line connection with body
                v.position = new Vector3(mid + thickness + outlineThickness, max - outlineThickness, 0f);
                v.uv0      = new Vector2(0f, 0f);
                yield return(v);

                v.position = new Vector3(mid + (float)mCandleSettings.LineThickness, max - outlineThickness, 0f);
                v.uv0      = new Vector2(1f, 0f);
                yield return(v);

                v.position = new Vector3(mid + thickness + outlineThickness, max + outlineThickness, 0f);
                v.uv0      = new Vector2(0f, 1f);
                yield return(v);

                v.position = new Vector3(mid + (float)mCandleSettings.LineThickness, max + outlineThickness, 0f);
                v.uv0      = new Vector2(1f, 1f);
                yield return(v);
            }
        }
Exemple #16
0
 /// <summary>
 /// format a candle value to the parameter strings
 /// </summary>
 /// <param name="candleVal"></param>
 /// <param name="fractionDigits"></param>
 /// <param name="open"></param>
 /// <param name="high"></param>
 /// <param name="low"></param>
 /// <param name="close"></param>
 /// <param name="start"></param>
 /// <param name="duration"></param>
 public void FormatCandleValue(CandleChartData.CandleValue candleVal, int fractionDigits, out string open, out string high, out string low, out string close, out string start, out string duration)
 {
     FormatCandleValue(candleVal, fractionDigits, out open, out high, out low, out close);
     FormatCandleValue(candleVal, fractionDigits, out start, out duration);
 }
        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);
                        }
                    }
                }
            }
        }