Skip to content

Commit

Permalink
Color styling improvements to tips and branches
Browse files Browse the repository at this point in the history
  • Loading branch information
trvrb committed Feb 3, 2017
1 parent ee7e45b commit 6c885e7
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 22 deletions.
6 changes: 3 additions & 3 deletions src/components/app.js
Expand Up @@ -31,7 +31,7 @@ import getColorScale from "../util/getColorScale";
import { parseGenotype, getGenotype } from "../util/getGenotype";
import * as globals from "../util/globals";
import { defaultDateRange, defaultLayout,
defaultDistanceMeasure, defaultColorBy } from "../util/globals";
defaultDistanceMeasure, defaultColorBy, tipRadius } from "../util/globals";
import Sidebar from "react-sidebar";
import moment from 'moment';

Expand Down Expand Up @@ -346,7 +346,7 @@ class App extends React.Component {
? cScale.legendBoundsMap : false;
return this.props.tree.nodes.map((d) => this.determineLegendMatch(selItem, d, legendMap, cScale) ? 6 : 3);
} else if (this.props.tree.nodes) {
return this.props.tree.nodes.map((d) => 3);
return this.props.tree.nodes.map((d) => tipRadius);
} else {
return null;
}
Expand Down Expand Up @@ -410,7 +410,7 @@ class App extends React.Component {
sidebar={this.state.sidebarOpen || this.state.sidebarDocked}
changeRoute={this.changeRoute.bind(this)}
location={this.state.location}
router={this.props.router}
router={this.props.router}
/>
</Background>
</Sidebar>
Expand Down
33 changes: 25 additions & 8 deletions src/components/tree/treeView.js
Expand Up @@ -100,16 +100,18 @@ class TreeView extends React.Component {

/* if we have a tree and we have new props, figure out what we need to update */
if (tree) {
const attrToUpdate = {};
const styleToUpdate = {};

/* update tips */
let attrToUpdate = {};
let styleToUpdate = {};

/* fill has changed */
if (nextProps.nodeColor && arrayInEquality(nextProps.nodeColor, this.props.nodeColor)) {
styleToUpdate['fill'] = nextProps.nodeColor;
tree.updateStyleOrAttributeArray(".branch", "stroke", nextProps.nodeColor, fastTransitionDuration, "style");
styleToUpdate['stroke'] = nextProps.nodeColor.map((d) => {
d3.rgb(d).darker(0.7)
styleToUpdate['fill'] = nextProps.nodeColor.map((col) => {
return d3.rgb(col).brighter([0.65]).toString();
});
tree.updateStyleOrAttributeArray(".branch", "stroke", nextProps.nodeColor, fastTransitionDuration, "style");
styleToUpdate['stroke'] = nextProps.nodeColor;
}
/* tip radius has changed */
if (nextProps.tipRadii && arrayInEquality(nextProps.tipRadii, this.props.tipRadii)) {
Expand All @@ -120,11 +122,26 @@ class TreeView extends React.Component {
// console.log("updateVisibility");
styleToUpdate['visibility'] = nextProps.tipVisibility;
}

/* update style changes */
/* implement style changes */
if (Object.keys(attrToUpdate).length || Object.keys(styleToUpdate).length) {
tree.updateMultipleArray(".tip", attrToUpdate, styleToUpdate, fastTransitionDuration);
}

/* update branches */
attrToUpdate = {};
styleToUpdate = {};

if (nextProps.nodeColor && arrayInEquality(nextProps.nodeColor, this.props.nodeColor)) {
styleToUpdate['stroke'] = nextProps.nodeColor.map((col) => {
var modCol = d3.interpolateRgb(col, "#BBB")(0.6);
return d3.rgb(modCol).toString();
});
}
/* implement style changes */
if (Object.keys(attrToUpdate).length || Object.keys(styleToUpdate).length) {
tree.updateMultipleArray(".branch", attrToUpdate, styleToUpdate, fastTransitionDuration);
}

/* swap layouts */
if (this.props.layout !== nextProps.layout) {
tree.updateLayout(nextProps.layout, slowTransitionDuration);
Expand Down
23 changes: 12 additions & 11 deletions src/util/phyloTree.js
Expand Up @@ -143,7 +143,7 @@ PhyloTree.prototype.setDefaults = function () {
branchStrokeWidth: 2,
tipStroke: "#AAA",
tipFill: "#CCC",
tipStrokeWidth: 2,
tipStrokeWidth: 1,
tipRadius: 4,
};
};
Expand Down Expand Up @@ -720,6 +720,16 @@ PhyloTree.prototype.drawBranches = function() {
.attr("d", function(d) {
return d.branch;
})
.style("stroke", function(d) {
return d.stroke || params.branchStroke;
})
.style("stroke-linecap", "round")
.style("stroke-width", function(d) {
return d.strokeWidth || params.branchStrokeWidth;
})
.style("fill", "none")
.style("cursor", "pointer")
.style("pointer-events", "auto")
.on("mouseover", (d) => {
this.callbacks.onBranchHover(d)
})
Expand All @@ -728,16 +738,7 @@ PhyloTree.prototype.drawBranches = function() {
})
.on("click", (d) => {
this.callbacks.onBranchClick(d)
})
.style("pointer-events", "auto")
.style("stroke", function(d) {
return d.stroke || params.branchStroke;
})
.style("fill", "none")
.style("stroke-width", function(d) {
return d.strokeWidth || params.branchStrokeWidth;
})
.style("cursor", "pointer");
});
};


Expand Down

0 comments on commit 6c885e7

Please sign in to comment.