Skip to content

Commit 8789690

Browse files
authored
fix: Set responsive dimensions on (re)render (#1556)
* fix: Set responsive dimentions on first render * test: Wait for visualization to fully render
1 parent 2080ffb commit 8789690

File tree

2 files changed

+28
-1
lines changed

2 files changed

+28
-1
lines changed

src/components/renderer/renderer.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -196,8 +196,8 @@ export default function Renderer(props: RendererProps) {
196196
);
197197

198198
const initView = useCallback(async () => {
199+
const chart = chartRef.current;
199200
const clearChartContainers = () => {
200-
const chart = chartRef.current;
201201
const portalChart = portalChartRef.current;
202202
if (chart) chart.innerHTML = '';
203203
if (portalChart) portalChart.innerHTML = '';
@@ -229,6 +229,7 @@ export default function Renderer(props: RendererProps) {
229229
hover,
230230
loader,
231231
expr: expressionInterpreter ? vegaInterpreter : undefined,
232+
container: chart,
232233
});
233234
newView.runAfter(runAfter, true);
234235
newView.logger(dispatchingLogger);

tests/e2e/test-runtime/renderer.test.ts

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -443,4 +443,30 @@ test.describe('Visualization Rendering', () => {
443443
});
444444
expect(hasUpdatedContent).toBe(true);
445445
});
446+
447+
test('should render responsive chart correctly', async () => {
448+
const DEFAULT_CHART_WIDTH = '500';
449+
450+
const responsiveSpec = `{
451+
"$schema": "https://vega.github.io/schema/vega-lite/v6.json",
452+
"width": "container",
453+
"data": {"values": [{"a": "A", "b": 28}, {"a": "B", "b": 55}]},
454+
"mark": "bar",
455+
"encoding": {
456+
"x": {"field": "a", "type": "nominal"},
457+
"y": {"field": "b", "type": "quantitative"}
458+
}
459+
}`;
460+
461+
await homePage.typeInEditor(responsiveSpec);
462+
await homePage.waitForVisualizationUpdate();
463+
await homePage.page.waitForTimeout(2000);
464+
465+
const svgWidth = await homePage.page
466+
.locator('.chart-container svg, .chart-container #vis svg, .vega-embed svg')
467+
.first()
468+
.getAttribute('width');
469+
470+
expect(svgWidth).toBe(DEFAULT_CHART_WIDTH);
471+
});
446472
});

0 commit comments

Comments
 (0)