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

new examples: Axis titles and script mode #205

Merged
merged 1 commit into from
Jun 9, 2024

Conversation

fermarsan
Copy link
Contributor

@fermarsan fermarsan commented Jun 8, 2024

Add 4 examples:

  • 1 simple plot adding axis titles
  • 3 more plotting examples using script mode

There are not examples with axis titles.
Script mode could be striking or more familiar for other languages users (Python, Julia, Matlab, etc)

Summary by CodeRabbit

  • New Features
    • Added a line plot example with axis titles.
    • Introduced functionality to plot an AC signal with customizable parameters.
    • Added a simple sine wave plot example using scatter points.
    • Introduced a three-phase signal system plot example with sinusoidal waves.

Copy link

coderabbitai bot commented Jun 8, 2024

Walkthrough

The changes introduce new functionalities for plotting various types of signals and functions using the vsl.plot library. These include creating line plots with axis titles, plotting an AC signal, generating simple sine wave plots, and visualizing three-phase signal systems. These additions enhance the visualization capabilities and provide diverse examples for users to understand and utilize the vsl.plot library effectively.

Changes

File Path Summary
examples/plot_line_axis_titles/... Introduces a module for generating a line plot with sine and cosine functions, including customized axis titles.
examples/script_mode_ac_signal/... Adds functionality to plot an AC signal with specified parameters like frequency, phase, and amplitude.
examples/script_mode_simple_plot/... Adds functionality to create a simple plot of a sine wave using scatter points.
examples/script_mode_three_phase_signal/... Adds functionality to plot a three-phase signal system with three sinusoidal waves of different phases.

Poem

In the land of code, where functions thrive,
New plots emerge, bringing graphs alive.
Sine and cosine in a graceful dance,
AC signals and phases, they all enhance.
With vsl.plot, the visuals bloom,
A coder's dream in the coding room.
🌟📊🐇


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

Share
Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

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 an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Configration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

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.

Actionable comments posted: 5

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between b66e4d9 and 7c434c9.

Files selected for processing (4)
  • examples/plot_line_axis_titles/main.v (1 hunks)
  • examples/script_mode_ac_signal/main.v (1 hunks)
  • examples/script_mode_simple_plot/main.v (1 hunks)
  • examples/script_mode_three_phase_signal/main.v (1 hunks)
Additional comments not posted (10)
examples/script_mode_simple_plot/main.v (1)

1-3: Imports are correctly added for the required libraries.

examples/script_mode_ac_signal/main.v (3)

1-3: Imports are correctly added for the required libraries.


6-8: Variable declarations are clear and well-documented with comments.


10-11: The signal generation using the map function is correctly implemented.

examples/plot_line_axis_titles/main.v (3)

1-4: Imports are correctly added for the required libraries.


6-40: The function main is well-structured, and the plot setup is correctly implemented with detailed customization for line properties and axis titles.


39-39: The use of the force unwrap operator ! in plt.show()! is risky if not handled properly.

examples/script_mode_three_phase_signal/main.v (3)

1-3: Imports are correctly added for the required libraries.


6-12: Variable declarations and signal calculations are clear and well-documented.


14-44: The plot setup and layout configuration are well-implemented, with detailed customization for each phase.

Comment on lines +9 to +16
mut plt := plot.Plot.new()

plt.scatter(
x: t
y: y
)

plt.show()!
Copy link

@coderabbitai coderabbitai bot Jun 8, 2024

Choose a reason for hiding this comment

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

The scatter plot setup looks good, but ensure proper separation of arguments for clarity.

- plt.scatter(
- 	x: t
- 	y: y
- )
+ plt.scatter(x: t, y: y)
Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.

Suggested change
mut plt := plot.Plot.new()
plt.scatter(
x: t
y: y
)
plt.show()!
mut plt := plot.Plot.new()
plt.scatter(x: t, y: y)
plt.show()!

Copy link
Contributor

Choose a reason for hiding this comment

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

@coderabbitai the code is properly formatted for the V language.

Copy link

Choose a reason for hiding this comment

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

@JalonSolov, thank you for the clarification regarding the code formatting standards for the V language. I'll make sure to align with these standards in future reviews.


Learnings added
User: JalonSolov
PR: vlang/vsl#205
File: examples/script_mode_simple_plot/main.v:9-16
Timestamp: 2024-06-08T12:23:35.483Z
Learning: In the V language, the formatting used by JalonSolov in the PR #205 is considered correct. Specifically, arguments in function calls like `plt.scatter` can be separated by new lines for clarity.

Note: Learnings are effective only in the context of specific code segments. To apply general coding guidelines, please configure review instructions.

