Changeset 35193 for gs3-extensions


Ignore:
Timestamp:
2021-05-30T16:47:16+12:00 (3 years ago)
Author:
davidb
Message:

NaN was occuring on some computed values. This was eventually traced to the JSON retrieved via AJAX return an array of string values. Now changed to be Number format in AJAX callback

File:
1 edited

Legend:

Unmodified
Added
Removed
  • gs3-extensions/mars-src/trunk/src/wavesurfer-renderer/drawer.spectrummulticanvas.js

    r34810 r35193  
    300300    createAVProgressTimelineData(arousal_vals,valence_vals, my)
    301301    {
    302     console.log("**** createAVProgressTimelineData");
     302    //console.log("**** createAVProgressTimelineData");
    303303    var canvas_width = this.canvases[0].wave.width;
    304     console.log("canvas width = " + canvas_width);
    305 
     304    //console.log("**** canvas width = " + canvas_width);
     305
     306    //console.log("     arousal_val = " + JSON.stringify(arousal_vals));
     307    //console.log("this.arousal_val = " + JSON.stringify(this.arousal_vals));
     308   
    306309    //this.arousal_vals = arousal_vals;
    307310    //this.valence_vals = valence_vals;
     
    310313    this.valence_vals.unshift(0);
    311314
    312     this.norm_arousal_vals = this.normaliseAVVals(arousal_vals);
    313     this.norm_valence_vals = this.normaliseAVVals(valence_vals);
     315    this.norm_arousal_vals = this.normaliseAVVals(this.arousal_vals);
     316    this.norm_valence_vals = this.normaliseAVVals(this.valence_vals);
    314317
    315318    const time_slice    = 6; // 6 secs
     
    319322    this.timeline_steps.unshift(0);
    320323
    321     var num_vals = arousal_vals.length;
     324    var num_vals = this.arousal_vals.length;
    322325    var t = time_slice;
    323326    var n = 1;
     
    329332    }
    330333    const total_duration = t;
    331     console.log("*** total duration = " + total_duration);
     334    //console.log("***              n = " + n);
     335    //console.log("*** total duration = " + total_duration);
    332336   
    333337    this.timeline_steps[n] = total_duration;
     338    this.arousal_vals[n] = 0;
     339    this.valence_vals[n] = 0;
    334340    this.norm_arousal_vals[n] = 0;
    335341    this.norm_valence_vals[n] = 0;
     
    367373        //console.log("*** start_ts = " + start_ts +  ", end_ts = " + end_ts + " (ts_diff = " + ts_diff +")");
    368374        //console.log("*** start_arousal = " + start_arousal +  ", end_arousal = " + end_arousal);
     375        //console.log("*** norm_start_arousal = " + norm_start_arousal +  ", norm_end_arousal = " + norm_end_arousal);
    369376       
    370377        for (var ts=start_ts; ts<end_ts; ts++) {
     
    401408        //console.log("*** that = ");
    402409        //console.log(that);
    403         this.arousal_vals = data.arousal;
    404         this.valence_vals = data.valence;
    405 
     410        //this.arousal_vals = data.arousal.slice(); // **** slice() does array copy
     411        //this.valence_vals = data.valence.slice(); // **** slice() does array copy
     412
     413        // The following two lines use map() to both:
     414        //   convert the JSON string vals to numbers
     415        //   generate a fresh array of values (rather than a shared ref) which is what we want     
     416        this.arousal_vals = data.arousal.map((v) => Number(v));
     417        this.valence_vals = data.valence.map((v) => Number(v));     
     418       
    406419        //this.createAVProgressTimelineData(arousal_vals, valence_vals, this); // **** need to pass in 'this' ??
    407420    });
     
    732745
    733746    if (arousal_val_3dp >= 0) {
    734         arousal_val_3dp = "&nbsp;" + arousal_val_3d;
     747        arousal_val_3dp = "&nbsp;" + arousal_val_3dp;
    735748    }
    736749
    737750    if (valence_val_3dp >= 0) {
    738         valence_val_3dp = "&nbsp;" + valence_val_3d;
     751        valence_val_3dp = "&nbsp;" + valence_val_3dp;
    739752    }
    740753
    741754    if ($('#arousal-val').length) {
    742         $('#arousal-val').text(arousal_val_3dp);
     755        $('#arousal-val').html(arousal_val_3dp);
    743756    }
    744757    if ($('#valence-val').length) {
    745         $('#valence-val').text(valence_val_3dp);
     758        $('#valence-val').html(valence_val_3dp);
    746759    }
    747760   
Note: See TracChangeset for help on using the changeset viewer.