Skip to content

Commit ad3d830

Browse files
committed
fix: papers sizes depending on the citations count
1 parent 874db5e commit ad3d830

3 files changed

Lines changed: 21 additions & 14 deletions

File tree

vis/js/dataprocessing/managers/DataManager.ts

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
import $ from "jquery";
44
import d3 from "d3";
5-
65
import {
76
getDiameterScale,
87
getInitialCoordsScale,
@@ -19,6 +18,7 @@ import {
1918
getVisibleMetric,
2019
isOpenAccess,
2120
parseCoordinate,
21+
getValueOrZero,
2222
} from "../../utils/data";
2323
import { transformData } from "../../utils/streamgraph";
2424

@@ -250,14 +250,8 @@ class DataManager {
250250
paper.num_readers = 0;
251251
paper.internal_readers = 1;
252252

253-
// ? should we use numb_readers in some cases?
254-
function parseNumber(value, defaultValue = 0) {
255-
const num = Number(value);
256-
return isNaN(num) ? defaultValue : num;
257-
}
258-
259-
paper.num_readers = parseNumber(paper.readers);
260-
paper.readers = parseNumber(paper.readers);
253+
paper.num_readers = getValueOrZero(paper.readers);
254+
paper.readers = getValueOrZero(paper.readers);
261255
paper.tweets = getVisibleMetric(paper, "cited_by_tweeters_count");
262256
paper.citations = getVisibleMetric(paper, "citation_count");
263257
// ? should we use readers.mendeley in some cases?

vis/js/reducers/data.ts

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,12 @@
11
import d3 from "d3";
22

33
import { getDiameterScale, getResizedScale } from "../utils/scale";
4+
import { getValueOrZero } from "../utils/data";
45

5-
const data = (state = { list: [], options: {}, size: null } as any, action: any) => {
6+
const data = (
7+
state = { list: [], options: {}, size: null } as any,
8+
action: any
9+
) => {
610
if (action.canceled) {
711
return state;
812
}
@@ -48,19 +52,23 @@ const data = (state = { list: [], options: {}, size: null } as any, action: any)
4852

4953
export default data;
5054

51-
52-
const resizePapers = (papers: any[], currentSize: number, newSize: number, options: any) => {
55+
const resizePapers = (
56+
papers: any[],
57+
currentSize: number,
58+
newSize: number,
59+
options: any
60+
) => {
5361
const resizedPapers = papers.slice(0);
5462

5563
let coordsScale = getResizedScale(currentSize, newSize);
5664

57-
let diameters = resizedPapers.map((e) => e.internal_readers);
65+
let diameters = resizedPapers.map((e) => getValueOrZero(e.citation_count));
5866
let dScale = getDiameterScale(d3.extent(diameters), newSize, options);
5967

6068
resizedPapers.forEach((paper: any) => {
6169
paper.x = coordsScale(paper.x);
6270
paper.y = coordsScale(paper.y);
63-
paper.diameter = dScale(paper.internal_readers);
71+
paper.diameter = dScale(getValueOrZero(paper.citation_count));
6472
paper.width =
6573
options.paperWidthFactor * Math.sqrt(Math.pow(paper.diameter, 2) / 2.6);
6674
paper.height =

vis/js/utils/data.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -549,3 +549,8 @@ export const queryConcatenator = (terms) => {
549549
let concatenatedQueries = filtered_terms.join(" and ");
550550
return concatenatedQueries;
551551
};
552+
553+
export const getValueOrZero = (value: unknown): number => {
554+
const transformedValue = Number(value);
555+
return isNaN(transformedValue) ? 0 : transformedValue;
556+
};

0 commit comments

Comments
 (0)