From 1ef5053ca0ca31840bb7053ba7b8a6dc0d8e2df1 Mon Sep 17 00:00:00 2001 From: Matt Walsh Date: Wed, 13 Jul 2022 10:34:29 -0500 Subject: [PATCH] add canvas options --- README.md | 6 ++++++ src/draw/index.js | 7 ++++++- src/index.js | 3 +++ 3 files changed, 15 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index e1635a5..0d1a06a 100644 --- a/README.md +++ b/README.md @@ -79,6 +79,9 @@ options.lineWidth|integer|2|The raster image is created by drawing several arcs options.palettize|boolean\|object|false|After drawing the image convert the image from RGBA to a palettized image. When true the same palette as the product is used. Additional options are described in [palettizing](#palettizing). This can significantly reduce the size of the resulting image with minimal loss of clarity. options.elevations|undefined\|integer\|Array of integers|undefined|The specific elevations to plot. If undefined (default) all available elevations will be plotted. If an integer is provided a single elevation will be plotted with all the selected ```products```. If an array of integers are provided each ```products``` in each elevation will be plotted. Note that when a product and elevation combination do not exist the returned object will have false in the missing location. This is common where elevation 1 will have reflectivity data and elevation 2 (altough at the same angle as elevation 1) will contain velocity data. options.usePreferredWaveforms|boolean|true|Waveform types of 1, 2, 3, 4 and 5 are produced by the radar. Type 1 is typically exclusive to reflectivity, Type 2 is typically exclusive to velocity however it also produces reflectivity data. Types 3, 4 and 5 all produce both velocity and reflectivity. When set to true type 1 waveforms will not plot velocity data, and type 2 waveforms will not plot reflectivity data. If you must see all information set this to false. +options.alpha|boolean|true|Draw on a 32-bit canvas. Passed directly to getContext('2d', {alpha}). +options.imageSmoothingEnabled|boolean|true|Enable image smoothing. Passed directly to ctx.imageSmoothingEnabled. +options.antialias|string|'default'|Enable antialias. Passed directly to ctx.antialias (part of node-canvas) ### Downsampling A full size plot is 3600 x 3600 pixels. This corresponds to the maximum range of the radar 460km (~250 mi) * maximum resolution 0.25 mi/bin * 2 (east and west side of radar). @@ -114,6 +117,9 @@ data|{canvas[palette]}|Typically the output of [plot()](#plotfile-options).\ { @@ -85,7 +88,9 @@ const draw = (data, _options) => { // create the canvas and context const canvas = createCanvas(cropTo, cropTo); - const ctx = canvas.getContext('2d'); + const ctx = canvas.getContext('2d', { alpha: options.alpha }); + ctx.antialias = options.antialias; + ctx.imageSmoothingEnabled = options.imageSmoothingEnabled; // fill background with black ctx.fillStyle = options.background; diff --git a/src/index.js b/src/index.js index 7a9e089..ba5a735 100644 --- a/src/index.js +++ b/src/index.js @@ -12,6 +12,9 @@ const { writePngToFile } = require('./utils/file'); * @param {(boolean|object)} [options.palettize] After drawing the image convert the image from RGBA to a palettized image. When true the same palette as the product is used. * @param {(undefined|number|number[])} [options.elevations=undefined] List of elevations to plot. * @param {boolean} [options.usePreferredWaveforms = true] Limit the plotted data to the preferred use of waveforms 1 and 2. + * @param {boolean} [options.alpha = true] Draw on a 32-bit canvas. Passed directly to getContext('2d', {alpha}). + * @param {boolean} [options.imageSmoothingEnabled = true] Control image smoothing. Passed directly to ctx.imageSmoothingEnabled. + * @param {string} [options.antialias = 'default'] Control antialias. Passed directly to ctx.antialias (part of node-canvas) * @returns Canvas */ const plot = (data, _products, options) => {