Format Conversion in UI

Everything related to the development of modules in jamovi
Post Reply
User avatar
mcfanda@gmail.com
Posts: 452
Joined: Thu Mar 23, 2017 9:24 pm

Format Conversion in UI

Post by mcfanda@gmail.com »

HI
I need to fill in a supplier with only variables present in modelterms. My strategy is to get the modelterms, remove possible interactions, convert the list into FormatDef.variable, and fill the supplier.

Code: Select all

var updateSimpleSupplier = function(ui, context) {
    var termsList = context.cloneArray(ui.modelTerms.value(), []);
    var varList=[];
    for (var j = 0; j < termsList.length; j++) {
        var newTerm=context.clone(termsList[j]);
        if (newTerm.length==1) {
              varList.push(newTerm);
        }
    }
    varList=context.valuesToItems(varList, FormatDef.variable);
    console.log(varList);
    ui.simpleSupplier.setValue(varList);
};



However, whereas the supplier gets filled in correctly, when the user selects a variable to put in the supplier target, the variable name gets crossed over, as if the format wasn't right. Please note that the target is defined as:

Code: Select all

    - name: simpleVariable
      title: Simple effects variable
      type: Variable
      default:
any help will be great.
dropmann
Posts: 79
Joined: Thu Feb 02, 2017 10:26 am

Re: Format Conversion in UI

Post by dropmann »

Can this be found in your repo? I can't see anything wrong with what you have written above but it would be good to see it in context.
User avatar
mcfanda@gmail.com
Posts: 452
Joined: Thu Mar 23, 2017 9:24 pm

Re: Format Conversion in UI

Post by mcfanda@gmail.com »

sure:
https://github.com/mcfanda/gamlj_glm/tree/develop

iin the "inst" folder there a example_glm which reproduce the problem. If you look at the "simple effects" tab you can see the crossed text
dropmann
Posts: 79
Joined: Thu Feb 02, 2017 10:26 am

Re: Format Conversion in UI

Post by dropmann »

Hi,

sorry that my response has been delayed again. I found a race condition that needed fixing while investigating your issue. That is now fixed and will be sent out in the next release. In regard to your specific issue, i used the 'glm.events.dev.js' and made the appropriate mods to the u.yaml file to allow for this and i found there were two very small issues in the glm.events.dev.js file that would cause your issues.

First you'll need to add 'updateSimpleSupplier' to the update function so that the 'simpleSupplier' populates correctly on a refresh (e.i file load). See code below.

Code: Select all

update: function(ui) {
    calcModelTerms(ui, this);
    filterModelTerms(ui, this);
    updatePostHocSupplier(ui, this);
    updateSimpleSupplier(ui, this);
},
secondly, the strike out is happening because the values that are being sent to the 'simpleSupplier' in the 'updateSimpleSupplier' function are terms not variables. A term is an array of variables. So rather than populating 'varList' with 'newTerm' it should be populated with 'newTerm[0]' (the variable in the term). Doing this means that 'varList' now represents a list of variables where as before it represented a list of terms.

Code: Select all

var updateSimpleSupplier = function(ui, context) {
    var termsList = context.cloneArray(ui.modelTerms.value(), []);
    var varList=[];
    for (var j = 0; j < termsList.length; j++) {
        var newTerm=context.clone(termsList[j]);
        if (newTerm.length==1) {
              varList.push(newTerm[0]); // was varList.push(newTerm);
        }
    }
    varList=context.valuesToItems(varList, FormatDef.variable);
    console.log(varList);
    ui.simpleSupplier.setValue(varList);
};
please let me know if this is confusing.

thanks for working through this with us.
User avatar
mcfanda@gmail.com
Posts: 452
Joined: Thu Mar 23, 2017 9:24 pm

Re: Format Conversion in UI

Post by mcfanda@gmail.com »

perfect, you're right, I should have noticed myself by inspecting the two lists. Thank you for the help
Post Reply