Skip to content

Commit 3296dcf

Browse files
Renaud PawlakRenaud Pawlak
authored andcommitted
support for async popovers
1 parent 35abaed commit 3296dcf

5 files changed

Lines changed: 33 additions & 10 deletions

File tree

components/bubbletree/arnd_bubbletree.ts

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ interface BubbleTreeConfiguration<D extends Data> {
9494
/**
9595
* A function to create a popover on a node. It can return undefined when no popover needs to be shown.
9696
*/
97-
nodePopover?: (node: d3.pack.Node<D>) => { title?: string, content: string };
97+
nodePopover?: (node: d3.pack.Node<D>, callback: (popover: { title?: string, content: string }) => void) => void;
9898
}
9999

100100
/**
@@ -152,12 +152,23 @@ class BubbleTree<D extends Data> {
152152
.style("fill", d => this.nodeColor(d));
153153

154154
if (this.config.nodePopover != null) {
155+
let self = this;
155156
this.circle
156157
.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)
158+
.filter(function(d) {
159+
self.config.nodePopover(d, popover => {
160+
if (popover && popover.content) {
161+
this.setAttribute("data-content", popover.content);
162+
}
163+
if (popover && popover.title) {
164+
this.setAttribute("data-original-title", popover.title);
165+
}
166+
});
167+
return true;
168+
})
159169
.attr("rel", "popover")
160170
.attr("data-trigger", "hover");
171+
161172
(<any>$('.popover-node')).popover();
162173
}
163174

dist/visualization-components-bundle.d.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,10 +78,10 @@ interface BubbleTreeConfiguration<D extends Data> {
7878
/**
7979
* A function to create a popover on a node. It can return undefined when no popover needs to be shown.
8080
*/
81-
nodePopover?: (node: d3.pack.Node<D>) => {
81+
nodePopover?: (node: d3.pack.Node<D>, callback: (popover: {
8282
title?: string;
8383
content: string;
84-
};
84+
}) => void) => void;
8585
}
8686
/**
8787
* An interactive D3.js component to render trees as an SVG flat bubble tree.

dist/visualization-components-bundle.js

Lines changed: 13 additions & 2 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: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -151,8 +151,9 @@
151151
},
152152
selectOnClick: true,
153153
showRoot: true,
154-
nodePopover: function(d) {
155-
return { title: "Node", content: d.data.name };
154+
nodePopover: function(d, callback) {
155+
console.info(d);
156+
callback({ title: "Node", content: d.data.name });
156157
}
157158
});
158159

0 commit comments

Comments
 (0)