refactor: Use nifty extension fns in vs grid vm
This commit is contained in:
1 parent
9df339c4a7
commit
53e9d90bf9
3 files changed
+41
-35
No files matched your search
@@ -178,25 +178,11 @@ namespace mbts.spark.VolSurface {
|
||||
public ObservableCollection<VolSurfaceRowContext> rows { get; } = new();
|
||||
public ObservableCollection<VolSurfaceRowContext> visible_rows { get; } = new();
|
||||
|
||||
public bool any_masters_selected { get { return selected_rows.Any(r => !r.expiration.is_slave); } }
|
||||
public bool any_masters_selected =>
|
||||
selected_rows.select_display_exp().where_master().Any();
|
||||
|
||||
public IEnumerable<VolSurfaceRowContext> selected_rows {
|
||||
get {
|
||||
return visible_rows
|
||||
.OfType<VolSurfaceRowContext>()
|
||||
.Where(r => r.is_selected);
|
||||
}
|
||||
}
|
||||
|
||||
IEnumerable<VolSurfaceRowContext> typed_visible_rows => visible_rows.Cast<VolSurfaceRowContext>();
|
||||
IEnumerable<VolSurfaceDisplayGridExpiration> selected_expirations => selected_rows.Select(r => r.expiration);
|
||||
IEnumerable<VolSurfaceDisplayGridExpiration> master_expirations => model.get_active_grid().get_ordered_expirations().Where(e => !e.is_slave);
|
||||
IEnumerable<VolSurfaceDisplayGridExpiration> all_expirations => model.get_active_grid().get_ordered_expirations();
|
||||
|
||||
public ICommand main_settings_command { get { return _parent.main_settings_command; } }
|
||||
public ICommand advanced_settings_command { get { return _parent.advanced_settings_command; } }
|
||||
public ICommand graph_settings_command { get { return _parent.vol_curve_vm.settings_command; } }
|
||||
public ICommand grid_settings_command { get { return _parent.grid_settings_command; } }
|
||||
public IEnumerable<VolSurfaceRowContext> selected_rows =>
|
||||
visible_rows.where_selected();
|
||||
|
||||
public IEnumerable<DIYGridSuperHeader> super_headers =>
|
||||
// There are no superheaders over frozen columns (currently)
|
||||
@@ -213,6 +199,9 @@ namespace mbts.spark.VolSurface {
|
||||
_on_grid_updated();
|
||||
}
|
||||
|
||||
public IEnumerable<VolSurfaceExpiration> get_hidden_expirations() =>
|
||||
rows.select_exp().Except(visible_rows.select_exp());
|
||||
|
||||
internal void signal_selection_changed() {
|
||||
var e = on_selection_changed;
|
||||
if (e != null) {
|
||||
@@ -222,30 +211,32 @@ namespace mbts.spark.VolSurface {
|
||||
}
|
||||
|
||||
internal void shift_selection(VolSurfaceDisplayGridTextInputColumn column) =>
|
||||
_launch_shift_editor(column, shift => _shift(column, selected_expirations, shift));
|
||||
_launch_shift_editor(column, shift => _shift(column, selected_rows.select_display_exp(), shift));
|
||||
|
||||
internal void shift_masters(VolSurfaceDisplayGridTextInputColumn column) =>
|
||||
_launch_shift_editor(column, shift => _shift(column, master_expirations, shift));
|
||||
_launch_shift_editor(column, shift => _shift(column, _expirations.where_master(), shift));
|
||||
|
||||
internal void shift_all(VolSurfaceDisplayGridTextInputColumn column) =>
|
||||
_launch_shift_editor(column, shift => _shift(column, all_expirations, shift));
|
||||
_launch_shift_editor(column, shift => _shift(column, _expirations, shift));
|
||||
|
||||
internal void clear(VolSurfaceDisplayGridColumn col, GridColumnSet where) {
|
||||
switch (where) {
|
||||
case GridColumnSet.Column:
|
||||
foreach (VolSurfaceDisplayGridExpiration exp in selected_expirations) {
|
||||
foreach (var exp in selected_rows.select_display_exp()) {
|
||||
_clear(exp, col);
|
||||
}
|
||||
_commit();
|
||||
break;
|
||||
case GridColumnSet.Group:
|
||||
foreach (VolSurfaceDisplayGridExpiration exp in selected_expirations) {
|
||||
foreach (var c in _internal_columns.Where(c => c.group == col.group)) _clear(exp, c);
|
||||
foreach (var exp in selected_rows.select_display_exp()) {
|
||||
foreach (var c in _internal_columns.Where(c => c.group == col.group)) {
|
||||
_clear(exp, c);
|
||||
}
|
||||
}
|
||||
_commit();
|
||||
break;
|
||||
case GridColumnSet.All:
|
||||
foreach (VolSurfaceDisplayGridExpiration exp in selected_expirations) {
|
||||
foreach (var exp in selected_rows.select_display_exp()) {
|
||||
foreach (var c in _internal_columns) _clear(exp, c);
|
||||
}
|
||||
_commit();
|
||||
@@ -257,19 +248,19 @@ namespace mbts.spark.VolSurface {
|
||||
|
||||
internal void copy_to_selection(VolSurfaceDisplayGridExpiration exp, VolSurfaceDisplayGridColumn column, GridColumnSet set) {
|
||||
if (column is VolSurfaceDisplayGridTextColumn input_col) {
|
||||
_replicate(exp, selected_expirations.Except(new[] { exp }), _get_columns(input_col, set));
|
||||
_replicate(exp, selected_rows.select_display_exp().Except(exp), _get_columns(input_col, set));
|
||||
}
|
||||
}
|
||||
|
||||
internal void copy_to_masters(VolSurfaceDisplayGridExpiration exp, VolSurfaceDisplayGridColumn column, GridColumnSet set) {
|
||||
if (column is VolSurfaceDisplayGridTextColumn input_col) {
|
||||
_replicate(exp, master_expirations.Except(new[] { exp }), _get_columns(input_col, set));
|
||||
_replicate(exp, _expirations.where_master().Except(exp), _get_columns(input_col, set));
|
||||
}
|
||||
}
|
||||
|
||||
internal void copy_to_all(VolSurfaceDisplayGridExpiration exp, VolSurfaceDisplayGridColumn column, GridColumnSet set) {
|
||||
if (column is VolSurfaceDisplayGridTextColumn input_col) {
|
||||
_replicate(exp, all_expirations.Except(new[] { exp }), _get_columns(input_col, set));
|
||||
_replicate(exp, _expirations.Except(exp), _get_columns(input_col, set));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -390,10 +381,5 @@ namespace mbts.spark.VolSurface {
|
||||
|
||||
void _commit() =>
|
||||
model.set_candidate_grid(current_grid);
|
||||
|
||||
public List<VolSurfaceExpiration> get_hidden_expirations() {
|
||||
var visible_exps = new HashSet<VolSurfaceDisplayGridExpiration>(typed_visible_rows.Select(rc => rc.expiration));
|
||||
return rows.Where(r => !visible_exps.Contains(r.expiration)).Select(r => r.expiration.ToVSExp()).ToList();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,8 +1,9 @@
|
||||
|
||||
namespace mbts.spark {
|
||||
namespace mbts.spark {
|
||||
using bts.api;
|
||||
using bts.api.analytics;
|
||||
|
||||
using mbts.analytics;
|
||||
using mbts.spark.VolSurface;
|
||||
using mbts.ui.controls;
|
||||
|
||||
using System.Collections.Generic;
|
||||
@@ -66,5 +67,17 @@ namespace mbts.spark {
|
||||
VolSurfaceGraphSeriesType.ImpliedVolCalls => true,
|
||||
_ => false,
|
||||
};
|
||||
|
||||
public static IEnumerable<VolSurfaceExpiration> select_exp(this IEnumerable<VolSurfaceRowContext> rows) =>
|
||||
rows.Select(r => r.expiration.ToVSExp());
|
||||
|
||||
public static IEnumerable<VolSurfaceDisplayGridExpiration> select_display_exp(this IEnumerable<VolSurfaceRowContext> rows) =>
|
||||
rows.Select(r => r.expiration);
|
||||
|
||||
public static IEnumerable<VolSurfaceDisplayGridExpiration> where_master(this IEnumerable<VolSurfaceDisplayGridExpiration> rows) =>
|
||||
rows.Where(r => !r.is_slave);
|
||||
|
||||
public static IEnumerable<VolSurfaceDisplayGridExpiration> where_slave(this IEnumerable<VolSurfaceDisplayGridExpiration> rows) =>
|
||||
rows.Where(r => !r.is_slave);
|
||||
}
|
||||
}
|
||||
@@ -1,8 +1,15 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
|
||||
namespace mbts.ui {
|
||||
public interface ISelectable {
|
||||
event Action<bool> is_selected_changed;
|
||||
bool is_selected { get; set; }
|
||||
}
|
||||
|
||||
static class ISelectableExtensions {
|
||||
public static IEnumerable<T> where_selected<T>(this IEnumerable<T> source) where T : ISelectable =>
|
||||
source.Where(s => s.is_selected);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user