Skip to content

Commit

Permalink
Add mapToObject to handle nested data
Browse files Browse the repository at this point in the history
[skip ci]
  • Loading branch information
hoxbro committed Feb 5, 2024
1 parent 9ba3d7a commit e3582b8
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion panel/models/vega.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,20 @@ import {set_size} from "./layout"
import {debounce} from "debounce"


function mapToObject(map: Map<any, any>): any {
const obj: Record<string, any> = {};

map.forEach((value, key) => {
if (value instanceof Map) {
obj[key] = mapToObject(value);
} else {
obj[key] = value;
}
});

return obj;
}

export class VegaEvent extends ModelEvent {
constructor(readonly data: any) {
super()
Expand Down Expand Up @@ -147,8 +161,9 @@ export class VegaPlotView extends LayoutDOMView {
this.model.data['datasets'] = datasets
}
const config: any = {actions: this.model.show_actions, theme: this.model.theme};
const embed_data = mapToObject(this.model.data);

(window as any).vegaEmbed(this.container, this.model.data, config).then((result: any) => {
(window as any).vegaEmbed(this.container, embed_data, config).then((result: any) => {
this.vega_view = result.view
this._resize = debounce(() => this.resize_view(result.view), 50)
const callback = (name: string, value: any) => this._dispatch_event(name, value)
Expand Down

0 comments on commit e3582b8

Please sign in to comment.