Comment on lines +6 to +7
t := util.lin_space(-math.pi, math.pi, 50)
y := []f64{len: t.len, init: math.sin(t[index])}
Copy link

@coderabbitai coderabbitai bot Jun 8, 2024

Choose a reason for hiding this comment

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

Ensure correct indexing in the array initialization.

- y := []f64{len: t.len, init: math.sin(t[index])}
+ y := []f64{len: t.len, init: math.sin(t[it])}
Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.

Suggested change
t := util.lin_space(-math.pi, math.pi, 50)
y := []f64{len: t.len, init: math.sin(t[index])}
t := util.lin_space(-math.pi, math.pi, 50)
y := []f64{len: t.len, init: math.sin(t[it])}

Copy link
Contributor

Choose a reason for hiding this comment

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

@coderabbitai it is being deprecated. index is the new variable.

Copy link

Choose a reason for hiding this comment

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

@JalonSolov, thank you for the update on the deprecation of it and the transition to using index. I've noted this change for future reviews to ensure consistency with the latest standards in your codebase.

Here's the updated suggestion reflecting this change:

t := util.lin_space(-math.pi, math.pi, 50)
y := []f64{len: t.len, init: math.sin(t[index])}

If there's anything else you need, feel free to ask!


Learnings added
User: JalonSolov
PR: vlang/vsl#205
File: examples/script_mode_simple_plot/main.v:6-7
Timestamp: 2024-06-08T12:21:50.857Z
Learning: The variable `it` is being deprecated in array initializations, and `index` is the new variable to be used.

Note: Learnings are effective only in the context of specific code segments. To apply general coding guidelines, please configure review instructions.

Comment on lines +13 to +30
mut plt := plot.Plot.new()

plt.scatter(
x: t
y: y
)

plt.layout(
title: 'AC signal (60Hz)'
xaxis: plot.Axis {
title: plot.AxisTitle { 'time [s]' }
}
yaxis: plot.Axis {
title: plot.AxisTitle { 'amplitude [V]' }
}
)

plt.show()!
Copy link

@coderabbitai coderabbitai bot Jun 8, 2024

Choose a reason for hiding this comment

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

The plot setup and layout configuration are well-implemented. However, consider using a consistent approach for axis titles across examples.

- title: plot.AxisTitle { 'time [s]' }
+ title: plot.AxisTitle { text: 'time [s]' }
Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.

Suggested change
mut plt := plot.Plot.new()
plt.scatter(
x: t
y: y
)
plt.layout(
title: 'AC signal (60Hz)'
xaxis: plot.Axis {
title: plot.AxisTitle { 'time [s]' }
}
yaxis: plot.Axis {
title: plot.AxisTitle { 'amplitude [V]' }
}
)
plt.show()!
mut plt := plot.Plot.new()
plt.scatter(
x: t
y: y
)
plt.layout(
title: 'AC signal (60Hz)'
xaxis: plot.Axis {
title: plot.AxisTitle { text: 'time [s]' }
}
yaxis: plot.Axis {
title: plot.AxisTitle { 'amplitude [V]' }
}
)
plt.show()!

Copy link
Contributor

@JalonSolov JalonSolov Jun 8, 2024

Choose a reason for hiding this comment

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

@coderabbitai the original code is proper V.

Copy link

Choose a reason for hiding this comment

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

Seems like the humans are having a chat. I'll hop back into my burrow for now. If you need me again, just tag @coderabbitai in a new comment, and I'll come hopping out!

}
)

plt.show()!
Copy link

@coderabbitai coderabbitai bot Jun 8, 2024

Choose a reason for hiding this comment

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

Tip

Codebase Verification

The search results indicate multiple instances of plt.show()! across the project, but no instances of plt.show() without the force unwrap operator were found. This suggests that the force unwrap operator is consistently used without additional error handling.

  • File: examples/script_mode_ac_signal/main.v
    • Line: 30: plt.show()!

This consistent use of the force unwrap operator without error handling is risky and should be addressed to prevent potential runtime errors.

Analysis chain

The use of the force unwrap operator ! in plt.show()! is risky if not handled properly.

Scripts executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Description: Check for error handling around plot display functions across the project.
rg --type v 'plt.show()!'

Length of output: 53



Script:

#!/bin/bash
# Description: Find all `.v` files and search for `plt.show()!` within them.
fd -e v -x rg 'plt.show()!' {}

Length of output: 34



Script:

#!/bin/bash
# Description: Find all `.v` files and search for `plt.show()` within them to check for error handling.
fd -e v -x rg 'plt.show()' {}

Length of output: 446

Copy link
Contributor

Choose a reason for hiding this comment

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

