Create New Variables - Create Banner from Selected Variables
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!
Create a banner from several questions in Displayr
How to apply this QScript
- Start typing the name of the QScript into the Search features and data box in the top right of the Q window.
- Click on the QScript when it appears in the QScripts and Rules section of the search results.
OR
- Select Automate > Browse Online Library.
- Select this QScript from the list.
Customizing the QScript
This QScript is written in JavaScript and can be customized by copying and modifying the JavaScript.
Customizing QScripts in Q4.11 and more recent versions
- Start typing the name of the QScript into the Search features and data box in the top right of the Q window.
- Hover your mouse over the QScript when it appears in the QScripts and Rules section of the search results.
- Press Edit a Copy (bottom-left corner of the preview).
- Modify the JavaScript (see QScripts for more detail on this).
- Either:
- Run the QScript, by pressing the blue triangle button.
- Save the QScript and run it at a later time, using Automate > Run QScript (Macro) from File.
Customizing QScripts in older versions
JavaScript
includeWeb("QScript Utility Functions");
if (!main()) {
log("Could not create banner");
} else {
log("The banner has been added to the top of your data set. A page showing your banner has been added to the bottom of your document.");
}
function main() {
var allowed_types = ["Pick One", "Pick One - Multi", "Pick Any", "Pick Any - Grid", "Pick Any - Compact"];
// On the web just take from what is selected.
var web_mode = (!!Q.isOnTheWeb && Q.isOnTheWeb());
var selected_questions;
selected_questions = project.report.selectedQuestions();
var sorted_selection = splitArrayIntoApplicableAndNotApplicable(selected_questions, function (q) { return allowed_types.indexOf(q.questionType) != -1 && !q.isBanner; });
selected_questions = sorted_selection.applicable;
var not_applicable_questions = sorted_selection.notApplicable;
if (not_applicable_questions.length > 0) {
log("The following variable sets can not be used in a banner because they do not have appropriate structure:");
log(not_applicable_questions.map(function (q) { return q.name}).join("\r\n"))
return false;
}
if (selected_questions.length == 1) {
log("Only one variable set selected. Banners require two or more variable sets.");
return false;
}
flattenSelectedQuestions(selected_questions);
var data_file = selected_questions[0].dataFile;
var banner_name = preventDuplicateQuestionName(data_file, 'BANNER');
var new_banner_question = data_file.createBanner(banner_name, selected_questions.map(function (a) { return [a]; }), false, true, true);
// Create page and title
var pageName = "Banner"
var page = project.report.appendPage('TitleOnly');
page.name = pageName;
var titleText = page.subItems[0];
titleText.text = pageName;
var t = page.appendTable();
t.primary = selected_questions[0];
t.secondary = new_banner_question;
return true;
}
See also
- QScript for more general information about QScripts.
- QScript Examples Library for other examples.
- Online JavaScript Libraries for the libraries of functions that can be used when writing QScripts.
- QScript Reference for information about how QScript can manipulate the different elements of a project.
- JavaScript for information about the JavaScript programming language.
- Table JavaScript and Plot JavaScript for tools for using JavaScript to modify the appearance of tables and charts.