function print_chart_by_decade($data, $title) { $count = 0; $vmax = 0; foreach ($data as $v) { $n = strlen($v); $vmax = max($vmax, $n); $count += $n; } if ($count < 1) { return; } $chart_url = "https://chart.googleapis.com/chart?cht=bvs"; // chart type $chart_url .= "&chs=360x150"; // size $chart_url .= "&chbh=3,3"; // bvg : 4,1,2 $chart_url .= "&chf=bg,s,FFFFFF99"; //background color $chart_url .= "&chco=0000FF,FFA0CB"; // bar color $chart_url .= "&chtt=" . rawurlencode($title); // title $chart_url .= "&chxt=x,y,r"; // axis labels specification $chart_url .= "&chxl=0:|<|||"; // <1570 for ($y = 1600; $y < 2030; $y += 50) { $chart_url .= $y . "|||||"; // x axis } $chart_url .= "|1:||" . rawurlencode(WT_I18N::percentage($vmax / $count)); // y axis $chart_url .= "|2:||"; $step = $vmax; for ($d = $vmax; $d > 0; $d--) { if ($vmax < $d * 10 + 1 && $vmax % $d == 0) { $step = $d; } } if ($step == $vmax) { for ($d = $vmax - 1; $d > 0; $d--) { if ($vmax - 1 < $d * 10 + 1 && ($vmax - 1) % $d == 0) { $step = $d; } } } for ($n = $step; $n < $vmax; $n += $step) { $chart_url .= $n . "|"; } $chart_url .= rawurlencode($vmax . " / " . $count); // r axis $chart_url .= "&chg=100," . round(100 * $step / $vmax, 1) . ",1,5"; // grid $chart_url .= "&chd=s:"; // data : simple encoding from A=0 to 9=61 $CHART_ENCODING61 = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"; for ($y = 1570; $y < 2030; $y += 10) { $chart_url .= $CHART_ENCODING61[(int) (substr_count($data[$y], "M") * 61 / $vmax)]; } $chart_url .= ","; for ($y = 1570; $y < 2030; $y += 10) { $chart_url .= $CHART_ENCODING61[(int) (substr_count($data[$y], "F") * 61 / $vmax)]; } $html = '<img src="' . $chart_url . '" alt="' . $title . '" title="' . $title . '" class="gchart">'; return $html; }
function chartFamsWithSources($params = null) { global $WT_STATS_CHART_COLOR1, $WT_STATS_CHART_COLOR2, $WT_STATS_S_CHART_X, $WT_STATS_S_CHART_Y; if ($params === null) { $params = array(); } if (isset($params[0]) && $params[0] != '') { $size = strtolower($params[0]); } else { $size = $WT_STATS_S_CHART_X . "x" . $WT_STATS_S_CHART_Y; } if (isset($params[1]) && $params[1] != '') { $color_from = strtolower($params[1]); } else { $color_from = $WT_STATS_CHART_COLOR1; } if (isset($params[2]) && $params[2] != '') { $color_to = strtolower($params[2]); } else { $color_to = $WT_STATS_CHART_COLOR2; } $sizes = explode('x', $size); $tot_fam = $this->_totalFamilies(); if ($tot_fam == 0) { return ''; } else { $tot_sfam_per = round($this->_totalFamsWithSources() / $tot_fam, 3); $chd = self::_array_to_extended_encoding(array(100 - 100 * $tot_sfam_per, 100 * $tot_sfam_per)); $chl = WT_I18N::translate('Without sources') . ' - ' . WT_I18N::percentage(1 - $tot_sfam_per, 1) . '|' . WT_I18N::translate('With sources') . ' - ' . WT_I18N::percentage($tot_sfam_per, 1); $chart_title = WT_I18N::translate('Families with sources'); return "<img src=\"https://chart.googleapis.com/chart?cht=p3&chd=e:{$chd}&chs={$size}&chco={$color_from},{$color_to}&chf=bg,s,ffffff00&chl={$chl}\" width=\"{$sizes[0]}\" height=\"{$sizes[1]}\" alt=\"" . $chart_title . "\" title=\"" . $chart_title . "\" />"; } }