Skip to content

Commit

Permalink
Added jsapi() method for manual output of the google javascript api
Browse files Browse the repository at this point in the history
  • Loading branch information
kevinkhill committed Apr 1, 2015
1 parent 8bf3d37 commit a603328
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 21 deletions.
16 changes: 7 additions & 9 deletions src/Khill/Lavacharts/JavascriptFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,6 @@ private function buildChartJs()

$out .= '$this.chart.draw($this.data, $this.options);'.PHP_EOL;


$out .= "};".PHP_EOL.PHP_EOL;

$out .= sprintf(
Expand Down Expand Up @@ -292,15 +291,15 @@ private function buildEventCallbacks()

foreach ($this->chart->getEvents() as $event) {

$cb = sprintf(
$callback = sprintf(
'function (event) {return lava.event(event, $this.chart, %s);}',
$event->callback
);

$out .= sprintf(
'google.visualization.events.addListener($this.chart, "%s", %s);',
$event::TYPE,
$cb
$callback
).PHP_EOL.PHP_EOL;

}
Expand Down Expand Up @@ -329,8 +328,7 @@ private function buildFormatters()
).PHP_EOL;

$out .= sprintf(
'$this.formats["col%s"].format($this.data, %s);',
$index,
'$this.formats["col%1$s"].format($this.data, %1$s);',
$index
).PHP_EOL.PHP_EOL;
}
Expand All @@ -346,11 +344,11 @@ private function buildFormatters()
* @return bool
*/
public function coreJsRendered($stat = false) {
if ($stat === false) {
return $this->coreJsRendered;
} else {
return $this->coreJsRendered = $stat;
if ($stat !== false) {
$this->coreJsRendered = $stat;
}

return $this->coreJsRendered;
}

/**
Expand Down
4 changes: 2 additions & 2 deletions src/Khill/Lavacharts/Laravel/BladeTemplateExtensions.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,14 @@
'GaugeChart',
'GeoChart',
'LineChart',
'PieChart',
'PieChart'
);

foreach ($charts as $chart)
{
$blade->extend(function($view, $compiler) use ($chart) {
$pattern = $compiler->createMatcher(strtolower($chart));
$output = '<?php echo Lava::render'.$chart.'$2; ?>';
$output = '$1<?php echo Lava::render'.$chart.'$2; ?>';

return preg_replace($pattern, $output, $view);
});
Expand Down
33 changes: 23 additions & 10 deletions src/Khill/Lavacharts/Lavacharts.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@
* @license http://opensource.org/licenses/MIT MIT
*/

use Khill\Lavacharts\Utils;
use Khill\Lavacharts\Volcano;
use Khill\Lavacharts\JavascriptFactory;
use Khill\Lavacharts\Helpers;
use Khill\Lavacharts\Exceptions\ChartNotFound;
use Khill\Lavacharts\Exceptions\InvalidChartLabel;
use Khill\Lavacharts\Exceptions\InvalidLavaObject;
Expand Down Expand Up @@ -149,7 +149,6 @@ public function __call($member, $arguments)
} else {
return new Configs\DataTable;
}
return new Configs\DataTable;
}

if (in_array($member, $this->chartClasses)) {
Expand All @@ -160,7 +159,7 @@ public function __call($member, $arguments)
throw new InvalidChartLabel($arguments[0]);
}
} else {
throw new InvalidChartLabel();
throw new InvalidChartLabel;
}
}

Expand Down Expand Up @@ -208,25 +207,39 @@ public function __call($member, $arguments)
*/
public function render($chartType, $chartLabel, $elementId, $divDimensions = false)
{
$jsOutput = '';

$chart = $this->volcano->getChart($chartType, $chartLabel);

if ($this->jsFactory->coreJsRendered()) {
$jsOutput = '';
} else {
if ($this->jsFactory->coreJsRendered() === false) {
$jsOutput = $this->jsFactory->getCoreJs();
$this->jsFactory->coreJsRendered(true);
}

if ($divDimensions === false) {
$jsOutput .= $this->jsFactory->getChartJs($chart, $elementId);
} else {
if ($divDimensions !== false) {
$jsOutput .= $this->div($elementId, $divDimensions);
$jsOutput .= $this->jsFactory->getChartJs($chart, $elementId);
}

$jsOutput .= $this->jsFactory->getChartJs($chart, $elementId);

return $jsOutput;
}

/**
* Outputs the link to the Google JSAPI
*
* @access public
* @since v2.3
*
* @return string
*/
public function jsapi()
{
$this->jsFactory->coreJsRendered(true);

return $this->jsFactory->getCoreJs();
}

/**
* Sets global configuration options for the whole Lavachart library.
*
Expand Down

0 comments on commit a603328

Please sign in to comment.