You are here

public function D3ViewsDataMapping::map in d3.js 7

Map views fields to library info specified field names.

Overrides D3DataMapping::map

See also

template_preprocess_d3_views_view_d3().

File

modules/d3_views/includes/D3ViewsDataMapping.inc, line 273

Class

D3ViewsDataMapping

Code

public function map($rows = array()) {
  $vis =& $this->plugin
    ->getVis();
  $map = $this
    ->getMapping();
  $fields = $this->library
    ->getFields();

  // If there are no mapping setings, just add the rows as is.
  if (empty($map)) {
    $vis['rows'] = $rows;
    return;
  }

  // Loop through data rows.
  foreach ($rows as $index => $row) {

    // If there are no mappings, map the default views behavior.
    // Loop through mapping rows.
    foreach ($map as $key => $value) {
      if (empty($vis[$key])) {
        $vis[$key] = NULL;
      }
      $type = FALSE;
      if ($this->library
        ->isDataKey($key)) {
        $type = '2DNAV';
      }
      if (!empty($fields[$key]['_info']['data_type'])) {
        $type = $fields[$key]['_info']['data_type'];
      }
      if ($type && method_exists($this, 'map' . $type)) {
        $this
          ->{'map' . $type}($value, $row, $vis[$key], $index);
      }
      else {
        $vis['rows'][$index] = $row;
      }
    }
  }
}