|
From: <var...@us...> - 2009-01-12 16:48:59
|
Revision: 6395
http://phpwiki.svn.sourceforge.net/phpwiki/?rev=6395&view=rev
Author: vargenau
Date: 2009-01-12 16:48:53 +0000 (Mon, 12 Jan 2009)
Log Message:
-----------
New plugin: Chart
Added Paths:
-----------
trunk/lib/plugin/Chart.php
trunk/pgsrc/Help%2FChartPlugin
Added: trunk/lib/plugin/Chart.php
===================================================================
--- trunk/lib/plugin/Chart.php (rev 0)
+++ trunk/lib/plugin/Chart.php 2009-01-12 16:48:53 UTC (rev 6395)
@@ -0,0 +1,172 @@
+<?php // -*-php-*-
+rcs_id('$Id$');
+/*
+ * Copyright 2007 $ThePhpWikiProgrammingTeam
+ * Copyright 2009 Marc-Etienne Vargenau, Alcatel-Lucent
+ *
+ * This file is part of PhpWiki.
+ *
+ * PhpWiki is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * PhpWiki 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 General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with PhpWiki; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+
+/*
+ * Standard Alcatel-Lucent disclaimer for contributing to open source
+ *
+ * "The ChartPlugin ("Contribution") has not been tested and/or
+ * validated for release as or in products, combinations with products or
+ * other commercial use. Any use of the Contribution is entirely made at
+ * the user's own responsibility and the user can not rely on any features,
+ * functionalities or performances Alcatel-Lucent has attributed to the
+ * Contribution.
+ *
+ * THE CONTRIBUTION BY ALCATEL-LUCENT IS PROVIDED AS IS, WITHOUT WARRANTY
+ * OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
+ * WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, COMPLIANCE,
+ * NON-INTERFERENCE AND/OR INTERWORKING WITH THE SOFTWARE TO WHICH THE
+ * CONTRIBUTION HAS BEEN MADE, TITLE AND NON-INFRINGEMENT. IN NO EVENT SHALL
+ * ALCATEL-LUCENT BE LIABLE FOR ANY DAMAGES OR OTHER LIABLITY, WHETHER IN
+ * CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+ * CONTRIBUTION OR THE USE OR OTHER DEALINGS IN THE CONTRIBUTION, WHETHER
+ * TOGETHER WITH THE SOFTWARE TO WHICH THE CONTRIBUTION RELATES OR ON A STAND
+ * ALONE BASIS."
+ */
+
+class WikiPlugin_Chart
+extends WikiPlugin
+{
+ function getName() {
+ return _("Chart");
+ }
+
+ function getDescription() {
+ return _("Render SVG charts");
+ }
+
+ function getVersion() {
+ return preg_replace("/[Revision: $]/", '',
+ "\$Revision: 6185 $");
+ }
+
+ function getDefaultArguments() {
+ return array('width' => 200,
+ 'height' => 200,
+ 'type' => 'line', // or 'area', 'bar', 'pie'
+ // 'xlabel' => 'x', // TODO
+ // 'ylabel' => 'y', // TODO
+ 'color' => 'green',
+ // 'legend' => false, // TODO
+ 'data' => false // mandatory
+ );
+ }
+ function handle_plugin_args_cruft(&$argstr, &$args) {
+ $this->source = $argstr;
+ }
+
+ function run($dbi, $argstr, &$request, $basepage) {
+
+ global $WikiTheme;
+ $args = $this->getArgs($argstr, $request);
+ extract($args);
+ $html = HTML();
+ $js = JavaScript('', array ('src' => $WikiTheme->_findData('ASCIIsvg.js')));
+ $html->pushContent($js);
+
+ $values = explode(",", $data);
+
+ // x_min = 0
+ // x_max = number of elements in data
+ // y_min = 0
+ // y_max = biggest element in data
+
+ $x_max = sizeof($values);
+ $y_max = max($values);
+ $sum = 0;
+ foreach ($values as $value) {
+ $sum += $value;
+ }
+
+ $source = 'initPicture(0,'.$x_max.',0,'.$y_max.'); axes(); stroke = "'.$color.'"; strokewidth = 5;';
+
+ if ($type == "bar") {
+ $abscisse = 1;
+ $source .= 'strokewidth = 10; ';
+ foreach ($values as $value) {
+ $source .= 'point1 = ['.$abscisse.', 0];'
+ . 'point2 = ['.$abscisse.','.$value.'];'
+ . 'line(point1, point2);';
+ $abscisse += 1;
+ }
+ } else if ($type == "line") {
+ $abscisse = 0;
+ $source .= 'strokewidth = 3; p = []; ';
+ foreach ($values as $value) {
+ $source .= 'for (t = 1; t < 1.01; t += 1) p[p.length] = ['
+ . $abscisse
+ . ', t*'
+ . trim($value)
+ . '];';
+ $abscisse += 1;
+ }
+ $source .= 'path(p);';
+ } else if ($type == "pie") {
+ $source = 'initPicture(-1.1,1.1,-1.1,1.1); stroke = "'.$color.'"; strokewidth = 1;'
+ . 'center = [0, 0]; circle(center, 1);'
+ . 'point = [1, 0]; line(center, point);';
+ $angle = 0;
+ foreach ($values as $value) {
+ $angle += $value/$sum;
+ $source .= 'point = [cos(2*pi*'.$angle.'), sin(2*pi*'.$angle.')]; line(center, point);';
+ }
+ }
+
+ $embedargs = array('width' => $args['width'],
+ 'height' => $args['height'],
+ 'script' => $source);
+ $embed = new SVG_HTML("embed", $embedargs);
+ $html->pushContent($embed);
+ return $html;
+ }
+};
+
+class SVG_HTML extends HtmlElement {
+ function startTag() {
+ $start = "<" . $this->_tag;
+ $this->_setClasses();
+ foreach ($this->_attr as $attr => $val) {
+ if (is_bool($val)) {
+ if (!$val)
+ continue;
+ $val = $attr;
+ }
+ $qval = str_replace("\"", '"', $this->_quote((string)$val));
+ if ($attr == 'script')
+ // note the ' not "
+ $start .= " $attr='$qval'";
+ else
+ $start .= " $attr=\"$qval\"";
+ }
+ $start .= ">";
+ return $start;
+ }
+}
+
+// Local Variables:
+// mode: php
+// tab-width: 8
+// c-basic-offset: 4
+// c-hanging-comment-ender-p: nil
+// indent-tabs-mode: nil
+// End:
+?>
Property changes on: trunk/lib/plugin/Chart.php
___________________________________________________________________
Added: svn:keywords
+ Id
Added: trunk/pgsrc/Help%FChartPlugin
===================================================================
--- trunk/pgsrc/Help%2FChartPlugin (rev 0)
+++ trunk/pgsrc/Help%2FChartPlugin 2009-01-12 16:48:53 UTC (rev 6395)
@@ -0,0 +1,32 @@
+Date: Mon, 12 Jan 2009 8:18:24 +0100
+Mime-Version: 1.0 (Produced by PhpWiki 1.3.14-20080124)
+X-Rcs-Id: $Id$
+Content-Type: application/x-phpwiki;
+ pagename=Help%2FSpreadsheet;
+ flags=PAGE_LOCKED;
+ markup=2;
+ charset=iso-8859-1
+Content-Transfer-Encoding: binary
+
+Chart plugin allows to easily draw simple graphs.
+
+== Line chart ==
+
+<<Chart type=line
+ data="5, 7, 11, 3, 15"
+>>
+
+== Bar chart ==
+
+<<Chart type=bar
+ color=red
+ data="5, 7, 11, 3, 15"
+>>
+
+== Pie chart ==
+
+<<Chart type=pie
+ color=blue
+ data="5, 7, 11, 3, 15"
+>>
+
Property changes on: trunk/pgsrc/Help%2FChartPlugin
___________________________________________________________________
Added: svn:keywords
+ Id
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|