/** * configures instance upon construct * @param \Altamira\JsWriter\JsWriterAbstract $jsWriter */ protected function configure(\Altamira\JsWriter\JsWriterAbstract $jsWriter) { $confInstance = \Altamira\Config::getInstance(); $file = $confInstance['altamira.root'] . $confInstance['altamira.typeconfigpath']; $config = \parse_ini_file($file, true); $libConfig = $config[strtolower($jsWriter->getLibrary())]; $type = static::TYPE; $typeAttributes = preg_grep("/{$type}\\./i", array_keys($libConfig)); foreach ($typeAttributes as $key) { $attribute = preg_replace("/{$type}\\./i", '', $key); $this->{$attribute} = $libConfig[$key]; } }
/** * @covers \Altamira\FilesRenderer::__construct * @covers \Altamira\FilesRenderer::handleMinify * @covers \Altamira\FilesRenderer::offsetSet * @covers \Altamira\FilesRenderer::render */ public function testFilesRendererWithMin() { $files = array('foo.js', 'bar.min.js'); $expectedResult = <<<ENDSCRIPT <script type="text/javascript" src="foo.min.js"></script> <script type="text/javascript" src="bar.min.js"></script> <script type="text/javascript" src="baz.min.js"></script> ENDSCRIPT; $config = \Altamira\Config::getInstance(); $config['js.minify'] = true; $this->expectOutputString($expectedResult, '\\Altamira\\FilesRenderer should implement ArrayIterator, and calling next() on it should provide the next script.' . ' Providing a path should prepend that path to each file.'); $filesRenderer = new \Altamira\FilesRenderer($files); $filesRenderer[2] = 'baz.js'; do { $filesRenderer->render(); $filesRenderer->next(); } while ($filesRenderer->valid()); }
/** * Provides the appropriate path to where required CSS is stored for these charting libraries * @return Ambigous <string, \Altamira\Config> */ public function getCSSPath() { $config = \Altamira\Config::getInstance(); $cssPath = ''; foreach ($this->libraries as $library => $junk) { switch ($library) { case \Altamira\JsWriter\Flot::LIBRARY: break; case \Altamira\JsWriter\JqPlot::LIBRARY: default: $cssPath = $config['css.jqplotpath']; } } return $cssPath; }
/** * Returns an array of files required to render the chart * Includes the default files, as well as any files registered by type * It's important to note that some methods in concrete classes will add additional files to this instance * @return array */ public function getFiles() { $files = $this->files; foreach ($this->types as $type) { $files = array_merge($files, $type->getFiles()); } $path = \Altamira\Config::getInstance()->getPluginPath($this->getLibrary()); array_walk($files, function (&$val) use($path) { $val = $path . $val; }); return $files; }
<?php include __DIR__ . '/autoload.php'; ini_set('display_errors', 'on'); error_reporting(E_ALL); use Altamira\Chart; use Altamira\ChartIterator; use Altamira\Series; use Altamira\ChartRenderer; use Altamira\Config; use Altamira\ChartDatum\TwoDimensionalPointFactory; \Altamira\Config::setConfigFile('altamira-config.ini'); $library = isset($_GET['library']) ? $_GET['library'] : \Altamira\JsWriter\JqPlot::LIBRARY; if ($library == \Altamira\JsWriter\Flot::LIBRARY) { ChartRenderer::pushRenderer('Altamira\\ChartRenderer\\DefaultRenderer'); ChartRenderer::pushRenderer('Altamira\\ChartRenderer\\TitleRenderer'); } $chart = new Chart('chart1', $library); $series1Points = TwoDimensionalPointFactory::getFromYValues(array(2, 8, 5, 3, 8, 9, 7, 8, 4, 2, 1, 6)); $series2Points = TwoDimensionalPointFactory::getFromYValues(array(7, 3, 7, 8, 2, 3, 1, 2, 5, 7, 8, 3)); $chart->addSeries($chart->createSeries($series1Points, 'Sales'))->addSeries($chart->createSeries($series2Points, 'Returns'))->setTitle('Basic Line Chart')->setAxisOptions('y', 'formatString', '$%d')->setAxisOptions('x', 'tickInterval', 1)->setAxisOptions('x', 'min', 0)->setLegend(array('on' => true))->setAxisOptions('x', 'min', 0)->setAxisOptions('x', 'max', 14)->setAxisOptions('y', 'min', 0)->setAxisOptions('y', 'max', 10); $seriesPoints = TwoDimensionalPointFactory::getFromNested(array(array('1/4/1990', 850), array('2/27/1991', 427), array('1/6/1994', 990), array('8/6/1994', 127), array('12/25/1995', 325))); $chart2 = new Chart('chart2', $library); $series = $chart2->createSeries($seriesPoints, 'Measured Readings'); $series->useLabels(array('a', 'b', 'c', 'd', 'e'))->setLabelSetting('location', 'w')->setLabelSetting('xpadding', 8)->setLabelSetting('ypadding', 8); $chart2->setTitle('Line Chart With Highlights and Labels')->addSeries($series)->useDates()->useHighlighting(); $chart3 = new Chart('chart3', $library); $seriesA = $chart3->createSeries(TwoDimensionalPointFactory::getFromYValues(array(1, 2, 3, 4, 5, 6, 7, 8, 9, 10)), 'First'); $seriesB = $chart3->createSeries(TwoDimensionalPointFactory::getFromYValues(array(1, 10, 2, 9, 3, 8, 4, 7, 5, 6)), 'Second'); $seriesC = $chart3->createSeries(TwoDimensionalPointFactory::getFromYValues(array(10, 7, 6, 5, 3, 1, 3, 5, 6, 7)), 'Third'); // These styles are only supported by Flot
function __construct($library, $logger) { $this->logger = $logger; $this->setLibrary($library); \Altamira\Config::setConfigFile(__DIR__ . '/Resources/config/altamira-config.ini'); }
public function setUp() { parent::setUp(); \Altamira\Config::setConfigFile(__DIR__ . '/altamira-config.test.ini'); }
/** * Determines whether to point to minified or unmified js file * @param string $val * @return mixed */ protected function handleMinify($val) { return \Altamira\Config::minifyJs() ? preg_replace('/.(min.)?js/', '.min.js', $val) : preg_replace('/.(min.)?js/', '.js', $val); }