dc.js Flatten Data vs Array of Objects and filtering

喜你入骨 提交于 2021-02-08 11:17:17

问题


I would like to understand if the following is possible. If have two jsFiddle examples with the same dataset. One contains an array of objects while the other is flatten. I have also added some records that are not fully scoped.

Can the filter on the scatter plot work correctly for the Array of Objects dataset?

Data - Flatten : jsFiddle Example

var data = [
    {"_uid":  1, "business": 'Resort',   "state": {name: 'Virginia', startups: 15}},
    {"_uid":  1, "business": 'Resort',   "state": {name: 'Maryland', startups:  6}},
    {"_uid":  3, "business": 'Training', "state": {name: 'Virginia', startups:  4}},
    {"_uid":  3, "business": 'Training', "state": {name: 'Maryland', startups:  2}},
    {"_uid":  3, "business": 'Training', "state": {name: 'D.C.',     startups:  3}},
    {"_uid":  4, "business": 'Sitting'},
    {"_uid":  5, "business": 'Vet',      "state": {name: 'Virginia', startups:  4}},
    {"_uid":  6, "business": 'Parties',  "state": {}},
    {"_uid":  7, "business": 'Grooming', "state": {name: 'Virginia', startups:  4}},
    {"_uid":  7, "business": 'Grooming', "state": {name: 'D.C.',     startups:  3}},
    ];

Data - Array of Objects : jsFiddle Example

var data = [
    {"_uid":  1, "business": 'Resort',   "states": [{state: 'Virginia', startups: 15}, {state: 'Maryland', startups: 6}]},
    {"_uid":  3, "business": 'Training', "states": [{state: 'Virginia', startups: 4}, {state: 'Maryland', startups: 2}, {state: 'D.C.', startups: 3}]},
    {"_uid":  4, "business": 'Sitting'},
    {"_uid":  5, "business": 'Vet',      "states": [{state: 'Virginia', startups: 4}]},
    {"_uid":  6, "business": 'Parties',  "state": {}},
    {"_uid":  7, "business": 'Grooming', "states": [{state: 'Virginia', startups: 4}, {state: 'D.C.', startups: 3}]}
];

The data is displayed correctly for both datasets.

If I select the Pet Business Type - "Grooming" and brush the scatter plot vertically on 3 the filtered data is correct for the Flatten dataset, but not correct for the Array of Objects dataset.

Flatten dataset - Filtered


CORRECT - It is showing that "Training" also has a startup value of "3"

Array of Objects - Filtered


INCORRECT - All of the business types are showing up along with the other state "Virginia" for "Grooming".

I know we are asking a lot out of Crossfilter and dc.js by not flattening the data, but is this possible?

来源:https://stackoverflow.com/questions/48649766/dc-js-flatten-data-vs-array-of-objects-and-filtering

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!