Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Number formatting #288

Merged
merged 34 commits into from
Jul 24, 2024
Merged

Number formatting #288

merged 34 commits into from
Jul 24, 2024

Conversation

justinlaughlin
Copy link
Contributor

Addressing #260 by adding the ability to specify number formats for the colorbar and axes.

Keybind for colorbar is Alt+c and for axes is Alt+a. Once pressed, you can specify precision, format (default, fixed, or scientific), and whether the positive sign is always shown or not.

This PR also adds prompt() in aux_vis.hpp which is a more general function for requesting user input. A default value can be specified (I think implementation could be cleaner with std::optional) as well as a validator lambda.

ex9.saved defaults

image

ex9.saved using (1, 'f', true) for colorbar and (0, 'f', false) for axes.

Setting colorbar number formatting...
Enter precision (4):  1
Enter format [(d)efault, (f)ixed, (s)cientific] (d):  f
Show sign? [(1)true, (0)false] (0):  1
Setting axes number formatting...
Enter precision (4):  0
Enter format [(d)efault, (f)ixed, (s)cientific] (d):  f
Show sign? [(1)true, (0)false] (0):  0

image

@justinlaughlin
Copy link
Contributor Author

justinlaughlin commented Jul 15, 2024

Suggestion from gm: change the input from the terminal to the glvis window. e.g. by typing 5f1 to set precision=5, format type=float, and showpos=true.

@najlkin
Copy link
Contributor

najlkin commented Jul 15, 2024

@justinlaughlin , if you mean what I was saying, it was about streams. That could be done now 💨 . In console, I think it is ok to ask the user interactively, but you may support both 😉 . Like asking the user for the code, but when left empty (there should be a hint 😇 ), it will ask for the options interactively. In the window, it makes sense to me only when we add the popup window/overlay 🤔 .

@najlkin
Copy link
Contributor

najlkin commented Jul 15, 2024

besides that, I would prefer C-style formatting flags like in printf. 👍

@najlkin najlkin self-requested a review July 15, 2024 22:31
@v-dobrev
Copy link
Member

Suggestion from gm: change the input from the terminal to the glvis window. e.g. by typing 5f1 to set precision=5, format type=float, and showpos=true.

I think the prompts on the terminal are much better than expecting (even experts in GLVis) to remember what keys they need to press (after the initial key, which I assume is already documented in the output from pressing h) and also do it without any visual feedback.

@justinlaughlin
Copy link
Contributor Author

Thanks for the help explaining some of the glvis internals @v-dobrev! I added the option to change via stream and glvis script. NumberFormatter() also has an additional constructor for c-style strings @najlkin 👍. For inputs via stream/script that is the expected format, but when pressing alt+a / alt+c it will have the same behavior (prompts).

Comment on lines +164 to +165
- <kbd>Alt</kbd> + <kbd>a</kbd> – Set axes number format
- <kbd>Alt</kbd> + <kbd>c</kbd> – Set colorbar number format
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What does Alt mean on Mac? Is it option or command -- it will be good to clarify it here.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For what's it worth, we do use Alt already in https://github.com/glvis/glvis/?tab=readme-ov-file#advanced

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not able to test but I did see other places that used Alt like Tzanio mentioned. It'd probably be good to mention it somewhere at the top.

Copy link
Member

@v-dobrev v-dobrev left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I did not test it, but the changes look good to me.

lib/aux_vis.cpp Outdated Show resolved Hide resolved
@tzanio
Copy link
Member

tzanio commented Jul 22, 2024

@justinlaughlin, were you able to try #288 (comment)?

@v-dobrev, can you share your alternative fix?

@justinlaughlin
Copy link
Contributor Author

justinlaughlin commented Jul 22, 2024

I saw some specific handling for Ctrl in lib/sdl.cpp and when I added the same for Alt thing started working for me.

Here is the patch:

@v-dobrev and @justinlaughlin -- can you confirm this works on both Mac and Linux?

