Permalink
Browse files

Merge pull request #1 from afishbeck/google_charts

Create examples of google chart visualizations using HPCC

Reviewed-By: Richard Chapman <rchapman@hpccsystems.com>
  • Loading branch information...
2 parents d8e5541 + ef812ba commit ee7366c9f803ef96af6bc687b0ad2c23400b910b @richardkchapman richardkchapman committed Nov 15, 2011
@@ -0,0 +1,42 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+##############################################################################
+# Copyright (C) 2011 HPCC Systems.
+#
+# All rights reserved. This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU Affero General Public License as
+# published by the Free Software Foundation, either version 3 of the
+# License, or (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU Affero General Public License for more details.
+#
+# You should have received a copy of the GNU Affero General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
+##############################################################################
+-->
+<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
+ <xsl:template match="Dataset[starts-with(@name,'BarChart')]" mode="generate_body">
+ <h1><xsl:value-of select="translate(substring-after(@name, 'BarChart_'),'_',' ')"/></h1>
+ <div style="height: 400px; width: 600px;">
+ <xsl:attribute name="id"><xsl:value-of select="@name"/></xsl:attribute>
+ </div>
+ </xsl:template>
+ <xsl:template match="Dataset[starts-with(@name,'BarChart')]" mode="generate_script">
+ <xsl:text>
+ google.setOnLoadCallback(draw</xsl:text><xsl:value-of select="@name"/><xsl:text>);
+ function draw</xsl:text><xsl:value-of select="@name"/><xsl:text>() {
+ var data = new google.visualization.DataTable(</xsl:text>
+ <xsl:call-template name="outputJsonGoogleChartDataTable"/>
+ <xsl:text>,
+ 0.6
+ );
+ var options = {is3D: true};
+ var barchart = new google.visualization.BarChart(document.getElementById('</xsl:text><xsl:value-of select="@name"/><xsl:text>'));
+ barchart.draw(data, options);
+ }
+ </xsl:text>
+ </xsl:template>
+</xsl:stylesheet>
@@ -0,0 +1,53 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+##############################################################################
+# Copyright (C) 2011 HPCC Systems.
+#
+# All rights reserved. This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU Affero General Public License as
+# published by the Free Software Foundation, either version 3 of the
+# License, or (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU Affero General Public License for more details.
+#
+# You should have received a copy of the GNU Affero General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
+##############################################################################
+-->
+<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
+ <xsl:output method="html"/>
+ <xsl:include href="json_chart_data.xslt"/>
+ <xsl:include href="table.xslt"/>
+ <xsl:include href="piechart.xslt"/>
+ <xsl:include href="linechart.xslt"/>
+ <xsl:include href="barchart.xslt"/>
+ <xsl:include href="geochart.xslt"/>
+ <xsl:include href="geomapchart.xslt"/>
+ <xsl:include href="timelinechart.xslt"/>
+ <xsl:include href="motionchart.xslt"/>
+ <xsl:include href="sparklinechart.xslt"/>
+ <xsl:include href="scatterchart.xslt"/>
+ <xsl:template match="/">
+ <xsl:apply-templates select="*/Results/Result"/>
+ </xsl:template>
+ <xsl:template match="Result">
+ <html>
+ <head>
+ <meta http-equiv="content-type" content="text/html; charset=utf-8"/>
+ <title>ECL Workunit Web View using Google Visualization API. </title>
+ <script type="text/javascript" src="http://www.google.com/jsapi"> </script>
+ <script type="text/javascript"><xsl:text>
+ google.load('visualization', '1.0', {packages: ['corechart', 'geochart', 'annotatedtimeline', 'table', 'motionchart', 'ImageSparkLine']});
+ </xsl:text>
+ <xsl:apply-templates select="Dataset" mode="generate_script"/>
+ </script>
+ </head>
+ <body>
+ <xsl:apply-templates select="Dataset" mode="generate_body"/>
+ </body>
+ </html>
+ </xsl:template>
+</xsl:stylesheet>
@@ -0,0 +1,53 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+##############################################################################
+# Copyright (C) 2011 HPCC Systems.
+#
+# All rights reserved. This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU Affero General Public License as
+# published by the Free Software Foundation, either version 3 of the
+# License, or (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU Affero General Public License for more details.
+#
+# You should have received a copy of the GNU Affero General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
+##############################################################################
+-->
+<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
+ <xsl:template match="Dataset" mode="generate_body">
+ <h1><xsl:value-of select="translate(@name, '_',' ')"/></h1>
+ <div style="height: 400px; width: 600px;">
+ <xsl:attribute name="id"><xsl:value-of select="@name"/></xsl:attribute>
+ </div>
+ </xsl:template>
+ <xsl:template match="Dataset" mode="generate_script">
+ <xsl:text>
+ google.setOnLoadCallback(load</xsl:text><xsl:value-of select="@name"/><xsl:text>);
+ var chartEditor = null;
+ function load</xsl:text><xsl:value-of select="@name"/><xsl:text>() {
+ var data = new google.visualization.DataTable(</xsl:text>
+ <xsl:call-template name="outputJsonGoogleChartDataTable"/>
+ <xsl:text>,
+ 0.6
+ );
+ var options = {};
+ // Create the chart to edit.
+ var wrapper = new google.visualization.ChartWrapper({
+ 'chartType':'PieChart',
+ 'options': {}
+ });
+ wrapper.setDataTable(data);
+ chartEditor = new google.visualization.ChartEditor();
+ google.visualization.events.addListener(chartEditor, 'ok', redraw</xsl:text><xsl:value-of select="@name"/><xsl:text>);
+ chartEditor.openDialog(wrapper, {});
+ }
+ function redraw</xsl:text><xsl:value-of select="@name"/><xsl:text>(){
+ chartEditor.getChartWrapper().draw(document.getElementById('</xsl:text><xsl:value-of select="@name"/><xsl:text>'));
+ }
+ </xsl:text>
+ </xsl:template>
+</xsl:stylesheet>
@@ -0,0 +1,44 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+##############################################################################
+# Copyright (C) 2011 HPCC Systems.
+#
+# All rights reserved. This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU Affero General Public License as
+# published by the Free Software Foundation, either version 3 of the
+# License, or (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU Affero General Public License for more details.
+#
+# You should have received a copy of the GNU Affero General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
+##############################################################################
+-->
+<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
+ <xsl:output method="html"/>
+ <xsl:include href="json_chart_data.xslt"/>
+ <xsl:include href="editor.xslt"/>
+ <xsl:template match="/">
+ <xsl:apply-templates select="*/Results/Result"/>
+ </xsl:template>
+ <xsl:template match="Result">
+ <html>
+ <head>
+ <meta http-equiv="content-type" content="text/html; charset=utf-8"/>
+ <title>ECL Workunit Web View using Google Chart Editor.</title>
+ <script type="text/javascript" src="http://www.google.com/jsapi"> </script>
+ <script type="text/javascript"><xsl:text>
+ google.load('visualization', '1.0', {packages: ['charteditor']});
+ </xsl:text>
+ <xsl:apply-templates select="Dataset" mode="generate_script"/>
+ </script>
+ </head>
+ <body>
+ <xsl:apply-templates select="Dataset" mode="generate_body"/>
+ </body>
+ </html>
+ </xsl:template>
+</xsl:stylesheet>
@@ -0,0 +1,43 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+##############################################################################
+# Copyright (C) 2011 HPCC Systems.
+#
+# All rights reserved. This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU Affero General Public License as
+# published by the Free Software Foundation, either version 3 of the
+# License, or (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU Affero General Public License for more details.
+#
+# You should have received a copy of the GNU Affero General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
+##############################################################################
+-->
+<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
+ <xsl:template match="Dataset[starts-with(@name,'GeoChart')]" mode="generate_body">
+ <h1><xsl:value-of select="translate(substring-after(@name, 'GeoChart_'),'_',' ')"/></h1>
+ <div style="height: 400px; width: 600px;">
+ <xsl:attribute name="id"><xsl:value-of select="@name"/></xsl:attribute>
+ </div>
+ </xsl:template>
+ <xsl:template match="Dataset[starts-with(@name,'GeoChart')]" mode="generate_script">
+ <xsl:text>
+ google.setOnLoadCallback(draw</xsl:text><xsl:value-of select="@name"/><xsl:text>);
+ function draw</xsl:text><xsl:value-of select="@name"/><xsl:text>() {
+ var data = new google.visualization.DataTable(</xsl:text>
+ <xsl:call-template name="outputJsonGoogleChartDataTable"/>
+ <xsl:text>,
+ 0.6
+ );
+
+ var options = {colors: ['darkblue', 'darkred'], title: '</xsl:text><xsl:value-of select="translate(substring-after(@name, 'GeoChart_'), '_', ' ')"/><xsl:text>'};
+ var geochart = new google.visualization.GeoChart(document.getElementById('</xsl:text><xsl:value-of select="@name"/><xsl:text>'));
+ geochart.draw(data, options);
+ }
+ </xsl:text>
+ </xsl:template>
+</xsl:stylesheet>
@@ -0,0 +1,48 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+##############################################################################
+# Copyright (C) 2011 HPCC Systems.
+#
+# All rights reserved. This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU Affero General Public License as
+# published by the Free Software Foundation, either version 3 of the
+# License, or (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU Affero General Public License for more details.
+#
+# You should have received a copy of the GNU Affero General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
+##############################################################################
+-->
+<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
+ <xsl:template match="Dataset[starts-with(@name,'GeomapChart')]" mode="generate_body">
+ <h1><xsl:value-of select="translate(substring-after(@name, 'GeomapChart_'),'_',' ')"/></h1>
+ <div style="height: 400px; width: 600px;">
+ <xsl:attribute name="id"><xsl:value-of select="@name"/></xsl:attribute>
+ </div>
+ </xsl:template>
+ <xsl:template match="Dataset[starts-with(@name,'GeomapChart')]" mode="generate_script">
+ <xsl:text>
+ google.setOnLoadCallback(draw</xsl:text><xsl:value-of select="@name"/><xsl:text>);
+ function draw</xsl:text><xsl:value-of select="@name"/><xsl:text>() {
+ var data = new google.visualization.DataTable(</xsl:text>
+ <xsl:call-template name="outputJsonGoogleChartDataTable"/>
+ <xsl:text>,
+ 0.6
+ );
+ var options = {};
+ options['region'] = 'US';
+ options['colors'] = [0xE0FFD4, 0xA5EF63, 0x50AA00, 0x267114];
+ options['width'] = 800;
+ options['height'] = 500;
+ options['title'] = '</xsl:text><xsl:value-of select="translate(substring-after(@name, 'GeomapChart_'), '_', ' ')"/><xsl:text>';
+
+ var geomap = new google.visualization.GeoMap(document.getElementById('</xsl:text><xsl:value-of select="@name"/><xsl:text>'));
+ geomap.draw(data, options);
+ }
+ </xsl:text>
+ </xsl:template>
+</xsl:stylesheet>
@@ -0,0 +1,66 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+##############################################################################
+# Copyright (C) 2011 HPCC Systems.
+#
+# All rights reserved. This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU Affero General Public License as
+# published by the Free Software Foundation, either version 3 of the
+# License, or (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU Affero General Public License for more details.
+#
+# You should have received a copy of the GNU Affero General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
+##############################################################################
+-->
+<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:xs="http://www.w3.org/2001/XMLSchema">
+ <xsl:template name="outputJsonGoogleChartDataTable">
+ <xsl:variable name="dsname" select="@name"/>
+ <xsl:variable name="dataset" select="/*/Results/Result/XmlSchema[@name=$dsname]/xs:schema/xs:element[@name='Dataset']"/>
+ <xsl:variable name="record" select="$dataset/xs:complexType/xs:sequence/xs:element/xs:complexType/xs:sequence"/>
+ <xsl:text> {
+ cols: [</xsl:text>
+ <xsl:for-each select="$record/xs:element">
+ <xsl:if test="position()>1">,</xsl:if><xsl:text>
+ {id:'</xsl:text><xsl:value-of select="@name"/><xsl:text>', label: '</xsl:text><xsl:value-of select="@name"/><xsl:text>', type: '</xsl:text>
+ <xsl:choose>
+ <xsl:when test="contains(@name, 'jsdate_')"><xsl:text>date</xsl:text></xsl:when>
+ <xsl:when test="contains(@type, 'string')"><xsl:text>string</xsl:text></xsl:when>
+ <xsl:otherwise><xsl:text>number</xsl:text></xsl:otherwise>
+ </xsl:choose>
+ <xsl:text>'}</xsl:text>
+ </xsl:for-each>
+ <xsl:text>],
+ rows: [</xsl:text>
+ <xsl:for-each select="Row">
+ <xsl:if test="position()>1">,</xsl:if>
+ <xsl:text>
+ {c:[</xsl:text>
+ <xsl:for-each select="*">
+ <xsl:variable name="elname" select="local-name()"/>
+ <xsl:variable name="isString" select="contains($record/xs:element[@name=$elname]/@type, 'string')"/>
+ <xsl:variable name="isDate" select="contains($record/xs:element[@name=$elname]/@name, 'jsdate_')"/>
+ <xsl:if test="position()>1"><xsl:text>,</xsl:text></xsl:if>
+ <xsl:choose>
+ <xsl:when test="$isDate">
+ <xsl:text>{v: new Date(</xsl:text><xsl:value-of select="substring(., 1, 4)"/><xsl:text>,</xsl:text><xsl:value-of select="substring(., 5, 2)"/><xsl:text>,</xsl:text><xsl:value-of select="substring(., 7, 2)"/><xsl:text>)}</xsl:text>
+ </xsl:when>
+ <xsl:when test="$isString">
+ <xsl:text> {v: '</xsl:text><xsl:value-of select="."/>'<xsl:text>}</xsl:text>
+ </xsl:when>
+ <xsl:otherwise>
+ <xsl:text> {v: </xsl:text><xsl:value-of select="."/><xsl:text>}</xsl:text>
+ </xsl:otherwise>
+ </xsl:choose>
+ </xsl:for-each>
+ <xsl:text>]}</xsl:text>
+ </xsl:for-each>
+ <xsl:text>
+ ]
+ }</xsl:text>
+ </xsl:template>
+</xsl:stylesheet>
Oops, something went wrong.

0 comments on commit ee7366c

Please sign in to comment.