diff --git a/README.md b/README.md index ff049fd..be5e44e 100644 --- a/README.md +++ b/README.md @@ -10,18 +10,36 @@ API and connection handler to connect with [R httpgd servers](https://github.com ## Usage +### Base usage + Minimal example how to listen for server side changes: ```JavaScript -import 'httpgd'; +import { Httpgd } from 'httpgd'; const httpgd = new Httpgd('127.0.0.1:1234', 'mytoken', true); httpgd.onPlotsChanged((newState) => console.log(newState)); httpgd.connect(); + +// httpgd.removePlot(...) +// httpgd.getPlotURL(...) ``` Advanced usage example: The client included in the [httpgd R package](https://github.com/nx10/httpgd). +### Direct API access + +In applications where there is no need to continuously listen for server side changes, `httpgd` APIs can also be called directly using the `api` module. + +Example: + +```JavaScript +import { url_plot } from 'httpgd/lib/api'; + +const url = url_plot({ host: '127.0.0.1:1234' }, { id: 'myPlotId' }); +document.getElementsByTagName('img')[0].src = url; +``` + ## License MIT \ No newline at end of file diff --git a/package.json b/package.json index 3628b64..0d107de 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "httpgd", - "version": "0.1.1", - "description": "API wrapper and connection helpers to connect with R httpgd servers.", + "version": "0.1.2", + "description": "R httpgd GraphicsDevice API and connection handler", "main": "lib/httpgd.js", "types": "lib/httpgd.d.ts", "scripts": { @@ -15,8 +15,17 @@ "version": "npm run format && git add -A src", "postversion": "git push && git push --tags" }, + "repository": { + "type": "git", + "url": "git+https://github.com/nx10/httpgd-js.git" + }, + "keywords": ["httpgd", "R", "Plot", "Graphics"], "author": "Florian Rupprecht", "license": "MIT", + "bugs": { + "url": "https://github.com/nx10/httpgd-js/issues" + }, + "homepage": "https://github.com/nx10/httpgd-js#readme", "devDependencies": { "@typescript-eslint/eslint-plugin": "^4.31.2", "@typescript-eslint/parser": "^4.31.2", diff --git a/src/types.ts b/src/types.ts index c938de4..ca6bf0d 100644 --- a/src/types.ts +++ b/src/types.ts @@ -1,25 +1,38 @@ +/** + * Access parameters to a httpgd server. + */ export interface HttpgdBackend { host: string; token?: string; } -// API response objects - +/** + * Defines the httpgd server state. + */ export interface HttpgdStateResponse { upid: number; hsize: number; active: boolean; } +/** + * Plot ID object + */ export interface HttpgdIdResponse { id: string; } +/** + * List of plot IDs + */ export interface HttpgdPlotsResponse { state: HttpgdStateResponse; plots: HttpgdIdResponse[]; } +/** + * Renderer meta information + */ export interface HttpgdRendererResponse { id: string; mime: string; @@ -29,12 +42,16 @@ export interface HttpgdRendererResponse { bin: boolean; } +/** + * List of renderers + */ export interface HttpgdRenderersResponse { renderers: HttpgdRendererResponse[]; } -// API request objects - +/** + * Plot request parameters + */ export interface HttpgdPlotRequest { id?: string; renderer?: string; @@ -44,6 +61,9 @@ export interface HttpgdPlotRequest { download?: string; } +/** + * Remove request parameters + */ export interface HttpgdRemoveRequest { id: string; }