-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Major refactor; mesh is a simple callable
I've changed my mind a few times
- Loading branch information
1 parent
12bcc78
commit d2e586c
Showing
6 changed files
with
109 additions
and
10 deletions.
There are no files selected for viewing
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,25 +1,43 @@ | ||
<!DOCTYPE html> | ||
<meta charset="utf-8"> | ||
<style> | ||
.box { | ||
fill: mediumaquamarine; | ||
} | ||
.box { | ||
max-height: 100%; | ||
max-width: 100%; | ||
} | ||
</style> | ||
<body> | ||
<script src="https://d3js.org/d3.v3.min.js"></script> | ||
<script src="d3-mesh.js"></script> | ||
<script> | ||
|
||
var margin = {top: 20, right: 30, bottom: 30, left: 40}, | ||
width = 960, | ||
height = 500; | ||
width = 960 - margin.left - margin.right, | ||
height = 500 - margin.top - margin.bottom; | ||
|
||
var svg = d3.select("body").append("svg") | ||
.attr("width", width) | ||
.attr("height", height); | ||
.attr("width", width + margin.left + margin.right) | ||
.attr("height", height + margin.top + margin.bottom); | ||
|
||
var plot = svg.append("g") | ||
.attr("transform", "translate(" + margin.left + "," + margin.top + ")"); | ||
|
||
var x = d3.scale.linear().range([0, width]).domain([0,1]); | ||
var y = d3.interpolate(0, height); | ||
|
||
var mesh = d3_mesh.mesh() | ||
.dims([x,y]) | ||
.divs([4,44]); | ||
|
||
d3.json("./table.json", function(error, data) { | ||
if (error) throw error; | ||
|
||
console.log(data); | ||
for (var i in [0,1,2]) { | ||
console.log(mesh([i, i])); | ||
} | ||
}); | ||
|
||
</script> |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
{ | ||
"data": [ | ||
"table": [ | ||
["a", "b", "c", "d"], | ||
["e", "f", "g", "h"], | ||
["i", "j", "k", "l"], | ||
|
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,42 @@ | ||
export default function() { | ||
return 42; | ||
var dims, | ||
divs; | ||
|
||
//TODO: cell.js | ||
//TODO: 3 results: interpolate(relX, relY, ...) -> array of interpolated dims, mesh(dims) -> N-D array of cells / callable?, cover(context, data) -> selection of {data, d1, d2, dx...} | ||
//TODO: provide some useful interpolators out of the box | ||
|
||
function mesh(indices) { | ||
var ans = []; | ||
for (var i in dims) { | ||
ans[i] = dims[i](indices[i] / divs[i]); | ||
} | ||
return ans; | ||
} | ||
|
||
function interpolate(args) { | ||
var ans = new Array(dims.length); | ||
for (var i in args) { | ||
ans[i] = dims[i](args[i]); | ||
} | ||
return ans; | ||
} | ||
|
||
mesh.dims = function(_) { | ||
return arguments.length ? ( | ||
dims = _, | ||
mesh | ||
) : dims; | ||
}; | ||
|
||
mesh.divs = function(_) { | ||
return arguments.length ? ( | ||
divs = _, | ||
mesh | ||
) : divs; | ||
}; | ||
|
||
mesh.interpolate = interpolate; | ||
|
||
return mesh; | ||
}; |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
var tape = require("tape"), | ||
mesh = require("../"); | ||
|
||
tape("mesh() returns the answer to the ultimate question of life, the universe, and everything.", function(test) { | ||
tape("I know tests are important :/", function(test) { | ||
test.equal(true, true); | ||
test.end(); | ||
}); |