From e67761cad2dc4d7289923f75aeeabe9208971fbd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20Hallet?= Date: Wed, 4 Aug 2021 16:23:22 +0200 Subject: [PATCH 1/6] Add a logger to embed init options --- src/embed.ts | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/embed.ts b/src/embed.ts index 1f95fdb9..78c1b81b 100644 --- a/src/embed.ts +++ b/src/embed.ts @@ -10,6 +10,8 @@ import { isString, Loader, LoaderOptions, + logger as VgLogger, + LoggerInterface, mergeConfig, Renderers, Spec as VgSpec, @@ -68,6 +70,7 @@ export interface EmbedOptions { mode?: Mode; theme?: 'excel' | 'ggplot2' | 'quartz' | 'vox' | 'dark'; defaultStyle?: boolean | string; + logger?: LoggerInterface; logLevel?: number; loader?: Loader | LoaderOptions; renderer?: R; @@ -275,6 +278,7 @@ async function _embed( const i18n = {...I18N, ...opts.i18n}; const renderer = opts.renderer ?? 'canvas'; + const logger = opts.logger ?? VgLogger(); const logLevel = opts.logLevel ?? vega.Warn; const downloadFileName = opts.downloadFileName ?? 'visualization'; @@ -352,6 +356,7 @@ async function _embed( const view = new (opts.viewClass || vega.View)(runtime, { loader, + logger, logLevel, renderer, ...(ast ? {expr: (vega as any).expressionInterpreter} : {}), From a22deb0509b5410c5d647e9dc9308500daab51cf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20Hallet?= Date: Wed, 4 Aug 2021 16:29:29 +0200 Subject: [PATCH 2/6] update doc --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index 774e6fe4..484f3204 100644 --- a/README.md +++ b/README.md @@ -180,6 +180,7 @@ var opt = { | `defaultStyle` | Boolean or String | If set to `true` (default), the embed actions are shown in a menu. Set to `false` to use simple links. Provide a string to set the style sheet. | | `bind` | String or Element | The element that should contain any input elements bound to signals. | | `renderer` | String | The renderer to use for the view. One of `"canvas"` (default) or `"svg"`. See [Vega docs](https://vega.github.io/vega/docs/api/view/#view_renderer) for details. May be a custom value if passing your own `viewClass` option. | +| `logger` | Object | Sets a custom logger handler. See [Vega docs](https://vega.github.io/vega/docs/api/view/#view_logger) for details. It must follow the interface of [the original one](https://github.com/vega/vega/tree/master/packages/vega-util#logger). | | `logLevel` | Level | Sets the current log level. See [Vega docs](https://vega.github.io/vega/docs/api/view/#view_logLevel) for details. | | `tooltip` | Handler or Boolean or Object | Provide a [tooltip handler](https://vega.github.io/vega/docs/api/view/#view_tooltip), customize the default [Vega Tooltip](https://github.com/vega/vega-tooltip) handler, or disable the default handler. | | `loader` | Loader / Object | _Loader_ : Sets a custom Vega loader. _Object_ : Vega loader options for a loader that will be created.
See [Vega docs](https://vega.github.io/vega/docs/api/view/#view) for details. | From 24f1620cbb6ac87542dc3be1f8112d4142c81af3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20Hallet?= Date: Thu, 5 Aug 2021 11:02:59 +0200 Subject: [PATCH 3/6] Update README.md Co-authored-by: Dominik Moritz --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 484f3204..20abad22 100644 --- a/README.md +++ b/README.md @@ -180,7 +180,7 @@ var opt = { | `defaultStyle` | Boolean or String | If set to `true` (default), the embed actions are shown in a menu. Set to `false` to use simple links. Provide a string to set the style sheet. | | `bind` | String or Element | The element that should contain any input elements bound to signals. | | `renderer` | String | The renderer to use for the view. One of `"canvas"` (default) or `"svg"`. See [Vega docs](https://vega.github.io/vega/docs/api/view/#view_renderer) for details. May be a custom value if passing your own `viewClass` option. | -| `logger` | Object | Sets a custom logger handler. See [Vega docs](https://vega.github.io/vega/docs/api/view/#view_logger) for details. It must follow the interface of [the original one](https://github.com/vega/vega/tree/master/packages/vega-util#logger). | +| `logger` | Object | Sets a [custom logger handler on the view](https://vega.github.io/vega/docs/api/view/#view_logger). A logger must implement the [Vega logger API](https://github.com/vega/vega/tree/master/packages/vega-util#logger). | | `logLevel` | Level | Sets the current log level. See [Vega docs](https://vega.github.io/vega/docs/api/view/#view_logLevel) for details. | | `tooltip` | Handler or Boolean or Object | Provide a [tooltip handler](https://vega.github.io/vega/docs/api/view/#view_tooltip), customize the default [Vega Tooltip](https://github.com/vega/vega-tooltip) handler, or disable the default handler. | | `loader` | Loader / Object | _Loader_ : Sets a custom Vega loader. _Object_ : Vega loader options for a loader that will be created.
See [Vega docs](https://vega.github.io/vega/docs/api/view/#view) for details. | From 81065ec091a8417c8f90674350a6641734227aaa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20Hallet?= Date: Thu, 5 Aug 2021 11:03:46 +0200 Subject: [PATCH 4/6] rename an import --- src/embed.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/embed.ts b/src/embed.ts index 78c1b81b..69005b35 100644 --- a/src/embed.ts +++ b/src/embed.ts @@ -10,7 +10,7 @@ import { isString, Loader, LoaderOptions, - logger as VgLogger, + logger as vegaLogger, LoggerInterface, mergeConfig, Renderers, @@ -278,7 +278,7 @@ async function _embed( const i18n = {...I18N, ...opts.i18n}; const renderer = opts.renderer ?? 'canvas'; - const logger = opts.logger ?? VgLogger(); + const logger = opts.logger ?? vegaLogger(); const logLevel = opts.logLevel ?? vega.Warn; const downloadFileName = opts.downloadFileName ?? 'visualization'; From 15a97f60736859a12db83454fc68b7a154445a32 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20Hallet?= Date: Thu, 5 Aug 2021 17:28:09 +0200 Subject: [PATCH 5/6] add a test --- test/embed.test.ts | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/test/embed.test.ts b/test/embed.test.ts index 52fff1f2..00a93117 100644 --- a/test/embed.test.ts +++ b/test/embed.test.ts @@ -385,3 +385,11 @@ test('can set loader via usermeta', async () => { target: '_blank', }); }); + +test('can set logger', async () => { + const el = document.createElement('div'); + const logger = vega.logger(); + const result = await embed(el, vlSpec, {logger}); + expect(result).toBeTruthy(); + expect((result.view as any)._log).toEqual(logger); +}); From 7c57477fe189bc801df3dfb55e06900acdc21c9e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20Hallet?= Date: Mon, 31 Jan 2022 17:36:33 +0100 Subject: [PATCH 6/6] Pass the logger to vegaLite --- src/embed.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/embed.ts b/src/embed.ts index 69005b35..3c2a6b7d 100644 --- a/src/embed.ts +++ b/src/embed.ts @@ -304,7 +304,7 @@ async function _embed( const mode = guessMode(spec, opts.mode); - let vgSpec: VgSpec = PREPROCESSOR[mode](spec, config); + let vgSpec: VgSpec = PREPROCESSOR[mode](spec, { ...config, logger }); if (mode === 'vega-lite') { if (vgSpec.$schema) {