ui: Refine slide settings dialog
* Unify greeks configuration/display settings into one section * Replace tabs with modal expandable sections (like in the analytics shell module view)
This commit is contained in:
1 parent
9b5aea2458
commit
fbfd601270
17 files changed
+1019
-574
No files matched your search
@@ -1,7 +1,9 @@
|
||||
#nullable enable
|
||||
namespace mbts.analytics {
|
||||
using bts.api.analytics;
|
||||
using bts.utils;
|
||||
|
||||
using mbts.ui.shell;
|
||||
using mbts.user.settings;
|
||||
|
||||
using ProtoBuf;
|
||||
@@ -75,31 +77,87 @@ namespace mbts.analytics {
|
||||
Clone();
|
||||
}
|
||||
|
||||
class GreekDisplayVM {
|
||||
public GreekDisplayVM(GreekDisplay greek_display) =>
|
||||
this.greek_display = greek_display;
|
||||
class GreekDisplayVM : ViewModelBase {
|
||||
readonly Property<double> _tick_base;
|
||||
readonly Property<double> _tick_unit;
|
||||
readonly Property<double> _multiplier;
|
||||
readonly Property<bool> _is_visible;
|
||||
readonly Property<VolSurfaceGreeks> _greek;
|
||||
readonly DelegateProperty<GreekDisplay> _result;
|
||||
readonly DeferrableActionWrapper _refresh;
|
||||
|
||||
public readonly GreekDisplay greek_display;
|
||||
public GreekDisplayVM() {
|
||||
_tick_base = backing(nameof(tick_base), 100D);
|
||||
_tick_unit = backing(nameof(tick_base), 1D);
|
||||
_multiplier = backing(nameof(multiplier), double.NaN);
|
||||
_is_visible = backing(nameof(is_visible), false);
|
||||
_greek = backing(nameof(greek), VolSurfaceGreeks.Vol);
|
||||
|
||||
_result = backing(nameof(result), mk_result);
|
||||
_refresh = new(_result.refresh);
|
||||
|
||||
hook_prop(_tick_base);
|
||||
hook_prop(_tick_unit);
|
||||
hook_prop(_multiplier);
|
||||
hook_prop(_is_visible);
|
||||
hook_prop(_greek);
|
||||
|
||||
_result.Changed += (o, n) => result_changed?.Invoke();
|
||||
_is_visible.Changed += (o, n) => is_visible_changed?.Invoke(n);
|
||||
|
||||
void hook_prop<T>(IProperty<T> prop) =>
|
||||
prop.Changed += (o, n) => _refresh.execute();
|
||||
|
||||
GreekDisplay mk_result() => new() {
|
||||
greek = greek,
|
||||
tick_factors = new(tick_base, tick_unit),
|
||||
display_multiplier = multiplier,
|
||||
is_visible = is_visible,
|
||||
};
|
||||
}
|
||||
|
||||
public event Action? result_changed;
|
||||
public event Action<bool>? is_visible_changed;
|
||||
|
||||
public GreekDisplay result {
|
||||
get => _result.Value;
|
||||
set => load_from(value);
|
||||
}
|
||||
|
||||
public VolSurfaceGreeks greek {
|
||||
get => _greek.Value;
|
||||
set => _greek.set(value);
|
||||
}
|
||||
|
||||
public VolSurfaceGreeks greek => greek_display.greek;
|
||||
public double tick_base {
|
||||
get => greek_display.tick_factors.tick_base;
|
||||
set => greek_display.tick_factors = greek_display.tick_factors.with(tick_base: value);
|
||||
}
|
||||
public double tick_unit {
|
||||
get => greek_display.tick_factors.tick_unit;
|
||||
set => greek_display.tick_factors = greek_display.tick_factors.with(tick_unit: value);
|
||||
}
|
||||
public double multiplier {
|
||||
get => greek_display.display_multiplier;
|
||||
set => greek_display.display_multiplier = value;
|
||||
}
|
||||
public bool is_visible {
|
||||
get => greek_display.is_visible;
|
||||
set => greek_display.is_visible = value;
|
||||
get => _tick_base.Value;
|
||||
set => _tick_base.set(value);
|
||||
}
|
||||
|
||||
public override string ToString() => greek_display.greek.ToString();
|
||||
public double tick_unit {
|
||||
get => _tick_unit.Value;
|
||||
set => _tick_unit.set(value);
|
||||
}
|
||||
|
||||
public double multiplier {
|
||||
get => _multiplier.Value;
|
||||
set => _multiplier.set(value);
|
||||
}
|
||||
|
||||
public bool is_visible {
|
||||
get => _is_visible.Value;
|
||||
set => _is_visible.set(value);
|
||||
}
|
||||
|
||||
public void load_from(GreekDisplay greek_display) {
|
||||
using var _ = _refresh.defer_execution(true);
|
||||
tick_base = greek_display.tick_factors.tick_base;
|
||||
tick_unit = greek_display.tick_factors.tick_unit;
|
||||
multiplier = greek_display.display_multiplier;
|
||||
is_visible = greek_display.is_visible;
|
||||
}
|
||||
|
||||
public override string ToString() => result.greek.ToString();
|
||||
}
|
||||
|
||||
class GreekDisplayModel {
|
||||
|
||||
@@ -49,18 +49,7 @@ namespace mbts.analytics {
|
||||
internal_account_selector.selected_item_changed += on_internal_account_changed;
|
||||
|
||||
_dispose = Disposable.Create(
|
||||
_security_criteria.Subscribe(ch => _refresh.execute()),
|
||||
ObservableAutoWrapper.connect_item_hooks(greek_vms, gvm => {
|
||||
_refresh.execute();
|
||||
gvm.is_selected_changed += on_is_selected_changed;
|
||||
return Disposable.Create(() => {
|
||||
_refresh.execute();
|
||||
gvm.is_selected_changed -= on_is_selected_changed;
|
||||
});
|
||||
|
||||
void on_is_selected_changed(bool value) =>
|
||||
_refresh.execute();
|
||||
}));
|
||||
_security_criteria.Subscribe(ch => _refresh.execute()));
|
||||
_refresh.execute();
|
||||
|
||||
void on_vol_surface_changed() {
|
||||
@@ -167,7 +156,6 @@ namespace mbts.analytics {
|
||||
set => _set_and_refresh(ref _handles_in_percentage, value);
|
||||
}
|
||||
|
||||
public ObservableCollection<SelectableItemVM<VolSurfaceGreeks>> greek_vms { get; } = new();
|
||||
public ReportImmutable result {
|
||||
get => _result.Value;
|
||||
set => load_from(value);
|
||||
@@ -196,7 +184,6 @@ namespace mbts.analytics {
|
||||
report.RiskTermsType, report.RiskTermsName, report.RiskTermsVenue);
|
||||
load_securities();
|
||||
load_volsurface();
|
||||
load_greek_vms();
|
||||
_validate();
|
||||
|
||||
void load_securities() {
|
||||
@@ -212,16 +199,6 @@ namespace mbts.analytics {
|
||||
vol_surface_selector.cancel_pending();
|
||||
}
|
||||
}
|
||||
|
||||
void load_greek_vms() {
|
||||
greek_vms.AddRange(report.Greeks
|
||||
.Select(g => new SelectableItemVM<VolSurfaceGreeks>(g, true)));
|
||||
var hidden_greeks = EnumHelper.get_values_except(report.Greeks
|
||||
.Concat(new[] { VolSurfaceGreeks.Vol, VolSurfaceGreeks.Moneyness }));
|
||||
foreach (var g in hidden_greeks) {
|
||||
greek_vms.Add(new SelectableItemVM<VolSurfaceGreeks>(g, false));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void assign_to(Report report) {
|
||||
@@ -240,7 +217,6 @@ namespace mbts.analytics {
|
||||
report.OptionEquivalenceVenue = option_equivalence?.security_exchange ?? Venue.Unset;
|
||||
|
||||
report.SecurityCriteria = security_criteria.to_criteria();
|
||||
report.Greeks.SetItems(greek_vms.Where(g => g.is_selected).Select(g => g.value));
|
||||
report.Handles.SetItems(handles);
|
||||
report.SlideHandlesInPercentage = handles_in_percentage;
|
||||
report.VsId = vol_surface_selector.selected_item?.id ?? -1;
|
||||
@@ -273,15 +249,28 @@ namespace mbts.analytics {
|
||||
void _validate() {
|
||||
using var _ = validation();
|
||||
validation_assert(
|
||||
!(internal_account?.name).is_null_or_empty(), string.Empty, nameof(internal_account));
|
||||
!name.is_null_or_white_space(),
|
||||
"Specify Name",
|
||||
nameof(name));
|
||||
validation_assert(
|
||||
!(internal_account?.name).is_null_or_empty(),
|
||||
"Specify Account",
|
||||
nameof(internal_account));
|
||||
validation_assert(
|
||||
risk_terms is not null && !risk_terms.Equals(mbts.SecurityTuple.empty),
|
||||
"Specify Risk Terms",
|
||||
nameof(risk_terms));
|
||||
validation_assert(
|
||||
!(option_equivalence?.security_name).is_null_or_empty(),
|
||||
string.Empty,
|
||||
"Specify Option Equivalence",
|
||||
nameof(option_equivalence));
|
||||
validation_assert(risk_terms is not null, string.Empty, nameof(risk_terms));
|
||||
validation_assert(
|
||||
selected_vol_surface is not null,
|
||||
"Specify Vol Surface",
|
||||
nameof(selected_vol_surface));
|
||||
validation_assert(
|
||||
!handles.is_null_or_empty() && !handles.Any(double.IsNaN),
|
||||
"Specify handles",
|
||||
"Specify Handles",
|
||||
nameof(handles));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,20 +4,66 @@
|
||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:sp="clr-namespace:mbts.spark"
|
||||
xmlns:u="clr-namespace:mbts.ui"
|
||||
xmlns:c="clr-namespace:mbts.ui.controls"
|
||||
xmlns:cv="clr-namespace:mbts.ui.converters"
|
||||
xmlns:ut="clr-namespace:mbts.ui.utility"
|
||||
Width="350"
|
||||
>
|
||||
xmlns:sys="clr-namespace:System;assembly=mscorlib"
|
||||
Width="350">
|
||||
<UserControl.Resources>
|
||||
<cv:SelectedItemsHeaderTextConverter x:Key="SelectedSecuritiesHeaderTextConverter" />
|
||||
|
||||
<ToolTip x:Key="ParameterToolTip" x:Shared="False">
|
||||
<ItemsControl ItemsSource="{Binding
|
||||
Path='PlacementTarget.Tag.(Validation.Errors)',
|
||||
RelativeSource={RelativeSource AncestorType=ToolTip}}">
|
||||
<ItemsControl.ItemTemplate>
|
||||
<DataTemplate>
|
||||
<TextBlock Text="{Binding ErrorContent}" />
|
||||
</DataTemplate>
|
||||
</ItemsControl.ItemTemplate>
|
||||
</ItemsControl>
|
||||
</ToolTip>
|
||||
|
||||
<sys:Double x:Key="ParameterVPadding">12</sys:Double>
|
||||
<sys:Double x:Key="ParameterHPadding">12</sys:Double>
|
||||
|
||||
<Style x:Key="ParameterLabel" TargetType="TextBlock">
|
||||
<Setter Property="VerticalAlignment" Value="Center" />
|
||||
<Setter Property="Margin">
|
||||
<Setter.Value>
|
||||
<Thickness Top="{StaticResource ParameterVPadding}" />
|
||||
</Setter.Value>
|
||||
</Setter>
|
||||
<Setter Property="ToolTip" Value="{DynamicResource ParameterToolTip}" />
|
||||
<Style.Triggers>
|
||||
<DataTrigger
|
||||
Binding="{Binding Path='Tag.(Validation.HasError)', RelativeSource={RelativeSource Self}}"
|
||||
Value="{u:True}">
|
||||
<Setter Property="Foreground" Value="{x:Static u:BTSColors.error_foreground_brush}" />
|
||||
<Setter Property="FontWeight" Value="Bold" />
|
||||
</DataTrigger>
|
||||
<DataTrigger
|
||||
Binding="{Binding Path='Tag.(Validation.HasError)', RelativeSource={RelativeSource Self}}"
|
||||
Value="{u:False}">
|
||||
<Setter Property="ToolTip" Value="{x:Null}" />
|
||||
</DataTrigger>
|
||||
</Style.Triggers>
|
||||
</Style>
|
||||
|
||||
<Style x:Key="ParameterValue" TargetType="FrameworkElement">
|
||||
<Setter Property="Validation.ErrorTemplate" Value="{x:Null}" />
|
||||
<Setter Property="Margin">
|
||||
<Setter.Value>
|
||||
<Thickness
|
||||
Left="{StaticResource ParameterHPadding}"
|
||||
Top="{StaticResource ParameterVPadding}" />
|
||||
</Setter.Value>
|
||||
</Setter>
|
||||
</Style>
|
||||
</UserControl.Resources>
|
||||
|
||||
<Grid>
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="Auto" />
|
||||
<ColumnDefinition Width="*" />
|
||||
</Grid.ColumnDefinitions>
|
||||
<Grid Grid.IsSharedSizeScope="True">
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition Height="Auto" />
|
||||
<RowDefinition Height="Auto" />
|
||||
@@ -27,125 +73,196 @@
|
||||
<RowDefinition Height="Auto" />
|
||||
<RowDefinition Height="Auto" />
|
||||
<RowDefinition Height="Auto" />
|
||||
<RowDefinition Height="Auto" />
|
||||
</Grid.RowDefinitions>
|
||||
|
||||
<!-- Name -->
|
||||
<TextBlock Grid.Row="0" Grid.Column="0" Margin="8,8,0,0">Name</TextBlock>
|
||||
<TextBox Grid.Row="0" Grid.Column="1" Margin="8,8,8,0" Text="{Binding name}"/>
|
||||
|
||||
<!-- Internal Account -->
|
||||
<TextBlock Grid.Row="1" Grid.Column="0" Margin="8,8,0,0">Internal Account</TextBlock>
|
||||
<ComboBox
|
||||
Grid.Row="1"
|
||||
Grid.Column="1"
|
||||
Margin="8,8,8,0"
|
||||
ItemsSource="{Binding internal_accounts}"
|
||||
SelectedItem="{Binding internal_account}"
|
||||
/>
|
||||
|
||||
<!-- Risk Terms -->
|
||||
<TextBlock Grid.Row="2" Grid.Column="0" Margin="8,8,0,0">In Terms of</TextBlock>
|
||||
<ComboBox
|
||||
Grid.Row="2"
|
||||
Grid.Column="1"
|
||||
Margin="8,8,8,0"
|
||||
ItemsSource="{Binding risk_terms_choices}"
|
||||
SelectedItem="{Binding risk_terms}"
|
||||
ItemTemplate="{StaticResource SecurityTemplate}"
|
||||
/>
|
||||
|
||||
<!-- Option Equivalent -->
|
||||
<TextBlock Grid.Row="3" Grid.Column="0" Margin="8,8,0,0">Option Equivalent</TextBlock>
|
||||
<ComboBox
|
||||
Grid.Row="3"
|
||||
Grid.Column="1"
|
||||
Margin="8,8,8,0"
|
||||
ItemsSource="{Binding option_equivalence_choices}"
|
||||
SelectedItem="{Binding option_equivalence}"
|
||||
/>
|
||||
|
||||
<!-- Vol Surface -->
|
||||
<TextBlock Grid.Row="4" Grid.Column="0" Margin="8,8,0,0">Vol Surface</TextBlock>
|
||||
<ComboBox
|
||||
Grid.Row="4"
|
||||
Grid.Column="1"
|
||||
Margin="8,8,8,0"
|
||||
ItemsSource="{Binding vol_surfaces}"
|
||||
SelectedItem="{Binding selected_vol_surface}"
|
||||
DisplayMemberPath="name"
|
||||
/>
|
||||
|
||||
<!-- Calculation Mode -->
|
||||
<TextBlock Grid.Row="5" Grid.Column="0" Margin="8,8,0,0">Calculation Mode</TextBlock>
|
||||
<ComboBox
|
||||
Grid.Row="5"
|
||||
Grid.Column="1"
|
||||
Margin="8,8,8,0"
|
||||
ItemsSource="{Binding calculation_modes}"
|
||||
SelectedItem="{Binding calculation_mode}"
|
||||
>
|
||||
<ComboBox.ItemTemplate>
|
||||
<DataTemplate>
|
||||
<TextBlock Text="{Binding Converter={StaticResource EnumDescriptionConverter}}" />
|
||||
</DataTemplate>
|
||||
</ComboBox.ItemTemplate>
|
||||
</ComboBox>
|
||||
|
||||
<!-- Securities -->
|
||||
<TextBlock
|
||||
Grid.Row="6"
|
||||
Grid.Column="0"
|
||||
Margin="8,8,0,0"
|
||||
Visibility="{Binding show_security_criteria_param, Converter={x:Static cv:BooleanToVisibilityConverter.Instance}}">
|
||||
Securities
|
||||
</TextBlock>
|
||||
<c:ContractPickerPopup
|
||||
Grid.Row="6"
|
||||
Grid.Column="1"
|
||||
Margin="8,8,8,0"
|
||||
VerticalAlignment="Stretch"
|
||||
CloseOnOK="True"
|
||||
SecurityMap="{Binding security_md_map}"
|
||||
SelectedCriteria="{Binding security_criteria}"
|
||||
Visibility="{Binding show_security_criteria_param, Converter={x:Static cv:BooleanToVisibilityConverter.Instance}}">
|
||||
<c:ContractPickerPopup.Header>
|
||||
<MultiBinding Converter="{x:Static cv:SecurityCriteriaTextConverter.Instance}">
|
||||
<Binding Path="security_criteria" />
|
||||
<Binding
|
||||
Path="DataContext.all_security_mds"
|
||||
RelativeSource="{RelativeSource AncestorType=sp:ContractPickerView}" />
|
||||
</MultiBinding>
|
||||
</c:ContractPickerPopup.Header>
|
||||
</c:ContractPickerPopup>
|
||||
|
||||
<!-- Handles -->
|
||||
<TextBlock Grid.Row="7" Grid.Column="0" Margin="8,8,0,0">Handles</TextBlock>
|
||||
<Grid Grid.Row="7" Grid.Column="1" Margin="8,8,8,0">
|
||||
<Grid Grid.Row="0">
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="Auto" SharedSizeGroup="label" />
|
||||
<ColumnDefinition Width="*" />
|
||||
<ColumnDefinition Width="Auto" />
|
||||
</Grid.ColumnDefinitions>
|
||||
<TextBox Text="{Binding handles, Converter={x:Static cv:EnumerableDoubleStringConverter.Instance}}" />
|
||||
<CheckBox
|
||||
<TextBlock
|
||||
Margin="0"
|
||||
Tag="{Binding ElementName=PART_Name}"
|
||||
Style="{StaticResource ParameterLabel}">
|
||||
Name
|
||||
</TextBlock>
|
||||
<TextBox
|
||||
x:Name="PART_Name"
|
||||
Grid.Column="1"
|
||||
Margin="8,0,0,0"
|
||||
IsChecked="{Binding handles_in_percentage}"
|
||||
Content="%"
|
||||
/>
|
||||
Text="{Binding name}"
|
||||
Style="{StaticResource ParameterValue}">
|
||||
<TextBox.Margin>
|
||||
<Thickness Left="{StaticResource ParameterHPadding}" />
|
||||
</TextBox.Margin>
|
||||
</TextBox>
|
||||
</Grid>
|
||||
|
||||
<!-- Greeks -->
|
||||
<GroupBox Grid.Row="8" Grid.Column="0" Grid.ColumnSpan="2" Margin="8,8,8,0" Header="Greeks" Padding="6">
|
||||
<ScrollViewer MaxHeight="400">
|
||||
<c:DragDropItemsControl ItemsSource="{Binding greek_vms}">
|
||||
<ItemsControl.ItemTemplate>
|
||||
<DataTemplate>
|
||||
<CheckBox Content="{Binding value, Converter={StaticResource EnumDescriptionConverter}}" IsChecked="{Binding is_selected}" />
|
||||
</DataTemplate>
|
||||
</ItemsControl.ItemTemplate>
|
||||
</c:DragDropItemsControl>
|
||||
</ScrollViewer>
|
||||
</GroupBox>
|
||||
<!-- Internal Account -->
|
||||
<Grid Grid.Row="1">
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="Auto" SharedSizeGroup="label" />
|
||||
<ColumnDefinition Width="*" />
|
||||
</Grid.ColumnDefinitions>
|
||||
<TextBlock
|
||||
Tag="{Binding ElementName=PART_InternalAccount}"
|
||||
Style="{StaticResource ParameterLabel}">
|
||||
Internal Account
|
||||
</TextBlock>
|
||||
<ComboBox
|
||||
x:Name="PART_InternalAccount"
|
||||
Grid.Column="1"
|
||||
Validation.ErrorTemplate="{x:Null}"
|
||||
ItemsSource="{Binding internal_accounts}"
|
||||
SelectedItem="{Binding internal_account}"
|
||||
Style="{StaticResource ParameterValue}"/>
|
||||
</Grid>
|
||||
|
||||
<!-- Risk Terms -->
|
||||
<Grid Grid.Row="2">
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="Auto" SharedSizeGroup="label" />
|
||||
<ColumnDefinition Width="*" />
|
||||
</Grid.ColumnDefinitions>
|
||||
<TextBlock
|
||||
Tag="{Binding ElementName=PART_RiskTerms}"
|
||||
Style="{StaticResource ParameterLabel}">
|
||||
In Terms of
|
||||
</TextBlock>
|
||||
<ComboBox
|
||||
x:Name="PART_RiskTerms"
|
||||
Grid.Column="1"
|
||||
ItemsSource="{Binding risk_terms_choices}"
|
||||
SelectedItem="{Binding risk_terms}"
|
||||
ItemTemplate="{StaticResource SecurityTemplate}"
|
||||
Style="{StaticResource ParameterValue}" />
|
||||
</Grid>
|
||||
|
||||
<!-- Option Equivalent -->
|
||||
<Grid Grid.Row="3">
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="Auto" SharedSizeGroup="label" />
|
||||
<ColumnDefinition Width="*" />
|
||||
</Grid.ColumnDefinitions>
|
||||
<TextBlock
|
||||
Tag="{Binding ElementName=PART_OptionEquivalence}"
|
||||
Style="{StaticResource ParameterLabel}">
|
||||
Option Equivalent
|
||||
</TextBlock>
|
||||
<ComboBox
|
||||
x:Name="PART_OptionEquivalence"
|
||||
Grid.Column="1"
|
||||
Validation.ErrorTemplate="{x:Null}"
|
||||
ItemsSource="{Binding option_equivalence_choices}"
|
||||
SelectedItem="{Binding option_equivalence}"
|
||||
Style="{StaticResource ParameterValue}" />
|
||||
</Grid>
|
||||
|
||||
<!-- Vol Surface -->
|
||||
<Grid Grid.Row="4">
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="Auto" SharedSizeGroup="label" />
|
||||
<ColumnDefinition Width="*" />
|
||||
</Grid.ColumnDefinitions>
|
||||
<TextBlock
|
||||
Tag="{Binding ElementName=PART_VolSurface}"
|
||||
Style="{StaticResource ParameterLabel}">
|
||||
Vol Surface
|
||||
</TextBlock>
|
||||
<ComboBox
|
||||
x:Name="PART_VolSurface"
|
||||
Grid.Column="1"
|
||||
Validation.ErrorTemplate="{x:Null}"
|
||||
ItemsSource="{Binding vol_surfaces}"
|
||||
SelectedItem="{Binding selected_vol_surface}"
|
||||
DisplayMemberPath="name"
|
||||
Style="{StaticResource ParameterValue}"/>
|
||||
</Grid>
|
||||
|
||||
<!-- Calculation Mode -->
|
||||
<Grid Grid.Row="5">
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="Auto" SharedSizeGroup="label" />
|
||||
<ColumnDefinition Width="*" />
|
||||
</Grid.ColumnDefinitions>
|
||||
<TextBlock
|
||||
Tag="{Binding ElementName=PART_CalculationMode}"
|
||||
Style="{StaticResource ParameterLabel}">
|
||||
Calculation Mode
|
||||
</TextBlock>
|
||||
<ComboBox
|
||||
x:Name="PART_CalculationMode"
|
||||
Grid.Column="1"
|
||||
ItemsSource="{Binding calculation_modes}"
|
||||
SelectedItem="{Binding calculation_mode}"
|
||||
Style="{StaticResource ParameterValue}">
|
||||
<ComboBox.ItemTemplate>
|
||||
<DataTemplate>
|
||||
<TextBlock Text="{Binding Converter={StaticResource EnumDescriptionConverter}}" />
|
||||
</DataTemplate>
|
||||
</ComboBox.ItemTemplate>
|
||||
</ComboBox>
|
||||
</Grid>
|
||||
|
||||
<!-- Securities -->
|
||||
<Grid Grid.Row="6">
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="Auto" SharedSizeGroup="label" />
|
||||
<ColumnDefinition Width="*" />
|
||||
</Grid.ColumnDefinitions>
|
||||
<TextBlock
|
||||
Visibility="{Binding show_security_criteria_param, Converter={x:Static cv:BooleanToVisibilityConverter.Instance}}"
|
||||
Tag="{Binding ElementName=PART_SecurityCriteria}"
|
||||
Style="{StaticResource ParameterLabel}">
|
||||
Securities
|
||||
</TextBlock>
|
||||
<c:ContractPickerPopup
|
||||
x:Name="PART_SecurityCriteria"
|
||||
Grid.Column="1"
|
||||
VerticalAlignment="Stretch"
|
||||
CloseOnOK="True"
|
||||
SecurityMap="{Binding security_md_map}"
|
||||
SelectedCriteria="{Binding security_criteria}"
|
||||
Visibility="{Binding show_security_criteria_param, Converter={x:Static cv:BooleanToVisibilityConverter.Instance}}"
|
||||
Style="{StaticResource ParameterValue}">
|
||||
<c:ContractPickerPopup.Header>
|
||||
<MultiBinding Converter="{x:Static cv:SecurityCriteriaTextConverter.Instance}">
|
||||
<Binding Path="security_criteria" />
|
||||
<Binding
|
||||
Path="DataContext.all_security_mds"
|
||||
RelativeSource="{RelativeSource AncestorType=sp:ContractPickerView}" />
|
||||
</MultiBinding>
|
||||
</c:ContractPickerPopup.Header>
|
||||
</c:ContractPickerPopup>
|
||||
</Grid>
|
||||
|
||||
<!-- Handles -->
|
||||
<Grid Grid.Row="7">
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="Auto" SharedSizeGroup="label" />
|
||||
<ColumnDefinition Width="*" />
|
||||
</Grid.ColumnDefinitions>
|
||||
<TextBlock
|
||||
Tag="{Binding ElementName=PART_Handles}"
|
||||
Style="{StaticResource ParameterLabel}">
|
||||
Handles
|
||||
</TextBlock>
|
||||
<Grid Grid.Column="1" Style="{StaticResource ParameterValue}">
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="*" />
|
||||
<ColumnDefinition Width="Auto" />
|
||||
</Grid.ColumnDefinitions>
|
||||
<TextBox
|
||||
x:Name="PART_Handles"
|
||||
Validation.ErrorTemplate="{x:Null}"
|
||||
Text="{Binding handles, Converter={x:Static cv:EnumerableDoubleStringConverter.Instance}}" />
|
||||
<CheckBox
|
||||
Grid.Column="1"
|
||||
Margin="8,0,0,0"
|
||||
IsChecked="{Binding handles_in_percentage}"
|
||||
Content="%"
|
||||
/>
|
||||
</Grid>
|
||||
</Grid>
|
||||
</Grid>
|
||||
</UserControl>
|
||||
@@ -3,34 +3,23 @@
|
||||
x:ClassModifier="internal"
|
||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:u="clr-namespace:mbts.ui"
|
||||
xmlns:c="clr-namespace:mbts.ui.controls"
|
||||
xmlns:analytics="clr-namespace:mbts.analytics"
|
||||
SizeToContent="WidthAndHeight"
|
||||
Title="New Slide Report"
|
||||
Style="{StaticResource BTSDialog}"
|
||||
>
|
||||
<Window.Resources>
|
||||
<ResourceDictionary>
|
||||
<ResourceDictionary.MergedDictionaries>
|
||||
<ResourceDictionary Source="/view/Resources/CursorsEx.xaml"/>
|
||||
<ResourceDictionary Source="/view/Resources/DataTemplates.xaml"/>
|
||||
</ResourceDictionary.MergedDictionaries>
|
||||
</ResourceDictionary>
|
||||
</Window.Resources>
|
||||
|
||||
<AdornerDecorator>
|
||||
<Grid>
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition Height="*" />
|
||||
<RowDefinition Height="Auto" />
|
||||
</Grid.RowDefinitions>
|
||||
<analytics:SlideReportConfigurationView Margin="4" DataContext="{Binding configuration_vm}" />
|
||||
<c:DialogSkirtOKCancel
|
||||
Grid.Row="1"
|
||||
Margin="0,10,0,0"
|
||||
OKCommand="{Binding ok_cmd}"
|
||||
OKCommandParameter="{Binding result}"
|
||||
/>
|
||||
</Grid>
|
||||
</AdornerDecorator>
|
||||
Icon="{x:Static u:Icons.Reports}"
|
||||
Style="{StaticResource BTSDialog}">
|
||||
<Grid>
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition Height="*" />
|
||||
<RowDefinition Height="Auto" />
|
||||
</Grid.RowDefinitions>
|
||||
<analytics:SlideReportSettingsView />
|
||||
<c:DialogSkirtOKCancel
|
||||
Grid.Row="1"
|
||||
OKCommand="{Binding ok_cmd}"
|
||||
OKCommandParameter="{Binding result}"
|
||||
CloseOnOK="False" />
|
||||
</Grid>
|
||||
</Window>
|
||||
@@ -1,5 +1,6 @@
|
||||
#nullable enable
|
||||
namespace mbts.analytics {
|
||||
using bts.api.analytics;
|
||||
using bts.collections;
|
||||
using bts.utils;
|
||||
|
||||
@@ -24,27 +25,33 @@ namespace mbts.analytics {
|
||||
GreekDisplayVM? _top_selected_greek;
|
||||
|
||||
public SlideReportGridSettingsVM() {
|
||||
tick_display_settings = new(new() {
|
||||
NanText = string.Empty,
|
||||
DisplayMultiplier = double.NaN
|
||||
});
|
||||
_result = backing(nameof(result), mk_result);
|
||||
_refresh = new(
|
||||
((int)RefreshFlags.Result, _result.refresh),
|
||||
((int)RefreshFlags.Validation, _validate));
|
||||
greek_views.AddRange(EnumHelper.get_values<VolSurfaceGreeks>().Select(
|
||||
g => new SelectableItemVM<GreekDisplayVM>(new() { greek = g })));
|
||||
|
||||
_dispose = Disposable.Create(
|
||||
ObservableAutoWrapper.connect_item_hooks(
|
||||
greek_views, gv => {
|
||||
_refresh.execute();
|
||||
gv.is_selected_changed += on_is_selected_changed;
|
||||
gv.value.result_changed += on_result_changed;
|
||||
return Disposable.Create(() => {
|
||||
_refresh.execute();
|
||||
gv.is_selected_changed -= on_is_selected_changed;
|
||||
gv.value.result_changed -= on_result_changed;
|
||||
});
|
||||
void on_is_selected_changed(bool value) =>
|
||||
void on_result_changed() =>
|
||||
_refresh.execute();
|
||||
}));
|
||||
|
||||
(GreekDisplay[], PriceDisplayFactors) mk_result() =>
|
||||
(ProtobufSerializationHelper.clone(
|
||||
greek_views.Select(gv => gv.value.greek_display).ToArray()),
|
||||
greek_views.Select(gv => gv.value.result).ToArray()),
|
||||
ProtobufSerializationHelper.clone(_price_display));
|
||||
}
|
||||
|
||||
@@ -91,41 +98,46 @@ namespace mbts.analytics {
|
||||
}
|
||||
}
|
||||
|
||||
public double tick_base {
|
||||
get => top_selected_greek?.tick_base ?? double.NaN;
|
||||
public double? tick_base {
|
||||
get => top_selected_greek?.tick_base;
|
||||
set {
|
||||
var newval = value ?? double.NaN;
|
||||
foreach (var gv in greek_views.Where(g => g.is_selected)) {
|
||||
gv.value.tick_base = value;
|
||||
gv.value.tick_base = newval;
|
||||
}
|
||||
_refresh.execute();
|
||||
}
|
||||
}
|
||||
|
||||
public double tick_unit {
|
||||
get => top_selected_greek?.tick_unit ?? double.NaN;
|
||||
public double? tick_unit {
|
||||
get => top_selected_greek?.tick_unit;
|
||||
set {
|
||||
var newval = value ?? double.NaN;
|
||||
foreach (var gv in greek_views.Where(g => g.is_selected)) {
|
||||
gv.value.tick_unit = value;
|
||||
gv.value.tick_unit = newval;
|
||||
}
|
||||
_refresh.execute();
|
||||
}
|
||||
}
|
||||
|
||||
public double multiplier {
|
||||
get => top_selected_greek?.multiplier ?? double.NaN;
|
||||
public double? multiplier {
|
||||
get => top_selected_greek?.multiplier;
|
||||
set {
|
||||
var newval = value ?? double.NaN;
|
||||
foreach (var gv in greek_views.Where(g => g.is_selected)) {
|
||||
gv.value.multiplier = value;
|
||||
gv.value.multiplier = newval;
|
||||
}
|
||||
_refresh.execute();
|
||||
}
|
||||
}
|
||||
|
||||
public bts.api.domain.TickDisplaySettingsImmutable tick_display_settings { get; }
|
||||
|
||||
public bool show_commas {
|
||||
get => top_selected_greek?.greek_display?.show_commas ?? false;
|
||||
get => top_selected_greek?.result?.show_commas ?? false;
|
||||
set {
|
||||
foreach (var gv in greek_views.Where(g => g.is_selected)) {
|
||||
gv.value.greek_display.show_commas = value;
|
||||
gv.value.result.show_commas = value;
|
||||
}
|
||||
_refresh.execute();
|
||||
}
|
||||
@@ -139,15 +151,42 @@ namespace mbts.analytics {
|
||||
public void assign_to(SlideReportSettings settings) {
|
||||
settings.price = ProtobufSerializationHelper.clone(_price_display);
|
||||
settings.greeks = ProtobufSerializationHelper.clone(
|
||||
greek_views.Select(gv => gv.value.greek_display).ToArray());
|
||||
greek_views.Select(gv => gv.value.result).ToArray());
|
||||
}
|
||||
|
||||
public void assign_to(Report report) {
|
||||
report.Greeks.SetItems(
|
||||
greek_views.Where(gv => gv.value.is_visible).Select(gv => gv.value.greek));
|
||||
}
|
||||
|
||||
public void load_from(SlideReportSettings settings) {
|
||||
using var _ = Disposable.Create(
|
||||
detect_property_changes_except(nameof(result)), _refresh.defer_execution());
|
||||
_price_display = settings.price?.Clone() ?? PriceDisplayFactors.Default;
|
||||
greek_views.SetItems(settings.greeks.empty_if_null()
|
||||
.Select(g => new SelectableItemVM<GreekDisplayVM>(new(g), g.is_visible)));
|
||||
foreach (var (gd, i) in settings.greeks.empty_if_null().ZipIndex()) {
|
||||
if (greek_views.TryGetFirst(
|
||||
gv => gv.value.greek == gd.greek, out var gv, out var old_i)) {
|
||||
if (gv is null) {
|
||||
throw new InvalidOperationException();
|
||||
}
|
||||
gv.value.result = gd;
|
||||
greek_views.Move(old_i, i);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void load_from(ReportImmutable report) {
|
||||
var vis_greeks = report.Greeks.ToHashSet();
|
||||
foreach (var gv in greek_views) {
|
||||
gv.value.is_visible = vis_greeks.Contains(gv.value.greek);
|
||||
}
|
||||
}
|
||||
|
||||
public void load_greek_vms(ReportImmutable report) {
|
||||
var vis_greeks = report.Greeks.ToHashSet();
|
||||
foreach (var gv in greek_views) {
|
||||
gv.value.is_visible = vis_greeks.Contains(gv.value.greek);
|
||||
}
|
||||
}
|
||||
|
||||
void _validate() {
|
||||
|
||||
@@ -4,8 +4,7 @@
|
||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:c="clr-namespace:mbts.ui.controls"
|
||||
Width="350"
|
||||
>
|
||||
Width="350">
|
||||
<UserControl.Resources>
|
||||
<ResourceDictionary>
|
||||
<ResourceDictionary.MergedDictionaries>
|
||||
@@ -16,102 +15,96 @@
|
||||
</UserControl.Resources>
|
||||
|
||||
<Grid>
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition Height="Auto"/>
|
||||
<RowDefinition Height="2*"/>
|
||||
<RowDefinition Height="1*"/>
|
||||
</Grid.RowDefinitions>
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="Auto" />
|
||||
<ColumnDefinition Width="*" />
|
||||
</Grid.ColumnDefinitions>
|
||||
|
||||
<TextBlock
|
||||
Text="Hint: To add more greeks to this list, Select 'Configuration' from the grid's Right Click Menu"
|
||||
Foreground="Gray"
|
||||
FontStyle="Italic"
|
||||
TextWrapping="Wrap"
|
||||
HorizontalAlignment="Stretch"
|
||||
Margin="20,12,20,12"
|
||||
/>
|
||||
<c:DragDropListBox
|
||||
MinWidth="186"
|
||||
MaxHeight="200"
|
||||
ItemsSource="{Binding greek_views}"
|
||||
SelectionMode="Extended"
|
||||
SelectedValuePath="value"
|
||||
SelectedValue="{Binding top_selected_greek}">
|
||||
<ListBox.ItemContainerStyle>
|
||||
<Style
|
||||
TargetType="c:DraggableListBoxItem"
|
||||
BasedOn="{StaticResource {x:Type c:DraggableListBoxItem}}">
|
||||
<Setter Property="IsSelected" Value="{Binding is_selected}" />
|
||||
<Setter Property="HorizontalContentAlignment" Value="Stretch" />
|
||||
</Style>
|
||||
</ListBox.ItemContainerStyle>
|
||||
<ListBox.ItemTemplate>
|
||||
<DataTemplate>
|
||||
<Grid>
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="Auto" />
|
||||
<ColumnDefinition Width="*" />
|
||||
</Grid.ColumnDefinitions>
|
||||
<TextBlock
|
||||
Text="{Binding value.greek, Converter={StaticResource EnumDescriptionConverter}}" />
|
||||
<CheckBox
|
||||
Grid.Column="1"
|
||||
HorizontalAlignment="Right"
|
||||
Margin="16,0,4,0"
|
||||
IsChecked="{Binding value.is_visible}"
|
||||
ToolTip="Show" />
|
||||
</Grid>
|
||||
</DataTemplate>
|
||||
</ListBox.ItemTemplate>
|
||||
</c:DragDropListBox>
|
||||
|
||||
<GroupBox Grid.Row="1" Header="Greeks" Margin="20,0,20,0" Padding="8" HeaderTemplate="{StaticResource BoldHeaderTemplate}">
|
||||
<Grid>
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="Auto" />
|
||||
<ColumnDefinition Width="*" />
|
||||
</Grid.ColumnDefinitions>
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition Height="Auto" />
|
||||
<RowDefinition Height="*" />
|
||||
</Grid.RowDefinitions>
|
||||
<TextBlock Text="Order/Visibility" HorizontalAlignment="Center" FontWeight="SemiBold" FontStyle="Italic" />
|
||||
<c:DragDropListBox
|
||||
Grid.Row="1"
|
||||
Margin="0,4,10,0"
|
||||
MaxHeight="400"
|
||||
ItemsSource="{Binding greek_views}"
|
||||
SelectionMode="Extended"
|
||||
SelectedValuePath="value"
|
||||
SelectedValue="{Binding top_selected_greek}"
|
||||
>
|
||||
<ListBox.ItemContainerStyle>
|
||||
<Style TargetType="c:DraggableListBoxItem" BasedOn="{StaticResource {x:Type c:DraggableListBoxItem}}">
|
||||
<Setter Property="IsSelected" Value="{Binding is_selected}" />
|
||||
<Setter Property="HorizontalContentAlignment" Value="Stretch" />
|
||||
</Style>
|
||||
</ListBox.ItemContainerStyle>
|
||||
<ListBox.ItemTemplate>
|
||||
<DataTemplate>
|
||||
<Grid>
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="Auto" />
|
||||
<ColumnDefinition Width="*" />
|
||||
</Grid.ColumnDefinitions>
|
||||
<TextBlock Text="{Binding value.greek, Converter={StaticResource EnumDescriptionConverter}}" />
|
||||
<CheckBox Grid.Column="1" HorizontalAlignment="Right" Margin="16,0,4,0" IsChecked="{Binding value.is_visible}" />
|
||||
</Grid>
|
||||
</DataTemplate>
|
||||
</ListBox.ItemTemplate>
|
||||
</c:DragDropListBox>
|
||||
<Grid Grid.Row="1" Grid.Column="1" Margin="0,4,0,0">
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition Height="Auto" />
|
||||
<RowDefinition Height="Auto" />
|
||||
<RowDefinition Height="Auto" />
|
||||
<RowDefinition Height="Auto" />
|
||||
</Grid.RowDefinitions>
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="Auto" />
|
||||
<ColumnDefinition Width="*" />
|
||||
</Grid.ColumnDefinitions>
|
||||
<TextBlock Text="Tick Unit" VerticalAlignment="Center" />
|
||||
<c:TickUpDownDouble Grid.Column="1" Margin="8,0,0,0" HorizontalAlignment="Stretch" Value="{Binding tick_unit}" />
|
||||
<TextBlock Grid.Row="1" Text="Tick Base" Margin="0,5,0,0" VerticalAlignment="Center"/>
|
||||
<c:TickUpDownDouble Grid.Row="1" Grid.Column="1" Margin="8,5,0,0" HorizontalAlignment="Stretch" Value="{Binding tick_base}" />
|
||||
<TextBlock Grid.Row="2" Text="Multiplier" Margin="0,5,0,0" VerticalAlignment="Center"/>
|
||||
<c:TickUpDownDouble Grid.Row="2" Grid.Column="1" Margin="8,5,0,0" Value="{Binding multiplier}" />
|
||||
<CheckBox Grid.Row="3" Grid.ColumnSpan="2" Margin="0,5,0,0" IsChecked="{Binding show_commas}">Show Commas</CheckBox>
|
||||
</Grid>
|
||||
</Grid>
|
||||
</GroupBox>
|
||||
<Grid
|
||||
Grid.Column="1"
|
||||
Margin="10,0,0,0"
|
||||
IsEnabled="{Binding top_selected_greek, Converter={StaticResource NotNullConverter}}"
|
||||
ToolTip="Select Greeks (left) to modify their display settings"
|
||||
ToolTipService.ShowOnDisabled="True">
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition Height="Auto" />
|
||||
<RowDefinition Height="Auto" />
|
||||
<RowDefinition Height="Auto" />
|
||||
<RowDefinition Height="Auto" />
|
||||
</Grid.RowDefinitions>
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="Auto" />
|
||||
<ColumnDefinition Width="*" />
|
||||
</Grid.ColumnDefinitions>
|
||||
|
||||
<TextBlock Text="Tick Unit" VerticalAlignment="Center" />
|
||||
<c:TickUpDownNullableDouble
|
||||
Grid.Column="1"
|
||||
HorizontalAlignment="Stretch"
|
||||
Margin="8,0,0,0"
|
||||
Minimum="0"
|
||||
TickDisplaySettings="{Binding tick_display_settings}"
|
||||
Value="{Binding tick_unit}" />
|
||||
|
||||
<TextBlock Grid.Row="1" Text="Tick Base" Margin="0,5,0,0" VerticalAlignment="Center"/>
|
||||
<c:TickUpDownNullableDouble
|
||||
Grid.Row="1"
|
||||
Grid.Column="1"
|
||||
HorizontalAlignment="Stretch"
|
||||
Margin="8,5,0,0"
|
||||
Minimum="0"
|
||||
TickDisplaySettings="{Binding tick_display_settings}"
|
||||
Value="{Binding tick_base}" />
|
||||
|
||||
<TextBlock Grid.Row="2" Text="Multiplier" Margin="0,5,0,0" VerticalAlignment="Center"/>
|
||||
<c:TickUpDownNullableDouble
|
||||
Grid.Row="2"
|
||||
Grid.Column="1"
|
||||
Margin="8,5,0,0"
|
||||
Minimum="0"
|
||||
TickDisplaySettings="{Binding tick_display_settings}"
|
||||
Value="{Binding multiplier}" />
|
||||
|
||||
<CheckBox
|
||||
Grid.Row="3" Grid.ColumnSpan="2" Margin="0,5,0,0" IsChecked="{Binding show_commas}">
|
||||
Show Commas
|
||||
</CheckBox>
|
||||
</Grid>
|
||||
</Grid>
|
||||
|
||||
<GroupBox Grid.Row="2" Header="Price" Margin="20,8,20,0" Padding="8" HeaderTemplate="{StaticResource BoldHeaderTemplate}">
|
||||
<Grid>
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition Height="Auto"/>
|
||||
<RowDefinition Height="Auto"/>
|
||||
<RowDefinition Height="Auto"/>
|
||||
</Grid.RowDefinitions>
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="Auto"/>
|
||||
<ColumnDefinition Width="*"/>
|
||||
</Grid.ColumnDefinitions>
|
||||
<StackPanel Grid.ColumnSpan="2" Orientation="Horizontal">
|
||||
<CheckBox x:Name="show_price_checkbox" Margin="4,0,0,0" IsChecked="{Binding show_price}">Show for each Exp/Symbol group</CheckBox>
|
||||
<c:HelpButton ToolTip="If unchecked, Price will only be displayed in the "All" section." />
|
||||
</StackPanel>
|
||||
<TextBlock Grid.Row="1" Margin="0,5,0,0" Text="Tick Unit" VerticalAlignment="Center" />
|
||||
<c:TickUpDownDouble Grid.Row="1" Grid.Column="1" Margin="8,5,0,0" HorizontalAlignment="Stretch" Value="{Binding price_tick_unit}" />
|
||||
<TextBlock Grid.Row="2" Text="Tick Base" Margin="0,5,0,0" VerticalAlignment="Center" />
|
||||
<c:TickUpDownDouble Grid.Row="2" Grid.Column="1" Margin="8,5,0,0" HorizontalAlignment="Stretch" Value="{Binding price_tick_base}" />
|
||||
</Grid>
|
||||
</GroupBox>
|
||||
</Grid>
|
||||
</UserControl>
|
||||
@@ -3,44 +3,25 @@
|
||||
x:ClassModifier="internal"
|
||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:u="clr-namespace:mbts.ui"
|
||||
xmlns:c="clr-namespace:mbts.ui.controls"
|
||||
xmlns:analytics="clr-namespace:mbts.analytics"
|
||||
SizeToContent="WidthAndHeight"
|
||||
Title="Slide Report Settings"
|
||||
Style="{StaticResource BTSDialog}"
|
||||
>
|
||||
<Window.Resources>
|
||||
<ResourceDictionary>
|
||||
<ResourceDictionary.MergedDictionaries>
|
||||
<ResourceDictionary Source="/view/Resources/CursorsEx.xaml"/>
|
||||
<ResourceDictionary Source="/view/Resources/DataTemplates.xaml"/>
|
||||
</ResourceDictionary.MergedDictionaries>
|
||||
</ResourceDictionary>
|
||||
</Window.Resources>
|
||||
|
||||
<AdornerDecorator>
|
||||
<Grid>
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition Height="*" />
|
||||
<RowDefinition Height="Auto" />
|
||||
</Grid.RowDefinitions>
|
||||
<TabControl>
|
||||
<TabItem Header="Grid Settings">
|
||||
<analytics:SlideReportGridSettingsView Margin="4" DataContext="{Binding grid_vm}" />
|
||||
</TabItem>
|
||||
<TabItem Header="Report Configuration">
|
||||
<analytics:SlideReportConfigurationView Margin="4" DataContext="{Binding configuration_vm}" />
|
||||
</TabItem>
|
||||
</TabControl>
|
||||
<c:DialogSkirtOKApplyCancel
|
||||
Grid.Row="1"
|
||||
Margin="0,10,0,0"
|
||||
OKCommand="{Binding ok_cmd}"
|
||||
OKCommandParameter="{Binding result}"
|
||||
ApplyCommand="{Binding apply_cmd}"
|
||||
ApplyCommandParameter="{Binding result}"
|
||||
CloseOnOK="False"
|
||||
/>
|
||||
</Grid>
|
||||
</AdornerDecorator>
|
||||
Icon="{x:Static u:Icons.Reports}"
|
||||
Style="{StaticResource BTSDialog}">
|
||||
<Grid>
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition Height="*" />
|
||||
<RowDefinition Height="Auto" />
|
||||
</Grid.RowDefinitions>
|
||||
<analytics:SlideReportSettingsView />
|
||||
<c:DialogSkirtOKApplyCancel
|
||||
Grid.Row="1"
|
||||
OKCommand="{Binding ok_cmd}"
|
||||
OKCommandParameter="{Binding result}"
|
||||
ApplyCommand="{Binding apply_cmd}"
|
||||
ApplyCommandParameter="{Binding result}"
|
||||
CloseOnOK="False" />
|
||||
</Grid>
|
||||
</Window>
|
||||
@@ -14,6 +14,7 @@ namespace mbts.analytics {
|
||||
|
||||
class SlideReportSettingsVM : DisposableViewModelBase {
|
||||
readonly DelegateProperty<(GreekDisplay[], PriceDisplayFactors, ReportImmutable)> _result;
|
||||
string _selected_section;
|
||||
|
||||
public SlideReportSettingsVM(
|
||||
SlideReportSettings settings,
|
||||
@@ -22,6 +23,7 @@ namespace mbts.analytics {
|
||||
IObservable<IReadOnlyDictionary<uint, AccountTuple>> accounts_src,
|
||||
IObservable<IReadOnlyDictionary<uint, SecurityMD>> security_md_src) {
|
||||
grid_vm.load_from(settings);
|
||||
grid_vm.load_from(report);
|
||||
grid_vm.ErrorsChanged += on_errors_changed;
|
||||
|
||||
configuration_vm.load_from(report);
|
||||
@@ -29,7 +31,9 @@ namespace mbts.analytics {
|
||||
|
||||
_result = backing(nameof(result), () => {
|
||||
var (greeks, price_display) = grid_vm.result;
|
||||
return (greeks, price_display, configuration_vm.result);
|
||||
var cfg = configuration_vm.result.CloneToMutable();
|
||||
grid_vm.assign_to(cfg);
|
||||
return (greeks, price_display, new ReportImmutable(cfg));
|
||||
});
|
||||
apply_cmd = new(_ => can_commit());
|
||||
ok_cmd = new(_ => can_commit());
|
||||
@@ -45,7 +49,7 @@ namespace mbts.analytics {
|
||||
grid_vm.observe_result().Subscribe(_ => _result.refresh()),
|
||||
configuration_vm.observe_result().Subscribe(_ => _result.refresh()));
|
||||
|
||||
bool can_commit() => !grid_vm.HasErrors && !configuration_vm.HasErrors ;
|
||||
bool can_commit() => !grid_vm.HasErrors && !configuration_vm.HasErrors;
|
||||
|
||||
void on_errors_changed(object sender, DataErrorsChangedEventArgs e) {
|
||||
apply_cmd.RaiseCanExecuteChanged();
|
||||
@@ -57,6 +61,11 @@ namespace mbts.analytics {
|
||||
public SlideReportConfigurationVM configuration_vm { get; } = new();
|
||||
public (GreekDisplay[], PriceDisplayFactors, ReportImmutable) result => _result.Value;
|
||||
|
||||
public string selected_section {
|
||||
get => _selected_section;
|
||||
set => Set(ref _selected_section, value);
|
||||
}
|
||||
|
||||
public EventCommand<(GreekDisplay[], PriceDisplayFactors, ReportImmutable)> apply_cmd { get; }
|
||||
public EventCommand<(GreekDisplay[], PriceDisplayFactors, ReportImmutable)> ok_cmd { get; }
|
||||
}
|
||||
|
||||
@@ -0,0 +1,150 @@
|
||||
<UserControl
|
||||
x:Class="mbts.analytics.SlideReportSettingsView"
|
||||
x:ClassModifier="internal"
|
||||
x:Name="me"
|
||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:analytics="clr-namespace:mbts.analytics"
|
||||
xmlns:u="clr-namespace:mbts.ui"
|
||||
xmlns:c="clr-namespace:mbts.ui.controls"
|
||||
>
|
||||
<UserControl.Resources>
|
||||
<ResourceDictionary>
|
||||
<ResourceDictionary.MergedDictionaries>
|
||||
<ResourceDictionary Source="/view/Resources/CursorsEx.xaml"/>
|
||||
<ResourceDictionary Source="/view/Resources/DataTemplates.xaml"/>
|
||||
</ResourceDictionary.MergedDictionaries>
|
||||
|
||||
<c:RadioButtonGroupManagerMap
|
||||
x:Key="SectionContentRadioButtonMap"
|
||||
SelectedItem="{Binding
|
||||
DataContext.selected_section,
|
||||
Source={u:DirectReference me},
|
||||
Mode=TwoWay}" />
|
||||
|
||||
<Style
|
||||
x:Key="SectionContentToggle"
|
||||
TargetType="ToggleButton"
|
||||
BasedOn="{StaticResource LargeMenuToggleButton}">
|
||||
<Setter
|
||||
Property="c:RadioButtonGroupManagerMap.GroupManagerMap"
|
||||
Value="{StaticResource SectionContentRadioButtonMap}" />
|
||||
<Setter Property="Padding" Value="12,10" />
|
||||
<Setter Property="Foreground" Value="Black" />
|
||||
<Setter Property="FontWeight" Value="Normal" />
|
||||
<Setter
|
||||
Property="IsChecked"
|
||||
Value="{Binding
|
||||
Path='(analytics:SlideReportSettingsView.SectionContentView).(u:ExpandCollapseAnimator.IsExpanded)',
|
||||
RelativeSource={RelativeSource Self},
|
||||
Mode=TwoWay}" />
|
||||
<Setter Property="ToolTip" Value="{x:Null}" />
|
||||
|
||||
<!-- Comment out GroupKey setter to only allow 1 expanded section at a time -->
|
||||
<Setter
|
||||
Property="c:RadioButtonGroupManagerMap.GroupKey"
|
||||
Value="{Binding Content, RelativeSource={RelativeSource Self}}" />
|
||||
<Setter Property="ContentTemplate">
|
||||
<Setter.Value>
|
||||
<DataTemplate>
|
||||
<TextBlock FontSize="13" Text="{Binding}" />
|
||||
</DataTemplate>
|
||||
</Setter.Value>
|
||||
</Setter>
|
||||
<Style.Triggers>
|
||||
<DataTrigger
|
||||
Binding="{Binding
|
||||
Path='(analytics:SlideReportSettingsView.SectionContentView).DataContext.HasErrors',
|
||||
RelativeSource={RelativeSource Self}}"
|
||||
Value="{u:True}">
|
||||
<Setter Property="Foreground" Value="{x:Static u:BTSColors.error_foreground_brush}" />
|
||||
<Setter Property="FontWeight" Value="Bold" />
|
||||
<Setter Property="ToolTip">
|
||||
<Setter.Value>
|
||||
<TextBlock>Invalid Parameters</TextBlock>
|
||||
</Setter.Value>
|
||||
</Setter>
|
||||
</DataTrigger>
|
||||
</Style.Triggers>
|
||||
</Style>
|
||||
|
||||
<Style x:Key="SectionContentHost" TargetType="ContentControl">
|
||||
<Setter Property="Height" Value="0" />
|
||||
<Setter Property="Padding" Value="16,8" />
|
||||
<Setter Property="Template">
|
||||
<Setter.Value>
|
||||
<ControlTemplate TargetType="ContentControl">
|
||||
<ContentPresenter Margin="{TemplateBinding Padding}" />
|
||||
</ControlTemplate>
|
||||
</Setter.Value>
|
||||
</Setter>
|
||||
</Style>
|
||||
</ResourceDictionary>
|
||||
</UserControl.Resources>
|
||||
|
||||
<StackPanel>
|
||||
<ToggleButton
|
||||
c:RadioButtonGroupManager.Value="report_configuration"
|
||||
analytics:SlideReportSettingsView.SectionContentView="{Binding ElementName=ConfigurationView}"
|
||||
Content="Configuration"
|
||||
Style="{StaticResource SectionContentToggle}">
|
||||
</ToggleButton>
|
||||
|
||||
<ContentControl Style="{StaticResource SectionContentHost}">
|
||||
<analytics:SlideReportConfigurationView
|
||||
x:Name="ConfigurationView" DataContext="{Binding configuration_vm}" />
|
||||
</ContentControl>
|
||||
|
||||
<ToggleButton
|
||||
c:RadioButtonGroupManager.Value="report_configuration"
|
||||
analytics:SlideReportSettingsView.SectionContentView="{Binding ElementName=GreeksView}"
|
||||
Content="Greeks"
|
||||
Style="{StaticResource SectionContentToggle}"
|
||||
/>
|
||||
|
||||
<ContentControl Style="{StaticResource SectionContentHost}">
|
||||
<analytics:SlideReportGridSettingsView x:Name="GreeksView" DataContext="{Binding grid_vm}" />
|
||||
</ContentControl>
|
||||
|
||||
<ToggleButton
|
||||
c:RadioButtonGroupManager.Value="report_configuration"
|
||||
analytics:SlideReportSettingsView.SectionContentView="{Binding ElementName=PriceView}"
|
||||
Content="Price"
|
||||
Style="{StaticResource SectionContentToggle}" />
|
||||
|
||||
<ContentControl Style="{StaticResource SectionContentHost}">
|
||||
<Grid x:Name="PriceView" DataContext="{Binding grid_vm}">
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition Height="Auto"/>
|
||||
<RowDefinition Height="Auto"/>
|
||||
<RowDefinition Height="Auto"/>
|
||||
</Grid.RowDefinitions>
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="Auto"/>
|
||||
<ColumnDefinition Width="*"/>
|
||||
</Grid.ColumnDefinitions>
|
||||
|
||||
<StackPanel Grid.ColumnSpan="2" Orientation="Horizontal">
|
||||
<CheckBox IsChecked="{Binding show_price}">Show for each Exp/Symbol group</CheckBox>
|
||||
<c:HelpButton ToolTip="If unchecked, Price will only be displayed in the "All" section." />
|
||||
</StackPanel>
|
||||
|
||||
<TextBlock Grid.Row="1" Margin="0,5,0,0" Text="Tick Unit" VerticalAlignment="Center" />
|
||||
<c:TickUpDownDouble
|
||||
Grid.Row="1"
|
||||
Grid.Column="1"
|
||||
HorizontalAlignment="Stretch"
|
||||
Margin="8,5,0,0"
|
||||
Value="{Binding price_tick_unit}" />
|
||||
|
||||
<TextBlock Grid.Row="2" Text="Tick Base" Margin="0,5,0,0" VerticalAlignment="Center" />
|
||||
<c:TickUpDownDouble
|
||||
Grid.Row="2"
|
||||
Grid.Column="1"
|
||||
HorizontalAlignment="Stretch"
|
||||
Margin="8,5,0,0"
|
||||
Value="{Binding price_tick_base}" />
|
||||
</Grid>
|
||||
</ContentControl>
|
||||
</StackPanel>
|
||||
</UserControl>
|
||||
@@ -0,0 +1,24 @@
|
||||
namespace mbts.analytics {
|
||||
using System.Windows;
|
||||
using System.Windows.Controls;
|
||||
|
||||
/// <summary>
|
||||
/// Interaction logic for SlideReportSettingsView.xaml
|
||||
/// </summary>
|
||||
partial class SlideReportSettingsView : UserControl {
|
||||
public SlideReportSettingsView() =>
|
||||
InitializeComponent();
|
||||
|
||||
#region SectionContentView
|
||||
public static readonly DependencyProperty SectionContentViewProperty =
|
||||
DependencyProperty.RegisterAttached(
|
||||
"SectionContentView", typeof(FrameworkElement), typeof(SlideReportSettingsView));
|
||||
|
||||
public static FrameworkElement GetSectionContentView(DependencyObject d) =>
|
||||
d.GetValue(SectionContentViewProperty) as FrameworkElement;
|
||||
|
||||
public static void SetSectionContentView(DependencyObject d, FrameworkElement value) =>
|
||||
d.SetValue(SectionContentViewProperty, value);
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
@@ -135,7 +135,6 @@ namespace mbts.analytics {
|
||||
RaisePropertyChanged(nameof(swipe_sum));
|
||||
}
|
||||
_model.save_report_parameters(report);
|
||||
win.Close();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -34,6 +34,9 @@ namespace mbts.ui {
|
||||
|
||||
public static BTSColor pinkalicious { get { return new BTSColor(0xff, 0x33, 0x99); } }
|
||||
|
||||
public static BTSColor error_foreground => Colors.Firebrick;
|
||||
public static Color error_foreground_color => error_foreground;
|
||||
public static Brush error_foreground_brush => error_foreground;
|
||||
// Grid column colors
|
||||
|
||||
public static class Security {
|
||||
|
||||
@@ -70,6 +70,9 @@
|
||||
<cv:ValueMap x:Key="IsNullConverter" Default="{u:False}">
|
||||
<cv:KeyValue Key="{x:Null}" Value="{u:True}"/>
|
||||
</cv:ValueMap>
|
||||
<cv:ValueMap x:Key="NotNullConverter" Default="{u:True}">
|
||||
<cv:KeyValue Key="{x:Null}" Value="{u:False}" />
|
||||
</cv:ValueMap>
|
||||
<cv:ValueMap x:Key="StringIsNullOrEmptyConverter" Default="{u:False}">
|
||||
<cv:KeyValue Key="{x:Null}" Value="{u:True}"/>
|
||||
<cv:KeyValue Key="{x:Static sys:String.Empty}" Value="{u:True}"/>
|
||||
|
||||
@@ -1,218 +1,267 @@
|
||||
using bts;
|
||||
|
||||
using mbts.ui.extensions;
|
||||
using mbts.ui.utility;
|
||||
using mbts.utils;
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.ObjectModel;
|
||||
using System.Reactive.Disposables;
|
||||
using System.Reactive.Linq;
|
||||
using System.Windows;
|
||||
using System.Windows.Controls;
|
||||
using System.Windows.Controls.Primitives;
|
||||
|
||||
namespace mbts.ui.controls {
|
||||
class RadioButtonGroupManagerMap : DependencyObject {
|
||||
readonly Dictionary<object, RadioButtonGroupManager> _managers = new Dictionary<object, RadioButtonGroupManager>();
|
||||
|
||||
#region GroupManagerMap
|
||||
public static readonly DependencyProperty GroupManagerMapProperty =
|
||||
DependencyProperty.Register("GroupManagerMap", typeof(RadioButtonGroupManagerMap), typeof(RadioButtonGroupManagerMap),
|
||||
new PropertyMetadata((d, e) => {
|
||||
var k = GetGroupKey(d);
|
||||
if (e.OldValue is RadioButtonGroupManagerMap old_man) old_man._leave(d, k);
|
||||
if (e.NewValue is RadioButtonGroupManagerMap new_man) new_man._join(RadioButtonGroupManager.mk_member(d), k);
|
||||
}));
|
||||
|
||||
public static RadioButtonGroupManagerMap GetGroupManagerMap(DependencyObject d) => d.GetValue(GroupManagerMapProperty) as RadioButtonGroupManagerMap;
|
||||
public static void SetGroupManagerMap(DependencyObject d, RadioButtonGroupManagerMap value) => d.SetValue(GroupManagerMapProperty, value);
|
||||
#endregion
|
||||
|
||||
#region GroupKey
|
||||
// the RadioButton.Group property doesn't have a corresponding GroupChanged event; rather than subscribe to RadioButton.Group property changes through the DependencyProperty store (which involves a dangerous strong event reference),
|
||||
// we can simply use the GroupKey property so changes are handled in the DependencyPropertyChangedCallback below.
|
||||
public static readonly DependencyProperty GroupKeyProperty = DependencyProperty.RegisterAttached("GroupKey", typeof(object), typeof(RadioButtonGroupManagerMap),
|
||||
new PropertyMetadata((d, e) => {
|
||||
var man_map = GetGroupManagerMap(d);
|
||||
if (man_map != null) {
|
||||
var m = RadioButtonGroupManager.mk_member(d);
|
||||
man_map._leave(m, e.OldValue);
|
||||
man_map._join(m, e.NewValue);
|
||||
}
|
||||
}));
|
||||
|
||||
public static object GetGroupKey(DependencyObject d) => d.GetValue(GroupKeyProperty);
|
||||
public static void SetGroupKey(DependencyObject d, object value) => d.SetValue(GroupKeyProperty, value);
|
||||
#endregion
|
||||
|
||||
public bool TryGetManager(object group_key, out RadioButtonGroupManager result) =>
|
||||
_managers.TryGetValue(group_key, out result);
|
||||
|
||||
public void join(RadioButtonGroupManager.Member member, object group_key) =>
|
||||
_join(member, group_key);
|
||||
|
||||
void _join(RadioButtonGroupManager.Member member, object group_key) {
|
||||
if (group_key == null) return;
|
||||
_managers.GetOrAdd(group_key, _ => new RadioButtonGroupManager()).join(member);
|
||||
}
|
||||
|
||||
void _leave(DependencyObject d, object group_key) => _leave(group_key, man => man.leave(d));
|
||||
void _leave(RadioButtonGroupManager.Member member, object group_key) => _leave(group_key, man => man.leave(member));
|
||||
|
||||
void _leave(object group_key, Action<RadioButtonGroupManager> leave) {
|
||||
if (group_key == null) return;
|
||||
if (_managers.TryGetValue(group_key, out RadioButtonGroupManager man)) {
|
||||
leave(man);
|
||||
if (man.is_empty)
|
||||
_managers.Remove(group_key);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
class RadioButtonGroupManager : DependencyObject {
|
||||
#region Manager (Attached Property)
|
||||
public static readonly DependencyProperty ManagerProperty =
|
||||
DependencyProperty.RegisterAttached("Manager", typeof(RadioButtonGroupManager), typeof(RadioButtonGroupManager),
|
||||
new PropertyMetadata((d, e) => {
|
||||
if (e.OldValue is RadioButtonGroupManager old_man) old_man.leave(d);
|
||||
if (e.NewValue is RadioButtonGroupManager new_man) new_man.join(mk_member(d));
|
||||
}));
|
||||
|
||||
public static RadioButtonGroupManager GetManager(DependencyObject d) => d.GetValue(ManagerProperty) as RadioButtonGroupManager;
|
||||
public static void SetManager(DependencyObject d, RadioButtonGroupManager value) => d.SetValue(ManagerProperty, value);
|
||||
#endregion
|
||||
|
||||
#region Value (Attached Property)
|
||||
public static readonly DependencyProperty ValueProperty =
|
||||
DependencyProperty.RegisterAttached("Value", typeof(object), typeof(RadioButtonGroupManager),
|
||||
new PropertyMetadata((d, e) => (d as UIElement)?.RaiseEvent(new RoutedEventArgs(ValueChangedEvent, d))));
|
||||
|
||||
public static object GetValue(DependencyObject d) => d.GetValue(ValueProperty);
|
||||
public static void SetValue(DependencyObject d, object value) => d.SetValue(ValueProperty, value);
|
||||
#endregion
|
||||
|
||||
#region ValueChanged (Attached Event)
|
||||
public static readonly RoutedEvent ValueChangedEvent = EventManager.RegisterRoutedEvent("ValueChanged", RoutingStrategy.Direct, typeof(RoutedEventHandler), typeof(RadioButtonGroupManager));
|
||||
public static void AddValueChangedHandler(DependencyObject d, RoutedEventHandler handler) => (d as UIElement)?.AddHandler(ValueChangedEvent, handler);
|
||||
public static void RemoveValueChangedHandler(DependencyObject d, RoutedEventHandler handler) => (d as UIElement)?.RemoveHandler(ValueChangedEvent, handler);
|
||||
#endregion
|
||||
|
||||
readonly ObservableCollection<Member> _members = new ObservableCollection<Member>();
|
||||
|
||||
public RadioButtonGroupManager() {
|
||||
ObservableAutoWrapper.connect_item_hooks(_members, m => {
|
||||
m.el.DataContextChanged += on_data_context_changed;
|
||||
return new CompositeDisposable(
|
||||
m.subscribe().Subscribe(is_checked => {
|
||||
if (is_checked)
|
||||
_member_Checked(m, new RoutedEventArgs());
|
||||
})) {
|
||||
() => m.el.DataContextChanged -= on_data_context_changed
|
||||
};
|
||||
|
||||
void on_data_context_changed(object sender, DependencyPropertyChangedEventArgs e) =>
|
||||
_member_DataContextChanged(m, e);
|
||||
});
|
||||
}
|
||||
|
||||
public static readonly DependencyProperty SelectedItemProperty = DependencyProperty.Register(nameof(SelectedItem), typeof(object), typeof(RadioButtonGroupManager),
|
||||
new PropertyMetadata((d, e) => {
|
||||
var group = (RadioButtonGroupManager)d;
|
||||
foreach (var m in group._members) {
|
||||
var val = group._get_member_value(m);
|
||||
m.IsChecked = Equals(e.NewValue, val);
|
||||
}
|
||||
}));
|
||||
|
||||
public object SelectedItem { get => GetValue(SelectedItemProperty); set => SetValue(SelectedItemProperty, value); }
|
||||
|
||||
public bool is_empty => _members.Count == 0;
|
||||
|
||||
public static Member mk_member(DependencyObject element) {
|
||||
return OneOf.infer<Member, ToggleButton, MenuItem>(element, toggle_button, menu_item);
|
||||
// toggle button
|
||||
Member toggle_button(ToggleButton tb) =>
|
||||
new Member(tb, ToggleButton.IsCheckedProperty, tb.ObserveIsChecked);
|
||||
// menu item
|
||||
Member menu_item(MenuItem mi) =>
|
||||
new Member(mi, MenuItem.IsCheckedProperty, mi.ObserveIsChecked);
|
||||
}
|
||||
|
||||
public void join(Member m) {
|
||||
if (m == null)
|
||||
return;
|
||||
if (!_members.Contains(m)) {
|
||||
_members.Add(m);
|
||||
m.IsChecked = Equals(SelectedItem, _get_member_value(m));
|
||||
AddValueChangedHandler(m.el, _on_value_changed);
|
||||
}
|
||||
}
|
||||
|
||||
void _on_value_changed(object sender, RoutedEventArgs e) =>
|
||||
_update_member_value((Member)sender);
|
||||
|
||||
public void leave(DependencyObject d) =>
|
||||
leave(_members.FirstOrDefault(m => m.el == d));
|
||||
|
||||
public void leave(Member m) {
|
||||
if (m == null)
|
||||
return;
|
||||
if (_members.Remove(m)) {
|
||||
RemoveValueChangedHandler(m.el, _on_value_changed);
|
||||
if (Equals(SelectedItem, m.el.DataContext))
|
||||
SetCurrentValue(SelectedItemProperty, null);
|
||||
}
|
||||
}
|
||||
|
||||
static bool _is_checked((FrameworkElement el, DependencyProperty dp) member) =>
|
||||
member.el.GetValue(member.dp) is bool b && b;
|
||||
|
||||
void _member_Checked(object sender, RoutedEventArgs e) {
|
||||
var m = (Member)sender;
|
||||
if (m.IsChecked)
|
||||
SetCurrentValue(SelectedItemProperty, _get_member_value(m));
|
||||
}
|
||||
|
||||
void _member_DataContextChanged(object sender, DependencyPropertyChangedEventArgs e) =>
|
||||
_update_member_value((Member)sender);
|
||||
|
||||
void _update_member_value(Member m) {
|
||||
var val = GetValue(m.el);
|
||||
if (!_is_value_valid(val)) {
|
||||
val = m.el.DataContext;
|
||||
if (!_is_value_valid(val)) return;
|
||||
}
|
||||
if (m.IsChecked)
|
||||
SetCurrentValue(SelectedItemProperty, val);
|
||||
}
|
||||
|
||||
object _get_member_value(Member m) {
|
||||
var val = GetValue(m.el);
|
||||
if (!_is_value_valid(val))
|
||||
val = m.el.DataContext;
|
||||
return _is_value_valid(val) ? val : null;
|
||||
}
|
||||
|
||||
bool _is_value_valid(object value) =>
|
||||
value != null && !value.Equals(DependencyProperty.UnsetValue);
|
||||
|
||||
public class Member {
|
||||
public readonly FrameworkElement el;
|
||||
public readonly DependencyProperty dp;
|
||||
public readonly Func<IObservable<bool>> subscribe;
|
||||
|
||||
public Member(FrameworkElement el, DependencyProperty dp, Func<IObservable<bool>> subscribe) {
|
||||
this.el = el;
|
||||
this.dp = dp;
|
||||
this.subscribe = subscribe;
|
||||
}
|
||||
|
||||
public bool IsChecked {
|
||||
get => el.GetValue(dp) is bool b && b;
|
||||
set => el.SetCurrentValue(dp, value);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
using bts;
|
||||
|
||||
using mbts.ui.extensions;
|
||||
using mbts.ui.utility;
|
||||
using mbts.utils;
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.ObjectModel;
|
||||
using System.Reactive.Disposables;
|
||||
using System.Reactive.Linq;
|
||||
using System.Windows;
|
||||
using System.Windows.Controls;
|
||||
using System.Windows.Controls.Primitives;
|
||||
using System.Windows.Data;
|
||||
|
||||
namespace mbts.ui.controls {
|
||||
class RadioButtonGroupManagerMap : DependencyObject {
|
||||
readonly Dictionary<object, RadioButtonGroupManager> _managers = new Dictionary<object, RadioButtonGroupManager>();
|
||||
|
||||
#region GroupManagerMap
|
||||
public static readonly DependencyProperty GroupManagerMapProperty =
|
||||
DependencyProperty.Register("GroupManagerMap", typeof(RadioButtonGroupManagerMap), typeof(RadioButtonGroupManagerMap),
|
||||
new PropertyMetadata((d, e) => {
|
||||
var k = GetGroupKey(d);
|
||||
if (e.OldValue is RadioButtonGroupManagerMap old_man) old_man._leave(d, k);
|
||||
if (e.NewValue is RadioButtonGroupManagerMap new_man) new_man._join(RadioButtonGroupManager.mk_member(d), k);
|
||||
_set_selected_item_binding(d, GetSelectedItem(d));
|
||||
}));
|
||||
|
||||
public static RadioButtonGroupManagerMap GetGroupManagerMap(DependencyObject d) => d.GetValue(GroupManagerMapProperty) as RadioButtonGroupManagerMap;
|
||||
public static void SetGroupManagerMap(DependencyObject d, RadioButtonGroupManagerMap value) => d.SetValue(GroupManagerMapProperty, value);
|
||||
#endregion
|
||||
|
||||
#region SelectedItem
|
||||
public static readonly DependencyProperty SelectedItemProperty =
|
||||
DependencyProperty.RegisterAttached(
|
||||
"SelectedItem",
|
||||
typeof(BindingBase),
|
||||
typeof(RadioButtonGroupManagerMap),
|
||||
new(_on_selected_item_changed));
|
||||
|
||||
static void _on_selected_item_changed(
|
||||
DependencyObject d, DependencyPropertyChangedEventArgs e) =>
|
||||
_set_selected_item_binding(d, e.NewValue as BindingBase);
|
||||
|
||||
public static BindingBase GetSelectedItem(DependencyObject d) =>
|
||||
d.GetValue(SelectedItemProperty) as BindingBase;
|
||||
|
||||
public static void SetSelectedItem(DependencyObject d, BindingBase value) =>
|
||||
d.SetValue(SelectedItemProperty, value);
|
||||
#endregion
|
||||
|
||||
#region GroupKey
|
||||
// the RadioButton.Group property doesn't have a corresponding GroupChanged event; rather than subscribe to RadioButton.Group property changes through the DependencyProperty store (which involves a dangerous strong event reference),
|
||||
// we can simply use the GroupKey property so changes are handled in the DependencyPropertyChangedCallback below.
|
||||
public static readonly DependencyProperty GroupKeyProperty = DependencyProperty.RegisterAttached("GroupKey", typeof(object), typeof(RadioButtonGroupManagerMap),
|
||||
new PropertyMetadata((d, e) => {
|
||||
var man_map = GetGroupManagerMap(d);
|
||||
if (man_map != null) {
|
||||
var m = RadioButtonGroupManager.mk_member(d);
|
||||
man_map._leave(m, e.OldValue);
|
||||
var man = man_map._join(m, e.NewValue);
|
||||
_set_selected_item_binding(man, GetSelectedItem(d));
|
||||
}
|
||||
}));
|
||||
|
||||
public static object GetGroupKey(DependencyObject d) => d.GetValue(GroupKeyProperty);
|
||||
public static void SetGroupKey(DependencyObject d, object value) => d.SetValue(GroupKeyProperty, value);
|
||||
#endregion
|
||||
|
||||
public bool TryGetManager(object group_key, out RadioButtonGroupManager result) =>
|
||||
_managers.TryGetValue(group_key, out result);
|
||||
|
||||
public void join(RadioButtonGroupManager.Member member, object group_key) =>
|
||||
_join(member, group_key);
|
||||
|
||||
RadioButtonGroupManager _join(RadioButtonGroupManager.Member member, object group_key) {
|
||||
if (group_key == null) {
|
||||
return null;
|
||||
}
|
||||
var man = _managers.GetOrAdd(group_key, _ => new RadioButtonGroupManager());
|
||||
man.join(member);
|
||||
return man;
|
||||
}
|
||||
|
||||
void _leave(DependencyObject d, object group_key) => _leave(group_key, man => man.leave(d));
|
||||
void _leave(RadioButtonGroupManager.Member member, object group_key) => _leave(group_key, man => man.leave(member));
|
||||
|
||||
void _leave(object group_key, Action<RadioButtonGroupManager> leave) {
|
||||
if (group_key == null) return;
|
||||
if (_managers.TryGetValue(group_key, out RadioButtonGroupManager man)) {
|
||||
leave(man);
|
||||
if (man.is_empty)
|
||||
_managers.Remove(group_key);
|
||||
}
|
||||
}
|
||||
|
||||
static void _set_selected_item_binding(DependencyObject d, BindingBase binding) =>
|
||||
_set_selected_item_binding(GetGroupKey(d), GetGroupManagerMap(d), binding);
|
||||
|
||||
static void _set_selected_item_binding(
|
||||
object group_key, RadioButtonGroupManagerMap man_map, BindingBase binding) {
|
||||
if (binding is not null &&
|
||||
group_key is not null &&
|
||||
man_map is not null &&
|
||||
man_map.TryGetManager(group_key, out var man)) {
|
||||
_set_selected_item_binding(man, binding);
|
||||
}
|
||||
}
|
||||
|
||||
static void _set_selected_item_binding(
|
||||
RadioButtonGroupManager man, BindingBase binding) {
|
||||
if (man is null || binding is null) {
|
||||
return;
|
||||
}
|
||||
BindingOperations.ClearBinding(man, RadioButtonGroupManager.SelectedItemProperty);
|
||||
BindingOperations.SetBinding(
|
||||
man, RadioButtonGroupManager.SelectedItemProperty, binding);
|
||||
}
|
||||
}
|
||||
|
||||
class RadioButtonGroupManager : DependencyObject {
|
||||
#region Manager (Attached Property)
|
||||
public static readonly DependencyProperty ManagerProperty =
|
||||
DependencyProperty.RegisterAttached("Manager", typeof(RadioButtonGroupManager), typeof(RadioButtonGroupManager),
|
||||
new PropertyMetadata((d, e) => {
|
||||
if (e.OldValue is RadioButtonGroupManager old_man) old_man.leave(d);
|
||||
if (e.NewValue is RadioButtonGroupManager new_man) new_man.join(mk_member(d));
|
||||
}));
|
||||
|
||||
public static RadioButtonGroupManager GetManager(DependencyObject d) => d.GetValue(ManagerProperty) as RadioButtonGroupManager;
|
||||
public static void SetManager(DependencyObject d, RadioButtonGroupManager value) => d.SetValue(ManagerProperty, value);
|
||||
#endregion
|
||||
|
||||
#region Value (Attached Property)
|
||||
public static readonly DependencyProperty ValueProperty =
|
||||
DependencyProperty.RegisterAttached("Value", typeof(object), typeof(RadioButtonGroupManager),
|
||||
new PropertyMetadata((d, e) => (d as UIElement)?.RaiseEvent(new RoutedEventArgs(ValueChangedEvent, d))));
|
||||
|
||||
public static object GetValue(DependencyObject d) => d.GetValue(ValueProperty);
|
||||
public static void SetValue(DependencyObject d, object value) => d.SetValue(ValueProperty, value);
|
||||
#endregion
|
||||
|
||||
#region ValueChanged (Attached Event)
|
||||
public static readonly RoutedEvent ValueChangedEvent = EventManager.RegisterRoutedEvent("ValueChanged", RoutingStrategy.Direct, typeof(RoutedEventHandler), typeof(RadioButtonGroupManager));
|
||||
public static void AddValueChangedHandler(DependencyObject d, RoutedEventHandler handler) => (d as UIElement)?.AddHandler(ValueChangedEvent, handler);
|
||||
public static void RemoveValueChangedHandler(DependencyObject d, RoutedEventHandler handler) => (d as UIElement)?.RemoveHandler(ValueChangedEvent, handler);
|
||||
#endregion
|
||||
|
||||
readonly ObservableCollection<Member> _members = new ObservableCollection<Member>();
|
||||
|
||||
public RadioButtonGroupManager() {
|
||||
ObservableAutoWrapper.connect_item_hooks(_members, m => {
|
||||
m.el.DataContextChanged += on_data_context_changed;
|
||||
return new CompositeDisposable(
|
||||
m.subscribe().Subscribe(is_checked => {
|
||||
if (is_checked)
|
||||
_member_Checked(m, new RoutedEventArgs());
|
||||
})) {
|
||||
() => m.el.DataContextChanged -= on_data_context_changed
|
||||
};
|
||||
|
||||
void on_data_context_changed(object sender, DependencyPropertyChangedEventArgs e) =>
|
||||
_member_DataContextChanged(m, e);
|
||||
});
|
||||
}
|
||||
|
||||
public static readonly DependencyProperty SelectedItemProperty = DependencyProperty.Register(nameof(SelectedItem), typeof(object), typeof(RadioButtonGroupManager),
|
||||
new PropertyMetadata((d, e) => {
|
||||
var group = (RadioButtonGroupManager)d;
|
||||
foreach (var m in group._members) {
|
||||
var val = group._get_member_value(m);
|
||||
m.IsChecked = Equals(e.NewValue, val);
|
||||
}
|
||||
}));
|
||||
|
||||
public object SelectedItem { get => GetValue(SelectedItemProperty); set => SetValue(SelectedItemProperty, value); }
|
||||
|
||||
public bool is_empty => _members.Count == 0;
|
||||
|
||||
public static Member mk_member(DependencyObject element) {
|
||||
return OneOf.infer<Member, ToggleButton, MenuItem>(element, toggle_button, menu_item);
|
||||
// toggle button
|
||||
Member toggle_button(ToggleButton tb) =>
|
||||
new Member(tb, ToggleButton.IsCheckedProperty, tb.ObserveIsChecked);
|
||||
// menu item
|
||||
Member menu_item(MenuItem mi) =>
|
||||
new Member(mi, MenuItem.IsCheckedProperty, mi.ObserveIsChecked);
|
||||
}
|
||||
|
||||
public void join(Member m) {
|
||||
if (m == null)
|
||||
return;
|
||||
if (!_members.Contains(m)) {
|
||||
_members.Add(m);
|
||||
m.IsChecked = Equals(SelectedItem, _get_member_value(m));
|
||||
AddValueChangedHandler(m.el, _on_value_changed);
|
||||
}
|
||||
}
|
||||
|
||||
void _on_value_changed(object sender, RoutedEventArgs e) =>
|
||||
_update_member_value((Member)sender);
|
||||
|
||||
public void leave(DependencyObject d) =>
|
||||
leave(_members.FirstOrDefault(m => m.el == d));
|
||||
|
||||
public void leave(Member m) {
|
||||
if (m == null)
|
||||
return;
|
||||
if (_members.Remove(m)) {
|
||||
RemoveValueChangedHandler(m.el, _on_value_changed);
|
||||
if (Equals(SelectedItem, m.el.DataContext))
|
||||
SetCurrentValue(SelectedItemProperty, null);
|
||||
}
|
||||
}
|
||||
|
||||
static bool _is_checked((FrameworkElement el, DependencyProperty dp) member) =>
|
||||
member.el.GetValue(member.dp) is bool b && b;
|
||||
|
||||
void _member_Checked(object sender, RoutedEventArgs e) {
|
||||
var m = (Member)sender;
|
||||
if (m.IsChecked)
|
||||
SetCurrentValue(SelectedItemProperty, _get_member_value(m));
|
||||
}
|
||||
|
||||
void _member_DataContextChanged(object sender, DependencyPropertyChangedEventArgs e) =>
|
||||
_update_member_value((Member)sender);
|
||||
|
||||
void _update_member_value(Member m) {
|
||||
var val = GetValue(m.el);
|
||||
if (!_is_value_valid(val)) {
|
||||
val = m.el.DataContext;
|
||||
if (!_is_value_valid(val)) return;
|
||||
}
|
||||
if (m.IsChecked)
|
||||
SetCurrentValue(SelectedItemProperty, val);
|
||||
}
|
||||
|
||||
object _get_member_value(Member m) {
|
||||
var val = GetValue(m.el);
|
||||
if (!_is_value_valid(val))
|
||||
val = m.el.DataContext;
|
||||
return _is_value_valid(val) ? val : null;
|
||||
}
|
||||
|
||||
bool _is_value_valid(object value) =>
|
||||
value != null && !value.Equals(DependencyProperty.UnsetValue);
|
||||
|
||||
public class Member {
|
||||
public readonly FrameworkElement el;
|
||||
public readonly DependencyProperty dp;
|
||||
public readonly Func<IObservable<bool>> subscribe;
|
||||
|
||||
public Member(FrameworkElement el, DependencyProperty dp, Func<IObservable<bool>> subscribe) {
|
||||
this.el = el;
|
||||
this.dp = dp;
|
||||
this.subscribe = subscribe;
|
||||
}
|
||||
|
||||
public bool IsChecked {
|
||||
get => el.GetValue(dp) is bool b && b;
|
||||
set => el.SetCurrentValue(dp, value);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -346,7 +346,7 @@ namespace System.Collections.Generic {
|
||||
}
|
||||
|
||||
public static bool TryGetFirst<T>(
|
||||
this IEnumerable<T> source, Func<T?, bool> predicate, out T? result, out int index) {
|
||||
this IEnumerable<T> source, Func<T, bool> predicate, out T? result, out int index) {
|
||||
if (source == null) throw new ArgumentNullException(nameof(source));
|
||||
index = 0;
|
||||
foreach (T element in source) {
|
||||
|
||||
@@ -63,6 +63,42 @@ namespace bts.collections {
|
||||
}
|
||||
}
|
||||
|
||||
public static bool? MoveItem<T>(this IList<T> list, T item, int index) =>
|
||||
MoveItem(list, item, index, EqualityComparer<T>.Default);
|
||||
|
||||
public static bool? MoveItem<T>(
|
||||
this IList<T> list, T item, int index, IEqualityComparer<T> comparer) {
|
||||
for (int i = 0; i < list.Count; i++) {
|
||||
if (!comparer.Equals(item, list[i])) {
|
||||
continue;
|
||||
}
|
||||
if (i == index) {
|
||||
return null;
|
||||
}
|
||||
list.RemoveAt(i);
|
||||
list.Insert(index, item);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public static bool? MoveFirst<T>(
|
||||
this IList<T> list, Func<T, bool> predicate, int index) {
|
||||
for (int i = 0; i < list.Count; i++) {
|
||||
if (!predicate(list[i])) {
|
||||
continue;
|
||||
}
|
||||
if (i == index) {
|
||||
return null;
|
||||
}
|
||||
var item = list[i];
|
||||
list.RemoveAt(i);
|
||||
list.Insert(index, item);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public static bool RemoveSorted<T>(this IList<T> list, T item, IComparer<T> comparer) {
|
||||
int i = CollectionHelper.binary_search(list, item, comparer);
|
||||
if (i < 0)
|
||||
@@ -174,7 +210,7 @@ namespace bts.collections {
|
||||
var source_list = source as IList<T> ?? source.ToList();
|
||||
var changes = Diff.diff(list, source_list, comp).ToList();
|
||||
// Apply the diff
|
||||
for(int i = 0; i < changes.Count; ++i) {
|
||||
for (int i = 0; i < changes.Count; ++i) {
|
||||
var c = changes[i];
|
||||
// removes
|
||||
for (var x = 0; x < c.deletedLeft; ++x) {
|
||||
|
||||
@@ -27,7 +27,8 @@ namespace mbts {
|
||||
nan_text = api_tick_display_settings.NanText,
|
||||
show_decimal_part = api_tick_display_settings.ShowDecimalPart,
|
||||
show_zero_integer = api_tick_display_settings.ShowZeroInteger,
|
||||
tick_factors = api_tick_display_settings.TickFactors.to_tick_factors()
|
||||
tick_factors = api_tick_display_settings.HasTickFactors ?
|
||||
api_tick_display_settings.TickFactors.to_tick_factors() : null
|
||||
};
|
||||
|
||||
public static bool is_valid(this TickFactors tick) =>
|
||||
@@ -73,7 +74,7 @@ namespace mbts {
|
||||
if (T.IsInfinity(value)) {
|
||||
return value.ToString();
|
||||
}
|
||||
return tick.is_valid() ?
|
||||
return tick?.is_valid() ?? false ?
|
||||
_format_tick(tick, value, settings) :
|
||||
_format_no_tick(
|
||||
value, settings.display_multiplier.as_type<double, T>(), settings.show_commas);
|
||||
@@ -151,9 +152,9 @@ namespace mbts {
|
||||
}
|
||||
|
||||
public static T parse<T>(this TickFactors tick, string text, T display_multiplier, string nan_text) where T : IFloatingPoint<T> =>
|
||||
tick.is_valid() ?
|
||||
tick?.is_valid() ?? false ?
|
||||
_parse(tick, text, display_multiplier, nan_text) :
|
||||
_parse_no_tick(text, display_multiplier);
|
||||
_parse_no_tick(text, display_multiplier, nan_text);
|
||||
|
||||
public static T parse<T>(
|
||||
this RegionalTickFactors regional_tick,
|
||||
@@ -163,7 +164,7 @@ namespace mbts {
|
||||
) where T : IFloatingPoint<T> =>
|
||||
regional_tick.is_valid() ?
|
||||
_parse(regional_tick, text, display_multiplier, nan_text) :
|
||||
_parse_no_tick(text, display_multiplier);
|
||||
_parse_no_tick(text, display_multiplier, nan_text);
|
||||
|
||||
public static T tick<T>(this TickFactors tick, T value, int count)
|
||||
where T : IFloatingPoint<T> =>
|
||||
@@ -410,8 +411,13 @@ namespace mbts {
|
||||
return value.ToString(show_commas ? "#,0" : "0", null);
|
||||
}
|
||||
|
||||
static T _parse_no_tick<T>(string text, T display_multiplier) where T : IFloatingPoint<T> =>
|
||||
T.TryParse(text, null, out var result) ? result.safe_divide(display_multiplier) : T.NaN;
|
||||
static T _parse_no_tick<T>(string text, T display_multiplier, string nan_text) where T : IFloatingPoint<T> {
|
||||
if (text == nan_text) {
|
||||
return T.NaN;
|
||||
}
|
||||
return T.TryParse(text, null, out var result) ?
|
||||
result.safe_divide(display_multiplier) : T.NaN;
|
||||
}
|
||||
|
||||
static T _get_integer_part<T>(string integer_text) where T : IFloatingPoint<T> {
|
||||
if (integer_text.is_null_or_white_space()) {
|
||||
|
||||
Reference in new issue
Block a user