1111import org .hjug .cbc .RankedCycle ;
1212import org .hjug .cbc .RankedDisharmony ;
1313import org .hjug .gdg .GraphDataGenerator ;
14+ import org .jgrapht .Graph ;
15+ import org .jgrapht .graph .DefaultWeightedEdge ;
1416
1517@ Slf4j
1618public class HtmlReport extends SimpleHtmlReport {
@@ -39,14 +41,13 @@ public class HtmlReport extends SimpleHtmlReport {
3941
4042 @ Override
4143 public void printHead (StringBuilder stringBuilder ) {
42- stringBuilder .append ("<link rel=\" stylesheet\" href=\" ./css/maven-base.css\" />\n "
43- + " <link rel=\" stylesheet\" href=\" ./css/maven-theme.css\" />\n "
44- + " <link rel=\" stylesheet\" href=\" ./css/site.css\" />\n "
45- + " <link rel=\" stylesheet\" href=\" ./css/print.css\" media=\" print\" />\n "
46- + "<script async defer src=\" https://buttons.github.io/buttons.js\" ></script>"
44+ stringBuilder .append ("<script async defer src=\" https://buttons.github.io/buttons.js\" ></script>"
4745 + "<script type=\" text/javascript\" src=\" https://www.gstatic.com/charts/loader.js\" >"
48- + "</script><script type=\" text/javascript\" src=\" ./gchart.js\" ></script>"
49- + "<script type=\" text/javascript\" src=\" ./gchart2.js\" ></script>"
46+ + "</script><script type=\" text/javascript\" src=\" ./gchart.js\" ></script>\n "
47+ + "<script type=\" text/javascript\" src=\" ./gchart2.js\" ></script>\n "
48+ + "<script src=\" https://d3js.org/d3.v5.min.js\" ></script>\n "
49+ +
"<script src=\" https://unpkg.com/[email protected] /build/d3-graphviz.min.js\" ></script>\n " 50+ +
"<script src=\" https://unpkg.com/@hpcc-js/[email protected] /dist/index.min.js\" ></script>\n " 5051 + " </head>\n " );
5152 }
5253
@@ -57,24 +58,24 @@ public void printTitle(String projectName, String projectVersion, StringBuilder
5758 .append (projectName )
5859 .append (" " )
5960 .append (projectVersion )
60- .append (" </title>" );
61+ .append (" </title>\n " );
6162 }
6263
6364 @ Override
6465 void renderGithubButtons (StringBuilder stringBuilder ) {
65- stringBuilder .append ("<div align=\" center\" >" );
66- stringBuilder .append ("Show RefactorFirst some ❤️" );
67- stringBuilder .append ("<br/>" );
66+ stringBuilder .append ("<div align=\" center\" >\n " );
67+ stringBuilder .append ("Show RefactorFirst some ❤️\n " );
68+ stringBuilder .append ("<br/>\n " );
6869 stringBuilder .append (
69- "<a class=\" github-button\" href=\" https://github.com/refactorfirst/refactorfirst\" data-icon=\" octicon-star\" data-size=\" large\" data-show-count=\" true\" aria-label=\" Star refactorfirst/refactorfirst on GitHub\" >Star</a>" );
70+ "<a class=\" github-button\" href=\" https://github.com/refactorfirst/refactorfirst\" data-icon=\" octicon-star\" data-size=\" large\" data-show-count=\" true\" aria-label=\" Star refactorfirst/refactorfirst on GitHub\" >Star</a>\n " );
7071 stringBuilder .append (
71- "<a class=\" github-button\" href=\" https://github.com/refactorfirst/refactorfirst/fork\" data-icon=\" octicon-repo-forked\" data-size=\" large\" data-show-count=\" true\" aria-label=\" Fork refactorfirst/refactorfirst on GitHub\" >Fork</a>" );
72+ "<a class=\" github-button\" href=\" https://github.com/refactorfirst/refactorfirst/fork\" data-icon=\" octicon-repo-forked\" data-size=\" large\" data-show-count=\" true\" aria-label=\" Fork refactorfirst/refactorfirst on GitHub\" >Fork</a>\n " );
7273 stringBuilder .append (
73- "<a class=\" github-button\" href=\" https://github.com/refactorfirst/refactorfirst/subscription\" data-icon=\" octicon-eye\" data-size=\" large\" data-show-count=\" true\" aria-label=\" Watch refactorfirst/refactorfirst on GitHub\" >Watch</a>" );
74+ "<a class=\" github-button\" href=\" https://github.com/refactorfirst/refactorfirst/subscription\" data-icon=\" octicon-eye\" data-size=\" large\" data-show-count=\" true\" aria-label=\" Watch refactorfirst/refactorfirst on GitHub\" >Watch</a>\n " );
7475 stringBuilder .append (
75- "<a class=\" github-button\" href=\" https://github.com/refactorfirst/refactorfirst/issues\" data-icon=\" octicon-issue-opened\" data-size=\" large\" data-show-count=\" false\" aria-label=\" Issue refactorfirst/refactorfirst on GitHub\" >Issue</a>" );
76+ "<a class=\" github-button\" href=\" https://github.com/refactorfirst/refactorfirst/issues\" data-icon=\" octicon-issue-opened\" data-size=\" large\" data-show-count=\" false\" aria-label=\" Issue refactorfirst/refactorfirst on GitHub\" >Issue</a>\n " );
7677 stringBuilder .append (
77- "<a class=\" github-button\" href=\" https://github.com/sponsors/jimbethancourt\" data-icon=\" octicon-heart\" data-size=\" large\" aria-label=\" Sponsor @jimbethancourt on GitHub\" >Sponsor</a>" );
78+ "<a class=\" github-button\" href=\" https://github.com/sponsors/jimbethancourt\" data-icon=\" octicon-heart\" data-size=\" large\" aria-label=\" Sponsor @jimbethancourt on GitHub\" >Sponsor</a>\n " );
7879 stringBuilder .append ("</div>" );
7980 }
8081
@@ -156,7 +157,7 @@ void renderGodClassChart(
156157 int maxGodClassPriority ,
157158 StringBuilder stringBuilder ) {
158159 writeGodClassGchartJs (rankedGodClassDisharmonies , maxGodClassPriority - 1 , outputDirectory );
159- stringBuilder .append ("<div id=\" series_chart_div\" align=\" center\" ></div>" );
160+ stringBuilder .append ("<div id=\" series_chart_div\" align=\" center\" ></div>\n " );
160161 renderGithubButtons (stringBuilder );
161162 stringBuilder .append (GOD_CLASS_CHART_LEGEND );
162163 }
@@ -168,23 +169,72 @@ void renderCBOChart(
168169 int maxCboPriority ,
169170 StringBuilder stringBuilder ) {
170171 writeGCBOGchartJs (rankedCBODisharmonies , maxCboPriority - 1 , outputDirectory );
171- stringBuilder .append ("<div id=\" series_chart_div_2\" align=\" center\" ></div>" );
172+ stringBuilder .append ("<div id=\" series_chart_div_2\" align=\" center\" ></div>\n " );
172173 renderGithubButtons (stringBuilder );
173174 stringBuilder .append (COUPLING_BETWEEN_OBJECT_CHART_LEGEND );
174175 }
175176
176177 @ Override
177178 public List <RankedCycle > runCycleAnalysis (CostBenefitCalculator costBenefitCalculator , String outputDirectory ) {
178- return costBenefitCalculator .runCycleAnalysis (outputDirectory , true );
179+ return costBenefitCalculator .runCycleAnalysis ();
179180 }
180181
181182 @ Override
182- public void renderCycleImage (String cycleName , StringBuilder stringBuilder , String outputDirectory ) {
183- stringBuilder .append ("<div align=\" center\" >" );
184- stringBuilder .append ("<img src=\" ./refactorFirst/cycles/graph" + cycleName
185- + ".png\" width=\" 1000\" height=\" 1000\" alt=\" Cycle " + cycleName + "\" >" );
186- stringBuilder .append ("</div>" );
187- stringBuilder .append ("<br/>" );
188- stringBuilder .append ("<br/>" );
183+ public void renderCycleImage (
184+ Graph <String , DefaultWeightedEdge > classGraph , RankedCycle cycle , StringBuilder stringBuilder ) {
185+ String dot = buildDot (classGraph , cycle );
186+
187+ stringBuilder .append ("<div align=\" center\" id=\" " + cycle .getCycleName () + "\" ></div>\n " );
188+ stringBuilder .append ("<script>\n " );
189+ stringBuilder .append ("d3.select(\" #" + cycle .getCycleName () + "\" )\n " );
190+ stringBuilder .append (".graphviz()\n " );
191+ stringBuilder .append (".renderDot(" + dot + ");\n " );
192+ stringBuilder .append ("</script>\n " );
193+ }
194+
195+ String buildDot (Graph <String , DefaultWeightedEdge > classGraph , RankedCycle cycle ) {
196+ StringBuilder dot = new StringBuilder ();
197+
198+ dot .append ("'strict digraph G {\\ n' +\n " );
199+
200+ // render vertices
201+ // e.g DownloadManager;
202+ for (String vertex : cycle .getVertexSet ()) {
203+ dot .append ("'" );
204+ dot .append (vertex );
205+ dot .append (";\\ n' +\n " );
206+ }
207+
208+ for (DefaultWeightedEdge edge : cycle .getEdgeSet ()) {
209+ // 'DownloadManager -> Download [ label="1" color="red" ];'
210+
211+ // render edge
212+ String [] vertexes =
213+ edge .toString ().replace ("(" , "" ).replace (")" , "" ).split (":" );
214+
215+ String start = vertexes [0 ].trim ();
216+ String end = vertexes [1 ].trim ();
217+
218+ dot .append ("'" );
219+ dot .append (start );
220+ dot .append (" -> " );
221+ dot .append (end );
222+
223+ // render edge attributes
224+ dot .append (" [ " );
225+ dot .append ("label = \" " );
226+ dot .append ((int ) classGraph .getEdgeWeight (edge ));
227+ dot .append ("\" " );
228+
229+ if (cycle .getMinCutEdges ().contains (edge )) {
230+ dot .append (" color = \" red\" " );
231+ }
232+
233+ dot .append (" ];\\ n' +\n " );
234+ }
235+
236+ dot .append ("'}'" );
237+
238+ return dot .toString ();
189239 }
190240}
0 commit comments