Conditional formatting - How to change color of text attribute dynamically bases on text

I have one question. I want to highlight the below field “Status” with color based on the text values, for example all Pass as Green and Fail as Red.

Status
Pass
Pass
Fail
Fail
Pass
Fail

I didn’t find the option to pass the text value as conditional parameter in Custom style. Please let me know if you have the solution.

@Mohan.Ammineni take a look at this post that discusses how you can use Custom Styles to achieve this behavior:

Hi Tadd, I have the same problem and have tried to modify the traffic light java script. I am not well versed with Java Script. So would really appreciate if you could please help me debug the code.

I want the custom style to allow the user to enter the column name
then String1, String 2, String 3 and Color1, Color2 and Color3

I would like to set all the rows with String1 in the entered column to have the background color = Color1 and similarly for String2 and String3

@taddwood @shaun

return function() {

var f = function() {};

f.version = “1”;

f.settings = function() {
return [
{
id: ‘Column name’,
displayName: ‘Enter the Column Name’,
defaultValue: ‘UN Region’
},
{
id: ‘String1’,
displayName: ‘Enter the 1st string’,
defaultValue: ‘High’
},
{
id: ‘String2’,
displayName: ‘Enter the 2nd string’,
defaultValue: ‘Medium’
},
{
id: ‘String3’,
displayName: ‘Enter the 3rd string’,
defaultValue: ‘Low’
},
{
id: ‘Color1’,
displayName: ‘Enter the 1st color’,
defaultValue: ‘#D2222D
},
{
id: ‘Color2’,
displayName: ‘Enter the 2nd color’,
defaultValue: ‘#FFBF00
},
{
id: ‘Color3’,
displayName: ‘Enter the 3rd color’,
defaultValue: ‘#238823
},
];
};
f.afterDraw = function() {

//Arcadia API to get result set and use to manipulate visual

var colname = arcapi.getSetting('Column name');
var String1 = arcapi.getSetting('String1');
var String2 = arcapi.getSetting('String2');
var String3 = arcapi.getSetting('String3');
var Color1 = arcapi.getSetting('Color1');
var Color2 = arcapi.getSetting('Color2');
var Color3 = arcapi.getSetting('Color3');

var colIndex = arcapi.dataResult().columnNameToIndex(colname);
if (colIndex === undefined) {
    console.log('Unknown columnForLabel for the table-bar extension');
    return;
}

var d = arcapi.dataResult();
var rows = d.rows();
if (rows.length === 0) {
    return;
}

console.log(threshold1);
console.log(threshold2);
console.log(condition);

function heatColm(colIndex) {
    var heat = d3.selectAll("#" + arcapi.chartId() + " .dataTables_scrollBody tbody tr :nth-child(" + (colIndex+1) +")");
    
    function getColor(rowIndex, colIndex) {
        var m = +rows[rowIndex][colIndex];
        console.log(m);
        switch(m){
            case 'String1': 
                if (m == String1)
                    return Color1;
                    break;
            case 'String2': 
                if (m == String2)
                    return Color2;
                    break;
            case 'String3': 
                if (m == String3)
                    return Color3;
                    break;
            default:
                return undefined;
        }
    }

    var colorsToApply = [];
    heat.filter(function(d, i) {
            var c = getColor(i, colIndex);
            if (c === undefined) {
                return false;
            }
            colorsToApply.push(c_color);
            return true;
        })
        .style('background-color', function(d, i) {
            return colorsToApply[i];
        })
}

heatColm(colIndex);

};

return f;
}();

Hi Tadd,

The Color Gradient solution above CANNOT be applied to a TABLE visual (only applicable for a Cross Tab or other visuals). So we would need to use the Custom Styles for the same. Could you please provide a similar solution i.e. conditional formatting of a particular column in a Table based on either discrete values (string variable) or value ranges (numeric variable) using Custom Styles for a TABLE visual?

Thanks,
Sourav
@shaun @taddwood

@taddwood @shaun can you please take a look at this help us with the code?