Skip to content

Commit 31313cb

Browse files
committed
some post merge fixes
1 parent 9ef3b99 commit 31313cb

4 files changed

Lines changed: 43 additions & 36 deletions

File tree

linegraph/createGraph.py

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -35,17 +35,6 @@ def nodeColour(difftype):
3535
elif difftype == g.DIFFTYPE_REM:
3636
return g.DIFFTYPE_REM_COLOR
3737

38-
39-
# the colour of the edge according to the specification, for "a", "b", and "ab"
40-
def edgeColour(edge):
41-
if edge == "a":
42-
return g.EDGE_A_COLOUR
43-
elif edge == "b":
44-
return g.EDGE_B_COLOUR
45-
else: # "ab"
46-
return g.EDGE_AB_COLOUR
47-
48-
4938
# draw a node within a sub graph
5039
def drawNode(cluster, tree, nodeId, nodeLabel):
5140
nodedata = NODE_PARSER(nodeId, nodeLabel)
@@ -65,7 +54,7 @@ def drawEdge(cluster, tree, childNodeId, parentNodeId, nodeLabel):
6554
cluster.edge(
6655
tree + "_" + childNodeId, # identifier of the destination node (where the edge arrow points to)
6756
tree + "_" + parentNodeId, # identifier of the source node (where the edge arrow points from)
68-
color=edgeColour(nodeLabel)) # colour of the edge
57+
color=g.edgeColour(nodeLabel)) # colour of the edge
6958

7059

7160
# draw one tree, i.e. sub graph, of the patterns file

linegraph/graphGeneration.py

Lines changed: 25 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,33 @@
11
#!/bin/python3
22

3-
43
# constants from our Java code
54
JAVA_TREE_NAME_SEPARATOR = "$$$"
6-
JAVA_ID_LINE_NUMBER_OFFSET = 16
7-
JAVA_ID_DIFF_TYPE_OFFSET = 8
5+
JAVA_ID_LINE_NUMBER_OFFSET = 6 #16
6+
JAVA_ID_DIFF_TYPE_OFFSET = 3 #8
87
JAVA_ID_DIFFLINE_FROM_OFFSET = 1
98

109
# export names
1110
# DIR_SEPARATOR = "$"
1211
DIR_SEPARATOR = "___"
1312

13+
COLORFUL_DELETED = '#A00000'
14+
COLORFUL_INSERTED = '#00A000'
15+
COLORFUL_MACRO = '#579'
16+
1417
# colour of a node shows diff type
15-
DIFFTYPE_ADD_COLOR = 'green'
16-
DIFFTYPE_REM_COLOR = 'red'
18+
DIFFTYPE_ADD_COLOR = 'green' #COLORFUL_INSERTED #
19+
DIFFTYPE_REM_COLOR = 'red' #COLORFUL_DELETED #'#ff9129'
1720
DIFFTYPE_NON_COLOR = '#d1d1e0' # light purple gray
1821

1922
# border colour of a node shows code type
20-
CODE_TYPE_CODE_COLOR = '#3399ff'
21-
CODE_TYPE_OTHER_COLOR = 'black'
23+
CODE_TYPE_CODE_COLOR = 'black'
24+
CODE_TYPE_OTHER_COLOR = '#3399ff'#COLORFUL_MACRO#
2225
TYPE_BORDER_SIZE = (8.0 / 7.0)
2326

24-
# edge colours
25-
EDGE_A_COLOUR = "#bbeb37"
26-
EDGE_B_COLOUR = "#ff9129"
27-
EDGE_AB_COLOUR = "black"
27+
# colour of edges
28+
EDGE_ADD_COLOR = '#bbeb37'
29+
EDGE_REM_COLOR = '#ff9129'
30+
EDGE_NON_COLOR = 'black'
2831

2932
RELEASE_PATTERNS_CODE_PREFIX = "c"
3033
RELEASE_PATTERNS_MACRO_PREFIX = "m"
@@ -224,4 +227,14 @@ def parseNodeReleaseAtomics(id, name):
224227
else:
225228
raise Exception("Node " + name + " has unknown type. Expected prefix " + RELEASE_PATTERNS_CODE_PREFIX + " or " + RELEASE_PATTERNS_MACRO_PREFIX + " but was none.")
226229

227-
return result
230+
return result
231+
232+
def edgeColour(edge):
233+
if edge.startswith("a"):
234+
return EDGE_ADD_COLOR
235+
elif edge.startswith("ba"):
236+
return EDGE_NON_COLOR
237+
elif edge.startswith("b"):
238+
return EDGE_REM_COLOR
239+
else:
240+
raise Exception("Cannot parse edge label " + edge)

linegraph/renderLinegraph.py

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
import re
66
import sys
77

8+
import graphGeneration as g
9+
810
## settings for running example
911
# for diff
1012
# NODE_POSITION_LAYOUT = "circo"
@@ -17,8 +19,6 @@
1719
# POS_SCALING_Y = 0.5
1820
# plt.margins(x=0.11)
1921

20-
import graphGeneration as g
21-
2222
# + install graphviz on your system: https://www.graphviz.org/download/
2323

