
nothing to plot...
'); - series.push({}); // add empty dataset to show axes + series.push({}); // add empty dataset to show axes } else { $('#overlay').empty(); @@ -555,8 +603,7 @@ vz.wui.drawPlot = function () { // disable automatic refresh if we are in past if (vz.options.refresh && vz.options.plot.xaxis.max < new Date().getTime() - 1000) { - $('#refresh').attr('checked', vz.options.refresh = false); - vz.wui.clearTimeout(); + vz.wui.clearTimeout('(suspended)'); } else if (vz.options.refresh) { vz.wui.setTimeout(); diff --git a/htdocs/frontend/stylesheets/style.css b/htdocs/frontend/stylesheets/style.css index 320bfaf..7f22f17 100644 --- a/htdocs/frontend/stylesheets/style.css +++ b/htdocs/frontend/stylesheets/style.css @@ -100,7 +100,7 @@ tbody tr td { float: left; } -#permalink { +#links { float: right; } diff --git a/htdocs/middleware.php b/htdocs/middleware.php index 9d599d8..23107f6 100644 --- a/htdocs/middleware.php +++ b/htdocs/middleware.php @@ -42,8 +42,12 @@ require_once VZ_DIR . '/lib/Util/Configuration.php'; // load configuration Util\Configuration::load(VZ_DIR . '/etc/volkszaehler.conf'); +// define include dirs for vendor libs +define('DOCTRINE_DIR', Util\Configuration::read('lib.doctrine') ? Util\Configuration::read('lib.doctrine') : 'Doctrine'); +define('JPGRAPH_DIR', Util\Configuration::read('lib.jpgraph') ? Util\Configuration::read('lib.jpgraph') : 'JpGraph'); + $classLoaders = array( - new Util\ClassLoader('Doctrine', (is_null(Util\Configuration::read('lib.doctrine'))) ? 'Doctrine' : Util\Configuration::read('lib.doctrine')), + new Util\ClassLoader('Doctrine', DOCTRINE_DIR), new Util\ClassLoader('Volkszaehler', VZ_DIR . '/lib') ); diff --git a/lib/Controller/CapabilitiesController.php b/lib/Controller/CapabilitiesController.php index 80183a8..780c9de 100644 --- a/lib/Controller/CapabilitiesController.php +++ b/lib/Controller/CapabilitiesController.php @@ -64,6 +64,14 @@ class CapabilitiesController extends Controller { $capabilities['statistics'] = $statistics; } + if (is_null($section) || $section == 'formats') { + $capabilities['formats'] = array_keys(\Volkszaehler\Router::$viewMapping); + } + + if (is_null($section) || $section == 'contexts') { + $capabilities['contexts'] = array_keys(\Volkszaehler\Router::$controllerMapping); + } + if (is_null($section) || $section == 'definitions') { if (!is_null($section)) { // only caching when we doesn't request dynamic informations $this->view->setCaching('expires', time()+2*7*24*60*60); // cache for 2 weeks diff --git a/lib/Router.php b/lib/Router.php index 492cd67..0de5b63 100644 --- a/lib/Router.php +++ b/lib/Router.php @@ -61,7 +61,7 @@ class Router { /** * @var array HTTP-method => operation mapping */ - protected static $operationMapping = array( + public static $operationMapping = array( 'post' => 'add', 'delete' => 'delete', 'get' => 'get', @@ -71,7 +71,7 @@ class Router { /** * @var array context => controller mapping */ - protected static $controllerMapping = array( + public static $controllerMapping = array( 'channel' => 'Volkszaehler\Controller\ChannelController', 'group' => 'Volkszaehler\Controller\AggregatorController', 'group' => 'Volkszaehler\Controller\AggregatorController', @@ -83,11 +83,7 @@ class Router { /** * @var array format => view mapping */ - protected static $viewMapping = array( - 'png' => 'Volkszaehler\View\JpGraph', - 'jpeg' => 'Volkszaehler\View\JpGraph', - 'jpg' => 'Volkszaehler\View\JpGraph', - 'gif' => 'Volkszaehler\View\JpGraph', + public static $viewMapping = array( 'xml' => 'Volkszaehler\View\XML', 'csv' => 'Volkszaehler\View\CSV', 'json' => 'Volkszaehler\View\JSON', @@ -110,6 +106,13 @@ class Router { $this->debug = new Util\Debug($debugLevel, $this->em); } } + + // check for JpGraph + if (file_exists(JPGRAPH_DIR . '/jpgraph.php')) { + foreach (array('png', 'jpeg', 'jpg', 'gif') as $format) { + self::$viewMapping[$format] = 'Volkszaehler\View\JpGraph'; + } + } // initialize view $this->pathInfo = self::getPathInfo(); diff --git a/lib/View/JpGraph.php b/lib/View/JpGraph.php index cbde4f9..8fc43c4 100644 --- a/lib/View/JpGraph.php +++ b/lib/View/JpGraph.php @@ -27,9 +27,9 @@ use Volkszaehler\Interpreter; use Volkszaehler\Model; use Volkszaehler\Util; -require_once VZ_DIR . '/lib/vendor/JpGraph/jpgraph.php'; -require_once VZ_DIR . '/lib/vendor/JpGraph/jpgraph_scatter.php'; -require_once VZ_DIR . '/lib/vendor/JpGraph/jpgraph_date.php'; +require_once JPGRAPH_DIR . '/jpgraph.php'; +require_once JPGRAPH_DIR . '/jpgraph_line.php'; +require_once JPGRAPH_DIR . '/jpgraph_date.php'; /** * Plotting and graphing of data on the server side @@ -48,7 +48,7 @@ class JpGraph extends View { */ protected $axes = array(); - protected $channels = array(); + protected $count = 0; /** * @var default width @@ -64,10 +64,10 @@ class JpGraph extends View { * @var color palette for the scatter plots * This are the same colors as in the webfronted */ - protected static $colors = array('#83CAFF', '#7E0021', '#579D1C', '#FFD320', '#FF420E', '#004586', '#0084D1', '#C5000B', '#FF950E', '#4B1F6F', '#AECF00', '#314004'); + protected $colors; /** - * @var JPGrpah handle + * @var JPGraph handle */ protected $graph; @@ -92,6 +92,7 @@ class JpGraph extends View { $this->height = $this->request->getParameter('height'); } + $this->colors = Util\Configuration::read('colors'); $this->graph = new \Graph($this->width, $this->height); $this->graph->img->SetImgFormat($format); @@ -99,8 +100,9 @@ class JpGraph extends View { // Specify what scale we want to use, $this->graph->SetScale('datlin'); - $this->graph->legend->SetPos(0.1,0.02, 'left', 'top'); + $this->graph->legend->SetPos(0.03, 0.06); $this->graph->legend->SetShadow(FALSE); + $this->graph->legend->SetFrameWeight(1); $this->graph->SetMarginColor('white'); $this->graph->SetYDeltaDist(65); @@ -121,17 +123,17 @@ class JpGraph extends View { * @param mixed $data */ public function add($data) { - if ($data instanceof Interpreter\Interpreter || $data instanceof Interpreter\AggregatorInterpreter) { + if ($data instanceof Interpreter\Interpreter) { $this->addData($data); } elseif($data instanceof Interpreter\AggregatorInterpreter) { - foreach ($data->getEntity()->getChildren() as $child) { - $this->add($child); + foreach ($data->getChildrenInterpreter() as $childInterpreter) { + $this->add($childInterpreter); } } else { // suppress other classes - //throw new \Exception('Can\'t show ' . get_class($data)); + //throw new \JpGraphException('Can\'t show ' . get_class($data)); } } @@ -141,28 +143,31 @@ class JpGraph extends View { * @param $obj * @param $data */ - public function addData(Interpreter\InterpreterInterface $interpreter){ - $data = $interpreter->processData($this->width/4); + public function addData($interpreter) { + if (is_null($interpreter->getTupleCount())) { + $interpreter->setTupleCount($this->width); + } + + $data = $interpreter->processData(function($tuple) { + $tuple[0] /= 1000; + return $tuple; + }); if (count($data) > 0) { - $count = count($this->channels); $xData = $yData = array(); + // TODO adjust x-Axis foreach ($data as $reading) { - $xData[] = $reading[0] / 1000; + $xData[] = $reading[0]; $yData[] = $reading[1]; } // Create the scatter plot - $plot = new \ScatterPlot($yData, $xData); + $plot = new \LinePlot($yData, $xData); $plot->setLegend($interpreter->getEntity()->getProperty('title') . ': [' . $interpreter->getEntity()->getDefinition()->getUnit() . ']'); - $plot->SetLinkPoints(TRUE, self::$colors[$count]); - - $plot->mark->SetColor(self::$colors[$count]); - $plot->mark->SetFillColor(self::$colors[$count]); - $plot->mark->SetType(MARK_DIAMOND); - $plot->mark->SetWidth(1); + $plot->SetColor($this->colors[$this->count]); + $plot->SetStepStyle($interpreter instanceof Interpreter\MeterInterpreter); $axis = $this->getAxisIndex($interpreter->getEntity()); if ($axis >= 0) { @@ -172,20 +177,10 @@ class JpGraph extends View { $this->graph->Add($plot); } - $this->channels[] = $interpreter->getEntity(); + $this->count++; } } - /** - * Shows exception - * - * @todo avoid graph plotting and set content-type to text/plain - * @param \Exception $exception - */ - protected function addException(\Exception $exception) { - echo $exception; - } - /** * check weather a axis for the indicator of $channel exists *