Skip to content

Commit ff2ee36

Browse files
committed
styled paper graph
1 parent 0c3c053 commit ff2ee36

File tree

4 files changed

+29
-32
lines changed

4 files changed

+29
-32
lines changed

app/tools/paper-graph/PaperDetail.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ export default function PaperDetail({ paper }: { paper: Paper | null }) {
125125
className="text-blue-600 text-sm mt-2"
126126
onClick={() => setVisibleReferenceCount(c => c + 10)}
127127
>
128-
Show 10 more
128+
More
129129
</button>
130130
)}
131131
</>
@@ -150,7 +150,7 @@ export default function PaperDetail({ paper }: { paper: Paper | null }) {
150150
className="text-blue-600 text-sm mt-2"
151151
onClick={() => setVisibleCitationCount(c => c + 10)}
152152
>
153-
Show 10 more
153+
More
154154
</button>
155155
)}
156156
</>

app/tools/paper-graph/PaperList.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,20 +10,20 @@ interface Props {
1010

1111
export default function PaperList({ nodes, hoveredNodeId, onHover, onClick }: Props) {
1212
return (
13-
<div className='border-gray-300'>
13+
<div className='h-[650px] overflow-auto shadow-gray-500 shadow-sm'>
1414
{nodes.map((node) => (
1515
<div
1616
key={node.id}
17-
className={`p-3 border border-b-gray-300
17+
className={`p-3
1818
${hoveredNodeId === node.id ? 'bg-gray-100' : 'bg-white'}
19-
rounded-lg shadow-sm cursor-pointer`}
19+
cursor-pointer border-b-gray-300 border-b-[1px]`}
2020
onMouseOver={() => onHover(node.id)}
2121
onMouseLeave={() => onHover(null)}
2222
onClick={() => onClick(node)}
2323
>
2424
<div className="text-sm">{node.title}</div>
2525
<div>
26-
{node.tags.map((tag) =>
26+
{(node.tags ?? []).map((tag) =>
2727
<span key={tag.name} style={{ backgroundColor: tag.color }} className='mt-2 mr-1 p-1 text-[10px] rounded-sm text-white opacity-60'>
2828
{tag.name}
2929
</span>)}

app/tools/paper-graph/Search.tsx

Lines changed: 14 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,7 @@ import useClickOutside from '@hooks/useClickOutside';
1414
type Suggestion = {
1515
id: string;
1616
title: string;
17-
abstract: string;
18-
year: string;
17+
authorsYear: string;
1918
};
2019

2120
export default function Search({
@@ -54,6 +53,7 @@ export default function Search({
5453

5554
setQuery('');
5655
setSuggestions([]);
56+
setModalOpen(false);
5757
setStatus('Fetching paper...');
5858
const paper = await fetchFromSemanticScholar(id);
5959

@@ -99,7 +99,7 @@ export default function Search({
9999

100100
return (
101101
<>
102-
<div className='search flex items-center justify-between'>
102+
<div className='search flex items-center justify-between w-full'>
103103
<button
104104
onClick={() => setModalOpen(true)}
105105
className="p-2 rounded-full bg-gray-100 hover:bg-gray-200"
@@ -113,25 +113,16 @@ export default function Search({
113113

114114

115115
{modalOpen && (
116-
<div className="fixed inset-0 z-50 bg-black/40 flex items-center justify-center">
117-
<div ref={ref} className="bg-white rounded-lg shadow-lg w-full max-w-md p-4 relative">
118-
<button
119-
onClick={() => setModalOpen(false)}
120-
className="absolute top-2 right-3 text-gray-400 hover:text-gray-600 text-xl"
121-
>
122-
×
123-
</button>
124-
116+
<div className="fixed inset-0 z-200 bg-black/40 flex items-center justify-center">
117+
<div ref={ref} className="bg-white rounded-lg shadow-lg w-[50%] p-4 relative">
125118
<h2 className="text-lg font-semibold mb-1">Search Paper</h2>
126-
<p className="text-sm text-gray-500 mb-3">{status}</p>
127-
128119
<input
129120
type="search"
130121
value={query}
131122
placeholder="Type paper title and press Enter..."
132123
onChange={(e) => setQuery(e.target.value)}
133124
onKeyDown={(e) => e.key === 'Enter' && handleSearch()}
134-
className="border p-2 w-full rounded mb-2"
125+
className="border p-2 w-full rounded mb-2 text-[20px]"
135126
autoFocus
136127
/>
137128

@@ -140,17 +131,22 @@ export default function Search({
140131
: suggestions.length === 0 && query.trim() !== '' ? (
141132
searched && <p className="text-sm text-gray-500 mt-2">No results</p>
142133
) : (
143-
<ul className="border max-h-60 overflow-auto rounded bg-white">
134+
<ul className=" max-h-60 overflow-auto">
144135
{suggestions.map((s) => (
145136
<li
146137
key={s.id}
147138
className={`p-2 ${knownIds.has(s.id)
148139
? 'bg-gray-100 text-gray-400 cursor-default'
149140
: 'hover:bg-blue-100 cursor-pointer'
150-
}`}
141+
} border-b-[1px] border-b-gray-200`}
151142
onClick={() => !knownIds.has(s.id) && handleSelect(s.id)}
152143
>
153-
{s.title}
144+
<div className='text-[14px]'>
145+
{s.title}
146+
</div>
147+
<div className='text-[12px]'>
148+
{s.authorsYear}
149+
</div>
154150
</li>
155151
))}
156152
</ul>

app/tools/paper-graph/page.tsx

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@ import { Loading } from '@components/atoms';
1010

1111
const MIN_SIZE = 5;
1212
const MAX_SIZE = 20;
13+
const GRAPH_WIDTH = 800;
14+
const GRAPH_HEIGHT = 700;
15+
1316

1417
export default function PaperGraph() {
1518
const svgRef = useRef<SVGSVGElement | null>(null);
@@ -23,9 +26,6 @@ export default function PaperGraph() {
2326
const svg = d3.select(svgRef.current);
2427
svg.selectAll('*').remove(); // Clear previous renders
2528

26-
const width = 800;
27-
const height = 600;
28-
2929
const citationCounts = data.nodes.map(d => d.citationCount ?? 0);
3030
const minCite = d3.min(citationCounts) ?? 0;
3131
const maxCite = d3.max(citationCounts) ?? 1;
@@ -52,11 +52,11 @@ export default function PaperGraph() {
5252
.alphaDecay(0.08)
5353
.force('link', d3.forceLink(data.links)
5454
.id((d: any) => d.id)
55-
.distance(80)
55+
.distance(150)
5656
.strength(0.7)
5757
)
5858
.force('charge', d3.forceManyBody().strength(-30))
59-
.force('center', d3.forceCenter(width / 2, height / 2));
59+
.force('center', d3.forceCenter(GRAPH_WIDTH / 2, GRAPH_HEIGHT / 2));
6060

6161
const link = zoomGroup
6262
.append('g')
@@ -85,7 +85,8 @@ export default function PaperGraph() {
8585
.on('start', (event: any, d: any) => {
8686
if (!event.active) {
8787
simulation.alphaTarget(0.3).restart();
88-
simulation.force('center', null);
88+
simulation.force('center', null)
89+
.force('charge', null)
8990
}
9091
d.fx = d.x;
9192
d.fy = d.y;
@@ -107,7 +108,7 @@ export default function PaperGraph() {
107108
.data(data.nodes)
108109
.join('text')
109110
.text(d => `${d.authors[0].name}, ${d.year}`)
110-
.attr('font-size', 10)
111+
.attr('font-size', 9)
111112
.attr('fill', '#000');
112113

113114
simulation.on('tick', () => {
@@ -187,7 +188,7 @@ export default function PaperGraph() {
187188
</div>
188189

189190
<div className='w-[75%]'>
190-
<svg ref={svgRef} width="100%" height={800}></svg>
191+
<svg ref={svgRef} width="100%" height={GRAPH_HEIGHT}></svg>
191192
</div>
192193

193194
<div

0 commit comments

Comments
 (0)