gnuplot-wasm

0.0.1 • Public • Published

gnuplot compiled to wasm

Experiment. I took idea from gnuplot-in-the-browser and tried to make ES6 module distributed in npm. I tried to create minimal API with single usecase in mind - generate SVG and output it as string.

import gnuplot from "gnuplot-wasm";

const script = `
  set key fixed left top vertical Right noreverse enhanced autotitle box lt black linewidth 1.000 dashtype solid
  set samples 1000, 1000
  plot [-10:10] sin(x),atan(x),cos(atan(x))`;

const { render } = await gnuplot();
const { svg } = render(script);

Will produce:

Example of generated graph

Hack for WASM in Vite

import gnuplot from "gnuplot-wasm";

import { createRequire } from "module";
const require = createRequire(import.meta.url);
const wasmPath = require.resolve("gnuplot-wasm/src/gnuplot.wasm");

const { render } = await gnuplot({
  locateFile: () => wasmPath,
});

See:

Other oprions

Build

To build locally you need docker and shell (plus tar, wget):

sh build.sh

TODO

  • smaller size
  • github action for npm deployment
  • test in browser
  • typescript signatures
    • --emit-tsd gnuplot.d.ts, but it requires Typescript, which mean I need to create custom Dcoker image with node, npm, TypeScript
  • update to gnuplot v6

Package Sidebar

Install

npm i gnuplot-wasm

Weekly Downloads

4

Version

0.0.1

License

MIT

Unpacked Size

1.62 MB

Total Files

6

Last publish

Collaborators

  • stereobooster