Skip to content

Static Filters

Common filters are usually handled (added, modified or removed) by the Interaction Manager or by any direct user interaction.

Sometimes we may need some inmutable filters that always filter the visualization and will never be modified by any action, for example if we want to exclude permanently a value from a visual.

That's when we can use static filters:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
let attr = cf.Attribute('venuecity')
            .limit(10)
            .sort('asc', 'venuecity')
let static = cf.Filter('venuecity')
                .operation('NOT IN')
                .value(['Los Angeles'])
let myChart = cf.provider('Elasticsearch')
                .source('ticket_sales')
                .groupby(...)

                // Here is how static filters are specified
                .staticFilters(static)
                ...
myChart.execute()

Static filters should be specified only at definition time since they are not meant to be changed.

In the previous example, we are querying the top 10 venue cities but excluding always the city of Los Angeles. This way we also make sure that if we use any other filter over this visual Los Angeles will never come within the results.

It is important to mention that for a visual with static filters, if a normal filter is applied and this one matches any static filter in the field name and the operation, the static filter will be ignored in favor of the normal filter.

So using the same example:

1
2
3
4
5
let newFilter = cf.Filter('venuecity')
                .operation('NOT IN')
                .value(['New York'])

myChart.filters(newFilter).execute();

This will use the new filter over the static filter. The static filter however will remain stored by the visual and will be used again as soon as newFilter is removed.

Static filters and the Interaction Manager

The Interaction Manager (IM) applies filters to your visualizations depending on user interactions.

When applying a filter to a specific visualization, the Interaction Manager checks to see if the visualization already contains a static filter with the same path (i.e. field name). If that is the case, the IM makes a decision to discard the Filter in favor of the Static Filter.

There are two cases driven by the coexistent property of the static filter.

When the coexistent property of the static filter is true (default), the IM discards the Filter in favor of the Static Filter only when their operation is the same and it is other than NOT IN. This allows users to add static filters to visualizations to exclude certain values using the NOT IN operation and still be able to interact with them by selecting other values (e.g. IN operation).

When the coexistent property of the static filter is false, the IM always discards the filter in favor of a Static Filter of the same path (i.e. field name). This allows true static behaviour when you want to always have a specific visualization (e.g. KPI) show a metric (e.g. revenue) for a specific filter (e.g. paymentType=CASH).

Static filter properties

  • coexistent: the Interaction Manager uses the coexistent property of a Static Filter to make a decision to discard a Filter with the same path (i.e. field name) in favor of the existing Static Filter per logic described in the section above.. Example:
1
2
3
4
5
const staticFilter = cf.Filter('field_name')
                .operation('operation')
                .value(value)
                .label('Label')
                .coexistent(false) // true by default