// for each language pair exists one array entry: // array[AB] = (count(A->B), count(B->A)) if (array_key_exists($slang . "|" . $tlang, $data)) { $data[$slang . "|" . $tlang]['num_ab'] += 1; $xtlang = $tlang; } elseif (array_key_exists($tlang . "|" . $slang, $data)) { $data[$tlang . "|" . $slang]['num_ba'] += 1; $xtlang = $slang; } else { $data[$slang . "|" . $tlang] = array(); $data[$slang . "|" . $tlang]['seg_a_id'] = $slang; $data[$slang . "|" . $tlang]['seg_b_id'] = $tlang; $data[$slang . "|" . $tlang]['num_ab'] = 1; $data[$slang . "|" . $tlang]['num_ba'] = 0; $colors[$slang] = hashColor($slang); $colors[$tlang] = hashColor($tlang); $xtlang = $tlang; } // counting the incomes of each language: if (array_key_exists($xtlang, $incomes)) { $incomes[$xtlang] += 1; } else { $incomes[$xtlang] = 1; } } // Beautify the distribution by appliying a logarithm : ) foreach ($data as &$langLink) { $langLink['num_ab'] = round(log($langLink['num_ab']) * 1000); $langLink['num_ba'] = round(log($langLink['num_ba']) * 1000); } // sorting the array by the sum of the incomes and outcomes:
continue; } if (!array_key_exists($sc, $cmap)) { $cmap[$sc] = getCoordinates($sc); echo $sc; } if (!array_key_exists($tc, $cmap)) { $cmap[$tc] = getCoordinates($tc); echo $tc; } if (!array_key_exists($sc . $tc, $lmap)) { $lmap[$sc . $tc] = 1; } else { ++$lmap[$sc . $tc]; } $links[] = array($cmap[$sc], $cmap[$tc], hashColor($slang), hashColor($tlang), $sc . $tc); } // Beautify the distribution by appliying a logarithm : ) /*foreach($lmap as &$elem) { $elem = round(log($elem)*1000)/1000; }*/ for ($i = 0; $i < count($links); ++$i) { $links[$i][4] = $lmap[$links[$i][4]]; } function sortByLmap($a, $b) { return $a[4] - $b[4]; } usort($links, "sortByLmap"); $links = array_reverse($links); echo json_encode($links);
while ($row = mysql_fetch_object($result)) { $sl = $row->slang; $tl = $row->tlang; //if($slang == $tlang || !(in_array($slang, $url_langs) && in_array($tlang, $url_langs))){ if ($sl == $tl || !link_match($ulangs, $sl, $tl)) { continue; } if (!array_key_exists($sl . "|" . $tl, $lmap)) { $lmap[$sl . "|" . $tl] = 1; } else { ++$lmap[$sl . "|" . $tl]; } } while ($l = current($lmap)) { $arr = explode("|", key($lmap)); $lmap[key($lmap)] = $arr[0] . "|" . $arr[1] . "|" . $l . "|" . hashColor($arr[1]); next($lmap); } function sortIt($a, $b) { $a = explode("|", $a); $b = explode("|", $b); return $a[2] - $b[2]; } usort($lmap, "sortIt"); $lmap = array_reverse($lmap); $lmap = link_top($ulangs, $lmap); $echo = "<table>"; for ($i = 0; $i < count($lmap); ++$i) { $data = explode("|", $lmap[$i]); $echo .= "<tr><td>" . $data[0] . "</td><td>" . $data[1] . "</td><td><span style='color:" . $data[3] . ";'>" . $data[2] . "</span></td></tr>";