-
Notifications
You must be signed in to change notification settings - Fork 1
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
frontend: sampling output view (take 3) #47
Merged
Merged
Changes from 3 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
da62c3c
develop sampling output view
magland bb76f84
add missing dependencies
magland 22f03f5
Merge branch 'main' into sampling-output-take-3
magland d411c89
LazyPlotlyPlot
magland 3e5e0ae
Update gui/src/app/components/LazyPlotlyPlot.tsx
magland 6f6a7e2
Merge branch 'main' into sampling-output-take-3
magland fd21058
Merge branch 'main' into sampling-output-take-3
magland File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
import { FunctionComponent, useMemo } from "react"; | ||
import SequenceHistogramWidget from "./SequenceHistogramWidget"; | ||
|
||
type HistsViewProps = { | ||
width: number, | ||
height: number, | ||
draws: number[][], | ||
paramNames: string[] | ||
drawChainIds: number[] | ||
} | ||
|
||
const HistsView: FunctionComponent<HistsViewProps> = ({ width, height, draws, paramNames, drawChainIds }) => { | ||
const paramNamesResorted = useMemo(() => { | ||
// put the names that don't end with __ first | ||
const names = paramNames.filter((name) => !name.endsWith('__')); | ||
const namesWithSuffix = paramNames.filter((name) => name.endsWith('__')); | ||
return [...names, ...namesWithSuffix]; | ||
}, [paramNames]); | ||
return ( | ||
<div style={{position: 'absolute', width, height, overflowY: 'auto', display: 'flex', flexWrap: 'wrap'}}> | ||
{ | ||
paramNamesResorted.map((paramName) => ( | ||
<SequenceHist | ||
key={paramName} | ||
width={300} | ||
height={300} | ||
variableName={paramName} | ||
columnIndex={paramNames.indexOf(paramName)} | ||
draws={draws} | ||
drawChainIds={drawChainIds} | ||
/> | ||
)) | ||
} | ||
</div> | ||
) | ||
} | ||
|
||
type SequenceHistProps = { | ||
width: number, | ||
height: number, | ||
variableName: string, | ||
draws: number[][] | ||
columnIndex: number | ||
drawChainIds: number[] | ||
} | ||
|
||
const SequenceHist: FunctionComponent<SequenceHistProps> = ({ width, height, variableName, draws, columnIndex }) => { | ||
return ( | ||
<SequenceHistogramWidget | ||
histData={draws[columnIndex]} | ||
title={variableName} | ||
variableName={variableName} | ||
width={width} | ||
height={height} | ||
/> | ||
) | ||
} | ||
|
||
export default HistsView; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
import React, { FunctionComponent, Suspense, useMemo } from "react"; | ||
|
||
type Props = { | ||
histData: number[] | ||
title: string | ||
variableName: string | ||
width: number | ||
height: number | ||
} | ||
|
||
const Plot = React.lazy(() => (import('react-plotly.js'))) | ||
|
||
const SequenceHistogramWidget: FunctionComponent<Props> = ({ histData, title, width, height, variableName }) => { | ||
const data = useMemo(() => ( | ||
{ | ||
x: histData, | ||
type: 'histogram', | ||
nbinsx: Math.ceil(1.5 * Math.sqrt(histData.length)), | ||
marker: {color: '#505060'}, | ||
histnorm: 'probability' | ||
} as any // had to do it this way because ts was not recognizing nbinsx | ||
), [histData]) | ||
return ( | ||
<div style={{ position: 'relative', width, height }}> | ||
<Suspense fallback={<div>Loading plotly</div>}> | ||
<Plot | ||
WardBrian marked this conversation as resolved.
Show resolved
Hide resolved
|
||
data={[data]} | ||
layout={{ | ||
width: width, | ||
height, | ||
title: {text: title, font: {size: 12}}, | ||
xaxis: {title: variableName}, | ||
yaxis: {title: 'Count'}, | ||
margin: {r: 0} | ||
}} | ||
/> | ||
</Suspense> | ||
</div> | ||
) | ||
} | ||
|
||
export default SequenceHistogramWidget |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
[note] it may be worth using an alternative plotly distribution for size if we only need certain kinds of plots. For stan-web-demo this made a pretty significant difference in overall bundle size.
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.
Thanks for pointing that out, I didn't know it was available.
Not an easy change right now since I am using react-plotly (npm package) which seems to only work with the full plotly.js. But I'm sure there's a workaround.
I'll note that since we are doing lazy loading, the plotly.js doesn't contribute to the main bundle on initial page load.
Shall we defer for a separate issue when we can figure out how to work around limitations of react-plotly?
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.
Sure, we can open a ticket to try it later. I know react-plotly supports it, but I’m not sure how this interacts with the lazy loading, and as you say the lazy loading helps make it less necessary
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.
For information, I just tried using a smaller distribution and ran into some bundling problems, so yeah I think we should do this in a different ticket.