diff --git a/src/draw/index.mjs b/src/draw/index.mjs index 2c45130..3965a68 100644 --- a/src/draw/index.mjs +++ b/src/draw/index.mjs @@ -162,38 +162,42 @@ const draw = (data, _options) => { const endAngle = radial.azimuth * (Math.PI / 180) + halfResolution * 1.1; // plot each bin - radial.moment_data.forEach((bin, idx) => { - if (bin === null) return; + // (a plain for loop avoids per-bin callback-invocation overhead - this runs + // up to ~radials x gates times per elevation/product) + const { moment_data: momentData } = radial; + for (let idx = 0; idx < momentData.length; idx += 1) { + const bin = momentData[idx]; + if (bin !== null) { + // different methods for rrle encoded or not + let color; + let arcEndAngle; + if (bin.count) { + // rrle encoded + color = palette.lookupRgba[bin.value]; + arcEndAngle = endAngle + resolution * (bin.count - 1); + } else { + // plain data + color = palette.lookupRgba[bin]; + arcEndAngle = endAngle; + } - // different methods for rrle encoded or not - let color; - let arcEndAngle; - if (bin.count) { - // rrle encoded - color = palette.lookupRgba[bin.value]; - arcEndAngle = endAngle + resolution * (bin.count - 1); - } else { - // plain data - color = palette.lookupRgba[bin]; - arcEndAngle = endAngle; + // paint and close out the prior path whenever the color changes, since a + // single stroke() call can only use one strokeStyle + if (color !== openStrokeStyle) { + flushStroke(); + ctx.beginPath(); + ctx.strokeStyle = color; + openStrokeStyle = color; + } + + const radius = (idx + deadZone) * gateSizeScaling; + // moveTo to the arc's start point first so this arc becomes its own + // subpath rather than getting connected to the previous arc by a + // straight line (canvas connects consecutive arc() calls otherwise) + ctx.moveTo(radius * Math.cos(startAngle), radius * Math.sin(startAngle)); + ctx.arc(0, 0, radius, startAngle, arcEndAngle); } - - // paint and close out the prior path whenever the color changes, since a - // single stroke() call can only use one strokeStyle - if (color !== openStrokeStyle) { - flushStroke(); - ctx.beginPath(); - ctx.strokeStyle = color; - openStrokeStyle = color; - } - - const radius = (idx + deadZone) * gateSizeScaling; - // moveTo to the arc's start point first so this arc becomes its own - // subpath rather than getting connected to the previous arc by a - // straight line (canvas connects consecutive arc() calls otherwise) - ctx.moveTo(radius * Math.cos(startAngle), radius * Math.sin(startAngle)); - ctx.arc(0, 0, radius, startAngle, arcEndAngle); - }); + } }); // paint whatever is left in the final open path flushStroke(); diff --git a/src/draw/preprocess/indexproduct.mjs b/src/draw/preprocess/indexproduct.mjs index 9daa70f..58c0465 100644 --- a/src/draw/preprocess/indexproduct.mjs +++ b/src/draw/preprocess/indexproduct.mjs @@ -2,11 +2,18 @@ // this is the first step in palettizing and in the Radial run-length encoding process const indexProduct = (radials, palette) => radials.map((radial) => { - const indexedMoment = radial.moment_data.map((bin) => { - if (bin === null) return null; - if (palette.inDeadband(bin)) return null; - return palette.findColorIndex(bin); - }); + // a plain for loop avoids per-bin callback-invocation overhead here - this + // runs up to ~radials x gates times per elevation/product + const { moment_data: momentData } = radial; + const indexedMoment = new Array(momentData.length); + for (let idx = 0; idx < momentData.length; idx += 1) { + const bin = momentData[idx]; + if (bin === null || palette.inDeadband(bin)) { + indexedMoment[idx] = null; + } else { + indexedMoment[idx] = palette.findColorIndex(bin); + } + } return { ...radial, moment_data: indexedMoment,