TPad & TGraph Zoomable with Mouse but kNotEditable set to kTRUE?

If you search the ROOT Forum archives for “SetEditable” you will find many old posts complaining that with a TGraph by default, you can move the data points around with the mouse. Indeed it’s very easy to do so without realizing this (and I’ve just wasted 1.5 hours rediscovering this). You can prevent this by using TGraph::SetEditable(kFALSE) (which sets a member variable kNotEditable to kTRUE), but this also disables the ability to zoom the graph axes with the mouse. The view of the data should be modifiable with the mouse, but the data itself should not!

These issues were reported over a decade ago and this problem still persists. Do any regular users have tricks for not accidentally changing your data when mousing, and do any ROOT team members have an update on making this behave more reasonably?


The help of TGraph::SetEditable says:

if editable=kFALSE, the graph cannot be modified with the mouse by default a TGraph is editable

So I guess if that is false it should behaves as said but still allows le zooming (zooming is not a modification) I will check.

I just did a test with the following macro. The points cannot be moved but axis can be zoom. I am using the latest ROOT on Mac.

   TCanvas *c = new TCanvas("c","A Simple Graph without axis",700,500);
   const Int_t n = 10;
   TGraph *gr = new TGraph(n);
   gr->SetTitle("A Simple Graph Example");
   gr->GetXaxis()->SetTitle("X axis");
   Double_t x, y;
   for (Int_t i=0;i<n;i++) {
      x = i*0.123;
      y = 10*sin(x+0.2);

Oh dear I hadn’t actually tested that myself, I believed what I read in those old reports. You are right, setting SetEditable(kFALSE) disables moving data points around but you can still zoom with the mouse. My apologies.

Is there a global/default setting for TGraph and TPad kNotEditable? I would love to put this in my startup scripts so I never have to worry about it again.

Not as far as I know. But I will check. that would be a good improvements if not.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.