Search

Edition: Futurama Website

Module: Futurama Web

User: Developer

Prerequisites

- Futurama version 5.3+

 

Description

In this example an explanation is given on how FICO could be used for changing the standard graph library to an external graph library. Whenever a graph is created within the Futurama Editor the lay-out of the graph can be changed by using FICO. Using FICO to generate a different graph comes with a few advantages:

  • Faster pageloads after an AjaxUpdate due to client-side calls instead of server side calls
  • Total freedom of functionality (depending on which graph library there will be used)

In the following sections a step by step guide is presented on how an external graph library could be implemented by using FICO.

Scope

This example can be used whenever there is the wish to change the graph component by an external graph library. This example shows which modifications are needed and how an external graph library could be used to render a graph. Please note that each library has their own implementation. Within this example a library is used which is highly supported and is easy to setup.

Prerequisites example

Within this example the following elements are used:

  • Knowledge on how to setup FICO
  • jQuery version 2.1.4 (Currently latest production version of jQuery)
  • Highcharts (jQuery graph library)

To use these files within a Futurama Webdocument the following steps, which are explained below, needs to be executed.

STEP 1: Setup

Within this section an explanation is given on what files are needed to use a different graph library and how it should be configured within FICO.

Downloading/add required files

  1. Create an extension.xsl file - Futurama Intermediate Control Output (FICO)
  2. Add the extension file to the web.config - Configuration - Rendering

The following subsection is only applicable for the Highcharts library and therefore this may diverge from other graph libraries

Highchart files

To generate a Highcharts graph there are two  files needed that needs to be implemented:

  • The library source file: Highcharts.js (Highcharts 4.1.10 -> js -> Highcharts.js)
  • A specific Javascript file which calls the Highcharts function

STEP 2: Adding Files to the extension

It is possible to add/edit headers with FICO within a Futurama Website. A detailed explanation on how this could be done can be find here: FICO example - Change/Add HTML headers

To load the Highcharts files and to replace the current jQuery version with the latest version the following objects needs to be added to the extension.xsl within the RenderInput template:

<xsl:template match="/ren:RenderInput[ren:Folder='FicoGraph']" priority="2">
	<xsl:choose>
		<!--HTML-->
		<xsl:when test="$retrievalMode = 'html'">
			<xsl:apply-templates select="ren:FICO/*">
			</xsl:apply-templates>
		</xsl:when>
		<!--Headers-->
		<xsl:when test="$retrievalMode = 'headers'">
			<RenderOutput xmlns="http://www.actuit.nl/futurama/render/2015/08">                                                                               
				<!--Define javaScripts-->
				<Scripts>
					<Script>
						<File>FuturamaModules/1702/jquery.js</File>
						<Type>text/javaScript</Type>
					</Script>
					<Script>
						<File>FicoGraph/js/Highcharts/Highcharts.js</File>
						<Type>text/javaScript</Type>
					</Script>
					<Script>
						<File>FicoGraph/js/call_graph.js</File>
						<Type>text/javaScript</Type>
					</Script>
					<xsl:copy-of select="./ren:Scripts/ren:*[not(contains(ren:File,'jquery-1.4.1.min.js'))]">
					</xsl:copy-of>
				</Scripts>
			</RenderOutput>
		</xsl:when>
		<!--Render options have moved from web.config to to extention.xsl in 17.02-->
		<xsl:when test="$retrievalMode = 'options'">
			<RenderOptions xmlns="http://www.actuit.nl/futurama/render/2015/08">
				<ChartRenderMode>DataXmlPlusMicrosoftChart</ChartRenderMode>
				<RenderTelerikControls>false</RenderTelerikControls>
			</RenderOptions>
		</xsl:when>
	</xsl:choose>
</xsl:template>

In the above XML example there a couple of things that are important to note:

XSL Template match

As can be seen within the example above, within the template match parameter there is a conditional field. This conditional field checks whether the Folder name of the application is equal to FicoGraph. With this setting it is possible to only apply this graph converter template to one website. If another website is been added, for example a website called: FuturamaGraph, then this whole template is not executed and the standard graph functionality will be used.

Scripts - jQuery

The correct jQuery version is shipped with Futurama.

Scripts - Highcharts

To use Highcharts, two files are needed, and both are included within the FicoGraph application. Highcharts.js is a standard library filen, the other file is needed to generate a graph.

ChartRenderMode

The setting ChartrenderMode has moved from web.config to the extention.xsl, and for the FicoGRaph example it is set to DataXmlPlusMicrosoftChart. This allows rendering of custom graphs (client side) alongside with standard graphs. You can make this choice by specifying a GraphConverter template, see below.

STEP 3: Using the Graph data

When STEP 2 is completed regarding adding the files within the RenderInput template, the graph data could be used by adjusting the GraphConverter template. Within the GraphConverter template several objects can be used via XSLT. To retrieve the desired objects it is important to know which data could be used. Within the following section an explanation is given on which data can be used and how it could be retrieved:

FICO LOG XML

The XML code of a graph converter can be achieved, if it is been added to a Futurama Document, by checking the debug file. When a Futurama document is been viewed within a browser, FICO generates a debug file which shows the content of each object in XML. Based on the XML code a XSL template can be created as been shown above. Please keep in mind that the logging should be enabled within the web.config. For more information regarding logging see this page: Configuration - Log.

Within the example that is been used, the following XML is logged:

<RenderInput xmlns="http://www.actuit.nl/futurama/render/2015/08">
	<FICO>
		<WebPage id="id2" xmlns="http://www.actuit.nl/futurama/FICO/2015/06">
			<WebPanel id="id38">
				<GraphConverter id="id23">
					<MicrosoftChart>
						<img src="/portals/0/chart.aspx?id=0&cache=FICO Graph_0_2" id="id23" />
					</MicrosoftChart>
					<Data>
						<Chart rendertype="BinaryStreaming" ismapenabled="False" antialiasing="None" width="1000" height="800" borderwidth="0">
							<Series>
								<Series name="Dollar" legend="Legend1" xvaluetype="Double" yvaluetype="Double" shadowcolor="" charttype="Area" ChartArea="chart" color="Red">
									<Points>
										<Datapoint xvalue="2000" yvalues="1.37984"/>
										<Datapoint xvalue="2001" yvalues="1.38572"/>
										<Datapoint xvalue="2002" yvalues="1.38921"/>
										<Datapoint xvalue="2003" yvalues="1.39227"/>
										<Datapoint xvalue="2004" yvalues="1.4078"/>
										<Datapoint xvalue="2005" yvalues="1.41923"/>
										<Datapoint xvalue="2006" yvalues="1.42242"/>
										<Datapoint xvalue="2007" yvalues="1.42119"/>
										<Datapoint xvalue="2008" yvalues="1.42223"/>
										<Datapoint xvalue="2009" yvalues="1.42206"/>
										<Datapoint xvalue="2010" yvalues="1.42238"/>
										<Datapoint xvalue="2011" yvalues="1.42238"/>
										<Datapoint xvalue="2012" yvalues="1.42662"/>
										<Datapoint xvalue="2013" yvalues="1.42701"/>
										<Datapoint xvalue="2014" yvalues="1.42771"/>
										<Datapoint xvalue="2015" yvalues="1.42704"/>
									</Points>
								</Series>
								<Series name="Pond" legend="Legend1" xvaluetype="Double" yvaluetype="Double" shadowcolor="" charttype="Area" ChartArea="chart" color="Blue">
									<Points>
										<Datapoint xvalue="2000" yvalues="1.3235"/>
										<Datapoint xvalue="2001" yvalues="1.3251"/>
										<Datapoint xvalue="2002" yvalues="1.3271"/>
										<Datapoint xvalue="2003" yvalues="1.3177"/>
										<Datapoint xvalue="2004" yvalues="1.3201"/>
										<Datapoint xvalue="2005" yvalues="1.3122"/>
										<Datapoint xvalue="2006" yvalues="1.3059"/>
										<Datapoint xvalue="2007" yvalues="1.3036"/>
										<Datapoint xvalue="2008" yvalues="1.3048"/>
										<Datapoint xvalue="2009" yvalues="1.3029"/>
										<Datapoint xvalue="2010" yvalues="1.3028"/>
										<Datapoint xvalue="2011" yvalues="1.3018"/>
										<Datapoint xvalue="2012" yvalues="1.3062"/>
										<Datapoint xvalue="2013" yvalues="1.3025"/>
										<Datapoint xvalue="2014" yvalues="1.301"/>
										<Datapoint xvalue="2015" yvalues="1.3398"/>
									</Points>
								</Series>
							</Series>
							<ChartAreas>
								<ChartArea backcolor="White" name="chart">
									<Axisy islabelautofit="False" titlefont="Verdana, 7pt" intervaltype="Number" intervaloffsettype="Number" intervalautomode="VariableCount" ismarginvisible="False" maximum="1.42771" minimum="1.301">
										<LabelStyle font="Verdana, 7pt">
										</LabelStyle>
									</Axisy>
									<Axisx islabelautofit="False" titlefont="Verdana, 7pt" intervaltype="Number" intervaloffsettype="Number" intervalautomode="VariableCount" ismarginvisible="False">
										<LabelStyle font="Verdana, 7pt">
										</LabelStyle>
									</Axisx>
								</ChartArea>
							</ChartAreas>
							<Legends>
								<Legend name="Legend1" dockedtoChartArea="chart" isdockedinsideChartArea="False" istextautofit="False" legendstyle="Column" backcolor="Transparent" font="Verdana, 7pt" legenditemorder="ReversedSeriesOrder">
								</Legend>
							</Legends>
						</Chart>
					</Data>
				</GraphConverter>
			</WebPanel>
		</WebPage>
	</FICO>
	<Folder>FICOGraph</Folder>
	<MetaTags>
		<Scripts>
			<Script>
				<File>Scripts/jquery-1.4.1.min.js</File>
				<Type>text/javaScript</Type>
			</Script>
			<Script>
				<File>Scripts/FuturamaScripts.js</File>
				<Type>text/javaScript</Type>
			</Script>
		</Scripts>
	</MetaTags>
</RenderInput>

Graphconverter template

By specifying this template we can override the default rendering of Microsoft Charts specific to the graph level. In the Fico Graph example, a pie chart is rendered default, and an area graph is rendered as HighChart. The data from the Fico is used as input for the Highcharts function, through overriding the default GraphConverter template for graph-id 'id23'. In the example there are two series that contains data. Each series is dedicated to a single variable. This variable is been passed to the CallGraph function, which used this data as input for the Highcharts graph. Every object that FICO returns can be used via XSLT. In the example can be seen that not only the series are used but also the minimum and maximum values. Every object can be passed towards a function, depending on the desired graph library that is used.

<xsl:template match="fut:GraphConverter[@id='id23']">
	<script type="text/javascript">
			$(function () {
				var series1 = [<xsl:for-each select="//fut:Series[@Name='Dollar']//fut:DataPoint">[<xsl:value-of select="@XValue" />,<xsl:value-of select="@YValues" />],</xsl:for-each>];
				var series2 = [<xsl:for-each select="//fut:Series[@Name='Pond']//fut:DataPoint">[<xsl:value-of select="@XValue" />,<xsl:value-of select="@YValues" />],</xsl:for-each>];
				var minimum = <xsl:value-of select="//fut:AxisY/@Minimum" />;
				var maximum = <xsl:value-of select="//fut:AxisY/@Maximum" />;				
				setGraph(series1,series2,minimum,maximum);
			});
	</script>
	<div id="container" style="width: 1000px; height: 500px;"/>		
</xsl:template>

Download Example File

Download files

The result of the total implementation of objects within the extension.xsl can be seen in the example file which can be downloaded. You can download the example file by clicking on the image at the right.

Related Topics

- WebAPI Overview: This document explains the WebAPI architecture.

Feedback

If you have any questions about this subject or if you want to provide us feedback please send us an e-mail.

Updated: 2017-11-14