Hi guys, I have a Word Cloud visualization which represents the states of the United States grouped by name and the sum of another field as a metric. In the interaction manager I have configured a rule, a restriction and the drill hierarchy configuration so that when I select a state it shows me the counties of the selected state.
The problem is that the state data and the county data are at different indices so I had to use the filter:before-add
and filter:before-remove
events to manually change the state source to county and vice versa.
This is my Interaction Manager configuration:
const state_source = "state_index";
const county_source = "county_index";
const wcId = "wordclouduniqueid";
const drill = {
[wcId]: {
group1: ["state_name", "county_name"]
}
};
const rules = {
[wcId]: { clientFilters: true }
};
let restrictions = [
{ filter: "county_name", dependsOn: "state_name" }
];
let aktive = cf.create();
let myChart = aktive.graph("Interaction Manager")
.set("skin", "modern")
.set("rules", rules)
.set("drill", drill)
.set("restrictions", restrictions)
.on("filter:before-add", (event) => {
const wordcloud = cf.getVisualization(wcId);
const isStateFilter = event.filters.find((f) => f.getPath() === "state_name");
// Change the source to county if any state was selected
if (isStateFilter) {
wordcloud.source(county_source);
}
})
.on("filter:before-remove", (event) => {
const wordcloud = cf.getVisualization(wcId);
const removingState = event.filters.find((f) => f.getPath() === "state_name");
// Change the source back to state if the state filter was removed
if (removingState) {
wordcloud.source(state_source);
}
})
.execute();
This solution works and achieves the desired goal, but I know that it can be heavy to do this in the interaction manager’s events or perhaps is not the best practice. Is this the proper way to do this?