@coderabbitai plt.show()! is proper syntax for propagating errors to the caller. In the case of main, it propagates the error to the user.

While it would be nice to have a cleaner error message, this is acceptable as-is.

Copy link

Choose a reason for hiding this comment

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

@JalonSolov, thank you for clarifying the use of plt.show()! and its context in error propagation. I appreciate your decision to keep the implementation as-is for now. If there's anything else you need, feel free to ask!


Learnings added
User: JalonSolov
PR: vlang/vsl#205
File: examples/script_mode_ac_signal/main.v:30-30
Timestamp: 2024-06-08T12:24:17.214Z
Learning: The use of `plt.show()!` in V code is considered proper syntax for propagating errors to the caller, especially in the context of the `main` function, as clarified by JalonSolov.

Note: Learnings are effective only in the context of specific code segments. To apply general coding guidelines, please configure review instructions.

title: plot.AxisTitle { 'amplitude [V]' }
}
)

Copy link

Choose a reason for hiding this comment

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

Tip

Codebase Verification

The search results indicate multiple instances of plt.show()! across various files in the codebase. The use of the force unwrap operator ! in these instances is risky if not handled properly.

  • plot/plot_test.v
  • examples/plot_surface_easing/main.v
  • examples/script_mode_simple_plot/main.v
  • examples/script_mode_ac_signal/main.v
  • examples/plot_line_axis_titles/main.v
  • examples/script_mode_three_phase_signal/main.v
  • examples/roots_bisection_solver/main.v
  • examples/plot_sin_cos_surface/main.v
  • examples/plot_surface/main.v
  • examples/plot_shaded_area_sin/main.v
  • examples/plot_scatter_with_histogram/main.v
  • examples/plot_scatter_with_bars/main.v
  • examples/plot_scatter_with_annotations/main.v
  • examples/plot_scatter_easing/main.v
  • examples/plot_scatter_with_regression/main.v
  • examples/plot_scatter3d_easing/main.v
  • examples/plot_scatter3d_2/main.v
  • examples/plot_scatter_colorscale/main.v
  • examples/plot_scatter3d_1/main.v
  • examples/plot_scatter/main.v
  • examples/plot_ripple_surface/main.v
  • examples/plot_pie/main.v
  • examples/plot_saddle_surface/main.v
  • examples/plot_heatmap_golden_ratio/main.v
  • examples/plot_line_plot_with_areas/main.v
  • examples/plot_grouped_bar_chart/main.v
  • examples/plot_bubble_chart/main.v
  • examples/plot_basic_heatmap/main.v
  • examples/plot_bar/main.v
  • examples/plot_annotated_pie_chart/main.v
  • examples/plot_histogram/main.v
  • examples/fft_plot_example/main.v

Please review these instances to ensure proper error handling around the use of plt.show()!.

Analysis chain

The use of the force unwrap operator ! in plt.show()! is risky if not handled properly.

Scripts executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Description: Check for error handling around plot display functions across the project.
rg --type v 'plt.show()!'

Length of output: 53



Script:

#!/bin/bash
# Description: Check for error handling around plot display functions across the project.
rg 'plt.show()!'

Length of output: 18



Script:

#!/bin/bash
# Description: Search for all instances of plt.show() in the codebase.
rg 'plt.show()'

Length of output: 1590

@ulises-jeremias
Copy link
Member

thanks for your PR @fermarsan ! will merge and do some minor naming changes right after that 😊

@ulises-jeremias ulises-jeremias merged commit 91a3e7b into vlang:main Jun 9, 2024
5 of 9 checks passed
@fermarsan
Copy link
Contributor Author

fermarsan commented Jun 11, 2024 via email

ulises-jeremias added a commit that referenced this pull request Jun 17, 2024
* 'main' of github.com:vlang/vsl:
  refactor: Update create_image_2d function to use local variable for format
  Update lint.yml
  Update lint.yml
  refactor: update README.md to include link to examples folder
  refactor: update README.md to include link to examples folder
  fix error in examples/vcl_opencl_fractals_one_argument/main.v (fix main V CI)
  refactor: Update image creation functions to use generic 'image' instead of 'image_2d'
  refactor: Update image creation functions to use generic 'image' instead of 'image_2d'
  refactor: Update create_image_2d function to use local variable for format
  chore: Add output image to README
  chore: Remove unused plot examples using script mode
  refactor: Update AC signal calculation to include amplitude parameter
  chore: Update plot examples with axis titles and script mode
  1 basic plotting example with axis titles and 3 more ones using script mode (#205)
  remove unused `math` import, run `v fmt -w .`
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.

3 participants