From 1ec2324b834756cb619c30c7be16c3449556a499 Mon Sep 17 00:00:00 2001 From: javi Date: Tue, 10 Nov 2015 15:14:39 +0100 Subject: [PATCH] fixed category count --- lib/torque/provider/filterableJson.js | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/lib/torque/provider/filterableJson.js b/lib/torque/provider/filterableJson.js index ea86295..03377b8 100644 --- a/lib/torque/provider/filterableJson.js +++ b/lib/torque/provider/filterableJson.js @@ -24,12 +24,14 @@ var Profiler = require('../profiler'); this._filters = {}; // category mapping for each column this.categoryMapping = {} + this.categoryMappingSize = {} // generate the mapping, global for all the tiles var fields = this.options.fields; for (var i = 0 ; i < fields.length; ++i) { if (fields[i].type === 'cat') { this.categoryMapping[fields[i].name] = {} + this.categoryMappingSize[fields[i].name] = 0; } } @@ -112,12 +114,17 @@ var Profiler = require('../profiler'); if (this.options.fields[j].type === 'cat') { var mapping = this.categoryMapping[this.options.fields[j].name]; var m = mapping[v] - var count = Object.keys(mapping).length - if (!m && count < 100) { - mapping[v] = 0; + if (!m) { + var count = this.categoryMappingSize[this.options.fields[j].name]; + if (count < 100) { + ++this.categoryMappingSize[this.options.fields[j].name]; + v = mapping[v] = count; + } else { + v = 0; + } + } else { + v = m; } - mapping[v] += 1; - v = m } rr.push([r, v]); }