You are here

protected function ScatterField::getFieldValue in Charts 5.0.x

Same name and namespace in other branches
  1. 8.4 src/Plugin/views/field/ScatterField.php \Drupal\charts\Plugin\views\field\ScatterField::getFieldValue()
  2. 8.3 src/Plugin/views/field/ScatterField.php \Drupal\charts\Plugin\views\field\ScatterField::getFieldValue()

Get the value of a simple math field.

Parameters

\Drupal\views\ResultRow $values: Row results.

bool $xAxis: Whether we are fetching field one's value.

Return value

mixed The field value.

Throws

\Exception

1 call to ScatterField::getFieldValue()
ScatterField::getValue in src/Plugin/views/field/ScatterField.php

File

src/Plugin/views/field/ScatterField.php, line 99
Defines Drupal\charts\Plugin\views\field\ScatterField.

Class

ScatterField
Field handler to provide x and y values for a scatter plot.

Namespace

Drupal\charts\Plugin\views\field

Code

protected function getFieldValue(ResultRow $values, $xAxis) {
  if (!empty($xAxis)) {
    $field = $this->options['fieldset_one']['x_axis'];
  }
  else {
    $field = $this->options['fieldset_two']['y_axis'];
  }
  $data = NULL;

  // Fetch the data from the database alias.
  if (isset($this->view->field[$field])) {
    if ($field == 'scatter_field') {
      $data = $this->view->field['field_charts_fields_scatter']
        ->getValue($values);
    }
    else {
      $data = $this->view->field[$field]
        ->getValue($values);
    }
  }
  if (!isset($data)) {

    // There's no value. Default to 0.
    $data = 0;
  }

  // Ensure the input is numeric.
  if (!is_numeric($data)) {
    \Drupal::messenger()
      ->addError($this
      ->t('Check the formatting of your
        Scatter Field inputs: one or both of them are not numeric.'));
  }
  return $data;
}