Skip to content

Commit aaf967a

Browse files
stoivoidank
authored andcommitted
web/ui: use same pattern to create SVG path
1 parent baf0000 commit aaf967a

File tree

1 file changed

+24
-10
lines changed
  • explainshell/web/static/js

1 file changed

+24
-10
lines changed

explainshell/web/static/js/es.js

Lines changed: 24 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -573,10 +573,16 @@ function drawgrouplines(commandselector, options) {
573573
commandRight = commandRect.right - strokewidth;
574574

575575
link.starty = commandRect.bottom - commandWrapperRect.top + 1;
576+
var commandOffsetToCanvas = marginBetweenCommandAndCanvas - link.starty
576577

577578
// points for marker under command
578-
link.paths.push(new espath().addpoint(commandRect.left, 0).addpoint(commandRight, 5));
579-
link.paths.push(new espath().addpoint(commandRight, 5).addpoint(commandRight, 0));
579+
link.paths.push(new espath()
580+
.addpoint(commandRect.left, 0)
581+
.addpoint(commandRect.left, 5)
582+
.addpoint(commandRight, 5)
583+
.addpoint(commandRight, 0)
584+
);
585+
580586
var path = new espath();
581587
path.addpoint(spanmid, 5); // 3
582588

@@ -592,10 +598,10 @@ function drawgrouplines(commandselector, options) {
592598
// this line
593599
if (link == leftmost) {
594600
topskip = topheight / goingleft;
595-
y = topskip * goneleft + topskip;
601+
y = topskip * goneleft + topskip + commandOffsetToCanvas;
596602
path.addpoint(left - ((goingleft - goneleft) * sidespace), y); // 4
597603
helprect = link.help.getBoundingClientRect();
598-
y = helprect.top - commandWrapperRect.bottom + helprect.height / 2;
604+
y = (helprect.top - commandWrapperRect.bottom + helprect.height / 2) + commandOffsetToCanvas;
599605
path.addpoint(left, y);
600606

601607
link.circle = {x: left+3, y: y, r: 4};
@@ -617,10 +623,10 @@ function drawgrouplines(commandselector, options) {
617623

618624
if (link == rightmost) {
619625
topskip = topheight / goingright;
620-
y = topskip * goneright + topskip;
626+
y = topskip * goneright + topskip + commandOffsetToCanvas;
621627
path.addpoint(right + ((goingright - goneright) * sidespace), y); // 4
622628
helprect = link.help.getBoundingClientRect();
623-
y = helprect.top - commandWrapperRect.bottom + helprect.height / 2;
629+
y = (helprect.top - commandWrapperRect.bottom + helprect.height / 2) + commandOffsetToCanvas;
624630
path.addpoint(right, y);
625631

626632
link.circle = {x: right-3, y: y, r: 4};
@@ -653,6 +659,7 @@ function drawgrouplines(commandselector, options) {
653659
prevlink = _.find(links, function(l) { return l.option == prevspan; });
654660

655661
link.starty = link.option.getBoundingClientRect().bottom - link.option.parentElement.getBoundingClientRect().top + 1;
662+
var commandOffsetToCanvas = marginBetweenCommandAndCanvas - link.starty
656663
link.unknown = true;
657664
link.text = "?";
658665

@@ -668,11 +675,18 @@ function drawgrouplines(commandselector, options) {
668675
// link.circle = {x: rrmid, y: startytop-5-unknownlinelength-3, r: 8};
669676
//}
670677
//else {
671-
link.paths.push(new espath().addpoint(rr.left, 0).addpoint(rrright, 5));
672-
link.paths.push(new espath().addpoint(rrright, 5).addpoint(rrright, 0));
678+
link.paths.push(new espath()
679+
.addpoint(rr.left, 0)
680+
.addpoint(rr.left, 5)
681+
.addpoint(rrright, 5)
682+
.addpoint(rrright, 0)
683+
);
673684
var rrmid = d3.round(rr.left + rr.width / 2);
674-
link.lines.push({x1: rrmid, y1: 6, x2: rrmid, y2: 5+unknownlinelength});
675-
link.circle = {x: rrmid, y: 5+unknownlinelength+3, r: 8};
685+
link.paths.push(new espath()
686+
.addpoint(rrmid, 5 + strokewidth)
687+
.addpoint(rrmid, 5 + strokewidth + unknownlinelength + commandOffsetToCanvas)
688+
);
689+
link.circle = {x: rrmid, y: 5+unknownlinelength+3+commandOffsetToCanvas, r: 8};
676690
//}
677691

678692
links.push(link);

0 commit comments

Comments
 (0)