Skip to content

Commit

Permalink
Adds the material charts
Browse files Browse the repository at this point in the history
  • Loading branch information
cmen committed Dec 24, 2016
1 parent f6145a0 commit ab3b356
Show file tree
Hide file tree
Showing 13 changed files with 604 additions and 9 deletions.
33 changes: 27 additions & 6 deletions GoogleCharts/Chart.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@ abstract class Chart
protected $events;


/**
* Chart constructor.
*/
public function __construct()
{
$this->data = new Data();
Expand All @@ -56,7 +59,7 @@ public function getName()
*/
public function getDataName()
{
return 'data'. ucfirst($this->getName());
return 'data' . ucfirst($this->getName());
}

/**
Expand All @@ -66,7 +69,7 @@ public function getDataName()
*/
public function getOptionsName()
{
return 'options'. ucfirst($this->getName());
return 'options' . ucfirst($this->getName());
}

/**
Expand All @@ -76,6 +79,16 @@ public function getOptionsName()
*/
abstract protected function getType();

/**
* Returns library used by chart.
*
* @return string
*/
protected function getLibrary()
{
return 'visualization';
}

/**
* Returns the chart package.
*
Expand Down Expand Up @@ -110,7 +123,7 @@ public function startDraw()
throw new GoogleChartsException('Container is not defined.');
}

$js = 'var ' . $this->getName() . ' = new google.visualization.' . $this->getType() .
$js = 'var ' . $this->getName() . ' = new google.' . $this->getLibrary() . '.' . $this->getType() .
'(document.getElementById("' . $this->elementID . '"));';

if (!$this instanceof DiffChart) {
Expand All @@ -119,7 +132,7 @@ public function startDraw()
$js .= $this->getOldChart()->getData()->draw('old_' . $this->getDataName()) .
$this->getNewChart()->getData()->draw('new_' . $this->getDataName()) .
'var ' . $this->getDataName() . ' = ' . $this->getName() .
'.computeDiff(old_' . $this->getDataName() . ',
'.computeDiff(old_' . $this->getDataName() . ',
new_' . $this->getDataName() . ');';
}

Expand All @@ -135,8 +148,16 @@ public function startDraw()
*/
public function endDraw()
{
return $this->events->draw(). $this->getName() .
'.draw('. $this->getDataName() . ', '. $this->getOptionsName() .');';
if ($this->getLibrary() == 'visualization') {
$options = $this->getOptionsName();
} else {
/* Options conversion for material charts */
$options = 'google.' . $this->getLibrary() . '.' . $this->getType() .
'.convertOptions(' . $this->getOptionsName() . ')';
}

return $this->events->draw() . $this->getName() .
'.draw(' . $this->getDataName() . ', ' . $options . ');';
}

/**
Expand Down
56 changes: 56 additions & 0 deletions GoogleCharts/Charts/Material/BarChart.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
<?php

namespace CMEN\GoogleChartsBundle\GoogleCharts\Charts\Material;

use CMEN\GoogleChartsBundle\GoogleCharts\Options\BarChart\Material\BarChartOptions;

/**
* Class BarChart
*
* @author Christophe Meneses
*/
class BarChart extends \CMEN\GoogleChartsBundle\GoogleCharts\Charts\BarChart
{
/**
* BarChart constructor.
*/
public function __construct()
{
parent::__construct();

$this->options = new BarChartOptions();
$this->options->setBars('horizontal');
}

/**
* @inheritdoc
*/
public function getPackage()
{
return 'bar';
}

/**
* @inheritdoc
*/
protected function getLibrary()
{
return 'charts';
}

/**
* @inheritdoc
*/
protected function getType()
{
return 'Bar';
}

/**
* @return BarChartOptions
*/
public function getOptions()
{
return $this->options;
}
}
55 changes: 55 additions & 0 deletions GoogleCharts/Charts/Material/ColumnChart.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
<?php

namespace CMEN\GoogleChartsBundle\GoogleCharts\Charts\Material;

use CMEN\GoogleChartsBundle\GoogleCharts\Options\ColumnChart\Material\ColumnChartOptions;

/**
* Class ColumnChart
*
* @author Christophe Meneses
*/
class ColumnChart extends \CMEN\GoogleChartsBundle\GoogleCharts\Charts\ColumnChart
{
/**
* ColumnChart constructor.
*/
public function __construct()
{
parent::__construct();

$this->options = new ColumnChartOptions();
}

/**
* @inheritdoc
*/
public function getPackage()
{
return 'bar';
}

/**
* @inheritdoc
*/
protected function getLibrary()
{
return 'charts';
}

/**
* @inheritdoc
*/
protected function getType()
{
return 'Bar';
}

/**
* @return ColumnChartOptions
*/
public function getOptions()
{
return $this->options;
}
}
55 changes: 55 additions & 0 deletions GoogleCharts/Charts/Material/LineChart.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
<?php

namespace CMEN\GoogleChartsBundle\GoogleCharts\Charts\Material;

use CMEN\GoogleChartsBundle\GoogleCharts\Options\LineChart\Material\LineChartOptions;

/**
* Class LineChart
*
* @author Christophe Meneses
*/
class LineChart extends \CMEN\GoogleChartsBundle\GoogleCharts\Charts\LineChart
{
/**
* LineChart constructor.
*/
public function __construct()
{
parent::__construct();

$this->options = new LineChartOptions();
}

/**
* @inheritdoc
*/
public function getPackage()
{
return 'line';
}

/**
* @inheritdoc
*/
protected function getLibrary()
{
return 'charts';
}

/**
* @inheritdoc
*/
protected function getType()
{
return 'Line';
}

/**
* @return LineChartOptions
*/
public function getOptions()
{
return $this->options;
}
}
55 changes: 55 additions & 0 deletions GoogleCharts/Charts/Material/ScatterChart.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
<?php

namespace CMEN\GoogleChartsBundle\GoogleCharts\Charts\Material;

use CMEN\GoogleChartsBundle\GoogleCharts\Options\ScatterChart\Material\ScatterChartOptions;

/**
* Class ScatterChart
*
* @author Christophe Meneses
*/
class ScatterChart extends \CMEN\GoogleChartsBundle\GoogleCharts\Charts\ScatterChart
{
/**
* ScatterChart constructor.
*/
public function __construct()
{
parent::__construct();

$this->options = new ScatterChartOptions();
}

/**
* @inheritdoc
*/
public function getPackage()
{
return 'scatter';
}

/**
* @inheritdoc
*/
protected function getLibrary()
{
return 'charts';
}

/**
* @inheritdoc
*/
protected function getType()
{
return 'Scatter';
}

/**
* @return ScatterChartOptions
*/
public function getOptions()
{
return $this->options;
}
}
4 changes: 2 additions & 2 deletions GoogleCharts/Options/AdvancedChartOptions.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class AdvancedChartOptions extends MediumChartOptions
* $chart->getOptions()->setSeries([$series1, null, $series3]);
* $chart->getOptions()->setSeries([0 => $series1, 2 => $series3])
*
* @var Series[]
* @var array|Series[]
*/
protected $series;

Expand Down Expand Up @@ -95,7 +95,7 @@ public function setAxisTitlesPosition($axisTitlesPosition)
}

/**
* @param Series[] $series
* @param array|Series[] $series
*
* @return $this
*/
Expand Down
45 changes: 45 additions & 0 deletions GoogleCharts/Options/BarChart/Material/BarChartOptions.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
<?php

namespace CMEN\GoogleChartsBundle\GoogleCharts\Options\BarChart\Material;

use CMEN\GoogleChartsBundle\GoogleCharts\Options\Material\Chart;
use CMEN\GoogleChartsBundle\GoogleCharts\Options\Material\MaterialTrait;

/**
* Class BarChartOptions
*
* @author Christophe Meneses
*/
class BarChartOptions extends \CMEN\GoogleChartsBundle\GoogleCharts\Options\BarChart\BarChartOptions
{
use MaterialTrait;

/**
* Whether the bars in a Material Bar Chart are vertical or horizontal.
*
* @var string
*/
protected $bars;

/**
* BarChartOptions constructor.
*/
public function __construct()
{
parent::__construct();

$this->chart = new Chart();
}

/**
* @param string $bars
*
* @return BarChartOptions
*/
public function setBars($bars)
{
$this->bars = $bars;

return $this;
}
}
Loading

0 comments on commit ab3b356

Please sign in to comment.