Skip to content
Snippets Groups Projects
Commit 758970bb authored by Kevin Hill's avatar Kevin Hill
Browse files

merging the related toJavascript methods into the Renderable class

parent 819afd4e
No related branches found
No related tags found
No related merge requests found
Loading
Loading
@@ -143,40 +143,6 @@ class Chart extends Renderable implements Visualization, Wrappable
return $formats;
}
 
/**
* Convert the Chart to Javascript.
*
* @return string
*/
public function toJavascript()
{
return sprintf(
$this->getJavascriptFormat(),
$this->getJavascriptSource()
);
}
/**
* Return the JSON payload that will be passed to lava.createChart.
*
* @return string
*/
public function getJavascriptSource()
{
return $this->toJson();
}
/**
* Return a format string that will be used to convert the class to javascript.
*
* @lang javascript
* @return string
*/
public function getJavascriptFormat()
{
return 'window.lava.addNewChart(%s);';
}
/**
* Array representation of the Chart.
*
Loading
Loading
Loading
Loading
@@ -188,35 +188,6 @@ class Dashboard extends Renderable implements Visualization
return $charts;
}
 
/**
* Convert the Chart to Javascript.
*
* @return string
*/
public function toJavascript()
{
return sprintf(
$this->getJavascriptFormat(),
$this->getJavascriptSource()
);
}
/**
* @inheritdoc
*/
public function getJavascriptSource()
{
return $this->toJson();
}
/**
* @inheritdoc
*/
public function getJavascriptFormat()
{
return 'window.lava.addNewDashboard(%s);';
}
/**
* Array representation of the Dashboard.
*
Loading
Loading
Loading
Loading
@@ -63,30 +63,19 @@ class JoinedDataTable implements DataInterface, Javascriptable
*
* @return string
*/
public function getJavascriptFormat()
public function toJavascript()
{
return 'google.visualization.data.join(%s, %s, "%s", %s, %s, %s)';
}
/**
* Return an array of arguments to pass to the format string provided
* by getJavascriptFormat().
*
* These variables will be used with vsprintf, and the format string
* to convert the extending class to javascript.
*
* @return array
*/
public function getJavascriptSource()
{
return array_merge(
$this->tables,
[
$this->options->joinMethod,
json_encode($this->options->keys),
json_encode($this->options->dt1Columns),
json_encode($this->options->dt2Columns),
]
return vsprintf(
'google.visualization.data.join(%s, %s, "%s", %s, %s, %s)',
array_merge(
$this->tables,
[
$this->options->joinMethod,
json_encode($this->options->keys),
json_encode($this->options->dt1Columns),
json_encode($this->options->dt2Columns),
]
)
);
}
}
Loading
Loading
@@ -24,23 +24,4 @@ interface Javascriptable
* @return string
*/
public function toJavascript();
/**
* Return a format string that will be used by vsprintf to convert the
* extending class to javascript.
*
* @return string
*/
public function getJavascriptFormat();
/**
* Return an array of arguments to pass to the format string provided
* by getJavascriptFormat().
*
* These variables will be used with vsprintf, and the format string
* to convert the extending class to javascript.
*
* @return array
*/
public function getJavascriptSource();
}
Loading
Loading
@@ -65,6 +65,19 @@ abstract class Renderable implements Arrayable, Customizable, Javascriptable, Js
}
}
 
/**
* Convert the Chart to Javascript.
*
* @return string
*/
public function toJavascript()
{
return sprintf(
'window.lava.createAndStore(%s);',
$this->toJson()
);
}
/**
* Returns the class type.
*
Loading
Loading
Loading
Loading
@@ -20,17 +20,6 @@ namespace Khill\Lavacharts\Support\Traits;
*/
trait ToJavascriptTrait
{
/**
* Using the format provided and the source variables, transform the instance
* to javascript source.
*
* @return string
*/
public function toJavascript()
{
return vsprintf($this->getJavascriptFormat(), $this->getJavascriptSource());
}
/**
* When accessing as a string, the instance will converted to javascript source.
*
Loading
Loading
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment