Skip to content

Commit

Permalink
Updated BBB graphs to render one dot per paper/read
Browse files Browse the repository at this point in the history
  • Loading branch information
romanchyla committed Aug 27, 2021
1 parent 8465e8c commit 6714197
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 8 deletions.
24 changes: 18 additions & 6 deletions src/js/wraps/graph_tabs.js
Original file line number Diff line number Diff line change
Expand Up @@ -126,13 +126,19 @@ define([
}

const counts = apiResponse.get('facets.citation_count.buckets');
const maxDataPoints = 2000;

// map counts into coordinates for graph
const finalData = [];
var xCounter = 0;
counts.forEach(function(item, index) {
counts.some(function(item, index) {
xCounter = xCounter + item.count;
finalData.push({y: item.val, x: xCounter});
// one dot per paper (this way we'll only plot the top ranked X - fraction of results)
while(xCounter > finalData.length && finalData.length < maxDataPoints) {
finalData.push({y: item.val, x: finalData.length + 1});
}
if (finalData.length > maxDataPoints)
return true;
})

const statsCount = apiResponse.toJSON().stats
Expand All @@ -148,7 +154,7 @@ define([
this.model.set({
graphData: finalData,
statsCount: statsCount,
statsDescription: 'total number of citations',
statsDescription: finalData.length + ' top ranked citations of',
});
},
});
Expand Down Expand Up @@ -182,13 +188,19 @@ define([
}

const counts = apiResponse.get('facets.read_count.buckets');
const maxDataPoints = 2000;

// map counts into coordinates for graph
const finalData = [];
var xCounter = 0;
counts.forEach(function(item, index) {
counts.some(function(item, index) {
xCounter = xCounter + item.count;
finalData.push({y: item.val, x: xCounter});
// one dot per paper (this way we'll only plot the top ranked X - fraction of results)
while(xCounter > finalData.length && finalData.length < maxDataPoints) {
finalData.push({y: item.val, x: finalData.length + 1});
}
if (finalData.length > maxDataPoints)
return true;
})

const statsCount = apiResponse.toJSON().stats
Expand All @@ -204,7 +216,7 @@ define([
this.model.set({
graphData: finalData,
statsCount: statsCount,
statsDescription: 'total recent (90 day) reads',
statsDescription: finalData.length + ' top ranked reads of',
});
},
});
Expand Down
2 changes: 1 addition & 1 deletion test/mocha/js/widgets/citation_graph_facet_widget.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ define([
','
);
// where y is # citations
var expectedResults = '0,23,1,8,2,6,3,5,4,4,5,3,6,2,7,1,8,0';
var expectedResults = '23,1,8,2,6,3,6,4,6,5,6,6,5,7,4,8,4,9,4,10,3,11,3,12,3,13,3,14,2,15,2,16,2,17,1,18,1,19,1,20,1,21,0,22,0,23,0,24,0,25,0,26,0,27,0,28,0,29,0,30,0,31,0,32,0,33,0,34,0,35,0,36,0,37,0,38,0,39,0,40,0,41,0,42,0,43,0,44,0,45,0,46,0,47,0,48';
expect(graphData).to.eql(expectedResults);
done();
});
Expand Down
2 changes: 1 addition & 1 deletion test/mocha/js/widgets/reads_graph_facet_widget.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ define([
','
);
var expectedResults =
'0,18,1,14,2,11,3,10,4,9,5,7,6,6,7,5,8,4,9,3,10,2,11,0';
'18,1,14,2,11,3,10,4,9,5,7,6,6,7,5,8,5,9,5,10,5,11,4,12,4,13,3,14,2,15,2,16,2,17,0,18,0,19,0,20,0,21,0,22,0,23,0,24,0,25,0,26,0,27,0,28,0,29,0,30,0,31,0,32,0,33,0,34,0,35,0,36,0,37,0,38,0,39,0,40,0,41,0,42,0,43,0,44,0,45,0,46,0,47,0,48';
expect(graphData).to.eql(expectedResults);
done();
});
Expand Down

0 comments on commit 6714197

Please sign in to comment.