Skip to content

Commit 5b9427b

Browse files
committed
Fix Issue #3
1 parent 0e6fa9a commit 5b9427b

File tree

1 file changed

+35
-24
lines changed

1 file changed

+35
-24
lines changed

reporter/assets/js/sankey.js

Lines changed: 35 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -452,7 +452,7 @@ function mouseover(d, contexter) {
452452
computedHeight = boundingRect.height;
453453

454454
let xPosition = d.x + margins.left + d.dx + 10;
455-
let yPosition = margins.top;
455+
let yPosition = d.y + d.dy/2;
456456
let endXPosition = xPosition + computedWidth;
457457

458458
if(endXPosition > width) {
@@ -467,38 +467,49 @@ function mouseover(d, contexter) {
467467
im.id = "scene" + d.id;
468468
im.src = "data:image/png;base64," + d.image
469469
im.onload = function(e) {
470-
var w = this.width;
471-
var h = this.height;
470+
var h = 100;
472471
var ixPosition = d.x + margins.left + d.dx + 10; // 10 of separation from node
473-
var iyPosition = computedHeight + 10; // 10 of separation from label
474-
let endiXPosition = ixPosition + w;
475-
let endiYPosition = iyPosition + h;
472+
var iyPosition = d.y + d.dy/2 + 10; // 10 of separation from label
476473

477-
var i = 1
478-
while(w/i > 100 || h/i > 100) {
479-
i++;
480-
}
481-
482-
h = h/i;
483-
w = w/i;
484-
485-
endiXPosition = ixPosition + w;
486-
endiYPosition = iyPosition + h;
487-
488-
if(endiXPosition > width) {
489-
ixPosition -= (endiXPosition-width)
490-
}
491-
492-
contexter.base.append("image")
474+
image = contexter.base.append("image")
493475
.data([this])
494476
.attr("x", ixPosition)
495477
.attr("y", iyPosition)
478+
.attr("height", 100)
479+
.style("width", "auto")
496480
.attr("xlink:href", this.src)
497481
.attr("transform", null)
498482
.attr("id", this.id)
499483
.attr("class", "scene-image")
500-
.attr("width", w)
501-
.attr("height", h)
484+
485+
imageBoundingRect = image.node().getBoundingClientRect();
486+
computedImageWidth = imageBoundingRect.width;
487+
computedImageHeight = imageBoundingRect.height;
488+
let endImageXPosition = ixPosition + computedImageWidth;
489+
let endImageYPosition = iyPosition + computedImageHeight;
490+
491+
if(endImageXPosition > width) {
492+
ixPosition -= (endImageXPosition-width)
493+
}
494+
495+
if(endImageYPosition > height + margins.bottom) {
496+
iyPosition -= (endImageYPosition-(height+margins.bottom))
497+
}
498+
499+
image.attr("x", ixPosition)
500+
.attr("y", iyPosition);
501+
502+
text.attr("y", iyPosition - 10);
503+
504+
contexter.base.append('rect')
505+
.attr('class', 'scene-image')
506+
.attr('width', computedImageWidth)
507+
.attr('height', computedImageHeight)
508+
.attr('fill', 'transparent')
509+
.attr('stroke', 'black')
510+
.style('opacity', 0.25)
511+
.attr("x", ixPosition)
512+
.attr("y", iyPosition);
502513
}
503514
}
504515
}

0 commit comments

Comments
 (0)