Skip to content

Instantly share code, notes, and snippets.

<!DOCTYPE html>
<script src="https://unpkg.com/d3/dist/d3.js"></script>
<script src="https://unpkg.com/d3fc/build/d3fc.js"></script>
<style> #small-multiples > div { height: 250px; } </style>
<d3fc-canvas id='small-multiples'></d3fc-canvas>
<script>
xScale = d3.scaleLinear().domain([-1, 10]);
yScale = d3.scaleLinear().domain([-1, 10]);
series = fc.seriesSvgPoint().crossValue(d => d.x).mainValue(d => d.y);
chart = fc.chartCartesian(xScale, yScale).svgPlotArea(series);
@truher
truher / tooltip.js
Last active December 12, 2015 05:18
d3 tooltips
/*
* selection datum should contain a 'label' field, which can
* contain multiple lines. first line is emphasized.
*
* selection datum should accomodate the tips fifo called 'tips'.
*
* using a single tooltip element exposes the add/remove race,
* so it's easier to have lots of them; by id. that way we can
* nicely transition the fade of the old one, while creating
* new ones. so each mouseover target datum gets a fifo of
@truher
truher / knapsack-test.js
Last active August 4, 2016 16:51
0-1 knapsack solution in javascript
/*global portviz:false, _:false */
/*
* after rosettacode.org/mw/index.php?title=Knapsack_problem/0-1
*
* details: https://github.com/truher/truher.github.com/wiki/Knapsack
*/
var allwants = [
{name:"map", weight:9, value: 150},
{name:"compass", weight:13, value: 35},
{name:"water", weight:153, value: 200},