Skip to content

Commit 4dd24a2

Browse files
pingzhkaxil
authored andcommitted
[AIRFLOW-5543] Fix tooltip disappears in tree and graph view (#6174)
when page scrolls
1 parent 6b6d44f commit 4dd24a2

File tree

4 files changed

+50
-37
lines changed

4 files changed

+50
-37
lines changed

airflow/www/static/css/main.css

+10
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,16 @@ span.skipped{
105105
text-align:left !important;
106106
font-size: 12px;
107107
}
108+
109+
.d3-tip {
110+
background: black;
111+
color: white;
112+
border: solid;
113+
border-width: 1px;
114+
border-radius: 5px;
115+
padding: 10px;
116+
}
117+
108118
input#execution_date {
109119
margin-bottom: 0px;
110120
}

airflow/www/static/js/graph.js

+4-4
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,7 @@ function update_nodes_states(task_instances) {
2929
.parent().parent().parent().parent()
3030
.attr("class", "node enter " + (ti.state ? ti.state : "no_status"))
3131
.attr("data-toggle", "tooltip")
32-
.attr("data-original-title", function (d) {
33-
// Tooltip
32+
.on("mouseover", function (d) {
3433
const task = tasks[task_id];
3534
let tt = "";
3635
if(ti.task_id != undefined) {
@@ -44,8 +43,9 @@ function update_nodes_states(task_instances) {
4443
tt += "Duration: " + escapeHtml(convertSecsToHumanReadable(ti.duration)) + "<br>";
4544
tt += "Started: " + escapeHtml(ti.start_date) + "<br>";
4645
tt += generateTooltipDateTime(ti.start_date, ti.end_date, dagTZ); // dagTZ has been defined in dag.html
47-
return tt;
48-
});
46+
taskTip.show(tt, this); // taskTip is defined in graph.html
47+
})
48+
.on('mouseout', taskTip.hide);
4949
});
5050
}
5151

airflow/www/templates/airflow/graph.html

+7-5
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,7 @@
9797

9898
<script src="{{ url_for_asset('d3.min.js') }}"></script>
9999
<script src="{{ url_for_asset('dagre-d3.min.js') }}"></script>
100+
<script src="{{ url_for_asset('d3-tip.js') }}"></script>
100101
<script>
101102

102103
var highlight_color = "#000000";
@@ -128,6 +129,11 @@
128129
'queued': false,
129130
'no_status': false
130131
};
132+
const taskTip = d3.tip()
133+
.attr('class', 'tooltip d3-tip')
134+
.html(function(toolTipHtml) {
135+
return toolTipHtml;
136+
});
131137

