diff --git a/src/api.ts b/src/api.ts index f5916a2..c966ffa 100644 --- a/src/api.ts +++ b/src/api.ts @@ -25,7 +25,7 @@ function make_headers(b: HttpgdBackend): Headers { return headers; } -async function fetch_url( +async function fetch_json( b: HttpgdBackend, url: string ): Promise { @@ -74,7 +74,7 @@ export function url_state(b: HttpgdBackend): string { * @returns Response promise */ export function fetch_state(b: HttpgdBackend): Promise { - return fetch_url(b, url_state(b)); + return fetch_json(b, url_state(b)); } // /clear @@ -96,7 +96,7 @@ export function url_clear(b: HttpgdBackend): string { * @returns Response promise */ export function fetch_clear(b: HttpgdBackend): Promise { - return fetch_url(b, url_clear(b)); + return fetch_json(b, url_clear(b)); } // /renderers @@ -120,7 +120,7 @@ export function url_renderers(b: HttpgdBackend): string { export function fetch_renderers( b: HttpgdBackend ): Promise { - return fetch_url(b, url_renderers(b)); + return fetch_json(b, url_renderers(b)); } // /plots @@ -142,7 +142,7 @@ export function url_plots(b: HttpgdBackend): string { * @returns Response promise */ export function fetch_plots(b: HttpgdBackend): Promise { - return fetch_url(b, url_plots(b)); + return fetch_json(b, url_plots(b)); } // /plot @@ -187,10 +187,11 @@ export function url_plot( export function fetch_plot( b: HttpgdBackend, r: HttpgdPlotRequest - // eslint-disable-next-line @typescript-eslint/no-explicit-any -): Promise { - // eslint-disable-next-line @typescript-eslint/no-explicit-any - return fetch_url(b, url_plot(b, r)); +): Promise { + const res = fetch(url_plot(b, r), { + headers: make_headers(b) + }); + return res; } // /remove @@ -219,5 +220,5 @@ export function fetch_remove( b: HttpgdBackend, r: HttpgdRemoveRequest ): Promise { - return fetch_url(b, url_remove(b, r)); + return fetch_json(b, url_remove(b, r)); } diff --git a/src/httpgd.ts b/src/httpgd.ts index e86f54f..b39fc1f 100644 --- a/src/httpgd.ts +++ b/src/httpgd.ts @@ -1,5 +1,6 @@ import { fetch_clear, + fetch_plot, fetch_plots, fetch_remove, fetch_renderers, @@ -148,6 +149,16 @@ export class Httpgd { : undefined; } + /** + * Get rendered plot data. + * + * @param r Plot request object. + * @returns Plot data + */ + public getPlot(r: HttpgdPlotRequest): Promise | undefined { + return this.data.plots ? fetch_plot(this.backend, r) : undefined; + } + /** * Listen to plot changes. *