cancel
Showing results for 
Search instead for 
Did you mean: 

Graph.indexToScreenX() inaccurate after changing histogram bar width

franck23
Senior

Hi,

Not a question, but a bug report.

Setup:

TouchGFX 4.21.1

Simulation on VS2022

It seems that the internal variable holding the histogram bar position is not updated when the bar width is changed at execution time.

Example:

1- The bar width is set to 100 at design time.

2- During execution, we move a red vertical line at the position returned by Graph.indexToScreenX(1). The position returned by Graph.indexToScreenX(1) is 204.

// Original bar width = 100.
testPosX = Graph.indexToScreenX(1);		// testPosX = 204
line1.moveTo(Graph.getX() + Graph.indexToScreenX(1), line1.getY());
line1.invalidate();

0693W00000aJrV4QAK.png 

3- Bar width is changed to 50

4- We move the red vertical line at the position returned by Graph.indexToScreenX(1).

But Graph.indexToScreenX(1) still returns 204.

// New bar width = 50;
GraphHistogram1.setBarWidth(50);
testPosX = Graph.indexToScreenX(1);			// testPosX = 204
line1.moveTo(Graph.getX() + Graph.indexToScreenX(1), line1.getY());
line1.invalidate();

0693W00000aJrasQAC.png 

We can of course workaround this problem by saving the design time bar width and using it to calculate the real bar coordinate:

int realX = Graph.getX() + Graph.indexToScreenX(1) + (DesignedBarWidth - GraphHistogram1.getBarWidth()) / 2;

Secondly, there is a problem with Graph.indexToScreenX(x) returning a coordinate referenced to the graph, and not to the screen as you would expect.

The real screen coordinate is given Graph.getX() + Graph.indexToScreenX(x).

Maybe Graph.indexToScreenX(x) should be re-named Graph.indexToGraphX(x) and the description should be changed.

I hope it helps others.

3 REPLIES 3
Yoann KLEIN
ST Employee

Hello again @Community member​,

Thanks for the report.

Is it possible for you to share your project here? So I can show the issues to my colleagues quickly?

Thanks,

/Yoann

Yoann KLEIN
ST Software Developer | TouchGFX
franck23
Senior

I'll find some time to make a small demo and I'll share it here.

Thanks.

franck23
Senior

Hi @Yoann KLEIN​ ,

I was building the small demo when I realized that the issue is not what I thought.

It's not that there is a problem with the X position of the bar not being internally updated.

The problem is that the function Graph.indexToScreenX() does not take into account the Graph Location on the screen AND the Graph Area Margin.

However, for some reason, it does take into account the Graph Area Padding...

It doesn't make much sense to me.

We would expect the Graph.indexToScreenX() to return the position of a histogram bar referenced to the screen.

The indexToScreenX() function should be updated or its name and online description be changed to avoid confusion.

Anyway, as it is now, to get a bar position referenced to the screen we need to add the graph X position and the left margin:

PosBar2 = Graph.indexToScreenX(1) + Graph.getX() + Graph.getGraphAreaMarginLeft();

I have attached a working demo, using the code above.

Thanks.