Fit axes to series on vs graph double click
This commit is contained in:
1 parent
98f3c5c433
commit
f8813bda36
2 files changed
+49
-2
No files matched your search
@@ -420,7 +420,8 @@
|
||||
x:Name="vol_curve_plot_view"
|
||||
Grid.Row="2"
|
||||
Grid.ColumnSpan="3"
|
||||
Model="{Binding graph_vm.plot_model}" />
|
||||
Model="{Binding graph_vm.plot_model}"
|
||||
MouseDoubleClick="_on_graph_mouse_double_click" />
|
||||
|
||||
</Grid>
|
||||
</TabItem>
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
namespace mbts.ui.shell {
|
||||
namespace mbts.ui.shell {
|
||||
using bts.utils;
|
||||
|
||||
using mbts.spark;
|
||||
@@ -47,6 +47,46 @@ namespace mbts.ui.shell {
|
||||
}
|
||||
#endregion
|
||||
|
||||
public void fit_axes_to_series() {
|
||||
if (_vol_curve_graph_vm?.axes?.Count != 2) {
|
||||
return;
|
||||
}
|
||||
|
||||
var vis_series = _vol_curve_graph_vm.flat_visible_series.Where(s => s.points.Any()).ToList();
|
||||
if (!vis_series.Any()) {
|
||||
return;
|
||||
}
|
||||
|
||||
Type tx = vis_series.Select(s => s.points.First().x.GetType()).Distinct().SingleOrDefault();
|
||||
if (tx != typeof(double)) {
|
||||
return;
|
||||
}
|
||||
Type ty = vis_series.Select(s => s.points.First().y.GetType()).Distinct().SingleOrDefault();
|
||||
if (ty != typeof(double)) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (_vol_curve_graph_vm.axes.TryGetFirst(a => a.position.is_horizontal(), out var x_axis) &&
|
||||
_vol_curve_graph_vm.axes.TryGetFirst(a => a.position.is_vertical(), out var y_axis)) {
|
||||
var points = vis_series.SelectMany(vs => vs.points);
|
||||
var x_points = points.Select(p => (double)p.x);
|
||||
if (x_points.Except(double.NaN).MinMax(out var x_min, out var x_max) && x_min < x_max) {
|
||||
double padding = (x_max - x_min) * 0.05;
|
||||
x_axis.minimum = x_min - padding;
|
||||
x_axis.maximum = x_max + padding;
|
||||
}
|
||||
|
||||
var y_points = points.Select(p => (double)p.y);
|
||||
if (y_points.Except(double.NaN).MinMax(out var y_min, out var y_max) && y_min < y_max) {
|
||||
double padding = (y_max - y_min) * 0.05;
|
||||
y_axis.minimum = y_min - padding;
|
||||
y_axis.maximum = y_max + padding;
|
||||
}
|
||||
}
|
||||
|
||||
_vol_curve_graph_vm?.reset_all_axes();
|
||||
}
|
||||
|
||||
void _on_is_legend_visible_changed(bool value) {
|
||||
Disposable.dispose(ref _legend_popup);
|
||||
if (!value) {
|
||||
@@ -77,6 +117,12 @@ namespace mbts.ui.shell {
|
||||
_legend_popup = Disposable.Create(() => popup_adorner.detach());
|
||||
}
|
||||
|
||||
void _on_graph_mouse_double_click(object sender, MouseButtonEventArgs e) {
|
||||
fit_axes_to_series();
|
||||
vol_curve_plot_view.InvalidatePlot();
|
||||
e.Handled = true;
|
||||
}
|
||||
|
||||
private void vol_time_popup_button_Loaded(object sender, RoutedEventArgs e) {
|
||||
// don't initialize more than once
|
||||
if (_time_editor_popup != null) return;
|
||||
|
||||
Reference in new issue
Block a user