Skip to content

Commit

Permalink
add reroot callback to the treeview
Browse files Browse the repository at this point in the history
  • Loading branch information
bmesuere committed Sep 7, 2017
1 parent e28d3f9 commit 1a34f85
Show file tree
Hide file tree
Showing 8 changed files with 25 additions and 8 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ The options object is an optional parameter and allows to override the default v
* `nodeStrokeColor`: Function that returns a color to use as stroke color. Is called with a node as parameter. By default, the node color is used.
* `linkStrokeColor`: Function that returns a color to use as link color between two nodes. Is called with an object containing a `source` and `target` node as parameter. By default, the target node color is used.
* `countAccessor` : Function that returns the value associated with the node. Is called with a node as parameter. By default, the value of `node.data.count` is used.
* `rerootCallback`: Function that gets called after every "reroot" (rightClick) of the visualization. Is called with a node as parameter. By default, this is empty.

## Treemap

Expand Down
7 changes: 6 additions & 1 deletion dist/unipept-visualizations.es5.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/unipept-visualizations.es5.js.map

Large diffs are not rendered by default.

7 changes: 6 additions & 1 deletion dist/unipept-visualizations.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/unipept-visualizations.js.map

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions dist/unipept-visualizations.min.js

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions examples/treeview-taxonomy.html
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
$("#d3TreeView").treeview(data, {
width: 900,
height: 600,
rerootCallback: d => {console.log(d.name);},
getTooltip: function(d) {
let numberFormat = d3.format(",d");
return "<b>" + d.name + "</b> (" + d.data.rank + ")<br/>" + numberFormat(!d.data.self_count ? "0" : d.data.self_count) + (d.data.self_count && d.data.self_count === 1 ? " sequence" : " sequences") +
Expand Down
9 changes: 7 additions & 2 deletions src/treeview/treeview.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ export default function TreeView(element, data, options = {}) {
maxNodeSize: 105,

countAccessor: d => d.data.count,
rerootCallback: undefined,

colors: d => COLOR_SCALE(d.name),
nodeFillColor: nodeFillColor,
Expand Down Expand Up @@ -310,13 +311,13 @@ export default function TreeView(element, data, options = {}) {
}
}

// Toggle children on click.
// Toggle children on click.
function click(d) {
if (!settings.enableExpandOnClick) {
return;
}

// check if click is triggered by panning on a node
// check if click is triggered by panning on a node
if (d3.event.defaultPrevented) {
return;
}
Expand Down Expand Up @@ -361,6 +362,10 @@ export default function TreeView(element, data, options = {}) {
}
update(d);
centerNode(d);

if (settings.rerootCallback) {
settings.rerootCallback.call(null, d);
}
}

// Center a node
Expand Down

0 comments on commit 1a34f85

Please sign in to comment.