Forum

icCube support is given through stackoverflow for the Community Edition as well as for generic questions on the Enterprise edition.

Don’t forget to quote your questions with iccube

or iccube-reporting tags.

For the Enterprise version, support is given through our email, support at iccube.com

You may nevertheless find some help from our How-To videos in the Academy’s page

Analytics video
Learn more
In this academy post we are going to show how to create your own HTML Widget using icCube Reporting 6. What are Widgets ? They allow for defining your own visualization charts (html/javascript), add options to them and save them so it can be reused in other reports. Once published users without technical knowledge can use them as any other charts in icCube. For this you'll need some html and javascript knowledge. The first step is deciding what kind of visualization we want. Do no underestimate this task and ideally this is to be done by a designer that will help you giving a professional and consistent look to your reports. If you don't have these resources in-house you might contact icCube or use freelancers on one of the existing available freelancers platform. Let's start. Our first task is to decide what kind of visualization we want and how our widget should look like. post-your-first-html-widget-1 The left is an example on how the widget should look like, the right part defines the parameters that will come from the data query. On top of these parameters, we will add the widgets background color. For the image, we will use the fonts that are freely available from Font Awesome but you can change this with any image or icon that better suits your business. With this image draft, ok we're cheating it's also the final version, we will create an html version of the chart. It's not the goal of this post to go over the technical details how do it, but you can check and play with the final version in codepen. Pay attention that the widget is going to be included into the icCube reporting and inserted into a div with a defined width and height that the report user can freely define. [Hint] When using css classes you should ensure there is no name collision with other html components. We're going to prefix all Academy examples with ic3a- , that should be unique in the whole html page. Now we are ready to start integrating into icCube our new widget.

The Data

Before starting with the widget lets spend a bit of time on the data. The widgets will use the parameters from an MDX query that a result should look like : [table] ,Amount,Difference from previous year,Icon License,$4 500, +23%,fa-bicycle [/table] Where License is our AmountLabel, and Difference from previous year is our Amount2Label. We could alternatively add two additional measures for the label that is more verbose. The MDX query in our standard MDX Sales schema would look like : [icCubeMdx]
WITH
  MEMBER [Measures].[Difference Previous Day] AS PercN( [Measures].[Count] , ( [Time].[Year].prevMember , [Measures].[Count] ) ) , FORMAT_STRING="percent"
  MEMBER [Measures].[IconName] AS CASE
    WHEN [Product].[Product].currentMember is [Product].[Product].[Category].[License] THEN "fa-cubes"
    ELSE "fa-phone" END
SELECT
  {[Measures].[Count],[Measures].[Difference Previous Day],[Measures].[IconName]} ON 0,
  {[Product].[Product].[Category]} on 1
FROM [Sales]
WHERE [Time].[Year].[2007]
[/icCubeMdx]

The Visualization

From here we're starting to work on the core of creating a new widget with icCube's latest reporting tool, it's time to start icCube reporting tool.   1 . Copy the css to the report Here we have two options, we could directly inject the css into the html style attribute or add the css classes to the whole reporting (you might also add the css just for the report in Configuration / Report CSS ). For this example we will copy the css, on the bottom of the page, to the common css (Admin / Common CSS) so it's available on all reports. 2 . Create a new report and add an empty chart, 'Chart/Widget'.   3. Now copy and paste the MDX statement into our query   4. Navigate to the 'Data Render'. Here we are. A widget template is divided in two main parts. Properties and Options. Properties define new fields that will be seen as widget options and allow the end user to easily parametrize the widget. In our example we're going to define one properties, background-color. You can see in the left how the two new properties fields that we're going to use in the options part. The option part has 4 fields, Initial HTML, HTML, On Data Received and After Render. Initial HTML and HTML are two static text fields that define the html code the widget will render without any data and after receiving the query result. 'On Data Received' field allows for creating on the fly the html each time a new request result is received by the widget. Once the html is available it's going to be inserted into the DOM (browser page). 'After Render' allows for working directly on the DOM , binding events, using jquery and creating complex html/javascript effects. For this example we're going to put all code in the 'After Render', but feel free to use the other fields as well. The code is document so it should be easy to understand. [code language="javascript"] function(context, node, props) { // debugger; //uncomment to debug using browser's debugger // Jquery node for the widget $node = $(node).html(" <div class='ic3a-container'> "); // html code for our boc var htmlTemplate = " <div class='ic3a-mini-box-c'> " + " <div class='ic3a-mini-box' id='$id$'> " + "<i class='ic3a-sep fa'></i>" + " <div class='value'>$value$</div> " + " <div class='measure'>$valueLabel$</div> " + " <div class='description'><span class='diff'>$valueDif$</span> <span class='description-text'>$labelDif$</span></div> " + "</div> </div> </div> "; // the actual html node where we will insert the boxes var $widget = $node.find(".ic3a-container").empty(); // for each row create a box for (var r = 0, h = context.rowsCount; r < h; r++) { // the field values for the box var labelR = context.rowLabel(r); var labelL = context.columnLabel(1); var val = context.cellFValue(r, 0); var valDiff = context.cellFValue(r, 1); // this creates an uniqueId on the whole report var id = ic3.uniqueId("ic3-mini-box"); // let's do a straight forward string substituion for all our parameters var htmlWdiget = htmlTemplate.replace("$id$",id).replace("$value$",val) .replace("$valueLabel$",labelR).replace("$valueDif$",valDiff).replace("$labelDif$",labelL); // append the html code, now it's in the DOM (visible) $widget.append(htmlWdiget); // for this parameters let's do a bit of JQuery, but a replace string // would be fine too. var color = props.backgroundColor(r,0); var iconClassName = context.cellFValue(r, 2); // direct manipulation/substituion on DOOM var $mWidget = $widget.find("#" + id); $mWidget.css('background-color', color); $mWidget.find(".fa").addClass(iconClassName); } } [/code] The debugger code that is commented when uncommented allows for debugging the code when your browser debugger is active. The browser debugger will stop at the js statement, yes this is amazing. Now our widget is finished and we can test it. Once we are fine with our widget we can save it, provided you've the rights, as a template to be reused in any of the reports. academy-firstwidget-final   icCube is deployed with a couple of already made Html Templates, feel free to check how they are implement as the code is available.  For example, the 'Progress Bar' is implemented like an html template that is a different way to implement a template. D3 examples are implemented more like this example, pure javascript code. CSS Code [code language="css"] .ic3a-container { width: 100%; color: white; } .ic3a-mini-box-c { display: inline-block; width: 500px; } .ic3a-mini-box { height: 150px; margin: 15px; padding: 20px; background-color:red } .ic3a-mini-box i { display: block; height: 100%; line-height:100px; font-size: 60px; width: 100px; float: left; text-align: center; border-right: 2px solid rgba(255, 255, 255, 0.5); margin-right: 20px; padding-right: 20px; color: white; } .ic3a-mini-box .value { font-size: 2em; } .ic3a-mini-box .measure { font-size: 1.5em; } .ic3a-mini-box .description { margin-top: 15px; } [/code]
Analytics video
Learn more
Always wanted to show location based insights to your audience on a vector map of your own (and not Google maps)? With icCube's custom "Widget Template" you can! Here is how.... In this blog post I will explain how to create a custom spatial dashboard from a vector map and link the images to the data in icCube. But before you continue, please do not overwhelm your audience with spatial dashboards, just because you can! Always be intentional in why you choose for a particular visualization. A spatial dashboard can be of enormous help in very specific situations, but it can be really annoying, to say the least, if you apply it to answer questions your audience is not interested in. So far the "teacher" ... now on to the fun part. In the next steps, I will guide you how to create a spatial dashboard yourself, by using a simple example for a cinema. Below you will see the cinema map (one room only) on which the seats are plotted. The general idea here is that we will analyze sales per seat; seats will light up (green) if a ticket has been sold for that day (I admit, this is not really a "killer" business case). A live demo can be found here.

ingredients for a spatial dashboards

  • a vector map with objects that can be linked to data
  • an svg editor to edit the map
  • a text file editor
  • a hierarchy in icCube that contains unique object IDs that can be linked to objects in the vector map (in this example we have the dimension "chair" and the metric “tickets sold”).
All the files for the example can be downloaded here.

steps for making the dashboard

step 1 - create or update the vector map

This is the creative part. Create or import a map in a drawing tool that supports vectors. For this tutorial I have created a floor plan for the cinema in Inkscape: each seat is a rectangle. The cinema has 5 rows (A - E) and 8 seats (1 - 8): [caption id="attachment_984" align="aligncenter" width="300"]svg drawing that is used in the dashboard vector drawing to be used in the dashboard in Inkscape[/caption] The colors of the seats are just for illustration purposes only as these will eventually be set by icCube, based on the underlying data.

step 2 - name all objects to corresponding IDs in data

This is the "magic trick". To allow the seats (or vector objects) to be linked to the icCube data, each object must have a unique identifier (ID) that is also available in icCube. In Inkscape, this can be done by selecting the rectangle and then pressing ctrl + shift + o and adding the unique ID. In this case I use the seat code as unique ID: [caption id="attachment_985" align="aligncenter" width="300"]change the object ID to the icCube dimension element add the unique ID to the object[/caption]

step 3 - group the changeable objects

Group all the changeable objects and assign a unique id so it can be addressed using CSS. In this example we have provided a hover effect for each seat using CSS. This can be done by selecting and grouping all the seats and providing it with a recognizable ID, e.g. “chairs”: [code language="CSS"] #cinema1 g #chairs rect:hover { cursor: pointer; opacity: 0.5; } #cinema1 g #chairs rect.on { stroke: black; stroke-width: 1px; } [/code] Save the file and close the svg editor. Note that each object that you want to be colored by icCube should have a unique distinct ID.

step 4 - prepare your icCube model

Ensure that you have a dimension in your schema that consists of elements that have the ID you provided to the objects in the previous step. I have created a schema using the “in memory” data source with a dimension called "chair". In practice you would build a dimension based on the metadata in your ticketing system. The "in-memory" data has the following columns: [table] column,data type, example date ticket sold, date field, e.g. 1 Nov 2016 chair, alphanumeric, ID for the seat e.g. A4 or E1 ticket sold, integer, number of tickets sold [/table] Below the in-memory data source in the icCube Builder and its columns: [caption id="attachment_986" align="aligncenter" width="300"]source data as used for this tutorial. Note the "chair" matches the object ID in the svg source data as used for this tutorial. Note the "chair" matches the object ID in the svg[/caption] The dimension “Chair” has been set up as:
  • key column = chair
  • name column = chair
(In practice, the key column would be a unique number and the name a meaningful label that is readable to the end user). [caption id="attachment_987" align="aligncenter" width="300"]set-up of the "chair". Note that the key column equals the object ID in the svg set-up of the "chair". Note that the key column equals the object ID in the svg[/caption] That is a bit all there is for the model. The following MDX statement will provide the number of tickets per seat. Its result is going to be used in the dashboard: [icCubeMdx]
SELECT {[Measures].[tickets]} ON 0,
[Chairs].[Chair].[chair].allmembers ON 1
FROM [Cube]
CELL PROPERTIES VALUE, FORMATTED_VALUE, STYLE
[/icCubeMdx]  

step 5 - blend all together in the widget template

Now, it is finally time to do some "magic". Let's bind all ingredients into a dashboard. Please stay with me, as this might get a bit complicated ;-). First, we start with a fresh dashboard on the cinema schema described in the previous step and add a "Widget Template" (more details on this functionality can be found here). To enable you to see the result, paste the MDX statement from the previous step in the "data" section (press tab "MDX" to paste it). Navigate to the "Data Render" tab and add the property "Background Color" so it can be referenced later: [caption id="attachment_1049" align="aligncenter" width="300"]add the property "Background Color" so it can be used in the widget add the property "Background Color" so it can be used in the widget[/caption] Click on "Options" and fill the "After Render" and "HTML, data received" with the information further on in the blog post: [caption id="attachment_1050" align="aligncenter" width="300"]specific options for the spatial-bi blog post, refer to the text as how to make it specific options for the spatial-bi blog post, refer to the text as how to make it[/caption] Then, open the svg file of the map you using a text editor. Select and copy the HTML code and paste it in the "HTML, data received" section: [caption id="attachment_1051" align="aligncenter" width="300"]paste the svg text in the HTML after ... paste the svg text in the HTML after ...[/caption]
Here is a sample of the code. Note that there is a bit of HTML code at the end that must be added as well (between the <style> and </style>):
[code language="HTML"] &amp;lt;?xml version="1.0" encoding="UTF-8" standalone="no"?&amp;gt; &amp;lt;!-- Created with Inkscape (http://www.inkscape.org/) --&amp;gt; &amp;lt;svg &amp;nbsp;&amp;nbsp; xmlns:dc="http://purl.org/dc/elements/1.1/" &amp;nbsp;&amp;nbsp; xmlns:cc="http://creativecommons.org/ns#" &amp;nbsp;&amp;nbsp; xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" &amp;nbsp;&amp;nbsp; xmlns:svg="http://www.w3.org/2000/svg" &amp;nbsp;&amp;nbsp; xmlns="http://www.w3.org/2000/svg" &amp;nbsp;&amp;nbsp; xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd" &amp;nbsp;&amp;nbsp; xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape" &amp;nbsp;&amp;nbsp; id="cinema1" &amp;nbsp;&amp;nbsp; version="1.1" &amp;nbsp;&amp;nbsp; inkscape:version="0.91 r13725" &amp;nbsp;&amp;nbsp; ... etcetera &amp;lt;/svg&amp;gt; &amp;lt;style&amp;gt; &amp;nbsp;&amp;nbsp;&amp;nbsp; #cinema1 g #chairs rect:hover { &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; cursor: pointer; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; opacity: 0.5; &amp;nbsp;&amp;nbsp;&amp;nbsp; } &amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; #cinema1 g #chairs rect.on { &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; stroke: black; &amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;stroke-width: 1px; &amp;nbsp;&amp;nbsp;&amp;nbsp; } &amp;lt;/style&amp;gt; &amp;lt;script&amp;gt; &amp;nbsp;&amp;nbsp;&amp;nbsp; var allObjects = $("#cinema1 #chairs rect"); &amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; allObjects.on("click", function() { &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;allObjects.removeAttr("class"); &amp;nbsp; &amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;$(this).attr("class", "on"); &amp;nbsp;&amp;nbsp;&amp;nbsp; }); &amp;lt;/script&amp;gt; [/code] As a next step, add the javascript code to the "After Render" section: [caption id="attachment_1052" align="aligncenter" width="300"]add the javascript code in the text to this field add the javascript code in the text to this field[/caption] This is the code: [code language="javascript"] /** &amp;nbsp;* You can bind events to node and it's children &amp;nbsp;*/ function(context, node, props) { &amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;for (var row = 0; row &amp;lt; context.rowsCount; row++) { &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; var idd = context.RowLabel(row); &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; //var color = context.getValue(row, 0); &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; var color = props.backColor(row,0) || '#ccc'; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; // Find object &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; var $object = $(node).find("#" + idd); &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; // Change color and add row click &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; $object.attr('style', 'fill:' + color) &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; .click(function(row) { &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; context.fireRowClick(row, 0); &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; context.fireCellClick(row, 0); &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; }.bind(this, row)); &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; // it's a bit special managing svg &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; var titleElem = document.createElementNS("http://www.w3.org/2000/svg", "title"); &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; titleElem.textContent =&amp;nbsp; 'seat '+ idd + ', tickets sold: '&amp;nbsp; + context.getValue() ; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; $object.append( titleElem ); &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; } }[/code]
You are almost there...
Click on the property "Background Color" value "Pallete for Cell values" and select the following:
[caption id="attachment_1053" align="aligncenter" width="300"]select the palette to color the data select the palette to color the data[/caption] You should now be able to see the colored cinema seats. If so, save the template so it can be used in any other dashboard: In the "data render" tab, press [Save]: [caption id="attachment_1054" align="aligncenter" width="300"]save the template so you can use it in any dashboard save the template so you can use it in any dashboard[/caption]  

step 6 - use the template in your dashboard

Create a new dashboard and add the filter widgets of your choice. To add the cinema template, just created, select "Charts" > "Widget Template". Add your MDX (remember to have the chair in the row and the numeric data in the first column). On the "data render" tab, click on the "default" icon under "Preset". Now all available saved custom templates will be displayed. Select the one just created "Inside Vision Spatial Dashboard": [caption id="attachment_1055" align="aligncenter" width="300"]use the previously created template in this dashboard use the previously created template in this dashboard[/caption] By changing the "Palette for Cell Values" for the property "Background color" you can tweak how the data is translated to colors. This is my end-result: [caption id="attachment_1056" align="aligncenter" width="300"]the end result: the spatial bi dashboard showing ticket sales for a cinema the end result: the spatial bi dashboard showing ticket sales for a cinema[/caption]   This was the last step of the tutorial, if you copied my steps, you should have now a spatial BI map of your choice. You can find the precise settings in the online demo (press the "Edit" link).

More applications of the vector map

This icCube functionality is not limited to maps only. Any vector based file can be linked in this way to icCube. We think to use this functionality for our clients for the following applications:
  • interactive maps (hotels, flex workspace usage, holiday rentals, …)
  • interactive flow charts
  • custom sales funnels (not the standard boring pictures ;-))
  • interactive diagrams (machines, in- and outflows, education)
May be you have some great idea’s how to apply this nice feature to your company’s or clients’ data. Please share with us, so we together can build and educate the icCube community to create killer dashboards that really turn data into value.

FAQ

  • My svg doesn’t fit in the container, and it doesn’t adjust to the size of the container. The width and height of the svg are defined in the svg code itself. You can change these by changing the values of the width and height attribute. Preferably, set these to 100% (see the demo example).
  • The hover effect doesn’t work Recheck if the grouped id and the CSS selector are the same. If this isn’t the case, maybe your items are not rectangles, but paths. You can check this in the svg code. Simply change the CSS selector to path instead of rect.Another possible cause could be that the opacity is hard-coded in the svg. Check the objects in the svg code. Ensure to remove the opacity or fill-opacity field in the styling attribute for all objects using a simple text search and replace.
  • The click effect doesn’t work The click effect changes the stroke and the stroke-width. These attributes are probably hard-coded in your svg code. For each object in the svg code, remove these fields in the styling attribute. This can be done with a text search and replace.
  • I would like to change another svg attribute, next to the color At present, this is not supported, but you can contact icCube services to see how your specific needs can be addressed shortly.
 
Analytics video
Learn more