You are here

protected function flot_views_plugin_style::build_layer in Flot 6

1 call to flot_views_plugin_style::build_layer()
flot_views_plugin_style::get_layers in views/flot_views_plugin_style.inc
Build each layer and retrieve its result set.

File

views/flot_views_plugin_style.inc, line 123

Class

flot_views_plugin_style

Code

protected function build_layer($view, $result, $title = NULL) {

  // Get flot field, and bail if not present.
  if (isset($view->style_plugin) && method_exists($view->style_plugin, 'get_flot_field')) {
    $flot_field = $view->style_plugin
      ->get_flot_field();
  }
  else {
    return;
  }
  $layer = array(
    'range' => array(
      'min' => NULL,
      'max' => NULL,
    ),
    'ticks' => array(),
    'series' => array(),
    'title' => $title,
  );

  // Iterate over results to build data and ticks
  foreach ($result as $id => $row) {
    $datapoint = $view->field[$flot_field]
      ->flot_render($row);
    $value = $datapoint['value'];
    $label = isset($datapoint['label']) ? $datapoint['label'] : $datapoint['value'];
    $layer['series'][] = array(
      $value[0],
      $value[1],
    );
    $layer['ticks'][$value[0]] = array(
      $value[0],
      $label[0],
    );
    if (!isset($layer['range']['min']) || $value[1] < $layer['range']['min']) {
      $layer['range']['min'] = $value[1];
    }
    if (!isset($layer['range']['max']) || $value[1] > $layer['range']['max']) {
      $layer['range']['max'] = $value[1];
    }
  }
  $layer['series'] = new flotData($layer['series']);
  return $layer;
}