Skip to content

Conversation

cobacdavid
Copy link
Contributor

@cobacdavid cobacdavid commented Feb 21, 2023

I propose this radial progress bar.

  • unlike other "Display" method, and due to its shape, positioning is done with center: xc and yc parameters. Postionnal parameters.
  • parameters value, min_value and max_value are kept from DisplayProgressBar method
  • background parameters are also kept
  • the radial bar is controlled with eight parameters:
    • radius parameter is the outer radius of the bar. Postionnal parameter.
    • bar_width the width of the bar (>0 and <radius). Postionnal parameters.
    • bar_color kept from DisplayProgressBar method
    • angle_start the start angle (0% of the value). Default is 0 (3 o'clock)
    • angle_end the end angle (100% of the value). Default is 360
    • clockwise a boolean specifying if the bar progresses clockwise (default: True) or counter-clockwise (False)
    • angle_steps the number of sectors (positive integer value) from angle_start to angle_end. Default is 10.
    • angle_sep (>0) the angle between two steps. Default is 5.
  • this bar embeds a text, default one is the percentage calculated with value, min_value and max_value (the value is simply normalized). This text can be controlled using five parameters:
    • text text to display. Default is None and percentage will be displayed
    • with_text a boolean to decide if a text will be displayed. Default is True
    • parameters font, font_color and font_size from DisplayProgressBar method are kept

Why does this radial progress bar embed a text?
Actually, fake transparency mechanism is used and it's hard to have a radial bar free from the text.

Can the bar change its color according to the value?
A library like colour offers a simple way to create a table of needed colors. In the following example, a colors table is created for 101 integer values (from 0 to 100) using Color function:

g_to_r = list(map(lambda t: tuple(int(t[i]*255) for i in range(3)),
                      map(lambda x: x.get_rgb(),
                          Color("green").range_to(Color("red"), 101))))

Further using DisplayRadialProgressBar method, we specify the color to use according to a variable, below temperature is used:

 lcd_comm.DisplayRadialProgressBar(100, 100, 30, 5,
                                          min_value=0,
                                          max_value=100,
                                          value=temperature,
                                          angle_start=20,
                                          angle_end=160,
                                          text=f"{temperature}°C",
                                          bar_color=colors[temperature],
                                          font_color=font_color,
                                          background_image=bg)

Can it display a discontinued line?
Not for the moment...

Examples

edit: formatting
edit2: simplified rules to specify angles
edit3: discontinued bar
edit4: positionnal parameters

@cobacdavid cobacdavid marked this pull request as draft February 22, 2023 08:35
@cobacdavid
Copy link
Contributor Author

Angles management is too complicated, I'm trying to change this.
I convert this to draft.

@cobacdavid
Copy link
Contributor Author

No more complicated rules on angles as they are standardized using modulo and tests.

@cobacdavid
Copy link
Contributor Author

I stay on "draft" stage: I'd like to change barwidth in bar_width and add an assert on this variable bar_width <= radius.
I'll do this later on this day.

@mathoudebine
Copy link
Owner

Thanks for the update, and sorry for the action bot commit, you can disable it on your repository if it's a problem, or work on a branch instead of main (since the bot only update previews on main branch)

@cobacdavid
Copy link
Contributor Author

Eventually I wrote discontinued bar possibility.
In the code I kept the separation with the solid bar case for display performance.
I change the stage to "ready for review".

@cobacdavid cobacdavid marked this pull request as ready for review February 22, 2023 13:37
@mathoudebine mathoudebine changed the base branch from main to feature/radial-progress-bar May 5, 2023 14:43
@mathoudebine mathoudebine merged commit 2cf052a into mathoudebine:feature/radial-progress-bar May 5, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants