Skip to content

Commit bcf4956

Browse files
committed
docs: add unconstrained resize use-case
1 parent b4a6686 commit bcf4956

File tree

1 file changed

+104
-32
lines changed

1 file changed

+104
-32
lines changed

apps/playground/pages/Resize.tsx

Lines changed: 104 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -151,45 +151,117 @@ export const Resize: Component = () => {
151151
dimensions are determined entirely by the container.
152152
</p>
153153

154-
<p class="mb-3 text-sm text-gray-600">
155-
The container below has an explicit height (400px). The chart fills the available space,
156-
including accounting for child content placed above it. Try resizing your browser window
157-
to see the width adapt.
158-
</p>
154+
<div class="space-y-6">
155+
{/* Sized Container */}
156+
<div>
157+
<h3 class="mb-2 text-lg font-medium">Sized Container</h3>
158+
<p class="mb-3 text-sm text-gray-600">
159+
The container below has an explicit height (400px). The chart fills the available
160+
space, including accounting for child content placed above it. Try resizing your
161+
browser window to see the width adapt.
162+
</p>
159163

160-
<div class="mb-4 border-2 border-dashed border-blue-300 p-4" style={{ height: "400px" }}>
161-
<SolidUplot
162-
autoResize
163-
data={data()}
164-
style={CHART_STYLE}
165-
series={[
166-
{},
167-
{ label: "Auto Resize", stroke: "#8b5cf6", width: 2 },
168-
{ label: "Series B", stroke: "#f59e0b", width: 2 },
169-
]}
170-
scales={{ x: { time: false } }}
171-
childrenPlacement="top"
172-
>
173164
<div
174-
style={{
175-
height: "50px",
176-
background: "#dbeafe",
177-
padding: "8px",
178-
display: "flex",
179-
"align-items": "center",
180-
"justify-content": "center",
181-
}}
165+
class="mb-4 border-2 border-dashed border-blue-300 p-4"
166+
style={{ height: "400px" }}
182167
>
183-
Child content that adds height
168+
<SolidUplot
169+
autoResize
170+
data={data()}
171+
style={CHART_STYLE}
172+
series={[
173+
{},
174+
{ label: "Auto Resize", stroke: "#8b5cf6", width: 2 },
175+
{ label: "Series B", stroke: "#f59e0b", width: 2 },
176+
]}
177+
scales={{ x: { time: false } }}
178+
childrenPlacement="top"
179+
>
180+
<div
181+
style={{
182+
height: "50px",
183+
background: "#dbeafe",
184+
padding: "8px",
185+
display: "flex",
186+
"align-items": "center",
187+
"justify-content": "center",
188+
}}
189+
>
190+
Child content that adds height
191+
</div>
192+
</SolidUplot>
184193
</div>
185-
</SolidUplot>
186-
</div>
187194

188-
<pre class="overflow-x-auto rounded bg-gray-50 p-3 text-sm">
189-
{`<div style={{ height: '400px' }}>
195+
<pre class="overflow-x-auto rounded bg-gray-50 p-3 text-sm">
196+
{`<div style={{ height: '400px' }}>
190197
<SolidUplot autoResize data={data} series={series} />
191198
</div>`}
192-
</pre>
199+
</pre>
200+
</div>
201+
202+
{/* Unsized Container */}
203+
<div>
204+
<h3 class="mb-2 text-lg font-medium">Unsized Container</h3>
205+
<p class="mb-3 text-sm text-gray-600">
206+
The container below has <strong>no explicit height</strong>. Notice how the child
207+
content bar is visible but the chart itself has collapsed to 0px.
208+
</p>
209+
210+
<div class="mb-4 border-2 border-dashed border-blue-300 p-4">
211+
<SolidUplot
212+
autoResize
213+
data={data()}
214+
style={CHART_STYLE}
215+
series={[
216+
{},
217+
{ label: "Collapsed", stroke: "#8b5cf6", width: 2 },
218+
{ label: "Series B", stroke: "#f59e0b", width: 2 },
219+
]}
220+
scales={{ x: { time: false } }}
221+
childrenPlacement="top"
222+
>
223+
<div
224+
style={{
225+
height: "50px",
226+
background: "#fef3c7",
227+
padding: "8px",
228+
display: "flex",
229+
"align-items": "center",
230+
"justify-content": "center",
231+
}}
232+
>
233+
Child content is visible, but the chart below is 0px
234+
</div>
235+
</SolidUplot>
236+
</div>
237+
238+
<div class="mb-4 rounded-lg border border-amber-200 bg-amber-50 p-4 text-sm">
239+
<p class="mb-2 font-medium text-amber-800">Why did the chart collapse?</p>
240+
<p class="mb-2 text-amber-700">
241+
<code class="rounded bg-amber-100 px-1 text-xs">autoResize</code> means "fill the
242+
container." If the container has no defined height, the chart has no height to fill
243+
— so it collapses to 0px. In development mode, a console warning is logged to help
244+
identify this issue.
245+
</p>
246+
<p class="text-amber-700">
247+
<strong>Fix:</strong> Give the container an explicit height (e.g.{" "}
248+
<code class="rounded bg-amber-100 px-1 text-xs">height: 400px</code>), or place it
249+
within a flex/grid layout that provides height. See the{" "}
250+
<a href="/dashboard-layout" class="font-medium text-amber-900 underline">
251+
Dashboard Layout
252+
</a>{" "}
253+
page for a realistic example using flexbox.
254+
</p>
255+
</div>
256+
257+
<pre class="overflow-x-auto rounded bg-gray-50 p-3 text-sm">
258+
{`{/* Container has no height — chart collapses to 0px */}
259+
<div>
260+
<SolidUplot autoResize data={data} series={series} />
261+
</div>`}
262+
</pre>
263+
</div>
264+
</div>
193265
</div>
194266

195267
{/* Container-Driven Sizing */}

0 commit comments

Comments
 (0)