Skip to content

Instantly share code, notes, and snippets.

View nautilytics's full-sized avatar

Nautilytics nautilytics

View GitHub Profile
@nautilytics
nautilytics / d3-axis-angular.html
Created January 2, 2020 15:49
An example of creating an axis using Angular
<svg:g class="axis--x"></svg:g>
@nautilytics
nautilytics / d3-axis.js
Created January 2, 2020 15:50
An example of creating an axis using D3
const xAxis = d3.select(‘svg’)
.append(‘g’)
.attr(‘class’, ‘axis--x’)
.call(d3.axisBottom(xScale));
@nautilytics
nautilytics / d3-transition-react.js
Last active January 2, 2020 15:58
Using d3-transition with React
import {select as d3_select} from 'd3-selection';
...
const markerRef = useRef();
useEffect(() => {
d3_select(markerRef.current)
.transition()
.duration(1000)
.attr('cx', item.x)
.attr('cy', item.y);
@nautilytics
nautilytics / d3-transition.js
Created January 2, 2020 15:56
Using d3.transition.
const markers = d3.selectAll(‘.marker’)
.data(data, d => d.id)
.enter()
.append(‘circle’)
.attr(‘class’, ‘marker’)
.attr(‘r’, 7.5)
.transition()
.duration(1000)
.attr(‘cx’, d => d.x)
.attr(‘cy’, d => d.y);
@nautilytics
nautilytics / d3-transition-angular.html
Created January 2, 2020 16:00
Using d3.transition with Angular
<svg:circle [attr.r.px]="item.r"
[ngClass]="'marker'"
[appSvgTransition]="transition"
[d3-attr]="{cx: item.x, cy: item.y}">
</svg:circle>
@nautilytics
nautilytics / d3-quadtree-search.js
Last active January 21, 2020 18:41
A quadtree recursively partitions two-dimensional space into squares, dividing each square into four equally-sized squares.
import {quadtree as d3_quadtree} from "d3-quadtree";
import {search} from "search.js";
// ...
// Create cluster points, i.e. an array of:
// [[cluster_x, cluster_y, [points_to_cluster], ...]
const nodes = [[0, 0, {id: 1, r: 10, name: "node-1"}], [10, 10, {id: 2, r: 10, name: "node-2"}]];
const clusterRange = 80;
const quadtree = d3_quadtree().addAll(nodes);
@nautilytics
nautilytics / d3-force-layout.js
Created January 21, 2020 18:45
Using d3-force simulation to place points
const calculateLayout = (items, spacing = 0.01) => {
// Calculate a force directed placement for each point
const MAX_STEPS = 300,
STRENGTH = 10,
ALPHA = 0.3;
if (!items.length) return [];
const getY = d => d.y;
const getX = d => d.x;
@nautilytics
nautilytics / area-chart-mask.html
Created January 29, 2020 21:48
An SVG Mask for interactive mouse events on an area chart
<svg width="100%" height="100%">
<defs>
<mask
id='mask-for-area-chart'
maskUnits="userSpaceOnUse"
maskContentUnits="userSpaceOnUse">
<path d="M0Z" style="fill: white;">
</path>
</g>
</mask>
@nautilytics
nautilytics / UK.json
Last active January 12, 2021 17:05
A GeoJSON to PNG converter using D3 for Node
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@nautilytics
nautilytics / deploy_staging.yml
Created February 17, 2020 01:49
A Github action for deploying the UK Political Atlas to S3 after a merged pull request
name: Deploy Staging Branch
on:
push:
branches:
- master
jobs:
build:
runs-on: ubuntu-latest