Skip to content

Commit 35abaed

Browse files
Renaud PawlakRenaud Pawlak
authored andcommitted
add node popover feature
1 parent 9e53beb commit 35abaed

5 files changed

Lines changed: 48 additions & 2 deletions

File tree

components/bubbletree/arnd_bubbletree.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,10 @@ interface BubbleTreeConfiguration<D extends Data> {
9191
* On built callback.
9292
*/
9393
onBuilt?: (bubbleTree: BubbleTree<D>) => any;
94+
/**
95+
* A function to create a popover on a node. It can return undefined when no popover needs to be shown.
96+
*/
97+
nodePopover?: (node: d3.pack.Node<D>) => { title?: string, content: string };
9498
}
9599

96100
/**
@@ -147,6 +151,16 @@ class BubbleTree<D extends Data> {
147151
.style("stroke", "#B0B0B0")
148152
.style("fill", d => this.nodeColor(d));
149153

154+
if (this.config.nodePopover != null) {
155+
this.circle
156+
.classed("popover-node", true)
157+
.attr("data-content", d => this.config.nodePopover(d).content)
158+
.attr("data-original-title", d => this.config.nodePopover(d).title)
159+
.attr("rel", "popover")
160+
.attr("data-trigger", "hover");
161+
(<any>$('.popover-node')).popover();
162+
}
163+
150164
let handlers = {
151165
"click": (d: d3.pack.Node<D>) => {
152166
if (!d.children) {

dist/visualization-components-bundle.d.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,13 @@ interface BubbleTreeConfiguration<D extends Data> {
7575
* On built callback.
7676
*/
7777
onBuilt?: (bubbleTree: BubbleTree<D>) => any;
78+
/**
79+
* A function to create a popover on a node. It can return undefined when no popover needs to be shown.
80+
*/
81+
nodePopover?: (node: d3.pack.Node<D>) => {
82+
title?: string;
83+
content: string;
84+
};
7885
}
7986
/**
8087
* An interactive D3.js component to render trees as an SVG flat bubble tree.

dist/visualization-components-bundle.js

Lines changed: 9 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/visualization-components-bundle.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

test/index.html

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,19 @@
3131
<div id="list" style="max-height:300px;overflow-y:scroll">
3232
</div>
3333

34+
<nav>
35+
<div class="nav nav-tabs" id="nav-tab" role="tablist">
36+
<a class="nav-item nav-link active" id="nav-home-tab" data-toggle="tab" href="#nav-home" role="tab" aria-controls="nav-home" aria-selected="true">Home</a>
37+
<a class="nav-item nav-link" id="nav-profile-tab" data-toggle="tab" href="#nav-profile" role="tab" aria-controls="nav-profile" aria-selected="false">Profile</a>
38+
<a class="nav-item nav-link" id="nav-contact-tab" data-toggle="tab" href="#nav-contact" role="tab" aria-controls="nav-contact" aria-selected="false">Contact</a>
39+
</div>
40+
</nav>
41+
<div class="tab-content" id="nav-tabContent">
42+
<div class="tab-pane fade show active" id="nav-home" role="tabpanel" aria-labelledby="nav-home-tab">ABC</div>
43+
<div class="tab-pane fade" id="nav-profile" role="tabpanel" aria-labelledby="nav-profile-tab">DEF</div>
44+
<div class="tab-pane fade" id="nav-contact" role="tabpanel" aria-labelledby="nav-contact-tab">GFHI</div>
45+
</div>
46+
3447
<script src="../lib/d3.v4.min.js"></script>
3548
<script src="../lib/jquery-1.12.4.js"></script>
3649
<script src="../lib/bootstrap.bundle.min.js"></script>
@@ -137,7 +150,10 @@
137150
"dblclick": function(d) { console.info("dblclick"); }
138151
},
139152
selectOnClick: true,
140-
showRoot: true
153+
showRoot: true,
154+
nodePopover: function(d) {
155+
return { title: "Node", content: d.data.name };
156+
}
141157
});
142158

143159
var t = new Table();

0 commit comments

Comments
 (0)