/**
  * Get the chart for this report.
  *
  * @since 1.0
  *
  * @param string $date_type
  * @param int    $product
  *
  * @return Base
  */
 public function get_chart($date_type = 'this_year', $product = 0)
 {
     if ($date_type != 'all_time') {
         $start = date('Y-m-d H:i:s', $this->convert_date($date_type));
         $end = date('Y-m-d H:i:s', $this->convert_date($date_type, true));
     }
     /**
      * @var \wpdb $wpdb
      */
     global $wpdb;
     $rtn = Manager::get('itelic-renewals')->get_table_name($wpdb);
     $ktn = Manager::get('itelic-keys')->get_table_name($wpdb);
     if ($product) {
         $product = absint($product);
         $product = " AND k.product = {$product}";
     } else {
         $product = '';
     }
     $expired_status = Key::EXPIRED;
     $all_where = " WHERE k.status = '{$expired_status}'";
     if ($date_type != 'all_time') {
         $renew_where = " WHERE r.renewal_date BETWEEN '{$start}' AND '{$end}'";
         $all_where .= " AND k.expires BETWEEN '{$start}' AND '{$end}'";
     } else {
         $renew_where = '';
     }
     if ($product) {
         $all_where .= $product;
     }
     $raw_renewed = "SELECT COUNT(1) as c FROM {$rtn} r JOIN {$ktn} k ON (k.lkey = r.lkey{$product}){$renew_where}";
     $renewed_results = $wpdb->get_results($raw_renewed);
     $renewed = (int) $renewed_results[0]->c;
     $raw_expired = "SELECT COUNT(1) as c FROM {$ktn} k{$all_where}";
     $expired_results = $wpdb->get_results($raw_expired);
     $expired = (int) $expired_results[0]->c;
     if ($expired == 0) {
         $renewed = 100;
         $expired = 0;
     } else {
         $renewed = number_format($renewed / ($expired + $renewed) * 100, 0);
         $expired = 100 - $renewed;
     }
     $colors = array(array('color' => '#E94F37', 'highlight' => '#FF6951'), array('color' => '#393E41', 'highlight' => '#53585B'), array('color' => '#3F88C5', 'highlight' => '#59A2DF'), array('color' => '#44BBA4', 'highlight' => '#5ED5BE'), array('color' => '#EDDDD4', 'highlight' => '#D4C4BB'));
     $chart = new Pie(600, 200, array('ibdShowLegend' => '#legend-' . $this->get_slug(), 'responsive' => true, 'tooltipTemplate' => '<%= value %>%'));
     $chart->add_data_set($renewed, __("Renewed", Plugin::SLUG), $colors[2]);
     if ($expired > 0) {
         $chart->add_data_set($expired, __("Expired", Plugin::SLUG), $colors[0]);
     }
     return $chart;
 }
 /**
  * Get the chart for this report.
  *
  * @since 1.0
  *
  * @param string $date_type
  * @param int    $product
  *
  * @return Chart
  */
 public function get_chart($date_type = 'this_year', $product = 0)
 {
     if (!$product) {
         return null;
     }
     /**
      * @var \wpdb $wpdb
      */
     global $wpdb;
     $atn = Manager::get('itelic-activations')->get_table_name($wpdb);
     $ktn = Manager::get('itelic-keys')->get_table_name($wpdb);
     $raw = "SELECT COUNT(1) as c, `release_id` as d FROM {$atn} a JOIN {$ktn} k ON (k.lkey = a.lkey AND k.product = %d)\n\t\t\t\tWHERE a.status = %s GROUP BY `release_id` LIMIT 5";
     $results = $wpdb->get_results($wpdb->prepare($raw, $product, Activation::ACTIVE));
     $translated = self::translate_results($results);
     if (isset($translated[''])) {
         $unknown = $translated[''];
         $translated[__('Unknown', Plugin::SLUG)] = $unknown;
         unset($translated['']);
     }
     $colors = array(array('color' => '#E94F37', 'highlight' => '#FF6951'), array('color' => '#393E41', 'highlight' => '#53585B'), array('color' => '#3F88C5', 'highlight' => '#59A2DF'), array('color' => '#44BBA4', 'highlight' => '#5ED5BE'), array('color' => '#EDDDD4', 'highlight' => '#D4C4BB'));
     $chart = new Pie(600, 200, array('ibdShowLegend' => '#legend-' . $this->get_slug(), 'responsive' => true, 'tooltipTemplate' => '<%= value %> install<%if (value != 1){%>s<%}%>'));
     $i = 0;
     foreach ($translated as $label => $value) {
         if ($label != __('Unknown', Plugin::SLUG)) {
             $release = itelic_get_release($label);
             $label = $release->get_version();
             $label = "v{$label}";
         }
         $chart->add_data_set($value, $label, $colors[$i]);
         $i++;
     }
     return $chart;
 }
 /**
  * Get the chart for displaying the previous version being upgrade from.
  *
  * @since 1.0
  *
  * @param Release $release
  *
  * @return Chart\Base
  */
 private function get_version_chart(Release $release)
 {
     if ($release->get_status() == Release::STATUS_DRAFT) {
         return null;
     }
     $results = $release->get_top_5_previous_versions();
     $chart = new Chart\Pie(698, 200, array('ibdLoadOn' => 'loadVersionsChart', 'ibdShowLegend' => '#pie-chart-legend', 'tooltipTemplate' => '<%= value %> install<%if (value != 1){%>s<%}%>', 'responsive' => true));
     $colors = array(array('color' => '#E94F37', 'highlight' => '#FF6951'), array('color' => '#393E41', 'highlight' => '#53585B'), array('color' => '#3F88C5', 'highlight' => '#59A2DF'), array('color' => '#44BBA4', 'highlight' => '#5ED5BE'), array('color' => '#EDDDD4', 'highlight' => '#D4C4BB'));
     $i = 0;
     foreach ($results as $version => $count) {
         $label = empty($version) ? __("Unknown", Plugin::SLUG) : "v{$version}";
         $chart->add_data_set($count, $label, $colors[$i]);
         $i++;
     }
     return $chart;
 }