From 28c1e06a22f4f377e3c66541bcb03a5111bfc0f6 Mon Sep 17 00:00:00 2001 From: Dorian Goepp <dorian.goepp@gmail.com> Date: Fri, 5 Apr 2019 11:36:41 +0200 Subject: [PATCH] Little refactor for mear readability --- src/InteractionTrace/InteractionTrace.js | 23 ++++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-) diff --git a/src/InteractionTrace/InteractionTrace.js b/src/InteractionTrace/InteractionTrace.js index 6feccb9..65b3eb2 100644 --- a/src/InteractionTrace/InteractionTrace.js +++ b/src/InteractionTrace/InteractionTrace.js @@ -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 -- GitLab