diff --git a/src/client/spark/Modules/Spreader/ExecutionStrategyEditor.xaml b/src/client/spark/Modules/Spreader/ExecutionStrategyEditor.xaml
index 6055d5bfe..0094ac79f 100644
--- a/src/client/spark/Modules/Spreader/ExecutionStrategyEditor.xaml
+++ b/src/client/spark/Modules/Spreader/ExecutionStrategyEditor.xaml
@@ -14,6 +14,7 @@
+
285
16
@@ -365,20 +366,11 @@
Grid.Column="2" VerticalAlignment="Center" Margin="6,0,0,0" Text="Ticks" IsEnabled="{TemplateBinding IsNew}"
Visibility="{Binding LegTuples.Count, RelativeSource={RelativeSource TemplatedParent}, Converter={StaticResource IntNotZeroVisibilityConverter}}"
/>
-
-
-
-
-
-
-
-
-
-
+ />
Pricing
GetValue(TickFactorsProperty) as TickFactors; set => SetValue(TickFactorsProperty, value); }
#endregion
- #region AvailableTickFactors
- public static readonly DependencyProperty AvailableTickFactorsProperty = DependencyProperty.Register(
- nameof(AvailableTickFactors), typeof(IEnumerable), typeof(ExecutionStrategyEditor), new PropertyMetadata(new TickFactors[0]));
-
- public IEnumerable AvailableTickFactors { get => GetValue(AvailableTickFactorsProperty) as IEnumerable; set => SetValue(AvailableTickFactorsProperty, value); }
- #endregion
-
#region IsNew
public static readonly DependencyProperty IsNewProperty =
DependencyProperty.Register(
@@ -253,11 +246,11 @@ namespace mbts.ui.spark {
class ExecutionStrategyErrorAdorner : NotifyDataErrorAdorner, IDisposable {
readonly ChildProperty _name_text_box;
- readonly ChildProperty _tick_combo_box;
+ readonly ChildProperty _tick_factors_picker;
public ExecutionStrategyErrorAdorner(ExecutionStrategyEditor editor) : base(editor) {
_name_text_box = child_property("PART_Name_TextBox");
- _tick_combo_box = child_property("PART_Tick_ComboBox");
+ _tick_factors_picker = child_property("PART_TickFactorsPicker");
}
protected override void OnRender(DrawingContext drawing_context) {
@@ -269,7 +262,7 @@ namespace mbts.ui.spark {
if (_vm != null && _vm.GetErrors(nameof(SyntheticEditorVM.name)).Cast().Any())
this.draw_border(drawing_context, _name_text_box.value, null, new Pen(Brushes.Red, 1));
if (_vm != null && _vm.GetErrors(nameof(SyntheticEditorVM.tick_factors)).Cast().Any())
- this.draw_border(drawing_context, _tick_combo_box.value, null, new Pen(Brushes.Red, 1));
+ this.draw_border(drawing_context, _tick_factors_picker.value, null, new Pen(Brushes.Red, 1));
string error_text = string.Join(", ", _vm.AllErrors);
this.draw_relative_text(RelativePosition.Below, error_text, drawing_context, _name_text_box.value, BTSColors.header_error_text_brush, 0, y_offset);
}
diff --git a/src/client/spark/Modules/Spreader/SyntheticEditorView.xaml b/src/client/spark/Modules/Spreader/SyntheticEditorView.xaml
index 704959c14..a14c6b8f0 100644
--- a/src/client/spark/Modules/Spreader/SyntheticEditorView.xaml
+++ b/src/client/spark/Modules/Spreader/SyntheticEditorView.xaml
@@ -23,7 +23,6 @@
HorizontalAlignment="Stretch" Margin="6"
SyntheticName="{Binding name}"
TickFactors="{Binding tick_factors}"
- AvailableTickFactors="{Binding available_tick_factors_view}"
IsNew="{Binding is_new}"
CanUserAddNewLeg="{Binding can_add_leg}"
IsNewLegPopupOpen="{Binding is_new_leg_popup_open}"
diff --git a/src/client/spark/Modules/Spreader/VM/SyntheticEditorVM.cs b/src/client/spark/Modules/Spreader/VM/SyntheticEditorVM.cs
index e9996aa90..a70aeb29c 100644
--- a/src/client/spark/Modules/Spreader/VM/SyntheticEditorVM.cs
+++ b/src/client/spark/Modules/Spreader/VM/SyntheticEditorVM.cs
@@ -11,11 +11,9 @@ using mbts.utils;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
-using System.ComponentModel;
using System.Linq;
using System.Reactive.Linq;
using System.Threading.Tasks;
-using System.Windows.Data;
using System.Windows.Input;
using System.Windows.Media;
@@ -24,7 +22,6 @@ namespace mbts.spark {
/// The view model designed to serve as the DataContext for the SyntheticEditorView
///
partial class SyntheticEditorVM : DisposableViewModelBase, IRequestViewClose, IRequestBindingSourceUpdate, IDisposable {
- readonly ObservableCollection _available_tick_factors = new ObservableCollection(TickUtils.synthetic_presets);
readonly QuantityModel _quantity_model;
readonly PriceMultiplierModel _price_mult_model;
readonly List _resources = new List();
@@ -42,7 +39,7 @@ namespace mbts.spark {
public SyntheticEditorVM(SpreaderModel model, SecurityImmutable synthetic, ExecutionStrategyImmutable strategy, IObservable security_has_working_orders)
: this(synthetic, strategy, false) {
ExceptionAssert.InvalidOperation.That(synthetic.Id != 0, "This constructor may only be used for already-existing synthetic securities (id must be non-zero).");
- _tick_factors = TickUtils.get_regional_ticks(synthetic).low_tick;
+ _tick_factors = TickUtils.get_regional_ticks(synthetic.ContractSpec).low_tick;
title = $"Edit '{synthetic.Synthetic.Name}'";
icon = Icons.ModifySynthetic;
_has_working_orders = backing(nameof(has_working_orders), security_has_working_orders.OnDispatcher());
@@ -95,7 +92,7 @@ namespace mbts.spark {
_set_ticks_automatically = false;
_set_quantities_automatically = false;
_set_price_mults_automatically = false;
- _tick_factors = TickUtils.get_regional_ticks(_synthetic).low_tick;
+ _tick_factors = TickUtils.get_regional_ticks(_synthetic.ContractSpec).low_tick;
} else {
_deduce_name();
_deduce_ticks();
@@ -122,7 +119,7 @@ namespace mbts.spark {
flash_error_msg("Name already taken", SparkUtils.UI.MessageFlashDuration, nameof(name)).ignore();
valid = false;
}
- if (_tick_factors == null || !_tick_factors.is_valid() || !_available_tick_factors.Contains(_tick_factors)) {
+ if (_tick_factors == null || !_tick_factors.is_valid()) {
flash_error_msg("Please select ticks", SparkUtils.UI.MessageFlashDuration, nameof(tick_factors)).ignore();
valid = false;
}
@@ -134,6 +131,8 @@ namespace mbts.spark {
_synthetic.ContractSpec.LowTick = tick_frac;
_synthetic.ContractSpec.HighTick = tick_frac;
_synthetic.ContractSpec.PriceBreak = double.MaxValue;
+ _synthetic.ContractSpec.MainFraction = (uint)MathUtils.factor_out(_tick_factors.tick_base, 10);
+ _synthetic.ContractSpec.PriceDisplayFormat = (uint)_tick_factors.display_digits();
uint? id = await model.create_synthetic(_synthetic);
if (id.HasValue && id != 0) {
if (await model.save_strategy(id.Value, get_strategy())) {
@@ -153,9 +152,6 @@ namespace mbts.spark {
_set_ticks_automatically = is_new;
_set_quantities_automatically = is_new;
_set_price_mults_automatically = is_new;
- available_tick_factors_view = CollectionViewSource.GetDefaultView(_available_tick_factors);
- ((ListCollectionView)available_tick_factors_view).CustomSort = TickUtils.CompareUtils.base_unit_comparer.as_non_generic();
- available_tick_factors_view.GroupDescriptions.Add(new PropertyGroupDescription(nameof(TickFactors.tick_base)));
_quantity_model = new QuantityModel(!is_new);
_price_mult_model = new PriceMultiplierModel(!is_new);
@@ -247,9 +243,11 @@ namespace mbts.spark {
public TickFactors tick_factors {
get => _tick_factors;
set {
- _tick_factors = value;
- _set_ticks_automatically = false;
- RaisePropertyChanged();
+ if (_tick_factors != value) {
+ _tick_factors = value;
+ _set_ticks_automatically = false;
+ RaisePropertyChanged();
+ }
}
}
public bool has_working_orders => _has_working_orders.Value;
@@ -263,7 +261,6 @@ namespace mbts.spark {
public IRaiseCanExecuteChangedCommand commit { get; }
public ICommand remove_leg { get; }
public ContractPickerModel contract_picker_model { get; }
- public ICollectionView available_tick_factors_view { get; }
public ExecutionStrategyImmutable get_strategy() {
var mutable_strategy = _strategy.CloneToMutable();
@@ -330,8 +327,6 @@ namespace mbts.spark {
void _deduce_ticks() {
_tick_factors = TickUtils.deduce_ticks(leg_tuples.Select(l => l.leg.Security.ContractSpec));
- if (_tick_factors != null && !_available_tick_factors.Contains(_tick_factors))
- _available_tick_factors.Add(_tick_factors);
RaisePropertyChanged(nameof(tick_factors));
}
@@ -340,4 +335,4 @@ namespace mbts.spark {
else clear_error(nameof(leg_count));
}
}
-}
\ No newline at end of file
+}
diff --git a/src/client/spark/core/GlobalExtensions/TickExtensions.cs b/src/client/spark/core/GlobalExtensions/TickExtensions.cs
index 5174402b7..8400fc04b 100644
--- a/src/client/spark/core/GlobalExtensions/TickExtensions.cs
+++ b/src/client/spark/core/GlobalExtensions/TickExtensions.cs
@@ -271,7 +271,8 @@ namespace mbts {
string integer_part_text = show_commas ? integer_part.ToString("#,0") : integer_part.ToString();
return integer_part_text + tick.separator() + decimal_part.ToString(new string('0', display_digits(tick.tick_base)));
}
- } catch (OverflowException ex) {
+ }
+ catch (OverflowException ex) {
Logger.warn(bts.log.Subsystem.Ui, $"Arithmetic overflow exception in format_tick (tick:{tick}, value:{value}):{ex}");
return "Overflow";
}
@@ -279,7 +280,7 @@ namespace mbts {
private static double _round_tick(double tick_unit_frac, double input) {
return input - Math.IEEERemainder(input, tick_unit_frac);
- }
+ }
#endregion
}
}
\ No newline at end of file
diff --git a/src/client/spark/core/Utility/AnonymousEqualityComparer.cs b/src/client/spark/core/Utility/AnonymousEqualityComparer.cs
index 99b86c440..ce4b27e89 100644
--- a/src/client/spark/core/Utility/AnonymousEqualityComparer.cs
+++ b/src/client/spark/core/Utility/AnonymousEqualityComparer.cs
@@ -1,4 +1,5 @@
using System;
+using System.Collections;
using System.Collections.Generic;
namespace mbts.utils {
@@ -25,6 +26,9 @@ namespace mbts.utils {
public static IEqualityComparer CreateNullable(Func equals) where T : struct =>
new AnonymousEqualityComparer((a, b) => a.HasValue ? b.HasValue && equals(a.Value, b.Value) : !b.HasValue);
+ public static IEqualityComparer to_non_generic(this IEqualityComparer comparer) =>
+ new AnonymousEqualityComparer(comparer.Equals, comparer.GetHashCode);
+
public static bool NullCheckEquals(T x, T y, Func non_null_equals) where T : class, IEquatable =>
x == null ? y == null :
y != null &&
@@ -55,7 +59,7 @@ namespace mbts.utils {
static void _accumulate_hash(ref int aggregate_hash, ref int item_hash) =>
aggregate_hash = aggregate_hash * _hash_multiplier + item_hash;
- private class AnonymousEqualityComparer : IEqualityComparer {
+ private class AnonymousEqualityComparer : IEqualityComparer, IEqualityComparer {
readonly Func _equals;
readonly Func _get_hash_code;
@@ -67,6 +71,9 @@ namespace mbts.utils {
public bool Equals(T x, T y) => _equals(x, y);
public int GetHashCode(T obj) => _get_hash_code(obj);
+
+ bool IEqualityComparer.Equals(object x, object y) => x is T xt && y is T yt && _equals(xt, yt);
+ int IEqualityComparer.GetHashCode(object obj) => throw new NotImplementedException();
}
}
}
\ No newline at end of file
diff --git a/src/client/spark/core/Utility/CompareUtils.cs b/src/client/spark/core/Utility/CompareUtils.cs
index ee081f19f..89ebe5f3e 100644
--- a/src/client/spark/core/Utility/CompareUtils.cs
+++ b/src/client/spark/core/Utility/CompareUtils.cs
@@ -23,9 +23,12 @@ namespace mbts.utils {
#endregion
#region Comparer
- public static IComparer as_non_generic(this IComparer comparer) =>
+ public static IComparer to_non_generic(this IComparer comparer) =>
new NonGenericComparerWrapper(comparer);
+ public static IComparer wrap(this IComparer inner_comparer, Func selector) =>
+ Comparer.Create((a, b) => inner_comparer.Compare(a == null ? default : selector(a), b == null ? default : selector(b)));
+
class NonGenericComparerWrapper : IComparer {
readonly IComparer _comparer;
@@ -36,4 +39,4 @@ namespace mbts.utils {
}
#endregion
}
-}
\ No newline at end of file
+}
diff --git a/src/client/spark/core/Utility/IValueFactoryVM.cs b/src/client/spark/core/Utility/IValueFactoryVM.cs
new file mode 100644
index 000000000..68322105e
--- /dev/null
+++ b/src/client/spark/core/Utility/IValueFactoryVM.cs
@@ -0,0 +1,6 @@
+namespace mbts.spark {
+ interface IValueFactoryVM {
+ T create();
+ void load_from(T value);
+ }
+}
\ No newline at end of file
diff --git a/src/client/spark/view/Controls/Order/OrderDetailsPopupControl.xaml b/src/client/spark/view/Controls/Order/OrderDetailsPopupControl.xaml
index d73ba0daa..8267e375f 100644
--- a/src/client/spark/view/Controls/Order/OrderDetailsPopupControl.xaml
+++ b/src/client/spark/view/Controls/Order/OrderDetailsPopupControl.xaml
@@ -375,7 +375,6 @@
DataContext="{Binding strategy_editor}"
SyntheticName="{Binding name}"
TickFactors="{Binding tick_factors}"
- AvailableTickFactors="{Binding available_tick_factors_view}"
IsNew="False"
IsNewLegPopupOpen="{Binding is_new_leg_popup_open}"
PriceCalc="{Binding price_calc}"
diff --git a/src/client/spark/view/Controls/PriceEntryControl.xaml.cs b/src/client/spark/view/Controls/PriceEntryControl.xaml.cs
index 44edd0ac6..a73750489 100644
--- a/src/client/spark/view/Controls/PriceEntryControl.xaml.cs
+++ b/src/client/spark/view/Controls/PriceEntryControl.xaml.cs
@@ -1,10 +1,12 @@
using bts.api;
using mbts.spark;
+using mbts.ui.extensions;
using mbts.ui.spark.converters;
using System;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Input;
+using static mbts.ui.utility.text.TextUtils;
namespace mbts.ui.spark {
///
@@ -16,7 +18,7 @@ namespace mbts.ui.spark {
#region Value
public static readonly DependencyProperty ValueProperty = DependencyProperty.Register("Value", typeof(double), typeof(PriceEntryControl),new FrameworkPropertyMetadata(double.NaN, FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, null, CoerceValue));
- private static object CoerceValue(DependencyObject d, object baseValue) { return TickUtils.get_regional_ticks((SecurityImmutable)d.GetValue(SecurityProperty)).round((double)baseValue); }
+ private static object CoerceValue(DependencyObject d, object baseValue) { return TickUtils.get_regional_ticks((ContractSpecificationImmutable)d.GetValue(ContractSpecProperty)).round((double)baseValue); }
public double Value { get => (double)GetValue(ValueProperty); set => SetValue(ValueProperty, value); }
#endregion
@@ -37,11 +39,11 @@ namespace mbts.ui.spark {
public ICommand TickDownCommand { get => GetValue(TickDownCommandProperty) as ICommand; private set => SetValue(TickDownCommandPropertyKey, value); }
#endregion
- #region Security
- public static readonly DependencyProperty SecurityProperty = DependencyProperty.Register(
- nameof(Security), typeof(SecurityImmutable), typeof(PriceEntryControl), new PropertyMetadata(SecurityDataHelper.Defaults.SecurityImmutable, OnSecurityChanged));
- static void OnSecurityChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) => ((PriceEntryControl)d)._update_text_binding();
- public SecurityImmutable? Security { get => GetValue(SecurityProperty) as SecurityImmutable?; set => SetValue(SecurityProperty, value); }
+ #region ContractSpec
+ public static readonly DependencyProperty ContractSpecProperty = DependencyProperty.Register("ContractSpec", typeof(ContractSpecificationImmutable), typeof(PriceEntryControl),
+ new PropertyMetadata(SecurityDataHelper.Defaults.ContractSpecificationImmutablePennies, OnContractSpecChanged));
+ static void OnContractSpecChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) => ((PriceEntryControl)d)._update_text_binding();
+ public ContractSpecificationImmutable? ContractSpec { get => GetValue(ContractSpecProperty) as ContractSpecificationImmutable?; set => SetValue(ContractSpecProperty, value); }
#endregion
TextBox _text;
@@ -69,8 +71,8 @@ namespace mbts.ui.spark {
if (double.IsNaN(v)) {
SetCurrentValue(ValueProperty, TickDefaultValue);
} else {
- var sec = Security;
- if (sec.HasValue) SetCurrentValue(ValueProperty, sec.Value.tickup(v));
+ var spec = ContractSpec;
+ if (spec.HasValue) SetCurrentValue(ValueProperty, spec.Value.tickup(v));
else SetCurrentValue(ValueProperty, TickDefaultValue);
}
}
@@ -83,21 +85,21 @@ namespace mbts.ui.spark {
if (double.IsNaN(v)) {
SetCurrentValue(ValueProperty, TickDefaultValue);
} else {
- var sec = Security;
- if (sec.HasValue) SetCurrentValue(ValueProperty, sec.Value.tickdown(v));
+ var spec = ContractSpec;
+ if (spec.HasValue) SetCurrentValue(ValueProperty, spec.Value.tickdown(v));
else SetCurrentValue(ValueProperty, TickDefaultValue);
}
}
void _update_text_binding() {
if (_text != null) {
- var sec = Security;
- if (sec != null) {
+ var spec = ContractSpec;
+ if (spec != null) {
var be = _text.GetBindingExpression(TextBox.TextProperty);
if (be != null) {
var converter = be.ParentBinding.Converter as TickDisplayTwoWayConverter;
if (converter != null) {
- converter.Security = sec;
+ converter.ContractSpec = spec;
be.UpdateTarget();
}
}
@@ -105,4 +107,4 @@ namespace mbts.ui.spark {
}
}
}
-}
\ No newline at end of file
+}
diff --git a/src/client/spark/view/Controls/TickFactorsPicker/TickFactorsPicker.xaml b/src/client/spark/view/Controls/TickFactorsPicker/TickFactorsPicker.xaml
new file mode 100644
index 000000000..204ea5bb9
--- /dev/null
+++ b/src/client/spark/view/Controls/TickFactorsPicker/TickFactorsPicker.xaml
@@ -0,0 +1,75 @@
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/src/client/spark/view/Controls/TickFactorsPicker/TickFactorsPicker.xaml.cs b/src/client/spark/view/Controls/TickFactorsPicker/TickFactorsPicker.xaml.cs
new file mode 100644
index 000000000..a9ff8fd3c
--- /dev/null
+++ b/src/client/spark/view/Controls/TickFactorsPicker/TickFactorsPicker.xaml.cs
@@ -0,0 +1,157 @@
+using mbts.spark;
+using mbts.spark.utilities;
+using mbts.ui.converters;
+using mbts.ui.shell;
+using mbts.ui.utility;
+using mbts.user.settings;
+using mbts.utils;
+using System;
+using System.Collections.Generic;
+using System.Collections.ObjectModel;
+using System.ComponentModel;
+using System.Linq;
+using System.Windows;
+using System.Windows.Controls;
+using System.Windows.Data;
+
+namespace mbts.ui.controls {
+ ///
+ /// Interaction logic for TickPicker.xaml
+ ///
+ class TickFactorsPicker : Control {
+ readonly ObservableCollection _tick_unit_presets = new ObservableCollection();
+
+ static TickFactorsPicker() =>
+ DefaultStyleKeyProperty.OverrideMetadata(typeof(TickFactorsPicker), new FrameworkPropertyMetadata(typeof(TickFactorsPicker)));
+
+ public TickFactorsPicker() {
+ Controller = new TickFactorsController(this);
+ TickBasePresetsView.GroupDescriptions.Add(new PropertyGroupDescription(nameof(TickBaseVM.reduced_base_group)));
+ ((ListCollectionView)TickBasePresetsView).CustomSort = TickUtils.CompareUtils.base_comparer.wrap(vm => vm.value).to_non_generic();
+ TickUnitPresetsView = CollectionViewSource.GetDefaultView(new ObservableAutoWrapper(_tick_unit_presets, v => new TickUnitVM(v)));
+ TickUnitPresetsView.GroupDescriptions.Add(new PropertyGroupDescription(nameof(TickUnitVM.reduced_unit_group)));
+ ((ListCollectionView)TickUnitPresetsView).CustomSort = Comparer.Default.wrap(vm => vm.value).to_non_generic();
+ }
+
+ public static IEnumerable TickBasePresets =>
+ new [] {
+ 8, 16, 32, 64, 100
+ }.SelectMany(i => Enumerable.Range(0, 4).Select(log10 => i * Math.Pow(10, log10)));
+
+ public static IMultiValueConverter TickUnitVisibleTextConverter =>
+ ValueConverter.create((double tick_base, double tick_unit) => {
+ int display_digits = TickExtensions.display_digits(tick_base);
+ return ((int)(tick_unit)).ToString(new string('0', display_digits));
+ });
+
+ public static IValueConverter TickUnitHiddenTextConverter =>
+ ValueConverter.create((double tick_unit) => new string(tick_unit.ToString().SkipWhile(c => c != '.').ToArray()));
+
+ public static readonly DependencyProperty SelectedTickFactorsProperty =
+ WPFHelper.create_dp(
+ nameof(SelectedTickFactors),
+ FrameworkPropertyMetadataOptions.BindsTwoWayByDefault,
+ (o, v) => o.Controller.load_from(v),
+ new TickFactors());
+
+ public TickFactors SelectedTickFactors {
+ get => GetValue(SelectedTickFactorsProperty) as TickFactors;
+ set => SetValue(SelectedTickFactorsProperty, value);
+ }
+
+ public TickFactorsController Controller { get; }
+
+ public ICollectionView TickBasePresetsView { get; } = CollectionViewSource.GetDefaultView(TickBasePresets.Select(v => new TickBaseVM(v)).ToList());
+ public ICollectionView TickUnitPresetsView { get; }
+
+ static IEnumerable _get_tick_unit_presets(double tick_base) {
+ double reduced_base = MathUtils.factor_out(tick_base, 10, out int base_log10);
+ return reduced_base == 1 ?
+ _get_dbased_tick_unit_presets(base_log10) :
+ _get_2based_tick_unit_presets((int)Math.Log(reduced_base, 2), base_log10);
+ }
+
+ static IEnumerable _get_2based_tick_unit_presets(int log2, int log10) =>
+ (log10 == 0 ? new[] { 1.0 } : _get_dbased_tick_unit_presets(log10)).Concat(
+ Enumerable.Range(1, log2 - 1).SelectMany(pow2 => {
+ double root = Math.Pow(2, pow2);
+ return Enumerable.Range(0, log10 + 1).Select(pow10 => root * Math.Pow(10, pow10));
+ }));
+
+ static IEnumerable _get_dbased_tick_unit_presets(int log10) =>
+ Enumerable.Range(0, log10).SelectMany(_coins);
+
+ static IEnumerable _coins(int pow10) {
+ double d = Math.Pow(10, pow10);
+ yield return d;
+ yield return 1.25 * d;
+ yield return 2.5 * d;
+ yield return 5.0 * d;
+ }
+
+ public class TickFactorsController : ViewModelBase, IValueFactoryVM {
+ readonly TickFactorsPicker _view;
+ readonly Property _tick_base, _tick_unit;
+
+ public TickFactorsController(TickFactorsPicker view) {
+ var init = (_view = view).SelectedTickFactors;
+ _tick_base = backing(nameof(tick_base), init.tick_base);
+ _tick_unit = backing(nameof(tick_unit), init.tick_unit);
+ }
+
+ public double tick_base {
+ get => _tick_base.Value;
+ set {
+ _tick_base.set(value);
+ WPFHelper.set_current_if_changed(_view, SelectedTickFactorsProperty, new TickFactors(value, tick_unit));
+ _view._tick_unit_presets.sync_with(_get_tick_unit_presets(value));
+ }
+ }
+ public double tick_unit {
+ get => _tick_unit.Value;
+ set {
+ _tick_unit.set(value);
+ WPFHelper.set_current_if_changed(_view, SelectedTickFactorsProperty, new TickFactors(tick_base, value));
+ }
+ }
+
+ public TickFactors create() => new TickFactors(tick_base, tick_unit);
+ public void load_from(TickFactors value) {
+ if (value != null) {
+ _tick_base.set(value.tick_base);
+ _tick_unit.set(value.tick_unit);
+ }
+ }
+ }
+
+ public class TickBaseVM : IEquatable {
+ public TickBaseVM(double value) =>
+ this.value = value;
+
+ public double value { get; }
+ public double reduced_base_group => MathUtils.factor_out(value, 10);
+
+ public bool Equals(TickBaseVM other) => other != null && value == other.value;
+ public override bool Equals(object obj) => Equals(obj as TickBaseVM);
+ public override int GetHashCode() => value.GetHashCode();
+ }
+
+ public class TickUnitVM : IEquatable {
+ public TickUnitVM(double value) =>
+ this.value = value;
+
+ public double value { get; }
+ public double reduced_unit_group {
+ get {
+ if (!MathUtils.is_int(value))
+ return 1;
+ else return MathUtils.factor_out(value, 10, 5);
+ }
+ }
+
+ public bool Equals(TickUnitVM other) => other != null && value == other.value;
+ public override bool Equals(object obj) => Equals(obj as TickUnitVM);
+ public override int GetHashCode() => value.GetHashCode();
+ }
+ }
+}
\ No newline at end of file
diff --git a/src/client/spark/view/Converters/AnonymousValueConverter.cs b/src/client/spark/view/Converters/AnonymousValueConverter.cs
index 28aab2c2c..5b7a396f5 100644
--- a/src/client/spark/view/Converters/AnonymousValueConverter.cs
+++ b/src/client/spark/view/Converters/AnonymousValueConverter.cs
@@ -2,8 +2,15 @@
using System.Globalization;
using System.Windows.Data;
-namespace mbts.ui.converters
-{
+namespace mbts.ui.converters {
+ static class ValueConverter {
+ public static IValueConverter create(Func convert) =>
+ new AnonymousValueConverter(convert);
+
+ public static IMultiValueConverter create(Func convert) =>
+ new AnonymousMultiValueConverter(convert);
+ }
+
public class AnonymousValueConverter : IValueConverter {
public AnonymousValueConverter(Func