-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathPaper.js
162 lines (150 loc) · 5.54 KB
/
Paper.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
import React from 'react';
import { observer } from 'mobx-react';
import {onPaperMouseEnter, onPaperMouseLeave, onPaperClick} from '../../eventhandlers/PaperEvents';
import HighlightableText from '../HighlightableText';
/**
* Paper component.
* Renders a Paper SVG element from a PaperModel.
* Also contains math for the actual coordinate of the Paper on the Chart.
* @type {<T extends IReactComponent>(clazz: T) => void | IReactComponent | (function({store?: *, paper?: *}))}
*/
const Paper =
observer(
({store, paper}) =>{
const {
zoomFactor,
translationVecX,
translationVecY,
svgWidth,
svgHeight,
searchString,
papersStore
} = store;
const {
orig_x,
orig_y,
orig_width,
orig_height,
zoomed,
selected,
authors : displayAuthors,
title,
clicked,
oa,
readers,
published_in,
year
} = paper;
// Actual coordinates and dimensions for the Paper is calculated from the
// orig_ prefixed values
// zoomFactor & translationVecX,Y are set by the zoom state
let x = zoomFactor * orig_x + translationVecX;
let y = zoomFactor * orig_y + translationVecY;
let w = zoomFactor * orig_width;
let h = zoomFactor * orig_height;
// Caculate enlarged paper dimensions so paper stays within svg
// when paper is hovered in zoomed-in visualization state
// TODO zoomed flag should be renamed hovered
while (
zoomed &&
((x + w) < svgWidth) &&
((y + h) < svgHeight) &&
(w < svgWidth*0.5) &&
(h < svgHeight*0.5)) {
w += 1;
h += 1.33;
}
// The messy part
// Creates SVG paths
// Adds css classes/other styles according to visualization state
// TODO extract parts of it to functions, define css classes instead of manually styling them here
let textClassName = 'highlightable';
const pathD = 'M ' + 0 + ' ' + 0 +
' h ' + (0.9*w) +
' l ' + (0.1*w) + ' ' + (0.1*h) +
' v ' + (0.9*h) +
' h ' + (-w) +
' v ' + (-h);
let pathClassName = clicked ? 'framed' : 'unframed';
let openAccessStyle = oa ? {height: (15) + "px", display: "block", marginBottom:"3px"} : {display: "none"};
let dogearPath = "M " + (0 + 0.9*w) + ' ' + 0 + " v " + (0.1*h) + " h " + (0.1*w);
let displayStyle = {display: "block", cursor : "default"};
let metadataStyle = {height: (0.75*h) + "px", width: (0.9*w) + "px"};
let readersDivStyle = {height: 0.24*h + "px", width: w + "px", marginBottom: "0px", marginTop: "0px"};
let citationsFontSize = "8px";
let translateString = "translate(" + x + " " + y + ")";
let highlightStrings = searchString.split(' ');
if (selected) {
textClassName = 'large highlightable';
displayStyle.cursor = "pointer";
metadataStyle.height = (h - 20) + "px";
readersDivStyle.height = 15 + "px";
readersDivStyle.marginBottom = '3px';
readersDivStyle.marginTop = '5px';
citationsFontSize = '11px';
} else {
if (papersStore.hasSelectedEntities) displayStyle.display = "none";
}
if (zoomed) {
textClassName = 'larger';
citationsFontSize = '11px';
}
return (
/* HTML starts here */
<g
onMouseEnter={onPaperMouseEnter.bind(this, store, paper)}
onMouseLeave={onPaperMouseLeave.bind(this, store, paper)}
onClick={onPaperClick.bind(this, store, paper)}
className="paper"
style={displayStyle}
transform={translateString}
>
<path
id="region"
d={pathD}
className={pathClassName}
>
</path>
<path
className="dogear"
d={dogearPath}>
</path>
<foreignObject
width={w}
height={h}
style={{"overflow":"hidden"}}
>
<div className="paper_holder">
<div className="metadata" style={metadataStyle}>
<div id="icons" style={openAccessStyle}>
<p id="open-access-logo" className={textClassName}></p>
</div>
<p id="title" className={textClassName}>
<HighlightableText highlightStrings={highlightStrings} value={title}/>
</p>
<p id="details" className={textClassName}>
<HighlightableText highlightStrings={highlightStrings} value={displayAuthors}/>
</p>
<p id="in" className={textClassName}>in
<span className={textClassName}>
<HighlightableText highlightStrings={highlightStrings} value={published_in}/>
<span className="pubyear">
(<HighlightableText highlightStrings={highlightStrings} value={year} />)
</span>
</span>
</p>
</div>
<div className="readers" style={readersDivStyle}>
<p id="readers" className={textClassName}>
<span id="num-readers">{readers}</span>
<span className="readers_entity" style={{fontSize: citationsFontSize}}> citations</span>
</p>
</div>
</div>
</foreignObject>
</g>
/* HTML ends here */
)
}
);
export default Paper;