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

Started working updating vsl.plot #181

Merged
merged 4 commits into from
Oct 22, 2023
Merged

Started working updating vsl.plot #181

merged 4 commits into from
Oct 22, 2023

Conversation

ulises-jeremias
Copy link
Member

@ulises-jeremias ulises-jeremias commented Oct 21, 2023

Summary by CodeRabbit

  • Refactor: Simplified code in plot_scatter, plot_scatter3d_1, and plot_scatter_colorscale examples by removing unnecessary mapping operations, improving code readability.
  • New Feature: Introduced PlotConfig and PlotlyScriptConfig in plot/show.v to provide more configuration options for Plotly plots, enhancing customization.
  • New Feature: Added get_plotly_script function in plot/show.v to generate plot scripts as HTML tags, enabling easier integration with web pages.
  • Refactor: Updated Layout struct in plot/layout.v to improve plot layout configuration, enhancing the visual appeal of plots.
  • Refactor: Enhanced Annotation struct in plot/annotation.v to require certain fields, ensuring more consistent annotations.
  • New Feature: Extended XType, YType, and ZType in plot/trace.v to accept arrays of integers, broadening data type compatibility.

@coderabbitai
Copy link

coderabbitai bot commented Oct 21, 2023

Walkthrough

The changes primarily focus on simplifying the code and enhancing the functionality of the plot module. The modifications include the removal of unnecessary mapping operations, the addition of new structs for plot configuration, and the enhancement of existing structs to improve plot layout and annotation.

Changes

File(s) Summary
examples/plot_heatmap_golden_ratio/main.v Wrapped code in main function, removed commented-out code, and made minor adjustments to function calls.
examples/plot_scatter/main.v, examples/plot_scatter3d_1/main.v, examples/plot_scatter_colorscale/main.v Simplified code by removing unnecessary map function calls and directly assigning results to variables.
examples/plot_scatter_with_annotations/main.v Added a new module with a main function for plotting a scatter plot with annotations.
plot/annotation.v Made changes to the Annotation struct, making some fields required and others optional.
plot/layout.v Modified the Layout struct, changing default values and field types.
plot/show.v Added new structs for plot configuration, a function for generating plot script, and modified existing functions and structs to use these new additions.
plot/trace.v Enhanced XType, YType, and ZType types to accept arrays of integers.

🐇

"In the land of code, where the shadows lie,

A rabbit hopped, with a twinkle in its eye.

With every hop, a change was made,

Simplifying code, enhancing the grade.

Now the plots are neat, and the code is clean,

Thanks to the rabbit, the coding machine!" 🎉


Tips

