Skip to content
Snippets Groups Projects
Commit 0a598f01 authored by andileco's avatar andileco
Browse files

Enable donut for C3 - based on issue 2881161.

parent aa767fa7
No related branches found
No related tags found
No related merge requests found
...@@ -5,13 +5,26 @@ ...@@ -5,13 +5,26 @@
* Charts module integration with C3 library. * Charts module integration with C3 library.
*/ */
use Drupal\charts\Theme\ChartsInterface;
/** /**
* Implements hook_charts_info(). * Implements hook_charts_info().
*/ */
function charts_c3_charts_info() { function charts_c3_charts_info() {
$info['c3'] = [ $info['c3'] = [
'label' => t('C3 Charts'), 'label' => t('C3 Charts'),
'types' => ['area', 'bar', 'column', 'line', 'pie', 'scatter'], 'types' => ['area', 'bar', 'column', 'line', 'pie', 'donut', 'scatter'],
]; ];
return $info; return $info;
} }
/**
* Implements hook_charts_type_info().
*/
function charts_c3_charts_type_info() {
$chart_types['donut'] = [
'label' => t('Donut'),
'axis' => ChartsInterface::CHARTS_SINGLE_AXIS,
];
return $chart_types;
}
...@@ -82,7 +82,7 @@ class C3ChartsRender implements ChartsRenderInterface { ...@@ -82,7 +82,7 @@ class C3ChartsRender implements ChartsRenderInterface {
array_push($c3Data, $categories); array_push($c3Data, $categories);
$chartData->setColumns($c3Data); $chartData->setColumns($c3Data);
} }
else if ($options['type'] == 'pie') { else if ($options['type'] == 'pie' || $options['type'] == 'donut') {
$chartData->setColumns($c3Data); $chartData->setColumns($c3Data);
} }
else { else {
...@@ -92,7 +92,7 @@ class C3ChartsRender implements ChartsRenderInterface { ...@@ -92,7 +92,7 @@ class C3ChartsRender implements ChartsRenderInterface {
} }
$chartData->types = $types; $chartData->types = $types;
if ($options['type'] != 'pie') { if ($options['type'] != 'pie' && $options['type'] != 'donut') {
$c3->setAxis($chartAxis); $c3->setAxis($chartAxis);
} }
......
...@@ -70,7 +70,7 @@ class ChartData implements \JsonSerializable { ...@@ -70,7 +70,7 @@ class ChartData implements \JsonSerializable {
public function jsonSerialize() { public function jsonSerialize() {
$vars = get_object_vars($this); $vars = get_object_vars($this);
if ($vars['type'] == 'pie') { if ($vars['type'] == 'pie' || $vars['type'] == 'donut') {
unset($vars['x']); unset($vars['x']);
} }
......
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