From da1ae1b410e5494b9c3fb0da795c8d0f0e199ea1 Mon Sep 17 00:00:00 2001 From: Jake Norbut Date: Mon, 29 Apr 2019 09:25:22 -0500 Subject: [PATCH] badge - the rest of SPARK-2291 - no more parent info --- .../Trading/Ladder/VM/LadderOrderVM.cs | 20 +++---- .../Modules/Trading/Ladder/VM/LadderVM.cs | 19 ------- .../Trading/Ladder/View/LadderView.xaml | 3 +- .../Trading/Ladder/View/MiniLadderView.xaml | 3 +- src/client/spark/view/Controls/Badge.cs | 57 +++++++------------ 5 files changed, 33 insertions(+), 69 deletions(-) diff --git a/src/client/spark/Modules/Trading/Ladder/VM/LadderOrderVM.cs b/src/client/spark/Modules/Trading/Ladder/VM/LadderOrderVM.cs index 50eb09d5f..f8016c184 100644 --- a/src/client/spark/Modules/Trading/Ladder/VM/LadderOrderVM.cs +++ b/src/client/spark/Modules/Trading/Ladder/VM/LadderOrderVM.cs @@ -34,9 +34,9 @@ namespace mbts.spark { readonly Property _font_family; readonly Property _font_weight; readonly Property _font_size; - readonly Property _foreground, _background, _hoverbackground, _border, _parent_algo_type_brush; + readonly Property _foreground, _background, _hoverbackground, _border; readonly Property _has_multiple_orders_at_same_level, _is_hedge_order; - readonly Property _parent_algo_type; + readonly Property _algo_type; readonly Property _summary; IObservable _bs; LadderSettings.BadgeStyle _current_badge_style; @@ -65,8 +65,7 @@ namespace mbts.spark { _summary = backing(nameof(summary), string.Empty); _has_multiple_orders_at_same_level = backing(nameof(has_multiple_orders_at_same_level), false); _is_hedge_order = backing(nameof(is_hedge_order), false); - _parent_algo_type = backing(nameof(parent_algo_type), CustomOrderDefinition.CustomOneofCase.None); - _parent_algo_type_brush = backing(nameof(parent_algo_type_brush), _color_bg_brush); + _algo_type = backing(nameof(algo_type), CustomOrderDefinition.CustomOneofCase.None); FontFamily get_font_family(LadderSettings s) => new FontFamily(s.orders_column.font_family); FontWeight get_font_weight(LadderSettings s) => ui.utility.text.TextUtils.from_open_type_weight_safe(s.orders_column.font_weight); double get_font_size(LadderSettings s) => s.orders_column.font_size; @@ -94,9 +93,6 @@ namespace mbts.spark { } var darker = BTSColor.darken2(color.R, color.G, color.B, 0.75); Color dark = new Color() { A = 255, R = darker.r, G = darker.g, B = darker.b }; - //var completion = _parent_and_child_not_sharing_slot().Sum(order => OrderUtils.filled(order)) / _parent_and_child_not_sharing_slot().Sum(order => OrderUtils.quantity(order)); - bts.spark.OrderMetadata parent_algo_metadata = _parent.model.order_gateway.factory.get_metadata(parent_algo_type); - parent_algo_type_brush = parent_algo_metadata.Color.rgb_brush(); var buy_sell_background_fill_color = new SolidColorBrush(color); buy_sell_background_fill_color.Freeze(); background = buy_sell_background_fill_color; @@ -117,6 +113,12 @@ namespace mbts.spark { var single_order = _orders.Values.First(); var single_order_metadata = _parent.model.order_gateway.factory.get_metadata(single_order); border = single_order_metadata.Color.rgb_brush(); + if (single_order.order_type().is_bts_algo_type()) { + algo_type = single_order.order_type(); + } else { + algo_type = CustomOrderDefinition.CustomOneofCase.None; + } + } else { border = new SolidColorBrush(color); } @@ -190,9 +192,7 @@ namespace mbts.spark { public string summary { get => _summary.Value; private set => _summary.Value = value; } public bool has_multiple_orders_at_same_level { get => _has_multiple_orders_at_same_level.Value; private set => _has_multiple_orders_at_same_level.Value = value; } public bool is_hedge_order { get => _is_hedge_order.Value; private set => _is_hedge_order.Value = value; } - public Brush parent_algo_type_brush { get => _parent_algo_type_brush.Value; private set => _parent_algo_type_brush.Value = value; } - // the setter is public so that the LadderVM can set this field - public CustomOrderDefinition.CustomOneofCase parent_algo_type { get => _parent_algo_type.Value; set => _parent_algo_type.Value = value; } + public CustomOrderDefinition.CustomOneofCase algo_type { get => _algo_type.Value; private set => _algo_type.Value = value; } public IEnumerable orders => _orders.Values; diff --git a/src/client/spark/Modules/Trading/Ladder/VM/LadderVM.cs b/src/client/spark/Modules/Trading/Ladder/VM/LadderVM.cs index fbb2bf8f7..31508a8a3 100644 --- a/src/client/spark/Modules/Trading/Ladder/VM/LadderVM.cs +++ b/src/client/spark/Modules/Trading/Ladder/VM/LadderVM.cs @@ -193,25 +193,6 @@ namespace mbts.spark { // update dirty brushes and text foreach (var lovm in _slot_price_vs_orders.Values) { - // the parent algo is only valid when there is only a single order at a level - if (lovm.orders.Count() == 1) { - var only_order = lovm.orders.First(); - - if (only_order.has_parent()) { - var traversal_candidate = only_order; - bool exit_early = false; - while (!exit_early && traversal_candidate.ParentKey != 0) { - if (_cache.TryGetValue(traversal_candidate.ParentKey, out var target)) - traversal_candidate = target; - else - exit_early = true; - } - if (!exit_early) - // we have successfully reached the root - lovm.parent_algo_type = traversal_candidate.Def.CustomDef.CustomCase; - } - // else this a single order, so do nothing - } lovm.update(); } diff --git a/src/client/spark/Modules/Trading/Ladder/View/LadderView.xaml b/src/client/spark/Modules/Trading/Ladder/View/LadderView.xaml index 325e0164e..88aab21f8 100644 --- a/src/client/spark/Modules/Trading/Ladder/View/LadderView.xaml +++ b/src/client/spark/Modules/Trading/Ladder/View/LadderView.xaml @@ -554,8 +554,7 @@ - - + diff --git a/src/client/spark/Modules/Trading/Ladder/View/MiniLadderView.xaml b/src/client/spark/Modules/Trading/Ladder/View/MiniLadderView.xaml index a9a0d1863..140c0ad25 100644 --- a/src/client/spark/Modules/Trading/Ladder/View/MiniLadderView.xaml +++ b/src/client/spark/Modules/Trading/Ladder/View/MiniLadderView.xaml @@ -102,8 +102,7 @@ - - + diff --git a/src/client/spark/view/Controls/Badge.cs b/src/client/spark/view/Controls/Badge.cs index 2d7b10449..7c2c4ff4c 100644 --- a/src/client/spark/view/Controls/Badge.cs +++ b/src/client/spark/view/Controls/Badge.cs @@ -36,9 +36,9 @@ namespace mbts.ui.controls { //static ConcurrentDictionary<(Point p1, Point p2, Point p3), StreamGeometry> _sg_cache = new ConcurrentDictionary<(Point p1, Point p2, Point p3), StreamGeometry>(); readonly GlyphContentRect _gcr = new GlyphContentRect(); - Brush _background, _foreground, _border_brush, _parent_algo_type_brush; + Brush _background, _foreground, _border_brush; bool _has_multiple_orders_at_level, _is_hedge_order; - CustomOrderDefinition.CustomOneofCase _parent_algo_type; + CustomOrderDefinition.CustomOneofCase _algo_type; (Point p1, Point p2, Point p3) _current_triangle_vertices; StreamGeometry _triangle_geometry; Popup _popup; @@ -221,30 +221,18 @@ namespace mbts.ui.controls { (b, v) => b._has_multiple_orders_at_level = v, false); - public CustomOrderDefinition.CustomOneofCase ParentAlgoType { - get { return (CustomOrderDefinition.CustomOneofCase)GetValue(ParentAlgoTypeProperty); } - set { SetValue(ParentAlgoTypeProperty, value); } + public CustomOrderDefinition.CustomOneofCase AlgoType { + get { return (CustomOrderDefinition.CustomOneofCase)GetValue(AlgoTypeProperty); } + set { SetValue(AlgoTypeProperty, value); } } - public static readonly DependencyProperty ParentAlgoTypeProperty = + public static readonly DependencyProperty AlgoTypeProperty = WPFHelper.create_dp( - nameof(ParentAlgoType), + nameof(AlgoType), FrameworkPropertyMetadataOptions.AffectsRender, - (b, v) => b._parent_algo_type = v, + (b, v) => b._algo_type = v, CustomOrderDefinition.CustomOneofCase.None); - public Brush ParentAlgoTypeBrush { - get { return (Brush)GetValue(ParentAlgoTypeBrushProperty); } - set { SetValue(ParentAlgoTypeBrushProperty, value); } - } - - public static readonly DependencyProperty ParentAlgoTypeBrushProperty = - WPFHelper.create_dp( - nameof(ParentAlgoTypeBrush), - FrameworkPropertyMetadataOptions.AffectsRender, - (b, v) => b._parent_algo_type_brush = v, - Brushes.White); - public bool IsHedgeOrder { get { return (bool)GetValue(IsHedgeOrderProperty); } set { SetValue(IsHedgeOrderProperty, value); } @@ -326,22 +314,19 @@ namespace mbts.ui.controls { dc.DrawGlyphRun(Brushes.Black, a_glyph_run); } - if (ParentAlgoType != CustomOrderDefinition.CustomOneofCase.None) { - dc.DrawRectangle(ParentAlgoTypeBrush, null, new Rect(4 * border_thickness, 0 + 2 * border_thickness, 10, _gcr.layout_size.Height - 2 * border_thickness)); - var palgo_type_name = utility.EnumHelper.get_display_name(ParentAlgoType); - if (palgo_type_name.Length > 1) { - var a_glyph_context = _gcr.glyph_context; - var a_glyph_run = a_glyph_context.get_glyph_run( - palgo_type_name.Substring(0, 1), - 12, - _gcr.layout_size.Width, - _gcr.layout_size.Height, - HorizontalAlignment.Left, - 4 * border_thickness + 1, - VerticalAlignment.Center, - 0); - dc.DrawGlyphRun(Brushes.Black, a_glyph_run); - } + if (AlgoType != CustomOrderDefinition.CustomOneofCase.None) { + var a_glyph_context = _gcr.glyph_context; + var a_glyph_run = a_glyph_context.get_glyph_run( + mbts.spark.utilities.OrderDataHelper.abbreviate_algo_type(AlgoType), + 12, + _gcr.layout_size.Width, + _gcr.layout_size.Height, + HorizontalAlignment.Left, + 2 * border_thickness + 1, + VerticalAlignment.Center, + 0); + dc.DrawGlyphRun(Brushes.Black, a_glyph_run); + }