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

DO NOT MERGE: Request for comments: Plan 5a Proof of concept #3852

Closed
wants to merge 1 commit into from

Conversation

PavelVanecek
Copy link
Collaborator

@PavelVanecek PavelVanecek commented Oct 13, 2023

So this doesn't pass tests, I don't think it actually renders the Tooltip at all. All the problems are fixable, I am just wondering what do you think about the general direction before I sink the time into fixing them.

In the meantime I would like to use the Pull Request as a vehicle for comments and discussion.

Please focus on:

  • Overall architecture and data flow
  • Breaking API changes
  • Any changes we want to bring to master independent of the refactor to minimize the PR size and reduce risk?

Please do not yet pay attention to:

  • Variable naming
  • Component split
  • File names
  • any

Description

As described in #3717:

  • The Tooltip component is now purely a marker. It renders nothing. It only cleans its props, adds some defaults, and pushes everything into a React.Context
  • generateCategoricalChart no longer needs to search for the Tooltip Element in DOM because it has all its data in the context. It gets some precomputed data and global state and passes it down to a new component:
  • TooltipRenderer This is grouping all the small individual renders that used to be split in three places before:
    1. Tooltip.render
    2. generateCategoricalChart.renderCursor
    3. generateCategoricalChart.renderTooltip

Related Issue

#3823

Motivation and Context

#3717

How Has This Been Tested?

I tested it won't work, please don't merge it yet.

Screenshots (if appropriate):

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)

Checklist:

  • My code follows the code style of this project.
  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.
  • I have added tests to cover my changes.
  • I have added a storybook story or extended an existing story to show my changes
  • All new and existing tests passed.
  • Only discuss, no merge

@@ -2312,7 +2250,6 @@ export const generateCategoricalChart = ({
Scatter: { handler: this.renderGraphicChild },
Pie: { handler: this.renderGraphicChild },
Funnel: { handler: this.renderGraphicChild },
Tooltip: { handler: this.renderCursor, once: true },
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Tooltip no longer uses the cloning map!

// @ts-expect-error TODO
position: props.position,
};
setContext(newContext);
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

The public Tooltip will now only gather and cleanup the public props and push to context - nothing more.

Copy link
Member

Choose a reason for hiding this comment

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

we should scrutinize every effect we add, but I guess optimizations can come later once its working

y: boolean;
};

export type ChartContextType = {
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

The context might grow quite a bit, we might consider splitting to one context per component.

Copy link
Member

Choose a reason for hiding this comment

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

We'll have to see how re-renders do as well

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Here is the actual Tooltip + Cursor rendering. Reads from props (shared global state) and context (public props).

Copy link
Contributor

Choose a reason for hiding this comment

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

Combining the Tooltip and the Cursor generally seems like a great refactoring. Do you see a way to get this in independent on the conceptual change?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yeah so without the conceptual change the component of TooltipWithCursor will accept merged props from both. There might be slight complications since they are both rendered at different times (not sure why?). I will look into that.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

@PavelVanecek
Copy link
Collaborator Author

PavelVanecek commented Oct 13, 2023

The more I work on the codebase the less I am convinced we can have a clean split between 5a ("Push") and 5b ("Pull"). It might end up as a combination of both, either way.

This could be a special case because generateCategoricalChart never reads any props from Tooltip - so it doesn't need its context. Or maybe I haven't found those places yet.

@PavelVanecek PavelVanecek changed the title DO NOT MERGE, WORK IN PROGRESS: Plan 5a Proof of concept DO NOT MERGE: Request for comments: Plan 5a Proof of concept Oct 13, 2023
Copy link
Member

@ckifer ckifer left a comment

Choose a reason for hiding this comment

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

I like the direction! We'll have to be careful about how unwieldy that context gets, it could quite literally get as bad as generateCategoricalChart itself lol

src/chart/generateCategoricalChart.tsx Show resolved Hide resolved
// @ts-expect-error TODO
position: props.position,
};
setContext(newContext);
Copy link
Member

Choose a reason for hiding this comment

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

we should scrutinize every effect we add, but I guess optimizations can come later once its working

y: boolean;
};

export type ChartContextType = {
Copy link
Member

Choose a reason for hiding this comment

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

We'll have to see how re-renders do as well

import { isNumber } from '../util/DataUtils';
import { ContentType } from '../component/Tooltip';

type Props = {
Copy link
Member

Choose a reason for hiding this comment

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

going forward I think we should be specific about how we name prop types, instead of renaming on export (even though in this case this is scoped to the file)

src/renderer/TooltipRenderer.tsx Show resolved Hide resolved
@PavelVanecek PavelVanecek force-pushed the plan-5a-poc branch 3 times, most recently from 2e1b2b2 to 22b0c6d Compare October 22, 2023 22:51
@ckifer ckifer mentioned this pull request Oct 23, 2023
9 tasks
@ckifer
Copy link
Member

ckifer commented Oct 23, 2023

I think tests are basically passing besides snaps?

@PavelVanecek
Copy link
Collaborator Author

PavelVanecek commented Oct 23, 2023 via email

@ckifer
Copy link
Member

ckifer commented Oct 23, 2023

Sounds good!

@PavelVanecek
Copy link
Collaborator Author

I can't get the latest changes to work. In the name of performance optimization, this PR introduced mutable variables outside of state: HHongSeungWoo@830bd00 and I can't figure out if it's meant to be that way and I should follow that or if that's an oversight.

@HHongSeungWoo
Copy link
Member

Not using the state was an intentional change. Currently, the tooltip is being rerendered by outer components, so there is no need to trigger state change. but you can change it if necessary

@PavelVanecek
Copy link
Collaborator Author

I don't have enough insight to tell if it's necessary or not but I can tell it looks like an oversight. I recommend to add unit tests that show that it is intentional and what unnecessary re-renders does it prevent. Otherwise you can have someone come and go "This is not The React Way(tm)" and change it.

@PavelVanecek
Copy link
Collaborator Author

And a comment too 😬

@PavelVanecek
Copy link
Collaborator Author

Sibling PR: #3965

@PavelVanecek
Copy link
Collaborator Author

Declining in favour of #3965

@PavelVanecek PavelVanecek mentioned this pull request Nov 25, 2023
9 tasks
ckifer pushed a commit that referenced this pull request Dec 5, 2023
## Description

Following up from @nikolasrieble's suggestion in
#3852 (comment) I
am moving towards merging Cursor and Tooltip component. Cursor depends
on Tooltip props anyway so it's a natural refactor.

Baby steps. First I move the Cursor rendering as-is to its own
component. In a followup PR, I will make it read props from Tooltip
directly and remove `renderCursor` method from generateCategoricalChart.

## Related Issue

#3717

## Motivation and Context

Small step towards breaking down generateCategoricalChart

## How Has This Been Tested?

`npm test`, storybooks

## Screenshots (if appropriate):

## Types of changes

- [ ] Bug fix (non-breaking change which fixes an issue)
- [ ] New feature (non-breaking change which adds functionality)
- [ ] Breaking change (fix or feature that would cause existing
functionality to change)

## Checklist:

- [X] My code follows the code style of this project.
- [ ] My change requires a change to the documentation.
- [ ] I have updated the documentation accordingly.
- [X] I have added tests to cover my changes.
- [X] I have added a storybook story or extended an existing story to
show my changes
- [X] All new and existing tests passed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants