Professional Documents
Culture Documents
BACon 2021 Custom Viz in Cognos
BACon 2021 Custom Viz in Cognos
Software
• Installing NodeJS and NPM
1. Download NodeJS at https://nodejs.org/en/download
a. The latest LTS release is best. “14.17.5 LTS” currently.
b. Either 32 bit or 64 bit. It doesn’t matter for this application.
2. Run the installer and use the default settings
3. After install is complete, validate the node and npm installation.
a. Open a command-line interface (CLI). CMD on Windows or Terminal on OSX
b. Run the following command:
node --version
The CLI displays the current version of the node. Make sure it meets the
prerequisites.
customvis --help
The CLI should display all available commands.
1. In your CLI navigate to a “Projects” folder. This can be wherever you want to keep your
custom visualization code.
2. Run the following command:
customvis start
a. This will install all necessary dependencies and start a local NodeJS process
b. Once it says “Started a local server”, it’s ready to go
5. Open the Cognos Analytics environment: http://cognos.pm2analytics.com/viz-workshop/
6. Create a new Dashboard
7. Select the default template and click Create
8. Select the Visualizations panel
9. Select the Custom tab
Demos: https://www.highcharts.com/demo
Sunburst: https://www.highcharts.com/demo/sunburst
customvis clean
This removes all the dependency files from the project folder leaving only the main source code
customvis start
a. This redownloads all the necessary dependencies and compiles the visualization code.
Your CLI should end with “Started a local server on port 8585”.
Save Point #1 -- If your files did not look like the above or something went wrong, you can download the
Step 1 file from the PM2 Download Site.
Check the box next to “Step1_HighchartLib_YourName - Custom Sunburst.zip” and click Download in the
top left corner. Unzip this file on your machine and open a CLI in that folder. You should be able to
continue from that point.
More( Highcharts );
SunburstModule(Highcharts);
a. The top line imports all the different data types available from the customvis library. We
may not use all of them in this code, but we have them available as needed.
i. See CustomViz API for more info
b. Highcharts and highcharts-more are two different libraries that we will use to create our
custom viz.
c. More(Highcharts) just ties the two libraries together and get the “more” part ready to
use.
d. SunburstModule(Highcharts) ties the Sunburst library together as well.
5. Update the “create” method to the following by removing the line with “Basic VizBundle”:
Check the box next to “Step2_InitialChart_YourName - Custom Sunburst.zip” and click Download in the
top left corner. Unzip this file on your machine and open a CLI in that folder. You should be able to
continue from that point.
Now we have a basic chart working, but it doesn’t do much. If you try making it bigger or smaller, the
chart stays the same. We need a way for the chart to get updated.
1. An update method is part of the custom visualization library. It gets called every time the size of
the chart, a property, or the data is changed.
Add an update method:
Save Point #3 -- If your chart does not look like the above or something went wrong with compiling your
code, you can download the Step 3 file from the PM2 Download Site.
Check the box next to “Step3_ChartResize_YourName - Custom Sunburst.zip” and click Download in the
top left corner. Unzip this file on your machine and open a CLI in that folder. You should be able to
continue from that point.
Cognos has the chart in the Dashboard, but we need a way to pass it some data instead of having it
hardcoded.
1. From the main MyCustomViz folder, open the file vizdef.xml in your text or code editor
a. For more information on this file, see the Visualization Definition Guide
2. Add slots and dataSets:
<?xml version="1.0" encoding="UTF-8"?>
<visualizationDefinition version="3.1"
xmlns="http://www.ibm.com/xmlns/prod/ba/vipr/vizBundle/vizdef.3">
<slots>
<slot name="categories" caption="Categories" type="cat" optional="false" />
<slot name="values" caption="Values" type="cont" optional="false" />
</slots>
<dataSets>
<dataSet>
<ref slot="categories" />
<ref slot="values" />
</dataSet>
</dataSets>
</visualizationDefinition>
a. Slots add a space on the visualization add a data item from Cognos
i. The first slot is of type “cat” or “categorical”. This is used for any dimension type
data.
ii. The second slot is of type “cont” or “continuous”. This is used for any measure
type data.
b. dataSets tie that slot with an object that gets passed back to our custom visualization
code
3. Save the file
4. Review the CLI. It should say “Generating vizdef.xml”
5. In Cognos, delete the visualization from the Dashboard panel
6. Add the Test visualization back in from the Custom tab under Visualizations
a. This is needed when the vizdef.xml changes. They are not picked up when only doing a
refresh.
7. There should now be fields available:
Save Point #4 -- If your chart does not look like the above or something went wrong with compiling your
code, you can download the Step 4 file from the PM2 Download Site.
Check the box next to “Step4_SlotsAdded_YourName - Custom Sunburst.zip” and click Download in the
top left corner. Unzip this file on your machine and open a CLI in that folder. You should be able to
continue from that point.
rows.forEach(row => {
for (var i = 0; i < row.tuple("categories").segments.length; i++) {
if(!keys.includes(row.tuple("categories").segments.slice(0,i+1).map(e => e.caption).join("|"))) {
keys.push(row.tuple("categories").segments.slice(0,i+1).map(e => e.caption).join("|"));
result.push(
{
"name":row.tuple("categories").segments[i].caption,
"id":row.tuple("categories").segments.slice(0,i+1).map(e => e.caption).join("|"),
"parent": i == 0 ? "total" : row.tuple("categories").segments.slice(0,i).map(e => e.caption).join("|"),
"value": i == row.tuple("categories").segments.length-1 ? row.value("values") : null
}
);
}
}
});
return result;
}
b. This function iterates through all the rows from the Cognos data and generates a result
array that gets passed to Highcharts. This result array contains objects that have four
attributes: name, id, parent, and value. Depending on the level, some attributes may be
null. For instance, the value attribute is only populated at the lowest level of data.
8. Save the file
9. Validate it compiles in your CLI
10. Refresh the chart in Cognos
11. Add a source for you Dashboard
a. Public Folders → Data → 2019 NFL Game Data
12. Add “down” as Categories
13. Add “play_id” to the Values field
14. This should result in a chart that shows us how many plays there were for each down. It should
look like this:
Check the box next to “Step5_DataConnected_YourName - Custom Sunburst.zip” and click Download in
the top left corner. Unzip this file on your machine and open a CLI in that folder. You should be able to
continue from that point.
This gets us a basic chart that displays data, but it doesn’t provide very many configuration options. For
instance, what if I wanted to add my own title? Let’s add a couple properties to be able to customize it.
Save Point #6 -- If your chart does not look like the above or something went wrong with compiling your
code, you can download the Step 6 file from the PM2 Download Site.
Check the box next to “Step6_CustomTitle_YourName - Custom Sunburst.zip” and click Download in the
top left corner. Unzip this file on your machine and open a CLI in that folder. You should be able to
continue from that point.
The chart is functional now, and we can change the title. It’s still pretty bland though with only one
color. Let’s add some more configuration options to make a little more interesting.
if( _info.reason.data )
{
updateOptions.series = [
{
colorByPoint: true,
data: transformData(_info.data.rows)
}]
4. Refresh the chart in Cognos:
6. That answers the question, but as we add levels like this, the color becomes a bit too much. We
can add some more configuration to make it look better. Instead of coloring every section
differently, we can make some adjustments based on the level. Review
https://api.highcharts.com/highcharts/series.sunburst.levels
updateOptions.series = [
{
data: transformData(_info.data.rows),
levels: [{
level: 1,
color:"#FFFFFF"
}, {
level: 2,
colorByPoint: true
},
{
level: 3,
colorVariation: {
key: 'brightness',
to: -0.5
}
}, {
level: 4,
colorVariation: {
key: 'brightness',
to: 0.5
}
}]
}]
Level 1 is set to White. Level 2 is set to color by point. Levels 3 and 4 are to adjust the brightness of
Level 2 for their colors. This helps lower levels stay visually tied to their parent levels.
9. These are the default colors provided by HighCharts. We can also set our own set of colors. In
the “update” method under the properties change if-statement, add a line for setting colors. It
should look like this:
if ( _info.reason.properties )
{
updateOptions.title = {
text: _info.props.get ( "showChartTitle") ? _info.props.get ( "chartTitle") : null
};
updateOptions.colors = ['#33728f','#58508d','#bc5090','#ff6361','#ffa600'];
}
Check the box next to “Step7_LevelColoring_YourName - Custom Sunburst.zip” and click Download in
the top left corner. Unzip this file on your machine and open a CLI in that folder. You should be able to
continue from that point.
Now that we have a pretty functional sunburst chart, let’s go back to our use case. We wanted to know
how the distance to go and type of play affected the result.
3. Add yrdtogo_grouping
a. Short: 3 yards or less
b. Medium: 4 to 7 yards
c. Long: 8 or more yards
4. Add result_first_down_text
5. Update chart title
Now we can get a good sense of how many plays there were at each category breakdown, as well as the
success rate of different selections. For instance, look at the success of a pass up the middle on a
medium distance to go. Compared to passes to the left or right, it results in success a higher percentage
of the time, but there are significantly fewer pass plays up the middle compared to left or right.
Now that we have 4 levels in our sunburst chart, it can get difficult to see the outside slices. Let’s add
one more property to the chart to help with that.
if( _info.reason.data )
{
updateOptions.series = [
{
allowTraversingTree: true,
data: transformData(_info.data.rows),
levels: [{
level: 1,
…
Save Point #8 -- If your chart does not look like the above or something went wrong with compiling your
code, you can download the Step 8 file from the PM2 Download Site.
Check the box next to “Step8_CompletedViz_YourName - Custom Sunburst.zip” and click Download in
the top left corner. Unzip this file on your machine and open a CLI in that folder. You should be able to
continue from that point.
At this point, we might want to share our visualization with someone else. They may find it useful, or we
could at least get feedback on what other customizations should be made.
customvis pack
5. Option #1
a. If you have the appropriate privileges in your environment, open the Manage panel
b. Select Customization
c. Select Custom Visuals
d. Upload the zip file from your “YourName Custom Sunburst” directory
e. Open Dashboard or Report
f. Go to Visualizations and the Custom tab
g. Your visualization should now appear in the list for all users
c. Report:
From there you can add a special icon or add further description to help other users understand your
visualization in the package.json file. As you make updates, just pack them up again and update the
visualization through the Manage panel. All existing Dashboards and Reports will have the updated
version automatically.
Check the box next to “Custom Sunburst.packed.zip” and click Download in the top left corner. This zip
file is ready to upload to any 11.2.0 (may work with later 11.1 releases as well) and use in your
Dashboards and Reports.
• If you want to distribute the code, use the “customvis clean” command to remove the
dependencies from the folder. This will make it significantly smaller and easier to share.
• After running “customvis pack”, the packaged zip file contains everything needed to deploy the
visualization, but the TypeScript code will be compiled into JavaScript.