Commit 28c1e06a authored by Dorian Goepp's avatar Dorian Goepp
Browse files

Little refactor for mear readability

parent a962bcef
......@@ -87,6 +87,21 @@ class InteractionTrace extends Component {
}
}
/**
* Ensure that there is at least minXWidth between each interaction (on x axis). If we have too much data, filter it
* and keep only the latest data that can be displayed.
* @param {any} data The data for the trace
* @return {xDomain, domainFilter} the first is an array of the first and last index in data to be displayed;
* the second is a function that will return true iff the datum we give it belongs to the domain.
*/
filter(data) {
const maxNumberOfInteractions = Math.floor(this.xLayout.width(2) / this.minXWidth()) || 0;
const highestId = d3.max(data, (datum => datum.id)) || 0;
const xDomain = [highestId-maxNumberOfInteractions, highestId];
const domainFilter = (datum) => (datum.id >= xDomain[0] && datum.id <= xDomain[1]);
return {xDomain: xDomain, domainFilter: domainFilter}
}
render() {
let data = this.props.data;
......@@ -100,13 +115,7 @@ class InteractionTrace extends Component {
this.yLayout.updateCellValue(4, this.em * (this.nbPrimitiveActions + 1));
}
// Ensure that there is at least minXWidth around each interaction (on x axis). If we have too much data,
// filter it and keep only the latest data that can be displayed.
const maxNumberOfInteractions = Math.floor(this.xLayout.width(2) / this.minXWidth()) || 0;
const highestId = d3.max(data, (datum => datum.id)) || 0;
const xDomain = [highestId-maxNumberOfInteractions, highestId];
const domainFilter = (datum) => (datum.id >= xDomain[0] && datum.id <= xDomain[1]);
const {xDomain, domainFilter} = this.filter(data);
data = data.filter(domainFilter);
// Scales for all the figure elements, including the plots
......
Markdown is supported
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