Skip to content

Commit 9867cf0

Browse files
committed
catch and log Plot-level errors
1 parent 1978053 commit 9867cf0

File tree

1 file changed

+81
-69
lines changed

1 file changed

+81
-69
lines changed

src/lib/Plot.svelte

Lines changed: 81 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -91,89 +91,101 @@
9191
<!-- There's a bug triggering RangeError: Maximum call stack size exceeded
9292
when using SveltePlot in ssr, so for now, we're disabling it -->
9393

94-
<Plot
95-
{overlay}
96-
{underlay}
97-
{...restOptions}
98-
header={userHeader ||
99-
restOptions.title ||
100-
restOptions.subtitle ||
101-
restOptions.color?.legend ||
102-
restOptions.symbol?.legend
103-
? header
104-
: null}
105-
footer={userFooter || restOptions?.caption ? footer : null}
106-
projection={projectionOpts}
107-
implicitScales
108-
{...scales}>
109-
{#snippet children({
110-
hasProjection,
111-
hasExplicitAxisX,
112-
hasExplicitAxisY,
113-
hasExplicitGridX,
114-
hasExplicitGridY,
115-
options,
116-
scales,
117-
...restProps
118-
})}
119-
<svelte:boundary onerror={(err) => console.warn(err)}>
120-
<!-- implicit axes -->
121-
{#if !hasProjection && !hasExplicitAxisX}
122-
{#if options.axes && (options.x.axis === 'top' || options.x.axis === 'both')}
123-
<AxisX anchor="top" automatic />
94+
<svelte:boundary>
95+
<Plot
96+
{overlay}
97+
{underlay}
98+
{...restOptions}
99+
header={userHeader ||
100+
restOptions.title ||
101+
restOptions.subtitle ||
102+
restOptions.color?.legend ||
103+
restOptions.symbol?.legend
104+
? header
105+
: null}
106+
footer={userFooter || restOptions?.caption ? footer : null}
107+
projection={projectionOpts}
108+
implicitScales
109+
{...scales}>
110+
{#snippet children({
111+
hasProjection,
112+
hasExplicitAxisX,
113+
hasExplicitAxisY,
114+
hasExplicitGridX,
115+
hasExplicitGridY,
116+
options,
117+
scales,
118+
...restProps
119+
})}
120+
<svelte:boundary onerror={(err) => console.warn(err)}>
121+
<!-- implicit axes -->
122+
{#if !hasProjection && !hasExplicitAxisX}
123+
{#if options.axes && (options.x.axis === 'top' || options.x.axis === 'both')}
124+
<AxisX anchor="top" automatic />
125+
{/if}
126+
{#if options.axes && (options.x.axis === 'bottom' || options.x.axis === 'both')}
127+
<AxisX anchor="bottom" automatic />
128+
{/if}
124129
{/if}
125-
{#if options.axes && (options.x.axis === 'bottom' || options.x.axis === 'both')}
126-
<AxisX anchor="bottom" automatic />
130+
{#if !hasProjection && !hasExplicitAxisY}
131+
{#if options.axes && (options.y.axis === 'left' || options.y.axis === 'both')}
132+
<AxisY anchor="left" automatic />
133+
{/if}
134+
{#if options.axes && (options.y.axis === 'right' || options.y.axis === 'both')}
135+
<AxisY anchor="right" automatic />
136+
{/if}
127137
{/if}
128-
{/if}
129-
{#if !hasProjection && !hasExplicitAxisY}
130-
{#if options.axes && (options.y.axis === 'left' || options.y.axis === 'both')}
131-
<AxisY anchor="left" automatic />
138+
<!-- implicit grids -->
139+
{#if !hasExplicitGridX && (options.grid || options.x.grid)}
140+
<GridX automatic />
132141
{/if}
133-
{#if options.axes && (options.y.axis === 'right' || options.y.axis === 'both')}
134-
<AxisY anchor="right" automatic />
142+
{#if !hasExplicitGridY && (options.grid || options.y.grid)}
143+
<GridY automatic />
135144
{/if}
136-
{/if}
137-
<!-- implicit grids -->
138-
{#if !hasExplicitGridX && (options.grid || options.x.grid)}
139-
<GridX automatic />
140-
{/if}
141-
{#if !hasExplicitGridY && (options.grid || options.y.grid)}
142-
<GridY automatic />
143-
{/if}
144-
<!-- implicit frame -->
145-
{#if options.frame}
146-
<Frame automatic />
147-
{/if}
148-
{@render parentChildren?.({
149-
options,
150-
scales,
151-
...restProps
152-
})}
153-
{#snippet failed(error, reset)}
154-
<text class="error" transform="translate(10,10)">
155-
{#each error.message.split('\n') as line, i (i)}
156-
<tspan x="0" dy={i ? 14 : 0}>{line}</tspan>
157-
{/each}
158-
</text>{/snippet}
159-
</svelte:boundary>
160-
{/snippet}
161-
{#snippet facetAxes()}
162-
<FacetAxes />
145+
<!-- implicit frame -->
146+
{#if options.frame}
147+
<Frame automatic />
148+
{/if}
149+
{@render parentChildren?.({
150+
options,
151+
scales,
152+
...restProps
153+
})}
154+
{#snippet failed(error, reset)}
155+
<text class="error" transform="translate(10,10)">
156+
{#each error.message.split('\n') as line, i (i)}
157+
<tspan x="0" dy={i ? 14 : 0}>{line}</tspan>
158+
{/each}
159+
</text>{/snippet}
160+
</svelte:boundary>
161+
{/snippet}
162+
{#snippet facetAxes()}
163+
<FacetAxes />
164+
{/snippet}
165+
</Plot>
166+
{#snippet failed(error)}
167+
<div class="error">Error: {error.message}</div>
163168
{/snippet}
164-
</Plot>
169+
</svelte:boundary>
165170

166171
<style>
167172
:root {
168173
--plot-bg: white;
169174
--plot-fg: currentColor;
170175
}
171-
text.error {
172-
stroke: var(--plot-bg);
173-
fill: crimson;
176+
.error {
174177
font-size: 11px;
175178
stroke-width: 3px;
176179
font-weight: bold;
180+
}
181+
text.error {
182+
stroke: var(--plot-bg);
183+
fill: crimson;
177184
paint-order: stroke fill;
178185
}
186+
div.error {
187+
color: crimson;
188+
white-space: pre-wrap;
189+
line-height: 1.1;
190+
}
179191
</style>

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy