#include #include #include #include #include #include #include #include "output.h" #include "relations.h" #include "linecount.h" std::string get_color(int strength, struct graphparam pars) { std::ostringstream result; const int mapmax = 0, mapmin = 200; int color = ((strength - pars.min) * (mapmax - mapmin)) / (pars.max - pars.min) + mapmin; result << "#" << std::hex; result << std::setfill('0') << std::setw(2) << color; result << std::setfill('0') << std::setw(2) << color; result << "ff"; return result.str(); } void get_params(struct graphparam &pars, const std::map &relations) { std::map::const_iterator iter; int sum = 0; int count = 0; pars.max = 0; for (iter = relations.begin(); iter != relations.end(); iter++) { pars.max = std::max(iter->second, pars.max); sum += iter->second; count++; } if (count == 0) pars.treshold = 0; else pars.treshold = (int) (sum * pars.tresholdfactor) / count; pars.min = pars.treshold; // we skip those below treshold.. } void writerel(std::ostream &dest, struct relation rel, int strength, const std::set &usenicks, const struct graphparam &pars) { dest << "\"" << realnick(rel.referrer, usenicks) << "\""; if (pars.words.size() == 0) { // Referred is a person dest << " -> \"" << realnick(rel.referred, usenicks) << "\""; } else { // Referred is a word dest << " -> \"" << rel.referred << "\""; } // dest << " [label=" << strength; dest << "[color=\"" << get_color(strength, pars) << "\""; dest << ", len=" << (pars.length * pars.min) / (double) strength; dest << ", weight=" << strength << "];" << std::endl; } void writegraph(std::ostream &dest, const std::map &relations, const std::set &usenicks, struct graphparam pars) { get_params(pars, relations); dest << "digraph \"" << pars.title << "\" {" << std::endl; std::map::const_iterator iter; for (iter = relations.begin(); iter != relations.end(); iter++) { if (iter->second > pars.treshold) { writerel(dest, iter->first, iter->second, usenicks, pars); } } dest << "label=\"" << pars.title << "\";" << std::endl; dest << "}" << std::endl; } std::string realnick(std::string nick, const std::set &usenicks) { struct person p; p.nick = nick; // Find the nick std::set::const_iterator nickiter; nickiter = usenicks.find(p); if (nickiter == usenicks.end()) return p.nick; // Not found, return the same. p = *nickiter; switch (p.status) { case voice: return "+" + p.nick; case op: return "@" + p.nick; default: return p.nick; } }