Пример #1
0
 /**
  * Prepare chart data table by providing correct
  * column lables and colors
  *
  * @param Mzax_Chart_Table $table
  */
 public function prepareTable(Mzax_Chart_Table $table)
 {
     $variations = $table->getTableProperty('variations');
     $dimension = $table->getTableProperty('dimension');
     foreach ($table->getColumns() as $column) {
         if (isset($column->p->metric)) {
             switch ($column->p->metric) {
                 case 'sendings':
                     $column->label = $this->__('Recipients');
                     $column->p->color = self::COLOR_SENDINGS;
                     break;
                 case 'views':
                 case 'view_rate':
                     $column->label = $this->__('Views');
                     $column->p->color = self::COLOR_VIEWS;
                     break;
                 case 'clicks':
                 case 'click_rate':
                     $column->label = $this->__('Clicks');
                     $column->p->color = self::COLOR_CLICKS;
                     break;
                 case 'bounces':
                 case 'bounce_rate':
                     $column->label = $this->__('Bounces');
                     $column->p->color = self::COLOR_BOUNDS;
                     break;
                 case 'optouts':
                 case 'optout_rate':
                     $column->label = $this->__('Optouts');
                     $column->p->color = self::COLOR_OPTOUT;
                     break;
             }
         }
         if (isset($column->p->tracker_id)) {
             $tracker = $this->getCampaign()->getTracker($column->p->tracker_id);
             if ($tracker) {
                 $column->label = $tracker->getTitle();
             } else {
                 $column->label = $this->__('Tracker (%s)', $column->p->tracker_id);
             }
             $column->p->color = self::COLOR_CLICKS;
         }
         if (isset($column->p->color)) {
             $column->p->color_axis = array($this->brightness($column->p->color, 80), $this->brightness($column->p->color, -80));
         }
         if (isset($column->p->variation_id)) {
             $vid = $column->p->variation_id;
             $index = array_search($vid, $variations);
             $gradient = $this->gradient($this->brightness($column->p->color, -100), $this->brightness($column->p->color, 20), count($variations));
             $column->p->color = $gradient[$index];
             $variation = $this->getCampaign()->getVariation($vid);
             if ($variation) {
                 $column->label = $variation->getName();
             } else {
                 $column->label = $this->__('Variation (%s)', $vid);
             }
         }
     }
     if ($dimension !== 'date') {
         $colors = array('627379', 'FC7A00', 'BF4848', '87969E', 'D7D020', '00A6D4', 'A559BF', '14D277', '627379', 'FC7A00', 'BF4848', '87969E', 'D7D020', '00A6D4', 'A559BF', '14D277', '627379', 'FC7A00', 'BF4848', '87969E', 'D7D020', '00A6D4', 'A559BF', '14D277', '627379', 'FC7A00', 'BF4848', '87969E', 'D7D020', '00A6D4', 'A559BF', '14D277', '627379', 'FC7A00', 'BF4848', '87969E', 'D7D020', '00A6D4', 'A559BF', '14D277');
         //$table->addColumn('style', Mzax_Chart_Table::TYPE_STRING, 'style', array('role' => 'style'));
         foreach ($colors as $row => $color) {
             $table->setRowProperty($row, 'color', $color);
         }
         $table->setTableProperty('dye', true);
     }
     switch (strtolower($dimension)) {
         case 'hour':
             $table->setColumnType(0, Mzax_Chart_Table::TYPE_TIME);
             $table->setTableProperty('stacked', true);
             $table->setTableProperty('dye', false);
             break;
         case 'dayofweek':
             $table->setTableProperty('stacked', false);
             $table->setTableProperty('dye', false);
             break;
     }
 }
Пример #2
0
 /**
  * 
  * @return Mzax_Chart_Table
  */
 public function convertArrayToTable(array $data)
 {
     $table = new Mzax_Chart_Table();
     if (empty($data)) {
         return $table;
     }
     $table->setTableProperty($this->getParams());
     $table->setTableProperty('timeunit', $this->_timeUnit);
     // @todo only durring debug
     $table->setTableProperty('query', $this->getSelect()->assemble());
     $metrics = $this->getParam(self::METRICS);
     $columns = array_keys(reset($data));
     foreach ($columns as $index => $column) {
         if ($column === 'date') {
             $column = $table->addColumn('Date', Mzax_Chart_Table::TYPE_DATE, 'date', array('role' => 'domain', 'unit' => $this->_timeUnit));
             switch ($this->_timeUnit) {
                 case self::UNIT_MONTHS:
                     $column->p->pattern = 'F Y';
                     break;
                 case self::UNIT_WEEKS:
                     $column->p->pattern = 'W o';
                     break;
             }
             continue;
         } else {
             if (!$index) {
                 $table->addColumn($this->getParam(self::DIMENSION), Mzax_Chart_Table::TYPE_STRING, $column, array('role' => 'domain'));
                 continue;
             }
         }
         $p = array();
         $alias = $column;
         if (isset($metrics[$alias])) {
             $column = $metrics[$alias];
             $p['alias'] = $alias;
         }
         if (strpos($column, self::PIVOT_SEPARATOR)) {
             list($p['metric'], $p['variation_id']) = explode(self::PIVOT_SEPARATOR, $column);
         } else {
             $p['metric'] = $column;
         }
         if (strpos($column, '_rate')) {
             $p['_f'] = '%01.2f%%';
             $p['default'] = '@previous';
         }
         if (strpos($column, '_revenue_rate')) {
             $p['_f'] = '%01.5f';
             $p['default'] = '@previous';
         }
         if (strpos($column, '_sum')) {
             // $p['_f'] = '%01.2f';
             $p['default'] = '@previous';
         }
         $this->matchTracker($p['metric'], $p['tracker_id']);
         $table->addColumn($alias, Mzax_Chart_Table::TYPE_NUMBER, $column, $p);
     }
     foreach ($data as $row) {
         $table->addRow($row);
     }
     return $table;
 }