Skip to content

Commit

Permalink
Update documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
nx10 committed Sep 22, 2021
1 parent e004dff commit 0f15732
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 7 deletions.
20 changes: 19 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
13 changes: 11 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -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": {
Expand All @@ -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",
Expand Down
28 changes: 24 additions & 4 deletions src/types.ts
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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;
Expand All @@ -44,6 +61,9 @@ export interface HttpgdPlotRequest {
download?: string;
}

/**
* Remove request parameters
*/
export interface HttpgdRemoveRequest {
id: string;
}

0 comments on commit 0f15732

Please sign in to comment.