Skip to content

Commit 88fbe86

Browse files
authored
fix: allow plotly plots to shrink inside ui.flex/grid layouts (#1946)
- set responsive config to true which allows plots to properly grow and shrink - removed unnecessary useResizeHandler (which only watches window), as we have our own observer - fixed failing test by changing locator to plotly parent container. Responsive setting has an absolutely positioned child that makes the other locator have zero height, Tested with the following script, and resizing golden-layout panels both vertically and horizontally and resizing browser window horizontally and vertically. ```py from deephaven import ui, empty_table from deephaven.plot import express as dx t = empty_table(100).update(["x = i", "y = i"]) p = dx.line(t, x="x", y="y") @ui.component def common_example(): return ui.panel( ui.flex( ui.text_field(label="Text Field"), ui.text_field(label="Text Field"), ui.text_field(label="Text Field"), ), t, p ) ui_common_example = common_example() @ui.component def common_example_row(): return ui.panel( ui.flex( ui.text_field(label="Text Field"), ui.text_field(label="Text Field"), ui.text_field(label="Text Field"), direction="column" ), t, p, direction="row" ) ui_common_example_row = common_example_row() ```
1 parent b63ab18 commit 88fbe86

2 files changed

Lines changed: 6 additions & 3 deletions

File tree

packages/chart/src/Chart.tsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -332,6 +332,10 @@ class Chart extends Component<ChartProps, ChartState> {
332332
return {
333333
displaylogo: false,
334334

335+
// scales the plot to the container size
336+
// https://github.com/plotly/react-plotly.js/issues/102
337+
responsive: true,
338+
335339
// Display the mode bar if there's an error or downsampling so user can see progress
336340
// Yes, the value is a boolean or the string 'hover': https://github.com/plotly/plotly.js/blob/master/src/plot_api/plot_config.js#L249
337341
displayModeBar:
@@ -704,7 +708,6 @@ class Chart extends Component<ChartProps, ChartState> {
704708
onRelayout={this.handleRelayout}
705709
onUpdate={this.handlePlotUpdate}
706710
onRestyle={this.handleRestyle}
707-
useResizeHandler
708711
style={{ height: '100%', width: '100%' }}
709712
/>
710713
)}

tests/figure.spec.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ test('can open a simple figure', async ({ page }) => {
66
await openPlot(page, 'simple_plot');
77
// Now we should be able to check the snapshot on the plotly container
88
await expect(
9-
page.locator('.iris-chart-panel .plotly.plot-container')
9+
page.locator('.iris-chart-panel .js-plotly-plot')
1010
).toHaveScreenshot();
1111
});
1212

@@ -15,6 +15,6 @@ test('can set point shape and size', async ({ page }) => {
1515
await openPlot(page, 'trig_figure');
1616
// Now we should be able to check the snapshot on the plotly container
1717
await expect(
18-
page.locator('.iris-chart-panel .plotly.plot-container')
18+
page.locator('.iris-chart-panel .js-plotly-plot')
1919
).toHaveScreenshot();
2020
});

0 commit comments

Comments
 (0)