Set editable but only scaling axis

Hi

Is it possible to set a pad non-editable but still being able to change the scale of a TGraph with the mouse?
Usually, when people try to change the scale of graphs they accidentally “hit” the graph with the mouse and move it around unwantedly.

Cheers,
delos

Hi,
TGraph & Co have:

void SetEditable(Bool_t editable = kTRUE) 

That should do what you want, accessible also from context menu.

Cheers
Otto

Yes, thank you. But when people are not very carful clicking around in the graph things like shown in the attached picture will happen.
Maybe an idea for future root versions to set only special features editable like only axis scaling but not moving.

Cheers,
delos


Hi Delos,

did you really try what I suggested?

TGraph *g = new TGraph(10);
...
ge->Draw("AL");
ge-SetEditable(kFALSE);  // <<<< set cant modify by mouse
...

For me with 6.06.00 this works, i.e. what you show cannot happen.
Or you can click with right mouse on the graph
and uncheck “SetEditable”

Otto

Hi Otto

Yes, I did and with SetEditable(kFALSE) nothing can be manipulated anymore. Though, I still would like to be able to zoom in or out (scale) the graph with the mouse so the user can magnify a region of interest but not accidantely move the graph around or manipulate data points.
I thought there could be something like TGraph->GetYaxis->SetEditable(kTRUE) which the would then only set the y-axis editable.

Cheers,
delos

Hi Delos,
I can still zoom / unzoom in the X and Y axis while the graph itself in not editable
See att.
Otto


Hi Otto

Really strange. I have the mouse cross but I cannot scale.
I will have to play around further.

Thanks,
delos

are you sure the canvas, more precise the pad in which your TGraph is displayed
is set “Editable true”? (right mouse outside frame)
Otto

Yes, but when it is editable the graph can be moved around when I click inside it and not the axis. This is what I want to avoid.

Cheers,
delos

Hi Otto

Do you have a running macro that I could try?

Regards,
delos

here it is,
Otto

#include "TCanvas.h"
#include "TGraph.h"
void tgraph()
{
	TCanvas *c =new TCanvas();
	TGraph * g = new TGraph(3);
	g->SetPoint(0, 1, 1);
	g->SetPoint(1, 2, 2);
	g->SetPoint(2, 3, 1);
	c->SetEditable(kTRUE);
	g->SetEditable(kFALSE);
	g->Draw("AL");
}

Hi Otto

Thank you very much.
Though, as you can see in the picture I can scale but also move the graph aroung and change its size. That’s what I want to avoid. Just scaling is neccessary. Everything else will confuse the users.

Cheers,
delos


Hi delos,
I guess I see your point now:
You agree that with the macro I sent the graph or its points cant be moved anymore?

However the frame can still be changed.
To avoid that the underlying boxes kCannotMove bit must be set:

#include "TCanvas.h"
#include "TGraph.h"
#include "TFrame.h"
void tgraph()
{
	TCanvas *c =new TCanvas();
	TGraph * g = new TGraph(3);
	g->SetPoint(0, 1, 1);
	g->SetPoint(1, 2, 2);
	g->SetPoint(2, 3, 1);
	c->SetEditable(kTRUE);
	g->SetEditable(kFALSE);
	g->Draw("AL");
	c->Modified();	// make sure canvas and graph are painted
	c->Update();		// before the following line of code
	c->GetFrame()->SetBit(TBox::kCannotMove);
}

Cheers
Otto

Hi Otto

This c->GetFrame()->SetBit(TBox::kCannotMove); looks interesting and I tried. Though, The graphs can still be moved. I must say that I still have to go through the complete code to make sure I invoke this command a the right position. I’ll keep you updated. The difference probably is that I use pads (TPad).

Cheers,
delos