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

clean up some drawing code, consolidate time graph components #710

Merged
merged 3 commits into from
Apr 29, 2022

Conversation

ClementTsang
Copy link
Owner

@ClementTsang ClementTsang commented Apr 27, 2022

Description

A description of the change and what it does. If relevant (such as any change that modifies the UI), please provide screenshots of the change:

Cleans up some drawing code and unifies all time graph drawing.

Issue

If applicable, what issue does this address?

Closes: #

Testing

If relevant, please state how this was tested. All changes must be tested to work:

Please also indicate which platforms were tested. All platforms directly affected by the change must be tested:

  • Windows
  • macOS
  • Linux

Checklist

If relevant, ensure the following have been met:

  • Areas your change affects have been linted using rustfmt (cargo fmt)
  • The change has been tested and doesn't appear to cause any unintended breakage
  • Documentation has been added/updated if needed (README.md, help menu, etc.)
  • The pull request passes the provided CI pipeline
  • There are no merge conflicts

@ClementTsang ClementTsang force-pushed the consolidate_component_drawing branch 3 times, most recently from 73a4f04 to 63096aa Compare April 27, 2022 23:34
@codecov-commenter
Copy link

codecov-commenter commented Apr 27, 2022

Codecov Report

Merging #710 (f72fd9d) into master (b9a356f) will increase coverage by 3.71%.
The diff coverage is 41.63%.

@@            Coverage Diff             @@
##           master     #710      +/-   ##
==========================================
+ Coverage   17.14%   20.85%   +3.71%     
==========================================
  Files          52       53       +1     
  Lines       13215    13630     +415     
==========================================
+ Hits         2266     2843     +577     
+ Misses      10949    10787     -162     
Impacted Files Coverage Δ
src/app.rs 0.04% <0.00%> (+<0.01%) ⬆️
src/canvas.rs 16.50% <0.00%> (+0.03%) ⬆️
src/canvas/dialogs/dd_dialog.rs 0.00% <ø> (ø)
src/canvas/dialogs/help_dialog.rs 0.00% <0.00%> (ø)
src/canvas/widgets/basic_table_arrows.rs 0.00% <ø> (ø)
src/canvas/widgets/battery_display.rs 0.00% <0.00%> (ø)
src/canvas/widgets/cpu_basic.rs 0.00% <0.00%> (ø)
src/canvas/widgets/cpu_graph.rs 0.00% <0.00%> (ø)
src/canvas/widgets/disk_table.rs 0.00% <0.00%> (ø)
src/canvas/widgets/mem_basic.rs 0.00% <0.00%> (ø)
... and 15 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update b9a356f...f72fd9d. Read the comment docs.

@ClementTsang ClementTsang force-pushed the consolidate_component_drawing branch 2 times, most recently from a8a32da to db89cad Compare April 28, 2022 04:24
@ClementTsang ClementTsang marked this pull request as ready for review April 28, 2022 04:25
When I was newer to Rust, I got the weird impression that you couldn't
add functionality to a struct outside of the defining file without using
a trait.

That's obviously not true, so it's high time I got rid of it and just
made it part of the impl of the class itself, rather than declaring a
trait and then exporting/importing it.
This code was never used and might as well be removed for clarity's
sake.
@ClementTsang ClementTsang force-pushed the consolidate_component_drawing branch 4 times, most recently from 9850810 to f72fd9d Compare April 29, 2022 03:26
This consolidates all the time graph drawing to one main location, as well
as some small improvements. This is helpful in that I don't have to
reimplement the same thing across three locations if I have to make one
change that in theory should affect them all. In particular, the CPU
graph, memory graph, and network graph are all now using the same,
generic implementation for drawing, which we call (for now) a component.

Note this only affects drawing - it accepts some parameters affecting style
and labels, as well as data points, and draw similarly to how it used to
before. Widget-specific actions, or things affecting widget state,
should all be handled by the widget-specific code instead. For example,
our current implementation of x-axis autohide is still controlled by the
widget, not the component, even if some of the code is shared. Components
are, again, only responsible for drawing (at least for now). For that
matter, the graph component does not have mutable access to any form of
state outside of tui-rs' `Frame`. Note this *might* change in the
future, where we might give the component state.

Note that while functionally, the graph behaviour for now is basically
the same, a few changes were made internally other than the move to
components. The big change is that rather than using tui-rs' `Chart`
for the underlying drawing, we now use a tweaked custom `TimeChart`
tui-rs widget, which also handles all interpolation steps and some extra
customization. Personally, I don't like having to deviate from the
library's implementation, but this gives us more flexibility and allows
greater control. For example, this allows me to move away from the old
hacks required to do interpolation (where I had to mutate the existing
list to avoid having to reallocate an extra vector just to insert one
extra interpolated point). I can also finally allow customizable
legends (which will be added in the future).
@ClementTsang ClementTsang merged commit cddee9d into master Apr 29, 2022
@ClementTsang ClementTsang deleted the consolidate_component_drawing branch April 29, 2022 05:12
@ClementTsang ClementTsang mentioned this pull request May 15, 2022
15 tasks
ClementTsang added a commit that referenced this pull request May 17, 2022
This serves as somewhat of an intermediary refactor to unify some scrollable table code - in particular, in regards to drawing. This is almost a parallel refactor as #710, which did something similar for time graphs. However, this one has a bit more work in regards to the concepts of component state, in particular, for width calculation caching and scroll position management.
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.

None yet

2 participants