Commit c3e608ac authored by Aron Fiechter's avatar Aron Fiechter
Browse files

Refactor setting polygon color callback into setPolygonColor method

The color is either the one set bu the node or black if the entity is not in the selected year range.
parent 83af326b
......@@ -51,6 +51,7 @@ class Voronoi extends React.Component {
this.goDownAll = this.goDownAll.bind(this);
this.goUp = this.goUp.bind(this);
this.findChildrenOf = this.findChildrenOf.bind(this);
this.setPolygonColor = this.setPolygonColor.bind(this);
this.isEntityInYearRange = this.isEntityInYearRange.bind(this);
}
......@@ -161,13 +162,7 @@ class Voronoi extends React.Component {
.attr('stroke-width', function (d) {
return strokeScale(d.level);
})
.attr('fill', function (d) {
if (!d.color) {
return;
}
const { red, green, blue } = d.color.rgb_components;
return `rgb(${red},${green},${blue})`;
})
.attr('fill', this.setPolygonColor)
// On mouseover, set node data in Redux state (to be shown in another component)
.on('mouseover', (d) => {
this.props.setHoverSite(d.name);
......@@ -345,13 +340,7 @@ class Voronoi extends React.Component {
return strokeScale(d.level);
})
.style('opacity', 0)
.attr('fill', function (d) {
if (!d.color) {
return;
}
const { red, green, blue } = d.color.rgb_components;
return `rgb(${red},${green},${blue})`;
})
.attr('fill', this.setPolygonColor)
// On mouseover, set node data in Redux state (to be shown in another component)
.on('mouseover', (d) => {
this.props.setHoverSite(d.name);
......@@ -433,6 +422,24 @@ class Voronoi extends React.Component {
});
}
/**
* Given an entity, extract its colors and
* @param d
* @returns {string}
*/
setPolygonColor(d) {
if (!d.color) {
return;
}
const isInRange = this.isEntityInYearRange(d);
if (isInRange) {
const { red, green, blue } = d.color.rgb_components;
return `rgb(${red},${green},${blue})`;
} else {
return 'rgba(0,0,0, 1)';
}
}
/**
* Whether an entity is in the selected year range.
* At least one of the entity years must fall in the year range.
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment