-
Notifications
You must be signed in to change notification settings - Fork 23
/
demo-tippy.html
146 lines (113 loc) · 3.05 KB
/
demo-tippy.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
<!DOCTYPE>
<html>
<head>
<title>cytoscape-popper.js tippy demo</title>
<meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1, maximum-scale=1">
<script src="https://unpkg.com/cytoscape/dist/cytoscape.min.js"></script>
<!-- for testing with local version of cytoscape.js -->
<!--<script src="../cytoscape.js/build/cytoscape.js"></script>-->
<script src="https://unpkg.com/popper.js@1.16.0/dist/umd/popper.js"></script>
<script src="cytoscape-popper.js"></script>
<script src="https://unpkg.com/tippy.js@5.1.3/dist/tippy-bundle.iife.min.js"></script>
<link rel="stylesheet" href="https://unpkg.com/tippy.js@5.1.3/dist/tippy.css" />
<style>
body {
font-family: helvetica neue, helvetica, liberation sans, arial, sans-serif;
font-size: 14px
}
#cy {
position: absolute;
left: 0;
top: 0;
bottom: 0;
right: 0;
z-index: 1;
}
h1 {
opacity: 0.5;
font-size: 1em;
font-weight: bold;
}
/* makes sticky faster; disable if you want animated tippies */
.tippy-popper {
transition: none !important;
}
</style>
<script>
document.addEventListener('DOMContentLoaded', function () {
var cy = window.cy = cytoscape({
container: document.getElementById('cy'),
style: [
{
selector: 'node',
style: {
'content': 'data(id)'
}
},
{
selector: 'edge',
style: {
'curve-style': 'bezier',
'target-arrow-shape': 'triangle'
}
}
],
elements: {
nodes: [
{ data: { id: 'a' } },
{ data: { id: 'b' } }
],
edges: [
{ data: { id: 'ab', source: 'a', target: 'b' } }
]
},
layout: {
name: 'grid'
}
});
var a = cy.getElementById('a');
var b = cy.getElementById('b');
var ab = cy.getElementById('ab');
var makeTippy = function(node, text){
var ref = node.popperRef();
// unfortunately, a dummy element must be passed
// as tippy only accepts a dom element as the target
// https://github.com/atomiks/tippyjs/issues/661
var dummyDomEle = document.createElement('div');
var tip = tippy( dummyDomEle, {
onCreate: function(instance){ // mandatory
// patch the tippy's popper reference so positioning works
// https://atomiks.github.io/tippyjs/misc/#custom-position
instance.popperInstance.reference = ref;
},
lazy: false, // mandatory
trigger: 'manual', // mandatory
// dom element inside the tippy:
content: function(){ // function can be better for performance
var div = document.createElement('div');
div.innerHTML = text;
return div;
},
// your own preferences:
arrow: true,
placement: 'bottom',
hideOnClick: false,
multiple: true,
sticky: true
} );
return tip;
};
var tippyA = makeTippy(a, 'foo');
tippyA.show();
var tippyB = makeTippy(b, 'bar');
tippyB.show();
var tippyAB = makeTippy(ab, 'baz');
tippyAB.show();
});
</script>
</head>
<body>
<h1>cytoscape-popper tippy demo</h1>
<div id="cy"></div>
</body>
</html>