You are here

private function ChartsPluginStyleChart::processNumberValueFromField in Charts 8.4

Same name and namespace in other branches
  1. 5.0.x src/Plugin/views/style/ChartsPluginStyleChart.php \Drupal\charts\Plugin\views\style\ChartsPluginStyleChart::processNumberValueFromField()

Processes number value based on field.

Parameters

int $number: The number.

string $field: The field.

Return value

\Drupal\Component\Render\MarkupInterface|float|null The value.

1 call to ChartsPluginStyleChart::processNumberValueFromField()
ChartsPluginStyleChart::render in src/Plugin/views/style/ChartsPluginStyleChart.php
Render the display in this style.

File

src/Plugin/views/style/ChartsPluginStyleChart.php, line 499

Class

ChartsPluginStyleChart
Style plugin to render view as a chart.

Namespace

Drupal\charts\Plugin\views\style

Code

private function processNumberValueFromField($number, $field) {
  $value = current($this
    ->getField($number, $field));
  if (\Drupal::service('twig')
    ->isDebug()) {
    $value = trim(strip_tags($value));
  }
  if (strpos($field, 'field_charts_fields_scatter') === 0) {
    return Json::decode($value);
  }

  // Convert empty strings to NULL.
  if ($value === '' || is_null($value)) {
    $value = NULL;
  }
  else {

    // Strip thousands placeholders if present, then cast to float.
    $value = (double) str_replace([
      ',',
      ' ',
    ], '', $value);
  }
  return $value;
}