5 Replies Latest reply: Oct 31, 2017 9:24 AM by Jesper Snihs RSS

    easy way to check if dimension has values

    Jonathan Vitale
      
      

      Hello all,

       

      I'm revising a d3-based extension (Sankey) and I have a scenario in which I want to load several dimensions, but depending on the time in the year, several of these dimensions may have empty values. Specifically, I'll have dimensions like Q1, Q2, Q3, Q4 set up, but until its actually the 2nd quarter of the year (school year, actually), there won't be data there.

       

      So, I can check if there are any non-null values by doing something like this with the layout object in the paint function:

       

      var qData = layout.qHyperCube.qDataPages[0];
      var nDim = layout.qHyperCube.qDimensionInfo.length;
      var dimIsNull = [];
      for (var d = 0; d < nDim; d++){
           var allNull = true;
           for (var r = 0; r < qData.qMatrix.length; r++){
                if (qData.qMatrix[r][d].qElemNumber >= 0){ // or I might check for a specific text like [.qText != "-"]
                     allNull = false;
                     break;
                }
           }
           dimIsNull[d] = allNull;
      }
                     
           
      

       

      This works, but it seems inefficient because I have to loop through the entire HyperCube on every paint call. Really, I would only need to call this function once on load. Also, since I come from the R programming world iterating through this sort of matrix pains me deeply. Is there a more elegant way to do this?

       

      Thanks, Jonathan