Skip to content

Commit

Permalink
Merge pull request #21 from jenkinsci/kohsuke-master
Browse files Browse the repository at this point in the history
Allow to set graphviz rank direction
  • Loading branch information
guidograzioli authored Feb 11, 2020
2 parents bc8678b + bd754f2 commit 9c2ddca
Show file tree
Hide file tree
Showing 6 changed files with 54 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -59,13 +59,15 @@ public static class DescriptorImpl extends Descriptor<DependencyGraphProperty> {
private boolean graphvizEnabled = true;

private boolean editFunctionInJSViewEnabled = false;

private String projectNameStripRegex = ".*";

private int projectNameStripRegexGroup = 1;

private int projectNameSuperscriptRegexGroup = -1;

private String graphRankDirection = "TB";

public DescriptorImpl() {
load();
}
Expand All @@ -84,7 +86,7 @@ public boolean configure( StaplerRequest req, JSONObject o ) {
setProjectNameStripRegex(o.optString("projectNameStripRegex", ".*"));
setProjectNameStripRegexGroup(o.optInt("projectNameStripRegexGroup", 1));
setProjectNameSuperscriptRegexGroup(o.optInt("projectNameSuperscriptRegexGroup", 1));

setGraphRankDirection(o.optString("graphRankDirection", "TB"));
save();

return true;
Expand Down Expand Up @@ -119,6 +121,10 @@ public synchronized int getProjectNameSuperscriptRegexGroup() {
return projectNameSuperscriptRegexGroup;
}

public synchronized String getGraphRankDirection() {
return graphRankDirection;
}

/**
* @return configured dot executable or a default
*/
Expand All @@ -144,7 +150,12 @@ public synchronized void setProjectNameStripRegex(String projectNameStripRegex)
this.projectNameStripRegex = projectNameStripRegex;
save();
}


public synchronized void setGraphRankDirection(String graphRankDirection) {
this.graphRankDirection = graphRankDirection;
save();
}

public synchronized void setDotExe(String dotPath) {
this.dotExe = dotPath;
save();
Expand All @@ -154,7 +165,7 @@ public synchronized void setGraphvizEnabled(boolean graphvizEnabled) {
this.graphvizEnabled = graphvizEnabled;
save();
}

public void setEditFunctionInJSViewEnabled(boolean editFunctionInJSViewEnabled) {
this.editFunctionInJSViewEnabled = editFunctionInJSViewEnabled;
save();
Expand All @@ -163,7 +174,7 @@ public void setEditFunctionInJSViewEnabled(boolean editFunctionInJSViewEnabled)
public FormValidation doCheckDotExe(@QueryParameter final String value) {
return FormValidation.validateExecutable(value);
}

public FormValidation doCheckProjectNameStripRegex(@QueryParameter final String value)
throws IOException, ServletException {
String pattern = Util.fixEmptyAndTrim(value);
Expand All @@ -177,7 +188,7 @@ public FormValidation doCheckProjectNameStripRegex(@QueryParameter final String
}
return FormValidation.ok();
}

public FormValidation doCheckProjectNameStripRegexGroup(@QueryParameter final String value) {
return FormValidation.validatePositiveInteger(value);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@
* Generates a dot string representation of the graph
*/
public class DotStringGenerator extends AbstractDotStringGenerator {

private String rankDirection;
private static final Function<String, String> ESCAPE = new Function<String, String>() {
@Override
public String apply(String from) {
Expand Down Expand Up @@ -93,6 +95,7 @@ public DotStringGenerator(Jenkins jenkins, DependencyGraph graph, ListMultimap<P
int projectNameStripRegexGroup = jenkins.getDescriptorByType(DescriptorImpl.class).getProjectNameStripRegexGroup();
final String projectNameStripRegex = jenkins.getDescriptorByType(DescriptorImpl.class).getProjectNameStripRegex();
int projectNameSuperscriptRegexGroup = jenkins.getDescriptorByType(DescriptorImpl.class).getProjectNameSuperscriptRegexGroup();
this.rankDirection = jenkins.getDescriptorByType(DescriptorImpl.class).getGraphRankDirection();

Pattern nameStripPattern = null;
try {
Expand All @@ -119,6 +122,7 @@ public String generate() {

builder.append("digraph {\n");
builder.append("node [shape=box, style=rounded];\n");
builder.append("rankdir=").append(rankDirection).append(";\n");

/**** First define all the objects and clusters ****/

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,5 +41,8 @@
<f:entry field="projectNameSuperscriptRegexGroup" title="${%projectNameSuperscriptRegexGroup}">
<f:textbox />
</f:entry>
<f:entry field="graphRankDirection" title="${%graphRankDirection}">
<f:textbox />
</f:entry>
</f:section>
</j:jelly>
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,4 @@

editFunctionInJSViewEnabled=Enable edit functiononality in jsplumb view
projectNameStripRegex=Strip the project names
graphRankDirection=Graphviz rank direction
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<!--
~ Copyright (c) 2013 Dominik Bartholdi
~
~ Permission is hereby granted, free of charge, to any person obtaining a copy
~ of this software and associated documentation files (the "Software"), to deal
~ in the Software without restriction, including without limitation the rights
~ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
~ copies of the Software, and to permit persons to whom the Software is
~ furnished to do so, subject to the following conditions:
~
~ The above copyright notice and this permission notice shall be included in
~ all copies or substantial portions of the Software.
~
~ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
~ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
~ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
~ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
~ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
~ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
~ THE SOFTWARE.
-->

<div>
The direction used by graphviz to layout graph nodes.<br />
Can be set to <code>TB</code> (top to bottom) or <code>LR</code> (left to right), default is <code>TB</code>.
</div>
2 changes: 1 addition & 1 deletion src/main/resources/index.jelly
Original file line number Diff line number Diff line change
Expand Up @@ -30,5 +30,5 @@
<?jelly escape-by-default='true'?>
<div>
This plugin shows a dependency graph of the projects.
It uses dot (from graphviz) for drawing.
It uses dot (from graphviz) or jsPlumb for drawing.
</div>

0 comments on commit 9c2ddca

Please sign in to comment.