@@ -206,44 +206,29 @@ need to pass the necessary request headers and configuration as well.
206
206
207
207
#### ` getExportURL?: (...args) => URL | (() => Promise<URL | Blob>) | undefined ` (optional)
208
208
209
- The ` DataProvider#getExportURL ` method is used by the toolbars to generate URLs
210
- and controls for exporting the current dataset/slice to various formats. This
211
- prop allows providing your own implementation of this method .
209
+ Some visualizations allow exporting the current dataset/slice to various
210
+ formats. For instance, the _ Line _ visualization allows exporting to CSV and NPY;
211
+ the _ Heatmap _ visualization to NPY and TIFF, etc .
212
212
213
- ` getExportURL ` is called once for every export menu entry. It receives the
214
- export ` format ` , as well as the current ` dataset ` metadata object, ` selection `
215
- string, and ` value ` array. The export entry behaviour then depends of the return
216
- type:
213
+ For each format, the viewer invokes the provider's ` getExportURL ` method. If
214
+ this method returns a ` URL ` or an async function, then the export menu in the
215
+ toolbar shows an entry for the corresponding export format.
217
216
218
- - ` URL ` : the URL is set as the ` href ` of the export entry's download anchor.
219
- - ` () => Promise<URL | Blob> ` : the function is called when the user clicks on
220
- the export entry. When the promise resolves, the returned ` URL ` or ` Blob ` is
221
- used to trigger a download.
222
- - ` undefined ` : the export entry is not rendered.
217
+ In the case of JSON and CSV, the viewer itself takes care of the export by
218
+ providing its own "exporter" function to the ` getExportURL ` method. When this
219
+ happens, the ` getExportURL ` method just returns a function that calls the
220
+ exporter.
223
221
224
- Returning an async function enables advanced use cases like generating exports
225
- client-side, or server-side but from an authenticated endpoint.
222
+ In the case of NPY and TIFF, ` H5GroveApi#getExportURL ` returns a ` URL ` so the
223
+ export can be generated server-side by ` h5grove ` .
224
+
225
+ The optional ` getExportURL ` prop is called internally by the ` getExportURL `
226
+ method and allows taking over the export process. It enables advanced use cases
227
+ like generating exports from an authenticated endpoint.
226
228
227
229
<details >
228
230
<summary >Advanced examples</summary >
229
231
230
- ``` tsx
231
- // Client-side CSV export
232
- getExportURL = {(format , dataset , selection , value) => {
233
- if (format === ' csv' ) {
234
- // Async function that will be called when the user clicks on a `CSV` export menu entry
235
- return async () => {
236
- // Generate CSV string from `value` array
237
- let csv = ' ' ;
238
- value .forEach ((val ) => { ... })
239
-
240
- // Return CSV string as Blob so it can be downloaded
241
- return new Blob ([csv ]);
242
- };
243
- }
244
- }}
245
- ```
246
-
247
232
``` tsx
248
233
// Fetch export data from authenticated endpoint
249
234
getExportURL = {(format , dataset , selection) => async () => {
@@ -269,12 +254,19 @@ getExportURL={(format, dataset, selection) => async () => {
269
254
}}
270
255
```
271
256
272
- </details >
257
+ ``` tsx
258
+ // Tweak a built-in export payload in some way (round or format numbers, truncate lines, etc.)
259
+ getExportURL = {(format , dataset , selection , builtInExporter) => async () => {
260
+ if (!builtInExporter || format !== ' csv' ) {
261
+ return undefined ;
262
+ }
263
+
264
+ const csvPayload = builtInExporter ();
265
+ return csvPayload .split (' \n ' ).slice (0, 100).join (' \n ' ); // truncate to first 100 lines
266
+ }}
267
+ ```
273
268
274
- You may provide a partial implementation of ` getExportURL ` that handles only
275
- specific export scenarios. In this case, or if you don't provide a function at
276
- all, ` H5GroveProvider ` falls back to generating URLs based on the ` /data `
277
- endpoint and ` format ` query param.
269
+ </details >
278
270
279
271
#### ` resetKeys?: unknown[] ` (optional)
280
272
@@ -343,9 +335,7 @@ The path of the file to request.
343
335
See
344
336
[ ` H5GroveProvider#getExportURL ` ] ( https://github.com/silx-kit/h5web/blob/main/packages/app/README.md#getexporturl-args--url----promiseurl--blob--undefined-optional ) .
345
337
346
- ` HsdsProvider ` does not provide a fallback implementation of ` getExportURL ` at
347
- this time, so if you don't provide your own, the export menu will remain
348
- disabled in the toolbar.
338
+ ` HsdsProvider ` doesn't support the NPY and TIFF export formats out of the box.
349
339
350
340
#### ` resetKeys?: unknown[] ` (optional)
351
341
@@ -367,8 +357,7 @@ Data provider for demonstration and testing purposes.
367
357
See
368
358
[ ` H5GroveProvider#getExportURL ` ] ( https://github.com/silx-kit/h5web/blob/main/packages/app/README.md#getexporturl-args--url----promiseurl--blob--undefined-optional ) .
369
359
370
- ` MockProvider ` provides a very basic fallback implementation of ` getExportURL `
371
- that can generate only client-side CSV exports of 1D datasets.
360
+ ` MockProvider ` doesn't support the NPY and TIFF export formats out of the box.
372
361
373
362
### Utilities
374
363
0 commit comments