Woodran
Woodran

Reputation: 67

dc.js: dealing with entries with multi-valued attributes

I am dealing with data that contain multi-valued attributes (e.g.: a company has branches distributed over three states). When clicking the company with multiple branches, the geoChoroplethChart should highlight all the associated states. But, this works currently only for the entry with single value(one state). How could one realize the above-mentioned functionality?

var data= [
    {"Company":"MountainA","State":"CA PA NY"},
    {"Company":"HighlandA","State":"PA"}];

I modified the csv data for US Venture Capital Landscape 2011 and added multiple states for most of the entries. E.g.: instead of single state ("CA"), now the state information includes multiple states such as "CA PA NY" (space-separated). https://jsfiddle.net/woodlan/1ou8r1q9/1/

I guess one needs to modify this function?

var states = data.dimension(function (d) {
    return d["State"];
  });

Any help would be really appreciated.

Upvotes: 1

Views: 89

Answers (1)

Gordon
Gordon

Reputation: 20150

The community fork of crossfilter, available in npm as crossfilter2, has a new feature in version 1.4 supporting array (tag) keys:

var states = data.dimension(function (d) {
    return d["State"].split(' ');
  }, true // enable array keys
);

This will cause those rows to count once for each key which the dimension key function returns.

Crossfilter documentation - Dimensions with Arrays.

Upvotes: 1

Related Questions