Skip to content

Commit 4a575f0

Browse files
committed
[IT-2764] Take the width of the tooltip into account so the tooltip does not leave the graph area
1 parent afe5f71 commit 4a575f0

File tree

2 files changed

+14
-7
lines changed

2 files changed

+14
-7
lines changed

frontend/src/app/modules/time-series/components/time-series-line-chart/time-series-line-chart.component.scss

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,19 +7,22 @@ osm-time-series-line-chart {
77
position: absolute;
88
text-align: left;
99
padding: 5px;
10-
font: 12px sans-serif;
10+
font: 10pt sans-serif;
1111
color: white;
12-
background: black;
12+
background: rgba(0, 0, 0, 0.7);
1313
border: 0px;
1414
border-radius: 3px;
1515
pointer-events: none;
1616

1717
tr.active {
18-
background: lightgray;
18+
background: rgba(255, 255, 255, 0.35);
1919
}
2020

2121
td {
2222
padding-right: 10px;
23+
i {
24+
padding-right: 5px;
25+
}
2326
}
2427
}
2528

frontend/src/app/modules/time-series/services/line-chart.service.ts

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -552,12 +552,16 @@ export class LineChartService {
552552
const tooltipText = this.generateTooltipText(nearestDot, visibleDots, highlightedDate);
553553
tooltip.html(tooltipText.outerHTML);
554554

555-
556555
// TODO: Positioning of the tooltip must be left or right of the box, depending on the space left
556+
const tooltipWidth: number = (<HTMLDivElement>tooltip.node()).getBoundingClientRect().width;
557+
const nearestDotXPosition: number = parseFloat(nearestDot.attr('cx'));
558+
557559
const top = parseFloat(nearestDot.attr('cy')) + this._margin.top;
558-
const left = parseFloat(nearestDot.attr('cx')) + this._margin.left + 50;
560+
const left = ( tooltipWidth + nearestDotXPosition > this._width ) ?
561+
(nearestDotXPosition - tooltipWidth + this._margin.right + 10) : nearestDotXPosition + this._margin.left + 50;
559562
tooltip.style('top', top+'px');
560563
tooltip.style('left', left+ 'px');
564+
561565
}
562566

563567
private generateTooltipText(nearestDot: D3Selection<any, unknown, null, undefined>, visibleDots: D3Selection<D3BaseType, {}, HTMLElement, any>, highlightedDate: Date): HTMLTableElement {
@@ -569,13 +573,13 @@ export class LineChartService {
569573

570574
visibleDots
571575
.sort((a: TimeSeriesPoint, b: TimeSeriesPoint) => {
572-
console.log(a,b);
576+
// console.log(a,b);
573577
if (a.value > b.value) return -1
574578
else if (a.value < b.value) return 1
575579
else return 0;
576580
})
577581
.each((timeSeriesPoint: TimeSeriesPoint, index: number, nodes: D3BaseType[]) => {
578-
console.log(timeSeriesPoint, index, nodes[index]);
582+
// console.log(timeSeriesPoint, index, nodes[index]);
579583
tableBody.append(this.generateTooltipDatapointRow(timeSeriesPoint, nodes[index], nearestDot));
580584
});
581585

0 commit comments

Comments
 (0)