-
Notifications
You must be signed in to change notification settings - Fork 470
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: make peers page first render fast (#808)
* feat: make peers page first render fast The peers page was taking >2s to load on my machine. Turns out the d3 generated svg of the world map was around 3MiB This PR makes extracts the world map to a static svg that is used as a background image. It's ~79KiB / ~20KiB gzippped and cached as a static resource rather than generated by js. The peers page now loads faster than all the others. There is still too much fan spinning caused by the geo look ups, but this is an improvement. * fix: don't repeat the map on larger screens * fix: center peers map on large screens License: MIT Signed-off-by: Oli Evans <oli@tableflip.io>
- Loading branch information
Showing
5 changed files
with
65 additions
and
64 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
import * as d3 from 'd3' | ||
import * as topojson from 'topojson' | ||
import ReactFauxDOM from 'react-faux-dom' | ||
import worldData from './world.json' | ||
|
||
// Earth! It's complicated, so try not to re-render so much | ||
const Map = ({ width, height, path }) => { | ||
// https://github.com/d3/d3-geo/blob/master/README.md#geoGraticule | ||
const graticule = d3.geoGraticule() | ||
|
||
const el = d3.select(ReactFauxDOM.createElement('svg')) | ||
.attr('width', width) | ||
.attr('height', height) | ||
|
||
// Fill Pattern | ||
el.append('defs') | ||
.append('pattern') | ||
.attr('id', 'gridpattern') | ||
.attr('x', 0) | ||
.attr('y', 0) | ||
.attr('width', 5) | ||
.attr('height', 5) | ||
.attr('patternUnits', 'userSpaceOnUse') | ||
.append('circle') | ||
.attr('cx', 3) | ||
.attr('cy', 3) | ||
.attr('r', 1) | ||
.attr('fill', '#AAA') | ||
.attr('stroke', '#DDD') | ||
|
||
el.append('path') | ||
.datum(graticule) | ||
.attr('class', 'graticule') | ||
.attr('d', path) | ||
|
||
el.insert('path', '.graticule') | ||
.datum(topojson.feature(worldData, worldData.objects.land)) | ||
.attr('d', path) | ||
.attr('fill', 'url(#gridpattern)') | ||
|
||
el.insert('path', '.graticule') | ||
.datum(topojson.mesh( | ||
worldData, | ||
worldData.objects.countries, | ||
(a, b) => a !== b | ||
)) | ||
.attr('d', path) | ||
.attr('fill', 'none') | ||
.attr('stroke', 'none') | ||
|
||
return el.node().toReact() | ||
} | ||
|
||
export default Map |
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters