@@ -50,7 +50,8 @@ RenderArea::RenderArea(QWidget* parent) :
5050 clipped{ false },
5151 x_min{ 0.0 }, x_max{ 0.0 },
5252 a_x{}, b_x{}, a_y{}, b_y{}, numtraces{ 10 },
53- do_autoscale_on_load{ true }, isTraceDragging{ false }, isPinching{false },
53+ do_autoscale_on_load{ true }, global_autoscale{false },
54+ isTraceDragging{ false }, isPinching{false },
5455 isSelecting{ false }, selStart{}, selEnd{}, tempPixMap{ nullptr },
5556 settings_modified{ false }
5657{
@@ -565,18 +566,51 @@ static void find_min_max(std::vector<double>::const_iterator first,
565566void RenderArea::autoScale ()
566567{
567568 if (noData ()) return ;
568- if (isXYmode ()) {
569- find_min_max (xTrace.data .cbegin (), xTrace.data .cend (), x_min, x_max);
569+
570+ double g_x_min{std::numeric_limits<double >::max ()},
571+ g_x_max{std::numeric_limits<double >::min ()},
572+ g_y_min{std::numeric_limits<double >::max ()},
573+ g_y_max{std::numeric_limits<double >::min ()};
574+ // first find min/max for x
575+ if (isXYmode ()){
576+ find_min_max (xTrace.data .cbegin (), xTrace.data .cend (), g_x_min, g_x_max);
570577 }
571578 else if (yTrace.has_x_trace ()) {
572- find_min_max (yTrace.p_xdata ->cbegin (), yTrace.p_xdata ->cend (), x_min, x_max );
579+ find_min_max (yTrace.p_xdata ->cbegin (), yTrace.p_xdata ->cend (), g_x_min, g_x_max );
573580 }
574581 else
575582 {
576- x_min = yTrace.x0 ;
577- x_max = yTrace.x0 + static_cast <double >(yTrace.data .size () - 1 ) * yTrace.deltax ;
583+ g_x_min = yTrace.x0 ;
584+ g_x_max = yTrace.x0 + static_cast <double >(yTrace.data .size () - 1 ) * yTrace.deltax ;
585+ }
586+ if (global_autoscale){
587+ for (const auto * t: tracebuffer){
588+ if (t->has_x_trace ()){
589+ double minx, maxx;
590+ find_min_max (t->p_xdata ->cbegin (), t->p_xdata ->cend (), minx, maxx);
591+ g_x_min=std::min (g_x_min,minx);
592+ g_x_max=std::max (g_x_max, maxx);
593+ }
594+ }
595+ }
596+ x_min=g_x_min;
597+ x_max=g_x_max;
598+
599+
600+ // find_min_max(yTrace.data.cbegin(), yTrace.data.cend(), currentYscale->y_min, currentYscale->y_max);
601+ find_min_max (yTrace.data .cbegin (), yTrace.data .cend (), g_y_min, g_y_max);
602+ if (global_autoscale){
603+ for (const auto * t: tracebuffer){
604+ // only touch scaling for curent y-unit
605+ if (t->y_unit !=yTrace.y_unit ) continue ;
606+ double miny, maxy;
607+ find_min_max (t->data .cbegin (), t->data .cend (), miny, maxy);
608+ g_y_min=std::min (g_y_min,miny);
609+ g_y_max=std::max (g_y_max, maxy);
610+ }
578611 }
579- find_min_max (yTrace.data .cbegin (), yTrace.data .cend (), currentYscale->y_min , currentYscale->y_max );
612+ currentYscale->y_min =g_y_min;
613+ currentYscale->y_max =g_y_max;
580614 update ();
581615}
582616
@@ -655,11 +689,13 @@ void RenderArea::copyToClipboard()
655689void RenderArea::showSettingsDialog ()
656690{
657691 DlgGraphSettings dlg (this );
658- dlg.setValues (do_autoscale_on_load, x_min, x_max, currentYscale->y_min , currentYscale->y_max , numtraces,
692+ dlg.setValues (do_autoscale_on_load, global_autoscale,
693+ x_min, x_max, currentYscale->y_min , currentYscale->y_max , numtraces,
659694 show_grid_horz, show_grid_vert, shift_all_y_scales, color_grid, color_trace, color_bktrace);
660695 if (dlg.exec ()) {
661696 settings_modified = true ;
662- dlg.getValues (do_autoscale_on_load, x_min, x_max, currentYscale->y_min , currentYscale->y_max , numtraces,
697+ dlg.getValues (do_autoscale_on_load, global_autoscale,
698+ x_min, x_max, currentYscale->y_min , currentYscale->y_max , numtraces,
663699 show_grid_horz, show_grid_vert, shift_all_y_scales, color_grid, color_trace, color_bktrace);
664700 // if numtraces has been reduced we want to get rid of excess traces
665701 while (tracebuffer.size () > numtraces) {
@@ -845,7 +881,8 @@ void RenderArea::loadSettings()
845881{
846882 QSettings s;
847883 s.beginGroup (" renderarea" );
848- do_autoscale_on_load = s.value (" do_autoscale_on_load" , int (do_autoscale_on_load)).toInt ();
884+ do_autoscale_on_load = s.value (" do_autoscale_on_load" , do_autoscale_on_load).toBool ();
885+ global_autoscale = s.value (" global_autoscale" , global_autoscale).toBool ();
849886 shift_all_y_scales = s.value (" shift_all_y_scales" , int (shift_all_y_scales)).toInt ();
850887 show_grid_horz = s.value (" show_grid_horz" , int (show_grid_horz)).toInt ();
851888 show_grid_vert = s.value (" show_grid_vert" , int (show_grid_vert)).toInt ();
@@ -863,7 +900,8 @@ void RenderArea::saveSettings()
863900{
864901 QSettings s;
865902 s.beginGroup (" renderarea" );
866- s.setValue (" do_autoscale_on_load" , int (do_autoscale_on_load));
903+ s.setValue (" do_autoscale_on_load" , do_autoscale_on_load);
904+ s.setValue (" global_autoscale" , global_autoscale);
867905 s.setValue (" shift_all_y_scales" , int (shift_all_y_scales));
868906 s.setValue (" show_grid_horz" , int (show_grid_horz));
869907 s.setValue (" show_grid_vert" , int (show_grid_vert));
0 commit comments