Skip to content

Instantly share code, notes, and snippets.

View aholachek's full-sized avatar

Alex Holachek aholachek

View GitHub Profile
@aholachek
aholachek / .script-compiled.js
Last active May 24, 2017 07:59
Animated Grouped/Stacked Bar Transitions
/*eslint no-undef: 0*/
function createChart (svg, data) {
// //normalize data
// Object.keys(data).forEach((d)=>{
// ["0", "1", "2", "3", "4", "5", "6"].forEach(k=>{
// if (d[k] === undefined) d[k] =
// })
// })
@aholachek
aholachek / .script-compiled.js
Last active June 3, 2017 01:53
Data Brushing with Small Multiples
d3.json('./stock-data.json', function(error, data){
createChart(document.querySelector('svg'), data)
})
// ========================================================
// I like to encapsulate d3 logic in a createChart function that returns an update
// function -- this makes it easy to re-use the logic e.g. with React
// ========================================================
function createChart (svg, data, options) {
@aholachek
aholachek / .script-compiled.js
Last active June 1, 2017 17:02
Very simple responsive map of Asia
// load the data, find the svg container in the dom,
// and call createMap
d3.json('map-data.json', function(error, data){
var svg = d3.select('svg')
createMap(svg, data)
})
// put all logic in a nice reusable function
function createMap(svg, data) {
@aholachek
aholachek / FLIP_animation_function.js
Last active December 16, 2017 04:01
React Animation Article Examples
export function animateGroups (ListComponent) {
const items = [...ListComponent.querySelectorAll('.item')]
const oldPositionDict = items.reduce((acc, item) => {
acc[item.dataset.id] = item.getBoundingClientRect()
return acc
}, {})
return function initiateAnimation () {
const transformPositionDict = {}
// Make sure to get the new array of item elements --
// React might have destroyed and created new DOM nodes
export default function addAnimation(animateIn, animateOut) {
return function wrapComponent(WrappedComponent) {
return class AnimationHOC extends Component {
state = { animatingOut: false }
componentDidMount() {
if (this.props.isVisible) animateIn(this.child)
}
@aholachek
aholachek / launch.json
Last active July 19, 2018 15:20
Simple VSCode Node.js launch config for 1) running currently open JS file 2) running jest tests for currently open file
{
"version": "0.2.0",
"configurations": [
{
"name": "Launch current file",
"type": "node",
"request": "launch",
"program": "${file}",
"runtimeExecutable": "${env:HOME}/.nvm/versions/node/v8.4.0/bin/node"
},
@aholachek
aholachek / jsconfig.json
Created January 21, 2018 04:07
VSCode config to allow for "Go To Definition" with Webpack aliases
{
"compilerOptions": {
"baseUrl": ".",
"paths": {
"*": [
"*",
"components/*",
"portal/*",
"platform/*"
]
@aholachek
aholachek / simple_proxy.js
Last active February 5, 2018 18:12
Simple JS Proxy
// a handler object specifies which methods to proxy
// this one will simply override JavaScript’s default object get method
const loggingHandler = {
get(target, property) {
const val = target[property]
console.log(`Property "${property}" returned "${JSON.stringify(val)}"!`)
return val
}
}