-
Notifications
You must be signed in to change notification settings - Fork 1.7k
feat: add the ability to brush historical #7247
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
base: v5
Are you sure you want to change the base?
Conversation
Summary of ChangesHello @lxfu1, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request enhances the Highlights
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Code Review
This pull request introduces a history option to the brushFilter interaction, allowing users to undo brush actions. The implementation adds logic to store brush states and revert to them on dblclick. The changes look good overall, but there are a few points to address:
- A potential race condition exists because an
asyncfunction is not beingawaited. - The undo logic in the
resetfunction could be made more intuitive for a multi-level undo experience. - The new test is missing a crucial snapshot to verify the undo behavior.
- There's a minor typo in the updated documentation.
| filtered = true; | ||
| }, | ||
| reset: (event) => { | ||
| reset: async (event) => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This function is now async, but its caller, the click handler within the outer brushFilter function, does not await the call to reset. This can lead to race conditions and unpredictable behavior. The click handler should be updated to be async and await this promise.
// in brushFilter(...)
async function click(e) {
if (isDblclick(e)) {
e.nativeEvent = true;
await reset(e);
}
}Although this change is outside the diff, it's critical for the correctness of this feature.
| penguinsPointBrushFilterWithHistory.steps = ({ canvas }) => { | ||
| const { document } = canvas; | ||
| const plot = document.getElementsByClassName(PLOT_CLASS_NAME)[0]; | ||
| return [ | ||
| { | ||
| changeState: () => { | ||
| brush(plot, 100, 100, 300, 300); | ||
| }, | ||
| }, | ||
| { | ||
| changeState: () => { | ||
| brush(plot, 100, 100, 300, 300); | ||
| }, | ||
| }, | ||
| { | ||
| changeState: () => { | ||
| dblclick(plot); | ||
| }, | ||
| }, | ||
| ]; | ||
| }; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The test for the history feature seems incomplete and could be improved:
- Missing Snapshot: The test steps include a
dblclickto trigger the undo functionality, but the corresponding snapshot (step3.svg) is missing from the pull request. This is the most critical part of the test for this feature and should be included to verify the undo behavior. - Test Case Improvement: Both
brushactions use the same coordinates (100, 100, 300, 300). While this tests the history mechanism, using different coordinates for the second brush would make the visual change betweenstep1andstep2clearer, and would provide a more robust verification whenstep3reverts to the state ofstep1.
| | Property | Description | Type | Default | Required | | ||
| | -------- | ------------------------ | ------------- | ----------------- | -------- | | ||
| | reverse | Whether to reverse brush | boolean | false | | | ||
| | history | Whether to histroy brush | boolean | false | | |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| setState('brushFilter'); | ||
| update(); | ||
| // Restore previous brush state | ||
| if (brushHistory.length > 1) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The logic if (brushHistory.length > 1) for handling history is a bit counter-intuitive. It means that undoing the very first brush action results in a full reset, rather than stepping back to the initial state. A user would likely expect to be able to undo each brush step by step.
A more conventional undo behavior would be to pop from history on every dblclick until the history is empty.
Consider refactoring the logic to handle undo consistently for all levels of history. For example:
if (history && brushHistory.length > 0) {
brushHistory.pop();
if (brushHistory.length > 0) {
// Restore previous state
} else {
// Reset to initial state
}
} else {
// Reset to initial state (if no history)
}This would provide a more predictable multi-level undo experience.
Pull Request Test Coverage Report for Build 20460481285Details
💛 - Coveralls |
Checklist
npm testpassesDescription of change