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
/*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] = | |
// }) | |
// }) |
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
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) { |
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
gistup |
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
gistup |
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
// 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) { |
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
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 |
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
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) | |
} |
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
{ | |
"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" | |
}, |
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
Show hidden characters
{ | |
"compilerOptions": { | |
"baseUrl": ".", | |
"paths": { | |
"*": [ | |
"*", | |
"components/*", | |
"portal/*", | |
"platform/*" | |
] |
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
// 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 | |
} | |
} |