If we indeed need these changes, how can we get away without them before?

@tzanio
For me on linux, this causes an additional trigger of a after terminal input is done. Meaning the axes get toggled. e.g.

Event: SDL_KEYDOWN sym=1073742050 mod=4352
Event: SDL_KEYDOWN sym=97 mod=4352
Setting axes number formatting...
Enter precision (4):  4
Enter format [(d)efault, (f)ixed, (s)cientific] (d):  f
Show sign? [(1)true, (0)false] (0):  1
Event: SDL_TEXTINPUT text[0..3]=97 0 0 0 (as codes 0-255)
Toggling axes
Event: SDL_KEYUP sym=97 mod=4352
Event: SDL_KEYUP sym=1073742050 mod=4096

It looks like SDL_TEXTINPUT is what is making the additional call (keyEvent(e.text.text[0]);) but I'm not sure yet how to fix it.

SDL event loop. Added some comments to clarify behavior.
@v-dobrev
Copy link
Member

@justinlaughlin, @tzanio, I created a PR (#294) towards this PR with my proposed changes in the key events handling. Take a look and try it.

@justinlaughlin
Copy link
Contributor Author

@justinlaughlin, @tzanio, I created a PR (#294) towards this PR with my proposed changes in the key events handling. Take a look and try it.

Excellent! I just tried this and it is working.

@tzanio
Copy link
Member

tzanio commented Jul 22, 2024

@justinlaughlin, @tzanio, I created a PR (#294) towards this PR with my proposed changes in the key events handling. Take a look and try it.

Thanks @v-dobrev, I can confirm #294 works on Mac too!

@tzanio
Copy link
Member

tzanio commented Jul 23, 2024

@v-dobrev, should we mention the sld.?pp changes in CHANGELOG?

@v-dobrev
Copy link
Member

@v-dobrev, should we mention the sld.?pp changes in CHANGELOG?

It is something internal, so I'm not sure it is important to mention it there.

@v-dobrev
Copy link
Member

This PR need a new baseline screenshot for one test -- stream_mesh-explorer. This change will be independent of the baseline changes for #285, as prepared in GLVis/data#3. We should:

  1. prepare an update for https://github.com/GLVis/data,
  2. test it here (update the submodule hash),
  3. when the tests are fixed, merge the update for https://github.com/GLVis/data
  4. update the submodule hash with the merged hash of https://github.com/GLVis/data
  5. merge this PR.

Does this sound ok?

v-dobrev added a commit to GLVis/data that referenced this pull request Jul 23, 2024
   GLVis/glvis#288
that correctly interprets digit keys in input key sequences.
@v-dobrev
Copy link
Member

I did 1 and 2 from the above list. Waiting on tests to see if there are any issues.

@tzanio
Copy link
Member

tzanio commented Jul 23, 2024

Does this sound ok?

Yes

@justinlaughlin
Copy link
Contributor Author

Tests pass :). Can we merge? It'd probably be simpler to merge this prior to merging #285 since that PR has different baselines.

@tzanio
Copy link
Member

tzanio commented Jul 23, 2024

Go ahead and merge @justinlaughlin.

@justinlaughlin
Copy link
Contributor Author

Go ahead and merge @justinlaughlin.

I don't have the power to 😅

@tzanio
Copy link
Member

tzanio commented Jul 24, 2024

Go ahead and merge @justinlaughlin.

I don't have the power to 😅

try again

@justinlaughlin justinlaughlin merged commit 23fccee into master Jul 24, 2024
10 checks passed
@justinlaughlin justinlaughlin deleted the number-formatting branch July 24, 2024 16:19
@najlkin
Copy link
Contributor

najlkin commented Jul 25, 2024

@justinlaughlin , the merge does not pass on master through make style check! 😱 I do not know why PR CI does not have those checks, but this must be fixed asap as it is failing in autotests!

justinlaughlin pushed a commit that referenced this pull request Jul 25, 2024
tzanio added a commit that referenced this pull request Jul 25, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants