Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create examples of google chart visualizations using HPCC #1

Merged
merged 1 commit into from
Nov 15, 2011
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 42 additions & 0 deletions visualizations/google-charts/files/barchart.xslt
Original file line number Diff line number Diff line change
@@ -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>
53 changes: 53 additions & 0 deletions visualizations/google-charts/files/charts_view.xslt
Original file line number Diff line number Diff line change
@@ -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>
53 changes: 53 additions & 0 deletions visualizations/google-charts/files/editor.xslt
Original file line number Diff line number Diff line change
@@ -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>
44 changes: 44 additions & 0 deletions visualizations/google-charts/files/editor_view.xslt
Original file line number Diff line number Diff line change
@@ -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>
43 changes: 43 additions & 0 deletions visualizations/google-charts/files/geochart.xslt
Original file line number Diff line number Diff line change
@@ -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>
48 changes: 48 additions & 0 deletions visualizations/google-charts/files/geomapchart.xslt
Original file line number Diff line number Diff line change
@@ -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>
66 changes: 66 additions & 0 deletions visualizations/google-charts/files/json_chart_data.xslt
Original file line number Diff line number Diff line change
@@ -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>
Loading