Browse Source

fix: handle 0 in factor ratio correctly

jmacura 5 years ago
parent
commit
e4bdfd2f9b
1 changed files with 4 additions and 3 deletions
  1. 4 3
      nuts-data.js

+ 4 - 3
nuts-data.js

@@ -109,11 +109,11 @@ module.exports.modifyClusteringData = async function ({datasets, data, params, o
         allowedDatasets = [...allowedDatasets, ...factor.datasets];
     }
     const factorMultipliers = data[0].map((dataset) => {
+        if (dataset === 'NUTS_ID') return 1;
         const factor = datasets.find(ds => ds.Name === dataset);
         if (!factor) {
             /* If the factor is unknown for this dataset, it will effectivelly turn it off */
             console.log(`Undefined factor for dataset ${dataset}`);
-            allowedDatasets.filter(ds => ds !== dataset);
             return 0;
         } else if (!allowedDatasets.includes(dataset)) {
             return 0;
@@ -127,9 +127,10 @@ module.exports.modifyClusteringData = async function ({datasets, data, params, o
         return row.map((value, i) => {
             if (idx == 0) {
                 /* These are the headers */
-                return allowedDatasets.includes(value) ? value : null;
+                /* Have to check for both allowed datasets and zero multiplications */
+                return allowedDatasets.includes(value) && factorMultipliers[i] !== 0 ? value : null;
             } else if (isNaN(value)) {
-                /* This is the NUTS ID record */
+                /* This is the NUTS ID record at the beginning of each line */
                 return value;
             }
             return factorMultipliers[i] === 0 ? null : value*factorMultipliers[i];