spotfiresoftware / spotfire-mods

Spotfire® Mods
https://spotfiresoftware.github.io/spotfire-mods/
Other
56 stars 41 forks source link

Best way to check if categorical axis value is empty #63

Closed hski-github closed 2 years ago

hski-github commented 2 years ago

A value of a categorical axis can be empty. If I use row.categorical(”Label”).formattedValue() I get a localized string (empty) or (Leer).

What is the best way to check if this value is empty? Do I have to iterate over the value array and check each is empty? Or is there a simpler way to do it?

objerke commented 2 years ago

In the sunburst chart we validate that there are no gaps in the hierarchy (empty value followed by value) by iterating the value array in the following way: https://github.com/TIBCOSoftware/spotfire-mods/blob/44174deab6ea04bb52d689bf2f6a55aaa5ac8a65/catalog/sunburst-chart/src/index.ts#L379

An alternative approach is to check the value() of the DataViewHierarchyNode at that level in the hierarchy.

hski-github commented 2 years ago

Thank you very much. Doing like this now in my own Mod.

https://github.com/hski-github/spotfire-kanban/blob/b86336090157fc143f874b9d2e29bd2673aa4bf1/src/main.js#L146-L151

if ( iconAxis.parts.length > 0 ){
    var icon = row.categorical("Icon");
    var iconNotEmpty = false;
    icon.value().forEach(function(part){
        if ( part.value() ) iconNotEmpty = true;
    });
    if ( iconNotEmpty ){
        var iconValue = icon.formattedValue();
        ...
    }
}