MAXVAL|Label1:#,Label2:#,Label3:# * * EXAMPLE: 100|A:55,B:5,C:23,D:38 * * With Colored Bars: 100|A:55:#FFCCCC,B:5,C:23#00FF00,D:38 * * @license GPL-2.0 (https://www.gnu.org/licenses/old-licenses/gpl-2.0.en.html) * @author Sherri W. (http://syntaxseed.com) */ if (!defined('DOKU_INC')) { define('DOKU_INC', realpath(dirname(__FILE__).'/../../').'/'); } if (!defined('DOKU_PLUGIN')) { define('DOKU_PLUGIN', DOKU_INC.'lib/plugins/'); } require_once(DOKU_PLUGIN.'syntax.php'); /** * All DokuWiki plugins to extend the parser/rendering mechanism * need to inherit from this class */ class syntax_plugin_avbarchart extends DokuWiki_Syntax_Plugin { // ********* CHART CONFIG SETTINGS ************* public $barWidth = 25; // Pixel width of chart bars. public $barColor = "#ccccff"; // Default color of graph bars. public $fontSize = "8pt;"; // Font size of labels and values. public $maxPxHeight = "200"; // Maximum height of the chart in pixels. // ********************************************* /** * What kind of syntax are we? */ public function getType() { return 'substition'; } /** * Where to sort in? */ public function getSort() { return 999; } /** * Connect pattern to lexer */ public function connectTo($mode) { $this->Lexer->addEntryPattern('\', $mode, 'plugin_avbarchart'); } public function postConnect() { $this->Lexer->addExitPattern('\', 'plugin_avbarchart'); } /** * Handle the match */ public function handle($match, $state, $pos, Doku_Handler $handler) { switch ($state) { case DOKU_LEXER_ENTER: return array($state, ''); case DOKU_LEXER_MATCHED: break; case DOKU_LEXER_UNMATCHED: $chart = ""; list($maxRange, $data1) = preg_split("/\|/", $match); $maxRange = floatval($maxRange); if ($maxRange > 0 && !empty($data1)) { $values = preg_split("/,/", $data1); $chart = ""; foreach ($values as $col) { if (!empty($col)) { $inColumn = preg_split("/:/", $col); $label = $inColumn[0] ?? ''; $amount = $inColumn[1] ?? 0; $color = $inColumn[2] ?? null; $amount = floatval($amount); if (empty($label)) { $label=' '; } if (empty($color)) { $color = $this->barColor; } if ($amount >= 0) { $height = round(($amount/$maxRange*$this->maxPxHeight)); $chart .= "".$amount."

".$label.""; } } } } $match = $chart; return array($state, $match); case DOKU_LEXER_EXIT: return array($state, ''); case DOKU_LEXER_SPECIAL: break; } return array(); } /** * Create output */ public function render($mode, Doku_Renderer $renderer, $data) { if ($mode == 'xhtml') { list($state, $match) = $data; switch ($state) { case DOKU_LEXER_ENTER: $renderer->doc .= ""; break; case DOKU_LEXER_MATCHED: break; case DOKU_LEXER_UNMATCHED: $renderer->doc .= $match; break; case DOKU_LEXER_EXIT: $renderer->doc .= "
"; break; case DOKU_LEXER_SPECIAL: break; } return true; } return false; } } // End class