How to stop or prevent the execution of a visualization based on whether a filter exists or not?


#1

Hello folks, I have a visualization that is intended to load data from an Elasticsearch index with a large number of records, so I need this visualization to only be executed when in the Interaction Manager exists a filter applied for a specific field, in such a way that it narrows the data.

I tried using the execute:start event to then do something like aktive.stopExecution() if the filter does not exists in the IM but that function doesn’t exist, and well it turns out I don’t know how I can achieve it, any suggestions about it?


#2

Hi @oliver89, thanks for reaching out. ChartFactor allows us to achieve your goal in a very elegant way. At the visualization level it is possible to apply restrictions that allow you to specify when a visualization should be executed or not. Take a look at the following example:

const restrictions = [
    { filter: "community_areas" }
];
/* Configuration code for this widget */
let provider = cf.provider("Elasticsearch");
let source = provider.source("chicago_taxi_trips");
// Define metrics
let metric0 = cf.Metric("extras", "sum");
// Define attributes to group by
let group1 = cf.Attribute("company")
    .limit(10000)
    .sort("asc", "company");
// Add metrics and groups to data source
let myData = source.groupby(group1).metrics(metric0);
// --- Define chart options and static filters ---
let myChart = myData.graph("Slicer")
    .onlyWithFilters(restrictions)
    .execute();

As you can see in the piece of code above, in the restrictions array we have defined the rule that will be applied to the visualization using the .onlyWithFilters(restrictions) function. With this we are telling the visualization to run only when there is a filter applied to the community_areas field.

You can go even further and specify what filter values you want the visualization to load with. For more information please take a look at the following documentation: https://chartfactor.com/doc/latest/visualizations/interaction_manager/#visualization-level

Let me know if this solved your problem. :sunglasses:


#3

Thanks @juan.dominguez, wonderful, it works perfectly, as you said it is a clean and elegant solution. It’s great that ChartFactor contemplates all these situations. :grinning: