Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Add a logger to embed init options #732

Open
wants to merge 6 commits into
base: next
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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). |
challet marked this conversation as resolved.
Show resolved Hide resolved
| `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. <br> See [Vega docs](https://vega.github.io/vega/docs/api/view/#view) for details. |
Expand Down
5 changes: 5 additions & 0 deletions src/embed.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ import {
isString,
Loader,
LoaderOptions,
logger as VgLogger,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
logger as VgLogger,
logger as vegaLogger,

LoggerInterface,
mergeConfig,
Renderers,
Spec as VgSpec,
Expand Down Expand Up @@ -68,6 +70,7 @@ export interface EmbedOptions<S = string, R = Renderers> {
mode?: Mode;
theme?: 'excel' | 'ggplot2' | 'quartz' | 'vox' | 'dark';
defaultStyle?: boolean | string;
logger?: LoggerInterface;
logLevel?: number;
loader?: Loader | LoaderOptions;
renderer?: R;
Expand Down Expand Up @@ -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';

Expand Down Expand Up @@ -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} : {}),
Expand Down