/// <summary> /// use this to modify candles in realtime. /// </summary> /// <param name="category"></param> /// <param name="candle"></param> public void ModifyCandleInCategory(string category, int candleIndex, double open, double high, double low, double close) { if (mData.ContainsKey(category) == false) { Debug.LogWarning("Invalid category name. Make sure the category is present in the chart"); return; } CategoryData data = (CategoryData)mData[category]; List <CandleValue> candles = data.Data; if (candleIndex == -1) { candleIndex = data.Data.Count - 1; } if (candleIndex < 0 || candleIndex >= candles.Count) { Debug.LogWarning("Candle index is out of range, call is ignored"); return; } double candleMax = Math.Max(Math.Max(open, close), Math.Max(high, low)); double candleMin = Math.Min(Math.Min(open, close), Math.Min(high, low)); if (data.MaxY.HasValue == false || data.MaxY.Value < candleMax) { data.MaxY = candleMax; } if (data.MinY.HasValue == false || data.MinY.Value > candleMin) { data.MinY = candleMin; } CandleValue candle = data.Data[candleIndex]; candle.Open = open; candle.Close = close; candle.High = high; candle.Low = low; data.Data[candleIndex] = candle; RaiseRealtimeDataChanged(candleIndex, category); }
/// <summary> /// adds a point to the category. The points are sorted by their x value automatically /// </summary> /// <param name="category"></param> /// <param name="point"></param> public void AddCandleToCategory(string category, CandleValue candle, float autoScrollSlideTime = 0f) { if (mData.ContainsKey(category) == false) { Debug.LogWarning("Invalid category name. Make sure the category is present in the chart"); return; } CategoryData data = (CategoryData)mData[category]; List <CandleValue> candles = data.Data; double start = candle.Start; double end = candle.Start + candle.Duration; double candleMax = Math.Max(Math.Max(candle.Open, candle.Close), Math.Max(candle.High, candle.Low)); double candleMin = Math.Min(Math.Min(candle.Open, candle.Close), Math.Min(candle.High, candle.Low)); if (autoScrollSlideTime <= 0f) { if (data.MaxX.HasValue == false || data.MaxX.Value < end) { data.MaxX = end; } } if (data.MinX.HasValue == false || data.MinX.Value > start) { data.MinX = start; } if (data.MaxY.HasValue == false || data.MaxY.Value < candleMax) { data.MaxY = candleMax; } if (data.MinY.HasValue == false || data.MinY.Value > candleMin) { data.MinY = candleMin; } if (candles.Count > 0) { if (candles[candles.Count - 1].Start < candle.Start) { if (autoScrollSlideTime > 0f) { Slider s = new Slider(this); s.category = category; s.from = candles[candles.Count - 1].End; s.to = end; s.StartTime = Time.time; s.Duration = autoScrollSlideTime; s.y = (candleMax + candleMin) * 0.5; s.index = candles.Count - 1; mSliders.Add(s); } candles.Add(candle); RaiseRealtimeDataChanged(candles.Count - 1, category); return; } } int search = candles.BinarySearch(candle, mComparer); if (search < 0) { search = ~search; } candles.Insert(search, candle); RaiseRealtimeDataChanged(search, category); }