public void UpdateData(StockBarData model) { if (_bars.Count > 0) { var last = _bars[_bars.Count - 1]; if (last.Model.Equals(model)) { Bind(last, model); return; } } var view = Factory.Add().GetComponent <StockVolumeChartBar>(); _bars.Add(view); Bind(view, model); if (_bars.Count > MaxPeriod) { if (_tween != null) { _tween.Complete(); } var first = _bars[0]; _bars.RemoveAt(0); _tween = transform.DOMoveX(Factory.Root.position.x - XSpace, TweenTime) .SetEase(Ease.Linear) .OnComplete(() => { Factory.Remove(first.gameObject); _tween = null; }); } }
private void Bind(StockVolumeChartBar view, StockBarData model) { view.Model = model; var x = XSpace * model.Period; (view.transform as RectTransform).anchoredPosition = new Vector3(x, 0); //size var height = (Factory.Root as RectTransform).rect.height; var percent = (float)model.Volume / (float)High; var result = Mathf.Max(1, (percent * height)); view.Body.sizeDelta = new Vector2(view.Body.sizeDelta.x, result); // paint if (model.Open > model.Close) { view.PaintRed(); } else { view.PaintGreen(); } }
void NewBar() { var oldBar = current; current = new StockBarData(oldBar.Close, Period); Bars.Add(current); OnUpdate(current); }
public void Awake() { Bars = new List <StockBarData>(); Period = 0; Last = 50; StockCount = 0; CashValue = 100000; Low = 0; High = 100; LowVolume = 0; HighVolume = 10; Spread = 1; RollingVolume = new RollingWindow(5, 1); current = new StockBarData(Last, Period); Bars.Add(current); OnUpdate(current); }
private void Bind(StockCandleChartBar view, StockBarData model) { view.Model = model; var x = XSpace * model.Period; var y = PriceToY(model.Low); (view.transform as RectTransform).anchorMin = new Vector2(0, 0); (view.transform as RectTransform).anchorMax = new Vector2(0, 0); (view.transform as RectTransform).anchoredPosition = new Vector3(x, y); //wick size var wickRange = Mathf.Abs(model.High - model.Low); var wickSize = Mathf.Max(PriceToY(wickRange), 1); view.Wick.sizeDelta = new Vector2(view.Wick.sizeDelta.x, wickSize); //body size var bodyRange = Mathf.Max(Mathf.Abs(model.Close - model.Open), 1); var bodySize = PriceToY(bodyRange); view.Body.sizeDelta = new Vector2(view.Body.sizeDelta.x, bodySize); //body spread var bodyLow = model.Close > model.Open ? model.Open : model.Close; var bodySpread = Mathf.Abs(bodyLow - model.Low); var bodyY = PriceToY(bodySpread); view.Body.anchoredPosition = new Vector2(0, bodyY); // paint if (model.Open > model.Close) { view.PaintRed(); } else { view.PaintGreen(); } }