Javafx ("Les_Misérables")

well i thought having i few followers on twitter ,could allow me to create a data viz of who follows who keeping in mind the twitter API rate limit ,which didn't work and i took some time building the viz with dummy data ,i had a try with  Les_Misérables network of characters from Victor Hugo novel. the data

all characters

I edited the data to remain with label "character name" , source node and target node,the number of the node corresponds with the characters name. i.e number 11 is Jean Valjean.

drawing the nodes

private void drawNodes(AnchorPane root,List lines){
    
         Point2D center_point = new Point2D(size * 0.5, size * 0.5);
 
          for(angle=0,counter=0;angle;=360;angle+=angle_stepsize,counter++){
            
            double sinValue = Math.sin(Math.toRadians(angle + startAngle));
            double cosValue = Math.cos(Math.toRadians(angle + startAngle));

            Point2D outer_point = new Point2D(center_point.getX() + size * 0.445 * sinValue, center_point.getY() + size * 0.445 *   cosValue);
            Point2D outer_major_point = new Point2D(center_point.getX() + size * 0.470 * sinValue, center_point.getY() + size *  0.470 * cosValue); 

            Circle node=new Circle(1);
            node.setFill(Color.WHITE);
            node.setId(String.valueOf(counter));
            node.setLayoutX(outer_point.getX());
            node.setLayoutY(outer_point.getY());

            Text text=new Text(String.valueOf(counter));
            text.setUserData(names.get(counter));
            text.setFill(Color.ALICEBLUE);
            text.setLayoutX(outer_major_point.getX());
            text.setLayoutY(outer_major_point.getY());
            text.setWrappingWidth(15);

            root.getChildren().addAll(node,text);

            textOnMouseOver(text,root,lines);
        }
    }

private void drawPath(AnchorPane root,List lines){

        for(int i=0;i<77;i++){ 
                    
               Circle source_node=(Circle)root.lookup("#"+i);

                List rry=filterLines((double)i,lines);

                  for(String s:rry){
                        
                    String word=s.split(",")[1];

                    int start=word.indexOf("\"");
                    int end=word.indexOf(".");

                    int target=Integer.valueOf(word.substring(start, end).replaceAll("\"", ""));

                    Circle target_node=(Circle) root.lookup("#"+target);
                    
                    CubicCurve line = new CubicCurve();  
                    line.setStroke(Color.BROWN);
                    line.setFill(Color.TRANSPARENT);
                    line.setOpacity(0.6);
                    line.setStrokeWidth(1);
                    line.setControlX1(source_node.getLayoutX());
                    line.setControlY1(source_node.getLayoutY());
                    line.setControlX2(size/2);
                    line.setControlY2(size/2);
                   
                    line.setStartX(source_node.getLayoutX());
                    line.setStartY(source_node.getLayoutY());
                    line.setEndX(target_node.getLayoutX());
                    line.setEndY(target_node.getLayoutY());
                    
                    root.getChildren().add(line); 
                    }
                    
  }
}
private List filterLines(double source_value,List lines){
    List rry=lines.stream()
                     .filter(s->;s.contains("source=\""+source_value+"\"") )
                     .collect(toList()); 
    return rry;
}
private void textOnMouseOver(Text text,AnchorPane root,List lines){

    text.setOnMouseEntered((MouseEvent MouseEvent) {
        root.getChildren().removeIf(node instanceof CubicCurve);
        List rry=filterLines(Double.valueOf(text.getText()),lines);
        drawPath(root,rry);
    });
    text.setOnMouseExited((MouseEvent event){
          root.getChildren().removeIf(node instanceof CubicCurve);
          root.getChildren().removeIf(node instanceof Label);
          drawPath(root,lines);
    });
}
NB:ignore the string tags cant get to remove them
edges color coded  by node count
Chenildieu
By reading the characters in Wikipedia Jean went to prison and evades capture ....long story short they must have a connection with Javert the policeman,so here it is
Javert(27)  Jean(11)


Comments

Popular Posts