-
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 4 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,39 @@ | ||
import { FunctionComponent, useMemo } from "react"; | ||
import LazyPlotlyPlot from "../components/LazyPlotlyPlot"; | ||
|
||
type Props = { | ||
histData: number[] | ||
title: string | ||
variableName: string | ||
width: number | ||
height: number | ||
} | ||
|
||
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 }}> | ||
<LazyPlotlyPlot | ||
data={[data]} | ||
layout={{ | ||
width: width, | ||
height, | ||
title: {text: title, font: {size: 12}}, | ||
xaxis: {title: variableName}, | ||
yaxis: {title: 'Count'}, | ||
margin: {r: 0} | ||
}} | ||
/> | ||
</div> | ||
) | ||
} | ||
|
||
export default SequenceHistogramWidget |
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,57 @@ | ||
import { FunctionComponent, useMemo } from "react"; | ||
import LazyPlotlyPlot from "../components/LazyPlotlyPlot"; | ||
|
||
export type PlotSequence = { | ||
label: string | ||
data: number[] | ||
color: string | ||
} | ||
|
||
type Props = { | ||
plotSequences: PlotSequence[] | ||
variableName: string | ||
highlightDrawRange?: [number, number] | ||
width: number | ||
height: number | ||
} | ||
|
||
const SequencePlotWidget: FunctionComponent<Props> = ({ plotSequences, variableName, highlightDrawRange, width, height }) => { | ||
const shapes = useMemo(() => ( | ||
(highlightDrawRange ? ( | ||
[{type: 'rect', x0: highlightDrawRange[0], x1: highlightDrawRange[1], y0: 0, y1: 1, yref: 'paper', fillcolor: 'yellow', opacity: 0.1}] | ||
) : []) as any | ||
), [highlightDrawRange]) | ||
const data: any[] = useMemo(() => ( | ||
plotSequences.map(ps => ( | ||
{ | ||
x: [...new Array(ps.data.length).keys()].map(i => (i + 1)), | ||
y: ps.data, | ||
type: 'scatter', | ||
mode: 'lines+markers', | ||
marker: {color: ps.color} | ||
} | ||
)) | ||
), [plotSequences]) | ||
const layout = useMemo(() => ({ | ||
width: width, | ||
height, | ||
title: '', | ||
yaxis: {title: variableName}, | ||
xaxis: {title: 'draw'}, | ||
shapes, | ||
margin: { | ||
t: 30, b: 40, r: 0 | ||
}, | ||
showlegend: false | ||
}), [width, height, variableName, shapes]) | ||
return ( | ||
<div style={{ position: 'relative', width, height }}> | ||
<LazyPlotlyPlot | ||
data={data} | ||
layout={layout} | ||
/> | ||
</div> | ||
) | ||
} | ||
|
||
export default SequencePlotWidget |
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.