Q& Displayr - Add the "highlight cells with column comparisons" rule to Displayr
N
Nutty Stoat
Currently, there is a rule in the OneNote library that USE maintains with rules that we’ve written for users but haven’t been added to the online library (in both Q and Displayr) that highlights cells with any column comparison results in them. A rule that does something like this should be added to the online library in both Q and Displayr. The code for the rule is below:
Highlight cells with column comparisons
{noformat}includeWeb("Table JavaScript Utility Functions");
if (table.availableStatistics.indexOf("Column Names") == -1)
form.ruleNotApplicable("column comparisons not available on this table");
form.setSummary("Highlight comparisons");
var high_label = form.newLabel("Color results:");
var high_color_picker = form.newColorPicker("hcolor");
high_color_picker.setDefault("YellowGreen");
high_color_picker.lineBreakAfter = true;
var do_below_box = form.newCheckBox("dbb", "Highlight Statistics - Below");
form.setInputControls([high_label, high_color_picker, do_below_box]);
var high_color = high_color_picker.getValue();
var testing_results = table.get("Column Comparisons");
var cell_colors = table.cellColors;
// Color main table
for (var row = 0; row < table.numberRows; row++) {
for (var col = 0; col < table.numberColumns; col++) {
var current_cc = testing_results[row][col].toUpperCase();
if (current_cc.match(/[A-Za-z]+/)) {
cell_colors[row][col] = high_color;
}
}
}
table.cellColors = cell_colors;
// Do below table as well if it exists
if (do_below_box.getValue() && belowTableExists() && below_table.statistics.length > 0 && below_table.availableStatistics.indexOf("Column Comparisons") > -1) {
var testing_results = below_table.get("Column Comparisons");
if (testing_results.length == 1)
testing_results = testing_results[0];
else
testing_results = testing_results.map(function (a) { return a[0]; });
var cell_colors = below_table.cellColors;
var colors_transposed = cell_colors.length > 1;
for (var col = 0; col < table.numberColumns; col++) {
var current_cc = testing_results[col].toUpperCase();
if (current_cc.match(/[A-Za-z]+/)) {
var row_index = colors_transposed ? col : 0;
var col_index = colors_transposed ? 0 : col;
cell_colors[row_index][col_index] = high_color;
}
}
below_table.cellColors = cell_colors;
}{noformat}