Use Case:
Design Studio, being a multi-dimensional client, likes to decompose data into 'tuples' which basically defines each measure as a cell value that is represented by indexed tuples that map back to a dimension member. There's not really anything "wrong" with this, except that at least in my opinion, this is not the easiest way for me to work with the data in a 2D tabular form. There have been many SCN threads where people have struggled with basically looping through (aka iterating over) the rows in order to apply some script logic. Even in my other extensions, the first thing I do is "flatten" the dataset into a 2-dimensional (or table-like) form to work with. I start thinking about why couldn't I just open this convenience up to BIAL scripting? This is what I have written this component called 'Data Iterator'.
var rows = DATAITERATOR_1.getRows().containing({ "dimensions": [
{ "key" : "0D_CO_CODE", "value" : "1000" }, { "key" : "0D_CO_CODE", "value" : "2000" }
]
}).containing({
"dimensions" : [{ key : "0CALMONTH", "value" : "04/2004"}]
}) ;
// Get flattened rows from Data Iterator
var rows = DATAITERATOR_1.getRows(0,10);
// Get dimensions (Rows) and Measures (Cols)
var dimensions = DATAITERATOR_1.getDimensions();
var measures = DATAITERATOR_1.getMeasures();
// Start a simple HTML table
var html = "<div style='height:400px;overflow:scroll'><table class='example'><tr>";
// Draw headers for dimensions and measures
dimensions.forEach(function(element, index) {
html = html + "<th>" + element.text + "</th>";
});
measures.forEach(function(element, index) {
html = html + "<th>" + element.text + "</th>";
});
html = html + "</tr>";
// Loop through the rows...
rows.forEach(function(row, index) {
// Draw a new row
html = html + "<tr>";
// Write out the dimension texts
dimensions.forEach(function(member, index) {
var dimText = row.getDimensionValueText(member.key);
html = html + "<td class='dimension'>" + dimText + "</td>";
});
// Row striping example
var stripe = "even";
if(index/2 == Math.floor(index/2)) {
stripe = "odd";
}
// Write out the measure formatted values
measures.forEach(function(measure, index) {
var measureVal = row.getMeasureValue(measure.key);
var measureText = row.getMeasureFormattedValue(measure.key);
html = html + "<td class='measure " + stripe +" '>" + measureText + "</td>";
});
html = html + "</tr>";
});
html = html + "</table></div>";
RAPIDPROTOTYPE_1.setHTML(html);
// Get flattened rows from Data Iterator
var rows = DATAITERATOR_1.getRows(0,250);
// Get dimensions (Rows) and Measures (Cols)
var dimensions = DATAITERATOR_1.getDimensions();
var measures = DATAITERATOR_1.getMeasures();
var firstMeasureKey = measures.atIndex(0).key;
// Figure out Max in BIAL for rendering chart bars
var max = 0.0;
rows.forEach(function(row, index) {
var v = row.getMeasureValue(firstMeasureKey);
if(v>max){ max = v; }
});
// Start a simple HTML table
var html = "<div style='height:400px;overflow:scroll'><table class='chart'><tr>";
// Draw headers for dimensions and measures
dimensions.forEach(function(element, index) {
html = html + "<th>" + element.text + "</th>";
});
// Draw first measure header
html = html + "<th>" + measures.atIndex(0).text+"</th>";
var w = 300;
html = html + "</tr>";
// Loop through the rows...
rows.forEach(function(row, index) {
html = html + "<tr>";
// Draw a new row
dimensions.forEach(function(member, index) {
var dimText = row.getDimensionValueText(member.key);
html = html + "<td class='dimension'>" + dimText + "</td>";
});
var measureVal = row.getMeasureValue(firstMeasureKey);
var measureFVal = row.getMeasureFormattedValue(firstMeasureKey);
var barWidth = w * (measureVal / max);
html = html + "<td style = 'width:" + (w+200) +";'>";
html = html + "<div style = 'display:inline-block;width:" + barWidth + "px;background-color:#006699;'> </div>" + measureFVal;
html = html + "</td></tr>";
});
html = html + "</table></div>";
RAPIDPROTOTYPE_2.setHTML(html);
// Get flattened rows from Data Iterator
var rows = DATAITERATOR_1.getRows(0,10);
// Get dimensions (Rows) and Measures (Cols)
var dimensions = DATAITERATOR_1.getDimensions();
var measures = DATAITERATOR_1.getMeasures();
// Start a simple HTML table
var html = "<table class='example scorecard'><tr>";
// Draw headers for dimensions and measures
dimensions.forEach(function(element, index) {
if(element.text != "Key Figures"){
html = html + "<th>" + element.text + "</th>";
}
});
measures.forEach(function(element, index) {
html = html + "<th>" + element.text + "</th>";
});
html = html + "</tr>";
// Loop through the rows...
rows.forEach(function(row, index) {
// Draw a new row
html = html + "<tr>";
var priorValue = DATAITERATOR_1.makeNull();
// Write out the dimension texts
dimensions.forEach(function(member, index) {
var dimText = row.getDimensionValueText(member.key);
if(member.text!="Key Figures"){
html = html + "<td class='dimension'>" + dimText + "</td>";
}
});
// Row striping example
var stripe = "even";
if(index/2 == Math.floor(index/2)) {
stripe = "odd";
}
// Write out the measure formatted values
measures.forEach(function(measure, index) {
var trend = "";
var measureVal = row.getMeasureValue(measure.key);
var measureText = row.getMeasureFormattedValue(measure.key);
if(index>0 && !DATAITERATOR_1.isNull(priorValue) && !DATAITERATOR_1.isNull(measureVal)){
var delta = Math.round(measureVal / priorValue * 100) + "%";
var icon = "";
if(priorValue > measureVal){ // Down
trend = "downward";
}else{ // Up
trend = "upward";
}
measureText = "<div class='icon'></div><br />(" + delta + ")</span><br />" + measureText;
}
if(!DATAITERATOR_1.isNull(measureVal)){
priorValue = measureVal;
}else{
priorValue = DATAITERATOR_1.makeNull();
measureText = " - ";
}
html = html + "<td class='measure " + stripe + " " + trend + "'>" + measureText + "</td>";
});
html = html + "</tr>";
});
html = html + "</table>";
RAPIDPROTOTYPE_3.setHTML(html);
var members = DS_2.getMembers("0D_CO_CODE", 100);
var html = "<div style='height:100%;overflow:scroll'>";
members.forEach(function(member, index) {
var item = member.externalKey;
// Get flattened rows from Data Iterator containing certain company code
var rows = DATAITERATOR_1.getRows().containing({
"dimensions": [
{ "key" : "0D_CO_CODE", "value" : item }
]
});
html = html + "<h2>" + member.text + "</h2>";
// Get dimensions (Rows) and Measures (Cols)
var dimensions = DATAITERATOR_1.getDimensions();
var measures = DATAITERATOR_1.getMeasures();
// Start a simple HTML table
html = html + "<table class='example scorecard'><tr>";
// Draw headers for dimensions and measures
dimensions.forEach(function(element, index) {
if(element.text != "Key Figures" && element.key !="0D_CO_CODE"){
html = html + "<th>" + element.text + "</th>";
}
});
measures.forEach(function(element, index) {
html = html + "<th>" + element.text + "</th>";
});
html = html + "</tr>";
// Loop through the rows...
rows.forEach(function(row, index) {
// Draw a new row
html = html + "<tr>";
var priorValue = DATAITERATOR_1.makeNull();
// Write out the dimension texts
dimensions.forEach(function(member, index) {
var dimText = row.getDimensionValueText(member.key);
if(member.text!="Key Figures" && member.key !="0D_CO_CODE"){
html = html + "<td class='dimension'>" + dimText + "</td>";
}
});
// Row striping example
var stripe = "even";
if(index/2 == Math.floor(index/2)) {
stripe = "odd";
}
// Write out the measure formatted values
measures.forEach(function(measure, index) {
var trend = "";
var measureVal = row.getMeasureValue(measure.key);
var measureText = row.getMeasureFormattedValue(measure.key);
if(index>0 && !DATAITERATOR_1.isNull(priorValue) && !DATAITERATOR_1.isNull(measureVal)){
var delta = Math.round(measureVal / priorValue * 100) + "%";
var icon = "";
if(priorValue > measureVal){ // Down
trend = "downward";
}else{ // Up
trend = "upward";
}
measureText = "<div class='icon'></div><br />(" + delta + ")</span><br />" + measureText;
}
if(!DATAITERATOR_1.isNull(measureVal)){
priorValue = measureVal;
}else{
priorValue = DATAITERATOR_1.makeNull();
measureText = " - ";
}
html = html + "<td class='measure " + stripe + " " + trend + "'>" + measureText + "</td>";
});
html = html + "</tr>";
});
html = html + "</table>";
});
html = html + "</div>";
RAPIDPROTOTYPE_4.setHTML(html);
.example {
border-collapse : collapse;
}
.example .dimension {
background-color : #006699;
color : #FFFFFF;
}
.example th {
background-color : #006699;
color : #FFFFFF;
font-weight : bold;
}
.example.scorecard th {
/*white-space: nowrap;*/
padding : 20px;
background-color : #0099CC;
color : #FFFFFF;
font-weight : bold;
font-size : 20pt;
}
.example .measure {
text-align : center;
}
.example .icon {
display : inline-block;
width : 48px;
height : 48px;
}
.example .downward .icon{
background-image : url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAADAAAAAwCAYAAABXAvmHAAAABmJLR0QA/wD/AP+gvaeTAAAAB3RJTUUH2QcVCAsthDpI/AAABQ9JREFUaIHtV0tsG0UY/ma9XnudJq1Tp2ppRRMeF6jopVKFEIWq9NACogipQE9wQEgc4AYmAqkXWpUb0CvigopED1CqJgdSFBCoIFBJk5YWEhKnjR/JOonf+5wZDrEbs971ay0liHzSL8+u5//n++af+WcW2MAGNrCBDfyfQbw49x89zTtBQjDIlumRaLYdX9Hr4CdeeBIoy+AAOO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0yI6jr3l/mAynOyk1lf2pkWv85Fc/KGRsyKhasrnsjFef+WUQkCEpz89wKZPEag7Hjd2NEgINhygautEv3n4VMWQm6gdV6oFDX3bRkxLoes0T8ICxAvwdLzIrfPQKKJgAfM4f5lK2FzWKiVyD0AIhcMLbtya44fA3vjjeglIYBPDHSpArh8Akoh/9lKsAbc+FGkTJ2hEuZ88iRgMfL25Io5u3oAbwA2JhXOSiM29EpkqgkA0WKzkuZXpBLMYJM4wp7OPi4KOeL0i1lWgPpCICiHIpcwY1XljM4hmGsPQqaOg2FiyKQbBU56VURQTSXgqPsfH0aIwgjmBMPkWigqqCzWckiyIqFLfb/wUCg/nCNJ7nCy0RuU/QZoNoZCGtBv7KCFhsrBARIxL0PWIEtYpFgpqnIFbzLlYFqe6rxZKgbtrrV2DqFjAE7Ue+BQliNF+krKJCcOtW83vROjZiUg9YwA+HpUwph0AE2I2tHeKgibUISBCkUZqJ2oOwfYjacM0XNwEaY+Cj4cXWN0TAhN9HwIvX5PwMLgnG7Fh464E5RCmqxAEBayMiAZmYGeqKQHuhnmjtMYlVJiMgFN62W2JQ59zC5sVPx9pkxoM6f0wAMt+sBRZBwffHCdSEIEu8VAobrfwoi0BZ8vpbr1TyeCS1lTz8ZSniei5UKi6c8DlD4W1Gt2cpDNZif4/PxeuSLlROjpssiIsBR2spGnECcSJRtilFqOwgnmqSjqfRYtDxudTZ+U4iT6KYzJTTaDWqTHRG/PYnK5AR6Ag4lAjMaZmWafk/kn8DlgvUqMpTMAIAAAAASUVORK5CYII=)
}
.example .downward {
color : #FF0000;
}
.example .upward {
color : #009966;
}
.example .measure.even {
background-color : #FFFFFF;
}
.example .measure.odd {
background-color : #DFDFDF;
}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
7 | |
5 | |
5 | |
4 | |
4 | |
4 | |
4 | |
4 | |
3 | |
3 |