Skip to content

Commit 7b5e842

Browse files
author
epriestley
committedJul 1, 2016
Improve "thread" rendering of unusually-shaped graphs
Summary: Ref T4788. This fixes all the bugs I was immediately able to catch: - "Directory-Like" graph shapes could draw too many vertical lines. - "Reverse-Directory-Like" graph shapes could draw too few vertical lines. - Terminated, branched graph shapes drew the very last line to the wrong place. This covers the behavior with tests, so we should be able to fix more stuff later without breaking anything. Test Plan: - Added failing tests and made them pass. {F1708158} {F1708159} {F1708160} {F1708161} Reviewers: chad Reviewed By: chad Maniphest Tasks: T4788 Differential Revision: https://secure.phabricator.com/D16216
1 parent 0a132e4 commit 7b5e842

File tree

5 files changed

+135
-14
lines changed

5 files changed

+135
-14
lines changed
 

‎resources/celerity/map.php

+8-8
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
'differential.pkg.css' => '3e81ae60',
1414
'differential.pkg.js' => '634399e9',
1515
'diffusion.pkg.css' => '91c5d3a6',
16-
'diffusion.pkg.js' => '3a9a8bfa',
16+
'diffusion.pkg.js' => '84c8f8fd',
1717
'maniphest.pkg.css' => '4845691a',
1818
'maniphest.pkg.js' => '949a7498',
1919
'rsrc/css/aphront/aphront-bars.css' => '231ac33c',
@@ -394,7 +394,7 @@
394394
'rsrc/js/application/diffusion/DiffusionLocateFileSource.js' => 'b42eddc7',
395395
'rsrc/js/application/diffusion/behavior-audit-preview.js' => 'd835b03a',
396396
'rsrc/js/application/diffusion/behavior-commit-branches.js' => 'bdaf4d04',
397-
'rsrc/js/application/diffusion/behavior-commit-graph.js' => '5a0b1a64',
397+
'rsrc/js/application/diffusion/behavior-commit-graph.js' => '49ae8328',
398398
'rsrc/js/application/diffusion/behavior-diffusion-browse-file.js' => '054a0f0b',
399399
'rsrc/js/application/diffusion/behavior-jump-to.js' => '73d09eef',
400400
'rsrc/js/application/diffusion/behavior-load-blame.js' => '42126667',
@@ -619,7 +619,7 @@
619619
'javelin-behavior-differential-user-select' => 'a8d8459d',
620620
'javelin-behavior-diffusion-browse-file' => '054a0f0b',
621621
'javelin-behavior-diffusion-commit-branches' => 'bdaf4d04',
622-
'javelin-behavior-diffusion-commit-graph' => '5a0b1a64',
622+
'javelin-behavior-diffusion-commit-graph' => '49ae8328',
623623
'javelin-behavior-diffusion-jump-to' => '73d09eef',
624624
'javelin-behavior-diffusion-locate-file' => '6d3e1947',
625625
'javelin-behavior-diffusion-pull-lastmodified' => 'f01586dc',
@@ -1217,6 +1217,11 @@
12171217
'javelin-uri',
12181218
'phabricator-notification',
12191219
),
1220+
'49ae8328' => array(
1221+
'javelin-behavior',
1222+
'javelin-dom',
1223+
'javelin-stratcom',
1224+
),
12201225
'4b700e9e' => array(
12211226
'javelin-behavior',
12221227
'javelin-dom',
@@ -1343,11 +1348,6 @@
13431348
'javelin-vector',
13441349
'javelin-dom',
13451350
),
1346-
'5a0b1a64' => array(
1347-
'javelin-behavior',
1348-
'javelin-dom',
1349-
'javelin-stratcom',
1350-
),
13511351
'5a13c79f' => array(
13521352
'javelin-install',
13531353
'javelin-dom',

‎src/__phutil_library_map__.php

+2
Original file line numberDiff line numberDiff line change
@@ -1602,6 +1602,7 @@
16021602
'PHUICurtainPanelView' => 'view/layout/PHUICurtainPanelView.php',
16031603
'PHUICurtainView' => 'view/layout/PHUICurtainView.php',
16041604
'PHUIDiffGraphView' => 'infrastructure/diff/view/PHUIDiffGraphView.php',
1605+
'PHUIDiffGraphViewTestCase' => 'infrastructure/diff/view/__tests__/PHUIDiffGraphViewTestCase.php',
16051606
'PHUIDiffInlineCommentDetailView' => 'infrastructure/diff/view/PHUIDiffInlineCommentDetailView.php',
16061607
'PHUIDiffInlineCommentEditView' => 'infrastructure/diff/view/PHUIDiffInlineCommentEditView.php',
16071608
'PHUIDiffInlineCommentRowScaffold' => 'infrastructure/diff/view/PHUIDiffInlineCommentRowScaffold.php',
@@ -6139,6 +6140,7 @@
61396140
'PHUICurtainPanelView' => 'AphrontTagView',
61406141
'PHUICurtainView' => 'AphrontTagView',
61416142
'PHUIDiffGraphView' => 'Phobject',
6143+
'PHUIDiffGraphViewTestCase' => 'PhabricatorTestCase',
61426144
'PHUIDiffInlineCommentDetailView' => 'PHUIDiffInlineCommentView',
61436145
'PHUIDiffInlineCommentEditView' => 'PHUIDiffInlineCommentView',
61446146
'PHUIDiffInlineCommentRowScaffold' => 'AphrontView',

‎src/infrastructure/diff/view/PHUIDiffGraphView.php

+29-6
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ public function getIsTail() {
2323
return $this->isTail;
2424
}
2525

26-
public function renderGraph(array $parents) {
26+
public function renderRawGraph(array $parents) {
2727
// This keeps our accumulated information about each line of the
2828
// merge/branch graph.
2929
$graph = array();
@@ -47,7 +47,10 @@ public function renderGraph(array $parents) {
4747
$line = '';
4848
$found = false;
4949
$pos = count($threads);
50-
for ($n = 0; $n < $count; $n++) {
50+
51+
$thread_count = $pos;
52+
for ($n = 0; $n < $thread_count; $n++) {
53+
5154
if (empty($threads[$n])) {
5255
$line .= ' ';
5356
continue;
@@ -147,16 +150,30 @@ public function renderGraph(array $parents) {
147150
$line = $graph[$key]['line'];
148151
$len = strlen($line);
149152
for ($ii = 0; $ii < $len; $ii++) {
150-
if (isset($terminated[$ii])) {
151-
continue;
152-
}
153-
154153
$c = $line[$ii];
155154
if ($c == 'o') {
155+
// If we've already terminated this thread, we don't need to add
156+
// a terminator.
157+
if (isset($terminated[$ii])) {
158+
continue;
159+
}
160+
156161
$terminated[$ii] = true;
162+
163+
// If this thread is joinining some other node here, we don't want
164+
// to terminate it.
165+
if (isset($graph[$key + 1])) {
166+
$joins = $graph[$key + 1]['join'];
167+
if (in_array($ii, $joins)) {
168+
continue;
169+
}
170+
}
171+
157172
$graph[$key]['line'][$ii] = 'x';
158173
} else if ($c != ' ') {
159174
$terminated[$ii] = true;
175+
} else {
176+
unset($terminated[$ii]);
160177
}
161178
}
162179
}
@@ -166,6 +183,12 @@ public function renderGraph(array $parents) {
166183
$graph[] = $last;
167184
}
168185

186+
return array($graph, $count);
187+
}
188+
189+
public function renderGraph(array $parents) {
190+
list($graph, $count) = $this->renderRawGraph($parents);
191+
169192
// Render into tags for the behavior.
170193

171194
foreach ($graph as $k => $meta) {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
<?php
2+
3+
final class PHUIDiffGraphViewTestCase extends PhabricatorTestCase {
4+
5+
public function testTailTermination() {
6+
$nodes = array(
7+
'A' => array('B'),
8+
'B' => array('C', 'D', 'E'),
9+
'E' => array(),
10+
'D' => array(),
11+
'C' => array('F', 'G'),
12+
'G' => array(),
13+
'F' => array(),
14+
);
15+
16+
$graph = $this->newGraph($nodes);
17+
18+
$picture = array(
19+
'^',
20+
'o',
21+
'||x',
22+
'|x ',
23+
'o ',
24+
'|x ',
25+
'x ',
26+
);
27+
28+
$this->assertGraph($picture, $graph, pht('Terminating Tree'));
29+
}
30+
31+
public function testReverseTree() {
32+
$nodes = array(
33+
'A' => array('B'),
34+
'C' => array('B'),
35+
'B' => array('D'),
36+
'E' => array('D'),
37+
'F' => array('D'),
38+
'D' => array('G'),
39+
'G' => array(),
40+
);
41+
42+
$graph = $this->newGraph($nodes);
43+
44+
$picture = array(
45+
'^',
46+
'|^',
47+
'o ',
48+
'|^',
49+
'||^',
50+
'o ',
51+
'x',
52+
);
53+
54+
$this->assertGraph($picture, $graph, pht('Reverse Tree'));
55+
}
56+
57+
public function testJoinTerminateTree() {
58+
$nodes = array(
59+
'A' => array('D'),
60+
'B' => array('C'),
61+
'C' => array('D'),
62+
'D' => array(),
63+
);
64+
65+
$graph = $this->newGraph($nodes);
66+
67+
$picture = array(
68+
'^',
69+
'|^',
70+
'|o',
71+
'x ',
72+
);
73+
74+
$this->assertGraph($picture, $graph, pht('Reverse Tree'));
75+
}
76+
77+
private function newGraph(array $nodes) {
78+
return id(new PHUIDiffGraphView())
79+
->setIsHead(true)
80+
->setIsTail(true)
81+
->renderRawGraph($nodes);
82+
}
83+
84+
private function assertGraph($picture, $graph, $label) {
85+
list($data, $count) = $graph;
86+
$lines = ipull($data, 'line');
87+
88+
$picture = implode("\n", $picture);
89+
$lines = implode("\n", $lines);
90+
91+
$this->assertEqual($picture, $lines, $label);
92+
}
93+
94+
}

‎webroot/rsrc/js/application/diffusion/behavior-commit-graph.js

+2
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ JX.behavior('diffusion-commit-graph', function(config) {
7979
c = data.line.charAt(jj);
8080
switch (c) {
8181
case 'o':
82+
case 'x':
8283
case '^':
8384
origin = xpos(jj);
8485
break;
@@ -91,6 +92,7 @@ JX.behavior('diffusion-commit-graph', function(config) {
9192
for (jj = 0; jj < data.join.length; jj++) {
9293
var join = data.join[jj];
9394
x = xpos(join);
95+
9496
cxt.beginPath();
9597
cxt.moveTo(x, 0);
9698
cxt.bezierCurveTo(x, h/4, origin, h/4, origin, h/2);

0 commit comments

Comments
 (0)
Failed to load comments.