Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork137
Hook-based API#275
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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
base:master
Are you sure you want to change the base?
Hook-based API#275
Uh oh!
There was an error while loading.Please reload this page.
Conversation
Remove unused argument
Add dependencies for usePlotly hook
himbeles left a comment
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.
minor fix regarding requirement versions
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
govindthakur25 commentedJun 1, 2022
Suggestion: It would be good to have a section in the README for this hook, with a few working codepen examples. |
Adds example of `usePlotly`
@govindthakur25 @himbeles |
Bump |
himbeles commentedJun 30, 2022
Just to clarify, I'm not a maintainer of this project. |
Dyocius commentedJun 30, 2022
@nicolaskruchten Do you know who the maintainer of this repo is? |
I am just going to put some names of previous committers here in the hope of getting some movement: @alexcjohnson Sorry for the spam but it seems there is no-one actively looking at this repo? |
@JamesRamm apologies for the silence from us maintainers. This looks great! I'll make a few comments on the code itself, but the one extra thing I'll ask is some basic tests - either add tohttps://github.com/plotly/react-plotly.js/blob/master/src/__tests__/react-plotly.test.js or put a new file next to it for this purpose. We do have this repo connected to CircleCIhttps://app.circleci.com/pipelines/github/plotly/react-plotly.js - hopefully the config changes I just made there will enable it to (a) run on this and other forked PRs and (b) show up in the status of this PR 🤞 |
"react": ">0.13.0" | ||
"react": ">0.13.0", | ||
"flyd": ">=0.2.8", | ||
"ramda": ">=0.28.0" |
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.
flyd
andramda
seem like they'd be better asdependencies
rather thanpeerDependencies
- and then let's change from>=
to^
floriancargoetOct 13, 2022 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
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.
Are 2 news deps really required?ramda
seems to be used just to write this code in the functional style.
The author himself said in the related issue that it could be replaced with:
function getSizeForLayout(entries) { const { width, height } = entries[0].contentRect; return { layout: { width, height } };}
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.
Good question@floriancargoet -ramda
has a couple of other uses in this PR (and we do use it a good deal elsewhere at Plotly), but to my mind yourgetSizeForLayout
rewrite is more readable than the full functional version.
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.
While yesgetSizeForLayout
can be written easily withoutramda
(happy to do this), the main reason it was included was formergeDeepRight
which is a relatively complex function to implement.
We could go for an independent implementation but my argument would be thatramda
is relatively small and compatible with tree shaking
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.
Right, deep merge is annoying to reimplement. I have no problem adding this (andflyd
) but I do think they belong independencies
.
Plotly.react(internalRef, state); | ||
}); | ||
const endAppend = appendData.map(({ data, tracePos }) => Plotly.extendTraces(internalRef, data, tracePos)); |
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.
Since you've implementedextendTraces
here, let's finish it by includingmaxPoints
(the optional 4th argument toextendTraces
)
const appendData = useMemo(stream, []); | ||
const plotlyState = useMemo( | ||
() => scan(mergeDeepRight, { data: [], config: {}, layout: {} }, updates), | ||
[] |
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.
Shouldn'tupdates
be added to the dependencies list here since it's used inside the hook?
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.
sinceupdates
is memoized with an empty array, it will only be computed once on mount, so adding it to the dependencies array or not forplotlyState
will have no effect....
endS.end(true); | ||
}; | ||
} | ||
}, [internalRef, plotlyState, updates, appendData]); |
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.
Shouldn'tobserver
be added as a dependency here since it's used inside the hook?
Michael-fore commentedMay 19, 2023 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
Y'all... uhhh... gonna merge this? |
There are a number of unresolved review comments before we can merge |
Uh oh!
There was an error while loading.Please reload this page.
As discussed in#242 here is a simple hook-based API for react-plotly.
Usage
The hook gives you a
ref
and two streams:updates
andappendData
.Here is an example:
updates
can be treated as a function that you can give partialFigure
definitions to and it will update the graph usingPlotly.react
appendData
can also be used as a function which is directly mapped on toPlotly.extendTraces
every time it is called.Advantages
ref
(Demand for "ref" prop support #209) which gives you full access to the plotly API (functions/events, throughref.current
)