Esempio n. 1
0
  private void coloration(List<node> nodes, List<edge> edges) {

    for (int i = 0; i < edges.size(); i++) {
      node source = nodes.get(edges.get(i).getSource());
      node target = nodes.get(edges.get(i).getTarget());
      if (source.getColorId() != target.getColorId()) {
        int oldColorId = target.getColorId();
        for (int j = 0; j < nodes.size(); j++) {
          if (nodes.get(j).getColorId() == oldColorId) {
            nodes.get(j).setColorId(source.getColorId());
          }
        }
      }
    }

    for (int i = 0; i < nodes.size(); i++) {
      node n = nodes.get(i);
      n.setColor(colorTab[n.getColorId() % 9]);
    }
  }
Esempio n. 2
0
  public HttpServletRequest graph(HttpServletRequest req, HttpServletResponse response)
      throws SQLException {
    User user = User.getInstance();
    if (user == null) {
      this.parent.redirect("login", true);
      return req;
    } else {
      List<Tag> listTags = user.getAllTag();
      Iterator<Tag> it = listTags.iterator();
      node instTag = null;
      Tag currentTag = null;
      List<node> nodes = new ArrayList<node>();
      List<edge> links = new ArrayList<edge>();
      int ind = 0;
      double maxUrl = 0;
      while (it.hasNext()) {
        currentTag = (Tag) it.next();
        if (currentTag.getUrls().size() != 0) {
          instTag =
              new node(
                  currentTag.getTid(),
                  currentTag.gettName(),
                  currentTag.getUrls().size(),
                  currentTag);
          if (maxUrl < currentTag.getUrls().size()) maxUrl = currentTag.getUrls().size();
          instTag.setIndex(ind);
          instTag.setColorId(ind);
          nodes.add(instTag);
          instTag = null;
          ind++;
        }
      }

      // ratio taille des noeuds
      for (int i = 0; i < nodes.size(); i++) {
        nodes.get(i).setSize(nodes.get(i).getSize() / maxUrl);
      }

      List<Url> listUrls = user.getAllUrl();
      // Iterator<Url> itUri=listUrls.iterator();
      Url currentUrl;
      for (int k = 0; k < listUrls.size(); k++) {
        currentUrl = (Url) listUrls.get(k);
        if (currentUrl.getTags().size() > 1) {
          edge instEdge = null;
          for (int i = 0; i < nodes.size(); i++) {
            for (int j = i + 1; j < nodes.size(); j++) {
              if (currentUrl.getTags().contains((Tag) nodes.get(i).getTag())
                  && currentUrl.getTags().contains((Tag) nodes.get(j).getTag())) {
                instEdge = new edge(nodes.get(i).getIndex(), nodes.get(j).getIndex());
                links.add(instEdge);
                instEdge = null;
              }
            }
          }
        }
      }
      coloration(nodes, links);
      req.setAttribute("json_links", links.toString());
      req.setAttribute("json_nodes", nodes.toString());

      return req;
    }
  }