I am trying to create a nested map, something like this,
Map<Key1, Map<Key2, Map<Key3, List<Objects>>>>
using d3 map. I don't want to use d3.nest as I want to index my data on custom keys for faster pruning.
My key is getting created as per my expectation, but the moment I try to insert values (List) it's getting inserted in all the keys.
Sample output : <1, <1, <1, [1,2,3,4]> <1, <1, <2, [1,2,3,4]>
Expected output: <1, <1, <1, [1,2]> <1, <1, <2, [3,4]>
I wrote below mentioned code. Could someone point me to right direction what I am doing wrong here:
var dataByYear = d3.map();
var dataByMonth = d3.map();
var map = d3.map();
for (var rowIndex = 0; rowIndex < raw_data_length; rowIndex++) {
var firstID = data[rowIndex].firstKey;
var year = data[rowIndex].year; // year is second key
var month = data[rowIndex].month; // month is third key
if (ID_map.has(firstID)) {
if (dataByYear.has(year)) {
if (dataByMonth.has(month)) {
var dataSet = dataByMonth.get(month);
dataSet.push(data[rowIndex]); //I suspect this is working as a global variable, thats why its updating the array irrespective of keys
dataByMonth.set(month, dataSet);
}
} else {
dataByYear.set(year, new d3.map());
}
} else {
dataByMonth.set(month, []);
dataByYear.set(year, dataByMonth);
ID_map.set(firstID, dataByYear);
}
}