132138
// Preparation of DagreD3 data structures
133139
var g = new dagreD3.graphlib.Graph().setGraph({
@@ -152,6 +158,7 @@
152158
innerSvg = d3.select("svg g");
153159

154160
innerSvg.call(render, g);
161+
innerSvg.call(taskTip);
155162

156163
function setUpZoomSupport() {
157164
// Set up zoom support for Graph
@@ -207,11 +214,6 @@
207214
d3.selectAll("text").attr("class", "blur");
208215
{% endif %}
209216

210-
$("g.node").tooltip({
211-
html: true,
212-
container: "body",
213-
});
214-
215217
d3.selectAll("div.legend_item.state")
216218
.style("cursor", "pointer")
217219
.on("mouseover", function(){

airflow/www/templates/airflow/tree.html

+29-28
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@
7979
{% block tail %}
8080
{{ super() }}
8181
<script src="{{ url_for_asset('d3.min.js') }}"></script>
82+
<script src="{{ url_for_asset('d3-tip.js') }}"></script>
8283
<script>
8384
$('span.status_square').tooltip({html: true});
8485

@@ -108,6 +109,12 @@
108109
var diagonal = d3.svg.diagonal()
109110
.projection(function(d) { return [d.y, d.x]; });
110111

112+
const taskTip = d3.tip()
113+
.attr('class', 'tooltip d3-tip')
114+
.html(function(toolTipHtml) {
115+
return toolTipHtml;
116+
});
117+
111118
var svg = d3.select("svg")
112119
//.attr("width", width + margin.left + margin.right)
113120
.append("g")
@@ -145,7 +152,7 @@
145152
)
146153
.selectAll("text")
147154
.attr("transform", "rotate(-30)")
148-
.style("text-anchor", "start");
155+
.style("text-anchor", "start").call(taskTip);
149156

150157
function node_class(d) {
151158
var sclass = "node";
@@ -199,7 +206,7 @@
199206
.attr("r", (barHeight / 3))
200207
.attr("class", "task")
201208
.attr("data-toggle", "tooltip")
202-
.attr("title", function(d){
209+
.on("mouseover", function(d) {
203210
var tt = "";
204211
if (d.operator != undefined) {
205212
if (d.operator != undefined) {
@@ -212,7 +219,15 @@
212219
tt += "start_date: " + escapeHtml(d.start_date) + "<br/>";
213220
tt += "end_date: " + escapeHtml(d.end_date) + "<br/>";
214221
}
215-
return tt;
222+
taskTip.direction('e')
223+
taskTip.show(tt, this)
224+
d3.select(this).transition()
225+
.style('stroke-width', 3)
226+
})
227+
.on('mouseout', function(d, i) {
228+
taskTip.hide(d)
229+
d3.select(this).transition()
230+
.style("stroke-width", function(d) {return (d.run_id != undefined)? "2": "1"})
216231
})
217232
.attr("height", barHeight)
218233
.attr("width", function(d, i) {return barWidth - d.y;})
@@ -251,7 +266,7 @@
251266
.style("shape-rendering", function(d) {return (d.run_id != undefined)? "auto": "crispEdges"})
252267
.style("stroke-width", function(d) {return (d.run_id != undefined)? "2": "1"})
253268
.style("stroke-opacity", function(d) {return d.external_trigger ? "0": "1"})
254-
.attr("title", function(d){
269+
.on("mouseover", function(d){
255270
var s = "";
256271
if (d.task_id != undefined ) {
257272
s += "Task_id: " + escapeHtml(d.task_id) + "<br>";
@@ -271,20 +286,20 @@
271286
}
272287
s += "State: " + escapeHtml(d.state) + "<br>";
273288
}
274-
return s;
289+
taskTip.direction('n')
290+
taskTip.show(s, this)
291+
d3.select(this).transition()
292+
.style('stroke-width', 3)
293+
})
294+
.on('mouseout', function(d,i) {
295+
taskTip.hide(d)
296+
d3.select(this).transition()
297+
.style("stroke-width", function(d) {return (d.run_id != undefined)? "2": "1"})
275298
})
276299
.attr('x', function(d, i) {return (i*(square_size+square_spacing));})
277300
.attr('y', -square_size/2)
278301
.attr('width', 10)
279-
.attr('height', 10)
280-
.on('mouseover', function(d,i) {
281-
d3.select(this).transition()
282-
.style('stroke-width', 3)
283-
})
284-
.on('mouseout', function(d,i) {
285-
d3.select(this).transition()
286-
.style("stroke-width", function(d) {return (d.run_id != undefined)? "2": "1"})
287-
}) ;
302+
.attr('height', 10);
288303

289304

290305
// Transition nodes to their new position.
@@ -344,17 +359,6 @@
344359
$('#loading').remove()
345360
}
346361

347-
function set_tooltip(){
348-
$("rect.state").tooltip({
349-
html: true,
350-
container: "body",
351-
});
352-
$("circle.task").tooltip({
353-
html: true,
354-
container: "body",
355-
});
356-
357-
}
358362
function toggles(clicked_d) {
359363
// Collapse nodes with the same task id
360364
d3.selectAll("[task_id='" + clicked_d.name + "']").each(function(d){
@@ -374,7 +378,6 @@
374378
clicked_d.children = null;
375379
}
376380
update(clicked_d);
377-
set_tooltip();
378381
}
379382
// Toggle children on click.
380383
function click(d) {
@@ -387,10 +390,8 @@
387390
d._children = null;
388391
}
389392
update(d);
390-
set_tooltip();
391393
}
392394
}
393-
set_tooltip();
394395

395396
</script>
396397
{% endblock %}

0 commit comments

Comments
 (0)