Commit fc7652d3 authored by Nia Kathoni's avatar Nia Kathoni Committed by Daniel Cothran
Browse files

Issue #3156731 by nikathone, andileco, GuillaumeDuveau: #raw_options does not...

Issue #3156731 by nikathone, andileco, GuillaumeDuveau: #raw_options does not allow to override chart options
parent 14be3148
Loading
Loading
Loading
Loading
+1 −1
Changes for modules/charts_billboard/src/Plugin/chart/Library/Billboard.php: 1 added line, 1 removed line.
Original line number Diff line number Diff line
@@ -226,8 +226,8 @@ class Billboard extends ChartBase implements ContainerFactoryPluginInterface {
    // Merge in chart raw options.
    if (!empty($element['#raw_options'])) {
      $chart_definition = NestedArray::mergeDeepArray([
        $element['#raw_options'],
        $chart_definition,
        $element['#raw_options'],
      ]);
    }

+1 −1
Changes for modules/charts_c3/src/Plugin/chart/Library/C3.php: 1 added line, 1 removed line.
Original line number Diff line number Diff line
@@ -226,8 +226,8 @@ class C3 extends ChartBase implements ContainerFactoryPluginInterface {
    // Merge in chart raw options.
    if (!empty($element['#raw_options'])) {
      $chart_definition = NestedArray::mergeDeepArray([
        $element['#raw_options'],
        $chart_definition,
        $element['#raw_options'],
      ]);
    }

+2 −7
Changes for modules/charts_chartjs/src/Plugin/chart/Library/Chartjs.php: 2 added lines, 7 removed lines.
Original line number Diff line number Diff line
@@ -135,12 +135,7 @@ class Chartjs extends ChartBase {
   *   Return the chart definition.
   */
  private function populateAxes(array $element, array $chart_definition) {
    if (!empty($element['#stacking']) && $element['#stacking'] == 1) {
      $stacking = TRUE;
    }
    else {
      $stacking = FALSE;
    }
    $stacking = !empty($element['#stacking']) && $element['#stacking'] == 1;
    $chart_type = $chart_definition['type'];
    $children = Element::children($element);
    /*
@@ -343,8 +338,8 @@ class Chartjs extends ChartBase {
        // Merge in axis raw options.
        if (!empty($element[$child]['#raw_options'])) {
          $categories = NestedArray::mergeDeepArray([
            $element[$child]['#raw_options'],
            $categories,
            $element[$child]['#raw_options'],
          ]);
        }
      }
+43 −0
Changes for modules/charts_chartjs/tests/src/Kernel/RawOptionsTest.php: 43 added lines, 0 removed lines.
Original line number Diff line number Diff line
<?php

namespace Drupal\Tests\charts_chartjs\Kernel;

use Drupal\Tests\charts\Kernel\ChartElementKernelTestBase;

/**
 * Tests the raw_options element property behavior.
 *
 * @group charts
 */
class RawOptionsTest extends ChartElementKernelTestBase {

  /**
   * {@inheritdoc}
   */
  protected static $modules = [
    'charts',
    'charts_chartjs'
  ];

  /**
   * Test that the raw options settings can override main definition.
   */
  public function testRawOptionsOverride() {
    $element = [
      '#type' => 'chart',
      '#chart_type' => 'bar',
      '#stacking' => 1,
      '#raw_options' => [
        'options' => [
          'scales' => [
            'x' => ['stacked' => FALSE],
          ],
        ],
      ],
    ];

    $path = ['options', 'scales', 'x', 'stacked'];
    $this->assertJsonPropertyHasValue($element, $path, FALSE);
  }

}
+5 −4
Changes for modules/charts_google/src/Plugin/chart/Library/Google.php: 5 added lines, 4 removed lines.
Original line number Diff line number Diff line
@@ -212,8 +212,8 @@ class Google extends ChartBase implements ContainerFactoryPluginInterface {
    // Merge in chart raw options.
    if (!empty($element['#raw_options'])) {
      $chart_definition = NestedArray::mergeDeepArray([
        $element['#raw_options'],
        $chart_definition,
        $element['#raw_options'],
      ]);
    }

@@ -268,8 +268,8 @@ class Google extends ChartBase implements ContainerFactoryPluginInterface {
        // Merge in axis raw options.
        if (!empty($element[$key]['#raw_options'])) {
          $axis = NestedArray::mergeDeepArray([
            $element[$key]['#raw_options'],
            $axis,
            $element[$key]['#raw_options'],
          ]);
        }

@@ -421,8 +421,8 @@ class Google extends ChartBase implements ContainerFactoryPluginInterface {
        // Merge in point raw options.
        if (!empty($data_item['#raw_options'])) {
          $series = NestedArray::mergeDeepArray([
            $data_item['#raw_options'],
            $series,
            $data_item['#raw_options'],
          ]);
        }

@@ -451,7 +451,8 @@ class Google extends ChartBase implements ContainerFactoryPluginInterface {
            // Merge in data point raw options.
            if (!empty($data_item['#raw_options'])) {
              $chart_definition['_data'][$sub_key + 1][$series_number + 1] = NestedArray::mergeDeepArray([
                $data_item['#raw_options'], $chart_definition['_data'][$sub_key + 1][$series_number + 1],
                $chart_definition['_data'][$sub_key + 1][$series_number + 1],
                $data_item['#raw_options'],
              ]);
            }

Loading