Sort/Reorder Rows or Columns - Order Rows by Pattern

From Q
Jump to navigation Jump to search
This page is currently under construction, or it refers to features which are under development and not yet available for use.
This page is under construction. Its contents are only visible to developers!


This rule allows you to sort rows to show patterns in the data.

How to apply this rule

For the first time in a project

  • Select the table(s)/chart(s) that you wish to apply the rule to.
  • Start typing the name of the Rule into the Search features and data box in the top right of the Q window.
  • Click on the Rule when it appears in the QScripts and Rules section of the search results.

OR

  • Select Automate > Browse Online Library.
  • Choose this rule from the list.

Additional applications of the rule

  • Select a table or chart that has the rule and any table(s)/chart(s) that you wish to apply the rule to.
  • Click on the Rules tab (bottom-left of the table/chart).
  • Select the rule that you wish to apply.
  • Click on the Apply drop-down and choose your desired option.
  • Check New items to have it automatically applied to new items that you create. Use Edit > Project Options > Save as Template to create a new project template that automatically uses this rule.

Removing the rule

  • Select the table(s)/chart(s) that you wish to remove the rule from.
  • Press the Rules tab (bottom-right corner).
  • Press Apply next to the rule you wish to remove and choose the appropriate option.

How to modify the rule

  • Click on the Rules tab (bottom-left of the table/chart).
  • Select the rule that you wish to modify.
  • Click Edit Rule and make the desired changes. Alternatively, you can use the JavaScript below to make your own rule (see Customizing Rules).

JavaScript

var __webpack_modules__ = ({});
// The module cache
var __webpack_module_cache__ = {};

// The require function
function __webpack_require__(moduleId) {

// Check if module is in cache
var cachedModule = __webpack_module_cache__[moduleId];
if (cachedModule !== undefined) {
return cachedModule.exports;
}
// Create a new module (and put it into the cache)
var module = (__webpack_module_cache__[moduleId] = {
exports: {}
});
// Execute the module function
__webpack_modules__[moduleId](module, module.exports, __webpack_require__);

// Return the exports of the module
return module.exports;

}

// webpack/runtime/rspack_version
(() => {
__webpack_require__.rv = () => ("1.7.2")
})();
// webpack/runtime/rspack_unique_id
(() => {
__webpack_require__.ruid = "bundler=rspack@1.7.2";
})();
includeWeb('Table JavaScript Utility Functions');
includeWeb('JavaScript Text Analysis Functions');

form.setHeading("Order Rows by Pattern");
form.setSummary("Order rows by pattern");
let description = form.newLabel("Sort rows to show patterns in the data.");
description.lineBreakAfter = true;
let control_array = [description];
form.setInputControls(control_array);

// User specified labels to always exclude from the sort
// or never exclude from the sort.
let pattern_to_exclude = addExpandingTextBoxes(control_array, 'Exclude from sort (in addition to NET/SUM):', 'el').map(function (label) { return label.toLowerCase(); });
let pattern_to_include = addExpandingTextBoxes(control_array, 'Never exclude from sort:', 'dnel').map(function (label) { return label.toLowerCase(); });

let row_labels = table.rowLabels;
let net_rows = table.netRows;
let excluded_labels = [];
for (let i = 0; i < row_labels.length; i++) {
    let is_net = net_rows.indexOf(i) != -1;
    if (!shouldSort(row_labels[i], pattern_to_exclude, pattern_to_include, is_net)) {
        excluded_labels.push(row_labels[i]);
    }
}

table.sortRowsByPattern(excluded_labels);

See also