From 9d811bcc48de7d5b7fd5c20671c6ea57d26bbfdf Mon Sep 17 00:00:00 2001 From: Matt Walsh Date: Thu, 5 Aug 2021 22:54:05 -0500 Subject: [PATCH] export palette and canvas --- README.md | 22 ++++++++++++++++++---- src/draw/index.js | 7 ++++++- 2 files changed, 24 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 9ebc916..40e82dd 100644 --- a/README.md +++ b/README.md @@ -19,7 +19,7 @@ const file = fs.readFileSync(''); const level2Plot = plot(file, {elevation: 1, product: 'REF'}); // use bundled utility to write to disk (async () => { - await writePngToFile('.png', level2Plot.REF); + await writePngToFile('.png', level2Plot.REF.canvas); })(); ``` # Data @@ -47,13 +47,27 @@ Test code and data is provided in the `./demo` folder. `test.js` can be used to # API ## plot(data, products, options) -Returns a [Canvas](https://www.npmjs.com/package/canvas) object. -> Note: May return false if no data was found for the specified elevation and product. +Returns an object +``` javascript + { + REF: { + canvas: , + palette: + }, + //... additional products + } +``` +The first level key in the returned object represents each requested product. +> Note: Each product may return false if no data was found for the specified elevation and product. + +```[canvas](https://www.npmjs.com/package/canvas)``` contains the plotted data and functions for outputtting various image formats. + +```palette``` is an array that can be used to create palletized images from the canvas library. |Paramater|Type|Default|Description| |---|---|---|---| data|Level2Radar||Output from [nexrad-level-2-data](https://github.com/netbymatt/nexrad-level-2-data/). -products|Array of strings|Individual strings as shown in supported products to specify the products to be plotted. +products|Array of strings|All|Individual strings as shown in supported products to specify the products to be plotted. options.size|integer|1800|1 to 1800. Size of the x and y axis in pixels. The image must be square so only a single integer is needed. See [downsampling](#downsampling) options.background|string|#000000|Background color of the image. This can be transparent by using #RGBA notation. See [ctx.fillStyle](https://developer.mozilla.org/en-US/docs/Web/API/CanvasRenderingContext2D/fillStyle) for more information. options.lineWidth|integer|2|The raster image is created by drawing several arcs at the locations and colors specified in the data file. When scaling down you may get a better looking image by adjusting this value to something large than the default. diff --git a/src/draw/index.js b/src/draw/index.js index 0e48dbf..5b35ed5 100644 --- a/src/draw/index.js +++ b/src/draw/index.js @@ -136,7 +136,12 @@ const draw = (data, _options) => { ctx.stroke(); }); }); - return canvas; + + // return the palette and canvas + return { + canvas, + palette: palette.getPalette(), + }; }; module.exports = {