* @package MCMS\HTML\JScript * @link http://omnipotent.net/jquery.sparkline */ class Sparkline extends \Mammut\StrictObject implements \MCMS\Component\iComponent { const T_LINE = 'line'; const T_BAR = 'bar'; const T_TRISTATE = 'tristate'; const T_DISCRETE = 'discrete'; const T_BULLET = 'bullet'; const T_PIE = 'pie'; const T_BOXPLOT = 'box'; const TGT_ID = 'id'; const TGT_CLASS = 'class'; public $type = null; public $targetName = null; public $targetType = self::TGT_CLASS; public $values; public $width = null; public $height = null; public $lineColor = '000000'; public $lineWidth = 1; public $lineHeight = null; public $fillColor = null; public $normalColour = null; public $negativeColour = null; // Line Chart Settings public $spotColour = null; public $minSpotColour = null; public $maxSpotColour = null; public $hiSpotColour = null; public $hiLineColour = null; public $spotRadius = null; public $minYRange = null; public $maxYRange = null; public $minXRange = null; public $maxXRange = null; public $minNormalValue = null; public $maxNormalValue = null; public $drawNormalOnTop = false; // Bar/Tristate Chart Settings public $barWidth = 4; public $barSpacing = 1; public $zeroAxis = true; public $zeroBarColour = null; public $nullBarColour = null; public $stackedBarColor = null; // Discrete Chart Settings public $thresholdValue = null; public $thresholdColor = null; // Bullet Chart Settings public $targetWidth = null; public $targetColour = 'f03030'; public $performanceColour = '3030f0'; public $rangeColours = ['#d3dafe','#a8b6ff','#7f94ff']; // Pie Chart Settings public $sliceColours = ['#3366cc','#dc3912','#ff9900','#109618','#66aa00','#dd4477','#0099c6','#990099']; public $offset = null; public $borderWidth = null; public $borderColour = null; // Box Plot Chart Settings public $raw = false; public $targetValue = null; public $minimumValue = null; public $maximumValue = null; public $showOutliers = true; public $outlierIQR = null; public $spotMarkerRadius = null; public $boxLineColor = null; public $boxFillColor = null; public $whiskerColor = null; public $outlierLineColor = null; public $outlierFillColor = null; public $medianColor = null; public $targetColor = null; public function __construct() { } public function getJSFiles() { return [ JQUERY_JS_LIB, _JSURL_."/framework/jquery-addons/sparkline/jquery.sparkline.min.js" ]; } /** * Creates an array with 2 values, the HTML code and the matching jscript * @throws \InvalidArgumentException * @return array 'html' and 'jscript' */ public function generate() { $html = ''; $js = null; if ($this->targetType == self::TGT_ID) { $tag = 'id="'.$this->targetName.'"'; $tagJs = '#'.$this->targetName; } else { $tag = 'class="'.$this->targetName.'"'; $tagJs = '.'.$this->targetName; } if (empty($this->type)) { $html = ''.implode(',',$this->values).''; $js = '$(\''.$tagJs.'\').sparkline(\'html\');'; } else { switch ($this->type) { case self::T_LINE: $js = '$("#sparkline").sparkline(\'html\', { type: \'line\', drawNormalOnTop: '.($this->drawNormalOnTop ? 'true' : 'false').'});'; break; case self::T_BAR: $js = '$("#sparkline").sparkline(\'html\', { type: \'bar\'});'; break; case self::T_TRISTATE: $js = '$("#sparkline").sparkline(\'html\', { type: \'tristate\'});'; break; case self::T_DISCRETE: $js = '$("#sparkline").sparkline(\'html\', { type: \'discrete\'});'; break; case self::T_BULLET: $js = '$("#sparkline").sparkline(\'html\', { type: \'bullet\'});'; break; case self::T_PIE: $js = '$("#sparkline").sparkline(\'html\', { type: \'pie\'});'; break; case self::T_BOXPLOT: $js = '$("#sparkline").sparkline(\'html\', { type: \'box\'});'; break; default: throw new \InvalidArgumentException("Unknown type {$this->type}"); } } return [ 'html' => $html, 'jscript' => $js ]; } }