Unlock a world of possibilities! Login now and discover the exclusive benefits awaiting you.
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
.qElemNumber >= 0){ // or I might check for a specific text like [.qText != "-"] allNull = false;
break;
}
}
dimIsNull
= 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
Hi,
There is some info on diemnsions in the dimensionInfo array:
Is qCardinal what you are after? Use the dubugger to explore what is in the structure.
Doing this just on load seems not a good idea... What if the user makes a selection that excludes Q2, Q3, Q4? Or if he already has made such a selection when the extension first loads and then clears it?
Hope this helps
Erik Wetterberg
Hi Jonathan,
If you only want the code to run on load, can't you place the code inside the controller instead since the controller is only executed on load?
Regards
Jesper
Hi,
There is some info on diemnsions in the dimensionInfo array:
Is qCardinal what you are after? Use the dubugger to explore what is in the structure.
Doing this just on load seems not a good idea... What if the user makes a selection that excludes Q2, Q3, Q4? Or if he already has made such a selection when the extension first loads and then clears it?
Hope this helps
Erik Wetterberg
As Erik mentions, it's probably a bad idea for me to put the code outside the paint function - unforeseen circumstances.
But, I am interested in what you mean by the "controller". I'm not using angular here.
Jonathan
You've done it again Erik! There it is right in the hyperCube. Dimension index 3, qCardinal is 0.
Thanks again.
Yes, I'm referring to the controller in angular. So if you don't use that you can ignore my previous answer.