Skip to content

Commit

Permalink
Merge pull request #2198 from romanchyla/one-dot-one-paper
Browse files Browse the repository at this point in the history
One dot one paper policy
  • Loading branch information
thostetler committed Aug 27, 2021
2 parents 06de672 + 8048afc commit 7b710c4
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 6 deletions.
40 changes: 36 additions & 4 deletions src/js/wraps/graph_tabs.js
Original file line number Diff line number Diff line change
Expand Up @@ -126,9 +126,25 @@ define([
}

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

// map counts into coordinates for graph
const finalData = counts.map(({ val: y }, x) => ({ x, y }));
const finalData = [];
let xCounter = 0;
counts.some((item) => {
xCounter += item.count;
// 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;
}
return false;
});

const statsCount = apiResponse.toJSON().stats
? FormatMixin.formatNum(
Expand All @@ -143,7 +159,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 @@ -177,9 +193,25 @@ define([
}

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

// map counts into coordinates for graph
const finalData = counts.map(({ val: y }, x) => ({ x, y }));
const finalData = [];
let xCounter = 0;
counts.some((item) => {
xCounter += item.count;
// 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;
}
return false;
});

const statsCount = apiResponse.toJSON().stats
? FormatMixin.formatNum(
Expand All @@ -194,7 +226,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 7b710c4

Please sign in to comment.