-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactoring, configure linters (#39)
- Loading branch information
1 parent
3fff6ad
commit 4ddeb03
Showing
12 changed files
with
331 additions
and
161 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
import * as echartslib from "echarts"; | ||
import * as helpers from "./helpers"; | ||
import { render_d3sankey } from "./sankey"; | ||
import { PanelCtx } from "./types"; | ||
|
||
function runFunction(src: string, args: Record<string, any>): Promise<any> { | ||
const AsyncFunction = async function () {}.constructor; | ||
const params = Object.entries(args); | ||
const fn = AsyncFunction( | ||
params.map(([k, _]) => k), | ||
src, | ||
); | ||
return fn(...params.map(([_, v]) => v)); | ||
} | ||
|
||
function runScript(ctx: PanelCtx) { | ||
return runFunction(ctx.panel.script!, { | ||
...ctx, | ||
// pass 'fava' and 'helpers' for backwards compatibility | ||
fava: ctx.ledger, | ||
helpers, | ||
}); | ||
} | ||
|
||
export async function html(ctx: PanelCtx, elem: HTMLDivElement) { | ||
try { | ||
elem.innerHTML = await runScript(ctx); | ||
} catch (e) { | ||
elem.innerHTML = e; | ||
} | ||
} | ||
|
||
export async function echarts(ctx: PanelCtx, elem: HTMLDivElement) { | ||
let options: echartslib.EChartsOption; | ||
try { | ||
options = await runScript(ctx); | ||
} catch (e) { | ||
elem.innerHTML = e; | ||
return; | ||
} | ||
|
||
const renderer = window.navigator.userAgent === "puppeteer" ? "svg" : undefined; | ||
const chart = echartslib.init(elem, undefined, { renderer }); | ||
if (options.onClick) { | ||
chart.on("click", (options as any).onClick); | ||
delete options.onClick; | ||
} | ||
if (options.onDblClick) { | ||
chart.on("dblclick", (options as any).onDblClick); | ||
delete options.onDblClick; | ||
} | ||
chart.setOption(options); | ||
} | ||
|
||
export async function d3_sankey(ctx: PanelCtx, elem: HTMLDivElement) { | ||
let options: any; | ||
try { | ||
options = await runScript(ctx); | ||
} catch (e) { | ||
elem.innerHTML = e; | ||
return; | ||
} | ||
|
||
render_d3sankey(elem, options); | ||
} | ||
|
||
export async function jinja2(ctx: PanelCtx, elem: HTMLDivElement) { | ||
elem.innerHTML = ctx.panel.template ?? ""; | ||
} |
Oops, something went wrong.