Skip to content

Commit b869083

Browse files
committed
refactor(playground): update Resize page for new autoResize semantics
- Fix createElementSize demo overflow by using inner wrapper div for ref (getBoundingClientRect measures border-box, not content area) - Standardize border colors: gray=fixed, blue=autoResize, green=container-driven, indigo=manual - Remove unconstrained Auto Resize demo (chart would be 0px with new defaults) - Update Auto Resize section to show constrained container with explicit height - Update summary callout to remove min-fallback language - Add explanation of AutoSizer vs createElementSize measurement differences - Update createElementSize code snippet to show inner wrapper pattern
1 parent 4b0c060 commit b869083

File tree

1 file changed

+69
-117
lines changed

1 file changed

+69
-117
lines changed

apps/playground/pages/Resize.tsx

Lines changed: 69 additions & 117 deletions
Original file line numberDiff line numberDiff line change
@@ -53,19 +53,15 @@ export const Resize: Component = () => {
5353
<li>
5454
<strong>Auto Resize</strong> — Set the{" "}
5555
<code class="rounded bg-blue-100 px-1">autoResize</code> prop. The chart uses a
56-
ResizeObserver to automatically fill its container. When enabled, the{" "}
57-
<code class="rounded bg-blue-100 px-1">width</code> and{" "}
58-
<code class="rounded bg-blue-100 px-1">height</code> props act as minimum fallbacks
59-
(defaulting to 600×300) for unconstrained containers, while constrained containers are
60-
filled completely.
56+
ResizeObserver to automatically fill its container. The container must have defined
57+
dimensions (explicit height/width, flex layout, grid layout, etc.).
6158
</li>
6259
<li>
6360
<strong>Container-Driven</strong> — Measure the parent container and pass dimensions to
6461
the chart explicitly. Use <code class="rounded bg-blue-100 px-1">{"<AutoSizer>"}</code>{" "}
6562
for a render prop approach, or{" "}
6663
<code class="rounded bg-blue-100 px-1">createElementSize</code> for a ref-based
67-
primitive without a wrapper component. Useful when you need to share size data across
68-
multiple children or want explicit control over measurement.
64+
primitive without a wrapper component.
6965
</li>
7066
<li>
7167
<strong>Manual Resize</strong> — Combine{" "}
@@ -145,107 +141,55 @@ export const Resize: Component = () => {
145141
<h2 class="mb-4 text-xl font-semibold">Auto Resize</h2>
146142
<p class="mb-3 text-sm text-gray-600">
147143
Chart uses a ResizeObserver to automatically fill its container. Enable this via the{" "}
148-
<code class="rounded bg-gray-100 px-1 text-xs">autoResize</code> prop. No manual size
149-
management needed — the chart responds automatically to container size changes.
144+
<code class="rounded bg-gray-100 px-1 text-xs">autoResize</code> prop. The container must
145+
have defined dimensions — the chart fills whatever space it provides.
150146
</p>
151147
<p class="mb-4 text-sm text-gray-600">
152148
When <code class="rounded bg-gray-100 px-1 text-xs">autoResize</code> is enabled, the{" "}
153149
<code class="rounded bg-gray-100 px-1 text-xs">width</code> and{" "}
154-
<code class="rounded bg-gray-100 px-1 text-xs">height</code> props are not used as fixed
155-
dimensions. Instead, they serve as{" "}
156-
<code class="rounded bg-gray-100 px-1 text-xs">min-width</code> /{" "}
157-
<code class="rounded bg-gray-100 px-1 text-xs">min-height</code> fallbacks for containers
158-
that have no explicit size constraint. If neither prop is provided, the defaults are
159-
600×300.
150+
<code class="rounded bg-gray-100 px-1 text-xs">height</code> props are ignored. The chart
151+
dimensions are determined entirely by the container.
160152
</p>
161153

162-
<div class="space-y-6">
163-
{/* Unconstrained Container */}
164-
<div>
165-
<h3 class="mb-2 text-lg font-medium">Unconstrained Container</h3>
166-
<p class="mb-3 text-sm text-gray-600">
167-
This container has no height constraint. The chart settles at its default minimum
168-
height (300px) without growing infinitely. Try resizing your browser window to see the
169-
width adapt.
170-
</p>
171-
172-
<div class="mb-4 border-2 border-dashed border-blue-300 p-4">
173-
<SolidUplot
174-
autoResize
175-
data={data()}
176-
series={[
177-
{},
178-
{ label: "Auto Resize", stroke: "#8b5cf6", width: 2 },
179-
{ label: "Series B", stroke: "#f59e0b", width: 2 },
180-
]}
181-
scales={{ x: { time: false } }}
182-
childrenPlacement="top"
183-
>
184-
<div
185-
style={{
186-
height: "50px",
187-
background: "#ede9fe",
188-
padding: "8px",
189-
display: "flex",
190-
"align-items": "center",
191-
"justify-content": "center",
192-
}}
193-
>
194-
Child content that adds height
195-
</div>
196-
</SolidUplot>
197-
</div>
198-
199-
<pre class="overflow-x-auto rounded bg-gray-50 p-3 text-sm">
200-
{`<SolidUplot autoResize data={data} series={series} />`}
201-
</pre>
202-
</div>
203-
204-
{/* Constrained Container */}
205-
<div>
206-
<h3 class="mb-2 text-lg font-medium">Constrained Container</h3>
207-
<p class="mb-3 text-sm text-gray-600">
208-
This container has an explicit height (400px). The chart fills the available space via
209-
flexbox, regardless of the default fallback values.
210-
</p>
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>
211159

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+
>
212173
<div
213-
class="mb-4 border-2 border-dashed border-green-300 p-4"
214-
style={{ height: "400px" }}
174+
style={{
175+
height: "50px",
176+
background: "#dbeafe",
177+
padding: "8px",
178+
display: "flex",
179+
"align-items": "center",
180+
"justify-content": "center",
181+
}}
215182
>
216-
<SolidUplot
217-
autoResize
218-
data={data()}
219-
series={[
220-
{},
221-
{ label: "Constrained", stroke: "#22c55e", width: 2 },
222-
{ label: "Series B", stroke: "#06b6d4", width: 2 },
223-
]}
224-
scales={{ x: { time: false } }}
225-
childrenPlacement="top"
226-
>
227-
<div
228-
style={{
229-
height: "50px",
230-
background: "#dcfce7",
231-
padding: "8px",
232-
display: "flex",
233-
"align-items": "center",
234-
"justify-content": "center",
235-
}}
236-
>
237-
Child content that adds height
238-
</div>
239-
</SolidUplot>
183+
Child content that adds height
240184
</div>
185+
</SolidUplot>
186+
</div>
241187

242-
<pre class="overflow-x-auto rounded bg-gray-50 p-3 text-sm">
243-
{`<div style={{ height: '400px' }}>
188+
<pre class="overflow-x-auto rounded bg-gray-50 p-3 text-sm">
189+
{`<div style={{ height: '400px' }}>
244190
<SolidUplot autoResize data={data} series={series} />
245191
</div>`}
246-
</pre>
247-
</div>
248-
</div>
192+
</pre>
249193
</div>
250194

251195
{/* Container-Driven Sizing */}
@@ -282,7 +226,8 @@ export const Resize: Component = () => {
282226
<h3 class="mb-2 text-lg font-medium">AutoSizer</h3>
283227
<p class="mb-3 text-sm text-gray-600">
284228
Wraps the chart in a measuring container and provides width/height via render prop.
285-
Adjust the container size below.
229+
AutoSizer measures the <strong>content area</strong> of its parent (excluding padding
230+
and border), so the chart fits perfectly. Adjust the container size below.
286231
</p>
287232

288233
<div class="mb-4 grid max-w-md grid-cols-1 gap-4 md:grid-cols-2">
@@ -357,7 +302,10 @@ export const Resize: Component = () => {
357302
<h3 class="mb-2 text-lg font-medium">createElementSize</h3>
358303
<p class="mb-3 text-sm text-gray-600">
359304
Observes a container via ref and returns reactive dimensions — no wrapper component
360-
needed. Adjust the container size below.
305+
needed. Since <code class="rounded bg-gray-100 px-1 text-xs">createElementSize</code>{" "}
306+
uses <code class="rounded bg-gray-100 px-1 text-xs">getBoundingClientRect()</code>{" "}
307+
(which measures the <strong>border box</strong> including padding), the ref should
308+
point to an inner element with no padding or border. Adjust the container size below.
361309
</p>
362310

363311
<div class="mb-4 grid max-w-md grid-cols-1 gap-4 md:grid-cols-2">
@@ -392,25 +340,26 @@ export const Resize: Component = () => {
392340
</div>
393341

394342
<div
395-
ref={elementSizeContainer}
396-
class="mb-4 border-2 border-dashed border-amber-300 p-4"
343+
class="mb-4 border-2 border-dashed border-green-300 p-4"
397344
style={{
398345
width: `${elementSizeWidth()}px`,
399346
height: `${elementSizeHeight()}px`,
400347
}}
401348
>
402-
<SolidUplot
403-
data={data()}
404-
width={elementSize.width ?? 0}
405-
height={elementSize.height ?? 0}
406-
style={CHART_STYLE}
407-
series={[
408-
{},
409-
{ label: "ElementSize", stroke: "#f59e0b", width: 2 },
410-
{ label: "Series B", stroke: "#a855f7", width: 2 },
411-
]}
412-
scales={{ x: { time: false } }}
413-
/>
349+
<div ref={elementSizeContainer} style={{ width: "100%", height: "100%" }}>
350+
<SolidUplot
351+
data={data()}
352+
width={elementSize.width ?? 0}
353+
height={elementSize.height ?? 0}
354+
style={CHART_STYLE}
355+
series={[
356+
{},
357+
{ label: "ElementSize", stroke: "#f59e0b", width: 2 },
358+
{ label: "Series B", stroke: "#a855f7", width: 2 },
359+
]}
360+
scales={{ x: { time: false } }}
361+
/>
362+
</div>
414363
</div>
415364

416365
<pre class="overflow-x-auto rounded bg-gray-50 p-3 text-sm">
@@ -419,12 +368,15 @@ export const Resize: Component = () => {
419368
let container!: HTMLDivElement;
420369
const size = createElementSize(() => container);
421370
422-
<div ref={container} style={{ width: '100%', height: '400px' }}>
423-
<SolidUplot
424-
width={size.width ?? 0}
425-
height={size.height ?? 0}
426-
data={data}
427-
/>
371+
<div style={{ width: '100%', height: '400px' }}>
372+
{/* Ref targets an inner div with no padding/border */}
373+
<div ref={container} style={{ width: '100%', height: '100%' }}>
374+
<SolidUplot
375+
width={size.width ?? 0}
376+
height={size.height ?? 0}
377+
data={data}
378+
/>
379+
</div>
428380
</div>`}
429381
</pre>
430382
</div>

0 commit comments

Comments
 (0)