Chat with CodeRabbit Bot (@coderabbitai)

  • If you reply to a review comment from CodeRabbit, the bot will automatically respond.
  • To engage with CodeRabbit bot directly around the specific lines of code in the PR, mention @coderabbitai in your review comment
  • Note: Review comments are made on code diffs or files, not on the PR overview.
  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Commands (invoked as PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger a review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai help to get help.

Note: For conversation with the bot, please use the review comments on code diffs or files.

@ulises-jeremias ulises-jeremias marked this pull request as ready for review October 22, 2023 12:41
@ulises-jeremias ulises-jeremias merged commit 1ee1419 into main Oct 22, 2023
11 checks passed
@ulises-jeremias ulises-jeremias deleted the feature/plot_html branch October 22, 2023 12:41
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Review Status

Actionable comments generated: 3

Commits Files that changed from the base of the PR and between 0279180 and 9a5bf05.
Files ignored due to filter (1)
  • plot/static/plotly-2.26.2.min.js
Files selected for processing (9)
  • examples/plot_heatmap_golden_ratio/main.v (1 hunks)
  • examples/plot_scatter/main.v (1 hunks)
  • examples/plot_scatter3d_1/main.v (1 hunks)
  • examples/plot_scatter_colorscale/main.v (1 hunks)
  • examples/plot_scatter_with_annotations/main.v (1 hunks)
  • plot/annotation.v (1 hunks)
  • plot/layout.v (1 hunks)
  • plot/show.v (1 hunks)
  • plot/trace.v (1 hunks)
Files skipped from review due to trivial changes (3)
  • examples/plot_scatter/main.v
  • examples/plot_scatter_colorscale/main.v
  • plot/trace.v
Additional comments (Suppressed): 14
examples/plot_scatter_with_annotations/main.v (1)
  • 6-43: The changes in this hunk look good. The code is now encapsulated within a main function, which is a good practice for readability and maintainability. The x range is now directly assigned using util.arange(y.len), which simplifies the code. The scatter function call and the layout function call have been updated to match the new struct definitions. The show function call is now properly error-handled with the ! operator.
examples/plot_scatter3d_1/main.v (1)
  • 22-22: The new hunk has removed the .map(f64(it)) operation on x. This operation was converting the range of integers to a range of floats. If the scatter3d function or any other function that uses x expects a float array, this could cause type mismatch errors. Please verify if this change is intentional and compatible with the rest of the codebase.
- x := util.arange(y.len)
+ x := util.arange(y.len).map(f64(it))
plot/annotation.v (3)
  • 6-7: The x and y fields are now optional with the omitempty attribute. Ensure that the rest of the codebase can handle these fields being potentially empty, and that it doesn't lead to any runtime errors or unexpected behavior.

  • 8-8: The text field is now required. Make sure that all instances of Annotation in the codebase are updated to include this field to avoid any runtime errors.

  • 9-9: The showarrow field is no longer optional. If there are instances in the codebase where this field was not provided, they will need to be updated.

plot/layout.v (2)
  • 7-8: The title_x and autosize fields no longer have default values. This could potentially break existing code that relies on these defaults. Please ensure that all instances where Layout is used have been updated to explicitly set these fields if needed.

  • 9-9: The width field now defaults to 550. This is a change from the previous version where no default was set. This change should not cause any issues, but it's worth verifying that this new default value is appropriate in all contexts where Layout is used.

examples/plot_heatmap_golden_ratio/main.v (2)
  • 7-40: The new hunk has encapsulated the existing code into a main function, which is a good practice for structuring the code. However, the commented lines for drawing a spiral are still present and marked as a TODO. If this functionality is not intended to be implemented in the near future, consider removing these comments to avoid confusion.

  • 26-39: The heatmap and layout methods are called on the plt instance to create a heatmap plot and set its properties, respectively. The show method is then called to display the plot. Ensure that these methods are compatible with the changes made to the vsl.plot module in this PR.

plot/show.v (5)
  • 16-37: The show function now accepts a PlotConfig parameter, which is used to configure the plot. Ensure that all calls to this function throughout the codebase have been updated to pass this parameter.

  • 49-93: The get_plotly_script function generates the plot script as an HTML tag. This is a good practice as it separates the generation of the plot script from the rest of the HTML content, improving modularity and maintainability of the code.

  • 95-110: The get_html function now uses the get_plotly_script function to generate the plot script. This is a good practice as it separates the generation of the plot script from the rest of the HTML content, improving modularity and maintainability of the code.

  • 119-130: The handle function now uses the get_html function to generate the HTML content for the plot. This is a good practice as it separates the generation of the HTML content from the HTTP handling logic, improving modularity and maintainability of the code.

  • 134-150: The encode function has been updated to also replace occurrences of "[]int" and "[][]f64". This is a good practice as it ensures that all types of arrays are correctly encoded into JSON.

Comment on lines +13 to 14
use_cdn bool
}
Copy link

Choose a reason for hiding this comment

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

The PlotConfig struct only contains a single field use_cdn. If this is the only configuration option for the plot, it might be more straightforward to pass this as a boolean parameter to the show function and get_html function, rather than wrapping it in a struct. This would simplify the function signatures and make the code easier to understand.

Comment on lines +22 to +23
use_cdn: true
plot: p
Copy link

Choose a reason for hiding this comment

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

The use_cdn field of the PlotlyHandler struct is always set to true, ignoring the value in the PlotConfig parameter. This should be changed to use the value from the PlotConfig parameter.

- use_cdn: true
+ use_cdn: config.use_cdn

Comment on lines +42 to 46
// PlotlyScriptConfig is a configuration for the Plotly plot script.
[params]
pub struct PlotlyScriptConfig {
PlotConfig
}
Copy link

Choose a reason for hiding this comment

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

The PlotlyScriptConfig struct is defined but it only inherits from PlotConfig and doesn't add any new fields. If there are no additional configuration options for the plot script, it might be unnecessary to define a separate struct for it. Consider using PlotConfig directly instead.

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.

Fix default size settings in plot.Layout Add support of []int to plot axis types
1 participant