2424
# format
@@ -153,6 +153,8 @@ def plot_graphs(S, exportDir):
153153
node_colors.append(g.DIFFTYPE_ADD_COLOR)
154154
elif nodedata.difftype == g.DIFFTYPE_REM:
155155
node_colors.append(g.DIFFTYPE_REM_COLOR)
156+
else:
157+
raise Exception("Could not determine color of node " + str(nodedata.difftype))
156158

157159
if nodedata.codetype == g.CODETYPE_CODE:
158160
node_type_colors.append(g.CODE_TYPE_CODE_COLOR)
@@ -164,12 +166,7 @@ def plot_graphs(S, exportDir):
164166
edge_colors = []
165167
for _, _, d in difftree.edges.data():
166168
typeName = str(d['label'])
167-
if typeName.startswith("a"):
168-
edge_colors.append(EDGE_ADD_COLOR)
169-
if typeName.startswith("ba"):
170-
edge_colors.append(EDGE_NON_COLOR)
171-
elif typeName.startswith("b"):
172-
edge_colors.append(EDGE_REM_COLOR)
169+
edge_colors.append(g.edgeColour(typeName))
173170

174171
# pos = nx.spring_layout(S[i], scale=3)
175172
# pos = nx.planar_layout(S[i], scale=3)
@@ -198,6 +195,9 @@ def plot_graphs(S, exportDir):
198195
ycenter = (ymax + ymin) / 2
199196
yhalf = (ymax - ymin) / 2
200197

198+
if yhalf == 0:
199+
yhalf = ycenter / 2
200+
201201
# 3: shift our nodes and normalize their position on the y scale
202202
new_pos = {}
203203
for k, v in pos.items():
@@ -216,7 +216,8 @@ def plot_graphs(S, exportDir):
216216
# draw nodes
217217
if SHOW_LABELS:
218218
node_labels = dict([(v, d['label']) for v, d in difftree.nodes(data=True)])
219-
nx.draw(difftree, pos,
219+
nx.draw(difftree,
220+
pos,
220221
node_size=NODE_SIZE,
221222
node_color=node_colors,
222223
width=EDGE_SIZE,
@@ -283,6 +284,7 @@ def getAllFilesInDirectoryRecusivelyThat(dirname, condition):
283284
FONT_SIZE = args.fontsize
284285
LINE_NO_OFFSET = args.startlineno
285286

287+
# print("args.format", args.format)
286288
if args.format == "default":
287289
NODE_PARSER = g.parseNodeDefault
288290
elif args.format == "patternsdebug":

src/main/java/org/variantsync/diffdetective/main/SimpleRenderer.java

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ public class SimpleRenderer {
4949
.build();
5050

5151
private static final RenderOptions renderExampleOptions = new RenderOptions.Builder()
52+
.setTreeFormat(new RWCompositePatternTreeFormat())
5253
.setNodesize(3*RenderOptions.DEFAULT.nodesize())
5354
.setEdgesize(2*RenderOptions.DEFAULT.edgesize())
5455
.setArrowsize(2*RenderOptions.DEFAULT.arrowsize())
@@ -67,6 +68,8 @@ public class SimpleRenderer {
6768
.addExtraArguments("--format", "patternsdebug")
6869
.build();
6970

71+
private static final RenderOptions RENDER_OPTIONS_TO_USE = renderExampleOptions;
72+
7073
private final static boolean collapseMultipleCodeLines = true;
7174
private final static boolean ignoreEmptyLines = true;
7275
private final static List<String> SUPPORTED_FILE_TYPES = List.of(".diff", ".c", ".cpp", ".h", ".hpp");
@@ -80,7 +83,7 @@ private static void render(final Path fileToRender) {
8083
final String fileToRenderStr = fileToRender.toString();
8184
if (fileToRenderStr.endsWith(".lg")) {
8285
Logger.info("Rendering " + fileToRender);
83-
renderer.renderFile(fileToRender, vulkanRenderOptions);
86+
renderer.renderFile(fileToRender, RENDER_OPTIONS_TO_USE);
8487
} else if (SUPPORTED_FILE_TYPES.stream().anyMatch(fileToRenderStr::endsWith)) {
8588
Logger.info("Rendering " + fileToRender);
8689
final DiffTree t;
@@ -95,7 +98,7 @@ private static void render(final Path fileToRender) {
9598
fileToRender.getFileName().toString(),
9699
GetRelativeOutputDir.apply(fileToRender),
97100
// renderExampleOptions
98-
renderCompositePatterns
101+
RENDER_OPTIONS_TO_USE
99102
);
100103
} else {
101104
Logger.warn("Skipping unsupported file " + fileToRender);
@@ -137,7 +140,7 @@ public static void main(String[] args) throws IOException {
137140
final PatchDiff patch = DiffTreeParser.parsePatch(repository, file, commit);
138141
assert patch != null;
139142
DiffTreeTransformer.apply(transform, patch.getDiffTree());
140-
renderer.render(patch, Path.of("render", repoName), vulkanRenderOptions);
143+
renderer.render(patch, Path.of("render", repoName), RENDER_OPTIONS_TO_USE);
141144
}
142145

143146
System.out.println("done");

0 commit comments

Comments
 (0)