Skip to content

Instantly share code, notes, and snippets.

@thudfactor
thudfactor / gist:04902e0ceccfe24d9db8
Last active August 29, 2015 14:09
An example of overuse of brands in descriptions

She put on her Oakley sunglasses and checked her iWatch. Before too long, she knew she'd have to leave the comfortable confines of her Scion, look up her access code in LastPass and punch it into the keypad of her Sargent lock, walk through that Andersen door, and use her iPhone to call her Brylcreemed father. "I know," she said, "I'll poor myself a Maker's Mark before I sit down on the Ligne Roset."

Taking her keys by their basic Alden keyring, she rose unsteadily to her Nine West pumps, and with the empty stare of a Bethesda RPG game character, went to meet her HERO Entertainment Marketing scripted doom.

@thudfactor
thudfactor / Readme.md
Last active December 23, 2015 20:19
Constraint relaxing on a scatterplot

This demonstrates relaxing constraints on label placement. Reload the example to get a different scatterplot. Click "relax" do show the labels reorganizing themselves to prevent stacking.

The relax routine checks collisions between each member of the data and every subsequent member of the data array. If there is a collision, the labels get nudged a bit in opposite directions, and the entire array is walked again. The walking continues until no collisions are found. The routine was inspired by http://bl.ocks.org/syntagmatic/4054247, but I've made some changes to allow more than one label to occupying the same vertical space. I've also removed the setTimeout() method, choosing a loop instead -- this blocks display while computing, but executes much faster.

This is a relatively naïve example intended to demonstrate the basic approach, not serve as a one-size-fits-all, robust solution. Other things to take into consideration: Things I've ignored: changing height or width of labels, boundaries of the charts, e

@thudfactor
thudfactor / gist:6623863
Created September 19, 2013 13:56
Stack Values
// http://stackoverflow.com/questions/13308759/d3-d3-layout-stack-value-issues
@thudfactor
thudfactor / README.md
Last active May 23, 2020 18:46
Drag from HTML, Drop to SVG

This demonstrates dragging from HTML to SVG elements, which can be tricky because of the differences between SVG and HTML DOMs. JQueryUI has a nice API for handling drag and drop, including defining the appearance of a dragged object and providing start, drag, and stop events. Unfortunately, JQueryUI's "drop" does not work at all on SVG elements inside the SVG tag, although it does appear to work on the SVG tag itself.

To get over this limitation, we create a custom Drag/Drop manager, and use the start, drag, and stop events for the dragged elements in conjunction with mouseover and mouseout events on the SVG elements to determine whether or not a "drop" has been dropped on a legal SVG element.