Skip to content

Commit e3944ea

Browse files
committed
Link tidying
1 parent e27376f commit e3944ea

2 files changed

Lines changed: 15 additions & 12 deletions

File tree

components/Beeswarm.tsx

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,13 @@ export default function circleChart({ svgEl, rootSelection, scale, data = [] }:
2626

2727
// For force sim beeswarm example, see
2828
// http://bl.ocks.org/mbostock/6526445e2b44303eebf21da3b6627320
29-
const collisionForce = forceCollide<Datum & SimulationNodeDatum>().radius(d => d.radius + PADDING)
29+
const collisionForce = forceCollide<Datum & SimulationNodeDatum>().radius(
30+
(d) => d.radius + PADDING,
31+
)
3032
const sim = forceSimulation(data as Array<Datum & SimulationNodeDatum>)
3133
.force(
3234
'x',
33-
forceX((d: SimulationNodeDatum & Datum) => d.initialX)
35+
forceX((d: SimulationNodeDatum & Datum) => d.initialX),
3436
)
3537
.force('y', forceY(t).strength(1))
3638
.force('collide', collisionForce)
@@ -40,7 +42,7 @@ export default function circleChart({ svgEl, rootSelection, scale, data = [] }:
4042
const groups = rootSelection
4143
.append('g')
4244
.selectAll('g.item')
43-
.data(data.filter(d => t(d) > 0))
45+
.data(data.filter((d) => t(d) > 0))
4446
.enter()
4547
.append('g')
4648
.attr('class', 'item')
@@ -82,12 +84,12 @@ export default function circleChart({ svgEl, rootSelection, scale, data = [] }:
8284
.attr('class', 'tooltipLine')
8385
.attr('x1', 1)
8486
.attr('x2', 1)
85-
.attr('y1', function () {
87+
.attr('y1', function() {
8688
// @ts-ignore
8789
const circle = select(this.parentElement.firstChild)
8890
return -1 * (parseFloat(circle.attr('r')) + 3)
8991
})
90-
.attr('y2', function () {
92+
.attr('y2', function() {
9193
// @ts-ignore
9294
return parseFloat(select(this).attr('y1')) - 45
9395
})

components/Timeline.tsx

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { axisLeft, axisTop } from 'd3-axis'
33
import { scaleOrdinal, scaleTime } from 'd3-scale'
44
import { timeMonth, timeYear } from 'd3-time'
55
import { select } from 'd3-selection'
6+
67
import beeswarm from './Beeswarm'
78
import type { PinboardLink } from './types'
89

@@ -11,7 +12,7 @@ type Props = {
1112
}
1213

1314
const DAYS_OF_HISTORY = 365
14-
const START_DATE = new Date(new Date().getTime() - DAYS_OF_HISTORY * 24 * 3600 * 1000)
15+
const START_DATE = new Date(Date.now() - DAYS_OF_HISTORY * 24 * 3600 * 1000)
1516

1617
const CATEGORY_LANES = {
1718
typescript: -0.3,
@@ -25,7 +26,7 @@ const renderTimeline = async (svg: SVGSVGElement, links: Array<PinboardLink>) =>
2526
const { width, height, display } = getComputedStyle(svg)
2627
if (display === 'none') return // Don't do expensive rendering on mobile (svg is hidden)
2728

28-
const [svgWidth, svgHeight] = [parseInt(width), parseInt(height)]
29+
const [svgWidth, svgHeight] = [parseInt(width, 10), parseInt(height, 10)]
2930
const margin = { top: 30, right: 0, left: 0, bottom: 10 }
3031
const leavePadding = `translate(${svgWidth / 2}, ${margin.top})`
3132

@@ -58,8 +59,7 @@ const renderTimeline = async (svg: SVGSVGElement, links: Array<PinboardLink>) =>
5859
.call(makeAxis().ticks(nonZeroMonths) as any)
5960

6061
// Divide links into tag group "buckets":
61-
const getGroupForLink = (link: PinboardLink) =>
62-
TAGS.find((t) => link.t && link.t.includes(t)) || 'other'
62+
const getGroupForLink = (link: PinboardLink) => TAGS.find((t) => link?.t?.includes(t)) || 'other'
6363

6464
const linkChartData = links.map((l: PinboardLink) => {
6565
const group = getGroupForLink(l)
@@ -86,12 +86,13 @@ const LinksTimeline = ({ links }: Props) => {
8686
const timelineRef = useRef<SVGSVGElement | null>(null)
8787

8888
useEffect(() => {
89-
if (!timelineRef || !links) return
90-
renderTimeline(timelineRef.current!, links)
89+
if (!timelineRef.current || !links) return
90+
renderTimeline(timelineRef.current, links)
9191
}, [links])
9292

9393
return (
94-
<svg ref={timelineRef} className="timelineChart" width="350" height="1400">
94+
<svg ref={timelineRef} className="timelineChart" width="350" height="1000">
95+
<title>Links Timeline</title>
9596
<g className="categoryAxis"></g>
9697
<g className="yearAxis"></g>
9798
<g className="monthAxis"></g>

0 commit comments

Comments
 (0)