diff --git a/src/client/spark/AW2/ViewModel/Graph/VolSurfaceGraphVM.cs b/src/client/spark/AW2/ViewModel/Graph/VolSurfaceGraphVM.cs index 282d5d2c2..f7b00aa0b 100644 --- a/src/client/spark/AW2/ViewModel/Graph/VolSurfaceGraphVM.cs +++ b/src/client/spark/AW2/ViewModel/Graph/VolSurfaceGraphVM.cs @@ -10,7 +10,9 @@ namespace mbts.spark { using mbts.ui.shell; using mbts.ui.utility; + using Spark.Analytics.View; using Spark.Core.Disposables; + using Spark.Core.Protobuf; using System; using System.Collections; @@ -29,13 +31,13 @@ namespace mbts.spark { readonly LinearAxisVM _x_axis = new() { position = AxisPosition.BottomLeftToRight }; readonly LinearAxisVM _y_axis = new() { position = AxisPosition.LeftBottomToTop }; readonly Dictionary _expiration_graph_bounds; - readonly VolSurfaceGraphSettings _settings; readonly ObservableCollection _expirations = new(); readonly Dictionary _expiration_series_cache = new(); VolSurfaceExpiration _md_exp; VolSurfaceDisplayGridExpiration _expiration; VolSurfaceDisplayGridExpiration _earliest_selected_expiration; + VolSurfaceGraphSettings _settings; object _implied_vol_market_side = ImpliedVolHelper.None; bool _show_vol_path; @@ -82,13 +84,17 @@ namespace mbts.spark { if (_model.get_active_settings() is not VolSurfaceSettings vss) { return null; } - // return new VolSurfaceGraphSettingsEditor { - // DataContext = new VolSurfaceGraphSettingsEditorVM(vss.core_settings.vol_surface_name, ProtoBufSerializationHelper.clone_protobuf(_settings), settings => { - // _settings = settings; - // _recreate_series(); - // }) - // }; - return null; + var vm = new VolSurfaceGraphSettingsVM(vss.core_settings.vol_surface_name); + vm.load_from(_settings.Clone()); + vm.request_commit += commit; + return new VolSurfaceGraphSettingsWindow { + DataContext = vm + }; + + void commit(VolSurfaceGraphSettings settings) { + _settings = settings; + _recreate_series(); + } }); graph_vm = new BTSGraphVM { plot_area_background = Colors.Transparent, @@ -185,6 +191,20 @@ namespace mbts.spark { static (double call_wing_start, double put_wing_start) _get_actual_wing_starts(VolCurveDisplayGraph disp_graph) => disp_graph.all_points.Select(p => p.Item1).MinMax() ?? (double.NaN, double.NaN); + void _recreate_series() { + /// 'graph_vm.series_set' is bound to '_expirations', so clearing and re-adding expirations + /// in turn regenerates the series. '_expiration_series_cache' must + /// be cleared as well, otherwise cached series vms would just be back to the collection + /// ('graph_vm.series_set'). + var visible_exp = _earliest_selected_expiration; + _expiration_series_cache.Clear(); + _expirations.SetItems(_model.get_ordered_expirations()); + foreach (var svm in graph_vm.series.OfType()) { + svm.is_visible = svm.args.Equals(visible_exp); + } + _update(); + } + void _expirations_changed(IEnumerable added, IEnumerable removed) { _expirations.sync_with(_model.get_ordered_expirations()); _update(); diff --git a/src/client/spark/AW2/ViewModel/SettingsEditors/VolSurfaceGraphSettingsEditorVM.cs b/src/client/spark/AW2/ViewModel/SettingsEditors/VolSurfaceGraphSettingsEditorVM.cs deleted file mode 100644 index bee79a0f0..000000000 --- a/src/client/spark/AW2/ViewModel/SettingsEditors/VolSurfaceGraphSettingsEditorVM.cs +++ /dev/null @@ -1,72 +0,0 @@ -using mbts.ui; -using mbts.ui.controls.graph; -using System; -using System.Windows.Input; -using System.Windows.Media; - -namespace mbts.spark -{ - class VolSurfaceGraphSettingsEditorVM - { - public VolSurfaceGraphSettingsEditorVM(string vol_surface_name, VolSurfaceGraphSettings settings, Action commit) { - this.vol_surface_name = vol_surface_name; - _settings = settings; - this.commit = new DelegateCommand(() => commit(_settings)); - } - - private readonly VolSurfaceGraphSettings _settings; - - public string vol_surface_name { get; private set; } - - public VolSurfaceScatterSeriesSettingsVM implied_puts { get { return new VolSurfaceScatterSeriesSettingsVM(_settings.implied_puts); } } - public VolSurfaceScatterSeriesSettingsVM implied_atm { get { return new VolSurfaceScatterSeriesSettingsVM(_settings.implied_atm); } } - public VolSurfaceScatterSeriesSettingsVM implied_calls { get { return new VolSurfaceScatterSeriesSettingsVM(_settings.implied_calls); } } - - public VolSurfaceScatterSeriesSettingsVM put_control_points { get { return new VolSurfaceScatterSeriesSettingsVM(_settings.put_control_points); } } - public VolSurfaceScatterSeriesSettingsVM atm { get { return new VolSurfaceScatterSeriesSettingsVM(_settings.atm); } } - public VolSurfaceScatterSeriesSettingsVM call_control_points { get { return new VolSurfaceScatterSeriesSettingsVM(_settings.call_control_points); } } - - public VolSurfaceLineSeriesSettingsVM put_wing { get { return new VolSurfaceLineSeriesSettingsVM(_settings.put_wing); } } - public VolSurfaceLineSeriesSettingsVM inner_curve { get { return new VolSurfaceLineSeriesSettingsVM(_settings.inner_curve); } } - public VolSurfaceLineSeriesSettingsVM call_wing { get { return new VolSurfaceLineSeriesSettingsVM(_settings.call_wing); } } - - public VolSurfaceLineSeriesSettingsVM vol_path { get { return new VolSurfaceLineSeriesSettingsVM(_settings.vol_path); } } - - public ICommand commit { get; private set; } - } - - - class VolSurfaceScatterSeriesSettingsVM - { - public VolSurfaceScatterSeriesSettingsVM(ScatterSeriesSettings settings) { - _settings = settings; - } - - private readonly ScatterSeriesSettings _settings; - - public MarkerShape shape { get { return _settings.shape; } set { _settings.shape = value; } } - public double size { get { return _settings.size; } set { _settings.size = value; } } - public Color fill { - get => _settings.fill; - set => _settings.fill = value; - } - public Color stroke { - get => _settings.stroke; - set => _settings.stroke = value; - } - - public Array shapes { get { return Enum.GetValues(typeof(MarkerShape)); } } - } - - class VolSurfaceLineSeriesSettingsVM - { - public VolSurfaceLineSeriesSettingsVM(LineSeriesSettings settings) { - _settings = settings; - } - - private readonly LineSeriesSettings _settings; - - public Color color { get { return (Color)_settings.color; } set { _settings.color = (BTSColor)value; } } - public double thickness { get { return _settings.stroke_thickness; } set { _settings.stroke_thickness = value; } } - } -} diff --git a/src/client/spark/Modules/Analytics/VolSurface/View/VolSurfaceGraphSettingsView.xaml b/src/client/spark/Modules/Analytics/VolSurface/View/VolSurfaceGraphSettingsView.xaml new file mode 100644 index 000000000..904c25b3f --- /dev/null +++ b/src/client/spark/Modules/Analytics/VolSurface/View/VolSurfaceGraphSettingsView.xaml @@ -0,0 +1,161 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/client/spark/Modules/Analytics/VolSurface/View/VolSurfaceGraphSettingsView.xaml.cs b/src/client/spark/Modules/Analytics/VolSurface/View/VolSurfaceGraphSettingsView.xaml.cs new file mode 100644 index 000000000..c2e0e63ca --- /dev/null +++ b/src/client/spark/Modules/Analytics/VolSurface/View/VolSurfaceGraphSettingsView.xaml.cs @@ -0,0 +1,9 @@ +#nullable enable +namespace Spark.Analytics.View { + using System.Windows.Controls; + + partial class VolSurfaceGraphSettingsView : UserControl { + public VolSurfaceGraphSettingsView() => + InitializeComponent(); + } +} diff --git a/src/client/spark/Modules/Analytics/VolSurface/View/VolSurfaceGraphSettingsWindow.xaml b/src/client/spark/Modules/Analytics/VolSurface/View/VolSurfaceGraphSettingsWindow.xaml new file mode 100644 index 000000000..105c404d7 --- /dev/null +++ b/src/client/spark/Modules/Analytics/VolSurface/View/VolSurfaceGraphSettingsWindow.xaml @@ -0,0 +1,31 @@ + + + + + + + + + + + + + + diff --git a/src/client/spark/Modules/Analytics/VolSurface/View/VolSurfaceGraphSettingsWindow.xaml.cs b/src/client/spark/Modules/Analytics/VolSurface/View/VolSurfaceGraphSettingsWindow.xaml.cs new file mode 100644 index 000000000..2fe7eaad6 --- /dev/null +++ b/src/client/spark/Modules/Analytics/VolSurface/View/VolSurfaceGraphSettingsWindow.xaml.cs @@ -0,0 +1,9 @@ +#nullable enable +namespace Spark.Analytics.View { + using System.Windows; + + partial class VolSurfaceGraphSettingsWindow : Window { + public VolSurfaceGraphSettingsWindow() => + InitializeComponent(); + } +} diff --git a/src/client/spark/Modules/Analytics/VolSurface/ViewModel/VolSurfaceGraphSettingsVM.cs b/src/client/spark/Modules/Analytics/VolSurface/ViewModel/VolSurfaceGraphSettingsVM.cs new file mode 100644 index 000000000..30fd4bd82 --- /dev/null +++ b/src/client/spark/Modules/Analytics/VolSurface/ViewModel/VolSurfaceGraphSettingsVM.cs @@ -0,0 +1,85 @@ +#nullable enable +namespace mbts.spark { + using mbts.ui; + + using System; + using System.Windows.Input; + + class VolSurfaceGraphSettingsVM : IRequestViewClose { + /// + /// A reference to the settings obj last loaded (). It contains props + /// that aren't edited by this class. It is kept because a settings obj generated by this + /// class from scratch would lose some information from the original settings obj. + /// + VolSurfaceGraphSettings? _settings; + + public VolSurfaceGraphSettingsVM(string vol_surface_name) { + this.vol_surface_name = vol_surface_name; + apply_cmd = new Command(apply); + commit_cmd = new Command(commit); + + void apply() { + if (request_commit is null) { + return; + } + var res = _settings?.Clone() ?? new(); + assign_to(res); + request_commit(res); + } + + void commit() { + apply(); + RequestClose?.Invoke(this, EventArgs.Empty); + } + } + + public event EventHandler? RequestClose; + public event Action? request_commit; + + public string vol_surface_name { get; } + + public VolSurfaceScatterSeriesSettingsVM implied_puts { get; } = new(); + public VolSurfaceScatterSeriesSettingsVM implied_atm { get; } = new(); + public VolSurfaceScatterSeriesSettingsVM implied_calls { get; } = new(); + + public VolSurfaceScatterSeriesSettingsVM put_control_points { get; } = new(); + public VolSurfaceScatterSeriesSettingsVM atm { get; } = new(); + public VolSurfaceScatterSeriesSettingsVM call_control_points { get; } = new(); + + public VolSurfaceLineSeriesSettingsVM put_wing { get; } = new(); + public VolSurfaceLineSeriesSettingsVM inner_curve { get; } = new(); + public VolSurfaceLineSeriesSettingsVM call_wing { get; } = new(); + + public VolSurfaceLineSeriesSettingsVM vol_path { get; } = new(); + + public ICommand apply_cmd { get; } + public ICommand commit_cmd { get; } + + public void assign_to(VolSurfaceGraphSettings settings) { + implied_puts.assign_to(settings.implied_puts); + implied_atm.assign_to(settings.implied_atm); + implied_calls.assign_to(settings.implied_calls); + put_control_points.assign_to(settings.put_control_points); + atm.assign_to(settings.atm); + call_control_points.assign_to(settings.call_control_points); + put_wing.assign_to(settings.put_wing); + inner_curve.assign_to(settings.inner_curve); + call_wing.assign_to(settings.call_wing); + vol_path.assign_to(settings.vol_path); + } + + public void load_from(VolSurfaceGraphSettings settings) { + _settings = settings; + implied_puts.load_from(settings.implied_puts); + implied_atm.load_from(settings.implied_atm); + implied_calls.load_from(settings.implied_calls); + put_control_points.load_from(settings.put_control_points); + atm.load_from(settings.atm); + call_control_points.load_from(settings.call_control_points); + put_wing.load_from(settings.put_wing); + inner_curve.load_from(settings.inner_curve); + call_wing.load_from(settings.call_wing); + vol_path.load_from(settings.vol_path); + } + } +} diff --git a/src/client/spark/Modules/Analytics/VolSurface/ViewModel/VolSurfaceLineSeriesSettingsVM.cs b/src/client/spark/Modules/Analytics/VolSurface/ViewModel/VolSurfaceLineSeriesSettingsVM.cs new file mode 100644 index 000000000..32ec43d00 --- /dev/null +++ b/src/client/spark/Modules/Analytics/VolSurface/ViewModel/VolSurfaceLineSeriesSettingsVM.cs @@ -0,0 +1,30 @@ +#nullable enable +namespace mbts.spark { + using mbts.ui.controls; + using mbts.ui.shell; + + class VolSurfaceLineSeriesSettingsVM : ViewModelBase { + readonly Property _stroke_thickness; + + public VolSurfaceLineSeriesSettingsVM() { + _stroke_thickness = backing(nameof(stroke_thickness), 2.0); + } + + public double stroke_thickness { + get => _stroke_thickness.Value; + set => _stroke_thickness.set(value); + } + + public ColorPickerPopupVM color_vm { get; } = new() { bind_opacity_to_alpha = true }; + + public void load_from(LineSeriesSettings settings) { + color_vm.color = settings.color; + stroke_thickness = settings.stroke_thickness; + } + + public void assign_to(LineSeriesSettings settings) { + settings.color = color_vm.color; + settings.stroke_thickness = stroke_thickness; + } + } +} diff --git a/src/client/spark/Modules/Analytics/VolSurface/ViewModel/VolSurfaceScatterSeriesSettingsVM.cs b/src/client/spark/Modules/Analytics/VolSurface/ViewModel/VolSurfaceScatterSeriesSettingsVM.cs new file mode 100644 index 000000000..ca1f8e21c --- /dev/null +++ b/src/client/spark/Modules/Analytics/VolSurface/ViewModel/VolSurfaceScatterSeriesSettingsVM.cs @@ -0,0 +1,47 @@ +#nullable enable +namespace mbts.spark { + using mbts.ui.controls; + using mbts.ui.shell; + using mbts.ui.utility; + + using System.Collections.Generic; + + class VolSurfaceScatterSeriesSettingsVM : ViewModelBase { + readonly Property _shape; + readonly Property _size; + + public VolSurfaceScatterSeriesSettingsVM() { + _shape = backing(nameof(shape), MarkerShape.Circle); + _size = backing(nameof(size), 2.0); + } + + public MarkerShape shape { + get => _shape.Value; + set => _shape.set(value); + } + + public double size { + get => _size.Value; + set => _size.set(value); + } + + public IReadOnlyList shapes => + EnumHelper.get_values(); + + public ColorPickerPopupVM fill_vm { get; } = new() { bind_opacity_to_alpha = true }; + public ColorPickerPopupVM stroke_vm { get; } = new() { bind_opacity_to_alpha = true }; + + public void load_from(ScatterSeriesSettings settings) { + shape = settings.shape; + size = settings.size; + fill_vm.color = settings.fill; + stroke_vm.color = settings.stroke; + } + + public void assign_to(ScatterSeriesSettings settings) { + settings.fill = fill_vm.color; + settings.stroke = stroke_vm.color; + settings.shape = shape; + } + } +}