/// <summary>Add the spot price to the chart</summary> public void BuildScene(TradePair pair, ChartControl chart) { // Add b2q first, so green is above red var spot_b2q = pair.SpotPrice[ETradeType.B2Q]; var spot_q2b = pair.SpotPrice[ETradeType.Q2B]; if (spot_b2q != null) { var pt0 = chart.ChartToClient(new Point(chart.XAxis.Min, spot_b2q.Value.ToDouble())); var pt1 = chart.ChartToClient(new Point(chart.XAxis.Max, spot_b2q.Value.ToDouble())); // Add the line B2QLine.X1 = pt0.X; B2QLine.Y1 = pt0.Y; B2QLine.X2 = pt1.X; B2QLine.Y2 = pt1.Y; chart.Overlay.Adopt(B2QLine); // Add the price label var pt = chart.TransformToDescendant(chart.YAxisPanel).Transform(pt1); Canvas.SetLeft(B2QPrice, 0); Canvas.SetTop(B2QPrice, pt.Y - B2QPrice.RenderSize.Height / 2); B2QPrice.Text = spot_b2q.Value.ToString(8); chart.YAxisPanel.Adopt(B2QPrice); } else { B2QLine.Detach(); B2QPrice.Detach(); } if (spot_q2b != null) { var pt0 = chart.ChartToClient(new Point(chart.XAxis.Min, spot_q2b.Value.ToDouble())); var pt1 = chart.ChartToClient(new Point(chart.XAxis.Max, spot_q2b.Value.ToDouble())); // Add the line Q2BLine.X1 = pt0.X; Q2BLine.Y1 = pt0.Y; Q2BLine.X2 = pt1.X; Q2BLine.Y2 = pt1.Y; chart.Overlay.Adopt(Q2BLine); // Add the price label var pt = chart.TransformToDescendant(chart.YAxisPanel).Transform(pt1); Canvas.SetLeft(Q2BPrice, 0); Canvas.SetTop(Q2BPrice, pt.Y - Q2BPrice.RenderSize.Height / 2); Q2BPrice.Text = spot_q2b.Value.ToString(8); chart.YAxisPanel.Adopt(Q2BPrice); } else { Q2BLine.Detach(); Q2BPrice.Detach(); } }
/// <summary>Update the scene for the given transfers</summary> public void BuildScene(IEnumerable <IItem> items, IEnumerable <IItem> highlighted, ChartControl chart) { var in_scene = items.ToHashSet(0); var highlight = highlighted?.ToHashSet(0) ?? new HashSet <IItem>(); // Remove all gfx that is no longer in the scene var remove = m_gfx.Where(kv => !in_scene.Contains(kv.Key)).ToList(); foreach (var gfx in remove) { m_gfx.Remove(gfx.Key); gfx.Value.Dispose(); } // Add graphics objects for each item in the scene foreach (var item in items) { // Get the associated graphics objects var gfx = m_gfx.GetOrAdd(item, k => new GfxItem(this, item)); // Update the position var pt = Position(item); var s = chart.ChartToClient(pt); var hl = highlight.Contains(item); gfx.Update(chart.Overlay, s, hl); } }
/// <summary>Display the updating text</summary> public void BuildScene(bool updating, ChartControl chart) { if (updating) { var pt = chart.ChartToClient(new Point(chart.XAxis.Max, chart.YAxis.Max)); Canvas.SetLeft(Text, pt.X - Text.RenderSize.Width); Canvas.SetTop(Text, pt.Y); chart.Overlay.Adopt(Text); } else { Text.Detach(); } }
/// <summary></summary> public void BuildScene(ChartControl chart) { if (Instrument != null && Instrument.Count != 0 && (Instrument.Count - 1.0).Within(chart.XAxis.Range)) { Label.Text = (Instrument.Latest.CloseTime(Instrument.TimeFrame) - Model.UtcNow).ToPrettyString(); Label.Measure(new Size(1000, 1000)); var pt = chart.ChartToClient(new Point(Instrument.Count - 1, chart.YAxis.Min)); Canvas.SetLeft(Label, pt.X - Label.DesiredSize.Width / 2); Canvas.SetTop(Label, pt.Y - Label.DesiredSize.Height); chart.Overlay.Adopt(Label); } else { Label.Detach(); } }