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

"Positive/negative" graph meter style #1415

Draft
wants to merge 14 commits into
base: main
Choose a base branch
from

Conversation

Explorer09
Copy link
Contributor

This is a proof of concept of the graph style as discussed in #1390. I post this so that people can try it and see how it looks.

Notice this code is based on #714 -- the first few commit are the same, while the last one is the real modification of the new graph style.

@Explorer09 Explorer09 force-pushed the graph-with-neg branch 3 times, most recently from f47a975 to 745f394 Compare March 28, 2024 13:54
@BenBE BenBE added the new feature Completely new feature label Apr 13, 2024
@Explorer09 Explorer09 force-pushed the graph-with-neg branch 3 times, most recently from 31cb513 to bedca8f Compare April 21, 2024 06:39
@Explorer09 Explorer09 force-pushed the graph-with-neg branch 4 times, most recently from ade4922 to 54d3d1c Compare April 26, 2024 18:59
@Explorer09 Explorer09 force-pushed the graph-with-neg branch 3 times, most recently from 728ef87 to 3033b1d Compare May 2, 2024 21:01
@BenBE BenBE self-assigned this May 2, 2024
@Explorer09 Explorer09 force-pushed the graph-with-neg branch 2 times, most recently from aa96aa4 to 10bb617 Compare May 22, 2024 19:03
This suppresses a "-Wshorten-64-to-32" warning in Clang 19.
This property distinguishes meters that have a (relatively) fixed
"total" value and meters that do not have a definite maximum value.
The former meters would be drawn as a "100% stacked bar" or "graph", and
the latter could have their "total" values updated automatically in bar
meter mode.

This commit is a prerequisite for the feature "Graph meter dynamic
scaling and percent graph drawing".

Signed-off-by: Kang-Che Sung <[email protected]>
If "isPercentChart" of a meter is false, update its "total" value
automatically in the bar meter mode. The "total" value is capped to
DBL_MAX in order to ensure the division never produces NaN.

The newly introduced Meter_computeSum() function will be reused by the
feature "Graph meter dynamic scaling and percent graph drawing".

Signed-off-by: Kang-Che Sung <[email protected]>
Implement dynamic scaling for Graph meter mode, and separate it from
"100% graph" drawing. This is controlled by the "isPercentChart"
property of a MeterClass.

If "isPercentChart" is true, the meter would be drawn as a
"100% graph". Graph meters now expect the "total" value may change, and
the newly changed "total" value no longer affects the percent graph
drawings of earlier meter values.

If "isPercentChart" is false, the meter would be drawn with a dynamic
scale.

Signed-off-by: Kang-Che Sung <[email protected]>
Round the graph meter's dynamic scale to a power of two and print the
graph scale. For a percent graph, a "%" character is printed in place
of the scale.

Signed-off-by: Kang-Che Sung <[email protected]>
This is a code quality change that avoids dependency on the hard-coded
GRAPH_HEIGHT in GraphMeterMode_draw().

This doesn't enable variable graph heights per meter, but it makes room
for implementing such feature.

Signed-off-by: Kang-Che Sung <[email protected]>
This is a prerequisite for the feature "Graph meter coloring (with
GraphData structure rework)".

powerOf2Floor() will utilize __builtin_clz() or stdc_bit_floor_ui()
(__builtin_clz() is preferred) if either is supported.

popCount8() will utilize ARM NEON instructions and x86 POPCNT
instruction if the machine supports either of them.

I am not adopting the C23 standard interface stdc_count_ones_uc() yet,
as I am not sure C libraries would implement it as fast as our version.

Signed-off-by: Kang-Che Sung <[email protected]>
Rewrite the entire graph meter drawing code to support color graph
drawing in addition to the dynamic scaling (both can work together
because of the new GraphData structure design).

The colors of a graph are based on the percentages of item values of
the meter. The rounding differences of each terminal character are
addressed through the different numbers of braille dots.

Due to low resolution of the character terminal, the rasterized colors
may not look nice, but better than nothing. :)

The new GraphData structure design has two technical limitations:
* The height of a graph meter now has a limit of 8191 (terminal rows).
* If dynamic scaling is used, the "total" value or scale of a graph now
  has to align to a power of 2.

The code is designed with the anticipation that the graph height may
change at runtime. No UI or option has been implemented for that yet.

Signed-off-by: Kang-Che Sung <[email protected]>
Specifically 'PIXPERROW_*' and 'GraphMeterMode_dots*' constants.
They were commented out rather than removed in the previous commit (for
ease of code reviewing). Now this commit removes the constant defines
for good.
This special case of "details" value would print as ':' in the ASCII
display mode. It is used in "positive/negative" graph display only.

Signed-off-by: Kang-Che Sung <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
new feature Completely new feature
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants