refactor: Clean up VolSurfaceSimplifiedGridVM

This commit is contained in:
John Colvin committed 2022-01-23 16:15:10 -05:00
1 parent cf9591ae83
commit 5bcd00d499
1 file changed
+42 -48
@@ -1,24 +1,26 @@
using mbts;
using mbts.collections;
using mbts.ui;
using mbts.ui.controls;
using mbts.ui.converters;
using mbts.ui.shell;
using mbts.ui.utility;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Windows;
using System.Windows.Data;
using System.Windows.Input;
using System.Windows.Media;
using mbts.analytics;
using System.Diagnostics;
using bts;
using System.Windows.Controls;
namespace mbts.spark.VolSurface {
using bts;
using mbts;
using mbts.analytics;
using mbts.collections;
using mbts.ui;
using mbts.ui.controls;
using mbts.ui.converters;
using mbts.ui.shell;
using mbts.ui.utility;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Windows;
using System.Windows.Data;
using System.Windows.Input;
using System.Windows.Media;
using System.Diagnostics;
using System.Windows.Controls;
namespace mbts.spark.VolSurface {
enum VolSurfaceSimplifiedColumnType {
RowHeader,
ReadOnly,
@@ -40,13 +42,7 @@ namespace mbts.spark.VolSurface {
public VolSurfaceDisplayGridColumn volsurface_column { get; private set; }
IValueConverter _data_context_converter =>
ValueConverter.create<VolSurfaceRowContext, object>(row => {
if (row is null) {
return null;
}
var cell = row.get_cell(volsurface_column);
return cell;
});
ValueConverter.create<VolSurfaceRowContext, object>(row => row?.get_cell(volsurface_column));
public override FrameworkElement view_factory() {
switch (type) {
@@ -136,7 +132,6 @@ namespace mbts.spark.VolSurface {
// Columns
_internal_columns.AddRange(current_grid.get_ordered_columns());
// data_columns contains all columns except the expiration (header) column
var data_columns = new ObservableCollection<DIYGrid.ColumnBase>();
@@ -173,7 +168,6 @@ namespace mbts.spark.VolSurface {
public VolSurfaceDisplayGrid committed_grid { get; private set; }
public VolSurfaceDisplayModel model { get; }
public bool is_dirty => model.is_dirty;
public int frozen_columns => 1;
public ObservableCollection<DIYGrid.ColumnBase> columns { get; } = new();
public ObservableCollection<VolSurfaceRowContext> rows { get; } = new();
@@ -186,14 +180,15 @@ namespace mbts.spark.VolSurface {
visible_rows.where_selected();
public IEnumerable<DIYGridSuperHeader> super_headers =>
// There are no superheaders over frozen columns (currently)
columns
.Skip(frozen_columns)
.Cast<VolSurfaceSimplifiedColumn>()
.GroupBy(col => col.volsurface_column.group)
_internal_columns
.GroupBy(col => col.group)
.Select(group => new DIYGridSuperHeader(group.Count(), group.Key, _short_header(group.Key)))
.ToList();
public ICommand main_settings_command => _parent.main_settings_command;
public ICommand advanced_settings_command => _parent.advanced_settings_command;
public ICommand graph_settings_command => _parent.vol_curve_vm.settings_command;
public ICommand grid_settings_command => _parent.grid_settings_command;
public void update_column_filter(ISet<string> hidden_cols) {
_hidden_columns = hidden_cols;
@@ -342,11 +337,8 @@ namespace mbts.spark.VolSurface {
var grid = model.get_active_grid();
foreach (var exp in target_exps) {
// an inelegant (yet effective and simple) way to apply the column's parse logic to the shift argument
object parsed = column.parse(shift.ToString());
if (parsed is double) {
object data;
if (grid.get_grid_data(exp, column, out data) && data is double)
grid.set_grid_data(exp, column, (double)data + (double)parsed);
if (column.parse(shift.ToString()) is double parsed && grid.get_grid_data(exp, column, out double data)) {
grid.set_grid_data(exp, column, (double)data + (double)parsed);
}
}
model.set_candidate_grid(grid);
@@ -356,16 +348,18 @@ namespace mbts.spark.VolSurface {
current_grid.set_grid_data(row, col, double.NaN);
}
IEnumerable<VolSurfaceDisplayGridTextColumn> _get_columns(VolSurfaceDisplayGridTextColumn col, GridColumnSet set) {
switch (set) {
case GridColumnSet.Column: return new[] { col };
case GridColumnSet.Group: return _internal_columns.OfType<VolSurfaceDisplayGridTextInputColumn>().Where(c => c.group == col.group);
case GridColumnSet.All: return _internal_columns.OfType<VolSurfaceDisplayGridTextInputColumn>();
default: throw new ArgumentException("Received an unexpected [GridColumnSet] '{0}.'".fmt(set), "set");
}
}
IEnumerable<VolSurfaceDisplayGridTextColumn> _get_columns(VolSurfaceDisplayGridTextColumn col, GridColumnSet set) =>
set switch {
GridColumnSet.Column => new[] { col },
GridColumnSet.Group => _internal_columns.OfType<VolSurfaceDisplayGridTextInputColumn>().Where(c => c.group == col.group),
GridColumnSet.All => _internal_columns.OfType<VolSurfaceDisplayGridTextInputColumn>(),
_ => throw new ArgumentException($"Received an unexpected [GridColumnSet] '{set}.'", nameof(set)),
};
void _replicate(VolSurfaceDisplayGridExpiration source, IEnumerable<VolSurfaceDisplayGridExpiration> target_exps, IEnumerable<VolSurfaceDisplayGridTextColumn> cols) {
void _replicate(
VolSurfaceDisplayGridExpiration source,
IEnumerable<VolSurfaceDisplayGridExpiration> target_exps,
IEnumerable<VolSurfaceDisplayGridTextColumn> cols) {
foreach (var col in cols) {
foreach (var exp in target_exps) {
_copy(source, exp, col);