+ if (this.preset.cat !== undefined) {
+ let cats = {}; // category lookup
+ for (let i in json) {
+ let cat = json[i][3];
+ if (!cats[cat]) cats[cat] = [];
+ cats[cat].push(i)
+ }
+
+ rows = [];
+ let children = cats[this.preset.cat];
+ for (let loop = 0; children.length && loop < 20; loop++) {
+ rows.push(...children);
+ children = children.map(cat => cats[cat]).filter(is => is).flat();
+ }
+ rows = rows.map(row => json[row]).filter(row => row[2]);
+ }
+ if (this.preset.level !== undefined) {
+ rows = rows.filter(row => row[1] <= this.preset.level);
+ }
+
+ {
+ let cats = new Set();
+ let subcats = rows.map(row => row[3]); // direct parents
+ for (let loop = 0; subcats.length && loop < 20; loop++) {
+ subcats.forEach(cat => cats.add(cat));
+ subcats = subcats.map(row => json[row] && json[row][3]).filter(val => val); // recurse grandparents
+ }
+ rows = rows.filter(row => !cats.has(row[2])); // remove referenced categories
+ }