From b99fa2bcc191179502e328e03aad65cf70c9e3b7 Mon Sep 17 00:00:00 2001 From: Kellogg Date: Fri, 24 Jan 2020 15:59:45 -0500 Subject: [PATCH 1/2] adding rdp simplify js package and test which uses it --- js/mx.js | 42 ++++++++++++++++++++++++++++++++++++++++++ package.json | 1 + test/test.html | 3 ++- test/tests.js | 25 +++++++++++++++++++++++++ 4 files changed, 70 insertions(+), 1 deletion(-) diff --git a/js/mx.js b/js/mx.js index 04ad5f4..d6b891e 100644 --- a/js/mx.js +++ b/js/mx.js @@ -5352,6 +5352,40 @@ mx.update_image_row = function(Mx, buf, data, row, zmin, zmax, xcompression) { var imgd = new Uint32Array(buf, row * buf.width * 4, buf.width); + + // special case xcompression type 6 should run outside of for loop + if (data && xcompression === 6) { + console.log('INSIDE OUR SPECIAL CASE!'); + + let formattedData = []; + let simplifiedData = []; + let reformattedData = []; + + console.log('data before simplify: ', data); + + // format data with x and y properties + for (var index = 0; index < data.length; index++) { + value = data[index]; + formattedData.push({ ['x']: index, ['y']: value }); + } + + console.log('our formatted data! ', formattedData); + + // run formatted data through simplify js + simplifiedData = simplify(formattedData, 1, false); + + // reformat array back to original + reformattedData = simplifiedData.map((item) => { + return item.y + }); + + // set data equal to reformatted, simplified data + data = reformattedData; + + console.log('data after simplify: ', data); + } + + Mx.pixel.setRange(zmin, zmax); var xc = Math.max(1, data.length / buf.width); @@ -5360,25 +5394,33 @@ var value = data[didx]; if (xc > 1) { if (xcompression === 1) { // average + console.log('WENT INTO XCOMPRESSION 1!!!!!!!!!!!!!!!!!!!!!!!'); for (var j = 1; j < xc; j++) { value += data[didx + j]; } value = (value / xc); } else if (xcompression === 2) { // min + console.log('WENT INTO XCOMPRESSION 2!!!!!!!!!!!!!!!!!!!!!!!'); for (var j = 1; j < xc; j++) { value = Math.min(value, data[didx + j]); } } else if (xcompression === 3) { // max + console.log('WENT INTO XCOMPRESSION 3!!!!!!!!!!!!!!!!!!!!!!!'); for (var j = 1; j < xc; j++) { value = Math.max(value, data[didx + j]); } } else if (xcompression === 4) { // first + console.log('WENT INTO XCOMPRESSION 4!!!!!!!!!!!!!!!!!!!!!!!'); value = data[i]; } else if (xcompression === 5) { // max abs + console.log('WENT INTO XCOMPRESSION 5!!!!!!!!!!!!!!!!!!!!!!!'); for (var j = 1; j < xc; j++) { value = Math.max(Math.abs(value), Math.abs(data[didx + j])); } + } else if (xcompression === 6) { // RDP Compression / Decimation + console.log('WENT INTO XCOMPRESSION 6!!!!!!!!!!!!!!!!!!!!!!!'); } + } var colorIdx = Mx.pixel.getColorIndex(value); imgd[i] = colorIdx; diff --git a/package.json b/package.json index c0a7c86..7f5f8f7 100644 --- a/package.json +++ b/package.json @@ -40,6 +40,7 @@ }, "dependencies": { "loglevel": "^1.4.1", + "simplify-js": "^1.2.3", "spin": "0.0.1", "tinycolor2": "^1.4.1", "travis": "^0.1.1" diff --git a/test/test.html b/test/test.html index c994db6..ffc4b8f 100644 --- a/test/test.html +++ b/test/test.html @@ -4,7 +4,7 @@ WebSigPlot Unit Test - +