package com.github.ferstl.depgraph.graph;

import java.util.Set;
import org.apache.maven.artifact.Artifact;
import com.github.ferstl.depgraph.dot.NodeRenderer;
import com.google.common.base.Joiner;
import static java.util.Arrays.asList;


public class DependencyNodeLabelRenderer implements NodeRenderer<GraphNode> {

  private static final Joiner SLASH_JOINER = Joiner.on("/").skipNulls();
  private static final Joiner NEWLINE_JOINER = Joiner.on("\n").skipNulls();

  private final boolean showGroupId;
  private final boolean showArtifactId;
  private final boolean showVersion;

  public DependencyNodeLabelRenderer(boolean showGroupId, boolean showArtifactId, boolean showVersion) {
    this.showGroupId = showGroupId;
    this.showArtifactId = showArtifactId;
    this.showVersion = showVersion;
  }

  @Override
  public String render(GraphNode node) {
    Artifact artifact = node.getArtifact();
    String label = NEWLINE_JOINER.join(asList(
        this.showGroupId ? artifact.getGroupId() : null,
        this.showArtifactId ? artifact.getArtifactId() : null,
        this.showVersion ? artifact.getVersion() : null));

    return toScopedString(label, node.getScopes());
  }

  private static String toScopedString(String string, Set<String> scopes) {
    if (scopes.size() > 1 || !scopes.contains("compile")) {
      return string + "\n(" + SLASH_JOINER.join(scopes) + ")";
    }

    return string;
  }

}

@@ -101,16 +101,68 @@
 tifact;%0A
+import com.github.ferstl.depgraph.dot.LabelBuilder;%0A
 import c
@@ -247,47 +247,8 @@
 er;%0A
-import static java.util.Arrays.asList;%0A
 %0A%0Apu
@@ -400,84 +400,8 @@
 s();
-%0A  private static final Joiner NEWLINE_JOINER = Joiner.on(%22%5Cn%22).skipNulls();
 %0A%0A  
@@ -849,52 +849,136 @@
 ing 
-label = NEWLINE_JOINER.join(asList(%0A        
+scopes = createScopeString(node.getScopes());%0A%0A    LabelBuilder labelBuilder = new LabelBuilder()%0A        .font().size(11).text(
 this
@@ -1012,33 +1012,33 @@
 GroupId() : null
-,
+)
 %0A        this.sh
@@ -1022,32 +1022,53 @@
 : null)%0A        
+.smartNewLine().text(
 this.showArtifac
@@ -1104,17 +1104,17 @@
 ) : null
-,
+)
 %0A       
@@ -1110,24 +1110,61 @@
 ll)%0A        
+.smartNewLine().font().size(11).text(
 this.showVer
@@ -1203,61 +1203,141 @@
 ull)
-)
 ;%0A%0A    
-return toScopedString(label, node.getScopes()
+if (!scopes.isEmpty()) %7B%0A      labelBuilder.smartNewLine().font().size(11).text(scopes);%0A    %7D%0A%0A    return labelBuilder.build(
 );%0A 
@@ -1368,38 +1368,26 @@
 ing 
-to
+create
 Scope
-d
 String(
-String string, 
 Set%3C
@@ -1481,20 +1481,9 @@
 urn 
-string + %22%5Cn
+%22
 (%22 +
@@ -1538,14 +1538,10 @@
 urn 
-string
+%22%22
 ;%0A  

Use HTML-like labels for nodes